1 // SPDX-License-Identifier: GPL-2.0
3 * arch/arm/mach-ixp4xx/nas100d-setup.c
7 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
9 * based on ixdp425-setup.c:
10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
11 * based on nas100d-power.c:
12 * Copyright (C) 2005 Tower Technologies
13 * based on nas100d-io.c
14 * Copyright (C) 2004 Karen Spearel
16 * Author: Alessandro Zummo <a.zummo@towertech.it>
17 * Author: Rod Whitby <rod@whitby.id.au>
18 * Maintainers: http://www.nslu2-linux.org/
21 #include <linux/gpio.h>
22 #include <linux/if_ether.h>
23 #include <linux/irq.h>
24 #include <linux/jiffies.h>
25 #include <linux/timer.h>
26 #include <linux/serial.h>
27 #include <linux/serial_8250.h>
28 #include <linux/leds.h>
29 #include <linux/reboot.h>
30 #include <linux/i2c.h>
31 #include <linux/gpio/machine.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/flash.h>
36 #include <mach/hardware.h>
40 #define NAS100D_SDA_PIN 5
41 #define NAS100D_SCL_PIN 6
44 #define NAS100D_PB_GPIO 14 /* power button */
45 #define NAS100D_RB_GPIO 4 /* reset button */
48 #define NAS100D_PO_GPIO 12 /* power off */
51 #define NAS100D_LED_WLAN_GPIO 0
52 #define NAS100D_LED_DISK_GPIO 3
53 #define NAS100D_LED_PWR_GPIO 15
55 static struct flash_platform_data nas100d_flash_data = {
56 .map_name = "cfi_probe",
60 static struct resource nas100d_flash_resource = {
61 .flags = IORESOURCE_MEM,
64 static struct platform_device nas100d_flash = {
65 .name = "IXP4XX-Flash",
67 .dev.platform_data = &nas100d_flash_data,
69 .resource = &nas100d_flash_resource,
72 static struct i2c_board_info __initdata nas100d_i2c_board_info [] = {
74 I2C_BOARD_INFO("pcf8563", 0x51),
78 static struct gpio_led nas100d_led_pins[] = {
80 .name = "nas100d:green:wlan",
81 .gpio = NAS100D_LED_WLAN_GPIO,
85 .name = "nas100d:blue:power", /* (off=flashing) */
86 .gpio = NAS100D_LED_PWR_GPIO,
90 .name = "nas100d:yellow:disk",
91 .gpio = NAS100D_LED_DISK_GPIO,
96 static struct gpio_led_platform_data nas100d_led_data = {
97 .num_leds = ARRAY_SIZE(nas100d_led_pins),
98 .leds = nas100d_led_pins,
101 static struct platform_device nas100d_leds = {
104 .dev.platform_data = &nas100d_led_data,
107 static struct gpiod_lookup_table nas100d_i2c_gpiod_table = {
108 .dev_id = "i2c-gpio.0",
110 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN,
111 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
112 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN,
113 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
117 static struct platform_device nas100d_i2c_gpio = {
121 .platform_data = NULL,
125 static struct resource nas100d_uart_resources[] = {
127 .start = IXP4XX_UART1_BASE_PHYS,
128 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
129 .flags = IORESOURCE_MEM,
132 .start = IXP4XX_UART2_BASE_PHYS,
133 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
134 .flags = IORESOURCE_MEM,
138 static struct plat_serial8250_port nas100d_uart_data[] = {
140 .mapbase = IXP4XX_UART1_BASE_PHYS,
141 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
142 .irq = IRQ_IXP4XX_UART1,
143 .flags = UPF_BOOT_AUTOCONF,
146 .uartclk = IXP4XX_UART_XTAL,
149 .mapbase = IXP4XX_UART2_BASE_PHYS,
150 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
151 .irq = IRQ_IXP4XX_UART2,
152 .flags = UPF_BOOT_AUTOCONF,
155 .uartclk = IXP4XX_UART_XTAL,
160 static struct platform_device nas100d_uart = {
161 .name = "serial8250",
162 .id = PLAT8250_DEV_PLATFORM,
163 .dev.platform_data = nas100d_uart_data,
165 .resource = nas100d_uart_resources,
168 /* Built-in 10/100 Ethernet MAC interfaces */
169 static struct resource nas100d_eth_resources[] = {
171 .start = IXP4XX_EthB_BASE_PHYS,
172 .end = IXP4XX_EthB_BASE_PHYS + 0x0fff,
173 .flags = IORESOURCE_MEM,
177 static struct eth_plat_info nas100d_plat_eth[] = {
185 static struct platform_device nas100d_eth[] = {
187 .name = "ixp4xx_eth",
188 .id = IXP4XX_ETH_NPEB,
189 .dev.platform_data = nas100d_plat_eth,
190 .num_resources = ARRAY_SIZE(nas100d_eth_resources),
191 .resource = nas100d_eth_resources,
195 static struct platform_device *nas100d_devices[] __initdata = {
202 static void nas100d_power_off(void)
204 /* This causes the box to drop the power and go dead. */
206 /* enable the pwr cntl gpio and assert power off */
207 gpio_direction_output(NAS100D_PO_GPIO, 1);
210 /* This is used to make sure the power-button pusher is serious. The button
211 * must be held until the value of this counter reaches zero.
213 static int power_button_countdown;
215 /* Must hold the button down for at least this many counts to be processed */
216 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
218 static void nas100d_power_handler(struct timer_list *unused);
219 static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler);
221 static void nas100d_power_handler(struct timer_list *unused)
223 /* This routine is called twice per second to check the
224 * state of the power button.
227 if (gpio_get_value(NAS100D_PB_GPIO)) {
229 /* IO Pin is 1 (button pushed) */
230 if (power_button_countdown > 0)
231 power_button_countdown--;
235 /* Done on button release, to allow for auto-power-on mods. */
236 if (power_button_countdown == 0) {
237 /* Signal init to do the ctrlaltdel action,
238 * this will bypass init if it hasn't started
239 * and do a kernel_restart.
243 /* Change the state of the power LED to "blink" */
244 gpio_set_value(NAS100D_LED_PWR_GPIO, 0);
246 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
250 mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
253 static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
255 /* This is the paper-clip reset, it shuts the machine down directly. */
261 static int __init nas100d_gpio_init(void)
263 if (!machine_is_nas100d())
267 * The power button on the Iomega NAS100d is on GPIO 14, but
268 * it cannot handle interrupts on that GPIO line. So we'll
269 * have to poll it with a kernel timer.
272 /* Request the power off GPIO */
273 gpio_request(NAS100D_PO_GPIO, "power off");
275 /* Make sure that the power button GPIO is set up as an input */
276 gpio_request(NAS100D_PB_GPIO, "power button");
277 gpio_direction_input(NAS100D_PB_GPIO);
279 /* Set the initial value for the power button IRQ handler */
280 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
282 mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
286 device_initcall(nas100d_gpio_init);
288 static void __init nas100d_init(void)
295 nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
296 nas100d_flash_resource.end =
297 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
299 gpiod_add_lookup_table(&nas100d_i2c_gpiod_table);
300 i2c_register_board_info(0, nas100d_i2c_board_info,
301 ARRAY_SIZE(nas100d_i2c_board_info));
304 * This is only useful on a modified machine, but it is valuable
305 * to have it first in order to see debug messages, and so that
306 * it does *not* get removed if platform_add_devices fails!
308 (void)platform_device_register(&nas100d_uart);
310 platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
312 pm_power_off = nas100d_power_off;
314 if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
315 IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
317 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
318 gpio_to_irq(NAS100D_RB_GPIO));
322 * Map in a portion of the flash and read the MAC address.
323 * Since it is stored in BE in the flash itself, we need to
324 * byteswap it if we're in LE mode.
326 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
328 for (i = 0; i < 6; i++)
330 nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
332 nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
336 printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",
337 nas100d_plat_eth[0].hwaddr);
341 MACHINE_START(NAS100D, "Iomega NAS 100d")
342 /* Maintainer: www.nslu2-linux.org */
343 .atag_offset = 0x100,
344 .map_io = ixp4xx_map_io,
345 .init_early = ixp4xx_init_early,
346 .init_irq = ixp4xx_init_irq,
347 .init_time = ixp4xx_timer_init,
348 .init_machine = nas100d_init,
349 #if defined(CONFIG_PCI)
350 .dma_zone_size = SZ_64M,
352 .restart = ixp4xx_restart,