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