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