2 * arch/arm/mach-ixp4xx/nas100d-setup.c
6 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
8 * based on ixdp425-setup.c:
9 * Copyright (C) 2003-2004 MontaVista Software, Inc.
10 * based on nas100d-power.c:
11 * Copyright (C) 2005 Tower Technologies
12 * based on nas100d-io.c
13 * Copyright (C) 2004 Karen Spearel
15 * Author: Alessandro Zummo <a.zummo@towertech.it>
16 * Author: Rod Whitby <rod@whitby.id.au>
17 * Maintainers: http://www.nslu2-linux.org/
20 #include <linux/gpio.h>
21 #include <linux/if_ether.h>
22 #include <linux/irq.h>
23 #include <linux/jiffies.h>
24 #include <linux/timer.h>
25 #include <linux/serial.h>
26 #include <linux/serial_8250.h>
27 #include <linux/leds.h>
28 #include <linux/reboot.h>
29 #include <linux/i2c.h>
30 #include <linux/i2c-gpio.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/flash.h>
36 #define NAS100D_SDA_PIN 5
37 #define NAS100D_SCL_PIN 6
40 #define NAS100D_PB_GPIO 14 /* power button */
41 #define NAS100D_RB_GPIO 4 /* reset button */
44 #define NAS100D_PO_GPIO 12 /* power off */
47 #define NAS100D_LED_WLAN_GPIO 0
48 #define NAS100D_LED_DISK_GPIO 3
49 #define NAS100D_LED_PWR_GPIO 15
51 static struct flash_platform_data nas100d_flash_data
= {
52 .map_name
= "cfi_probe",
56 static struct resource nas100d_flash_resource
= {
57 .flags
= IORESOURCE_MEM
,
60 static struct platform_device nas100d_flash
= {
61 .name
= "IXP4XX-Flash",
63 .dev
.platform_data
= &nas100d_flash_data
,
65 .resource
= &nas100d_flash_resource
,
68 static struct i2c_board_info __initdata nas100d_i2c_board_info
[] = {
70 I2C_BOARD_INFO("pcf8563", 0x51),
74 static struct gpio_led nas100d_led_pins
[] = {
76 .name
= "nas100d:green:wlan",
77 .gpio
= NAS100D_LED_WLAN_GPIO
,
81 .name
= "nas100d:blue:power", /* (off=flashing) */
82 .gpio
= NAS100D_LED_PWR_GPIO
,
86 .name
= "nas100d:yellow:disk",
87 .gpio
= NAS100D_LED_DISK_GPIO
,
92 static struct gpio_led_platform_data nas100d_led_data
= {
93 .num_leds
= ARRAY_SIZE(nas100d_led_pins
),
94 .leds
= nas100d_led_pins
,
97 static struct platform_device nas100d_leds
= {
100 .dev
.platform_data
= &nas100d_led_data
,
103 static struct i2c_gpio_platform_data nas100d_i2c_gpio_data
= {
104 .sda_pin
= NAS100D_SDA_PIN
,
105 .scl_pin
= NAS100D_SCL_PIN
,
108 static struct platform_device nas100d_i2c_gpio
= {
112 .platform_data
= &nas100d_i2c_gpio_data
,
116 static struct resource nas100d_uart_resources
[] = {
118 .start
= IXP4XX_UART1_BASE_PHYS
,
119 .end
= IXP4XX_UART1_BASE_PHYS
+ 0x0fff,
120 .flags
= IORESOURCE_MEM
,
123 .start
= IXP4XX_UART2_BASE_PHYS
,
124 .end
= IXP4XX_UART2_BASE_PHYS
+ 0x0fff,
125 .flags
= IORESOURCE_MEM
,
129 static struct plat_serial8250_port nas100d_uart_data
[] = {
131 .mapbase
= IXP4XX_UART1_BASE_PHYS
,
132 .membase
= (char *)IXP4XX_UART1_BASE_VIRT
+ REG_OFFSET
,
133 .irq
= IRQ_IXP4XX_UART1
,
134 .flags
= UPF_BOOT_AUTOCONF
,
137 .uartclk
= IXP4XX_UART_XTAL
,
140 .mapbase
= IXP4XX_UART2_BASE_PHYS
,
141 .membase
= (char *)IXP4XX_UART2_BASE_VIRT
+ REG_OFFSET
,
142 .irq
= IRQ_IXP4XX_UART2
,
143 .flags
= UPF_BOOT_AUTOCONF
,
146 .uartclk
= IXP4XX_UART_XTAL
,
151 static struct platform_device nas100d_uart
= {
152 .name
= "serial8250",
153 .id
= PLAT8250_DEV_PLATFORM
,
154 .dev
.platform_data
= nas100d_uart_data
,
156 .resource
= nas100d_uart_resources
,
159 /* Built-in 10/100 Ethernet MAC interfaces */
160 static struct eth_plat_info nas100d_plat_eth
[] = {
168 static struct platform_device nas100d_eth
[] = {
170 .name
= "ixp4xx_eth",
171 .id
= IXP4XX_ETH_NPEB
,
172 .dev
.platform_data
= nas100d_plat_eth
,
176 static struct platform_device
*nas100d_devices
[] __initdata
= {
183 static void nas100d_power_off(void)
185 /* This causes the box to drop the power and go dead. */
187 /* enable the pwr cntl gpio and assert power off */
188 gpio_direction_output(NAS100D_PO_GPIO
, 1);
191 /* This is used to make sure the power-button pusher is serious. The button
192 * must be held until the value of this counter reaches zero.
194 static int power_button_countdown
;
196 /* Must hold the button down for at least this many counts to be processed */
197 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
199 static void nas100d_power_handler(unsigned long data
);
200 static DEFINE_TIMER(nas100d_power_timer
, nas100d_power_handler
, 0, 0);
202 static void nas100d_power_handler(unsigned long data
)
204 /* This routine is called twice per second to check the
205 * state of the power button.
208 if (gpio_get_value(NAS100D_PB_GPIO
)) {
210 /* IO Pin is 1 (button pushed) */
211 if (power_button_countdown
> 0)
212 power_button_countdown
--;
216 /* Done on button release, to allow for auto-power-on mods. */
217 if (power_button_countdown
== 0) {
218 /* Signal init to do the ctrlaltdel action,
219 * this will bypass init if it hasn't started
220 * and do a kernel_restart.
224 /* Change the state of the power LED to "blink" */
225 gpio_set_value(NAS100D_LED_PWR_GPIO
, 0);
227 power_button_countdown
= PBUTTON_HOLDDOWN_COUNT
;
231 mod_timer(&nas100d_power_timer
, jiffies
+ msecs_to_jiffies(500));
234 static irqreturn_t
nas100d_reset_handler(int irq
, void *dev_id
)
236 /* This is the paper-clip reset, it shuts the machine down directly. */
242 static int __init
nas100d_gpio_init(void)
244 if (!machine_is_nas100d())
248 * The power button on the Iomega NAS100d is on GPIO 14, but
249 * it cannot handle interrupts on that GPIO line. So we'll
250 * have to poll it with a kernel timer.
253 /* Request the power off GPIO */
254 gpio_request(NAS100D_PO_GPIO
, "power off");
256 /* Make sure that the power button GPIO is set up as an input */
257 gpio_request(NAS100D_PB_GPIO
, "power button");
258 gpio_direction_input(NAS100D_PB_GPIO
);
260 /* Set the initial value for the power button IRQ handler */
261 power_button_countdown
= PBUTTON_HOLDDOWN_COUNT
;
263 mod_timer(&nas100d_power_timer
, jiffies
+ msecs_to_jiffies(500));
267 device_initcall(nas100d_gpio_init
);
269 static void __init
nas100d_init(void)
276 /* gpio 14 and 15 are _not_ clocks */
277 *IXP4XX_GPIO_GPCLKR
= 0;
279 nas100d_flash_resource
.start
= IXP4XX_EXP_BUS_BASE(0);
280 nas100d_flash_resource
.end
=
281 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size
- 1;
283 i2c_register_board_info(0, nas100d_i2c_board_info
,
284 ARRAY_SIZE(nas100d_i2c_board_info
));
287 * This is only useful on a modified machine, but it is valuable
288 * to have it first in order to see debug messages, and so that
289 * it does *not* get removed if platform_add_devices fails!
291 (void)platform_device_register(&nas100d_uart
);
293 platform_add_devices(nas100d_devices
, ARRAY_SIZE(nas100d_devices
));
295 pm_power_off
= nas100d_power_off
;
297 if (request_irq(gpio_to_irq(NAS100D_RB_GPIO
), &nas100d_reset_handler
,
298 IRQF_TRIGGER_LOW
, "NAS100D reset button", NULL
) < 0) {
300 printk(KERN_DEBUG
"Reset Button IRQ %d not available\n",
301 gpio_to_irq(NAS100D_RB_GPIO
));
305 * Map in a portion of the flash and read the MAC address.
306 * Since it is stored in BE in the flash itself, we need to
307 * byteswap it if we're in LE mode.
309 f
= ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
311 for (i
= 0; i
< 6; i
++)
313 nas100d_plat_eth
[0].hwaddr
[i
] = readb(f
+ 0xFC0FD8 + i
);
315 nas100d_plat_eth
[0].hwaddr
[i
] = readb(f
+ 0xFC0FD8 + (i
^3));
319 printk(KERN_INFO
"NAS100D: Using MAC address %pM for port 0\n",
320 nas100d_plat_eth
[0].hwaddr
);
324 MACHINE_START(NAS100D
, "Iomega NAS 100d")
325 /* Maintainer: www.nslu2-linux.org */
326 .atag_offset
= 0x100,
327 .map_io
= ixp4xx_map_io
,
328 .init_early
= ixp4xx_init_early
,
329 .init_irq
= ixp4xx_init_irq
,
330 .init_time
= ixp4xx_timer_init
,
331 .init_machine
= nas100d_init
,
332 #if defined(CONFIG_PCI)
333 .dma_zone_size
= SZ_64M
,
335 .restart
= ixp4xx_restart
,