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