imote2.c 13 KB

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