2 * arch/arm/mach-ixp4xx/dsmg600-power.c
4 * DSM-G600 Power/Reset driver
5 * Author: Michael Westerhof <mwester@dls.net>
7 * Based on nslu2-power.c
8 * Copyright (C) 2005 Tower Technologies
9 * Author: Alessandro Zummo <a.zummo@towertech.it>
11 * which was based on nslu2-io.c
12 * Copyright (C) 2004 Karen Spearel
14 * Maintainers: http://www.nslu2-linux.org/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
22 #include <linux/module.h>
23 #include <linux/reboot.h>
24 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/jiffies.h>
27 #include <linux/timer.h>
29 #include <asm/mach-types.h>
31 extern void ctrl_alt_del(void);
33 /* This is used to make sure the power-button pusher is serious. The button
34 * must be held until the value of this counter reaches zero.
36 static volatile int power_button_countdown;
38 /* Must hold the button down for at least this many counts to be processed */
39 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
41 static void dsmg600_power_handler(unsigned long data);
42 static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
44 static void dsmg600_power_handler(unsigned long data)
46 /* This routine is called twice per second to check the
47 * state of the power button.
50 if (*IXP4XX_GPIO_GPINR & DSMG600_PB_BM) {
52 /* IO Pin is 1 (button pushed) */
53 if (power_button_countdown == 0) {
54 /* Signal init to do the ctrlaltdel action, this will bypass
55 * init if it hasn't started and do a kernel_restart.
59 /* Change the state of the power LED to "blink" */
60 gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
62 power_button_countdown--;
65 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
68 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
71 static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
73 /* This is the paper-clip reset, it shuts the machine down directly. */
79 static int __init dsmg600_power_init(void)
81 if (!(machine_is_dsmg600()))
84 if (request_irq(DSMG600_RB_IRQ, &dsmg600_reset_handler,
85 IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
88 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
94 /* The power button on the D-Link DSM-G600 is on GPIO 15, but
95 * it cannot handle interrupts on that GPIO line. So we'll
96 * have to poll it with a kernel timer.
99 /* Make sure that the power button GPIO is set up as an input */
100 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
102 /* Set the initial value for the power button IRQ handler */
103 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
105 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
110 static void __exit dsmg600_power_exit(void)
112 if (!(machine_is_dsmg600()))
115 del_timer_sync(&dsmg600_power_timer);
117 free_irq(DSMG600_RB_IRQ, NULL);
120 module_init(dsmg600_power_init);
121 module_exit(dsmg600_power_exit);
123 MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>");
124 MODULE_DESCRIPTION("DSM-G600 Power/Reset driver");
125 MODULE_LICENSE("GPL");