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
6 # Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
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
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>
34 +#define AR531X_RESET_GPIO_IRQ (AR531X_GPIO_IRQ(ar231x_board.config->resetConfigGpio))
37 + struct work_struct wq;
39 + unsigned long jiffies;
42 +static struct timer_list rst_button_timer;
43 +static unsigned long seen;
45 +extern struct sock *uevent_sock;
46 +extern u64 uevent_next_seqnum(void);
48 +static int no_release_workaround = 1;
49 +module_param(no_release_workaround, int, 0);
52 +add_msg(struct sk_buff *skb, char *msg)
55 + scratch = skb_put(skb, strlen(msg) + 1);
56 + sprintf(scratch, msg);
60 +hotplug_button(struct work_struct *wq)
62 + struct sk_buff *skb;
63 + struct event_t *event;
68 + event = container_of(wq, struct event_t, wq);
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);
80 + scratch = skb_put(skb, len);
81 + sprintf(scratch, "%s@",s);
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);
91 + snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
94 + NETLINK_CB(skb).dst_group = 1;
95 + netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL);
102 +reset_button_poll(unsigned long unused)
104 + struct event_t *event;
107 + if(!no_release_workaround)
110 + gpio = ar231x_gpiodev->get();
111 + gpio &= (1 << (AR531X_RESET_GPIO_IRQ - AR531X_GPIO_IRQ_BASE));
113 + rst_button_timer.expires = jiffies + (HZ / 4);
114 + add_timer(&rst_button_timer);
118 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
123 + event->jiffies = jiffies;
124 + INIT_WORK(&event->wq, hotplug_button);
125 + schedule_work(&event->wq);
129 +button_handler(int irq, void *dev_id)
131 + static int pressed = 0;
132 + struct event_t *event;
135 + event = (struct event_t *) kzalloc(sizeof(struct event_t), GFP_ATOMIC);
139 + pressed = !pressed;
141 + gpio = ar231x_gpiodev->get() & (1 << (irq - AR531X_GPIO_IRQ_BASE));
145 + no_release_workaround = 0;
147 + event->jiffies = jiffies;
149 + INIT_WORK(&event->wq, hotplug_button);
150 + schedule_work(&event->wq);
153 + if(event->set && no_release_workaround)
154 + mod_timer(&rst_button_timer, jiffies + (HZ / 4));
156 + return IRQ_HANDLED;
161 +ar231x_init_reset(void)
165 + if (ar231x_board.config->resetConfigGpio == 0xffff)
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);
173 + request_irq(AR531X_RESET_GPIO_IRQ, &button_handler, IRQF_SAMPLE_RANDOM, "ar231x_reset", NULL);
178 +module_init(ar231x_init_reset);