board-gsia18s.c 14 KB

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