blob: 7e55236c26eab3dea60ddfa2ef9eaacad17bd597 [file] [log] [blame]
Alessandro Zummoa7918f32005-11-10 14:05:04 +00001/*
2 * arch/arm/mach-ixp4xx/nslu2-setup.c
3 *
4 * NSLU2 board-setup
5 *
Rod Whitby0929ac32008-02-03 12:05:42 +01006 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
7 *
8 * based on ixdp425-setup.c:
Alessandro Zummoa7918f32005-11-10 14:05:04 +00009 * Copyright (C) 2003-2004 MontaVista Software, Inc.
Rod Whitby0929ac32008-02-03 12:05:42 +010010 * based on nslu2-power.c:
11 * Copyright (C) 2005 Tower Technologies
Alessandro Zummoa7918f32005-11-10 14:05:04 +000012 *
13 * Author: Mark Rakes <mrakes at mac.com>
Rod Whitbye22b04f2006-06-22 22:21:02 +010014 * Author: Rod Whitby <rod@whitby.id.au>
Rod Whitby0929ac32008-02-03 12:05:42 +010015 * Author: Alessandro Zummo <a.zummo@towertech.it>
Alessandro Zummoa7918f32005-11-10 14:05:04 +000016 * Maintainers: http://www.nslu2-linux.org/
17 *
Alessandro Zummoa7918f32005-11-10 14:05:04 +000018 */
Russell King2f8163b2011-07-26 10:53:52 +010019#include <linux/gpio.h>
Rod Whitbyb7edc842008-02-02 00:04:05 +010020#include <linux/if_ether.h>
Rod Whitby0929ac32008-02-03 12:05:42 +010021#include <linux/irq.h>
Alessandro Zummoa7918f32005-11-10 14:05:04 +000022#include <linux/serial.h>
23#include <linux/serial_8250.h>
Rod Whitbye22b04f2006-06-22 22:21:02 +010024#include <linux/leds.h>
Rod Whitby0929ac32008-02-03 12:05:42 +010025#include <linux/reboot.h>
Rod Whitbye28067d2008-01-29 00:36:12 +010026#include <linux/i2c.h>
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010027#include <linux/i2c-gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Alessandro Zummoa7918f32005-11-10 14:05:04 +000029#include <asm/mach-types.h>
30#include <asm/mach/arch.h>
31#include <asm/mach/flash.h>
Michael-Luke Jones435c5da2007-05-23 22:38:45 +010032#include <asm/mach/time.h>
Alessandro Zummoa7918f32005-11-10 14:05:04 +000033
Krzysztof HaƂasac1117c62009-11-16 16:02:02 +010034#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 Zummoa7918f32005-11-10 14:05:04 +000054static struct flash_platform_data nslu2_flash_data = {
55 .map_name = "cfi_probe",
56 .width = 2,
57};
58
59static struct resource nslu2_flash_resource = {
Alessandro Zummoa7918f32005-11-10 14:05:04 +000060 .flags = IORESOURCE_MEM,
61};
62
63static 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 Jones5a4a2382008-01-27 18:14:46 +010071static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
Alessandro Zummoa7918f32005-11-10 14:05:04 +000072 .sda_pin = NSLU2_SDA_PIN,
73 .scl_pin = NSLU2_SCL_PIN,
74};
75
Rod Whitbye28067d2008-01-29 00:36:12 +010076static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
77 {
Jean Delvare3760f732008-04-29 23:11:40 +020078 I2C_BOARD_INFO("x1205", 0x6f),
Rod Whitbye28067d2008-01-29 00:36:12 +010079 },
80};
81
Rod Whitby1208ebf2008-02-02 00:03:56 +010082static struct gpio_led nslu2_led_pins[] = {
Rod Whitbye22b04f2006-06-22 22:21:02 +010083 {
Richard Purdie6c152be2007-10-31 15:00:07 +010084 .name = "nslu2:green:ready",
Rod Whitby1208ebf2008-02-02 00:03:56 +010085 .gpio = NSLU2_LED_GRN_GPIO,
Rod Whitbye22b04f2006-06-22 22:21:02 +010086 },
87 {
Richard Purdie6c152be2007-10-31 15:00:07 +010088 .name = "nslu2:red:status",
Rod Whitby1208ebf2008-02-02 00:03:56 +010089 .gpio = NSLU2_LED_RED_GPIO,
Rod Whitbye22b04f2006-06-22 22:21:02 +010090 },
91 {
Richard Purdie6c152be2007-10-31 15:00:07 +010092 .name = "nslu2:green:disk-1",
Rod Whitby1208ebf2008-02-02 00:03:56 +010093 .gpio = NSLU2_LED_DISK1_GPIO,
94 .active_low = true,
Rod Whitbye22b04f2006-06-22 22:21:02 +010095 },
96 {
Richard Purdie6c152be2007-10-31 15:00:07 +010097 .name = "nslu2:green:disk-2",
Rod Whitby1208ebf2008-02-02 00:03:56 +010098 .gpio = NSLU2_LED_DISK2_GPIO,
99 .active_low = true,
Rod Whitbye22b04f2006-06-22 22:21:02 +0100100 },
101};
102
Rod Whitby1208ebf2008-02-02 00:03:56 +0100103static struct gpio_led_platform_data nslu2_led_data = {
104 .num_leds = ARRAY_SIZE(nslu2_led_pins),
105 .leds = nslu2_led_pins,
Rod Whitbye22b04f2006-06-22 22:21:02 +0100106};
Rod Whitby1208ebf2008-02-02 00:03:56 +0100107
108static struct platform_device nslu2_leds = {
109 .name = "leds-gpio",
110 .id = -1,
111 .dev.platform_data = &nslu2_led_data,
112};
Rod Whitbye22b04f2006-06-22 22:21:02 +0100113
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100114static struct platform_device nslu2_i2c_gpio = {
115 .name = "i2c-gpio",
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000116 .id = 0,
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100117 .dev = {
118 .platform_data = &nslu2_i2c_gpio_data,
119 },
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000120};
121
Alessandro Zummobc66d442006-02-22 21:12:06 +0000122static struct platform_device nslu2_beeper = {
123 .name = "ixp4xx-beeper",
124 .id = NSLU2_GPIO_BUZZ,
125 .num_resources = 0,
126};
127
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000128static 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
141static 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
163static 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 Whitbyb7edc842008-02-02 00:04:05 +0100171/* Built-in 10/100 Ethernet MAC interfaces */
172static struct eth_plat_info nslu2_plat_eth[] = {
173 {
174 .phy = 1,
175 .rxq = 3,
176 .txreadyq = 20,
177 }
178};
179
180static 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 Zummoa7918f32005-11-10 14:05:04 +0000188static struct platform_device *nslu2_devices[] __initdata = {
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100189 &nslu2_i2c_gpio,
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000190 &nslu2_flash,
Alessandro Zummobc66d442006-02-22 21:12:06 +0000191 &nslu2_beeper,
Rod Whitbye22b04f2006-06-22 22:21:02 +0100192 &nslu2_leds,
Rod Whitbyb7edc842008-02-02 00:04:05 +0100193 &nslu2_eth[0],
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000194};
195
196static void nslu2_power_off(void)
197{
198 /* This causes the box to drop the power and go dead. */
199
200 /* enable the pwr cntl gpio */
201 gpio_line_config(NSLU2_PO_GPIO, IXP4XX_GPIO_OUT);
202
203 /* do the deed */
204 gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
205}
206
Rod Whitby0929ac32008-02-03 12:05:42 +0100207static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
208{
209 /* Signal init to do the ctrlaltdel action, this will bypass init if
210 * it hasn't started and do a kernel_restart.
211 */
212 ctrl_alt_del();
213
214 return IRQ_HANDLED;
215}
216
217static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
218{
219 /* This is the paper-clip reset, it shuts the machine down directly.
220 */
221 machine_power_off();
222
223 return IRQ_HANDLED;
224}
225
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100226static void __init nslu2_timer_init(void)
227{
228 /* The xtal on this machine is non-standard. */
229 ixp4xx_timer_freq = NSLU2_FREQ;
230
231 /* Call standard timer_init function. */
232 ixp4xx_timer_init();
233}
234
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000235static void __init nslu2_init(void)
236{
Rod Whitbyb7edc842008-02-02 00:04:05 +0100237 uint8_t __iomem *f;
238 int i;
239
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000240 ixp4xx_sys_init();
241
Martin Michlmayr3dfaf7a2006-02-16 22:36:12 +0000242 nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
243 nslu2_flash_resource.end =
244 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
245
Rod Whitbye28067d2008-01-29 00:36:12 +0100246 i2c_register_board_info(0, nslu2_i2c_board_info,
247 ARRAY_SIZE(nslu2_i2c_board_info));
248
Michael-Luke Jonescc50a0d2007-05-23 22:41:53 +0100249 /*
250 * This is only useful on a modified machine, but it is valuable
Rod Whitbye22b04f2006-06-22 22:21:02 +0100251 * 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(&nslu2_uart);
255
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000256 platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
Rod Whitbyb7edc842008-02-02 00:04:05 +0100257
Rod Whitby0929ac32008-02-03 12:05:42 +0100258 pm_power_off = nslu2_power_off;
259
260 if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
261 IRQF_DISABLED | IRQF_TRIGGER_LOW,
262 "NSLU2 reset button", NULL) < 0) {
263
264 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
265 gpio_to_irq(NSLU2_RB_GPIO));
266 }
267
268 if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
269 IRQF_DISABLED | IRQF_TRIGGER_HIGH,
270 "NSLU2 power button", NULL) < 0) {
271
272 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
273 gpio_to_irq(NSLU2_PB_GPIO));
274 }
Rod Whitbyb7edc842008-02-02 00:04:05 +0100275
276 /*
277 * Map in a portion of the flash and read the MAC address.
278 * Since it is stored in BE in the flash itself, we need to
279 * byteswap it if we're in LE mode.
280 */
281 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
282 if (f) {
283 for (i = 0; i < 6; i++)
284#ifdef __ARMEB__
285 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
286#else
287 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
288#endif
289 iounmap(f);
290 }
Johannes Berge1749612008-10-27 15:59:26 -0700291 printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
292 nslu2_plat_eth[0].hwaddr);
Rod Whitbyb7edc842008-02-02 00:04:05 +0100293
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000294}
295
296MACHINE_START(NSLU2, "Linksys NSLU2")
297 /* Maintainer: www.nslu2-linux.org */
Nicolas Pitree022c722011-07-05 22:38:13 -0400298 .atag_offset = 0x100,
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000299 .map_io = ixp4xx_map_io,
Rob Herringf4495882012-03-06 15:01:53 -0600300 .init_early = ixp4xx_init_early,
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000301 .init_irq = ixp4xx_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700302 .init_time = nslu2_timer_init,
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000303 .init_machine = nslu2_init,
Nicolas Pitre7553ee72011-07-05 22:28:09 -0400304#if defined(CONFIG_PCI)
305 .dma_zone_size = SZ_64M,
306#endif
Russell Kingd1b860f2011-11-05 12:10:55 +0000307 .restart = ixp4xx_restart,
Alessandro Zummoa7918f32005-11-10 14:05:04 +0000308MACHINE_END