Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ixp4xx/nas100d-setup.c |
| 3 | * |
| 4 | * NAS 100d board-setup |
| 5 | * |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 6 | * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> |
| 7 | * |
| 8 | * based on ixdp425-setup.c: |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 9 | * Copyright (C) 2003-2004 MontaVista Software, Inc. |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 10 | * based on nas100d-power.c: |
| 11 | * Copyright (C) 2005 Tower Technologies |
| 12 | * based on nas100d-io.c |
| 13 | * Copyright (C) 2004 Karen Spearel |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 14 | * |
| 15 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
| 16 | * Author: Rod Whitby <rod@whitby.id.au> |
| 17 | * Maintainers: http://www.nslu2-linux.org/ |
| 18 | * |
| 19 | */ |
| 20 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 21 | #include <linux/if_ether.h> |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 22 | #include <linux/irq.h> |
| 23 | #include <linux/jiffies.h> |
| 24 | #include <linux/timer.h> |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 25 | #include <linux/serial.h> |
| 26 | #include <linux/serial_8250.h> |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 27 | #include <linux/leds.h> |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 28 | #include <linux/reboot.h> |
Rod Whitby | 400d823 | 2008-01-29 00:38:44 +0100 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 30 | #include <linux/i2c-gpio.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 31 | #include <linux/io.h> |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 32 | |
| 33 | #include <asm/mach-types.h> |
| 34 | #include <asm/mach/arch.h> |
| 35 | #include <asm/mach/flash.h> |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 36 | #include <asm/gpio.h> |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 37 | |
| 38 | static struct flash_platform_data nas100d_flash_data = { |
| 39 | .map_name = "cfi_probe", |
| 40 | .width = 2, |
| 41 | }; |
| 42 | |
| 43 | static struct resource nas100d_flash_resource = { |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 44 | .flags = IORESOURCE_MEM, |
| 45 | }; |
| 46 | |
| 47 | static struct platform_device nas100d_flash = { |
| 48 | .name = "IXP4XX-Flash", |
| 49 | .id = 0, |
| 50 | .dev.platform_data = &nas100d_flash_data, |
| 51 | .num_resources = 1, |
| 52 | .resource = &nas100d_flash_resource, |
| 53 | }; |
| 54 | |
Rod Whitby | 400d823 | 2008-01-29 00:38:44 +0100 | [diff] [blame] | 55 | static struct i2c_board_info __initdata nas100d_i2c_board_info [] = { |
| 56 | { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 57 | I2C_BOARD_INFO("pcf8563", 0x51), |
Rod Whitby | 400d823 | 2008-01-29 00:38:44 +0100 | [diff] [blame] | 58 | }, |
| 59 | }; |
| 60 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 61 | static struct gpio_led nas100d_led_pins[] = { |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 62 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 63 | .name = "nas100d:green:wlan", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 64 | .gpio = NAS100D_LED_WLAN_GPIO, |
| 65 | .active_low = true, |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 66 | }, |
| 67 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 68 | .name = "nas100d:blue:power", /* (off=flashing) */ |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 69 | .gpio = NAS100D_LED_PWR_GPIO, |
| 70 | .active_low = true, |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 71 | }, |
| 72 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 73 | .name = "nas100d:yellow:disk", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 74 | .gpio = NAS100D_LED_DISK_GPIO, |
| 75 | .active_low = true, |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 76 | }, |
| 77 | }; |
| 78 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 79 | static struct gpio_led_platform_data nas100d_led_data = { |
| 80 | .num_leds = ARRAY_SIZE(nas100d_led_pins), |
| 81 | .leds = nas100d_led_pins, |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 82 | }; |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 83 | |
| 84 | static struct platform_device nas100d_leds = { |
| 85 | .name = "leds-gpio", |
| 86 | .id = -1, |
| 87 | .dev.platform_data = &nas100d_led_data, |
| 88 | }; |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 89 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 90 | static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 91 | .sda_pin = NAS100D_SDA_PIN, |
| 92 | .scl_pin = NAS100D_SCL_PIN, |
| 93 | }; |
| 94 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 95 | static struct platform_device nas100d_i2c_gpio = { |
| 96 | .name = "i2c-gpio", |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 97 | .id = 0, |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 98 | .dev = { |
| 99 | .platform_data = &nas100d_i2c_gpio_data, |
| 100 | }, |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static struct resource nas100d_uart_resources[] = { |
| 104 | { |
| 105 | .start = IXP4XX_UART1_BASE_PHYS, |
| 106 | .end = IXP4XX_UART1_BASE_PHYS + 0x0fff, |
| 107 | .flags = IORESOURCE_MEM, |
| 108 | }, |
| 109 | { |
| 110 | .start = IXP4XX_UART2_BASE_PHYS, |
| 111 | .end = IXP4XX_UART2_BASE_PHYS + 0x0fff, |
| 112 | .flags = IORESOURCE_MEM, |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | static struct plat_serial8250_port nas100d_uart_data[] = { |
| 117 | { |
| 118 | .mapbase = IXP4XX_UART1_BASE_PHYS, |
| 119 | .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET, |
| 120 | .irq = IRQ_IXP4XX_UART1, |
| 121 | .flags = UPF_BOOT_AUTOCONF, |
| 122 | .iotype = UPIO_MEM, |
| 123 | .regshift = 2, |
| 124 | .uartclk = IXP4XX_UART_XTAL, |
| 125 | }, |
| 126 | { |
| 127 | .mapbase = IXP4XX_UART2_BASE_PHYS, |
| 128 | .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, |
| 129 | .irq = IRQ_IXP4XX_UART2, |
| 130 | .flags = UPF_BOOT_AUTOCONF, |
| 131 | .iotype = UPIO_MEM, |
| 132 | .regshift = 2, |
| 133 | .uartclk = IXP4XX_UART_XTAL, |
| 134 | }, |
| 135 | { } |
| 136 | }; |
| 137 | |
| 138 | static struct platform_device nas100d_uart = { |
| 139 | .name = "serial8250", |
| 140 | .id = PLAT8250_DEV_PLATFORM, |
| 141 | .dev.platform_data = nas100d_uart_data, |
| 142 | .num_resources = 2, |
| 143 | .resource = nas100d_uart_resources, |
| 144 | }; |
| 145 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 146 | /* Built-in 10/100 Ethernet MAC interfaces */ |
| 147 | static struct eth_plat_info nas100d_plat_eth[] = { |
| 148 | { |
| 149 | .phy = 0, |
| 150 | .rxq = 3, |
| 151 | .txreadyq = 20, |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | static struct platform_device nas100d_eth[] = { |
| 156 | { |
| 157 | .name = "ixp4xx_eth", |
| 158 | .id = IXP4XX_ETH_NPEB, |
| 159 | .dev.platform_data = nas100d_plat_eth, |
| 160 | } |
| 161 | }; |
| 162 | |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 163 | static struct platform_device *nas100d_devices[] __initdata = { |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 164 | &nas100d_i2c_gpio, |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 165 | &nas100d_flash, |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 166 | &nas100d_leds, |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 167 | &nas100d_eth[0], |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | static void nas100d_power_off(void) |
| 171 | { |
| 172 | /* This causes the box to drop the power and go dead. */ |
| 173 | |
| 174 | /* enable the pwr cntl gpio */ |
| 175 | gpio_line_config(NAS100D_PO_GPIO, IXP4XX_GPIO_OUT); |
| 176 | |
| 177 | /* do the deed */ |
| 178 | gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH); |
| 179 | } |
| 180 | |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 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 | */ |
| 184 | static 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 | |
| 189 | static void nas100d_power_handler(unsigned long data); |
| 190 | static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0); |
| 191 | |
| 192 | static 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 | |
| 224 | static 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 | |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 232 | static void __init nas100d_init(void) |
| 233 | { |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 234 | uint8_t __iomem *f; |
| 235 | int i; |
| 236 | |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 237 | ixp4xx_sys_init(); |
| 238 | |
Alessandro Zummo | dcc8fa5 | 2006-03-08 23:45:10 +0000 | [diff] [blame] | 239 | /* gpio 14 and 15 are _not_ clocks */ |
| 240 | *IXP4XX_GPIO_GPCLKR = 0; |
| 241 | |
Deepak Saxena | 54e269e | 2006-01-05 20:59:29 +0000 | [diff] [blame] | 242 | nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); |
| 243 | nas100d_flash_resource.end = |
| 244 | IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; |
| 245 | |
Rod Whitby | 400d823 | 2008-01-29 00:38:44 +0100 | [diff] [blame] | 246 | i2c_register_board_info(0, nas100d_i2c_board_info, |
| 247 | ARRAY_SIZE(nas100d_i2c_board_info)); |
| 248 | |
Michael-Luke Jones | cc50a0d | 2007-05-23 22:41:53 +0100 | [diff] [blame] | 249 | /* |
| 250 | * This is only useful on a modified machine, but it is valuable |
Rod Whitby | df6934b | 2006-06-22 22:21:01 +0100 | [diff] [blame] | 251 | * to have it first in order to see debug messages, and so that |
| 252 | * it does *not* get removed if platform_add_devices fails! |
| 253 | */ |
| 254 | (void)platform_device_register(&nas100d_uart); |
| 255 | |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 256 | platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices)); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 257 | |
Rod Whitby | c7d1623 | 2008-02-03 12:05:49 +0100 | [diff] [blame] | 258 | pm_power_off = nas100d_power_off; |
| 259 | |
| 260 | if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler, |
| 261 | IRQF_DISABLED | IRQF_TRIGGER_LOW, |
| 262 | "NAS100D reset button", NULL) < 0) { |
| 263 | |
| 264 | printk(KERN_DEBUG "Reset Button IRQ %d not available\n", |
| 265 | gpio_to_irq(NAS100D_RB_GPIO)); |
| 266 | } |
| 267 | |
| 268 | /* The power button on the Iomega NAS100d is on GPIO 14, but |
| 269 | * it cannot handle interrupts on that GPIO line. So we'll |
| 270 | * have to poll it with a kernel timer. |
| 271 | */ |
| 272 | |
| 273 | /* Make sure that the power button GPIO is set up as an input */ |
| 274 | gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN); |
| 275 | |
| 276 | /* Set the initial value for the power button IRQ handler */ |
| 277 | power_button_countdown = PBUTTON_HOLDDOWN_COUNT; |
| 278 | |
| 279 | mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); |
| 280 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 281 | /* |
| 282 | * Map in a portion of the flash and read the MAC address. |
| 283 | * Since it is stored in BE in the flash itself, we need to |
| 284 | * byteswap it if we're in LE mode. |
| 285 | */ |
| 286 | f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000); |
| 287 | if (f) { |
| 288 | for (i = 0; i < 6; i++) |
| 289 | #ifdef __ARMEB__ |
| 290 | nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i); |
| 291 | #else |
| 292 | nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3)); |
| 293 | #endif |
| 294 | iounmap(f); |
| 295 | } |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 296 | printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n", |
| 297 | nas100d_plat_eth[0].hwaddr); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 298 | |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | MACHINE_START(NAS100D, "Iomega NAS 100d") |
| 302 | /* Maintainer: www.nslu2-linux.org */ |
Rod Whitby | 3145d8a | 2006-01-04 17:17:11 +0000 | [diff] [blame] | 303 | .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS, |
| 304 | .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xFFFC, |
| 305 | .boot_params = 0x00000100, |
| 306 | .map_io = ixp4xx_map_io, |
| 307 | .init_irq = ixp4xx_init_irq, |
| 308 | .timer = &ixp4xx_timer, |
| 309 | .init_machine = nas100d_init, |
| 310 | MACHINE_END |