Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / arm / mach-at91 / board-gsia18s.c
blobb729dd1271bfbb2210e0e564a11cbbfbfd73e6fe
1 /*
2 * Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
3 * taskit GmbH
4 * 2010 Igor Plyatov <plyatov@gmail.com>
5 * GeoSIG Ltd
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>
36 #include "at91_aic.h"
37 #include "board.h"
38 #include "sam9_smc.h"
39 #include "generic.h"
40 #include "gsia18s.h"
41 #include "stamp9g20.h"
42 #include "gpio.h"
44 static void __init gsia18s_init_early(void)
46 stamp9g20_init_early();
50 * Two USB Host ports
52 static struct at91_usbh_data __initdata usbh_data = {
53 .ports = 2,
54 .vbus_pin = {-EINVAL, -EINVAL},
55 .overcurrent_pin= {-EINVAL, -EINVAL},
59 * USB Device port
61 static struct at91_udc_data __initdata udc_data = {
62 .vbus_pin = AT91_PIN_PA22,
63 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
67 * MACB Ethernet device
69 static struct macb_platform_data __initdata macb_data = {
70 .phy_irq_pin = AT91_PIN_PA28,
71 .is_rmii = 1,
75 * LEDs and GPOs
77 static struct gpio_led gpio_leds[] = {
79 .name = "gpo:spi1reset",
80 .gpio = AT91_PIN_PC1,
81 .active_low = 0,
82 .default_trigger = "none",
83 .default_state = LEDS_GPIO_DEFSTATE_OFF,
86 .name = "gpo:trig_net_out",
87 .gpio = AT91_PIN_PB20,
88 .active_low = 0,
89 .default_trigger = "none",
90 .default_state = LEDS_GPIO_DEFSTATE_OFF,
93 .name = "gpo:trig_net_dir",
94 .gpio = AT91_PIN_PB19,
95 .active_low = 0,
96 .default_trigger = "none",
97 .default_state = LEDS_GPIO_DEFSTATE_OFF,
100 .name = "gpo:charge_dis",
101 .gpio = AT91_PIN_PC2,
102 .active_low = 0,
103 .default_trigger = "none",
104 .default_state = LEDS_GPIO_DEFSTATE_OFF,
107 .name = "led:event",
108 .gpio = AT91_PIN_PB17,
109 .active_low = 1,
110 .default_trigger = "none",
111 .default_state = LEDS_GPIO_DEFSTATE_OFF,
114 .name = "led:lan",
115 .gpio = AT91_PIN_PB18,
116 .active_low = 1,
117 .default_trigger = "none",
118 .default_state = LEDS_GPIO_DEFSTATE_OFF,
121 .name = "led:error",
122 .gpio = AT91_PIN_PB16,
123 .active_low = 1,
124 .default_trigger = "none",
125 .default_state = LEDS_GPIO_DEFSTATE_ON,
129 static struct gpio_led_platform_data gpio_led_info = {
130 .leds = gpio_leds,
131 .num_leds = ARRAY_SIZE(gpio_leds),
134 static struct platform_device leds = {
135 .name = "leds-gpio",
136 .id = 0,
137 .dev = {
138 .platform_data = &gpio_led_info,
142 static void __init gsia18s_leds_init(void)
144 platform_device_register(&leds);
147 /* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
148 static struct gpio_led pcf_gpio_leds1[] = {
149 { /* bit 0 */
150 .name = "gpo:hdc_power",
151 .gpio = PCF_GPIO_HDC_POWER,
152 .active_low = 0,
153 .default_trigger = "none",
154 .default_state = LEDS_GPIO_DEFSTATE_OFF,
156 { /* bit 1 */
157 .name = "gpo:wifi_setup",
158 .gpio = PCF_GPIO_WIFI_SETUP,
159 .active_low = 1,
160 .default_trigger = "none",
161 .default_state = LEDS_GPIO_DEFSTATE_OFF,
163 { /* bit 2 */
164 .name = "gpo:wifi_enable",
165 .gpio = PCF_GPIO_WIFI_ENABLE,
166 .active_low = 1,
167 .default_trigger = "none",
168 .default_state = LEDS_GPIO_DEFSTATE_OFF,
170 { /* bit 3 */
171 .name = "gpo:wifi_reset",
172 .gpio = PCF_GPIO_WIFI_RESET,
173 .active_low = 1,
174 .default_trigger = "none",
175 .default_state = LEDS_GPIO_DEFSTATE_ON,
177 /* bit 4 used as GPI */
178 { /* bit 5 */
179 .name = "gpo:gps_setup",
180 .gpio = PCF_GPIO_GPS_SETUP,
181 .active_low = 1,
182 .default_trigger = "none",
183 .default_state = LEDS_GPIO_DEFSTATE_OFF,
185 { /* bit 6 */
186 .name = "gpo:gps_standby",
187 .gpio = PCF_GPIO_GPS_STANDBY,
188 .active_low = 0,
189 .default_trigger = "none",
190 .default_state = LEDS_GPIO_DEFSTATE_ON,
192 { /* bit 7 */
193 .name = "gpo:gps_power",
194 .gpio = PCF_GPIO_GPS_POWER,
195 .active_low = 0,
196 .default_trigger = "none",
197 .default_state = LEDS_GPIO_DEFSTATE_OFF,
201 static struct gpio_led_platform_data pcf_gpio_led_info1 = {
202 .leds = pcf_gpio_leds1,
203 .num_leds = ARRAY_SIZE(pcf_gpio_leds1),
206 static struct platform_device pcf_leds1 = {
207 .name = "leds-gpio", /* GS_IA18-CB_board */
208 .id = 1,
209 .dev = {
210 .platform_data = &pcf_gpio_led_info1,
214 /* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
215 static struct gpio_led pcf_gpio_leds2[] = {
216 { /* bit 0 */
217 .name = "gpo:alarm_1",
218 .gpio = PCF_GPIO_ALARM1,
219 .active_low = 1,
220 .default_trigger = "none",
221 .default_state = LEDS_GPIO_DEFSTATE_OFF,
223 { /* bit 1 */
224 .name = "gpo:alarm_2",
225 .gpio = PCF_GPIO_ALARM2,
226 .active_low = 1,
227 .default_trigger = "none",
228 .default_state = LEDS_GPIO_DEFSTATE_OFF,
230 { /* bit 2 */
231 .name = "gpo:alarm_3",
232 .gpio = PCF_GPIO_ALARM3,
233 .active_low = 1,
234 .default_trigger = "none",
235 .default_state = LEDS_GPIO_DEFSTATE_OFF,
237 { /* bit 3 */
238 .name = "gpo:alarm_4",
239 .gpio = PCF_GPIO_ALARM4,
240 .active_low = 1,
241 .default_trigger = "none",
242 .default_state = LEDS_GPIO_DEFSTATE_OFF,
244 /* bits 4, 5, 6 not used */
245 { /* bit 7 */
246 .name = "gpo:alarm_v_relay_on",
247 .gpio = PCF_GPIO_ALARM_V_RELAY_ON,
248 .active_low = 0,
249 .default_trigger = "none",
250 .default_state = LEDS_GPIO_DEFSTATE_OFF,
254 static struct gpio_led_platform_data pcf_gpio_led_info2 = {
255 .leds = pcf_gpio_leds2,
256 .num_leds = ARRAY_SIZE(pcf_gpio_leds2),
259 static struct platform_device pcf_leds2 = {
260 .name = "leds-gpio",
261 .id = 2,
262 .dev = {
263 .platform_data = &pcf_gpio_led_info2,
267 /* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
268 static struct gpio_led pcf_gpio_leds3[] = {
269 { /* bit 0 */
270 .name = "gpo:modem_power",
271 .gpio = PCF_GPIO_MODEM_POWER,
272 .active_low = 1,
273 .default_trigger = "none",
274 .default_state = LEDS_GPIO_DEFSTATE_OFF,
276 /* bits 1 and 2 not used */
277 { /* bit 3 */
278 .name = "gpo:modem_reset",
279 .gpio = PCF_GPIO_MODEM_RESET,
280 .active_low = 1,
281 .default_trigger = "none",
282 .default_state = LEDS_GPIO_DEFSTATE_ON,
284 /* bits 4, 5 and 6 not used */
285 { /* bit 7 */
286 .name = "gpo:trx_reset",
287 .gpio = PCF_GPIO_TRX_RESET,
288 .active_low = 1,
289 .default_trigger = "none",
290 .default_state = LEDS_GPIO_DEFSTATE_ON,
294 static struct gpio_led_platform_data pcf_gpio_led_info3 = {
295 .leds = pcf_gpio_leds3,
296 .num_leds = ARRAY_SIZE(pcf_gpio_leds3),
299 static struct platform_device pcf_leds3 = {
300 .name = "leds-gpio",
301 .id = 3,
302 .dev = {
303 .platform_data = &pcf_gpio_led_info3,
307 static void __init gsia18s_pcf_leds_init(void)
309 platform_device_register(&pcf_leds1);
310 platform_device_register(&pcf_leds2);
311 platform_device_register(&pcf_leds3);
315 * SPI busses.
317 static struct spi_board_info gsia18s_spi_devices[] = {
318 { /* User accessible spi0, cs0 used for communication with MSP RTC */
319 .modalias = "spidev",
320 .bus_num = 0,
321 .chip_select = 0,
322 .max_speed_hz = 580000,
323 .mode = SPI_MODE_1,
325 { /* User accessible spi1, cs0 used for communication with int. DSP */
326 .modalias = "spidev",
327 .bus_num = 1,
328 .chip_select = 0,
329 .max_speed_hz = 5600000,
330 .mode = SPI_MODE_0,
332 { /* User accessible spi1, cs1 used for communication with ext. DSP */
333 .modalias = "spidev",
334 .bus_num = 1,
335 .chip_select = 1,
336 .max_speed_hz = 5600000,
337 .mode = SPI_MODE_0,
339 { /* User accessible spi1, cs2 used for communication with ext. DSP */
340 .modalias = "spidev",
341 .bus_num = 1,
342 .chip_select = 2,
343 .max_speed_hz = 5600000,
344 .mode = SPI_MODE_0,
346 { /* User accessible spi1, cs3 used for communication with ext. DSP */
347 .modalias = "spidev",
348 .bus_num = 1,
349 .chip_select = 3,
350 .max_speed_hz = 5600000,
351 .mode = SPI_MODE_0,
356 * GPI Buttons
358 static struct gpio_keys_button buttons[] = {
360 .gpio = GPIO_TRIG_NET_IN,
361 .code = BTN_1,
362 .desc = "TRIG_NET_IN",
363 .type = EV_KEY,
364 .active_low = 0,
365 .wakeup = 1,
367 { /* SW80 on the GS_IA18_S-MN board*/
368 .gpio = GPIO_CARD_UNMOUNT_0,
369 .code = BTN_2,
370 .desc = "Card umount 0",
371 .type = EV_KEY,
372 .active_low = 1,
373 .wakeup = 1,
375 { /* SW79 on the GS_IA18_S-MN board*/
376 .gpio = GPIO_CARD_UNMOUNT_1,
377 .code = BTN_3,
378 .desc = "Card umount 1",
379 .type = EV_KEY,
380 .active_low = 1,
381 .wakeup = 1,
383 { /* SW280 on the GS_IA18-CB board*/
384 .gpio = GPIO_KEY_POWER,
385 .code = KEY_POWER,
386 .desc = "Power Off Button",
387 .type = EV_KEY,
388 .active_low = 0,
389 .wakeup = 1,
393 static struct gpio_keys_platform_data button_data = {
394 .buttons = buttons,
395 .nbuttons = ARRAY_SIZE(buttons),
398 static struct platform_device button_device = {
399 .name = "gpio-keys",
400 .id = -1,
401 .num_resources = 0,
402 .dev = {
403 .platform_data = &button_data,
407 static void __init gsia18s_add_device_buttons(void)
409 at91_set_gpio_input(GPIO_TRIG_NET_IN, 1);
410 at91_set_deglitch(GPIO_TRIG_NET_IN, 1);
411 at91_set_gpio_input(GPIO_CARD_UNMOUNT_0, 1);
412 at91_set_deglitch(GPIO_CARD_UNMOUNT_0, 1);
413 at91_set_gpio_input(GPIO_CARD_UNMOUNT_1, 1);
414 at91_set_deglitch(GPIO_CARD_UNMOUNT_1, 1);
415 at91_set_gpio_input(GPIO_KEY_POWER, 0);
416 at91_set_deglitch(GPIO_KEY_POWER, 1);
418 platform_device_register(&button_device);
422 * I2C
424 static int pcf8574x_0x20_setup(struct i2c_client *client, int gpio,
425 unsigned int ngpio, void *context)
427 int status;
429 status = gpio_request(gpio + PCF_GPIO_ETH_DETECT, "eth_det");
430 if (status < 0) {
431 pr_err("error: can't request GPIO%d\n",
432 gpio + PCF_GPIO_ETH_DETECT);
433 return status;
435 status = gpio_direction_input(gpio + PCF_GPIO_ETH_DETECT);
436 if (status < 0) {
437 pr_err("error: can't setup GPIO%d as input\n",
438 gpio + PCF_GPIO_ETH_DETECT);
439 return status;
441 status = gpio_export(gpio + PCF_GPIO_ETH_DETECT, false);
442 if (status < 0) {
443 pr_err("error: can't export GPIO%d\n",
444 gpio + PCF_GPIO_ETH_DETECT);
445 return status;
447 status = gpio_sysfs_set_active_low(gpio + PCF_GPIO_ETH_DETECT, 1);
448 if (status < 0) {
449 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
450 gpio + PCF_GPIO_ETH_DETECT);
451 return status;
454 return 0;
457 static int pcf8574x_0x20_teardown(struct i2c_client *client, int gpio,
458 unsigned ngpio, void *context)
460 gpio_free(gpio + PCF_GPIO_ETH_DETECT);
461 return 0;
464 static struct pcf857x_platform_data pcf20_pdata = {
465 .gpio_base = GS_IA18_S_PCF_GPIO_BASE0,
466 .n_latch = (1 << 4),
467 .setup = pcf8574x_0x20_setup,
468 .teardown = pcf8574x_0x20_teardown,
471 static struct pcf857x_platform_data pcf22_pdata = {
472 .gpio_base = GS_IA18_S_PCF_GPIO_BASE1,
475 static struct pcf857x_platform_data pcf24_pdata = {
476 .gpio_base = GS_IA18_S_PCF_GPIO_BASE2,
479 static struct i2c_board_info __initdata gsia18s_i2c_devices[] = {
480 { /* U1 on the GS_IA18-CB_V3 board */
481 I2C_BOARD_INFO("pcf8574", 0x20),
482 .platform_data = &pcf20_pdata,
484 { /* U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
485 I2C_BOARD_INFO("pcf8574", 0x22),
486 .platform_data = &pcf22_pdata,
488 { /* U1 on the GS_2G-OPT23-A_V0 board (Modem) */
489 I2C_BOARD_INFO("pcf8574", 0x24),
490 .platform_data = &pcf24_pdata,
492 { /* U161 on the GS_IA18_S-MN board */
493 I2C_BOARD_INFO("24c1024", 0x50),
495 { /* U162 on the GS_IA18_S-MN board */
496 I2C_BOARD_INFO("24c01", 0x53),
501 * Compact Flash
503 static struct at91_cf_data __initdata gsia18s_cf1_data = {
504 .irq_pin = AT91_PIN_PA27,
505 .det_pin = AT91_PIN_PB30,
506 .vcc_pin = -EINVAL,
507 .rst_pin = AT91_PIN_PB31,
508 .chipselect = 5,
509 .flags = AT91_CF_TRUE_IDE,
512 /* Power Off by RTC */
513 static void gsia18s_power_off(void)
515 pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
516 at91_set_gpio_output(AT91_PIN_PA25, 1);
517 /* Spin to death... */
518 while (1)
522 static int __init gsia18s_power_off_init(void)
524 pm_power_off = gsia18s_power_off;
525 return 0;
528 /* ---------------------------------------------------------------------------*/
530 static void __init gsia18s_board_init(void)
533 * USART0 on ttyS1 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI).
534 * Used for Internal Analog Modem.
536 at91_register_uart(AT91SAM9260_ID_US0, 1,
537 ATMEL_UART_CTS | ATMEL_UART_RTS |
538 ATMEL_UART_DTR | ATMEL_UART_DSR |
539 ATMEL_UART_DCD | ATMEL_UART_RI);
541 * USART1 on ttyS2 (Rx, Tx, CTS, RTS).
542 * Used for GPS or WiFi or Data stream.
544 at91_register_uart(AT91SAM9260_ID_US1, 2,
545 ATMEL_UART_CTS | ATMEL_UART_RTS);
547 * USART2 on ttyS3 (Rx, Tx, CTS, RTS).
548 * Used for External Modem.
550 at91_register_uart(AT91SAM9260_ID_US2, 3,
551 ATMEL_UART_CTS | ATMEL_UART_RTS);
553 * USART3 on ttyS4 (Rx, Tx, RTS).
554 * Used for RS-485.
556 at91_register_uart(AT91SAM9260_ID_US3, 4, ATMEL_UART_RTS);
559 * USART4 on ttyS5 (Rx, Tx).
560 * Used for TRX433 Radio Module.
562 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
563 stamp9g20_board_init();
564 at91_add_device_usbh(&usbh_data);
565 at91_add_device_udc(&udc_data);
566 at91_add_device_eth(&macb_data);
567 gsia18s_leds_init();
568 gsia18s_pcf_leds_init();
569 gsia18s_add_device_buttons();
570 at91_add_device_i2c(gsia18s_i2c_devices,
571 ARRAY_SIZE(gsia18s_i2c_devices));
572 at91_add_device_cf(&gsia18s_cf1_data);
573 at91_add_device_spi(gsia18s_spi_devices,
574 ARRAY_SIZE(gsia18s_spi_devices));
575 gsia18s_power_off_init();
578 MACHINE_START(GSIA18S, "GS_IA18_S")
579 .init_time = at91sam926x_pit_init,
580 .map_io = at91_map_io,
581 .handle_irq = at91_aic_handle_irq,
582 .init_early = gsia18s_init_early,
583 .init_irq = at91_init_irq_default,
584 .init_machine = gsia18s_board_init,
585 MACHINE_END