Ticket #3462: 032-subsume_power_files.patch

File 032-subsume_power_files.patch, 23.2 KB (added by Giampolo Mancini <giampaolo.mancini@…>, 10 years ago)

Working 032-subsume_power_files.patch

  • arch/arm/mach-ixp4xx/Makefile

    From: Rod Whitby <rod@whitby.id.au>
    Subject: ixp4xx: Merge nslu2-power.c into nslu2-setup.c (Patch #4807)
    
    There is no reason to have power control in a separate file from the
    board setup code.  Merge it back into the board setup file, removing
    superfluous header includes and removing superfluous constants from
    the machine header file.
    
    Signed-off-by: Rod Whitby <rod@whitby.id.au>
    --
    PATCH FOLLOWS
    KernelVersion: v2.6.24-1917-gaf66bd3
    
    old new  
    2424obj-$(CONFIG_MACH_IXDPG425)     += coyote-setup.o 
    2525obj-$(CONFIG_ARCH_ADI_COYOTE)   += coyote-setup.o 
    2626obj-$(CONFIG_MACH_GTWX5715)     += gtwx5715-setup.o 
    27 obj-$(CONFIG_MACH_NSLU2)        += nslu2-setup.o nslu2-power.o 
    28 obj-$(CONFIG_MACH_NAS100D)      += nas100d-setup.o nas100d-power.o 
    29 obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o dsmg600-power.o 
     27obj-$(CONFIG_MACH_NSLU2)        += nslu2-setup.o 
     28obj-$(CONFIG_MACH_NAS100D)      += nas100d-setup.o 
     29obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o 
    3030obj-$(CONFIG_MACH_GATEWAY7001)  += gateway7001-setup.o 
    3131obj-$(CONFIG_MACH_WG302V2)      += wg302v2-setup.o 
    3232obj-$(CONFIG_MACH_FSG)          += fsg-setup.o 
  • deleted file linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nslu2-power.c

    + -  
    1 /* 
    2  * arch/arm/mach-ixp4xx/nslu2-power.c 
    3  * 
    4  * NSLU2 Power/Reset driver 
    5  * 
    6  * Copyright (C) 2005 Tower Technologies 
    7  * 
    8  * based on nslu2-io.c 
    9  *  Copyright (C) 2004 Karen Spearel 
    10  * 
    11  * Author: Alessandro Zummo <a.zummo@towertech.it> 
    12  * Maintainers: http://www.nslu2-linux.org/ 
    13  * 
    14  * This program is free software; you can redistribute it and/or modify 
    15  * it under the terms of the GNU General Public License version 2 as 
    16  * published by the Free Software Foundation. 
    17  * 
    18  */ 
    19  
    20 #include <linux/module.h> 
    21 #include <linux/reboot.h> 
    22 #include <linux/irq.h> 
    23 #include <linux/interrupt.h> 
    24 #include <linux/reboot.h> 
    25  
    26 #include <asm/mach-types.h> 
    27  
    28 static irqreturn_t nslu2_power_handler(int irq, void *dev_id) 
    29 { 
    30         /* Signal init to do the ctrlaltdel action, this will bypass init if 
    31          * it hasn't started and do a kernel_restart. 
    32          */ 
    33         ctrl_alt_del(); 
    34  
    35         return IRQ_HANDLED; 
    36 } 
    37  
    38 static irqreturn_t nslu2_reset_handler(int irq, void *dev_id) 
    39 { 
    40         /* This is the paper-clip reset, it shuts the machine down directly. 
    41          */ 
    42         machine_power_off(); 
    43  
    44         return IRQ_HANDLED; 
    45 } 
    46  
    47 static int __init nslu2_power_init(void) 
    48 { 
    49         if (!(machine_is_nslu2())) 
    50                 return 0; 
    51  
    52         *IXP4XX_GPIO_GPISR = 0x20400000;        /* read the 2 irqs to clr */ 
    53  
    54         set_irq_type(NSLU2_RB_IRQ, IRQT_LOW); 
    55         set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH); 
    56  
    57         if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler, 
    58                 IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) { 
    59  
    60                 printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
    61                         NSLU2_RB_IRQ); 
    62  
    63                 return -EIO; 
    64         } 
    65  
    66         if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler, 
    67                 IRQF_DISABLED, "NSLU2 power button", NULL) < 0) { 
    68  
    69                 printk(KERN_DEBUG "Power Button IRQ %d not available\n", 
    70                         NSLU2_PB_IRQ); 
    71  
    72                 return -EIO; 
    73         } 
    74  
    75         return 0; 
    76 } 
    77  
    78 static void __exit nslu2_power_exit(void) 
    79 { 
    80         if (!(machine_is_nslu2())) 
    81                 return; 
    82  
    83         free_irq(NSLU2_RB_IRQ, NULL); 
    84         free_irq(NSLU2_PB_IRQ, NULL); 
    85 } 
    86  
    87 module_init(nslu2_power_init); 
    88 module_exit(nslu2_power_exit); 
    89  
    90 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 
    91 MODULE_DESCRIPTION("NSLU2 Power/Reset driver"); 
    92 MODULE_LICENSE("GPL"); 
  • arch/arm/mach-ixp4xx/nslu2-setup.c

    old new  
    33 * 
    44 * NSLU2 board-setup 
    55 * 
    6  * based ixdp425-setup.c: 
     6 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> 
     7 * 
     8 * based on ixdp425-setup.c: 
    79 *      Copyright (C) 2003-2004 MontaVista Software, Inc. 
     10 * based on nslu2-power.c: 
     11 *      Copyright (C) 2005 Tower Technologies 
    812 * 
    913 * Author: Mark Rakes <mrakes at mac.com> 
    1014 * Author: Rod Whitby <rod@whitby.id.au> 
     15 * Author: Alessandro Zummo <a.zummo@towertech.it> 
    1116 * Maintainers: http://www.nslu2-linux.org/ 
    1217 * 
    13  * Fixed missing init_time in MACHINE_START kas11 10/22/04 
    14  * Changed to conform to new style __init ixdp425 kas11 10/22/04 
    1518 */ 
    1619 
    1720#include <linux/if_ether.h> 
    18 #include <linux/kernel.h> 
     21#include <linux/irq.h> 
    1922#include <linux/serial.h> 
    2023#include <linux/serial_8250.h> 
    2124#include <linux/leds.h> 
     25#include <linux/reboot.h> 
    2226#include <linux/i2c.h> 
    2327#include <linux/i2c-gpio.h> 
    2428 
     
    2731#include <asm/mach/flash.h> 
    2832#include <asm/mach/time.h> 
    2933#include <asm/io.h> 
     34#include <asm/gpio.h> 
    3035 
    3136static struct flash_platform_data nslu2_flash_data = { 
    3237        .map_name               = "cfi_probe", 
    static void nslu2_power_off(void) 
    181186        gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH); 
    182187} 
    183188 
     189static irqreturn_t nslu2_power_handler(int irq, void *dev_id) 
     190{ 
     191        /* Signal init to do the ctrlaltdel action, this will bypass init if 
     192         * it hasn't started and do a kernel_restart. 
     193         */ 
     194        ctrl_alt_del(); 
     195 
     196        return IRQ_HANDLED; 
     197} 
     198 
     199static irqreturn_t nslu2_reset_handler(int irq, void *dev_id) 
     200{ 
     201        /* This is the paper-clip reset, it shuts the machine down directly. 
     202         */ 
     203        machine_power_off(); 
     204 
     205        return IRQ_HANDLED; 
     206} 
     207 
    184208static void __init nslu2_timer_init(void) 
    185209{ 
    186210    /* The xtal on this machine is non-standard. */ 
    static void __init nslu2_init(void) 
    206230        nslu2_flash_resource.end = 
    207231                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 
    208232 
    209         pm_power_off = nslu2_power_off; 
    210  
    211233        i2c_register_board_info(0, nslu2_i2c_board_info, 
    212234                                ARRAY_SIZE(nslu2_i2c_board_info)); 
    213235 
    static void __init nslu2_init(void) 
    220242 
    221243        platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices)); 
    222244 
     245        pm_power_off = nslu2_power_off; 
     246 
     247        if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler, 
     248                IRQF_DISABLED | IRQF_TRIGGER_LOW, 
     249                "NSLU2 reset button", NULL) < 0) { 
     250 
     251                printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
     252                        gpio_to_irq(NSLU2_RB_GPIO)); 
     253        } 
     254 
     255        if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler, 
     256                IRQF_DISABLED | IRQF_TRIGGER_HIGH, 
     257                "NSLU2 power button", NULL) < 0) { 
     258 
     259                printk(KERN_DEBUG "Power Button IRQ %d not available\n", 
     260                        gpio_to_irq(NSLU2_PB_GPIO)); 
     261        } 
    223262 
    224263        /* 
    225264         * Map in a portion of the flash and read the MAC address. 
  • include/asm-arm/arch-ixp4xx/nslu2.h

    old new  
    3939 
    4040/* Buttons */ 
    4141 
    42 #define NSLU2_PB_GPIO           5 
     42#define NSLU2_PB_GPIO           5       /* power button */ 
    4343#define NSLU2_PO_GPIO           8       /* power off */ 
    44 #define NSLU2_RB_GPIO           12 
    45  
    46 #define NSLU2_PB_IRQ            IRQ_IXP4XX_GPIO5 
    47 #define NSLU2_RB_IRQ            IRQ_IXP4XX_GPIO12 
    48  
    49 #define NSLU2_PB_BM             (1L << NSLU2_PB_GPIO) 
    50 #define NSLU2_PO_BM             (1L << NSLU2_PO_GPIO) 
    51 #define NSLU2_RB_BM             (1L << NSLU2_RB_GPIO) 
     44#define NSLU2_RB_GPIO           12      /* reset button */ 
    5245 
    5346/* Buzzer */ 
    5447 
    5548#define NSLU2_GPIO_BUZZ         4 
    56 #define NSLU2_BZ_BM             (1L << NSLU2_GPIO_BUZZ) 
    5749 
    5850/* LEDs */ 
    5951 
    6052#define NSLU2_LED_RED_GPIO      0 
    6153#define NSLU2_LED_GRN_GPIO      1 
    62  
    63 #define NSLU2_LED_RED_BM        (1L << NSLU2_LED_RED_GPIO) 
    64 #define NSLU2_LED_GRN_BM        (1L << NSLU2_LED_GRN_GPIO) 
    65  
    6654#define NSLU2_LED_DISK1_GPIO    3 
    6755#define NSLU2_LED_DISK2_GPIO    2 
    68  
    69 #define NSLU2_LED_DISK1_BM      (1L << NSLU2_LED_DISK1_GPIO) 
    70 #define NSLU2_LED_DISK2_BM      (1L << NSLU2_LED_DISK2_GPIO) 
    71  
    72  
  • deleted file linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nas100d-power.c

    + -  
    1 /* 
    2  * arch/arm/mach-ixp4xx/nas100d-power.c 
    3  * 
    4  * NAS 100d Power/Reset driver 
    5  * 
    6  * Copyright (C) 2005 Tower Technologies 
    7  * 
    8  * based on nas100d-io.c 
    9  *  Copyright (C) 2004 Karen Spearel 
    10  * 
    11  * Author: Alessandro Zummo <a.zummo@towertech.it> 
    12  * Maintainers: http://www.nslu2-linux.org/ 
    13  * 
    14  * This program is free software; you can redistribute it and/or modify 
    15  * it under the terms of the GNU General Public License version 2 as 
    16  * published by the Free Software Foundation. 
    17  * 
    18  */ 
    19  
    20 #include <linux/interrupt.h> 
    21 #include <linux/irq.h> 
    22 #include <linux/module.h> 
    23 #include <linux/reboot.h> 
    24 #include <linux/jiffies.h> 
    25 #include <linux/timer.h> 
    26  
    27 #include <asm/gpio.h> 
    28 #include <asm/mach-types.h> 
    29  
    30 /* This is used to make sure the power-button pusher is serious.  The button 
    31  * must be held until the value of this counter reaches zero. 
    32  */ 
    33 static int power_button_countdown; 
    34  
    35 /* Must hold the button down for at least this many counts to be processed */ 
    36 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */ 
    37  
    38 static void nas100d_power_handler(unsigned long data); 
    39 static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0); 
    40  
    41 static void nas100d_power_handler(unsigned long data) 
    42 { 
    43         /* This routine is called twice per second to check the 
    44          * state of the power button. 
    45          */ 
    46  
    47         if (gpio_get_value(NAS100D_PB_GPIO)) { 
    48  
    49                 /* IO Pin is 1 (button pushed) */ 
    50                 if (power_button_countdown > 0) 
    51                         power_button_countdown--; 
    52  
    53         } else { 
    54  
    55                 /* Done on button release, to allow for auto-power-on mods. */ 
    56                 if (power_button_countdown == 0) { 
    57                         /* Signal init to do the ctrlaltdel action, 
    58                          * this will bypass init if it hasn't started 
    59                          * and do a kernel_restart. 
    60                          */ 
    61                         ctrl_alt_del(); 
    62  
    63                         /* Change the state of the power LED to "blink" */ 
    64                         gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 
    65                 } else { 
    66                         power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
    67                 } 
    68         } 
    69  
    70         mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 
    71 } 
    72  
    73 static irqreturn_t nas100d_reset_handler(int irq, void *dev_id) 
    74 { 
    75         /* This is the paper-clip reset, it shuts the machine down directly. */ 
    76         machine_power_off(); 
    77  
    78         return IRQ_HANDLED; 
    79 } 
    80  
    81 static int __init nas100d_power_init(void) 
    82 { 
    83         if (!(machine_is_nas100d())) 
    84                 return 0; 
    85  
    86         set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW); 
    87  
    88         if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler, 
    89                 IRQF_DISABLED, "NAS100D reset button", NULL) < 0) { 
    90  
    91                 printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
    92                         gpio_to_irq(NAS100D_RB_GPIO)); 
    93  
    94                 return -EIO; 
    95         } 
    96  
    97         /* The power button on the Iomega NAS100d is on GPIO 14, but 
    98          * it cannot handle interrupts on that GPIO line.  So we'll 
    99          * have to poll it with a kernel timer. 
    100          */ 
    101  
    102         /* Make sure that the power button GPIO is set up as an input */ 
    103         gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN); 
    104  
    105         /* Set the initial value for the power button IRQ handler */ 
    106         power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
    107  
    108         mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 
    109  
    110         return 0; 
    111 } 
    112  
    113 static void __exit nas100d_power_exit(void) 
    114 { 
    115         if (!(machine_is_nas100d())) 
    116                 return; 
    117  
    118         del_timer_sync(&nas100d_power_timer); 
    119  
    120         free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL); 
    121 } 
    122  
    123 module_init(nas100d_power_init); 
    124 module_exit(nas100d_power_exit); 
    125  
    126 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 
    127 MODULE_DESCRIPTION("NAS100D Power/Reset driver"); 
    128 MODULE_LICENSE("GPL"); 
  • arch/arm/mach-ixp4xx/nas100d-setup.c

    old new  
    33 * 
    44 * NAS 100d board-setup 
    55 * 
    6  * based ixdp425-setup.c: 
     6 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> 
     7 * 
     8 * based on ixdp425-setup.c: 
    79 *      Copyright (C) 2003-2004 MontaVista Software, Inc. 
     10 * based on nas100d-power.c: 
     11 *      Copyright (C) 2005 Tower Technologies 
     12 * based on nas100d-io.c 
     13 *      Copyright (C) 2004 Karen Spearel 
    814 * 
    915 * Author: Alessandro Zummo <a.zummo@towertech.it> 
    1016 * Author: Rod Whitby <rod@whitby.id.au> 
     
    1319 */ 
    1420 
    1521#include <linux/if_ether.h> 
    16 #include <linux/kernel.h> 
     22#include <linux/irq.h> 
     23#include <linux/jiffies.h> 
     24#include <linux/timer.h> 
    1725#include <linux/serial.h> 
    1826#include <linux/serial_8250.h> 
    1927#include <linux/leds.h> 
     28#include <linux/reboot.h> 
    2029#include <linux/i2c.h> 
    2130#include <linux/i2c-gpio.h> 
    2231 
     
    2433#include <asm/mach/arch.h> 
    2534#include <asm/mach/flash.h> 
    2635#include <asm/io.h> 
     36#include <asm/gpio.h> 
    2737 
    2838static struct flash_platform_data nas100d_flash_data = { 
    2939        .map_name               = "cfi_probe", 
    static void nas100d_power_off(void) 
    168178        gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH); 
    169179} 
    170180 
     181/* This is used to make sure the power-button pusher is serious.  The button 
     182 * must be held until the value of this counter reaches zero. 
     183 */ 
     184static int power_button_countdown; 
     185 
     186/* Must hold the button down for at least this many counts to be processed */ 
     187#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */ 
     188 
     189static void nas100d_power_handler(unsigned long data); 
     190static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0); 
     191 
     192static void nas100d_power_handler(unsigned long data) 
     193{ 
     194        /* This routine is called twice per second to check the 
     195         * state of the power button. 
     196         */ 
     197 
     198        if (gpio_get_value(NAS100D_PB_GPIO)) { 
     199 
     200                /* IO Pin is 1 (button pushed) */ 
     201                if (power_button_countdown > 0) 
     202                        power_button_countdown--; 
     203 
     204        } else { 
     205 
     206                /* Done on button release, to allow for auto-power-on mods. */ 
     207                if (power_button_countdown == 0) { 
     208                        /* Signal init to do the ctrlaltdel action, 
     209                         * this will bypass init if it hasn't started 
     210                         * and do a kernel_restart. 
     211                         */ 
     212                        ctrl_alt_del(); 
     213 
     214                        /* Change the state of the power LED to "blink" */ 
     215                        gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 
     216                } else { 
     217                        power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
     218                } 
     219        } 
     220 
     221        mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 
     222} 
     223 
     224static irqreturn_t nas100d_reset_handler(int irq, void *dev_id) 
     225{ 
     226        /* This is the paper-clip reset, it shuts the machine down directly. */ 
     227        machine_power_off(); 
     228 
     229        return IRQ_HANDLED; 
     230} 
     231 
    171232static void __init nas100d_init(void) 
    172233{ 
    173234        DECLARE_MAC_BUF(mac_buf); 
    static void __init nas100d_init(void) 
    183244        nas100d_flash_resource.end = 
    184245                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 
    185246 
    186         pm_power_off = nas100d_power_off; 
    187  
    188247        i2c_register_board_info(0, nas100d_i2c_board_info, 
    189248                                ARRAY_SIZE(nas100d_i2c_board_info)); 
    190249 
    static void __init nas100d_init(void) 
    197256 
    198257        platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices)); 
    199258 
     259        pm_power_off = nas100d_power_off; 
     260 
     261        if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler, 
     262                IRQF_DISABLED | IRQF_TRIGGER_LOW, 
     263                "NAS100D reset button", NULL) < 0) { 
     264 
     265                printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
     266                        gpio_to_irq(NAS100D_RB_GPIO)); 
     267        } 
     268 
     269        /* The power button on the Iomega NAS100d is on GPIO 14, but 
     270         * it cannot handle interrupts on that GPIO line.  So we'll 
     271         * have to poll it with a kernel timer. 
     272         */ 
     273 
     274        /* Make sure that the power button GPIO is set up as an input */ 
     275        gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN); 
     276 
     277        /* Set the initial value for the power button IRQ handler */ 
     278        power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
     279 
     280        mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 
     281 
    200282        /* 
    201283         * Map in a portion of the flash and read the MAC address. 
    202284         * Since it is stored in BE in the flash itself, we need to 
  • deleted file linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/dsmg600-power.c

    + -  
    1 /* 
    2  * arch/arm/mach-ixp4xx/dsmg600-power.c 
    3  * 
    4  * DSM-G600 Power/Reset driver 
    5  * Author: Michael Westerhof <mwester@dls.net> 
    6  * 
    7  * Based on nslu2-power.c 
    8  *  Copyright (C) 2005 Tower Technologies 
    9  *  Author: Alessandro Zummo <a.zummo@towertech.it> 
    10  * 
    11  * which was based on nslu2-io.c 
    12  *  Copyright (C) 2004 Karen Spearel 
    13  * 
    14  * Maintainers: http://www.nslu2-linux.org/ 
    15  * 
    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. 
    19  * 
    20  */ 
    21  
    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> 
    28  
    29 #include <asm/gpio.h> 
    30 #include <asm/mach-types.h> 
    31  
    32 /* This is used to make sure the power-button pusher is serious.  The button 
    33  * must be held until the value of this counter reaches zero. 
    34  */ 
    35 static int power_button_countdown; 
    36  
    37 /* Must hold the button down for at least this many counts to be processed */ 
    38 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */ 
    39  
    40 static void dsmg600_power_handler(unsigned long data); 
    41 static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0); 
    42  
    43 static void dsmg600_power_handler(unsigned long data) 
    44 { 
    45         /* This routine is called twice per second to check the 
    46          * state of the power button. 
    47          */ 
    48  
    49         if (gpio_get_value(DSMG600_PB_GPIO)) { 
    50  
    51                 /* IO Pin is 1 (button pushed) */ 
    52                 if (power_button_countdown > 0) 
    53                         power_button_countdown--; 
    54  
    55         } else { 
    56  
    57                 /* Done on button release, to allow for auto-power-on mods. */ 
    58                 if (power_button_countdown == 0) { 
    59                         /* Signal init to do the ctrlaltdel action, 
    60                          * this will bypass init if it hasn't started 
    61                          * and do a kernel_restart. 
    62                          */ 
    63                         ctrl_alt_del(); 
    64  
    65                         /* Change the state of the power LED to "blink" */ 
    66                         gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 
    67                 } else { 
    68                         power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
    69                 } 
    70         } 
    71  
    72         mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 
    73 } 
    74  
    75 static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id) 
    76 { 
    77         /* This is the paper-clip reset, it shuts the machine down directly. */ 
    78         machine_power_off(); 
    79  
    80         return IRQ_HANDLED; 
    81 } 
    82  
    83 static int __init dsmg600_power_init(void) 
    84 { 
    85         if (!(machine_is_dsmg600())) 
    86                 return 0; 
    87  
    88         if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler, 
    89                 IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button", 
    90                 NULL) < 0) { 
    91  
    92                 printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
    93                         gpio_to_irq(DSMG600_RB_GPIO)); 
    94  
    95                 return -EIO; 
    96         } 
    97  
    98         /* The power button on the D-Link DSM-G600 is on GPIO 15, but 
    99          * it cannot handle interrupts on that GPIO line.  So we'll 
    100          * have to poll it with a kernel timer. 
    101          */ 
    102  
    103         /* Make sure that the power button GPIO is set up as an input */ 
    104         gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN); 
    105  
    106         /* Set the initial value for the power button IRQ handler */ 
    107         power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
    108  
    109         mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 
    110  
    111         return 0; 
    112 } 
    113  
    114 static void __exit dsmg600_power_exit(void) 
    115 { 
    116         if (!(machine_is_dsmg600())) 
    117                 return; 
    118  
    119         del_timer_sync(&dsmg600_power_timer); 
    120  
    121         free_irq(gpio_to_irq(DSMG600_RB_GPIO), NULL); 
    122 } 
    123  
    124 module_init(dsmg600_power_init); 
    125 module_exit(dsmg600_power_exit); 
    126  
    127 MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>"); 
    128 MODULE_DESCRIPTION("DSM-G600 Power/Reset driver"); 
    129 MODULE_LICENSE("GPL"); 
  • arch/arm/mach-ixp4xx/dsmg600-setup.c

    old new  
    11/* 
    22 * DSM-G600 board-setup 
    33 * 
     4 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> 
    45 * Copyright (C) 2006 Tower Technologies 
    5  * Author: Alessandro Zummo <a.zummo@towertech.it> 
    66 * 
    7  * based ixdp425-setup.c: 
     7 * based on ixdp425-setup.c: 
    88 *      Copyright (C) 2003-2004 MontaVista Software, Inc. 
     9 * based on nslu2-power.c: 
     10 *      Copyright (C) 2005 Tower Technologies 
     11 * based on nslu2-io.c: 
     12 *      Copyright (C) 2004 Karen Spearel 
    913 * 
    1014 * Author: Alessandro Zummo <a.zummo@towertech.it> 
     15 * Author: Michael Westerhof <mwester@dls.net> 
     16 * Author: Rod Whitby <rod@whitby.id.au> 
    1117 * Maintainers: http://www.nslu2-linux.org/ 
    1218 */ 
    1319 
    14 #include <linux/kernel.h> 
     20#include <linux/irq.h> 
     21#include <linux/jiffies.h> 
     22#include <linux/timer.h> 
    1523#include <linux/serial.h> 
    1624#include <linux/serial_8250.h> 
    1725#include <linux/leds.h> 
     26#include <linux/reboot.h> 
    1827#include <linux/i2c.h> 
    1928#include <linux/i2c-gpio.h> 
    2029 
     
    2231#include <asm/mach/arch.h> 
    2332#include <asm/mach/flash.h> 
    2433#include <asm/mach/time.h> 
     34#include <asm/gpio.h> 
    2535 
    2636static struct flash_platform_data dsmg600_flash_data = { 
    2737        .map_name               = "cfi_probe", 
    static void dsmg600_power_off(void) 
    140150        gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH); 
    141151} 
    142152 
     153/* This is used to make sure the power-button pusher is serious.  The button 
     154 * must be held until the value of this counter reaches zero. 
     155 */ 
     156static int power_button_countdown; 
     157 
     158/* Must hold the button down for at least this many counts to be processed */ 
     159#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */ 
     160 
     161static void dsmg600_power_handler(unsigned long data); 
     162static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0); 
     163 
     164static void dsmg600_power_handler(unsigned long data) 
     165{ 
     166        /* This routine is called twice per second to check the 
     167         * state of the power button. 
     168         */ 
     169 
     170        if (gpio_get_value(DSMG600_PB_GPIO)) { 
     171 
     172                /* IO Pin is 1 (button pushed) */ 
     173                if (power_button_countdown > 0) 
     174                        power_button_countdown--; 
     175 
     176        } else { 
     177 
     178                /* Done on button release, to allow for auto-power-on mods. */ 
     179                if (power_button_countdown == 0) { 
     180                        /* Signal init to do the ctrlaltdel action, 
     181                         * this will bypass init if it hasn't started 
     182                         * and do a kernel_restart. 
     183                         */ 
     184                        ctrl_alt_del(); 
     185 
     186                        /* Change the state of the power LED to "blink" */ 
     187                        gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 
     188                } else { 
     189                        power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
     190                } 
     191        } 
     192 
     193        mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 
     194} 
     195 
     196static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id) 
     197{ 
     198        /* This is the paper-clip reset, it shuts the machine down directly. */ 
     199        machine_power_off(); 
     200 
     201        return IRQ_HANDLED; 
     202} 
     203 
    143204static void __init dsmg600_timer_init(void) 
    144205{ 
    145206    /* The xtal on this machine is non-standard. */ 
    static void __init dsmg600_init(void) 
    164225        dsmg600_flash_resource.end = 
    165226                IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 
    166227 
    167         pm_power_off = dsmg600_power_off; 
    168  
    169228        i2c_register_board_info(0, dsmg600_i2c_board_info, 
    170229                                ARRAY_SIZE(dsmg600_i2c_board_info)); 
    171230 
    static void __init dsmg600_init(void) 
    176235        (void)platform_device_register(&dsmg600_uart); 
    177236 
    178237        platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices)); 
     238 
     239        pm_power_off = dsmg600_power_off; 
     240 
     241        if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler, 
     242                IRQF_DISABLED | IRQF_TRIGGER_LOW, 
     243                "DSM-G600 reset button", NULL) < 0) { 
     244 
     245                printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 
     246                        gpio_to_irq(DSMG600_RB_GPIO)); 
     247        } 
     248 
     249        /* The power button on the D-Link DSM-G600 is on GPIO 15, but 
     250         * it cannot handle interrupts on that GPIO line.  So we'll 
     251         * have to poll it with a kernel timer. 
     252         */ 
     253 
     254        /* Make sure that the power button GPIO is set up as an input */ 
     255        gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN); 
     256 
     257        /* Set the initial value for the power button IRQ handler */ 
     258        power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 
     259 
     260        mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 
    179261} 
    180262 
    181263MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")