blob: 63de1b3fd06bf0327549cf7670761ac7bccf7298 [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 */
Russell King2f8163b2011-07-26 10:53:52 +010019#include <linux/gpio.h>
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
Arnd Bergmann39f16012013-07-05 16:25:44 +020030#include <mach/hardware.h>
31
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010032#include <asm/mach-types.h>
33#include <asm/mach/arch.h>
34#include <asm/mach/flash.h>
Michael-Luke Jones435c5da2007-05-23 22:38:45 +010035#include <asm/mach/time.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010036
Krzysztof HaƂasa395e7122009-11-16 21:56:56 +010037#define DSMG600_SDA_PIN 5
38#define DSMG600_SCL_PIN 4
39
40/* DSM-G600 Timer Setting */
41#define DSMG600_FREQ 66000000
42
43/* Buttons */
44#define DSMG600_PB_GPIO 15 /* power button */
45#define DSMG600_RB_GPIO 3 /* reset button */
46
47/* Power control */
48#define DSMG600_PO_GPIO 2 /* power off */
49
50/* LEDs */
51#define DSMG600_LED_PWR_GPIO 0
52#define DSMG600_LED_WLAN_GPIO 14
53
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010054static struct flash_platform_data dsmg600_flash_data = {
55 .map_name = "cfi_probe",
56 .width = 2,
57};
58
59static struct resource dsmg600_flash_resource = {
60 .flags = IORESOURCE_MEM,
61};
62
63static struct platform_device dsmg600_flash = {
64 .name = "IXP4XX-Flash",
65 .id = 0,
66 .dev.platform_data = &dsmg600_flash_data,
67 .num_resources = 1,
68 .resource = &dsmg600_flash_resource,
69};
70
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010071static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010072 .sda_pin = DSMG600_SDA_PIN,
73 .scl_pin = DSMG600_SCL_PIN,
74};
75
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010076static struct platform_device dsmg600_i2c_gpio = {
77 .name = "i2c-gpio",
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010078 .id = 0,
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010079 .dev = {
80 .platform_data = &dsmg600_i2c_gpio_data,
81 },
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010082};
83
Rod Whitbya9a424c2008-01-29 00:40:02 +010084static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
85 {
Jean Delvare3760f732008-04-29 23:11:40 +020086 I2C_BOARD_INFO("pcf8563", 0x51),
Rod Whitbya9a424c2008-01-29 00:40:02 +010087 },
88};
89
Rod Whitby1208ebf2008-02-02 00:03:56 +010090static struct gpio_led dsmg600_led_pins[] = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010091 {
Richard Purdie6c152be2007-10-31 15:00:07 +010092 .name = "dsmg600:green:power",
Rod Whitby1208ebf2008-02-02 00:03:56 +010093 .gpio = DSMG600_LED_PWR_GPIO,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010094 },
95 {
Richard Purdie6c152be2007-10-31 15:00:07 +010096 .name = "dsmg600:green:wlan",
Rod Whitby1208ebf2008-02-02 00:03:56 +010097 .gpio = DSMG600_LED_WLAN_GPIO,
98 .active_low = true,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010099 },
100};
101
Rod Whitby1208ebf2008-02-02 00:03:56 +0100102static struct gpio_led_platform_data dsmg600_led_data = {
103 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
104 .leds = dsmg600_led_pins,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100105};
Rod Whitby1208ebf2008-02-02 00:03:56 +0100106
107static struct platform_device dsmg600_leds = {
108 .name = "leds-gpio",
109 .id = -1,
110 .dev.platform_data = &dsmg600_led_data,
111};
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100112
113static struct resource dsmg600_uart_resources[] = {
114 {
115 .start = IXP4XX_UART1_BASE_PHYS,
116 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
117 .flags = IORESOURCE_MEM,
118 },
119 {
120 .start = IXP4XX_UART2_BASE_PHYS,
121 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
122 .flags = IORESOURCE_MEM,
123 }
124};
125
126static struct plat_serial8250_port dsmg600_uart_data[] = {
127 {
128 .mapbase = IXP4XX_UART1_BASE_PHYS,
129 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
130 .irq = IRQ_IXP4XX_UART1,
131 .flags = UPF_BOOT_AUTOCONF,
132 .iotype = UPIO_MEM,
133 .regshift = 2,
134 .uartclk = IXP4XX_UART_XTAL,
135 },
136 {
137 .mapbase = IXP4XX_UART2_BASE_PHYS,
138 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
139 .irq = IRQ_IXP4XX_UART2,
140 .flags = UPF_BOOT_AUTOCONF,
141 .iotype = UPIO_MEM,
142 .regshift = 2,
143 .uartclk = IXP4XX_UART_XTAL,
144 },
145 { }
146};
147
148static struct platform_device dsmg600_uart = {
149 .name = "serial8250",
150 .id = PLAT8250_DEV_PLATFORM,
151 .dev.platform_data = dsmg600_uart_data,
152 .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
153 .resource = dsmg600_uart_resources,
154};
155
156static struct platform_device *dsmg600_devices[] __initdata = {
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100157 &dsmg600_i2c_gpio,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100158 &dsmg600_flash,
Rod Whitby1208ebf2008-02-02 00:03:56 +0100159 &dsmg600_leds,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100160};
161
162static void dsmg600_power_off(void)
163{
164 /* enable the pwr cntl gpio */
165 gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
166
167 /* poweroff */
168 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
169}
170
Rod Whitby43816bc2008-02-03 12:05:55 +0100171/* This is used to make sure the power-button pusher is serious. The button
172 * must be held until the value of this counter reaches zero.
173 */
174static int power_button_countdown;
175
176/* Must hold the button down for at least this many counts to be processed */
177#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
178
179static void dsmg600_power_handler(unsigned long data);
180static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
181
182static void dsmg600_power_handler(unsigned long data)
183{
184 /* This routine is called twice per second to check the
185 * state of the power button.
186 */
187
188 if (gpio_get_value(DSMG600_PB_GPIO)) {
189
190 /* IO Pin is 1 (button pushed) */
191 if (power_button_countdown > 0)
192 power_button_countdown--;
193
194 } else {
195
196 /* Done on button release, to allow for auto-power-on mods. */
197 if (power_button_countdown == 0) {
198 /* Signal init to do the ctrlaltdel action,
199 * this will bypass init if it hasn't started
200 * and do a kernel_restart.
201 */
202 ctrl_alt_del();
203
204 /* Change the state of the power LED to "blink" */
205 gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
206 } else {
207 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
208 }
209 }
210
211 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
212}
213
214static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
215{
216 /* This is the paper-clip reset, it shuts the machine down directly. */
217 machine_power_off();
218
219 return IRQ_HANDLED;
220}
221
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100222static void __init dsmg600_timer_init(void)
223{
224 /* The xtal on this machine is non-standard. */
225 ixp4xx_timer_freq = DSMG600_FREQ;
226
227 /* Call standard timer_init function. */
228 ixp4xx_timer_init();
229}
230
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100231static void __init dsmg600_init(void)
232{
233 ixp4xx_sys_init();
234
235 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
236 *IXP4XX_GPIO_GPCLKR = 0;
237
238 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
239 dsmg600_flash_resource.end =
240 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
241
Rod Whitbya9a424c2008-01-29 00:40:02 +0100242 i2c_register_board_info(0, dsmg600_i2c_board_info,
243 ARRAY_SIZE(dsmg600_i2c_board_info));
244
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100245 /* The UART is required on the DSM-G600 (Redboot cannot use the
246 * NIC) -- do it here so that it does *not* get removed if
247 * platform_add_devices fails!
248 */
249 (void)platform_device_register(&dsmg600_uart);
250
251 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
Rod Whitby43816bc2008-02-03 12:05:55 +0100252
253 pm_power_off = dsmg600_power_off;
254
255 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
256 IRQF_DISABLED | IRQF_TRIGGER_LOW,
257 "DSM-G600 reset button", NULL) < 0) {
258
259 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
260 gpio_to_irq(DSMG600_RB_GPIO));
261 }
262
263 /* The power button on the D-Link DSM-G600 is on GPIO 15, but
264 * it cannot handle interrupts on that GPIO line. So we'll
265 * have to poll it with a kernel timer.
266 */
267
268 /* Make sure that the power button GPIO is set up as an input */
269 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
270
271 /* Set the initial value for the power button IRQ handler */
272 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
273
274 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100275}
276
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100277MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
278 /* Maintainer: www.nslu2-linux.org */
Nicolas Pitree022c722011-07-05 22:38:13 -0400279 .atag_offset = 0x100,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100280 .map_io = ixp4xx_map_io,
Rob Herringf4495882012-03-06 15:01:53 -0600281 .init_early = ixp4xx_init_early,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100282 .init_irq = ixp4xx_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700283 .init_time = dsmg600_timer_init,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100284 .init_machine = dsmg600_init,
Nicolas Pitre7553ee72011-07-05 22:28:09 -0400285#if defined(CONFIG_PCI)
286 .dma_zone_size = SZ_64M,
287#endif
Russell Kingd1b860f2011-11-05 12:10:55 +0000288 .restart = ixp4xx_restart,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100289MACHINE_END