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/board.h>
34 #include <mach/at91sam9_smc.h>
35 #include <mach/gsia18s.h>
36 #include <mach/stamp9g20.h>
41 static void __init
gsia18s_init_early(void)
43 stamp9g20_init_early();
46 * USART0 on ttyS1 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI).
47 * Used for Internal Analog Modem.
49 at91_register_uart(AT91SAM9260_ID_US0
, 1,
50 ATMEL_UART_CTS
| ATMEL_UART_RTS
|
51 ATMEL_UART_DTR
| ATMEL_UART_DSR
|
52 ATMEL_UART_DCD
| ATMEL_UART_RI
);
54 * USART1 on ttyS2 (Rx, Tx, CTS, RTS).
55 * Used for GPS or WiFi or Data stream.
57 at91_register_uart(AT91SAM9260_ID_US1
, 2,
58 ATMEL_UART_CTS
| ATMEL_UART_RTS
);
60 * USART2 on ttyS3 (Rx, Tx, CTS, RTS).
61 * Used for External Modem.
63 at91_register_uart(AT91SAM9260_ID_US2
, 3,
64 ATMEL_UART_CTS
| ATMEL_UART_RTS
);
66 * USART3 on ttyS4 (Rx, Tx, RTS).
69 at91_register_uart(AT91SAM9260_ID_US3
, 4, ATMEL_UART_RTS
);
72 * USART4 on ttyS5 (Rx, Tx).
73 * Used for TRX433 Radio Module.
75 at91_register_uart(AT91SAM9260_ID_US4
, 5, 0);
81 static struct at91_usbh_data __initdata usbh_data
= {
83 .vbus_pin
= {-EINVAL
, -EINVAL
},
84 .overcurrent_pin
= {-EINVAL
, -EINVAL
},
90 static struct at91_udc_data __initdata udc_data
= {
91 .vbus_pin
= AT91_PIN_PA22
,
92 .pullup_pin
= -EINVAL
, /* pull-up driven by UDC */
96 * MACB Ethernet device
98 static struct macb_platform_data __initdata macb_data
= {
99 .phy_irq_pin
= AT91_PIN_PA28
,
106 static struct gpio_led gpio_leds
[] = {
108 .name
= "gpo:spi1reset",
109 .gpio
= AT91_PIN_PC1
,
111 .default_trigger
= "none",
112 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
115 .name
= "gpo:trig_net_out",
116 .gpio
= AT91_PIN_PB20
,
118 .default_trigger
= "none",
119 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
122 .name
= "gpo:trig_net_dir",
123 .gpio
= AT91_PIN_PB19
,
125 .default_trigger
= "none",
126 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
129 .name
= "gpo:charge_dis",
130 .gpio
= AT91_PIN_PC2
,
132 .default_trigger
= "none",
133 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
137 .gpio
= AT91_PIN_PB17
,
139 .default_trigger
= "none",
140 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
144 .gpio
= AT91_PIN_PB18
,
146 .default_trigger
= "none",
147 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
151 .gpio
= AT91_PIN_PB16
,
153 .default_trigger
= "none",
154 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
158 static struct gpio_led_platform_data gpio_led_info
= {
160 .num_leds
= ARRAY_SIZE(gpio_leds
),
163 static struct platform_device leds
= {
167 .platform_data
= &gpio_led_info
,
171 static void __init
gsia18s_leds_init(void)
173 platform_device_register(&leds
);
176 /* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
177 static struct gpio_led pcf_gpio_leds1
[] = {
179 .name
= "gpo:hdc_power",
180 .gpio
= PCF_GPIO_HDC_POWER
,
182 .default_trigger
= "none",
183 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
186 .name
= "gpo:wifi_setup",
187 .gpio
= PCF_GPIO_WIFI_SETUP
,
189 .default_trigger
= "none",
190 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
193 .name
= "gpo:wifi_enable",
194 .gpio
= PCF_GPIO_WIFI_ENABLE
,
196 .default_trigger
= "none",
197 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
200 .name
= "gpo:wifi_reset",
201 .gpio
= PCF_GPIO_WIFI_RESET
,
203 .default_trigger
= "none",
204 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
206 /* bit 4 used as GPI */
208 .name
= "gpo:gps_setup",
209 .gpio
= PCF_GPIO_GPS_SETUP
,
211 .default_trigger
= "none",
212 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
215 .name
= "gpo:gps_standby",
216 .gpio
= PCF_GPIO_GPS_STANDBY
,
218 .default_trigger
= "none",
219 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
222 .name
= "gpo:gps_power",
223 .gpio
= PCF_GPIO_GPS_POWER
,
225 .default_trigger
= "none",
226 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
230 static struct gpio_led_platform_data pcf_gpio_led_info1
= {
231 .leds
= pcf_gpio_leds1
,
232 .num_leds
= ARRAY_SIZE(pcf_gpio_leds1
),
235 static struct platform_device pcf_leds1
= {
236 .name
= "leds-gpio", /* GS_IA18-CB_board */
239 .platform_data
= &pcf_gpio_led_info1
,
243 /* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
244 static struct gpio_led pcf_gpio_leds2
[] = {
246 .name
= "gpo:alarm_1",
247 .gpio
= PCF_GPIO_ALARM1
,
249 .default_trigger
= "none",
250 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
253 .name
= "gpo:alarm_2",
254 .gpio
= PCF_GPIO_ALARM2
,
256 .default_trigger
= "none",
257 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
260 .name
= "gpo:alarm_3",
261 .gpio
= PCF_GPIO_ALARM3
,
263 .default_trigger
= "none",
264 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
267 .name
= "gpo:alarm_4",
268 .gpio
= PCF_GPIO_ALARM4
,
270 .default_trigger
= "none",
271 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
273 /* bits 4, 5, 6 not used */
275 .name
= "gpo:alarm_v_relay_on",
276 .gpio
= PCF_GPIO_ALARM_V_RELAY_ON
,
278 .default_trigger
= "none",
279 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
283 static struct gpio_led_platform_data pcf_gpio_led_info2
= {
284 .leds
= pcf_gpio_leds2
,
285 .num_leds
= ARRAY_SIZE(pcf_gpio_leds2
),
288 static struct platform_device pcf_leds2
= {
292 .platform_data
= &pcf_gpio_led_info2
,
296 /* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
297 static struct gpio_led pcf_gpio_leds3
[] = {
299 .name
= "gpo:modem_power",
300 .gpio
= PCF_GPIO_MODEM_POWER
,
302 .default_trigger
= "none",
303 .default_state
= LEDS_GPIO_DEFSTATE_OFF
,
305 /* bits 1 and 2 not used */
307 .name
= "gpo:modem_reset",
308 .gpio
= PCF_GPIO_MODEM_RESET
,
310 .default_trigger
= "none",
311 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
313 /* bits 4, 5 and 6 not used */
315 .name
= "gpo:trx_reset",
316 .gpio
= PCF_GPIO_TRX_RESET
,
318 .default_trigger
= "none",
319 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
323 static struct gpio_led_platform_data pcf_gpio_led_info3
= {
324 .leds
= pcf_gpio_leds3
,
325 .num_leds
= ARRAY_SIZE(pcf_gpio_leds3
),
328 static struct platform_device pcf_leds3
= {
332 .platform_data
= &pcf_gpio_led_info3
,
336 static void __init
gsia18s_pcf_leds_init(void)
338 platform_device_register(&pcf_leds1
);
339 platform_device_register(&pcf_leds2
);
340 platform_device_register(&pcf_leds3
);
346 static struct spi_board_info gsia18s_spi_devices
[] = {
347 { /* User accessible spi0, cs0 used for communication with MSP RTC */
348 .modalias
= "spidev",
351 .max_speed_hz
= 580000,
354 { /* User accessible spi1, cs0 used for communication with int. DSP */
355 .modalias
= "spidev",
358 .max_speed_hz
= 5600000,
361 { /* User accessible spi1, cs1 used for communication with ext. DSP */
362 .modalias
= "spidev",
365 .max_speed_hz
= 5600000,
368 { /* User accessible spi1, cs2 used for communication with ext. DSP */
369 .modalias
= "spidev",
372 .max_speed_hz
= 5600000,
375 { /* User accessible spi1, cs3 used for communication with ext. DSP */
376 .modalias
= "spidev",
379 .max_speed_hz
= 5600000,
387 static struct gpio_keys_button buttons
[] = {
389 .gpio
= GPIO_TRIG_NET_IN
,
391 .desc
= "TRIG_NET_IN",
396 { /* SW80 on the GS_IA18_S-MN board*/
397 .gpio
= GPIO_CARD_UNMOUNT_0
,
399 .desc
= "Card umount 0",
404 { /* SW79 on the GS_IA18_S-MN board*/
405 .gpio
= GPIO_CARD_UNMOUNT_1
,
407 .desc
= "Card umount 1",
412 { /* SW280 on the GS_IA18-CB board*/
413 .gpio
= GPIO_KEY_POWER
,
415 .desc
= "Power Off Button",
422 static struct gpio_keys_platform_data button_data
= {
424 .nbuttons
= ARRAY_SIZE(buttons
),
427 static struct platform_device button_device
= {
432 .platform_data
= &button_data
,
436 static void __init
gsia18s_add_device_buttons(void)
438 at91_set_gpio_input(GPIO_TRIG_NET_IN
, 1);
439 at91_set_deglitch(GPIO_TRIG_NET_IN
, 1);
440 at91_set_gpio_input(GPIO_CARD_UNMOUNT_0
, 1);
441 at91_set_deglitch(GPIO_CARD_UNMOUNT_0
, 1);
442 at91_set_gpio_input(GPIO_CARD_UNMOUNT_1
, 1);
443 at91_set_deglitch(GPIO_CARD_UNMOUNT_1
, 1);
444 at91_set_gpio_input(GPIO_KEY_POWER
, 0);
445 at91_set_deglitch(GPIO_KEY_POWER
, 1);
447 platform_device_register(&button_device
);
453 static int pcf8574x_0x20_setup(struct i2c_client
*client
, int gpio
,
454 unsigned int ngpio
, void *context
)
458 status
= gpio_request(gpio
+ PCF_GPIO_ETH_DETECT
, "eth_det");
460 pr_err("error: can't request GPIO%d\n",
461 gpio
+ PCF_GPIO_ETH_DETECT
);
464 status
= gpio_direction_input(gpio
+ PCF_GPIO_ETH_DETECT
);
466 pr_err("error: can't setup GPIO%d as input\n",
467 gpio
+ PCF_GPIO_ETH_DETECT
);
470 status
= gpio_export(gpio
+ PCF_GPIO_ETH_DETECT
, false);
472 pr_err("error: can't export GPIO%d\n",
473 gpio
+ PCF_GPIO_ETH_DETECT
);
476 status
= gpio_sysfs_set_active_low(gpio
+ PCF_GPIO_ETH_DETECT
, 1);
478 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
479 gpio
+ PCF_GPIO_ETH_DETECT
);
486 static int pcf8574x_0x20_teardown(struct i2c_client
*client
, int gpio
,
487 unsigned ngpio
, void *context
)
489 gpio_free(gpio
+ PCF_GPIO_ETH_DETECT
);
493 static struct pcf857x_platform_data pcf20_pdata
= {
494 .gpio_base
= GS_IA18_S_PCF_GPIO_BASE0
,
496 .setup
= pcf8574x_0x20_setup
,
497 .teardown
= pcf8574x_0x20_teardown
,
500 static struct pcf857x_platform_data pcf22_pdata
= {
501 .gpio_base
= GS_IA18_S_PCF_GPIO_BASE1
,
504 static struct pcf857x_platform_data pcf24_pdata
= {
505 .gpio_base
= GS_IA18_S_PCF_GPIO_BASE2
,
508 static struct i2c_board_info __initdata gsia18s_i2c_devices
[] = {
509 { /* U1 on the GS_IA18-CB_V3 board */
510 I2C_BOARD_INFO("pcf8574", 0x20),
511 .platform_data
= &pcf20_pdata
,
513 { /* U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
514 I2C_BOARD_INFO("pcf8574", 0x22),
515 .platform_data
= &pcf22_pdata
,
517 { /* U1 on the GS_2G-OPT23-A_V0 board (Modem) */
518 I2C_BOARD_INFO("pcf8574", 0x24),
519 .platform_data
= &pcf24_pdata
,
521 { /* U161 on the GS_IA18_S-MN board */
522 I2C_BOARD_INFO("24c1024", 0x50),
524 { /* U162 on the GS_IA18_S-MN board */
525 I2C_BOARD_INFO("24c01", 0x53),
532 static struct at91_cf_data __initdata gsia18s_cf1_data
= {
533 .irq_pin
= AT91_PIN_PA27
,
534 .det_pin
= AT91_PIN_PB30
,
536 .rst_pin
= AT91_PIN_PB31
,
538 .flags
= AT91_CF_TRUE_IDE
,
541 /* Power Off by RTC */
542 static void gsia18s_power_off(void)
544 pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
545 at91_set_gpio_output(AT91_PIN_PA25
, 1);
546 /* Spin to death... */
551 static int __init
gsia18s_power_off_init(void)
553 pm_power_off
= gsia18s_power_off
;
557 /* ---------------------------------------------------------------------------*/
559 static void __init
gsia18s_board_init(void)
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
);
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();
576 MACHINE_START(GSIA18S
, "GS_IA18_S")
577 .timer
= &at91sam926x_timer
,
578 .map_io
= at91_map_io
,
579 .init_early
= gsia18s_init_early
,
580 .init_irq
= at91_init_irq_default
,
581 .init_machine
= gsia18s_board_init
,