1 --- a/arch/mips/ar231x/Makefile
2 +++ b/arch/mips/ar231x/Makefile
4 # Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
7 -obj-y += board.o prom.o devices.o
8 +obj-y += board.o prom.o devices.o reset.o
10 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
13 +++ b/arch/mips/ar231x/reset.c
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>
30 +#define AR531X_RESET_GPIO_IRQ (AR531X_GPIO_IRQ(ar231x_board.config->resetConfigGpio))
33 + struct work_struct wq;
35 + unsigned long jiffies;
38 +static struct timer_list rst_button_timer;
39 +static unsigned long seen;
41 +extern struct sock *uevent_sock;
42 +extern u64 uevent_next_seqnum(void);
44 +static int no_release_workaround = 1;
45 +module_param(no_release_workaround, int, 0);
48 +add_msg(struct sk_buff *skb, char *msg)
51 + scratch = skb_put(skb, strlen(msg) + 1);
52 + sprintf(scratch, msg);
56 +hotplug_button(struct work_struct *wq)
58 + struct sk_buff *skb;
59 + struct event_t *event;
64 + event = container_of(wq, struct event_t, wq);
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);
76 + scratch = skb_put(skb, len);
77 + sprintf(scratch, "%s@",s);
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);
87 + snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
90 + NETLINK_CB(skb).dst_group = 1;
91 + netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL);
98 +reset_button_poll(unsigned long unused)
100 + struct event_t *event;
103 + if(!no_release_workaround)
106 + gpio = ar231x_gpiodev->get();
107 + gpio &= (1 << (AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE));
109 + rst_button_timer.expires = jiffies + (HZ / 4);
110 + add_timer(&rst_button_timer);
114 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
119 + event->jiffies = jiffies;
120 + INIT_WORK(&event->wq, hotplug_button);
121 + schedule_work(&event->wq);
125 +button_handler(int irq, void *dev_id)
127 + static int pressed = 0;
128 + struct event_t *event;
131 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
135 + pressed = !pressed;
137 + gpio = ar231x_gpiodev->get() & (1 << (irq - AR531X_GPIO_IRQ_BASE));
141 + no_release_workaround = 0;
143 + event->jiffies = jiffies;
145 + INIT_WORK(&event->wq, hotplug_button);
146 + schedule_work(&event->wq);
149 + if(event->set && no_release_workaround)
150 + mod_timer(&rst_button_timer, jiffies + (HZ / 4));
152 + return IRQ_HANDLED;
157 +ar231x_init_reset(void)
161 + if (ar231x_board.config->resetConfigGpio == 0xffff)
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);
169 + request_irq(AR531X_RESET_GPIO_IRQ, &button_handler, IRQF_SAMPLE_RANDOM, "ar231x_reset", NULL);
174 +module_init(ar231x_init_reset);