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