board-gsia18s.c 14 KB

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