]> git.ipfire.org Git - thirdparty/linux.git/blame - arch/arm/mach-ixp4xx/nas100d-setup.c
ARM: ixp4xx: Pass IRQ resource to beeper
[thirdparty/linux.git] / arch / arm / mach-ixp4xx / nas100d-setup.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
3145d8a6
RW
2/*
3 * arch/arm/mach-ixp4xx/nas100d-setup.c
4 *
5 * NAS 100d board-setup
6 *
c7d1623e
RW
7 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
8 *
9 * based on ixdp425-setup.c:
3145d8a6 10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
c7d1623e
RW
11 * based on nas100d-power.c:
12 * Copyright (C) 2005 Tower Technologies
13 * based on nas100d-io.c
14 * Copyright (C) 2004 Karen Spearel
3145d8a6
RW
15 *
16 * Author: Alessandro Zummo <a.zummo@towertech.it>
17 * Author: Rod Whitby <rod@whitby.id.au>
18 * Maintainers: http://www.nslu2-linux.org/
19 *
20 */
2f8163ba 21#include <linux/gpio.h>
b7edc84a 22#include <linux/if_ether.h>
c7d1623e
RW
23#include <linux/irq.h>
24#include <linux/jiffies.h>
25#include <linux/timer.h>
3145d8a6
RW
26#include <linux/serial.h>
27#include <linux/serial_8250.h>
df6934b3 28#include <linux/leds.h>
c7d1623e 29#include <linux/reboot.h>
400d8231 30#include <linux/i2c.h>
b2e63555 31#include <linux/gpio/machine.h>
fced80c7 32#include <linux/io.h>
3145d8a6
RW
33#include <asm/mach-types.h>
34#include <asm/mach/arch.h>
35#include <asm/mach/flash.h>
36
23fa6846
KH
37#define NAS100D_SDA_PIN 5
38#define NAS100D_SCL_PIN 6
39
40/* Buttons */
41#define NAS100D_PB_GPIO 14 /* power button */
42#define NAS100D_RB_GPIO 4 /* reset button */
43
44/* Power control */
45#define NAS100D_PO_GPIO 12 /* power off */
46
47/* LEDs */
48#define NAS100D_LED_WLAN_GPIO 0
49#define NAS100D_LED_DISK_GPIO 3
50#define NAS100D_LED_PWR_GPIO 15
51
3145d8a6
RW
52static struct flash_platform_data nas100d_flash_data = {
53 .map_name = "cfi_probe",
54 .width = 2,
55};
56
57static struct resource nas100d_flash_resource = {
3145d8a6
RW
58 .flags = IORESOURCE_MEM,
59};
60
61static struct platform_device nas100d_flash = {
62 .name = "IXP4XX-Flash",
63 .id = 0,
64 .dev.platform_data = &nas100d_flash_data,
65 .num_resources = 1,
66 .resource = &nas100d_flash_resource,
67};
68
400d8231
RW
69static struct i2c_board_info __initdata nas100d_i2c_board_info [] = {
70 {
3760f736 71 I2C_BOARD_INFO("pcf8563", 0x51),
400d8231
RW
72 },
73};
74
1208ebf2 75static struct gpio_led nas100d_led_pins[] = {
df6934b3 76 {
6c152bee 77 .name = "nas100d:green:wlan",
1208ebf2
RW
78 .gpio = NAS100D_LED_WLAN_GPIO,
79 .active_low = true,
df6934b3
RW
80 },
81 {
6c152bee 82 .name = "nas100d:blue:power", /* (off=flashing) */
1208ebf2
RW
83 .gpio = NAS100D_LED_PWR_GPIO,
84 .active_low = true,
df6934b3
RW
85 },
86 {
6c152bee 87 .name = "nas100d:yellow:disk",
1208ebf2
RW
88 .gpio = NAS100D_LED_DISK_GPIO,
89 .active_low = true,
df6934b3
RW
90 },
91};
92
1208ebf2
RW
93static struct gpio_led_platform_data nas100d_led_data = {
94 .num_leds = ARRAY_SIZE(nas100d_led_pins),
95 .leds = nas100d_led_pins,
96};
97
df6934b3 98static struct platform_device nas100d_leds = {
1208ebf2 99 .name = "leds-gpio",
df6934b3 100 .id = -1,
1208ebf2 101 .dev.platform_data = &nas100d_led_data,
df6934b3 102};
df6934b3 103
b2e63555 104static struct gpiod_lookup_table nas100d_i2c_gpiod_table = {
f59c303b 105 .dev_id = "i2c-gpio.0",
b2e63555
LW
106 .table = {
107 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN,
4d0ce62c 108 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
b2e63555 109 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN,
4d0ce62c 110 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
b2e63555 111 },
3145d8a6
RW
112};
113
5a4a2387
MLJ
114static struct platform_device nas100d_i2c_gpio = {
115 .name = "i2c-gpio",
3145d8a6 116 .id = 0,
5a4a2387 117 .dev = {
b2e63555 118 .platform_data = NULL,
5a4a2387 119 },
3145d8a6
RW
120};
121
122static struct resource nas100d_uart_resources[] = {
123 {
124 .start = IXP4XX_UART1_BASE_PHYS,
125 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
126 .flags = IORESOURCE_MEM,
127 },
128 {
129 .start = IXP4XX_UART2_BASE_PHYS,
130 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
131 .flags = IORESOURCE_MEM,
132 }
133};
134
135static struct plat_serial8250_port nas100d_uart_data[] = {
136 {
137 .mapbase = IXP4XX_UART1_BASE_PHYS,
138 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
139 .irq = IRQ_IXP4XX_UART1,
140 .flags = UPF_BOOT_AUTOCONF,
141 .iotype = UPIO_MEM,
142 .regshift = 2,
143 .uartclk = IXP4XX_UART_XTAL,
144 },
145 {
146 .mapbase = IXP4XX_UART2_BASE_PHYS,
147 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
148 .irq = IRQ_IXP4XX_UART2,
149 .flags = UPF_BOOT_AUTOCONF,
150 .iotype = UPIO_MEM,
151 .regshift = 2,
152 .uartclk = IXP4XX_UART_XTAL,
153 },
154 { }
155};
156
157static struct platform_device nas100d_uart = {
158 .name = "serial8250",
159 .id = PLAT8250_DEV_PLATFORM,
160 .dev.platform_data = nas100d_uart_data,
161 .num_resources = 2,
162 .resource = nas100d_uart_resources,
163};
164
b7edc84a
RW
165/* Built-in 10/100 Ethernet MAC interfaces */
166static struct eth_plat_info nas100d_plat_eth[] = {
167 {
168 .phy = 0,
169 .rxq = 3,
170 .txreadyq = 20,
171 }
172};
173
174static struct platform_device nas100d_eth[] = {
175 {
176 .name = "ixp4xx_eth",
177 .id = IXP4XX_ETH_NPEB,
178 .dev.platform_data = nas100d_plat_eth,
179 }
180};
181
3145d8a6 182static struct platform_device *nas100d_devices[] __initdata = {
5a4a2387 183 &nas100d_i2c_gpio,
3145d8a6 184 &nas100d_flash,
df6934b3 185 &nas100d_leds,
b7edc84a 186 &nas100d_eth[0],
3145d8a6
RW
187};
188
189static void nas100d_power_off(void)
190{
191 /* This causes the box to drop the power and go dead. */
192
8040dd09
LW
193 /* enable the pwr cntl gpio and assert power off */
194 gpio_direction_output(NAS100D_PO_GPIO, 1);
3145d8a6
RW
195}
196
c7d1623e
RW
197/* This is used to make sure the power-button pusher is serious. The button
198 * must be held until the value of this counter reaches zero.
199 */
200static int power_button_countdown;
201
202/* Must hold the button down for at least this many counts to be processed */
203#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
204
24ed960a 205static void nas100d_power_handler(struct timer_list *unused);
1d27e3e2 206static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler);
c7d1623e 207
24ed960a 208static void nas100d_power_handler(struct timer_list *unused)
c7d1623e
RW
209{
210 /* This routine is called twice per second to check the
211 * state of the power button.
212 */
213
214 if (gpio_get_value(NAS100D_PB_GPIO)) {
215
216 /* IO Pin is 1 (button pushed) */
217 if (power_button_countdown > 0)
218 power_button_countdown--;
219
220 } else {
221
222 /* Done on button release, to allow for auto-power-on mods. */
223 if (power_button_countdown == 0) {
224 /* Signal init to do the ctrlaltdel action,
225 * this will bypass init if it hasn't started
226 * and do a kernel_restart.
227 */
228 ctrl_alt_del();
229
230 /* Change the state of the power LED to "blink" */
8040dd09 231 gpio_set_value(NAS100D_LED_PWR_GPIO, 0);
c7d1623e
RW
232 } else {
233 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
234 }
235 }
236
237 mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
238}
239
240static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
241{
242 /* This is the paper-clip reset, it shuts the machine down directly. */
243 machine_power_off();
244
245 return IRQ_HANDLED;
246}
247
8040dd09
LW
248static int __init nas100d_gpio_init(void)
249{
250 if (!machine_is_nas100d())
251 return 0;
252
253 /*
254 * The power button on the Iomega NAS100d is on GPIO 14, but
255 * it cannot handle interrupts on that GPIO line. So we'll
256 * have to poll it with a kernel timer.
257 */
258
259 /* Request the power off GPIO */
260 gpio_request(NAS100D_PO_GPIO, "power off");
261
262 /* Make sure that the power button GPIO is set up as an input */
263 gpio_request(NAS100D_PB_GPIO, "power button");
264 gpio_direction_input(NAS100D_PB_GPIO);
265
266 /* Set the initial value for the power button IRQ handler */
267 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
268
269 mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
270
271 return 0;
272}
273device_initcall(nas100d_gpio_init);
274
3145d8a6
RW
275static void __init nas100d_init(void)
276{
b7edc84a
RW
277 uint8_t __iomem *f;
278 int i;
279
3145d8a6
RW
280 ixp4xx_sys_init();
281
dcc8fa50
AZ
282 /* gpio 14 and 15 are _not_ clocks */
283 *IXP4XX_GPIO_GPCLKR = 0;
284
54e269ea
DS
285 nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
286 nas100d_flash_resource.end =
287 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
288
b2e63555 289 gpiod_add_lookup_table(&nas100d_i2c_gpiod_table);
400d8231
RW
290 i2c_register_board_info(0, nas100d_i2c_board_info,
291 ARRAY_SIZE(nas100d_i2c_board_info));
292
cc50a0df
MLJ
293 /*
294 * This is only useful on a modified machine, but it is valuable
df6934b3
RW
295 * to have it first in order to see debug messages, and so that
296 * it does *not* get removed if platform_add_devices fails!
297 */
298 (void)platform_device_register(&nas100d_uart);
299
3145d8a6 300 platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
b7edc84a 301
c7d1623e
RW
302 pm_power_off = nas100d_power_off;
303
304 if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
1ee6564d 305 IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
c7d1623e
RW
306
307 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
308 gpio_to_irq(NAS100D_RB_GPIO));
309 }
310
b7edc84a
RW
311 /*
312 * Map in a portion of the flash and read the MAC address.
313 * Since it is stored in BE in the flash itself, we need to
314 * byteswap it if we're in LE mode.
315 */
316 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
317 if (f) {
318 for (i = 0; i < 6; i++)
319#ifdef __ARMEB__
320 nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
321#else
322 nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
323#endif
324 iounmap(f);
325 }
e174961c
JB
326 printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",
327 nas100d_plat_eth[0].hwaddr);
b7edc84a 328
3145d8a6
RW
329}
330
331MACHINE_START(NAS100D, "Iomega NAS 100d")
332 /* Maintainer: www.nslu2-linux.org */
e022c729 333 .atag_offset = 0x100,
3145d8a6 334 .map_io = ixp4xx_map_io,
f449588c 335 .init_early = ixp4xx_init_early,
3145d8a6 336 .init_irq = ixp4xx_init_irq,
6bb27d73 337 .init_time = ixp4xx_timer_init,
3145d8a6 338 .init_machine = nas100d_init,
7553ee77
NP
339#if defined(CONFIG_PCI)
340 .dma_zone_size = SZ_64M,
341#endif
d1b860fb 342 .restart = ixp4xx_restart,
3145d8a6 343MACHINE_END