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 | */ | |
19 | ||
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 MLJ |
29 | |
30 | #include <asm/mach-types.h> | |
31 | #include <asm/mach/arch.h> | |
32 | #include <asm/mach/flash.h> | |
435c5da0 | 33 | #include <asm/mach/time.h> |
43816bcb | 34 | #include <asm/gpio.h> |
28bd3a0d MLJ |
35 | |
36 | static struct flash_platform_data dsmg600_flash_data = { | |
37 | .map_name = "cfi_probe", | |
38 | .width = 2, | |
39 | }; | |
40 | ||
41 | static struct resource dsmg600_flash_resource = { | |
42 | .flags = IORESOURCE_MEM, | |
43 | }; | |
44 | ||
45 | static 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 | ||
5a4a2387 | 53 | static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { |
28bd3a0d MLJ |
54 | .sda_pin = DSMG600_SDA_PIN, |
55 | .scl_pin = DSMG600_SCL_PIN, | |
56 | }; | |
57 | ||
5a4a2387 MLJ |
58 | static struct platform_device dsmg600_i2c_gpio = { |
59 | .name = "i2c-gpio", | |
28bd3a0d | 60 | .id = 0, |
5a4a2387 MLJ |
61 | .dev = { |
62 | .platform_data = &dsmg600_i2c_gpio_data, | |
63 | }, | |
28bd3a0d MLJ |
64 | }; |
65 | ||
a9a424ce RW |
66 | static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = { |
67 | { | |
3760f736 | 68 | I2C_BOARD_INFO("pcf8563", 0x51), |
a9a424ce RW |
69 | }, |
70 | }; | |
71 | ||
1208ebf2 | 72 | static struct gpio_led dsmg600_led_pins[] = { |
28bd3a0d | 73 | { |
6c152bee | 74 | .name = "dsmg600:green:power", |
1208ebf2 | 75 | .gpio = DSMG600_LED_PWR_GPIO, |
28bd3a0d MLJ |
76 | }, |
77 | { | |
6c152bee | 78 | .name = "dsmg600:green:wlan", |
1208ebf2 RW |
79 | .gpio = DSMG600_LED_WLAN_GPIO, |
80 | .active_low = true, | |
28bd3a0d MLJ |
81 | }, |
82 | }; | |
83 | ||
1208ebf2 RW |
84 | static struct gpio_led_platform_data dsmg600_led_data = { |
85 | .num_leds = ARRAY_SIZE(dsmg600_led_pins), | |
86 | .leds = dsmg600_led_pins, | |
87 | }; | |
88 | ||
28bd3a0d | 89 | static struct platform_device dsmg600_leds = { |
1208ebf2 RW |
90 | .name = "leds-gpio", |
91 | .id = -1, | |
92 | .dev.platform_data = &dsmg600_led_data, | |
28bd3a0d | 93 | }; |
28bd3a0d MLJ |
94 | |
95 | static 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 | ||
108 | static 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 | ||
130 | static 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 | ||
138 | static struct platform_device *dsmg600_devices[] __initdata = { | |
5a4a2387 | 139 | &dsmg600_i2c_gpio, |
28bd3a0d | 140 | &dsmg600_flash, |
1208ebf2 | 141 | &dsmg600_leds, |
28bd3a0d MLJ |
142 | }; |
143 | ||
144 | static 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 | ||
43816bcb RW |
153 | /* 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 | */ | |
156 | static 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 | ||
161 | static void dsmg600_power_handler(unsigned long data); | |
162 | static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0); | |
163 | ||
164 | static 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 | ||
196 | static 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 | ||
435c5da0 MLJ |
204 | static 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 | ||
213 | static struct sys_timer dsmg600_timer = { | |
214 | .init = dsmg600_timer_init, | |
215 | }; | |
216 | ||
28bd3a0d MLJ |
217 | static 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 | ||
a9a424ce RW |
228 | i2c_register_board_info(0, dsmg600_i2c_board_info, |
229 | ARRAY_SIZE(dsmg600_i2c_board_info)); | |
230 | ||
28bd3a0d MLJ |
231 | /* 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)); | |
43816bcb RW |
238 | |
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)); | |
28bd3a0d MLJ |
261 | } |
262 | ||
28bd3a0d MLJ |
263 | MACHINE_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, | |
28bd3a0d MLJ |
268 | .map_io = ixp4xx_map_io, |
269 | .init_irq = ixp4xx_init_irq, | |
435c5da0 | 270 | .timer = &dsmg600_timer, |
28bd3a0d MLJ |
271 | .init_machine = dsmg600_init, |
272 | MACHINE_END |