Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / arch / arm / mach-ixp4xx / dsmg600-setup.c
blob8cb07437a807f81d92eed0bbd1a7d82b5118ab5d
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 static struct flash_platform_data dsmg600_flash_data = {
37 .map_name = "cfi_probe",
38 .width = 2,
41 static struct resource dsmg600_flash_resource = {
42 .flags = IORESOURCE_MEM,
45 static struct platform_device dsmg600_flash = {
46 .name = "IXP4XX-Flash",
47 .id = 0,
48 .dev.platform_data = &dsmg600_flash_data,
49 .num_resources = 1,
50 .resource = &dsmg600_flash_resource,
53 static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
54 .sda_pin = DSMG600_SDA_PIN,
55 .scl_pin = DSMG600_SCL_PIN,
58 static struct platform_device dsmg600_i2c_gpio = {
59 .name = "i2c-gpio",
60 .id = 0,
61 .dev = {
62 .platform_data = &dsmg600_i2c_gpio_data,
66 static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
68 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
72 static struct gpio_led dsmg600_led_pins[] = {
74 .name = "dsmg600:green:power",
75 .gpio = DSMG600_LED_PWR_GPIO,
78 .name = "dsmg600:green:wlan",
79 .gpio = DSMG600_LED_WLAN_GPIO,
80 .active_low = true,
84 static struct gpio_led_platform_data dsmg600_led_data = {
85 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
86 .leds = dsmg600_led_pins,
89 static struct platform_device dsmg600_leds = {
90 .name = "leds-gpio",
91 .id = -1,
92 .dev.platform_data = &dsmg600_led_data,
95 static struct resource dsmg600_uart_resources[] = {
97 .start = IXP4XX_UART1_BASE_PHYS,
98 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
99 .flags = IORESOURCE_MEM,
102 .start = IXP4XX_UART2_BASE_PHYS,
103 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
104 .flags = IORESOURCE_MEM,
108 static struct plat_serial8250_port dsmg600_uart_data[] = {
110 .mapbase = IXP4XX_UART1_BASE_PHYS,
111 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
112 .irq = IRQ_IXP4XX_UART1,
113 .flags = UPF_BOOT_AUTOCONF,
114 .iotype = UPIO_MEM,
115 .regshift = 2,
116 .uartclk = IXP4XX_UART_XTAL,
119 .mapbase = IXP4XX_UART2_BASE_PHYS,
120 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
121 .irq = IRQ_IXP4XX_UART2,
122 .flags = UPF_BOOT_AUTOCONF,
123 .iotype = UPIO_MEM,
124 .regshift = 2,
125 .uartclk = IXP4XX_UART_XTAL,
130 static struct platform_device dsmg600_uart = {
131 .name = "serial8250",
132 .id = PLAT8250_DEV_PLATFORM,
133 .dev.platform_data = dsmg600_uart_data,
134 .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
135 .resource = dsmg600_uart_resources,
138 static struct platform_device *dsmg600_devices[] __initdata = {
139 &dsmg600_i2c_gpio,
140 &dsmg600_flash,
141 &dsmg600_leds,
144 static void dsmg600_power_off(void)
146 /* enable the pwr cntl gpio */
147 gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
149 /* poweroff */
150 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
153 /* This is used to make sure the power-button pusher is serious. The button
154 * must be held until the value of this counter reaches zero.
156 static int power_button_countdown;
158 /* Must hold the button down for at least this many counts to be processed */
159 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
161 static void dsmg600_power_handler(unsigned long data);
162 static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
164 static void dsmg600_power_handler(unsigned long data)
166 /* This routine is called twice per second to check the
167 * state of the power button.
170 if (gpio_get_value(DSMG600_PB_GPIO)) {
172 /* IO Pin is 1 (button pushed) */
173 if (power_button_countdown > 0)
174 power_button_countdown--;
176 } else {
178 /* Done on button release, to allow for auto-power-on mods. */
179 if (power_button_countdown == 0) {
180 /* Signal init to do the ctrlaltdel action,
181 * this will bypass init if it hasn't started
182 * and do a kernel_restart.
184 ctrl_alt_del();
186 /* Change the state of the power LED to "blink" */
187 gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
188 } else {
189 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
193 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
196 static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
198 /* This is the paper-clip reset, it shuts the machine down directly. */
199 machine_power_off();
201 return IRQ_HANDLED;
204 static void __init dsmg600_timer_init(void)
206 /* The xtal on this machine is non-standard. */
207 ixp4xx_timer_freq = DSMG600_FREQ;
209 /* Call standard timer_init function. */
210 ixp4xx_timer_init();
213 static struct sys_timer dsmg600_timer = {
214 .init = dsmg600_timer_init,
217 static void __init dsmg600_init(void)
219 ixp4xx_sys_init();
221 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
222 *IXP4XX_GPIO_GPCLKR = 0;
224 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
225 dsmg600_flash_resource.end =
226 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
228 i2c_register_board_info(0, dsmg600_i2c_board_info,
229 ARRAY_SIZE(dsmg600_i2c_board_info));
231 /* The UART is required on the DSM-G600 (Redboot cannot use the
232 * NIC) -- do it here so that it does *not* get removed if
233 * platform_add_devices fails!
235 (void)platform_device_register(&dsmg600_uart);
237 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
239 pm_power_off = dsmg600_power_off;
241 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
242 IRQF_DISABLED | IRQF_TRIGGER_LOW,
243 "DSM-G600 reset button", NULL) < 0) {
245 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
246 gpio_to_irq(DSMG600_RB_GPIO));
249 /* The power button on the D-Link DSM-G600 is on GPIO 15, but
250 * it cannot handle interrupts on that GPIO line. So we'll
251 * have to poll it with a kernel timer.
254 /* Make sure that the power button GPIO is set up as an input */
255 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
257 /* Set the initial value for the power button IRQ handler */
258 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
260 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
263 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
264 /* Maintainer: www.nslu2-linux.org */
265 .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS,
266 .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xFFFC,
267 .boot_params = 0x00000100,
268 .map_io = ixp4xx_map_io,
269 .init_irq = ixp4xx_init_irq,
270 .timer = &dsmg600_timer,
271 .init_machine = dsmg600_init,
272 MACHINE_END