Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ixp4xx/nslu2-setup.c |
| 3 | * |
| 4 | * NSLU2 board-setup |
| 5 | * |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 6 | * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> |
| 7 | * |
| 8 | * based on ixdp425-setup.c: |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 9 | * Copyright (C) 2003-2004 MontaVista Software, Inc. |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 10 | * based on nslu2-power.c: |
| 11 | * Copyright (C) 2005 Tower Technologies |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 12 | * |
| 13 | * Author: Mark Rakes <mrakes at mac.com> |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 14 | * Author: Rod Whitby <rod@whitby.id.au> |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 15 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 16 | * Maintainers: http://www.nslu2-linux.org/ |
| 17 | * |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 20 | #include <linux/if_ether.h> |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 21 | #include <linux/irq.h> |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 22 | #include <linux/serial.h> |
| 23 | #include <linux/serial_8250.h> |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 24 | #include <linux/leds.h> |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 25 | #include <linux/reboot.h> |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 26 | #include <linux/i2c.h> |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 27 | #include <linux/i2c-gpio.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 29 | |
| 30 | #include <asm/mach-types.h> |
| 31 | #include <asm/mach/arch.h> |
| 32 | #include <asm/mach/flash.h> |
Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 33 | #include <asm/mach/time.h> |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 34 | #include <asm/gpio.h> |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 35 | |
| 36 | static struct flash_platform_data nslu2_flash_data = { |
| 37 | .map_name = "cfi_probe", |
| 38 | .width = 2, |
| 39 | }; |
| 40 | |
| 41 | static struct resource nslu2_flash_resource = { |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 42 | .flags = IORESOURCE_MEM, |
| 43 | }; |
| 44 | |
| 45 | static struct platform_device nslu2_flash = { |
| 46 | .name = "IXP4XX-Flash", |
| 47 | .id = 0, |
| 48 | .dev.platform_data = &nslu2_flash_data, |
| 49 | .num_resources = 1, |
| 50 | .resource = &nslu2_flash_resource, |
| 51 | }; |
| 52 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 53 | static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 54 | .sda_pin = NSLU2_SDA_PIN, |
| 55 | .scl_pin = NSLU2_SCL_PIN, |
| 56 | }; |
| 57 | |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 58 | static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { |
| 59 | { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 60 | I2C_BOARD_INFO("x1205", 0x6f), |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 61 | }, |
| 62 | }; |
| 63 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 64 | static struct gpio_led nslu2_led_pins[] = { |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 65 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 66 | .name = "nslu2:green:ready", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 67 | .gpio = NSLU2_LED_GRN_GPIO, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 68 | }, |
| 69 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 70 | .name = "nslu2:red:status", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 71 | .gpio = NSLU2_LED_RED_GPIO, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 72 | }, |
| 73 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 74 | .name = "nslu2:green:disk-1", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 75 | .gpio = NSLU2_LED_DISK1_GPIO, |
| 76 | .active_low = true, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 77 | }, |
| 78 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 79 | .name = "nslu2:green:disk-2", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 80 | .gpio = NSLU2_LED_DISK2_GPIO, |
| 81 | .active_low = true, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 82 | }, |
| 83 | }; |
| 84 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 85 | static struct gpio_led_platform_data nslu2_led_data = { |
| 86 | .num_leds = ARRAY_SIZE(nslu2_led_pins), |
| 87 | .leds = nslu2_led_pins, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 88 | }; |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 89 | |
| 90 | static struct platform_device nslu2_leds = { |
| 91 | .name = "leds-gpio", |
| 92 | .id = -1, |
| 93 | .dev.platform_data = &nslu2_led_data, |
| 94 | }; |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 95 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 96 | static struct platform_device nslu2_i2c_gpio = { |
| 97 | .name = "i2c-gpio", |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 98 | .id = 0, |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 99 | .dev = { |
| 100 | .platform_data = &nslu2_i2c_gpio_data, |
| 101 | }, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Alessandro Zummo | bc66d44 | 2006-02-22 21:12:06 +0000 | [diff] [blame] | 104 | static struct platform_device nslu2_beeper = { |
| 105 | .name = "ixp4xx-beeper", |
| 106 | .id = NSLU2_GPIO_BUZZ, |
| 107 | .num_resources = 0, |
| 108 | }; |
| 109 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 110 | static struct resource nslu2_uart_resources[] = { |
| 111 | { |
| 112 | .start = IXP4XX_UART1_BASE_PHYS, |
| 113 | .end = IXP4XX_UART1_BASE_PHYS + 0x0fff, |
| 114 | .flags = IORESOURCE_MEM, |
| 115 | }, |
| 116 | { |
| 117 | .start = IXP4XX_UART2_BASE_PHYS, |
| 118 | .end = IXP4XX_UART2_BASE_PHYS + 0x0fff, |
| 119 | .flags = IORESOURCE_MEM, |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | static struct plat_serial8250_port nslu2_uart_data[] = { |
| 124 | { |
| 125 | .mapbase = IXP4XX_UART1_BASE_PHYS, |
| 126 | .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET, |
| 127 | .irq = IRQ_IXP4XX_UART1, |
| 128 | .flags = UPF_BOOT_AUTOCONF, |
| 129 | .iotype = UPIO_MEM, |
| 130 | .regshift = 2, |
| 131 | .uartclk = IXP4XX_UART_XTAL, |
| 132 | }, |
| 133 | { |
| 134 | .mapbase = IXP4XX_UART2_BASE_PHYS, |
| 135 | .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, |
| 136 | .irq = IRQ_IXP4XX_UART2, |
| 137 | .flags = UPF_BOOT_AUTOCONF, |
| 138 | .iotype = UPIO_MEM, |
| 139 | .regshift = 2, |
| 140 | .uartclk = IXP4XX_UART_XTAL, |
| 141 | }, |
| 142 | { } |
| 143 | }; |
| 144 | |
| 145 | static struct platform_device nslu2_uart = { |
| 146 | .name = "serial8250", |
| 147 | .id = PLAT8250_DEV_PLATFORM, |
| 148 | .dev.platform_data = nslu2_uart_data, |
| 149 | .num_resources = 2, |
| 150 | .resource = nslu2_uart_resources, |
| 151 | }; |
| 152 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 153 | /* Built-in 10/100 Ethernet MAC interfaces */ |
| 154 | static struct eth_plat_info nslu2_plat_eth[] = { |
| 155 | { |
| 156 | .phy = 1, |
| 157 | .rxq = 3, |
| 158 | .txreadyq = 20, |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | static struct platform_device nslu2_eth[] = { |
| 163 | { |
| 164 | .name = "ixp4xx_eth", |
| 165 | .id = IXP4XX_ETH_NPEB, |
| 166 | .dev.platform_data = nslu2_plat_eth, |
| 167 | } |
| 168 | }; |
| 169 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 170 | static struct platform_device *nslu2_devices[] __initdata = { |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 171 | &nslu2_i2c_gpio, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 172 | &nslu2_flash, |
Alessandro Zummo | bc66d44 | 2006-02-22 21:12:06 +0000 | [diff] [blame] | 173 | &nslu2_beeper, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 174 | &nslu2_leds, |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 175 | &nslu2_eth[0], |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | static void nslu2_power_off(void) |
| 179 | { |
| 180 | /* This causes the box to drop the power and go dead. */ |
| 181 | |
| 182 | /* enable the pwr cntl gpio */ |
| 183 | gpio_line_config(NSLU2_PO_GPIO, IXP4XX_GPIO_OUT); |
| 184 | |
| 185 | /* do the deed */ |
| 186 | gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH); |
| 187 | } |
| 188 | |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 189 | static 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 | |
| 199 | static 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 | |
Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 208 | static void __init nslu2_timer_init(void) |
| 209 | { |
| 210 | /* The xtal on this machine is non-standard. */ |
| 211 | ixp4xx_timer_freq = NSLU2_FREQ; |
| 212 | |
| 213 | /* Call standard timer_init function. */ |
| 214 | ixp4xx_timer_init(); |
| 215 | } |
| 216 | |
| 217 | static struct sys_timer nslu2_timer = { |
| 218 | .init = nslu2_timer_init, |
| 219 | }; |
| 220 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 221 | static void __init nslu2_init(void) |
| 222 | { |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 223 | uint8_t __iomem *f; |
| 224 | int i; |
| 225 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 226 | ixp4xx_sys_init(); |
| 227 | |
Martin Michlmayr | 3dfaf7a | 2006-02-16 22:36:12 +0000 | [diff] [blame] | 228 | nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); |
| 229 | nslu2_flash_resource.end = |
| 230 | IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; |
| 231 | |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 232 | i2c_register_board_info(0, nslu2_i2c_board_info, |
| 233 | ARRAY_SIZE(nslu2_i2c_board_info)); |
| 234 | |
Michael-Luke Jones | cc50a0d | 2007-05-23 22:41:53 +0100 | [diff] [blame] | 235 | /* |
| 236 | * This is only useful on a modified machine, but it is valuable |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 237 | * to have it first in order to see debug messages, and so that |
| 238 | * it does *not* get removed if platform_add_devices fails! |
| 239 | */ |
| 240 | (void)platform_device_register(&nslu2_uart); |
| 241 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 242 | platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices)); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 243 | |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 244 | pm_power_off = nslu2_power_off; |
| 245 | |
| 246 | if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler, |
| 247 | IRQF_DISABLED | IRQF_TRIGGER_LOW, |
| 248 | "NSLU2 reset button", NULL) < 0) { |
| 249 | |
| 250 | printk(KERN_DEBUG "Reset Button IRQ %d not available\n", |
| 251 | gpio_to_irq(NSLU2_RB_GPIO)); |
| 252 | } |
| 253 | |
| 254 | if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler, |
| 255 | IRQF_DISABLED | IRQF_TRIGGER_HIGH, |
| 256 | "NSLU2 power button", NULL) < 0) { |
| 257 | |
| 258 | printk(KERN_DEBUG "Power Button IRQ %d not available\n", |
| 259 | gpio_to_irq(NSLU2_PB_GPIO)); |
| 260 | } |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * Map in a portion of the flash and read the MAC address. |
| 264 | * Since it is stored in BE in the flash itself, we need to |
| 265 | * byteswap it if we're in LE mode. |
| 266 | */ |
| 267 | f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000); |
| 268 | if (f) { |
| 269 | for (i = 0; i < 6; i++) |
| 270 | #ifdef __ARMEB__ |
| 271 | nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i); |
| 272 | #else |
| 273 | nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3)); |
| 274 | #endif |
| 275 | iounmap(f); |
| 276 | } |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 277 | printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n", |
| 278 | nslu2_plat_eth[0].hwaddr); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 279 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | MACHINE_START(NSLU2, "Linksys NSLU2") |
| 283 | /* Maintainer: www.nslu2-linux.org */ |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 284 | .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS, |
| 285 | .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xFFFC, |
| 286 | .boot_params = 0x00000100, |
| 287 | .map_io = ixp4xx_map_io, |
| 288 | .init_irq = ixp4xx_init_irq, |
Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 289 | .timer = &nslu2_timer, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 290 | .init_machine = nslu2_init, |
| 291 | MACHINE_END |