kvm tools, setup: Create private directory
[linux-2.6/next.git] / arch / arm / mach-ixp4xx / dsmg600-setup.c
blobd398229cfaa5d40b09e13effcf660dc71e97df8f
1 /*
2 * DSM-G600 board-setup
4 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
5 * Copyright (C) 2006 Tower Technologies
7 * based on ixdp425-setup.c:
8 * Copyright (C) 2003-2004 MontaVista Software, Inc.
9 * based on nslu2-power.c:
10 * Copyright (C) 2005 Tower Technologies
11 * based on nslu2-io.c:
12 * Copyright (C) 2004 Karen Spearel
14 * Author: Alessandro Zummo <a.zummo@towertech.it>
15 * Author: Michael Westerhof <mwester@dls.net>
16 * Author: Rod Whitby <rod@whitby.id.au>
17 * Maintainers: http://www.nslu2-linux.org/
20 #include <linux/irq.h>
21 #include <linux/jiffies.h>
22 #include <linux/timer.h>
23 #include <linux/serial.h>
24 #include <linux/serial_8250.h>
25 #include <linux/leds.h>
26 #include <linux/reboot.h>
27 #include <linux/i2c.h>
28 #include <linux/i2c-gpio.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/flash.h>
33 #include <asm/mach/time.h>
34 #include <asm/gpio.h>
36 #define DSMG600_SDA_PIN 5
37 #define DSMG600_SCL_PIN 4
39 /* DSM-G600 Timer Setting */
40 #define DSMG600_FREQ 66000000
42 /* Buttons */
43 #define DSMG600_PB_GPIO 15 /* power button */
44 #define DSMG600_RB_GPIO 3 /* reset button */
46 /* Power control */
47 #define DSMG600_PO_GPIO 2 /* power off */
49 /* LEDs */
50 #define DSMG600_LED_PWR_GPIO 0
51 #define DSMG600_LED_WLAN_GPIO 14
53 static struct flash_platform_data dsmg600_flash_data = {
54 .map_name = "cfi_probe",
55 .width = 2,
58 static struct resource dsmg600_flash_resource = {
59 .flags = IORESOURCE_MEM,
62 static struct platform_device dsmg600_flash = {
63 .name = "IXP4XX-Flash",
64 .id = 0,
65 .dev.platform_data = &dsmg600_flash_data,
66 .num_resources = 1,
67 .resource = &dsmg600_flash_resource,
70 static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
71 .sda_pin = DSMG600_SDA_PIN,
72 .scl_pin = DSMG600_SCL_PIN,
75 static struct platform_device dsmg600_i2c_gpio = {
76 .name = "i2c-gpio",
77 .id = 0,
78 .dev = {
79 .platform_data = &dsmg600_i2c_gpio_data,
83 static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
85 I2C_BOARD_INFO("pcf8563", 0x51),
89 static struct gpio_led dsmg600_led_pins[] = {
91 .name = "dsmg600:green:power",
92 .gpio = DSMG600_LED_PWR_GPIO,
95 .name = "dsmg600:green:wlan",
96 .gpio = DSMG600_LED_WLAN_GPIO,
97 .active_low = true,
101 static struct gpio_led_platform_data dsmg600_led_data = {
102 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
103 .leds = dsmg600_led_pins,
106 static struct platform_device dsmg600_leds = {
107 .name = "leds-gpio",
108 .id = -1,
109 .dev.platform_data = &dsmg600_led_data,
112 static struct resource dsmg600_uart_resources[] = {
114 .start = IXP4XX_UART1_BASE_PHYS,
115 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
116 .flags = IORESOURCE_MEM,
119 .start = IXP4XX_UART2_BASE_PHYS,
120 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
121 .flags = IORESOURCE_MEM,
125 static struct plat_serial8250_port dsmg600_uart_data[] = {
127 .mapbase = IXP4XX_UART1_BASE_PHYS,
128 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
129 .irq = IRQ_IXP4XX_UART1,
130 .flags = UPF_BOOT_AUTOCONF,
131 .iotype = UPIO_MEM,
132 .regshift = 2,
133 .uartclk = IXP4XX_UART_XTAL,
136 .mapbase = IXP4XX_UART2_BASE_PHYS,
137 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
138 .irq = IRQ_IXP4XX_UART2,
139 .flags = UPF_BOOT_AUTOCONF,
140 .iotype = UPIO_MEM,
141 .regshift = 2,
142 .uartclk = IXP4XX_UART_XTAL,
147 static struct platform_device dsmg600_uart = {
148 .name = "serial8250",
149 .id = PLAT8250_DEV_PLATFORM,
150 .dev.platform_data = dsmg600_uart_data,
151 .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
152 .resource = dsmg600_uart_resources,
155 static struct platform_device *dsmg600_devices[] __initdata = {
156 &dsmg600_i2c_gpio,
157 &dsmg600_flash,
158 &dsmg600_leds,
161 static void dsmg600_power_off(void)
163 /* enable the pwr cntl gpio */
164 gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
166 /* poweroff */
167 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
170 /* This is used to make sure the power-button pusher is serious. The button
171 * must be held until the value of this counter reaches zero.
173 static int power_button_countdown;
175 /* Must hold the button down for at least this many counts to be processed */
176 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
178 static void dsmg600_power_handler(unsigned long data);
179 static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
181 static void dsmg600_power_handler(unsigned long data)
183 /* This routine is called twice per second to check the
184 * state of the power button.
187 if (gpio_get_value(DSMG600_PB_GPIO)) {
189 /* IO Pin is 1 (button pushed) */
190 if (power_button_countdown > 0)
191 power_button_countdown--;
193 } else {
195 /* Done on button release, to allow for auto-power-on mods. */
196 if (power_button_countdown == 0) {
197 /* Signal init to do the ctrlaltdel action,
198 * this will bypass init if it hasn't started
199 * and do a kernel_restart.
201 ctrl_alt_del();
203 /* Change the state of the power LED to "blink" */
204 gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
205 } else {
206 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
210 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
213 static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
215 /* This is the paper-clip reset, it shuts the machine down directly. */
216 machine_power_off();
218 return IRQ_HANDLED;
221 static void __init dsmg600_timer_init(void)
223 /* The xtal on this machine is non-standard. */
224 ixp4xx_timer_freq = DSMG600_FREQ;
226 /* Call standard timer_init function. */
227 ixp4xx_timer_init();
230 static struct sys_timer dsmg600_timer = {
231 .init = dsmg600_timer_init,
234 static void __init dsmg600_init(void)
236 ixp4xx_sys_init();
238 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
239 *IXP4XX_GPIO_GPCLKR = 0;
241 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
242 dsmg600_flash_resource.end =
243 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
245 i2c_register_board_info(0, dsmg600_i2c_board_info,
246 ARRAY_SIZE(dsmg600_i2c_board_info));
248 /* The UART is required on the DSM-G600 (Redboot cannot use the
249 * NIC) -- do it here so that it does *not* get removed if
250 * platform_add_devices fails!
252 (void)platform_device_register(&dsmg600_uart);
254 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
256 pm_power_off = dsmg600_power_off;
258 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
259 IRQF_DISABLED | IRQF_TRIGGER_LOW,
260 "DSM-G600 reset button", NULL) < 0) {
262 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
263 gpio_to_irq(DSMG600_RB_GPIO));
266 /* The power button on the D-Link DSM-G600 is on GPIO 15, but
267 * it cannot handle interrupts on that GPIO line. So we'll
268 * have to poll it with a kernel timer.
271 /* Make sure that the power button GPIO is set up as an input */
272 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
274 /* Set the initial value for the power button IRQ handler */
275 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
277 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
280 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
281 /* Maintainer: www.nslu2-linux.org */
282 .boot_params = 0x00000100,
283 .map_io = ixp4xx_map_io,
284 .init_irq = ixp4xx_init_irq,
285 .timer = &dsmg600_timer,
286 .init_machine = dsmg600_init,
287 MACHINE_END