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