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