blob: 688659668bdf12156627f7780057ae76c6e9b5fb [file] [log] [blame]
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +01001/*
2 * DSM-G600 board-setup
3 *
Rod Whitby43816bc2008-02-03 12:05:55 +01004 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +01005 * Copyright (C) 2006 Tower Technologies
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +01006 *
Rod Whitby43816bc2008-02-03 12:05:55 +01007 * based on ixdp425-setup.c:
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +01008 * Copyright (C) 2003-2004 MontaVista Software, Inc.
Rod Whitby43816bc2008-02-03 12:05:55 +01009 * based on nslu2-power.c:
10 * Copyright (C) 2005 Tower Technologies
11 * based on nslu2-io.c:
12 * Copyright (C) 2004 Karen Spearel
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010013 *
14 * Author: Alessandro Zummo <a.zummo@towertech.it>
Rod Whitby43816bc2008-02-03 12:05:55 +010015 * Author: Michael Westerhof <mwester@dls.net>
16 * Author: Rod Whitby <rod@whitby.id.au>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010017 * Maintainers: http://www.nslu2-linux.org/
18 */
19
Rod Whitby43816bc2008-02-03 12:05:55 +010020#include <linux/irq.h>
21#include <linux/jiffies.h>
22#include <linux/timer.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010023#include <linux/serial.h>
24#include <linux/serial_8250.h>
Rod Whitby1208ebf2008-02-02 00:03:56 +010025#include <linux/leds.h>
Rod Whitby43816bc2008-02-03 12:05:55 +010026#include <linux/reboot.h>
Rod Whitbya9a424c2008-01-29 00:40:02 +010027#include <linux/i2c.h>
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010028#include <linux/i2c-gpio.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010029
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/flash.h>
Michael-Luke Jones435c5da2007-05-23 22:38:45 +010033#include <asm/mach/time.h>
Rod Whitby43816bc2008-02-03 12:05:55 +010034#include <asm/gpio.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010035
36static struct flash_platform_data dsmg600_flash_data = {
37 .map_name = "cfi_probe",
38 .width = 2,
39};
40
41static struct resource dsmg600_flash_resource = {
42 .flags = IORESOURCE_MEM,
43};
44
45static 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,
51};
52
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010053static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010054 .sda_pin = DSMG600_SDA_PIN,
55 .scl_pin = DSMG600_SCL_PIN,
56};
57
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010058static struct platform_device dsmg600_i2c_gpio = {
59 .name = "i2c-gpio",
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010060 .id = 0,
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010061 .dev = {
62 .platform_data = &dsmg600_i2c_gpio_data,
63 },
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010064};
65
Rod Whitbya9a424c2008-01-29 00:40:02 +010066static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
67 {
68 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
69 },
70};
71
Rod Whitby1208ebf2008-02-02 00:03:56 +010072static struct gpio_led dsmg600_led_pins[] = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010073 {
Rod Whitby1208ebf2008-02-02 00:03:56 +010074 .name = "power",
75 .gpio = DSMG600_LED_PWR_GPIO,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010076 },
77 {
Rod Whitby1208ebf2008-02-02 00:03:56 +010078 .name = "wlan",
79 .gpio = DSMG600_LED_WLAN_GPIO,
80 .active_low = true,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010081 },
82};
83
Rod Whitby1208ebf2008-02-02 00:03:56 +010084static struct gpio_led_platform_data dsmg600_led_data = {
85 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
86 .leds = dsmg600_led_pins,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010087};
Rod Whitby1208ebf2008-02-02 00:03:56 +010088
89static struct platform_device dsmg600_leds = {
90 .name = "leds-gpio",
91 .id = -1,
92 .dev.platform_data = &dsmg600_led_data,
93};
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010094
95static struct resource dsmg600_uart_resources[] = {
96 {
97 .start = IXP4XX_UART1_BASE_PHYS,
98 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
99 .flags = IORESOURCE_MEM,
100 },
101 {
102 .start = IXP4XX_UART2_BASE_PHYS,
103 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
104 .flags = IORESOURCE_MEM,
105 }
106};
107
108static struct plat_serial8250_port dsmg600_uart_data[] = {
109 {
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,
117 },
118 {
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,
126 },
127 { }
128};
129
130static 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,
136};
137
138static struct platform_device *dsmg600_devices[] __initdata = {
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100139 &dsmg600_i2c_gpio,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100140 &dsmg600_flash,
Rod Whitby1208ebf2008-02-02 00:03:56 +0100141 &dsmg600_leds,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100142};
143
144static void dsmg600_power_off(void)
145{
146 /* enable the pwr cntl gpio */
147 gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
148
149 /* poweroff */
150 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
151}
152
Rod Whitby43816bc2008-02-03 12:05:55 +0100153/* 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.
155 */
156static int power_button_countdown;
157
158/* Must hold the button down for at least this many counts to be processed */
159#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
160
161static void dsmg600_power_handler(unsigned long data);
162static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
163
164static void dsmg600_power_handler(unsigned long data)
165{
166 /* This routine is called twice per second to check the
167 * state of the power button.
168 */
169
170 if (gpio_get_value(DSMG600_PB_GPIO)) {
171
172 /* IO Pin is 1 (button pushed) */
173 if (power_button_countdown > 0)
174 power_button_countdown--;
175
176 } else {
177
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.
183 */
184 ctrl_alt_del();
185
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;
190 }
191 }
192
193 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
194}
195
196static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
197{
198 /* This is the paper-clip reset, it shuts the machine down directly. */
199 machine_power_off();
200
201 return IRQ_HANDLED;
202}
203
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100204static void __init dsmg600_timer_init(void)
205{
206 /* The xtal on this machine is non-standard. */
207 ixp4xx_timer_freq = DSMG600_FREQ;
208
209 /* Call standard timer_init function. */
210 ixp4xx_timer_init();
211}
212
213static struct sys_timer dsmg600_timer = {
214 .init = dsmg600_timer_init,
215};
216
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100217static void __init dsmg600_init(void)
218{
219 ixp4xx_sys_init();
220
221 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
222 *IXP4XX_GPIO_GPCLKR = 0;
223
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;
227
Rod Whitbya9a424c2008-01-29 00:40:02 +0100228 i2c_register_board_info(0, dsmg600_i2c_board_info,
229 ARRAY_SIZE(dsmg600_i2c_board_info));
230
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100231 /* 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!
234 */
235 (void)platform_device_register(&dsmg600_uart);
236
237 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
Rod Whitby43816bc2008-02-03 12:05:55 +0100238
239 pm_power_off = dsmg600_power_off;
240
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) {
244
245 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
246 gpio_to_irq(DSMG600_RB_GPIO));
247 }
248
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.
252 */
253
254 /* Make sure that the power button GPIO is set up as an input */
255 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
256
257 /* Set the initial value for the power button IRQ handler */
258 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
259
260 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100261}
262
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100263MACHINE_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,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100268 .map_io = ixp4xx_map_io,
269 .init_irq = ixp4xx_init_irq,
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100270 .timer = &dsmg600_timer,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100271 .init_machine = dsmg600_init,
272MACHINE_END