blob: 43ee06d3abe50fa9f94aa05c60e0f378cde92be6 [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>
Linus Walleij8040dd02013-09-10 11:19:55 +020029#include <linux/gpio.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010030
Arnd Bergmann39f16012013-07-05 16:25:44 +020031#include <mach/hardware.h>
32
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010033#include <asm/mach-types.h>
34#include <asm/mach/arch.h>
35#include <asm/mach/flash.h>
Michael-Luke Jones435c5da2007-05-23 22:38:45 +010036#include <asm/mach/time.h>
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010037
Krzysztof HaƂasa395e7122009-11-16 21:56:56 +010038#define DSMG600_SDA_PIN 5
39#define DSMG600_SCL_PIN 4
40
41/* DSM-G600 Timer Setting */
42#define DSMG600_FREQ 66000000
43
44/* Buttons */
45#define DSMG600_PB_GPIO 15 /* power button */
46#define DSMG600_RB_GPIO 3 /* reset button */
47
48/* Power control */
49#define DSMG600_PO_GPIO 2 /* power off */
50
51/* LEDs */
52#define DSMG600_LED_PWR_GPIO 0
53#define DSMG600_LED_WLAN_GPIO 14
54
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010055static struct flash_platform_data dsmg600_flash_data = {
56 .map_name = "cfi_probe",
57 .width = 2,
58};
59
60static struct resource dsmg600_flash_resource = {
61 .flags = IORESOURCE_MEM,
62};
63
64static struct platform_device dsmg600_flash = {
65 .name = "IXP4XX-Flash",
66 .id = 0,
67 .dev.platform_data = &dsmg600_flash_data,
68 .num_resources = 1,
69 .resource = &dsmg600_flash_resource,
70};
71
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010072static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010073 .sda_pin = DSMG600_SDA_PIN,
74 .scl_pin = DSMG600_SCL_PIN,
75};
76
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010077static struct platform_device dsmg600_i2c_gpio = {
78 .name = "i2c-gpio",
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010079 .id = 0,
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +010080 .dev = {
81 .platform_data = &dsmg600_i2c_gpio_data,
82 },
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010083};
84
Rod Whitbya9a424c2008-01-29 00:40:02 +010085static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
86 {
Jean Delvare3760f732008-04-29 23:11:40 +020087 I2C_BOARD_INFO("pcf8563", 0x51),
Rod Whitbya9a424c2008-01-29 00:40:02 +010088 },
89};
90
Rod Whitby1208ebf2008-02-02 00:03:56 +010091static struct gpio_led dsmg600_led_pins[] = {
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010092 {
Richard Purdie6c152be2007-10-31 15:00:07 +010093 .name = "dsmg600:green:power",
Rod Whitby1208ebf2008-02-02 00:03:56 +010094 .gpio = DSMG600_LED_PWR_GPIO,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +010095 },
96 {
Richard Purdie6c152be2007-10-31 15:00:07 +010097 .name = "dsmg600:green:wlan",
Rod Whitby1208ebf2008-02-02 00:03:56 +010098 .gpio = DSMG600_LED_WLAN_GPIO,
99 .active_low = true,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100100 },
101};
102
Rod Whitby1208ebf2008-02-02 00:03:56 +0100103static struct gpio_led_platform_data dsmg600_led_data = {
104 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
105 .leds = dsmg600_led_pins,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100106};
Rod Whitby1208ebf2008-02-02 00:03:56 +0100107
108static struct platform_device dsmg600_leds = {
109 .name = "leds-gpio",
110 .id = -1,
111 .dev.platform_data = &dsmg600_led_data,
112};
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100113
114static struct resource dsmg600_uart_resources[] = {
115 {
116 .start = IXP4XX_UART1_BASE_PHYS,
117 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
118 .flags = IORESOURCE_MEM,
119 },
120 {
121 .start = IXP4XX_UART2_BASE_PHYS,
122 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
123 .flags = IORESOURCE_MEM,
124 }
125};
126
127static struct plat_serial8250_port dsmg600_uart_data[] = {
128 {
129 .mapbase = IXP4XX_UART1_BASE_PHYS,
130 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
131 .irq = IRQ_IXP4XX_UART1,
132 .flags = UPF_BOOT_AUTOCONF,
133 .iotype = UPIO_MEM,
134 .regshift = 2,
135 .uartclk = IXP4XX_UART_XTAL,
136 },
137 {
138 .mapbase = IXP4XX_UART2_BASE_PHYS,
139 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
140 .irq = IRQ_IXP4XX_UART2,
141 .flags = UPF_BOOT_AUTOCONF,
142 .iotype = UPIO_MEM,
143 .regshift = 2,
144 .uartclk = IXP4XX_UART_XTAL,
145 },
146 { }
147};
148
149static struct platform_device dsmg600_uart = {
150 .name = "serial8250",
151 .id = PLAT8250_DEV_PLATFORM,
152 .dev.platform_data = dsmg600_uart_data,
153 .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
154 .resource = dsmg600_uart_resources,
155};
156
157static struct platform_device *dsmg600_devices[] __initdata = {
Michael-Luke Jones5a4a2382008-01-27 18:14:46 +0100158 &dsmg600_i2c_gpio,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100159 &dsmg600_flash,
Rod Whitby1208ebf2008-02-02 00:03:56 +0100160 &dsmg600_leds,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100161};
162
163static void dsmg600_power_off(void)
164{
Linus Walleij8040dd02013-09-10 11:19:55 +0200165 /* enable the pwr cntl and drive it high */
166 gpio_direction_output(DSMG600_PO_GPIO, 1);
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100167}
168
Rod Whitby43816bc2008-02-03 12:05:55 +0100169/* This is used to make sure the power-button pusher is serious. The button
170 * must be held until the value of this counter reaches zero.
171 */
172static int power_button_countdown;
173
174/* Must hold the button down for at least this many counts to be processed */
175#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
176
177static void dsmg600_power_handler(unsigned long data);
178static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
179
180static void dsmg600_power_handler(unsigned long data)
181{
182 /* This routine is called twice per second to check the
183 * state of the power button.
184 */
185
186 if (gpio_get_value(DSMG600_PB_GPIO)) {
187
188 /* IO Pin is 1 (button pushed) */
189 if (power_button_countdown > 0)
190 power_button_countdown--;
191
192 } else {
193
194 /* Done on button release, to allow for auto-power-on mods. */
195 if (power_button_countdown == 0) {
196 /* Signal init to do the ctrlaltdel action,
197 * this will bypass init if it hasn't started
198 * and do a kernel_restart.
199 */
200 ctrl_alt_del();
201
202 /* Change the state of the power LED to "blink" */
Linus Walleij8040dd02013-09-10 11:19:55 +0200203 gpio_set_value(DSMG600_LED_PWR_GPIO, 0);
Rod Whitby43816bc2008-02-03 12:05:55 +0100204 } else {
205 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
206 }
207 }
208
209 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
210}
211
212static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
213{
214 /* This is the paper-clip reset, it shuts the machine down directly. */
215 machine_power_off();
216
217 return IRQ_HANDLED;
218}
219
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100220static void __init dsmg600_timer_init(void)
221{
222 /* The xtal on this machine is non-standard. */
223 ixp4xx_timer_freq = DSMG600_FREQ;
224
225 /* Call standard timer_init function. */
226 ixp4xx_timer_init();
227}
228
Linus Walleij8040dd02013-09-10 11:19:55 +0200229static int __init dsmg600_gpio_init(void)
230{
231 if (!machine_is_dsmg600())
232 return 0;
233
234 gpio_request(DSMG600_RB_GPIO, "reset button");
235 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
Michael Opdenacker1ee65642014-03-04 21:59:03 +0100236 IRQF_TRIGGER_LOW, "DSM-G600 reset button", NULL) < 0) {
Linus Walleij8040dd02013-09-10 11:19:55 +0200237
238 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
239 gpio_to_irq(DSMG600_RB_GPIO));
240 }
241
242 /*
243 * The power button on the D-Link DSM-G600 is on GPIO 15, but
244 * it cannot handle interrupts on that GPIO line. So we'll
245 * have to poll it with a kernel timer.
246 */
247
248 /* Make sure that the power button GPIO is set up as an input */
249 gpio_request(DSMG600_PB_GPIO, "power button");
250 gpio_direction_input(DSMG600_PB_GPIO);
251 /* Request poweroff GPIO line */
252 gpio_request(DSMG600_PO_GPIO, "power off button");
253
254 /* Set the initial value for the power button IRQ handler */
255 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
256
257 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
258 return 0;
259}
260device_initcall(dsmg600_gpio_init);
261
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100262static void __init dsmg600_init(void)
263{
264 ixp4xx_sys_init();
265
266 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
267 *IXP4XX_GPIO_GPCLKR = 0;
268
269 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
270 dsmg600_flash_resource.end =
271 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
272
Rod Whitbya9a424c2008-01-29 00:40:02 +0100273 i2c_register_board_info(0, dsmg600_i2c_board_info,
274 ARRAY_SIZE(dsmg600_i2c_board_info));
275
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100276 /* The UART is required on the DSM-G600 (Redboot cannot use the
277 * NIC) -- do it here so that it does *not* get removed if
278 * platform_add_devices fails!
279 */
280 (void)platform_device_register(&dsmg600_uart);
281
282 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
Rod Whitby43816bc2008-02-03 12:05:55 +0100283
284 pm_power_off = dsmg600_power_off;
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100285}
286
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100287MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
288 /* Maintainer: www.nslu2-linux.org */
Nicolas Pitree022c722011-07-05 22:38:13 -0400289 .atag_offset = 0x100,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100290 .map_io = ixp4xx_map_io,
Rob Herringf4495882012-03-06 15:01:53 -0600291 .init_early = ixp4xx_init_early,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100292 .init_irq = ixp4xx_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700293 .init_time = dsmg600_timer_init,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100294 .init_machine = dsmg600_init,
Nicolas Pitre7553ee72011-07-05 22:28:09 -0400295#if defined(CONFIG_PCI)
296 .dma_zone_size = SZ_64M,
297#endif
Russell Kingd1b860f2011-11-05 12:10:55 +0000298 .restart = ixp4xx_restart,
Michael-Luke Jones28bd3a02007-04-28 08:31:40 +0100299MACHINE_END