Commit | Line | Data |
---|---|---|
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 |
54 | static struct flash_platform_data dsmg600_flash_data = { |
55 | .map_name = "cfi_probe", | |
56 | .width = 2, | |
57 | }; | |
58 | ||
59 | static struct resource dsmg600_flash_resource = { | |
60 | .flags = IORESOURCE_MEM, | |
61 | }; | |
62 | ||
63 | static 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 | 71 | static 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 |
76 | static 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 |
84 | static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = { |
85 | { | |
3760f736 | 86 | I2C_BOARD_INFO("pcf8563", 0x51), |
a9a424ce RW |
87 | }, |
88 | }; | |
89 | ||
1208ebf2 | 90 | static 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 |
102 | static struct gpio_led_platform_data dsmg600_led_data = { |
103 | .num_leds = ARRAY_SIZE(dsmg600_led_pins), | |
104 | .leds = dsmg600_led_pins, | |
105 | }; | |
106 | ||
28bd3a0d | 107 | static 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 | |
113 | static 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 | ||
126 | static 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 | ||
148 | static 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 | ||
156 | static struct platform_device *dsmg600_devices[] __initdata = { | |
5a4a2387 | 157 | &dsmg600_i2c_gpio, |
28bd3a0d | 158 | &dsmg600_flash, |
1208ebf2 | 159 | &dsmg600_leds, |
28bd3a0d MLJ |
160 | }; |
161 | ||
162 | static 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 | ||
43816bcb RW |
171 | /* 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 | */ | |
174 | static 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 | ||
179 | static void dsmg600_power_handler(unsigned long data); | |
180 | static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0); | |
181 | ||
182 | static 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 | ||
214 | static 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 | ||
435c5da0 MLJ |
222 | static 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 | ||
28bd3a0d MLJ |
231 | static 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 | ||
a9a424ce RW |
242 | i2c_register_board_info(0, dsmg600_i2c_board_info, |
243 | ARRAY_SIZE(dsmg600_i2c_board_info)); | |
244 | ||
28bd3a0d MLJ |
245 | /* 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)); | |
43816bcb RW |
252 | |
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)); | |
28bd3a0d MLJ |
275 | } |
276 | ||
28bd3a0d MLJ |
277 | MACHINE_START(DSMG600, "D-Link DSM-G600 RevA") |
278 | /* Maintainer: www.nslu2-linux.org */ | |
e022c729 | 279 | .atag_offset = 0x100, |
28bd3a0d | 280 | .map_io = ixp4xx_map_io, |
f449588c | 281 | .init_early = ixp4xx_init_early, |
28bd3a0d | 282 | .init_irq = ixp4xx_init_irq, |
6bb27d73 | 283 | .init_time = dsmg600_timer_init, |
28bd3a0d | 284 | .init_machine = dsmg600_init, |
7553ee77 NP |
285 | #if defined(CONFIG_PCI) |
286 | .dma_zone_size = SZ_64M, | |
287 | #endif | |
d1b860fb | 288 | .restart = ixp4xx_restart, |
28bd3a0d | 289 | MACHINE_END |