atheros: 2.6.32 support
[openwrt.git] / target / linux / atheros / patches-2.6.32 / 210-reset_button.patch
1 Index: linux-2.6.32.7/arch/mips/ar231x/Makefile
2 ===================================================================
3 --- linux-2.6.32.7.orig/arch/mips/ar231x/Makefile 2010-02-03 17:00:21.031428952 +0100
4 +++ linux-2.6.32.7/arch/mips/ar231x/Makefile 2010-02-03 17:02:36.795429223 +0100
5 @@ -8,7 +8,7 @@
6 # Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
7 #
8
9 -obj-y += board.o prom.o devices.o
10 +obj-y += board.o prom.o devices.o reset.o
11 obj-$(CONFIG_ATHEROS_AR5312) += ar5312.o
12 obj-$(CONFIG_ATHEROS_AR2315) += ar2315.o
13 obj-$(CONFIG_ATHEROS_AR2315_PCI) += pci.o
14 Index: linux-2.6.32.7/arch/mips/ar231x/reset.c
15 ===================================================================
16 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
17 +++ linux-2.6.32.7/arch/mips/ar231x/reset.c 2010-02-03 17:02:36.795429223 +0100
18 @@ -0,0 +1,160 @@
19 +#include <linux/init.h>
20 +#include <linux/module.h>
21 +#include <linux/timer.h>
22 +#include <linux/interrupt.h>
23 +#include <linux/kobject.h>
24 +#include <linux/workqueue.h>
25 +#include <linux/skbuff.h>
26 +#include <linux/netlink.h>
27 +#include <net/sock.h>
28 +#include <asm/uaccess.h>
29 +#include <ar231x_platform.h>
30 +#include <ar231x.h>
31 +#include <gpio.h>
32 +#include "devices.h"
33 +
34 +#define AR531X_RESET_GPIO_IRQ (AR531X_GPIO_IRQ(ar231x_board.config->resetConfigGpio))
35 +
36 +struct event_t {
37 + struct work_struct wq;
38 + int set;
39 + unsigned long jiffies;
40 +};
41 +
42 +static struct timer_list rst_button_timer;
43 +static unsigned long seen;
44 +
45 +extern struct sock *uevent_sock;
46 +extern u64 uevent_next_seqnum(void);
47 +
48 +static int no_release_workaround = 1;
49 +module_param(no_release_workaround, int, 0);
50 +
51 +static inline void
52 +add_msg(struct sk_buff *skb, char *msg)
53 +{
54 + char *scratch;
55 + scratch = skb_put(skb, strlen(msg) + 1);
56 + sprintf(scratch, msg);
57 +}
58 +
59 +static void
60 +hotplug_button(struct work_struct *wq)
61 +{
62 + struct sk_buff *skb;
63 + struct event_t *event;
64 + size_t len;
65 + char *scratch, *s;
66 + char buf[128];
67 +
68 + event = container_of(wq, struct event_t, wq);
69 + if (!uevent_sock)
70 + goto done;
71 +
72 + /* allocate message with the maximum possible size */
73 + s = event->set ? "pressed" : "released";
74 + len = strlen(s) + 2;
75 + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
76 + if (!skb)
77 + goto done;
78 +
79 + /* add header */
80 + scratch = skb_put(skb, len);
81 + sprintf(scratch, "%s@",s);
82 +
83 + /* copy keys to our continuous event payload buffer */
84 + add_msg(skb, "HOME=/");
85 + add_msg(skb, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
86 + add_msg(skb, "SUBSYSTEM=button");
87 + add_msg(skb, "BUTTON=reset");
88 + add_msg(skb, (event->set ? "ACTION=pressed" : "ACTION=released"));
89 + sprintf(buf, "SEEN=%ld", (event->jiffies - seen)/HZ);
90 + add_msg(skb, buf);
91 + snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
92 + add_msg(skb, buf);
93 +
94 + NETLINK_CB(skb).dst_group = 1;
95 + netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL);
96 +
97 +done:
98 + kfree(event);
99 +}
100 +
101 +static void
102 +reset_button_poll(unsigned long unused)
103 +{
104 + struct event_t *event;
105 + int gpio = ~0;
106 +
107 + if(!no_release_workaround)
108 + return;
109 +
110 + gpio = ar231x_gpiodev->get();
111 + gpio &= (1 << (AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE));
112 + if(gpio) {
113 + rst_button_timer.expires = jiffies + (HZ / 4);
114 + add_timer(&rst_button_timer);
115 + return;
116 + }
117 +
118 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
119 + if (!event)
120 + return;
121 +
122 + event->set = 0;
123 + event->jiffies = jiffies;
124 + INIT_WORK(&event->wq, hotplug_button);
125 + schedule_work(&event->wq);
126 +}
127 +
128 +static irqreturn_t
129 +button_handler(int irq, void *dev_id)
130 +{
131 + static int pressed = 0;
132 + struct event_t *event;
133 + u32 gpio = ~0;
134 +
135 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
136 + if (!event)
137 + return IRQ_NONE;
138 +
139 + pressed = !pressed;
140 +
141 + gpio = ar231x_gpiodev->get() & (1 << (irq - AR531X_GPIO_IRQ_BASE));
142 +
143 + event->set = gpio;
144 + if(!event->set)
145 + no_release_workaround = 0;
146 +
147 + event->jiffies = jiffies;
148 +
149 + INIT_WORK(&event->wq, hotplug_button);
150 + schedule_work(&event->wq);
151 +
152 + seen = jiffies;
153 + if(event->set && no_release_workaround)
154 + mod_timer(&rst_button_timer, jiffies + (HZ / 4));
155 +
156 + return IRQ_HANDLED;
157 +}
158 +
159 +
160 +static int __init
161 +ar231x_init_reset(void)
162 +{
163 + seen = jiffies;
164 +
165 + if (ar231x_board.config->resetConfigGpio == 0xffff)
166 + return -ENODEV;
167 +
168 + init_timer(&rst_button_timer);
169 + rst_button_timer.function = reset_button_poll;
170 + rst_button_timer.expires = jiffies + HZ / 50;
171 + add_timer(&rst_button_timer);
172 +
173 + request_irq(AR531X_RESET_GPIO_IRQ, &button_handler, IRQF_SAMPLE_RANDOM, "ar231x_reset", NULL);
174 +
175 + return 0;
176 +}
177 +
178 +module_init(ar231x_init_reset);
This page took 0.058281 seconds and 5 git commands to generate.