]> git.ipfire.org Git - thirdparty/linux.git/blame - arch/arm/mach-ixp4xx/nslu2-setup.c
ARM: ixp4xx: Convert to SPARSE_IRQ
[thirdparty/linux.git] / arch / arm / mach-ixp4xx / nslu2-setup.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
a7918f39
AZ
2/*
3 * arch/arm/mach-ixp4xx/nslu2-setup.c
4 *
5 * NSLU2 board-setup
6 *
0929ac3e
RW
7 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
8 *
9 * based on ixdp425-setup.c:
a7918f39 10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
0929ac3e
RW
11 * based on nslu2-power.c:
12 * Copyright (C) 2005 Tower Technologies
a7918f39
AZ
13 *
14 * Author: Mark Rakes <mrakes at mac.com>
e22b04fb 15 * Author: Rod Whitby <rod@whitby.id.au>
0929ac3e 16 * Author: Alessandro Zummo <a.zummo@towertech.it>
a7918f39
AZ
17 * Maintainers: http://www.nslu2-linux.org/
18 *
a7918f39 19 */
2f8163ba 20#include <linux/gpio.h>
b7edc84a 21#include <linux/if_ether.h>
0929ac3e 22#include <linux/irq.h>
a7918f39
AZ
23#include <linux/serial.h>
24#include <linux/serial_8250.h>
e22b04fb 25#include <linux/leds.h>
0929ac3e 26#include <linux/reboot.h>
e28067d5 27#include <linux/i2c.h>
b2e63555 28#include <linux/gpio/machine.h>
fced80c7 29#include <linux/io.h>
a7918f39
AZ
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/flash.h>
435c5da0 33#include <asm/mach/time.h>
a7918f39 34
dc8ef8cd
LW
35#include "irqs.h"
36
c1117c63
KH
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
a7918f39
AZ
57static struct flash_platform_data nslu2_flash_data = {
58 .map_name = "cfi_probe",
59 .width = 2,
60};
61
62static struct resource nslu2_flash_resource = {
a7918f39
AZ
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
b2e63555 74static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
f59c303b 75 .dev_id = "i2c-gpio.0",
b2e63555
LW
76 .table = {
77 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
4d0ce62c 78 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
b2e63555 79 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN,
4d0ce62c 80 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
b2e63555 81 },
a7918f39
AZ
82};
83
e28067d5
RW
84static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
85 {
3760f736 86 I2C_BOARD_INFO("x1205", 0x6f),
e28067d5
RW
87 },
88};
89
1208ebf2 90static struct gpio_led nslu2_led_pins[] = {
e22b04fb 91 {
6c152bee 92 .name = "nslu2:green:ready",
1208ebf2 93 .gpio = NSLU2_LED_GRN_GPIO,
e22b04fb
RW
94 },
95 {
6c152bee 96 .name = "nslu2:red:status",
1208ebf2 97 .gpio = NSLU2_LED_RED_GPIO,
e22b04fb
RW
98 },
99 {
6c152bee 100 .name = "nslu2:green:disk-1",
1208ebf2
RW
101 .gpio = NSLU2_LED_DISK1_GPIO,
102 .active_low = true,
e22b04fb
RW
103 },
104 {
6c152bee 105 .name = "nslu2:green:disk-2",
1208ebf2
RW
106 .gpio = NSLU2_LED_DISK2_GPIO,
107 .active_low = true,
e22b04fb
RW
108 },
109};
110
1208ebf2
RW
111static struct gpio_led_platform_data nslu2_led_data = {
112 .num_leds = ARRAY_SIZE(nslu2_led_pins),
113 .leds = nslu2_led_pins,
114};
115
e22b04fb 116static struct platform_device nslu2_leds = {
1208ebf2 117 .name = "leds-gpio",
e22b04fb 118 .id = -1,
1208ebf2 119 .dev.platform_data = &nslu2_led_data,
e22b04fb 120};
e22b04fb 121
5a4a2387
MLJ
122static struct platform_device nslu2_i2c_gpio = {
123 .name = "i2c-gpio",
a7918f39 124 .id = 0,
5a4a2387 125 .dev = {
b2e63555 126 .platform_data = NULL,
5a4a2387 127 },
a7918f39
AZ
128};
129
075df31a
LW
130static struct resource nslu2_beeper_resources[] = {
131 {
132 .start = IRQ_IXP4XX_TIMER2,
133 .flags = IORESOURCE_IRQ,
134 },
135};
136
bc66d449
AZ
137static struct platform_device nslu2_beeper = {
138 .name = "ixp4xx-beeper",
139 .id = NSLU2_GPIO_BUZZ,
075df31a
LW
140 .resource = nslu2_beeper_resources,
141 .num_resources = ARRAY_SIZE(nslu2_beeper_resources),
bc66d449
AZ
142};
143
a7918f39
AZ
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
b7edc84a
RW
187/* Built-in 10/100 Ethernet MAC interfaces */
188static struct eth_plat_info nslu2_plat_eth[] = {
189 {
190 .phy = 1,
191 .rxq = 3,
192 .txreadyq = 20,
193 }
194};
195
196static struct platform_device nslu2_eth[] = {
197 {
198 .name = "ixp4xx_eth",
199 .id = IXP4XX_ETH_NPEB,
200 .dev.platform_data = nslu2_plat_eth,
201 }
202};
203
a7918f39 204static struct platform_device *nslu2_devices[] __initdata = {
5a4a2387 205 &nslu2_i2c_gpio,
a7918f39 206 &nslu2_flash,
bc66d449 207 &nslu2_beeper,
e22b04fb 208 &nslu2_leds,
b7edc84a 209 &nslu2_eth[0],
a7918f39
AZ
210};
211
212static void nslu2_power_off(void)
213{
214 /* This causes the box to drop the power and go dead. */
215
8040dd09
LW
216 /* enable the pwr cntl gpio and assert power off */
217 gpio_direction_output(NSLU2_PO_GPIO, 1);
a7918f39
AZ
218}
219
0929ac3e
RW
220static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
221{
222 /* Signal init to do the ctrlaltdel action, this will bypass init if
223 * it hasn't started and do a kernel_restart.
224 */
225 ctrl_alt_del();
226
227 return IRQ_HANDLED;
228}
229
230static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
231{
232 /* This is the paper-clip reset, it shuts the machine down directly.
233 */
234 machine_power_off();
235
236 return IRQ_HANDLED;
237}
238
8040dd09
LW
239static int __init nslu2_gpio_init(void)
240{
241 if (!machine_is_nslu2())
242 return 0;
243
244 /* Request the power off GPIO */
245 return gpio_request(NSLU2_PO_GPIO, "power off");
246}
247device_initcall(nslu2_gpio_init);
248
435c5da0 249static void __init nslu2_timer_init(void)
a7918f39 250{
435c5da0
MLJ
251 /* The xtal on this machine is non-standard. */
252 ixp4xx_timer_freq = NSLU2_FREQ;
253
254 /* Call standard timer_init function. */
255 ixp4xx_timer_init();
256}
84904d0e 257
435c5da0
MLJ
258static void __init nslu2_init(void)
259{
b7edc84a
RW
260 uint8_t __iomem *f;
261 int i;
262
a7918f39
AZ
263 ixp4xx_sys_init();
264
3dfaf7a6
MM
265 nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
266 nslu2_flash_resource.end =
267 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
268
b2e63555 269 gpiod_add_lookup_table(&nslu2_i2c_gpiod_table);
e28067d5
RW
270 i2c_register_board_info(0, nslu2_i2c_board_info,
271 ARRAY_SIZE(nslu2_i2c_board_info));
272
cc50a0df
MLJ
273 /*
274 * This is only useful on a modified machine, but it is valuable
e22b04fb
RW
275 * to have it first in order to see debug messages, and so that
276 * it does *not* get removed if platform_add_devices fails!
277 */
278 (void)platform_device_register(&nslu2_uart);
279
a7918f39 280 platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
b7edc84a 281
0929ac3e
RW
282 pm_power_off = nslu2_power_off;
283
284 if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
1ee6564d 285 IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
0929ac3e
RW
286
287 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
288 gpio_to_irq(NSLU2_RB_GPIO));
289 }
290
291 if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
1ee6564d 292 IRQF_TRIGGER_HIGH, "NSLU2 power button", NULL) < 0) {
0929ac3e
RW
293
294 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
295 gpio_to_irq(NSLU2_PB_GPIO));
296 }
b7edc84a
RW
297
298 /*
299 * Map in a portion of the flash and read the MAC address.
300 * Since it is stored in BE in the flash itself, we need to
301 * byteswap it if we're in LE mode.
302 */
303 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
304 if (f) {
305 for (i = 0; i < 6; i++)
306#ifdef __ARMEB__
307 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
308#else
309 nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
310#endif
311 iounmap(f);
312 }
e174961c
JB
313 printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
314 nslu2_plat_eth[0].hwaddr);
b7edc84a 315
a7918f39
AZ
316}
317
318MACHINE_START(NSLU2, "Linksys NSLU2")
319 /* Maintainer: www.nslu2-linux.org */
e022c729 320 .atag_offset = 0x100,
a7918f39 321 .map_io = ixp4xx_map_io,
f449588c 322 .init_early = ixp4xx_init_early,
a7918f39 323 .init_irq = ixp4xx_init_irq,
6bb27d73 324 .init_time = nslu2_timer_init,
a7918f39 325 .init_machine = nslu2_init,
7553ee77
NP
326#if defined(CONFIG_PCI)
327 .dma_zone_size = SZ_64M,
328#endif
d1b860fb 329 .restart = ixp4xx_restart,
a7918f39 330MACHINE_END