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 | */ |
Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
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 | #include <asm/mach-types.h> |
| 30 | #include <asm/mach/arch.h> |
| 31 | #include <asm/mach/flash.h> |
Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 32 | #include <asm/mach/time.h> |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 33 | |
Krzysztof HaĆasa | c1117c6 | 2009-11-16 16:02:02 +0100 | [diff] [blame] | 34 | #define NSLU2_SDA_PIN 7 |
| 35 | #define NSLU2_SCL_PIN 6 |
| 36 | |
| 37 | /* NSLU2 Timer */ |
| 38 | #define NSLU2_FREQ 66000000 |
| 39 | |
| 40 | /* Buttons */ |
| 41 | #define NSLU2_PB_GPIO 5 /* power button */ |
| 42 | #define NSLU2_PO_GPIO 8 /* power off */ |
| 43 | #define NSLU2_RB_GPIO 12 /* reset button */ |
| 44 | |
| 45 | /* Buzzer */ |
| 46 | #define NSLU2_GPIO_BUZZ 4 |
| 47 | |
| 48 | /* LEDs */ |
| 49 | #define NSLU2_LED_RED_GPIO 0 |
| 50 | #define NSLU2_LED_GRN_GPIO 1 |
| 51 | #define NSLU2_LED_DISK1_GPIO 3 |
| 52 | #define NSLU2_LED_DISK2_GPIO 2 |
| 53 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 54 | static struct flash_platform_data nslu2_flash_data = { |
| 55 | .map_name = "cfi_probe", |
| 56 | .width = 2, |
| 57 | }; |
| 58 | |
| 59 | static struct resource nslu2_flash_resource = { |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 60 | .flags = IORESOURCE_MEM, |
| 61 | }; |
| 62 | |
| 63 | static struct platform_device nslu2_flash = { |
| 64 | .name = "IXP4XX-Flash", |
| 65 | .id = 0, |
| 66 | .dev.platform_data = &nslu2_flash_data, |
| 67 | .num_resources = 1, |
| 68 | .resource = &nslu2_flash_resource, |
| 69 | }; |
| 70 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 71 | static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 72 | .sda_pin = NSLU2_SDA_PIN, |
| 73 | .scl_pin = NSLU2_SCL_PIN, |
| 74 | }; |
| 75 | |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 76 | static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { |
| 77 | { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 78 | I2C_BOARD_INFO("x1205", 0x6f), |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 79 | }, |
| 80 | }; |
| 81 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 82 | static struct gpio_led nslu2_led_pins[] = { |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 83 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 84 | .name = "nslu2:green:ready", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 85 | .gpio = NSLU2_LED_GRN_GPIO, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 86 | }, |
| 87 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 88 | .name = "nslu2:red:status", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 89 | .gpio = NSLU2_LED_RED_GPIO, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 90 | }, |
| 91 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 92 | .name = "nslu2:green:disk-1", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 93 | .gpio = NSLU2_LED_DISK1_GPIO, |
| 94 | .active_low = true, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 95 | }, |
| 96 | { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 97 | .name = "nslu2:green:disk-2", |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 98 | .gpio = NSLU2_LED_DISK2_GPIO, |
| 99 | .active_low = true, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 100 | }, |
| 101 | }; |
| 102 | |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 103 | static struct gpio_led_platform_data nslu2_led_data = { |
| 104 | .num_leds = ARRAY_SIZE(nslu2_led_pins), |
| 105 | .leds = nslu2_led_pins, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 106 | }; |
Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 107 | |
| 108 | static struct platform_device nslu2_leds = { |
| 109 | .name = "leds-gpio", |
| 110 | .id = -1, |
| 111 | .dev.platform_data = &nslu2_led_data, |
| 112 | }; |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 113 | |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 114 | static struct platform_device nslu2_i2c_gpio = { |
| 115 | .name = "i2c-gpio", |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 116 | .id = 0, |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 117 | .dev = { |
| 118 | .platform_data = &nslu2_i2c_gpio_data, |
| 119 | }, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Alessandro Zummo | bc66d44 | 2006-02-22 21:12:06 +0000 | [diff] [blame] | 122 | static struct platform_device nslu2_beeper = { |
| 123 | .name = "ixp4xx-beeper", |
| 124 | .id = NSLU2_GPIO_BUZZ, |
| 125 | .num_resources = 0, |
| 126 | }; |
| 127 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 128 | static struct resource nslu2_uart_resources[] = { |
| 129 | { |
| 130 | .start = IXP4XX_UART1_BASE_PHYS, |
| 131 | .end = IXP4XX_UART1_BASE_PHYS + 0x0fff, |
| 132 | .flags = IORESOURCE_MEM, |
| 133 | }, |
| 134 | { |
| 135 | .start = IXP4XX_UART2_BASE_PHYS, |
| 136 | .end = IXP4XX_UART2_BASE_PHYS + 0x0fff, |
| 137 | .flags = IORESOURCE_MEM, |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | static struct plat_serial8250_port nslu2_uart_data[] = { |
| 142 | { |
| 143 | .mapbase = IXP4XX_UART1_BASE_PHYS, |
| 144 | .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET, |
| 145 | .irq = IRQ_IXP4XX_UART1, |
| 146 | .flags = UPF_BOOT_AUTOCONF, |
| 147 | .iotype = UPIO_MEM, |
| 148 | .regshift = 2, |
| 149 | .uartclk = IXP4XX_UART_XTAL, |
| 150 | }, |
| 151 | { |
| 152 | .mapbase = IXP4XX_UART2_BASE_PHYS, |
| 153 | .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, |
| 154 | .irq = IRQ_IXP4XX_UART2, |
| 155 | .flags = UPF_BOOT_AUTOCONF, |
| 156 | .iotype = UPIO_MEM, |
| 157 | .regshift = 2, |
| 158 | .uartclk = IXP4XX_UART_XTAL, |
| 159 | }, |
| 160 | { } |
| 161 | }; |
| 162 | |
| 163 | static struct platform_device nslu2_uart = { |
| 164 | .name = "serial8250", |
| 165 | .id = PLAT8250_DEV_PLATFORM, |
| 166 | .dev.platform_data = nslu2_uart_data, |
| 167 | .num_resources = 2, |
| 168 | .resource = nslu2_uart_resources, |
| 169 | }; |
| 170 | |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 171 | /* Built-in 10/100 Ethernet MAC interfaces */ |
| 172 | static struct eth_plat_info nslu2_plat_eth[] = { |
| 173 | { |
| 174 | .phy = 1, |
| 175 | .rxq = 3, |
| 176 | .txreadyq = 20, |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | static struct platform_device nslu2_eth[] = { |
| 181 | { |
| 182 | .name = "ixp4xx_eth", |
| 183 | .id = IXP4XX_ETH_NPEB, |
| 184 | .dev.platform_data = nslu2_plat_eth, |
| 185 | } |
| 186 | }; |
| 187 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 188 | static struct platform_device *nslu2_devices[] __initdata = { |
Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 189 | &nslu2_i2c_gpio, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 190 | &nslu2_flash, |
Alessandro Zummo | bc66d44 | 2006-02-22 21:12:06 +0000 | [diff] [blame] | 191 | &nslu2_beeper, |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 192 | &nslu2_leds, |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 193 | &nslu2_eth[0], |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | static void nslu2_power_off(void) |
| 197 | { |
| 198 | /* This causes the box to drop the power and go dead. */ |
| 199 | |
Linus Walleij | 8040dd0 | 2013-09-10 11:19:55 +0200 | [diff] [blame] | 200 | /* enable the pwr cntl gpio and assert power off */ |
| 201 | gpio_direction_output(NSLU2_PO_GPIO, 1); |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 204 | static irqreturn_t nslu2_power_handler(int irq, void *dev_id) |
| 205 | { |
| 206 | /* Signal init to do the ctrlaltdel action, this will bypass init if |
| 207 | * it hasn't started and do a kernel_restart. |
| 208 | */ |
| 209 | ctrl_alt_del(); |
| 210 | |
| 211 | return IRQ_HANDLED; |
| 212 | } |
| 213 | |
| 214 | static irqreturn_t nslu2_reset_handler(int irq, void *dev_id) |
| 215 | { |
| 216 | /* This is the paper-clip reset, it shuts the machine down directly. |
| 217 | */ |
| 218 | machine_power_off(); |
| 219 | |
| 220 | return IRQ_HANDLED; |
| 221 | } |
| 222 | |
Linus Walleij | 8040dd0 | 2013-09-10 11:19:55 +0200 | [diff] [blame] | 223 | static int __init nslu2_gpio_init(void) |
| 224 | { |
| 225 | if (!machine_is_nslu2()) |
| 226 | return 0; |
| 227 | |
| 228 | /* Request the power off GPIO */ |
| 229 | return gpio_request(NSLU2_PO_GPIO, "power off"); |
| 230 | } |
| 231 | device_initcall(nslu2_gpio_init); |
| 232 | |
Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 233 | static void __init nslu2_timer_init(void) |
| 234 | { |
| 235 | /* The xtal on this machine is non-standard. */ |
| 236 | ixp4xx_timer_freq = NSLU2_FREQ; |
| 237 | |
| 238 | /* Call standard timer_init function. */ |
| 239 | ixp4xx_timer_init(); |
| 240 | } |
| 241 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 242 | static void __init nslu2_init(void) |
| 243 | { |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 244 | uint8_t __iomem *f; |
| 245 | int i; |
| 246 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 247 | ixp4xx_sys_init(); |
| 248 | |
Martin Michlmayr | 3dfaf7a | 2006-02-16 22:36:12 +0000 | [diff] [blame] | 249 | nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); |
| 250 | nslu2_flash_resource.end = |
| 251 | IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; |
| 252 | |
Rod Whitby | e28067d | 2008-01-29 00:36:12 +0100 | [diff] [blame] | 253 | i2c_register_board_info(0, nslu2_i2c_board_info, |
| 254 | ARRAY_SIZE(nslu2_i2c_board_info)); |
| 255 | |
Michael-Luke Jones | cc50a0d | 2007-05-23 22:41:53 +0100 | [diff] [blame] | 256 | /* |
| 257 | * This is only useful on a modified machine, but it is valuable |
Rod Whitby | e22b04f | 2006-06-22 22:21:02 +0100 | [diff] [blame] | 258 | * to have it first in order to see debug messages, and so that |
| 259 | * it does *not* get removed if platform_add_devices fails! |
| 260 | */ |
| 261 | (void)platform_device_register(&nslu2_uart); |
| 262 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 263 | platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices)); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 264 | |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 265 | pm_power_off = nslu2_power_off; |
| 266 | |
| 267 | if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler, |
Michael Opdenacker | 1ee6564 | 2014-03-04 21:59:03 +0100 | [diff] [blame] | 268 | IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) { |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 269 | |
| 270 | printk(KERN_DEBUG "Reset Button IRQ %d not available\n", |
| 271 | gpio_to_irq(NSLU2_RB_GPIO)); |
| 272 | } |
| 273 | |
| 274 | if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler, |
Michael Opdenacker | 1ee6564 | 2014-03-04 21:59:03 +0100 | [diff] [blame] | 275 | IRQF_TRIGGER_HIGH, "NSLU2 power button", NULL) < 0) { |
Rod Whitby | 0929ac3 | 2008-02-03 12:05:42 +0100 | [diff] [blame] | 276 | |
| 277 | printk(KERN_DEBUG "Power Button IRQ %d not available\n", |
| 278 | gpio_to_irq(NSLU2_PB_GPIO)); |
| 279 | } |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 280 | |
| 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), 0x40000); |
| 287 | if (f) { |
| 288 | for (i = 0; i < 6; i++) |
| 289 | #ifdef __ARMEB__ |
| 290 | nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i); |
| 291 | #else |
| 292 | nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3)); |
| 293 | #endif |
| 294 | iounmap(f); |
| 295 | } |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 296 | printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n", |
| 297 | nslu2_plat_eth[0].hwaddr); |
Rod Whitby | b7edc84 | 2008-02-02 00:04:05 +0100 | [diff] [blame] | 298 | |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | MACHINE_START(NSLU2, "Linksys NSLU2") |
| 302 | /* Maintainer: www.nslu2-linux.org */ |
Nicolas Pitre | e022c72 | 2011-07-05 22:38:13 -0400 | [diff] [blame] | 303 | .atag_offset = 0x100, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 304 | .map_io = ixp4xx_map_io, |
Rob Herring | f449588 | 2012-03-06 15:01:53 -0600 | [diff] [blame] | 305 | .init_early = ixp4xx_init_early, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 306 | .init_irq = ixp4xx_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 307 | .init_time = nslu2_timer_init, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 308 | .init_machine = nslu2_init, |
Nicolas Pitre | 7553ee7 | 2011-07-05 22:28:09 -0400 | [diff] [blame] | 309 | #if defined(CONFIG_PCI) |
| 310 | .dma_zone_size = SZ_64M, |
| 311 | #endif |
Russell King | d1b860f | 2011-11-05 12:10:55 +0000 | [diff] [blame] | 312 | .restart = ixp4xx_restart, |
Alessandro Zummo | a7918f3 | 2005-11-10 14:05:04 +0000 | [diff] [blame] | 313 | MACHINE_END |