2 * Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
4 * 2010 Igor Plyatov <plyatov@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
33 #include <mach/at91sam9_smc.h>
34 #include <mach/hardware.h>
41 #include "stamp9g20.h"
43 static void __init gsia18s_init_early(void)
45 stamp9g20_init_early();
51 static struct at91_usbh_data __initdata usbh_data = {
53 .vbus_pin = {-EINVAL, -EINVAL},
54 .overcurrent_pin= {-EINVAL, -EINVAL},
60 static struct at91_udc_data __initdata udc_data = {
61 .vbus_pin = AT91_PIN_PA22,
62 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
66 * MACB Ethernet device
68 static struct macb_platform_data __initdata macb_data = {
69 .phy_irq_pin = AT91_PIN_PA28,
76 static struct gpio_led gpio_leds[] = {
78 .name = "gpo:spi1reset",
81 .default_trigger = "none",
82 .default_state = LEDS_GPIO_DEFSTATE_OFF,
85 .name = "gpo:trig_net_out",
86 .gpio = AT91_PIN_PB20,
88 .default_trigger = "none",
89 .default_state = LEDS_GPIO_DEFSTATE_OFF,
92 .name = "gpo:trig_net_dir",
93 .gpio = AT91_PIN_PB19,
95 .default_trigger = "none",
96 .default_state = LEDS_GPIO_DEFSTATE_OFF,
99 .name = "gpo:charge_dis",
100 .gpio = AT91_PIN_PC2,
102 .default_trigger = "none",
103 .default_state = LEDS_GPIO_DEFSTATE_OFF,
107 .gpio = AT91_PIN_PB17,
109 .default_trigger = "none",
110 .default_state = LEDS_GPIO_DEFSTATE_OFF,
114 .gpio = AT91_PIN_PB18,
116 .default_trigger = "none",
117 .default_state = LEDS_GPIO_DEFSTATE_OFF,
121 .gpio = AT91_PIN_PB16,
123 .default_trigger = "none",
124 .default_state = LEDS_GPIO_DEFSTATE_ON,
128 static struct gpio_led_platform_data gpio_led_info = {
130 .num_leds = ARRAY_SIZE(gpio_leds),
133 static struct platform_device leds = {
137 .platform_data = &gpio_led_info,
141 static void __init gsia18s_leds_init(void)
143 platform_device_register(&leds);
146 /* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
147 static struct gpio_led pcf_gpio_leds1[] = {
149 .name = "gpo:hdc_power",
150 .gpio = PCF_GPIO_HDC_POWER,
152 .default_trigger = "none",
153 .default_state = LEDS_GPIO_DEFSTATE_OFF,
156 .name = "gpo:wifi_setup",
157 .gpio = PCF_GPIO_WIFI_SETUP,
159 .default_trigger = "none",
160 .default_state = LEDS_GPIO_DEFSTATE_OFF,
163 .name = "gpo:wifi_enable",
164 .gpio = PCF_GPIO_WIFI_ENABLE,
166 .default_trigger = "none",
167 .default_state = LEDS_GPIO_DEFSTATE_OFF,
170 .name = "gpo:wifi_reset",
171 .gpio = PCF_GPIO_WIFI_RESET,
173 .default_trigger = "none",
174 .default_state = LEDS_GPIO_DEFSTATE_ON,
176 /* bit 4 used as GPI */
178 .name = "gpo:gps_setup",
179 .gpio = PCF_GPIO_GPS_SETUP,
181 .default_trigger = "none",
182 .default_state = LEDS_GPIO_DEFSTATE_OFF,
185 .name = "gpo:gps_standby",
186 .gpio = PCF_GPIO_GPS_STANDBY,
188 .default_trigger = "none",
189 .default_state = LEDS_GPIO_DEFSTATE_ON,
192 .name = "gpo:gps_power",
193 .gpio = PCF_GPIO_GPS_POWER,
195 .default_trigger = "none",
196 .default_state = LEDS_GPIO_DEFSTATE_OFF,
200 static struct gpio_led_platform_data pcf_gpio_led_info1 = {
201 .leds = pcf_gpio_leds1,
202 .num_leds = ARRAY_SIZE(pcf_gpio_leds1),
205 static struct platform_device pcf_leds1 = {
206 .name = "leds-gpio", /* GS_IA18-CB_board */
209 .platform_data = &pcf_gpio_led_info1,
213 /* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
214 static struct gpio_led pcf_gpio_leds2[] = {
216 .name = "gpo:alarm_1",
217 .gpio = PCF_GPIO_ALARM1,
219 .default_trigger = "none",
220 .default_state = LEDS_GPIO_DEFSTATE_OFF,
223 .name = "gpo:alarm_2",
224 .gpio = PCF_GPIO_ALARM2,
226 .default_trigger = "none",
227 .default_state = LEDS_GPIO_DEFSTATE_OFF,
230 .name = "gpo:alarm_3",
231 .gpio = PCF_GPIO_ALARM3,
233 .default_trigger = "none",
234 .default_state = LEDS_GPIO_DEFSTATE_OFF,
237 .name = "gpo:alarm_4",
238 .gpio = PCF_GPIO_ALARM4,
240 .default_trigger = "none",
241 .default_state = LEDS_GPIO_DEFSTATE_OFF,
243 /* bits 4, 5, 6 not used */
245 .name = "gpo:alarm_v_relay_on",
246 .gpio = PCF_GPIO_ALARM_V_RELAY_ON,
248 .default_trigger = "none",
249 .default_state = LEDS_GPIO_DEFSTATE_OFF,
253 static struct gpio_led_platform_data pcf_gpio_led_info2 = {
254 .leds = pcf_gpio_leds2,
255 .num_leds = ARRAY_SIZE(pcf_gpio_leds2),
258 static struct platform_device pcf_leds2 = {
262 .platform_data = &pcf_gpio_led_info2,
266 /* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
267 static struct gpio_led pcf_gpio_leds3[] = {
269 .name = "gpo:modem_power",
270 .gpio = PCF_GPIO_MODEM_POWER,
272 .default_trigger = "none",
273 .default_state = LEDS_GPIO_DEFSTATE_OFF,
275 /* bits 1 and 2 not used */
277 .name = "gpo:modem_reset",
278 .gpio = PCF_GPIO_MODEM_RESET,
280 .default_trigger = "none",
281 .default_state = LEDS_GPIO_DEFSTATE_ON,
283 /* bits 4, 5 and 6 not used */
285 .name = "gpo:trx_reset",
286 .gpio = PCF_GPIO_TRX_RESET,
288 .default_trigger = "none",
289 .default_state = LEDS_GPIO_DEFSTATE_ON,
293 static struct gpio_led_platform_data pcf_gpio_led_info3 = {
294 .leds = pcf_gpio_leds3,
295 .num_leds = ARRAY_SIZE(pcf_gpio_leds3),
298 static struct platform_device pcf_leds3 = {
302 .platform_data = &pcf_gpio_led_info3,
306 static void __init gsia18s_pcf_leds_init(void)
308 platform_device_register(&pcf_leds1);
309 platform_device_register(&pcf_leds2);
310 platform_device_register(&pcf_leds3);
316 static struct spi_board_info gsia18s_spi_devices[] = {
317 { /* User accessible spi0, cs0 used for communication with MSP RTC */
318 .modalias = "spidev",
321 .max_speed_hz = 580000,
324 { /* User accessible spi1, cs0 used for communication with int. DSP */
325 .modalias = "spidev",
328 .max_speed_hz = 5600000,
331 { /* User accessible spi1, cs1 used for communication with ext. DSP */
332 .modalias = "spidev",
335 .max_speed_hz = 5600000,
338 { /* User accessible spi1, cs2 used for communication with ext. DSP */
339 .modalias = "spidev",
342 .max_speed_hz = 5600000,
345 { /* User accessible spi1, cs3 used for communication with ext. DSP */
346 .modalias = "spidev",
349 .max_speed_hz = 5600000,
357 static struct gpio_keys_button buttons[] = {
359 .gpio = GPIO_TRIG_NET_IN,
361 .desc = "TRIG_NET_IN",
366 { /* SW80 on the GS_IA18_S-MN board*/
367 .gpio = GPIO_CARD_UNMOUNT_0,
369 .desc = "Card umount 0",
374 { /* SW79 on the GS_IA18_S-MN board*/
375 .gpio = GPIO_CARD_UNMOUNT_1,
377 .desc = "Card umount 1",
382 { /* SW280 on the GS_IA18-CB board*/
383 .gpio = GPIO_KEY_POWER,
385 .desc = "Power Off Button",
392 static struct gpio_keys_platform_data button_data = {
394 .nbuttons = ARRAY_SIZE(buttons),
397 static struct platform_device button_device = {
402 .platform_data = &button_data,
406 static void __init gsia18s_add_device_buttons(void)
408 at91_set_gpio_input(GPIO_TRIG_NET_IN, 1);
409 at91_set_deglitch(GPIO_TRIG_NET_IN, 1);
410 at91_set_gpio_input(GPIO_CARD_UNMOUNT_0, 1);
411 at91_set_deglitch(GPIO_CARD_UNMOUNT_0, 1);
412 at91_set_gpio_input(GPIO_CARD_UNMOUNT_1, 1);
413 at91_set_deglitch(GPIO_CARD_UNMOUNT_1, 1);
414 at91_set_gpio_input(GPIO_KEY_POWER, 0);
415 at91_set_deglitch(GPIO_KEY_POWER, 1);
417 platform_device_register(&button_device);
423 static int pcf8574x_0x20_setup(struct i2c_client *client, int gpio,
424 unsigned int ngpio, void *context)
428 status = gpio_request(gpio + PCF_GPIO_ETH_DETECT, "eth_det");
430 pr_err("error: can't request GPIO%d\n",
431 gpio + PCF_GPIO_ETH_DETECT);
434 status = gpio_direction_input(gpio + PCF_GPIO_ETH_DETECT);
436 pr_err("error: can't setup GPIO%d as input\n",
437 gpio + PCF_GPIO_ETH_DETECT);
440 status = gpio_export(gpio + PCF_GPIO_ETH_DETECT, false);
442 pr_err("error: can't export GPIO%d\n",
443 gpio + PCF_GPIO_ETH_DETECT);
446 status = gpio_sysfs_set_active_low(gpio + PCF_GPIO_ETH_DETECT, 1);
448 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
449 gpio + PCF_GPIO_ETH_DETECT);
456 static int pcf8574x_0x20_teardown(struct i2c_client *client, int gpio,
457 unsigned ngpio, void *context)
459 gpio_free(gpio + PCF_GPIO_ETH_DETECT);
463 static struct pcf857x_platform_data pcf20_pdata = {
464 .gpio_base = GS_IA18_S_PCF_GPIO_BASE0,
466 .setup = pcf8574x_0x20_setup,
467 .teardown = pcf8574x_0x20_teardown,
470 static struct pcf857x_platform_data pcf22_pdata = {
471 .gpio_base = GS_IA18_S_PCF_GPIO_BASE1,
474 static struct pcf857x_platform_data pcf24_pdata = {
475 .gpio_base = GS_IA18_S_PCF_GPIO_BASE2,
478 static struct i2c_board_info __initdata gsia18s_i2c_devices[] = {
479 { /* U1 on the GS_IA18-CB_V3 board */
480 I2C_BOARD_INFO("pcf8574", 0x20),
481 .platform_data = &pcf20_pdata,
483 { /* U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
484 I2C_BOARD_INFO("pcf8574", 0x22),
485 .platform_data = &pcf22_pdata,
487 { /* U1 on the GS_2G-OPT23-A_V0 board (Modem) */
488 I2C_BOARD_INFO("pcf8574", 0x24),
489 .platform_data = &pcf24_pdata,
491 { /* U161 on the GS_IA18_S-MN board */
492 I2C_BOARD_INFO("24c1024", 0x50),
494 { /* U162 on the GS_IA18_S-MN board */
495 I2C_BOARD_INFO("24c01", 0x53),
502 static struct at91_cf_data __initdata gsia18s_cf1_data = {
503 .irq_pin = AT91_PIN_PA27,
504 .det_pin = AT91_PIN_PB30,
506 .rst_pin = AT91_PIN_PB31,
508 .flags = AT91_CF_TRUE_IDE,
511 /* Power Off by RTC */
512 static void gsia18s_power_off(void)
514 pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
515 at91_set_gpio_output(AT91_PIN_PA25, 1);
516 /* Spin to death... */
521 static int __init gsia18s_power_off_init(void)
523 pm_power_off = gsia18s_power_off;
527 /* ---------------------------------------------------------------------------*/
529 static void __init gsia18s_board_init(void)
532 * USART0 on ttyS1 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI).
533 * Used for Internal Analog Modem.
535 at91_register_uart(AT91SAM9260_ID_US0, 1,
536 ATMEL_UART_CTS | ATMEL_UART_RTS |
537 ATMEL_UART_DTR | ATMEL_UART_DSR |
538 ATMEL_UART_DCD | ATMEL_UART_RI);
540 * USART1 on ttyS2 (Rx, Tx, CTS, RTS).
541 * Used for GPS or WiFi or Data stream.
543 at91_register_uart(AT91SAM9260_ID_US1, 2,
544 ATMEL_UART_CTS | ATMEL_UART_RTS);
546 * USART2 on ttyS3 (Rx, Tx, CTS, RTS).
547 * Used for External Modem.
549 at91_register_uart(AT91SAM9260_ID_US2, 3,
550 ATMEL_UART_CTS | ATMEL_UART_RTS);
552 * USART3 on ttyS4 (Rx, Tx, RTS).
555 at91_register_uart(AT91SAM9260_ID_US3, 4, ATMEL_UART_RTS);
558 * USART4 on ttyS5 (Rx, Tx).
559 * Used for TRX433 Radio Module.
561 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
562 stamp9g20_board_init();
563 at91_add_device_usbh(&usbh_data);
564 at91_add_device_udc(&udc_data);
565 at91_add_device_eth(&macb_data);
567 gsia18s_pcf_leds_init();
568 gsia18s_add_device_buttons();
569 at91_add_device_i2c(gsia18s_i2c_devices,
570 ARRAY_SIZE(gsia18s_i2c_devices));
571 at91_add_device_cf(&gsia18s_cf1_data);
572 at91_add_device_spi(gsia18s_spi_devices,
573 ARRAY_SIZE(gsia18s_spi_devices));
574 gsia18s_power_off_init();
577 MACHINE_START(GSIA18S, "GS_IA18_S")
578 .init_time = at91sam926x_pit_init,
579 .map_io = at91_map_io,
580 .handle_irq = at91_aic_handle_irq,
581 .init_early = gsia18s_init_early,
582 .init_irq = at91_init_irq_default,
583 .init_machine = gsia18s_board_init,