Loading...
1/*
2 * arch/arm/mach-ixp4xx/nslu2-setup.c
3 *
4 * NSLU2 board-setup
5 *
6 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
7 *
8 * based on ixdp425-setup.c:
9 * Copyright (C) 2003-2004 MontaVista Software, Inc.
10 * based on nslu2-power.c:
11 * Copyright (C) 2005 Tower Technologies
12 *
13 * Author: Mark Rakes <mrakes at mac.com>
14 * Author: Rod Whitby <rod@whitby.id.au>
15 * Author: Alessandro Zummo <a.zummo@towertech.it>
16 * Maintainers: http://www.nslu2-linux.org/
17 *
18 */
19#include <linux/gpio.h>
20#include <linux/if_ether.h>
21#include <linux/irq.h>
22#include <linux/serial.h>
23#include <linux/serial_8250.h>
24#include <linux/leds.h>
25#include <linux/reboot.h>
26#include <linux/i2c.h>
27#include <linux/i2c-gpio.h>
28#include <linux/io.h>
29#include <asm/mach-types.h>
30#include <asm/mach/arch.h>
31#include <asm/mach/flash.h>
32#include <asm/mach/time.h>
33
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
54static struct flash_platform_data nslu2_flash_data = {
55 .map_name = "cfi_probe",
56 .width = 2,
57};
58
59static struct resource nslu2_flash_resource = {
60 .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
71static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
72 .sda_pin = NSLU2_SDA_PIN,
73 .scl_pin = NSLU2_SCL_PIN,
74};
75
76static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
77 {
78 I2C_BOARD_INFO("x1205", 0x6f),
79 },
80};
81
82static struct gpio_led nslu2_led_pins[] = {
83 {
84 .name = "nslu2:green:ready",
85 .gpio = NSLU2_LED_GRN_GPIO,
86 },
87 {
88 .name = "nslu2:red:status",
89 .gpio = NSLU2_LED_RED_GPIO,
90 },
91 {
92 .name = "nslu2:green:disk-1",
93 .gpio = NSLU2_LED_DISK1_GPIO,
94 .active_low = true,
95 },
96 {
97 .name = "nslu2:green:disk-2",
98 .gpio = NSLU2_LED_DISK2_GPIO,
99 .active_low = true,
100 },
101};
102
103static struct gpio_led_platform_data nslu2_led_data = {
104 .num_leds = ARRAY_SIZE(nslu2_led_pins),
105 .leds = nslu2_led_pins,
106};
107
108static struct platform_device nslu2_leds = {
109 .name = "leds-gpio",
110 .id = -1,
111 .dev.platform_data = &nslu2_led_data,
112};
113
114static struct platform_device nslu2_i2c_gpio = {
115 .name = "i2c-gpio",
116 .id = 0,
117 .dev = {
118 .platform_data = &nslu2_i2c_gpio_data,
119 },
120};
121
122static struct platform_device nslu2_beeper = {
123 .name = "ixp4xx-beeper",
124 .id = NSLU2_GPIO_BUZZ,
125 .num_resources = 0,
126};
127
128static 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
171/* 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
188static struct platform_device *nslu2_devices[] __initdata = {
189 &nslu2_i2c_gpio,
190 &nslu2_flash,
191 &nslu2_beeper,
192 &nslu2_leds,
193 &nslu2_eth[0],
194};
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
207static 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
226static 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
235static struct sys_timer nslu2_timer = {
236 .init = nslu2_timer_init,
237};
238
239static void __init nslu2_init(void)
240{
241 uint8_t __iomem *f;
242 int i;
243
244 ixp4xx_sys_init();
245
246 nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
247 nslu2_flash_resource.end =
248 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
249
250 i2c_register_board_info(0, nslu2_i2c_board_info,
251 ARRAY_SIZE(nslu2_i2c_board_info));
252
253 /*
254 * This is only useful on a modified machine, but it is valuable
255 * to have it first in order to see debug messages, and so that
256 * it does *not* get removed if platform_add_devices fails!
257 */
258 (void)platform_device_register(&nslu2_uart);
259
260 platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
261
262 pm_power_off = nslu2_power_off;
263
264 if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
265 IRQF_DISABLED | IRQF_TRIGGER_LOW,
266 "NSLU2 reset button", NULL) < 0) {
267
268 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
269 gpio_to_irq(NSLU2_RB_GPIO));
270 }
271
272 if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
273 IRQF_DISABLED | IRQF_TRIGGER_HIGH,
274 "NSLU2 power button", NULL) < 0) {
275
276 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
277 gpio_to_irq(NSLU2_PB_GPIO));
278 }
279
280 /*
281 * Map in a portion of the flash and read the MAC address.
282 * Since it is stored in BE in the flash itself, we need to
283 * byteswap it if we're in LE mode.
284 */
285 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
286 if (f) {
287 for (i = 0; i < 6; i++)
288#ifdef __ARMEB__
289 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
290#else
291 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
292#endif
293 iounmap(f);
294 }
295 printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
296 nslu2_plat_eth[0].hwaddr);
297
298}
299
300MACHINE_START(NSLU2, "Linksys NSLU2")
301 /* Maintainer: www.nslu2-linux.org */
302 .atag_offset = 0x100,
303 .map_io = ixp4xx_map_io,
304 .init_early = ixp4xx_init_early,
305 .init_irq = ixp4xx_init_irq,
306 .timer = &nslu2_timer,
307 .init_machine = nslu2_init,
308#if defined(CONFIG_PCI)
309 .dma_zone_size = SZ_64M,
310#endif
311 .restart = ixp4xx_restart,
312MACHINE_END
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * arch/arm/mach-ixp4xx/nslu2-setup.c
4 *
5 * NSLU2 board-setup
6 *
7 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
8 *
9 * based on ixdp425-setup.c:
10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
11 * based on nslu2-power.c:
12 * Copyright (C) 2005 Tower Technologies
13 *
14 * Author: Mark Rakes <mrakes at mac.com>
15 * Author: Rod Whitby <rod@whitby.id.au>
16 * Author: Alessandro Zummo <a.zummo@towertech.it>
17 * Maintainers: http://www.nslu2-linux.org/
18 *
19 */
20#include <linux/gpio.h>
21#include <linux/if_ether.h>
22#include <linux/irq.h>
23#include <linux/serial.h>
24#include <linux/serial_8250.h>
25#include <linux/leds.h>
26#include <linux/reboot.h>
27#include <linux/i2c.h>
28#include <linux/gpio/machine.h>
29#include <linux/io.h>
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/flash.h>
33#include <asm/mach/time.h>
34
35#include "irqs.h"
36
37#define NSLU2_SDA_PIN 7
38#define NSLU2_SCL_PIN 6
39
40/* NSLU2 Timer */
41#define NSLU2_FREQ 66000000
42
43/* Buttons */
44#define NSLU2_PB_GPIO 5 /* power button */
45#define NSLU2_PO_GPIO 8 /* power off */
46#define NSLU2_RB_GPIO 12 /* reset button */
47
48/* Buzzer */
49#define NSLU2_GPIO_BUZZ 4
50
51/* LEDs */
52#define NSLU2_LED_RED_GPIO 0
53#define NSLU2_LED_GRN_GPIO 1
54#define NSLU2_LED_DISK1_GPIO 3
55#define NSLU2_LED_DISK2_GPIO 2
56
57static struct flash_platform_data nslu2_flash_data = {
58 .map_name = "cfi_probe",
59 .width = 2,
60};
61
62static struct resource nslu2_flash_resource = {
63 .flags = IORESOURCE_MEM,
64};
65
66static struct platform_device nslu2_flash = {
67 .name = "IXP4XX-Flash",
68 .id = 0,
69 .dev.platform_data = &nslu2_flash_data,
70 .num_resources = 1,
71 .resource = &nslu2_flash_resource,
72};
73
74static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
75 .dev_id = "i2c-gpio.0",
76 .table = {
77 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
78 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
79 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN,
80 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
81 },
82};
83
84static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
85 {
86 I2C_BOARD_INFO("x1205", 0x6f),
87 },
88};
89
90static struct gpio_led nslu2_led_pins[] = {
91 {
92 .name = "nslu2:green:ready",
93 .gpio = NSLU2_LED_GRN_GPIO,
94 },
95 {
96 .name = "nslu2:red:status",
97 .gpio = NSLU2_LED_RED_GPIO,
98 },
99 {
100 .name = "nslu2:green:disk-1",
101 .gpio = NSLU2_LED_DISK1_GPIO,
102 .active_low = true,
103 },
104 {
105 .name = "nslu2:green:disk-2",
106 .gpio = NSLU2_LED_DISK2_GPIO,
107 .active_low = true,
108 },
109};
110
111static struct gpio_led_platform_data nslu2_led_data = {
112 .num_leds = ARRAY_SIZE(nslu2_led_pins),
113 .leds = nslu2_led_pins,
114};
115
116static struct platform_device nslu2_leds = {
117 .name = "leds-gpio",
118 .id = -1,
119 .dev.platform_data = &nslu2_led_data,
120};
121
122static struct platform_device nslu2_i2c_gpio = {
123 .name = "i2c-gpio",
124 .id = 0,
125 .dev = {
126 .platform_data = NULL,
127 },
128};
129
130static struct resource nslu2_beeper_resources[] = {
131 {
132 .start = IRQ_IXP4XX_TIMER2,
133 .flags = IORESOURCE_IRQ,
134 },
135};
136
137static struct platform_device nslu2_beeper = {
138 .name = "ixp4xx-beeper",
139 .id = NSLU2_GPIO_BUZZ,
140 .resource = nslu2_beeper_resources,
141 .num_resources = ARRAY_SIZE(nslu2_beeper_resources),
142};
143
144static struct resource nslu2_uart_resources[] = {
145 {
146 .start = IXP4XX_UART1_BASE_PHYS,
147 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
148 .flags = IORESOURCE_MEM,
149 },
150 {
151 .start = IXP4XX_UART2_BASE_PHYS,
152 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
153 .flags = IORESOURCE_MEM,
154 }
155};
156
157static struct plat_serial8250_port nslu2_uart_data[] = {
158 {
159 .mapbase = IXP4XX_UART1_BASE_PHYS,
160 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
161 .irq = IRQ_IXP4XX_UART1,
162 .flags = UPF_BOOT_AUTOCONF,
163 .iotype = UPIO_MEM,
164 .regshift = 2,
165 .uartclk = IXP4XX_UART_XTAL,
166 },
167 {
168 .mapbase = IXP4XX_UART2_BASE_PHYS,
169 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
170 .irq = IRQ_IXP4XX_UART2,
171 .flags = UPF_BOOT_AUTOCONF,
172 .iotype = UPIO_MEM,
173 .regshift = 2,
174 .uartclk = IXP4XX_UART_XTAL,
175 },
176 { }
177};
178
179static struct platform_device nslu2_uart = {
180 .name = "serial8250",
181 .id = PLAT8250_DEV_PLATFORM,
182 .dev.platform_data = nslu2_uart_data,
183 .num_resources = 2,
184 .resource = nslu2_uart_resources,
185};
186
187/* Built-in 10/100 Ethernet MAC interfaces */
188static struct resource nslu2_eth_resources[] = {
189 {
190 .start = IXP4XX_EthB_BASE_PHYS,
191 .end = IXP4XX_EthB_BASE_PHYS + 0x0fff,
192 .flags = IORESOURCE_MEM,
193 },
194};
195
196static struct eth_plat_info nslu2_plat_eth[] = {
197 {
198 .phy = 1,
199 .rxq = 3,
200 .txreadyq = 20,
201 }
202};
203
204static struct platform_device nslu2_eth[] = {
205 {
206 .name = "ixp4xx_eth",
207 .id = IXP4XX_ETH_NPEB,
208 .dev.platform_data = nslu2_plat_eth,
209 .num_resources = ARRAY_SIZE(nslu2_eth_resources),
210 .resource = nslu2_eth_resources,
211 }
212};
213
214static struct platform_device *nslu2_devices[] __initdata = {
215 &nslu2_i2c_gpio,
216 &nslu2_flash,
217 &nslu2_beeper,
218 &nslu2_leds,
219 &nslu2_eth[0],
220};
221
222static void nslu2_power_off(void)
223{
224 /* This causes the box to drop the power and go dead. */
225
226 /* enable the pwr cntl gpio and assert power off */
227 gpio_direction_output(NSLU2_PO_GPIO, 1);
228}
229
230static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
231{
232 /* Signal init to do the ctrlaltdel action, this will bypass init if
233 * it hasn't started and do a kernel_restart.
234 */
235 ctrl_alt_del();
236
237 return IRQ_HANDLED;
238}
239
240static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
241{
242 /* This is the paper-clip reset, it shuts the machine down directly.
243 */
244 machine_power_off();
245
246 return IRQ_HANDLED;
247}
248
249static int __init nslu2_gpio_init(void)
250{
251 if (!machine_is_nslu2())
252 return 0;
253
254 /* Request the power off GPIO */
255 return gpio_request(NSLU2_PO_GPIO, "power off");
256}
257device_initcall(nslu2_gpio_init);
258
259static void __init nslu2_timer_init(void)
260{
261 /* The xtal on this machine is non-standard. */
262 ixp4xx_timer_freq = NSLU2_FREQ;
263
264 /* Call standard timer_init function. */
265 ixp4xx_timer_init();
266}
267
268static void __init nslu2_init(void)
269{
270 uint8_t __iomem *f;
271 int i;
272
273 ixp4xx_sys_init();
274
275 nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
276 nslu2_flash_resource.end =
277 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
278
279 gpiod_add_lookup_table(&nslu2_i2c_gpiod_table);
280 i2c_register_board_info(0, nslu2_i2c_board_info,
281 ARRAY_SIZE(nslu2_i2c_board_info));
282
283 /*
284 * This is only useful on a modified machine, but it is valuable
285 * to have it first in order to see debug messages, and so that
286 * it does *not* get removed if platform_add_devices fails!
287 */
288 (void)platform_device_register(&nslu2_uart);
289
290 platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
291
292 pm_power_off = nslu2_power_off;
293
294 if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
295 IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
296
297 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
298 gpio_to_irq(NSLU2_RB_GPIO));
299 }
300
301 if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
302 IRQF_TRIGGER_HIGH, "NSLU2 power button", NULL) < 0) {
303
304 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
305 gpio_to_irq(NSLU2_PB_GPIO));
306 }
307
308 /*
309 * Map in a portion of the flash and read the MAC address.
310 * Since it is stored in BE in the flash itself, we need to
311 * byteswap it if we're in LE mode.
312 */
313 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
314 if (f) {
315 for (i = 0; i < 6; i++)
316#ifdef __ARMEB__
317 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
318#else
319 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
320#endif
321 iounmap(f);
322 }
323 printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
324 nslu2_plat_eth[0].hwaddr);
325
326}
327
328MACHINE_START(NSLU2, "Linksys NSLU2")
329 /* Maintainer: www.nslu2-linux.org */
330 .atag_offset = 0x100,
331 .map_io = ixp4xx_map_io,
332 .init_early = ixp4xx_init_early,
333 .init_irq = ixp4xx_init_irq,
334 .init_time = nslu2_timer_init,
335 .init_machine = nslu2_init,
336#if defined(CONFIG_PCI)
337 .dma_zone_size = SZ_64M,
338#endif
339 .restart = ixp4xx_restart,
340MACHINE_END