Disable CONFIG_NETDEVICES_MULTIQUEUE for ar7 until we fix the race condition
[openwrt.git] / target / linux / atheros / files / arch / mips / atheros / reset.c
1 #include <linux/module.h>
2 #include <linux/timer.h>
3 #include <linux/interrupt.h>
4 #include <linux/kobject.h>
5 #include <linux/workqueue.h>
6 #include <linux/skbuff.h>
7 #include <linux/netlink.h>
8 #include <net/sock.h>
9 #include <asm/uaccess.h>
10 #include "ar531x.h"
11 #include "ar5315/ar5315.h"
12
13 #define AR531X_RESET_GPIO_IRQ (AR531X_GPIO_IRQ_BASE + bcfg->resetConfigGpio)
14
15 struct event_t {
16 struct work_struct wq;
17 int set;
18 long int jiffies;
19 };
20
21 static struct ar531x_boarddata *bcfg;
22
23 extern struct sock *uevent_sock;
24 extern u64 uevent_next_seqnum(void);
25 static int seen;
26
27 static inline void add_msg(struct sk_buff *skb, char *msg)
28 {
29 char *scratch;
30 scratch = skb_put(skb, strlen(msg) + 1);
31 sprintf(scratch, msg);
32 }
33
34 static void hotplug_button(struct work_struct *wq)
35 {
36 struct sk_buff *skb;
37 struct event_t *event;
38 size_t len;
39 char *scratch, *s;
40 char buf[128];
41
42 event = container_of(wq, struct event_t, wq);
43 if (!uevent_sock)
44 goto done;
45
46 /* allocate message with the maximum possible size */
47 s = event->set ? "pressed" : "released";
48 len = strlen(s) + 2;
49 skb = alloc_skb(len + 2048, GFP_KERNEL);
50 if (!skb)
51 goto done;
52
53 /* add header */
54 scratch = skb_put(skb, len);
55 sprintf(scratch, "%s@",s);
56
57 /* copy keys to our continuous event payload buffer */
58 add_msg(skb, "HOME=/");
59 add_msg(skb, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
60 add_msg(skb, "SUBSYSTEM=button");
61 add_msg(skb, "BUTTON=reset");
62 add_msg(skb, (event->set ? "ACTION=pressed" : "ACTION=released"));
63 sprintf(buf, "SEEN=%ld", (event->jiffies - seen)/HZ);
64 add_msg(skb, buf);
65 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
66 add_msg(skb, buf);
67
68 NETLINK_CB(skb).dst_group = 1;
69 netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL);
70
71 done:
72 kfree(event);
73 }
74
75 static irqreturn_t button_handler(int irq, void *dev_id)
76 {
77 static int pressed = 0;
78 struct event_t *event;
79 u32 gpio = ~0;
80
81 event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
82 if (!event)
83 return IRQ_NONE;
84
85 pressed = !pressed;
86
87 DO_AR5315(gpio = sysRegRead(AR5315_GPIO_DI);)
88 gpio &= 1 << (irq - AR531X_GPIO_IRQ_BASE);
89
90 event->set = gpio;
91 event->jiffies = jiffies;
92
93 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
94 schedule_work(&event->wq);
95
96 seen = jiffies;
97
98 return IRQ_HANDLED;
99 }
100
101 void ar531x_disable_reset_button(void)
102 {
103 disable_irq(AR531X_RESET_GPIO_IRQ);
104 }
105
106 EXPORT_SYMBOL(ar531x_disable_reset_button);
107
108 int __init ar531x_init_reset(void)
109 {
110 bcfg = (struct ar531x_boarddata *) board_config;
111
112 seen = jiffies;
113
114 request_irq(AR531X_RESET_GPIO_IRQ, &button_handler, IRQF_SAMPLE_RANDOM, "ar531x_reset", NULL);
115
116 return 0;
117 }
118
119
120
121 module_init(ar531x_init_reset);
This page took 0.05746 seconds and 5 git commands to generate.