Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/leds.h> |
Aurelien Jarno | 0788150 | 2008-02-07 03:17:16 +0100 | [diff] [blame] | 12 | #include <linux/mtd/physmap.h> |
Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 13 | #include <linux/ssb/ssb.h> |
Aurelien Jarno | 89f8c04 | 2008-10-14 11:44:43 +0200 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/reboot.h> |
| 16 | #include <linux/gpio.h> |
Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 17 | #include <asm/mach-bcm47xx/bcm47xx.h> |
| 18 | |
| 19 | /* GPIO definitions for the WGT634U */ |
| 20 | #define WGT634U_GPIO_LED 3 |
| 21 | #define WGT634U_GPIO_RESET 2 |
| 22 | #define WGT634U_GPIO_TP1 7 |
| 23 | #define WGT634U_GPIO_TP2 6 |
| 24 | #define WGT634U_GPIO_TP3 5 |
| 25 | #define WGT634U_GPIO_TP4 4 |
| 26 | #define WGT634U_GPIO_TP5 1 |
| 27 | |
| 28 | static struct gpio_led wgt634u_leds[] = { |
| 29 | { |
| 30 | .name = "power", |
| 31 | .gpio = WGT634U_GPIO_LED, |
| 32 | .active_low = 1, |
| 33 | .default_trigger = "heartbeat", |
| 34 | }, |
| 35 | }; |
| 36 | |
| 37 | static struct gpio_led_platform_data wgt634u_led_data = { |
| 38 | .num_leds = ARRAY_SIZE(wgt634u_leds), |
| 39 | .leds = wgt634u_leds, |
| 40 | }; |
| 41 | |
| 42 | static struct platform_device wgt634u_gpio_leds = { |
| 43 | .name = "leds-gpio", |
| 44 | .id = -1, |
| 45 | .dev = { |
| 46 | .platform_data = &wgt634u_led_data, |
| 47 | } |
| 48 | }; |
| 49 | |
Aurelien Jarno | 0788150 | 2008-02-07 03:17:16 +0100 | [diff] [blame] | 50 | |
| 51 | /* 8MiB flash. The struct mtd_partition matches original Netgear WGT634U |
| 52 | firmware. */ |
| 53 | static struct mtd_partition wgt634u_partitions[] = { |
| 54 | { |
| 55 | .name = "cfe", |
| 56 | .offset = 0, |
| 57 | .size = 0x60000, /* 384k */ |
| 58 | .mask_flags = MTD_WRITEABLE /* force read-only */ |
| 59 | }, |
| 60 | { |
| 61 | .name = "config", |
| 62 | .offset = 0x60000, |
| 63 | .size = 0x20000 /* 128k */ |
| 64 | }, |
| 65 | { |
| 66 | .name = "linux", |
| 67 | .offset = 0x80000, |
| 68 | .size = 0x140000 /* 1280k */ |
| 69 | }, |
| 70 | { |
| 71 | .name = "jffs", |
| 72 | .offset = 0x1c0000, |
| 73 | .size = 0x620000 /* 6272k */ |
| 74 | }, |
| 75 | { |
| 76 | .name = "nvram", |
| 77 | .offset = 0x7e0000, |
| 78 | .size = 0x20000 /* 128k */ |
| 79 | }, |
| 80 | }; |
| 81 | |
| 82 | static struct physmap_flash_data wgt634u_flash_data = { |
| 83 | .parts = wgt634u_partitions, |
| 84 | .nr_parts = ARRAY_SIZE(wgt634u_partitions) |
| 85 | }; |
| 86 | |
| 87 | static struct resource wgt634u_flash_resource = { |
| 88 | .flags = IORESOURCE_MEM, |
| 89 | }; |
| 90 | |
| 91 | static struct platform_device wgt634u_flash = { |
| 92 | .name = "physmap-flash", |
| 93 | .id = 0, |
| 94 | .dev = { .platform_data = &wgt634u_flash_data, }, |
| 95 | .resource = &wgt634u_flash_resource, |
| 96 | .num_resources = 1, |
| 97 | }; |
| 98 | |
| 99 | /* Platform devices */ |
| 100 | static struct platform_device *wgt634u_devices[] __initdata = { |
| 101 | &wgt634u_flash, |
| 102 | &wgt634u_gpio_leds, |
| 103 | }; |
| 104 | |
Aurelien Jarno | 89f8c04 | 2008-10-14 11:44:43 +0200 | [diff] [blame] | 105 | static irqreturn_t gpio_interrupt(int irq, void *ignored) |
| 106 | { |
| 107 | int state; |
| 108 | |
| 109 | /* Interrupts are shared, check if the current one is |
| 110 | a GPIO interrupt. */ |
| 111 | if (!ssb_chipco_irq_status(&ssb_bcm47xx.chipco, |
| 112 | SSB_CHIPCO_IRQ_GPIO)) |
| 113 | return IRQ_NONE; |
| 114 | |
| 115 | state = gpio_get_value(WGT634U_GPIO_RESET); |
| 116 | |
| 117 | /* Interrupt are level triggered, revert the interrupt polarity |
| 118 | to clear the interrupt. */ |
| 119 | gpio_polarity(WGT634U_GPIO_RESET, state); |
| 120 | |
| 121 | if (!state) { |
| 122 | printk(KERN_INFO "Reset button pressed"); |
| 123 | ctrl_alt_del(); |
| 124 | } |
| 125 | |
| 126 | return IRQ_HANDLED; |
| 127 | } |
| 128 | |
Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 129 | static int __init wgt634u_init(void) |
| 130 | { |
| 131 | /* There is no easy way to detect that we are running on a WGT634U |
| 132 | * machine. Use the MAC address as an heuristic. Netgear Inc. has |
| 133 | * been allocated ranges 00:09:5b:xx:xx:xx and 00:0f:b5:xx:xx:xx. |
| 134 | */ |
| 135 | |
Aurelien Jarno | cc2d6f7 | 2008-02-18 11:04:31 +0100 | [diff] [blame] | 136 | u8 *et0mac = ssb_bcm47xx.sprom.et0mac; |
Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 137 | |
| 138 | if (et0mac[0] == 0x00 && |
| 139 | ((et0mac[1] == 0x09 && et0mac[2] == 0x5b) || |
Aurelien Jarno | 0788150 | 2008-02-07 03:17:16 +0100 | [diff] [blame] | 140 | (et0mac[1] == 0x0f && et0mac[2] == 0xb5))) { |
| 141 | struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore; |
Aurelien Jarno | 91a385b | 2008-10-14 11:42:10 +0200 | [diff] [blame] | 142 | |
| 143 | printk(KERN_INFO "WGT634U machine detected.\n"); |
| 144 | |
Aurelien Jarno | 89f8c04 | 2008-10-14 11:44:43 +0200 | [diff] [blame] | 145 | if (!request_irq(gpio_to_irq(WGT634U_GPIO_RESET), |
| 146 | gpio_interrupt, IRQF_SHARED, |
| 147 | "WGT634U GPIO", &ssb_bcm47xx.chipco)) { |
| 148 | gpio_direction_input(WGT634U_GPIO_RESET); |
| 149 | gpio_intmask(WGT634U_GPIO_RESET, 1); |
| 150 | ssb_chipco_irq_mask(&ssb_bcm47xx.chipco, |
| 151 | SSB_CHIPCO_IRQ_GPIO, |
| 152 | SSB_CHIPCO_IRQ_GPIO); |
| 153 | } |
| 154 | |
Aurelien Jarno | 0788150 | 2008-02-07 03:17:16 +0100 | [diff] [blame] | 155 | wgt634u_flash_data.width = mcore->flash_buswidth; |
| 156 | wgt634u_flash_resource.start = mcore->flash_window; |
| 157 | wgt634u_flash_resource.end = mcore->flash_window |
| 158 | + mcore->flash_window_size |
| 159 | - 1; |
| 160 | return platform_add_devices(wgt634u_devices, |
| 161 | ARRAY_SIZE(wgt634u_devices)); |
| 162 | } else |
Aurelien Jarno | 21c854d | 2007-09-25 15:43:07 +0200 | [diff] [blame] | 163 | return -ENODEV; |
| 164 | } |
| 165 | |
| 166 | module_init(wgt634u_init); |
| 167 | |