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