Merge tag 'edac_for_4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp
[linux-2.6-block.git] / arch / arm / mach-ixp4xx / dsmg600-setup.c
CommitLineData
28bd3a0d
MLJ
1/*
2 * DSM-G600 board-setup
3 *
43816bcb 4 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
28bd3a0d 5 * Copyright (C) 2006 Tower Technologies
28bd3a0d 6 *
43816bcb 7 * based on ixdp425-setup.c:
28bd3a0d 8 * Copyright (C) 2003-2004 MontaVista Software, Inc.
43816bcb
RW
9 * based on nslu2-power.c:
10 * Copyright (C) 2005 Tower Technologies
11 * based on nslu2-io.c:
12 * Copyright (C) 2004 Karen Spearel
28bd3a0d
MLJ
13 *
14 * Author: Alessandro Zummo <a.zummo@towertech.it>
43816bcb
RW
15 * Author: Michael Westerhof <mwester@dls.net>
16 * Author: Rod Whitby <rod@whitby.id.au>
28bd3a0d
MLJ
17 * Maintainers: http://www.nslu2-linux.org/
18 */
2f8163ba 19#include <linux/gpio.h>
43816bcb
RW
20#include <linux/irq.h>
21#include <linux/jiffies.h>
22#include <linux/timer.h>
28bd3a0d
MLJ
23#include <linux/serial.h>
24#include <linux/serial_8250.h>
1208ebf2 25#include <linux/leds.h>
43816bcb 26#include <linux/reboot.h>
a9a424ce 27#include <linux/i2c.h>
5a4a2387 28#include <linux/i2c-gpio.h>
28bd3a0d 29
39f1601c
AB
30#include <mach/hardware.h>
31
28bd3a0d
MLJ
32#include <asm/mach-types.h>
33#include <asm/mach/arch.h>
34#include <asm/mach/flash.h>
435c5da0 35#include <asm/mach/time.h>
28bd3a0d 36
395e7127
KH
37#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
28bd3a0d
MLJ
54static 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
5a4a2387 71static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
28bd3a0d
MLJ
72 .sda_pin = DSMG600_SDA_PIN,
73 .scl_pin = DSMG600_SCL_PIN,
74};
75
5a4a2387
MLJ
76static struct platform_device dsmg600_i2c_gpio = {
77 .name = "i2c-gpio",
28bd3a0d 78 .id = 0,
5a4a2387
MLJ
79 .dev = {
80 .platform_data = &dsmg600_i2c_gpio_data,
81 },
28bd3a0d
MLJ
82};
83
a9a424ce
RW
84static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
85 {
3760f736 86 I2C_BOARD_INFO("pcf8563", 0x51),
a9a424ce
RW
87 },
88};
89
1208ebf2 90static struct gpio_led dsmg600_led_pins[] = {
28bd3a0d 91 {
6c152bee 92 .name = "dsmg600:green:power",
1208ebf2 93 .gpio = DSMG600_LED_PWR_GPIO,
28bd3a0d
MLJ
94 },
95 {
6c152bee 96 .name = "dsmg600:green:wlan",
1208ebf2
RW
97 .gpio = DSMG600_LED_WLAN_GPIO,
98 .active_low = true,
28bd3a0d
MLJ
99 },
100};
101
1208ebf2
RW
102static struct gpio_led_platform_data dsmg600_led_data = {
103 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
104 .leds = dsmg600_led_pins,
105};
106
28bd3a0d 107static struct platform_device dsmg600_leds = {
1208ebf2
RW
108 .name = "leds-gpio",
109 .id = -1,
110 .dev.platform_data = &dsmg600_led_data,
28bd3a0d 111};
28bd3a0d
MLJ
112
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 = {
5a4a2387 157 &dsmg600_i2c_gpio,
28bd3a0d 158 &dsmg600_flash,
1208ebf2 159 &dsmg600_leds,
28bd3a0d
MLJ
160};
161
162static void dsmg600_power_off(void)
163{
8040dd09
LW
164 /* enable the pwr cntl and drive it high */
165 gpio_direction_output(DSMG600_PO_GPIO, 1);
28bd3a0d
MLJ
166}
167
43816bcb
RW
168/* This is used to make sure the power-button pusher is serious. The button
169 * must be held until the value of this counter reaches zero.
170 */
171static int power_button_countdown;
172
173/* Must hold the button down for at least this many counts to be processed */
174#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
175
176static void dsmg600_power_handler(unsigned long data);
177static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
178
179static void dsmg600_power_handler(unsigned long data)
180{
181 /* This routine is called twice per second to check the
182 * state of the power button.
183 */
184
185 if (gpio_get_value(DSMG600_PB_GPIO)) {
186
187 /* IO Pin is 1 (button pushed) */
188 if (power_button_countdown > 0)
189 power_button_countdown--;
190
191 } else {
192
193 /* Done on button release, to allow for auto-power-on mods. */
194 if (power_button_countdown == 0) {
195 /* Signal init to do the ctrlaltdel action,
196 * this will bypass init if it hasn't started
197 * and do a kernel_restart.
198 */
199 ctrl_alt_del();
200
201 /* Change the state of the power LED to "blink" */
8040dd09 202 gpio_set_value(DSMG600_LED_PWR_GPIO, 0);
43816bcb
RW
203 } else {
204 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
205 }
206 }
207
208 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
209}
210
211static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
212{
213 /* This is the paper-clip reset, it shuts the machine down directly. */
214 machine_power_off();
215
216 return IRQ_HANDLED;
217}
218
435c5da0
MLJ
219static void __init dsmg600_timer_init(void)
220{
221 /* The xtal on this machine is non-standard. */
222 ixp4xx_timer_freq = DSMG600_FREQ;
223
224 /* Call standard timer_init function. */
225 ixp4xx_timer_init();
226}
227
8040dd09
LW
228static int __init dsmg600_gpio_init(void)
229{
230 if (!machine_is_dsmg600())
231 return 0;
232
233 gpio_request(DSMG600_RB_GPIO, "reset button");
234 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
1ee6564d 235 IRQF_TRIGGER_LOW, "DSM-G600 reset button", NULL) < 0) {
8040dd09
LW
236
237 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
238 gpio_to_irq(DSMG600_RB_GPIO));
239 }
240
241 /*
242 * The power button on the D-Link DSM-G600 is on GPIO 15, but
243 * it cannot handle interrupts on that GPIO line. So we'll
244 * have to poll it with a kernel timer.
245 */
246
247 /* Make sure that the power button GPIO is set up as an input */
248 gpio_request(DSMG600_PB_GPIO, "power button");
249 gpio_direction_input(DSMG600_PB_GPIO);
250 /* Request poweroff GPIO line */
251 gpio_request(DSMG600_PO_GPIO, "power off button");
252
253 /* Set the initial value for the power button IRQ handler */
254 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
255
256 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
257 return 0;
258}
259device_initcall(dsmg600_gpio_init);
260
28bd3a0d
MLJ
261static void __init dsmg600_init(void)
262{
263 ixp4xx_sys_init();
264
265 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
266 *IXP4XX_GPIO_GPCLKR = 0;
267
268 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
269 dsmg600_flash_resource.end =
270 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
271
a9a424ce
RW
272 i2c_register_board_info(0, dsmg600_i2c_board_info,
273 ARRAY_SIZE(dsmg600_i2c_board_info));
274
28bd3a0d
MLJ
275 /* The UART is required on the DSM-G600 (Redboot cannot use the
276 * NIC) -- do it here so that it does *not* get removed if
277 * platform_add_devices fails!
278 */
279 (void)platform_device_register(&dsmg600_uart);
280
281 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
43816bcb
RW
282
283 pm_power_off = dsmg600_power_off;
28bd3a0d
MLJ
284}
285
28bd3a0d
MLJ
286MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
287 /* Maintainer: www.nslu2-linux.org */
e022c729 288 .atag_offset = 0x100,
28bd3a0d 289 .map_io = ixp4xx_map_io,
f449588c 290 .init_early = ixp4xx_init_early,
28bd3a0d 291 .init_irq = ixp4xx_init_irq,
6bb27d73 292 .init_time = dsmg600_timer_init,
28bd3a0d 293 .init_machine = dsmg600_init,
7553ee77
NP
294#if defined(CONFIG_PCI)
295 .dma_zone_size = SZ_64M,
296#endif
d1b860fb 297 .restart = ixp4xx_restart,
28bd3a0d 298MACHINE_END