1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/platform_device.h>
23#include <linux/gpio.h>
24#include <linux/w1-gpio.h>
25#include <linux/i2c.h>
26#include <linux/i2c/pcf857x.h>
27#include <linux/gpio_keys.h>
28#include <linux/input.h>
29
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32
33#include <mach/at91sam9_smc.h>
34
35#include "at91_aic.h"
36#include "board.h"
37#include "sam9_smc.h"
38#include "generic.h"
39#include "gsia18s.h"
40#include "stamp9g20.h"
41
42static void __init gsia18s_init_early(void)
43{
44 stamp9g20_init_early();
45}
46
47
48
49
50static struct at91_usbh_data __initdata usbh_data = {
51 .ports = 2,
52 .vbus_pin = {-EINVAL, -EINVAL},
53 .overcurrent_pin= {-EINVAL, -EINVAL},
54};
55
56
57
58
59static struct at91_udc_data __initdata udc_data = {
60 .vbus_pin = AT91_PIN_PA22,
61 .pullup_pin = -EINVAL,
62};
63
64
65
66
67static struct macb_platform_data __initdata macb_data = {
68 .phy_irq_pin = AT91_PIN_PA28,
69 .is_rmii = 1,
70};
71
72
73
74
75static struct gpio_led gpio_leds[] = {
76 {
77 .name = "gpo:spi1reset",
78 .gpio = AT91_PIN_PC1,
79 .active_low = 0,
80 .default_trigger = "none",
81 .default_state = LEDS_GPIO_DEFSTATE_OFF,
82 },
83 {
84 .name = "gpo:trig_net_out",
85 .gpio = AT91_PIN_PB20,
86 .active_low = 0,
87 .default_trigger = "none",
88 .default_state = LEDS_GPIO_DEFSTATE_OFF,
89 },
90 {
91 .name = "gpo:trig_net_dir",
92 .gpio = AT91_PIN_PB19,
93 .active_low = 0,
94 .default_trigger = "none",
95 .default_state = LEDS_GPIO_DEFSTATE_OFF,
96 },
97 {
98 .name = "gpo:charge_dis",
99 .gpio = AT91_PIN_PC2,
100 .active_low = 0,
101 .default_trigger = "none",
102 .default_state = LEDS_GPIO_DEFSTATE_OFF,
103 },
104 {
105 .name = "led:event",
106 .gpio = AT91_PIN_PB17,
107 .active_low = 1,
108 .default_trigger = "none",
109 .default_state = LEDS_GPIO_DEFSTATE_OFF,
110 },
111 {
112 .name = "led:lan",
113 .gpio = AT91_PIN_PB18,
114 .active_low = 1,
115 .default_trigger = "none",
116 .default_state = LEDS_GPIO_DEFSTATE_OFF,
117 },
118 {
119 .name = "led:error",
120 .gpio = AT91_PIN_PB16,
121 .active_low = 1,
122 .default_trigger = "none",
123 .default_state = LEDS_GPIO_DEFSTATE_ON,
124 }
125};
126
127static struct gpio_led_platform_data gpio_led_info = {
128 .leds = gpio_leds,
129 .num_leds = ARRAY_SIZE(gpio_leds),
130};
131
132static struct platform_device leds = {
133 .name = "leds-gpio",
134 .id = 0,
135 .dev = {
136 .platform_data = &gpio_led_info,
137 }
138};
139
140static void __init gsia18s_leds_init(void)
141{
142 platform_device_register(&leds);
143}
144
145
146static struct gpio_led pcf_gpio_leds1[] = {
147 {
148 .name = "gpo:hdc_power",
149 .gpio = PCF_GPIO_HDC_POWER,
150 .active_low = 0,
151 .default_trigger = "none",
152 .default_state = LEDS_GPIO_DEFSTATE_OFF,
153 },
154 {
155 .name = "gpo:wifi_setup",
156 .gpio = PCF_GPIO_WIFI_SETUP,
157 .active_low = 1,
158 .default_trigger = "none",
159 .default_state = LEDS_GPIO_DEFSTATE_OFF,
160 },
161 {
162 .name = "gpo:wifi_enable",
163 .gpio = PCF_GPIO_WIFI_ENABLE,
164 .active_low = 1,
165 .default_trigger = "none",
166 .default_state = LEDS_GPIO_DEFSTATE_OFF,
167 },
168 {
169 .name = "gpo:wifi_reset",
170 .gpio = PCF_GPIO_WIFI_RESET,
171 .active_low = 1,
172 .default_trigger = "none",
173 .default_state = LEDS_GPIO_DEFSTATE_ON,
174 },
175
176 {
177 .name = "gpo:gps_setup",
178 .gpio = PCF_GPIO_GPS_SETUP,
179 .active_low = 1,
180 .default_trigger = "none",
181 .default_state = LEDS_GPIO_DEFSTATE_OFF,
182 },
183 {
184 .name = "gpo:gps_standby",
185 .gpio = PCF_GPIO_GPS_STANDBY,
186 .active_low = 0,
187 .default_trigger = "none",
188 .default_state = LEDS_GPIO_DEFSTATE_ON,
189 },
190 {
191 .name = "gpo:gps_power",
192 .gpio = PCF_GPIO_GPS_POWER,
193 .active_low = 0,
194 .default_trigger = "none",
195 .default_state = LEDS_GPIO_DEFSTATE_OFF,
196 }
197};
198
199static struct gpio_led_platform_data pcf_gpio_led_info1 = {
200 .leds = pcf_gpio_leds1,
201 .num_leds = ARRAY_SIZE(pcf_gpio_leds1),
202};
203
204static struct platform_device pcf_leds1 = {
205 .name = "leds-gpio",
206 .id = 1,
207 .dev = {
208 .platform_data = &pcf_gpio_led_info1,
209 }
210};
211
212
213static struct gpio_led pcf_gpio_leds2[] = {
214 {
215 .name = "gpo:alarm_1",
216 .gpio = PCF_GPIO_ALARM1,
217 .active_low = 1,
218 .default_trigger = "none",
219 .default_state = LEDS_GPIO_DEFSTATE_OFF,
220 },
221 {
222 .name = "gpo:alarm_2",
223 .gpio = PCF_GPIO_ALARM2,
224 .active_low = 1,
225 .default_trigger = "none",
226 .default_state = LEDS_GPIO_DEFSTATE_OFF,
227 },
228 {
229 .name = "gpo:alarm_3",
230 .gpio = PCF_GPIO_ALARM3,
231 .active_low = 1,
232 .default_trigger = "none",
233 .default_state = LEDS_GPIO_DEFSTATE_OFF,
234 },
235 {
236 .name = "gpo:alarm_4",
237 .gpio = PCF_GPIO_ALARM4,
238 .active_low = 1,
239 .default_trigger = "none",
240 .default_state = LEDS_GPIO_DEFSTATE_OFF,
241 },
242
243 {
244 .name = "gpo:alarm_v_relay_on",
245 .gpio = PCF_GPIO_ALARM_V_RELAY_ON,
246 .active_low = 0,
247 .default_trigger = "none",
248 .default_state = LEDS_GPIO_DEFSTATE_OFF,
249 },
250};
251
252static struct gpio_led_platform_data pcf_gpio_led_info2 = {
253 .leds = pcf_gpio_leds2,
254 .num_leds = ARRAY_SIZE(pcf_gpio_leds2),
255};
256
257static struct platform_device pcf_leds2 = {
258 .name = "leds-gpio",
259 .id = 2,
260 .dev = {
261 .platform_data = &pcf_gpio_led_info2,
262 }
263};
264
265
266static struct gpio_led pcf_gpio_leds3[] = {
267 {
268 .name = "gpo:modem_power",
269 .gpio = PCF_GPIO_MODEM_POWER,
270 .active_low = 1,
271 .default_trigger = "none",
272 .default_state = LEDS_GPIO_DEFSTATE_OFF,
273 },
274
275 {
276 .name = "gpo:modem_reset",
277 .gpio = PCF_GPIO_MODEM_RESET,
278 .active_low = 1,
279 .default_trigger = "none",
280 .default_state = LEDS_GPIO_DEFSTATE_ON,
281 },
282
283 {
284 .name = "gpo:trx_reset",
285 .gpio = PCF_GPIO_TRX_RESET,
286 .active_low = 1,
287 .default_trigger = "none",
288 .default_state = LEDS_GPIO_DEFSTATE_ON,
289 }
290};
291
292static struct gpio_led_platform_data pcf_gpio_led_info3 = {
293 .leds = pcf_gpio_leds3,
294 .num_leds = ARRAY_SIZE(pcf_gpio_leds3),
295};
296
297static struct platform_device pcf_leds3 = {
298 .name = "leds-gpio",
299 .id = 3,
300 .dev = {
301 .platform_data = &pcf_gpio_led_info3,
302 }
303};
304
305static void __init gsia18s_pcf_leds_init(void)
306{
307 platform_device_register(&pcf_leds1);
308 platform_device_register(&pcf_leds2);
309 platform_device_register(&pcf_leds3);
310}
311
312
313
314
315static struct spi_board_info gsia18s_spi_devices[] = {
316 {
317 .modalias = "spidev",
318 .bus_num = 0,
319 .chip_select = 0,
320 .max_speed_hz = 580000,
321 .mode = SPI_MODE_1,
322 },
323 {
324 .modalias = "spidev",
325 .bus_num = 1,
326 .chip_select = 0,
327 .max_speed_hz = 5600000,
328 .mode = SPI_MODE_0,
329 },
330 {
331 .modalias = "spidev",
332 .bus_num = 1,
333 .chip_select = 1,
334 .max_speed_hz = 5600000,
335 .mode = SPI_MODE_0,
336 },
337 {
338 .modalias = "spidev",
339 .bus_num = 1,
340 .chip_select = 2,
341 .max_speed_hz = 5600000,
342 .mode = SPI_MODE_0,
343 },
344 {
345 .modalias = "spidev",
346 .bus_num = 1,
347 .chip_select = 3,
348 .max_speed_hz = 5600000,
349 .mode = SPI_MODE_0,
350 }
351};
352
353
354
355
356static struct gpio_keys_button buttons[] = {
357 {
358 .gpio = GPIO_TRIG_NET_IN,
359 .code = BTN_1,
360 .desc = "TRIG_NET_IN",
361 .type = EV_KEY,
362 .active_low = 0,
363 .wakeup = 1,
364 },
365 {
366 .gpio = GPIO_CARD_UNMOUNT_0,
367 .code = BTN_2,
368 .desc = "Card umount 0",
369 .type = EV_KEY,
370 .active_low = 1,
371 .wakeup = 1,
372 },
373 {
374 .gpio = GPIO_CARD_UNMOUNT_1,
375 .code = BTN_3,
376 .desc = "Card umount 1",
377 .type = EV_KEY,
378 .active_low = 1,
379 .wakeup = 1,
380 },
381 {
382 .gpio = GPIO_KEY_POWER,
383 .code = KEY_POWER,
384 .desc = "Power Off Button",
385 .type = EV_KEY,
386 .active_low = 0,
387 .wakeup = 1,
388 }
389};
390
391static struct gpio_keys_platform_data button_data = {
392 .buttons = buttons,
393 .nbuttons = ARRAY_SIZE(buttons),
394};
395
396static struct platform_device button_device = {
397 .name = "gpio-keys",
398 .id = -1,
399 .num_resources = 0,
400 .dev = {
401 .platform_data = &button_data,
402 }
403};
404
405static void __init gsia18s_add_device_buttons(void)
406{
407 at91_set_gpio_input(GPIO_TRIG_NET_IN, 1);
408 at91_set_deglitch(GPIO_TRIG_NET_IN, 1);
409 at91_set_gpio_input(GPIO_CARD_UNMOUNT_0, 1);
410 at91_set_deglitch(GPIO_CARD_UNMOUNT_0, 1);
411 at91_set_gpio_input(GPIO_CARD_UNMOUNT_1, 1);
412 at91_set_deglitch(GPIO_CARD_UNMOUNT_1, 1);
413 at91_set_gpio_input(GPIO_KEY_POWER, 0);
414 at91_set_deglitch(GPIO_KEY_POWER, 1);
415
416 platform_device_register(&button_device);
417}
418
419
420
421
422static int pcf8574x_0x20_setup(struct i2c_client *client, int gpio,
423 unsigned int ngpio, void *context)
424{
425 int status;
426
427 status = gpio_request(gpio + PCF_GPIO_ETH_DETECT, "eth_det");
428 if (status < 0) {
429 pr_err("error: can't request GPIO%d\n",
430 gpio + PCF_GPIO_ETH_DETECT);
431 return status;
432 }
433 status = gpio_direction_input(gpio + PCF_GPIO_ETH_DETECT);
434 if (status < 0) {
435 pr_err("error: can't setup GPIO%d as input\n",
436 gpio + PCF_GPIO_ETH_DETECT);
437 return status;
438 }
439 status = gpio_export(gpio + PCF_GPIO_ETH_DETECT, false);
440 if (status < 0) {
441 pr_err("error: can't export GPIO%d\n",
442 gpio + PCF_GPIO_ETH_DETECT);
443 return status;
444 }
445 status = gpio_sysfs_set_active_low(gpio + PCF_GPIO_ETH_DETECT, 1);
446 if (status < 0) {
447 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
448 gpio + PCF_GPIO_ETH_DETECT);
449 return status;
450 }
451
452 return 0;
453}
454
455static int pcf8574x_0x20_teardown(struct i2c_client *client, int gpio,
456 unsigned ngpio, void *context)
457{
458 gpio_free(gpio + PCF_GPIO_ETH_DETECT);
459 return 0;
460}
461
462static struct pcf857x_platform_data pcf20_pdata = {
463 .gpio_base = GS_IA18_S_PCF_GPIO_BASE0,
464 .n_latch = (1 << 4),
465 .setup = pcf8574x_0x20_setup,
466 .teardown = pcf8574x_0x20_teardown,
467};
468
469static struct pcf857x_platform_data pcf22_pdata = {
470 .gpio_base = GS_IA18_S_PCF_GPIO_BASE1,
471};
472
473static struct pcf857x_platform_data pcf24_pdata = {
474 .gpio_base = GS_IA18_S_PCF_GPIO_BASE2,
475};
476
477static struct i2c_board_info __initdata gsia18s_i2c_devices[] = {
478 {
479 I2C_BOARD_INFO("pcf8574", 0x20),
480 .platform_data = &pcf20_pdata,
481 },
482 {
483 I2C_BOARD_INFO("pcf8574", 0x22),
484 .platform_data = &pcf22_pdata,
485 },
486 {
487 I2C_BOARD_INFO("pcf8574", 0x24),
488 .platform_data = &pcf24_pdata,
489 },
490 {
491 I2C_BOARD_INFO("24c1024", 0x50),
492 },
493 {
494 I2C_BOARD_INFO("24c01", 0x53),
495 },
496};
497
498
499
500
501static struct at91_cf_data __initdata gsia18s_cf1_data = {
502 .irq_pin = AT91_PIN_PA27,
503 .det_pin = AT91_PIN_PB30,
504 .vcc_pin = -EINVAL,
505 .rst_pin = AT91_PIN_PB31,
506 .chipselect = 5,
507 .flags = AT91_CF_TRUE_IDE,
508};
509
510
511static void gsia18s_power_off(void)
512{
513 pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
514 at91_set_gpio_output(AT91_PIN_PA25, 1);
515
516 while (1)
517 ;
518}
519
520static int __init gsia18s_power_off_init(void)
521{
522 pm_power_off = gsia18s_power_off;
523 return 0;
524}
525
526
527
528static void __init gsia18s_board_init(void)
529{
530
531
532
533
534 at91_register_uart(AT91SAM9260_ID_US0, 1,
535 ATMEL_UART_CTS | ATMEL_UART_RTS |
536 ATMEL_UART_DTR | ATMEL_UART_DSR |
537 ATMEL_UART_DCD | ATMEL_UART_RI);
538
539
540
541
542 at91_register_uart(AT91SAM9260_ID_US1, 2,
543 ATMEL_UART_CTS | ATMEL_UART_RTS);
544
545
546
547
548 at91_register_uart(AT91SAM9260_ID_US2, 3,
549 ATMEL_UART_CTS | ATMEL_UART_RTS);
550
551
552
553
554 at91_register_uart(AT91SAM9260_ID_US3, 4, ATMEL_UART_RTS);
555
556
557
558
559
560 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
561 stamp9g20_board_init();
562 at91_add_device_usbh(&usbh_data);
563 at91_add_device_udc(&udc_data);
564 at91_add_device_eth(&macb_data);
565 gsia18s_leds_init();
566 gsia18s_pcf_leds_init();
567 gsia18s_add_device_buttons();
568 at91_add_device_i2c(gsia18s_i2c_devices,
569 ARRAY_SIZE(gsia18s_i2c_devices));
570 at91_add_device_cf(&gsia18s_cf1_data);
571 at91_add_device_spi(gsia18s_spi_devices,
572 ARRAY_SIZE(gsia18s_spi_devices));
573 gsia18s_power_off_init();
574}
575
576MACHINE_START(GSIA18S, "GS_IA18_S")
577 .init_time = at91sam926x_pit_init,
578 .map_io = at91_map_io,
579 .handle_irq = at91_aic_handle_irq,
580 .init_early = gsia18s_init_early,
581 .init_irq = at91_init_irq_default,
582 .init_machine = gsia18s_board_init,
583MACHINE_END
584