board-gsia18s.c 14 KB

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