board-gsia18s.c 14 KB

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