hiddenDangerAnalysis.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * TI DA850/OMAP-L138 EVM board
  3. *
  4. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Derived from: arch/arm/mach-davinci/board-da830-evm.c
  7. * Original Copyrights follow:
  8. *
  9. * 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. #include <linux/console.h>
  15. #include <linux/delay.h>
  16. #include <linux/gpio.h>
  17. #include <linux/gpio_keys.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/i2c.h>
  21. #include <linux/i2c/at24.h>
  22. #include <linux/i2c/pca953x.h>
  23. #include <linux/input.h>
  24. #include <linux/input/tps6507x-ts.h>
  25. #include <linux/mfd/tps6507x.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/mtd/partitions.h>
  29. #include <linux/mtd/physmap.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/platform_data/mtd-davinci.h>
  32. #include <linux/platform_data/mtd-davinci-aemif.h>
  33. #include <linux/platform_data/spi-davinci.h>
  34. #include <linux/platform_data/uio_pruss.h>
  35. #include <linux/regulator/machine.h>
  36. #include <linux/regulator/tps6507x.h>
  37. #include <linux/spi/spi.h>
  38. #include <linux/spi/flash.h>
  39. #include <linux/wl12xx.h>
  40. #include <mach/cp_intc.h>
  41. #include <mach/da8xx.h>
  42. #include <mach/mux.h>
  43. #include <mach/sram.h>
  44. #include <asm/mach-types.h>
  45. #include <asm/mach/arch.h>
  46. #include <asm/system_info.h>
  47. #include <media/tvp514x.h>
  48. #include <media/adv7343.h>
  49. #define DA850_EVM_PHY_ID "davinci_mdio-0:00"
  50. #define DA850_LCD_PWR_PIN GPIO_TO_PIN(2, 8)
  51. #define DA850_LCD_BL_PIN GPIO_TO_PIN(2, 15)
  52. #define DA850_MMCSD_CD_PIN GPIO_TO_PIN(4, 0)
  53. #define DA850_MMCSD_WP_PIN GPIO_TO_PIN(4, 1)
  54. #define DA850_WLAN_EN GPIO_TO_PIN(6, 9)
  55. #define DA850_WLAN_IRQ GPIO_TO_PIN(6, 10)
  56. #define DA850_MII_MDIO_CLKEN_PIN GPIO_TO_PIN(2, 6)
  57. static struct mtd_partition da850evm_spiflash_part[] = {
  58. [0] = {
  59. .name = "UBL",
  60. .offset = 0,
  61. .size = SZ_64K,
  62. .mask_flags = MTD_WRITEABLE,
  63. },
  64. [1] = {
  65. .name = "U-Boot",
  66. .offset = MTDPART_OFS_APPEND,
  67. .size = SZ_512K,
  68. .mask_flags = MTD_WRITEABLE,
  69. },
  70. [2] = {
  71. .name = "U-Boot-Env",
  72. .offset = MTDPART_OFS_APPEND,
  73. .size = SZ_64K,
  74. .mask_flags = MTD_WRITEABLE,
  75. },
  76. [3] = {
  77. .name = "Kernel",
  78. .offset = MTDPART_OFS_APPEND,
  79. .size = SZ_2M + SZ_512K,
  80. .mask_flags = 0,
  81. },
  82. [4] = {
  83. .name = "Filesystem",
  84. .offset = MTDPART_OFS_APPEND,
  85. .size = SZ_4M,
  86. .mask_flags = 0,
  87. },
  88. [5] = {
  89. .name = "MAC-Address",
  90. .offset = SZ_8M - SZ_64K,
  91. .size = SZ_64K,
  92. .mask_flags = MTD_WRITEABLE,
  93. },
  94. };
  95. static struct flash_platform_data da850evm_spiflash_data = {
  96. .name = "m25p80",
  97. .parts = da850evm_spiflash_part,
  98. .nr_parts = ARRAY_SIZE(da850evm_spiflash_part),
  99. .type = "m25p64",
  100. };
  101. static struct davinci_spi_config da850evm_spiflash_cfg = {
  102. .io_type = SPI_IO_TYPE_DMA,
  103. .c2tdelay = 8,
  104. .t2cdelay = 8,
  105. };
  106. static struct spi_board_info da850evm_spi_info[] = {
  107. {
  108. .modalias = "m25p80",
  109. .platform_data = &da850evm_spiflash_data,
  110. .controller_data = &da850evm_spiflash_cfg,
  111. .mode = SPI_MODE_0,
  112. .max_speed_hz = 30000000,
  113. .bus_num = 1,
  114. .chip_select = 0,
  115. },
  116. };
  117. #ifdef CONFIG_MTD
  118. static void da850_evm_m25p80_notify_add(struct mtd_info *mtd)
  119. {
  120. char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
  121. size_t retlen;
  122. if (!strcmp(mtd->name, "MAC-Address")) {
  123. mtd_read(mtd, 0, ETH_ALEN, &retlen, mac_addr);
  124. if (retlen == ETH_ALEN)
  125. pr_info("Read MAC addr from SPI Flash: %pM\n",
  126. mac_addr);
  127. }
  128. }
  129. static struct mtd_notifier da850evm_spi_notifier = {
  130. .add = da850_evm_m25p80_notify_add,
  131. };
  132. static void da850_evm_setup_mac_addr(void)
  133. {
  134. register_mtd_user(&da850evm_spi_notifier);
  135. }
  136. #else
  137. static void da850_evm_setup_mac_addr(void) { }
  138. #endif
  139. static struct mtd_partition da850_evm_norflash_partition[] = {
  140. {
  141. .name = "bootloaders + env",
  142. .offset = 0,
  143. .size = SZ_512K,
  144. .mask_flags = MTD_WRITEABLE,
  145. },
  146. {
  147. .name = "kernel",
  148. .offset = MTDPART_OFS_APPEND,
  149. .size = SZ_2M,
  150. .mask_flags = 0,
  151. },
  152. {
  153. .name = "filesystem",
  154. .offset = MTDPART_OFS_APPEND,
  155. .size = MTDPART_SIZ_FULL,
  156. .mask_flags = 0,
  157. },
  158. };
  159. static struct physmap_flash_data da850_evm_norflash_data = {
  160. .width = 2,
  161. .parts = da850_evm_norflash_partition,
  162. .nr_parts = ARRAY_SIZE(da850_evm_norflash_partition),
  163. };
  164. static struct resource da850_evm_norflash_resource[] = {
  165. {
  166. .start = DA8XX_AEMIF_CS2_BASE,
  167. .end = DA8XX_AEMIF_CS2_BASE + SZ_32M - 1,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. };
  171. static struct platform_device da850_evm_norflash_device = {
  172. .name = "physmap-flash",
  173. .id = 0,
  174. .dev = {
  175. .platform_data = &da850_evm_norflash_data,
  176. },
  177. .num_resources = 1,
  178. .resource = da850_evm_norflash_resource,
  179. };
  180. static struct davinci_pm_config da850_pm_pdata = {
  181. .sleepcount = 128,
  182. };
  183. static struct platform_device da850_pm_device = {
  184. .name = "pm-davinci",
  185. .dev = {
  186. .platform_data = &da850_pm_pdata,
  187. },
  188. .id = -1,
  189. };
  190. /* DA850/OMAP-L138 EVM includes a 512 MByte large-page NAND flash
  191. * (128K blocks). It may be used instead of the (default) SPI flash
  192. * to boot, using TI's tools to install the secondary boot loader
  193. * (UBL) and U-Boot.
  194. */
  195. static struct mtd_partition da850_evm_nandflash_partition[] = {
  196. {
  197. .name = "u-boot env",
  198. .offset = 0,
  199. .size = SZ_128K,
  200. .mask_flags = MTD_WRITEABLE,
  201. },
  202. {
  203. .name = "UBL",
  204. .offset = MTDPART_OFS_APPEND,
  205. .size = SZ_128K,
  206. .mask_flags = MTD_WRITEABLE,
  207. },
  208. {
  209. .name = "u-boot",
  210. .offset = MTDPART_OFS_APPEND,
  211. .size = 4 * SZ_128K,
  212. .mask_flags = MTD_WRITEABLE,
  213. },
  214. {
  215. .name = "kernel",
  216. .offset = 0x200000,
  217. .size = SZ_2M,
  218. .mask_flags = 0,
  219. },
  220. {
  221. .name = "filesystem",
  222. .offset = MTDPART_OFS_APPEND,
  223. .size = MTDPART_SIZ_FULL,
  224. .mask_flags = 0,
  225. },
  226. };
  227. static struct davinci_aemif_timing da850_evm_nandflash_timing = {
  228. .wsetup = 24,
  229. .wstrobe = 21,
  230. .whold = 14,
  231. .rsetup = 19,
  232. .rstrobe = 50,
  233. .rhold = 0,
  234. .ta = 20,
  235. };
  236. static struct davinci_nand_pdata da850_evm_nandflash_data = {
  237. .parts = da850_evm_nandflash_partition,
  238. .nr_parts = ARRAY_SIZE(da850_evm_nandflash_partition),
  239. .ecc_mode = NAND_ECC_HW,
  240. .ecc_bits = 4,
  241. .bbt_options = NAND_BBT_USE_FLASH,
  242. .timing = &da850_evm_nandflash_timing,
  243. };
  244. static struct resource da850_evm_nandflash_resource[] = {
  245. {
  246. .start = DA8XX_AEMIF_CS3_BASE,
  247. .end = DA8XX_AEMIF_CS3_BASE + SZ_512K + 2 * SZ_1K - 1,
  248. .flags = IORESOURCE_MEM,
  249. },
  250. {
  251. .start = DA8XX_AEMIF_CTL_BASE,
  252. .end = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,
  253. .flags = IORESOURCE_MEM,
  254. },
  255. };
  256. static struct platform_device da850_evm_nandflash_device = {
  257. .name = "davinci_nand",
  258. .id = 1,
  259. .dev = {
  260. .platform_data = &da850_evm_nandflash_data,
  261. },
  262. .num_resources = ARRAY_SIZE(da850_evm_nandflash_resource),
  263. .resource = da850_evm_nandflash_resource,
  264. };
  265. static struct platform_device *da850_evm_devices[] = {
  266. &da850_evm_nandflash_device,
  267. &da850_evm_norflash_device,
  268. };
  269. #define DA8XX_AEMIF_CE2CFG_OFFSET 0x10
  270. #define DA8XX_AEMIF_ASIZE_16BIT 0x1
  271. static void __init da850_evm_init_nor(void)
  272. {
  273. void __iomem *aemif_addr;
  274. aemif_addr = ioremap(DA8XX_AEMIF_CTL_BASE, SZ_32K);
  275. /* Configure data bus width of CS2 to 16 bit */
  276. writel(readl(aemif_addr + DA8XX_AEMIF_CE2CFG_OFFSET) |
  277. DA8XX_AEMIF_ASIZE_16BIT,
  278. aemif_addr + DA8XX_AEMIF_CE2CFG_OFFSET);
  279. iounmap(aemif_addr);
  280. }
  281. static const short da850_evm_nand_pins[] = {
  282. DA850_EMA_D_0, DA850_EMA_D_1, DA850_EMA_D_2, DA850_EMA_D_3,
  283. DA850_EMA_D_4, DA850_EMA_D_5, DA850_EMA_D_6, DA850_EMA_D_7,
  284. DA850_EMA_A_1, DA850_EMA_A_2, DA850_NEMA_CS_3, DA850_NEMA_CS_4,
  285. DA850_NEMA_WE, DA850_NEMA_OE,
  286. -1
  287. };
  288. static const short da850_evm_nor_pins[] = {
  289. DA850_EMA_BA_1, DA850_EMA_CLK, DA850_EMA_WAIT_1, DA850_NEMA_CS_2,
  290. DA850_NEMA_WE, DA850_NEMA_OE, DA850_EMA_D_0, DA850_EMA_D_1,
  291. DA850_EMA_D_2, DA850_EMA_D_3, DA850_EMA_D_4, DA850_EMA_D_5,
  292. DA850_EMA_D_6, DA850_EMA_D_7, DA850_EMA_D_8, DA850_EMA_D_9,
  293. DA850_EMA_D_10, DA850_EMA_D_11, DA850_EMA_D_12, DA850_EMA_D_13,
  294. DA850_EMA_D_14, DA850_EMA_D_15, DA850_EMA_A_0, DA850_EMA_A_1,
  295. DA850_EMA_A_2, DA850_EMA_A_3, DA850_EMA_A_4, DA850_EMA_A_5,
  296. DA850_EMA_A_6, DA850_EMA_A_7, DA850_EMA_A_8, DA850_EMA_A_9,
  297. DA850_EMA_A_10, DA850_EMA_A_11, DA850_EMA_A_12, DA850_EMA_A_13,
  298. DA850_EMA_A_14, DA850_EMA_A_15, DA850_EMA_A_16, DA850_EMA_A_17,
  299. DA850_EMA_A_18, DA850_EMA_A_19, DA850_EMA_A_20, DA850_EMA_A_21,
  300. DA850_EMA_A_22, DA850_EMA_A_23,
  301. -1
  302. };
  303. #if defined(CONFIG_MMC_DAVINCI) || \
  304. defined(CONFIG_MMC_DAVINCI_MODULE)
  305. #define HAS_MMC 1
  306. #else
  307. #define HAS_MMC 0
  308. #endif
  309. static inline void da850_evm_setup_nor_nand(void)
  310. {
  311. int ret = 0;
  312. if (!HAS_MMC) {
  313. ret = davinci_cfg_reg_list(da850_evm_nand_pins);
  314. if (ret)
  315. pr_warning("da850_evm_init: nand mux setup failed: "
  316. "%d\n", ret);
  317. ret = davinci_cfg_reg_list(da850_evm_nor_pins);
  318. if (ret)
  319. pr_warning("da850_evm_init: nor mux setup failed: %d\n",
  320. ret);
  321. da850_evm_init_nor();
  322. platform_add_devices(da850_evm_devices,
  323. ARRAY_SIZE(da850_evm_devices));
  324. }
  325. }
  326. #ifdef CONFIG_DA850_UI_RMII
  327. static inline void da850_evm_setup_emac_rmii(int rmii_sel)
  328. {
  329. struct davinci_soc_info *soc_info = &davinci_soc_info;
  330. soc_info->emac_pdata->rmii_en = 1;
  331. gpio_set_value_cansleep(rmii_sel, 0);
  332. }
  333. #else
  334. static inline void da850_evm_setup_emac_rmii(int rmii_sel) { }
  335. #endif
  336. #define DA850_KEYS_DEBOUNCE_MS 10
  337. /*
  338. * At 200ms polling interval it is possible to miss an
  339. * event by tapping very lightly on the push button but most
  340. * pushes do result in an event; longer intervals require the
  341. * user to hold the button whereas shorter intervals require
  342. * more CPU time for polling.
  343. */
  344. #define DA850_GPIO_KEYS_POLL_MS 200
  345. enum da850_evm_ui_exp_pins {
  346. DA850_EVM_UI_EXP_SEL_C = 5,
  347. DA850_EVM_UI_EXP_SEL_B,
  348. DA850_EVM_UI_EXP_SEL_A,
  349. DA850_EVM_UI_EXP_PB8,
  350. DA850_EVM_UI_EXP_PB7,
  351. DA850_EVM_UI_EXP_PB6,
  352. DA850_EVM_UI_EXP_PB5,
  353. DA850_EVM_UI_EXP_PB4,
  354. DA850_EVM_UI_EXP_PB3,
  355. DA850_EVM_UI_EXP_PB2,
  356. DA850_EVM_UI_EXP_PB1,
  357. };
  358. static const char const *da850_evm_ui_exp[] = {
  359. [DA850_EVM_UI_EXP_SEL_C] = "sel_c",
  360. [DA850_EVM_UI_EXP_SEL_B] = "sel_b",
  361. [DA850_EVM_UI_EXP_SEL_A] = "sel_a",
  362. [DA850_EVM_UI_EXP_PB8] = "pb8",
  363. [DA850_EVM_UI_EXP_PB7] = "pb7",
  364. [DA850_EVM_UI_EXP_PB6] = "pb6",
  365. [DA850_EVM_UI_EXP_PB5] = "pb5",
  366. [DA850_EVM_UI_EXP_PB4] = "pb4",
  367. [DA850_EVM_UI_EXP_PB3] = "pb3",
  368. [DA850_EVM_UI_EXP_PB2] = "pb2",
  369. [DA850_EVM_UI_EXP_PB1] = "pb1",
  370. };
  371. #define DA850_N_UI_PB 8
  372. static struct gpio_keys_button da850_evm_ui_keys[] = {
  373. [0 ... DA850_N_UI_PB - 1] = {
  374. .type = EV_KEY,
  375. .active_low = 1,
  376. .wakeup = 0,
  377. .debounce_interval = DA850_KEYS_DEBOUNCE_MS,
  378. .code = -1, /* assigned at runtime */
  379. .gpio = -1, /* assigned at runtime */
  380. .desc = NULL, /* assigned at runtime */
  381. },
  382. };
  383. static struct gpio_keys_platform_data da850_evm_ui_keys_pdata = {
  384. .buttons = da850_evm_ui_keys,
  385. .nbuttons = ARRAY_SIZE(da850_evm_ui_keys),
  386. .poll_interval = DA850_GPIO_KEYS_POLL_MS,
  387. };
  388. static struct platform_device da850_evm_ui_keys_device = {
  389. .name = "gpio-keys-polled",
  390. .id = 0,
  391. .dev = {
  392. .platform_data = &da850_evm_ui_keys_pdata
  393. },
  394. };
  395. static void da850_evm_ui_keys_init(unsigned gpio)
  396. {
  397. int i;
  398. struct gpio_keys_button *button;
  399. for (i = 0; i < DA850_N_UI_PB; i++) {
  400. button = &da850_evm_ui_keys[i];
  401. button->code = KEY_F8 - i;
  402. button->desc = (char *)
  403. da850_evm_ui_exp[DA850_EVM_UI_EXP_PB8 + i];
  404. button->gpio = gpio + DA850_EVM_UI_EXP_PB8 + i;
  405. }
  406. }
  407. #ifdef CONFIG_DA850_UI_SD_VIDEO_PORT
  408. static inline void da850_evm_setup_video_port(int video_sel)
  409. {
  410. gpio_set_value_cansleep(video_sel, 0);
  411. }
  412. #else
  413. static inline void da850_evm_setup_video_port(int video_sel) { }
  414. #endif
  415. static int da850_evm_ui_expander_setup(struct i2c_client *client, unsigned gpio,
  416. unsigned ngpio, void *c)
  417. {
  418. int sel_a, sel_b, sel_c, ret;
  419. sel_a = gpio + DA850_EVM_UI_EXP_SEL_A;
  420. sel_b = gpio + DA850_EVM_UI_EXP_SEL_B;
  421. sel_c = gpio + DA850_EVM_UI_EXP_SEL_C;
  422. ret = gpio_request(sel_a, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_A]);
  423. if (ret) {
  424. pr_warning("Cannot open UI expander pin %d\n", sel_a);
  425. goto exp_setup_sela_fail;
  426. }
  427. ret = gpio_request(sel_b, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_B]);
  428. if (ret) {
  429. pr_warning("Cannot open UI expander pin %d\n", sel_b);
  430. goto exp_setup_selb_fail;
  431. }
  432. ret = gpio_request(sel_c, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_C]);
  433. if (ret) {
  434. pr_warning("Cannot open UI expander pin %d\n", sel_c);
  435. goto exp_setup_selc_fail;
  436. }
  437. /* deselect all functionalities */
  438. gpio_direction_output(sel_a, 1);
  439. gpio_direction_output(sel_b, 1);
  440. gpio_direction_output(sel_c, 1);
  441. da850_evm_ui_keys_init(gpio);
  442. ret = platform_device_register(&da850_evm_ui_keys_device);
  443. if (ret) {
  444. pr_warning("Could not register UI GPIO expander push-buttons");
  445. goto exp_setup_keys_fail;
  446. }
  447. pr_info("DA850/OMAP-L138 EVM UI card detected\n");
  448. da850_evm_setup_nor_nand();
  449. da850_evm_setup_emac_rmii(sel_a);
  450. da850_evm_setup_video_port(sel_c);
  451. return 0;
  452. exp_setup_keys_fail:
  453. gpio_free(sel_c);
  454. exp_setup_selc_fail:
  455. gpio_free(sel_b);
  456. exp_setup_selb_fail:
  457. gpio_free(sel_a);
  458. exp_setup_sela_fail:
  459. return ret;