imote2.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * linux/arch/arm/mach-pxa/imote2.c
  3. *
  4. * Author: Ed C. Epp
  5. * Created: Nov 05, 2002
  6. * Copyright: Intel Corp.
  7. *
  8. * Modified 2008: Jonathan Cameron
  9. *
  10. * The Imote2 is a wireless sensor node platform sold
  11. * by Crossbow (www.xbow.com).
  12. */
  13. #include <linux/init.h>
  14. #include <linux/device.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regulator/machine.h>
  19. #include <linux/gpio.h>
  20. #include <linux/leds.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/i2c.h>
  23. #include <linux/mfd/da903x.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/flash.h>
  28. #include <mach/pxa27x.h>
  29. #include <mach/i2c.h>
  30. #include <mach/udc.h>
  31. #include <mach/mmc.h>
  32. #include <mach/pxa2xx_spi.h>
  33. #include <mach/pxa27x-udc.h>
  34. #include "devices.h"
  35. #include "generic.h"
  36. static unsigned long imote2_pin_config[] __initdata = {
  37. /* Device Identification for wakeup*/
  38. GPIO102_GPIO,
  39. /* Button */
  40. GPIO91_GPIO,
  41. /* DA9030 */
  42. GPIO1_GPIO,
  43. /* MMC */
  44. GPIO32_MMC_CLK,
  45. GPIO112_MMC_CMD,
  46. GPIO92_MMC_DAT_0,
  47. GPIO109_MMC_DAT_1,
  48. GPIO110_MMC_DAT_2,
  49. GPIO111_MMC_DAT_3,
  50. /* 802.15.4 radio - driver out of mainline */
  51. GPIO22_GPIO, /* CC_RSTN */
  52. GPIO114_GPIO, /* CC_FIFO */
  53. GPIO116_GPIO, /* CC_CCA */
  54. GPIO0_GPIO, /* CC_FIFOP */
  55. GPIO16_GPIO, /* CCSFD */
  56. GPIO39_GPIO, /* CSn */
  57. GPIO115_GPIO, /* Power enable */
  58. /* I2C */
  59. GPIO117_I2C_SCL,
  60. GPIO118_I2C_SDA,
  61. /* SSP 3 - 802.15.4 radio */
  62. GPIO39_GPIO, /* Chip Select */
  63. GPIO34_SSP3_SCLK,
  64. GPIO35_SSP3_TXD,
  65. GPIO41_SSP3_RXD,
  66. /* SSP 2 - to daughter boards */
  67. GPIO37_GPIO, /* Chip Select */
  68. GPIO36_SSP2_SCLK,
  69. GPIO38_SSP2_TXD,
  70. GPIO11_SSP2_RXD,
  71. /* SSP 1 - to daughter boards */
  72. GPIO24_GPIO, /* Chip Select */
  73. GPIO23_SSP1_SCLK,
  74. GPIO25_SSP1_TXD,
  75. GPIO26_SSP1_RXD,
  76. /* BTUART Basic Connector*/
  77. GPIO42_BTUART_RXD,
  78. GPIO43_BTUART_TXD,
  79. GPIO44_BTUART_CTS,
  80. GPIO45_BTUART_RTS,
  81. /* STUART Serial console via debug board*/
  82. GPIO46_STUART_RXD,
  83. GPIO47_STUART_TXD,
  84. /* Basic sensor board */
  85. GPIO96_GPIO, /* accelerometer interrupt */
  86. GPIO99_GPIO, /* ADC interrupt */
  87. /* Connector pins specified as gpios */
  88. GPIO94_GPIO, /* large basic connector pin 14 */
  89. GPIO10_GPIO, /* large basic connector pin 23 */
  90. /* LEDS */
  91. GPIO103_GPIO, /* red led */
  92. GPIO104_GPIO, /* green led */
  93. GPIO105_GPIO, /* blue led */
  94. };
  95. static struct gpio_led imote2_led_pins[] = {
  96. {
  97. .name = "imote2:red",
  98. .gpio = 103,
  99. .active_low = 1,
  100. }, {
  101. .name = "imote2:green",
  102. .gpio = 104,
  103. .active_low = 1,
  104. }, {
  105. .name = "imote2:blue",
  106. .gpio = 105,
  107. .active_low = 1,
  108. },
  109. };
  110. static struct gpio_led_platform_data imote2_led_data = {
  111. .num_leds = ARRAY_SIZE(imote2_led_pins),
  112. .leds = imote2_led_pins,
  113. };
  114. static struct platform_device imote2_leds = {
  115. .name = "leds-gpio",
  116. .id = -1,
  117. .dev = {
  118. .platform_data = &imote2_led_data,
  119. },
  120. };
  121. /* Reverse engineered partly from Platformx drivers */
  122. enum imote2_ldos{
  123. vcc_vref,
  124. vcc_cc2420,
  125. vcc_mica,
  126. vcc_bt,
  127. /* The two voltages available to sensor boards */
  128. vcc_sensor_1_8,
  129. vcc_sensor_3,
  130. vcc_sram_ext, /* directly connected to the pxa271 */
  131. vcc_pxa_pll,
  132. vcc_pxa_usim, /* Reference voltage for certain gpios */
  133. vcc_pxa_mem,
  134. vcc_pxa_flash,
  135. vcc_pxa_core, /*Dc-Dc buck not yet supported */
  136. vcc_lcd,
  137. vcc_bb,
  138. vcc_bbio,
  139. vcc_io, /* cc2420 802.15.4 radio and pxa vcc_io ?*/
  140. };
  141. /* The values of the various regulator constraints are obviously dependent
  142. * on exactly what is wired to each ldo. Unfortunately this information is
  143. * not generally available. More information has been requested from Xbow
  144. * but as of yet they haven't been forthcoming.
  145. *
  146. * Some of these are clearly Stargate 2 related (no way of plugging
  147. * in an lcd on the IM2 for example!).
  148. */
  149. static struct regulator_init_data imote2_ldo_init_data[] = {
  150. [vcc_bbio] = {
  151. .constraints = { /* board default 1.8V */
  152. .name = "vcc_bbio",
  153. .min_uV = 1800000,
  154. .max_uV = 1800000,
  155. },
  156. },
  157. [vcc_bb] = {
  158. .constraints = { /* board default 2.8V */
  159. .name = "vcc_bb",
  160. .min_uV = 2700000,
  161. .max_uV = 3000000,
  162. },
  163. },
  164. [vcc_pxa_flash] = {
  165. .constraints = {/* default is 1.8V */
  166. .name = "vcc_pxa_flash",
  167. .min_uV = 1800000,
  168. .max_uV = 1800000,
  169. },
  170. },
  171. [vcc_cc2420] = { /* also vcc_io */
  172. .constraints = {
  173. /* board default is 2.8V */
  174. .name = "vcc_cc2420",
  175. .min_uV = 2700000,
  176. .max_uV = 3300000,
  177. },
  178. },
  179. [vcc_vref] = { /* Reference for what? */
  180. .constraints = { /* default 1.8V */
  181. .name = "vcc_vref",
  182. .min_uV = 1800000,
  183. .max_uV = 1800000,
  184. },
  185. },
  186. [vcc_sram_ext] = {
  187. .constraints = { /* default 2.8V */
  188. .name = "vcc_sram_ext",
  189. .min_uV = 2800000,
  190. .max_uV = 2800000,
  191. },
  192. },
  193. [vcc_mica] = {
  194. .constraints = { /* default 2.8V */
  195. .name = "vcc_mica",
  196. .min_uV = 2800000,
  197. .max_uV = 2800000,
  198. },
  199. },
  200. [vcc_bt] = {
  201. .constraints = { /* default 2.8V */
  202. .name = "vcc_bt",
  203. .min_uV = 2800000,
  204. .max_uV = 2800000,
  205. },
  206. },
  207. [vcc_lcd] = {
  208. .constraints = { /* default 2.8V */
  209. .name = "vcc_lcd",
  210. .min_uV = 2700000,
  211. .max_uV = 3300000,
  212. },
  213. },
  214. [vcc_io] = { /* Same or higher than everything
  215. * bar vccbat and vccusb */
  216. .constraints = { /* default 2.8V */
  217. .name = "vcc_io",
  218. .min_uV = 2692000,
  219. .max_uV = 3300000,
  220. },
  221. },
  222. [vcc_sensor_1_8] = {
  223. .constraints = { /* default 1.8V */
  224. .name = "vcc_sensor_1_8",
  225. .min_uV = 1800000,
  226. .max_uV = 1800000,
  227. },
  228. },
  229. [vcc_sensor_3] = { /* curiously default 2.8V */
  230. .constraints = {
  231. .name = "vcc_sensor_3",
  232. .min_uV = 2800000,
  233. .max_uV = 3000000,
  234. },
  235. },
  236. [vcc_pxa_pll] = { /* 1.17V - 1.43V, default 1.3V*/
  237. .constraints = {
  238. .name = "vcc_pxa_pll",
  239. .min_uV = 1170000,
  240. .max_uV = 1430000,
  241. },
  242. },
  243. [vcc_pxa_usim] = {
  244. .constraints = { /* default 1.8V */
  245. .name = "vcc_pxa_usim",
  246. .min_uV = 1710000,
  247. .max_uV = 2160000,
  248. },
  249. },
  250. [vcc_pxa_mem] = {
  251. .constraints = { /* default 1.8V */
  252. .name = "vcc_pxa_mem",
  253. .min_uV = 1800000,
  254. .max_uV = 1800000,
  255. },
  256. },
  257. };
  258. static struct da903x_subdev_info imote2_da9030_subdevs[] = {
  259. {
  260. .name = "da903x-regulator",
  261. .id = DA9030_ID_LDO2,
  262. .platform_data = &imote2_ldo_init_data[vcc_bbio],
  263. }, {
  264. .name = "da903x-regulator",
  265. .id = DA9030_ID_LDO3,
  266. .platform_data = &imote2_ldo_init_data[vcc_bb],
  267. }, {
  268. .name = "da903x-regulator",
  269. .id = DA9030_ID_LDO4,
  270. .platform_data = &imote2_ldo_init_data[vcc_pxa_flash],
  271. }, {
  272. .name = "da903x-regulator",
  273. .id = DA9030_ID_LDO5,
  274. .platform_data = &imote2_ldo_init_data[vcc_cc2420],
  275. }, {
  276. .name = "da903x-regulator",
  277. .id = DA9030_ID_LDO6,
  278. .platform_data = &imote2_ldo_init_data[vcc_vref],
  279. }, {
  280. .name = "da903x-regulator",
  281. .id = DA9030_ID_LDO7,
  282. .platform_data = &imote2_ldo_init_data[vcc_sram_ext],
  283. }, {
  284. .name = "da903x-regulator",
  285. .id = DA9030_ID_LDO8,
  286. .platform_data = &imote2_ldo_init_data[vcc_mica],
  287. }, {
  288. .name = "da903x-regulator",
  289. .id = DA9030_ID_LDO9,
  290. .platform_data = &imote2_ldo_init_data[vcc_bt],
  291. }, {
  292. .name = "da903x-regulator",
  293. .id = DA9030_ID_LDO10,
  294. .platform_data = &imote2_ldo_init_data[vcc_sensor_1_8],
  295. }, {
  296. .name = "da903x-regulator",
  297. .id = DA9030_ID_LDO11,
  298. .platform_data = &imote2_ldo_init_data[vcc_sensor_3],
  299. }, {
  300. .name = "da903x-regulator",
  301. .id = DA9030_ID_LDO12,
  302. .platform_data = &imote2_ldo_init_data[vcc_lcd],
  303. }, {
  304. .name = "da903x-regulator",
  305. .id = DA9030_ID_LDO15,
  306. .platform_data = &imote2_ldo_init_data[vcc_pxa_pll],
  307. }, {
  308. .name = "da903x-regulator",
  309. .id = DA9030_ID_LDO17,
  310. .platform_data = &imote2_ldo_init_data[vcc_pxa_usim],
  311. }, {
  312. .name = "da903x-regulator",
  313. .id = DA9030_ID_LDO18,
  314. .platform_data = &imote2_ldo_init_data[vcc_io],
  315. }, {
  316. .name = "da903x-regulator",
  317. .id = DA9030_ID_LDO19,
  318. .platform_data = &imote2_ldo_init_data[vcc_pxa_mem],
  319. },
  320. };
  321. static struct da903x_platform_data imote2_da9030_pdata = {
  322. .num_subdevs = ARRAY_SIZE(imote2_da9030_subdevs),
  323. .subdevs = imote2_da9030_subdevs,
  324. };
  325. /* As the the imote2 doesn't currently have a conventional SD slot
  326. * there is no option to hotplug cards, making all this rather simple
  327. */
  328. static int imote2_mci_get_ro(struct device *dev)
  329. {
  330. return 0;
  331. }
  332. /* Rather simple case as hotplugging not possible */
  333. static struct pxamci_platform_data imote2_mci_platform_data = {
  334. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* default anyway */
  335. .get_ro = imote2_mci_get_ro,
  336. };
  337. static struct mtd_partition imote2flash_partitions[] = {
  338. {
  339. .name = "Bootloader",
  340. .size = 0x00040000,
  341. .offset = 0,
  342. .mask_flags = MTD_WRITEABLE,
  343. }, {
  344. .name = "Kernel",
  345. .size = 0x00200000,
  346. .offset = 0x00040000,
  347. .mask_flags = 0,
  348. }, {
  349. .name = "Filesystem",
  350. .size = 0x01DC0000,
  351. .offset = 0x00240000,
  352. .mask_flags = 0,
  353. },
  354. };
  355. static struct resource flash_resources = {
  356. .start = PXA_CS0_PHYS,
  357. .end = PXA_CS0_PHYS + SZ_32M - 1,
  358. .flags = IORESOURCE_MEM,
  359. };
  360. static struct flash_platform_data imote2_flash_data = {
  361. .map_name = "cfi_probe",
  362. .parts = imote2flash_partitions,
  363. .nr_parts = ARRAY_SIZE(imote2flash_partitions),
  364. .name = "PXA27xOnChipROM",
  365. .width = 2,
  366. };
  367. static struct platform_device imote2_flash_device = {
  368. .name = "pxa2xx-flash",
  369. .id = 0,
  370. .dev = {
  371. .platform_data = &imote2_flash_data,
  372. },
  373. .resource = &flash_resources,
  374. .num_resources = 1,
  375. };
  376. /* Some of the drivers here are out of kernel at the moment (parts of IIO)
  377. * and it may be a while before they are in the mainline.
  378. */
  379. static struct i2c_board_info __initdata imote2_i2c_board_info[] = {
  380. { /* UCAM sensor board */
  381. .type = "max1238",
  382. .addr = 0x35,
  383. }, { /* ITS400 Sensor board only */
  384. .type = "max1363",
  385. .addr = 0x34,
  386. /* Through a nand gate - Also beware, on V2 sensor board the
  387. * pull up resistors are missing.
  388. */
  389. .irq = IRQ_GPIO(99),
  390. }, { /* ITS400 Sensor board only */
  391. .type = "tsl2561",
  392. .addr = 0x49,
  393. /* Through a nand gate - Also beware, on V2 sensor board the
  394. * pull up resistors are missing.
  395. */
  396. .irq = IRQ_GPIO(99),
  397. }, { /* ITS400 Sensor board only */
  398. .type = "tmp175",
  399. .addr = 0x4A,
  400. .irq = IRQ_GPIO(96),
  401. },
  402. };
  403. static struct i2c_board_info __initdata imote2_pwr_i2c_board_info[] = {
  404. {
  405. .type = "da9030",
  406. .addr = 0x49,
  407. .platform_data = &imote2_da9030_pdata,
  408. .irq = gpio_to_irq(1),
  409. },
  410. };
  411. static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
  412. .num_chipselect = 1,
  413. };
  414. static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
  415. .num_chipselect = 1,
  416. };
  417. static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
  418. .num_chipselect = 1,
  419. };
  420. /* Patch posted by Eric Miao <eric.miao@marvell.com> will remove
  421. * the need for these functions.
  422. */
  423. static void spi1control(u32 command)
  424. {
  425. gpio_set_value(24, command & PXA2XX_CS_ASSERT ? 0 : 1);
  426. };
  427. static void spi3control(u32 command)
  428. {
  429. gpio_set_value(39, command & PXA2XX_CS_ASSERT ? 0 : 1);
  430. };
  431. static struct pxa2xx_spi_chip staccel_chip_info = {
  432. .tx_threshold = 8,
  433. .rx_threshold = 8,
  434. .dma_burst_size = 8,
  435. .timeout = 235,
  436. .cs_control = spi1control,
  437. };
  438. static struct pxa2xx_spi_chip cc2420_info = {
  439. .tx_threshold = 8,
  440. .rx_threshold = 8,
  441. .dma_burst_size = 8,
  442. .timeout = 235,
  443. .cs_control = spi3control,
  444. };
  445. static struct spi_board_info spi_board_info[] __initdata = {
  446. { /* Driver in IIO */
  447. .modalias = "lis3l02dq",
  448. .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
  449. .bus_num = 1,
  450. .chip_select = 0,
  451. .controller_data = &staccel_chip_info,
  452. .irq = IRQ_GPIO(96),
  453. }, { /* Driver out of kernel as it needs considerable rewriting */
  454. .modalias = "cc2420",
  455. .max_speed_hz = 6500000,
  456. .bus_num = 3,
  457. .chip_select = 0,
  458. .controller_data = &cc2420_info,
  459. },
  460. };
  461. static void im2_udc_command(int cmd)
  462. {
  463. switch (cmd) {
  464. case PXA2XX_UDC_CMD_CONNECT:
  465. UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
  466. break;
  467. case PXA2XX_UDC_CMD_DISCONNECT:
  468. UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
  469. break;
  470. }
  471. }
  472. static struct pxa2xx_udc_mach_info imote2_udc_info __initdata = {
  473. .udc_command = im2_udc_command,
  474. };
  475. static struct platform_device *imote2_devices[] = {
  476. &imote2_flash_device,
  477. &imote2_leds,
  478. };
  479. static struct i2c_pxa_platform_data i2c_pwr_pdata = {
  480. .fast_mode = 1,
  481. };
  482. static struct i2c_pxa_platform_data i2c_pdata = {
  483. .fast_mode = 1,
  484. };
  485. static void __init imote2_init(void)
  486. {
  487. pxa2xx_mfp_config(ARRAY_AND_SIZE(imote2_pin_config));
  488. /* SPI chip select directions - all other directions should
  489. * be handled by drivers.*/
  490. gpio_direction_output(37, 0);
  491. gpio_direction_output(24, 0);
  492. gpio_direction_output(39, 0);
  493. platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
  494. pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
  495. pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
  496. pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
  497. spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
  498. i2c_register_board_info(0, imote2_i2c_board_info,
  499. ARRAY_SIZE(imote2_i2c_board_info));
  500. i2c_register_board_info(1, imote2_pwr_i2c_board_info,
  501. ARRAY_SIZE(imote2_pwr_i2c_board_info));
  502. pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
  503. pxa_set_i2c_info(&i2c_pdata);
  504. pxa_set_mci_info(&imote2_mci_platform_data);
  505. pxa_set_udc_info(&imote2_udc_info);
  506. }
  507. MACHINE_START(INTELMOTE2, "IMOTE 2")
  508. .phys_io = 0x40000000,
  509. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  510. .map_io = pxa_map_io,
  511. .init_irq = pxa27x_init_irq,
  512. .timer = &pxa_timer,
  513. .init_machine = imote2_init,
  514. .boot_params = 0xA0000100,
  515. MACHINE_END