board-gsia18s.c 14 KB

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