devices.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * linux/arch/arm/mach-omap2/devices.c
  3. *
  4. * OMAP2 platform device setup/initialization
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/clk.h>
  17. #include <mach/hardware.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/mach/map.h>
  20. #include <mach/control.h>
  21. #include <mach/tc.h>
  22. #include <mach/board.h>
  23. #include <mach/mux.h>
  24. #include <mach/gpio.h>
  25. #include <mach/eac.h>
  26. #include <mach/mmc.h>
  27. #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
  28. static struct resource cam_resources[] = {
  29. {
  30. .start = OMAP24XX_CAMERA_BASE,
  31. .end = OMAP24XX_CAMERA_BASE + 0xfff,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. {
  35. .start = INT_24XX_CAM_IRQ,
  36. .flags = IORESOURCE_IRQ,
  37. }
  38. };
  39. static struct platform_device omap_cam_device = {
  40. .name = "omap24xxcam",
  41. .id = -1,
  42. .num_resources = ARRAY_SIZE(cam_resources),
  43. .resource = cam_resources,
  44. };
  45. static inline void omap_init_camera(void)
  46. {
  47. platform_device_register(&omap_cam_device);
  48. }
  49. #elif defined(CONFIG_VIDEO_OMAP3) || defined(CONFIG_VIDEO_OMAP3_MODULE)
  50. static struct resource omap3isp_resources[] = {
  51. {
  52. .start = OMAP3430_ISP_BASE,
  53. .end = OMAP3430_ISP_END,
  54. .flags = IORESOURCE_MEM,
  55. },
  56. {
  57. .start = OMAP3430_ISP_CBUFF_BASE,
  58. .end = OMAP3430_ISP_CBUFF_END,
  59. .flags = IORESOURCE_MEM,
  60. },
  61. {
  62. .start = OMAP3430_ISP_CCP2_BASE,
  63. .end = OMAP3430_ISP_CCP2_END,
  64. .flags = IORESOURCE_MEM,
  65. },
  66. {
  67. .start = OMAP3430_ISP_CCDC_BASE,
  68. .end = OMAP3430_ISP_CCDC_END,
  69. .flags = IORESOURCE_MEM,
  70. },
  71. {
  72. .start = OMAP3430_ISP_HIST_BASE,
  73. .end = OMAP3430_ISP_HIST_END,
  74. .flags = IORESOURCE_MEM,
  75. },
  76. {
  77. .start = OMAP3430_ISP_H3A_BASE,
  78. .end = OMAP3430_ISP_H3A_END,
  79. .flags = IORESOURCE_MEM,
  80. },
  81. {
  82. .start = OMAP3430_ISP_PREV_BASE,
  83. .end = OMAP3430_ISP_PREV_END,
  84. .flags = IORESOURCE_MEM,
  85. },
  86. {
  87. .start = OMAP3430_ISP_RESZ_BASE,
  88. .end = OMAP3430_ISP_RESZ_END,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. {
  92. .start = OMAP3430_ISP_SBL_BASE,
  93. .end = OMAP3430_ISP_SBL_END,
  94. .flags = IORESOURCE_MEM,
  95. },
  96. {
  97. .start = OMAP3430_ISP_CSI2A_BASE,
  98. .end = OMAP3430_ISP_CSI2A_END,
  99. .flags = IORESOURCE_MEM,
  100. },
  101. {
  102. .start = OMAP3430_ISP_CSI2PHY_BASE,
  103. .end = OMAP3430_ISP_CSI2PHY_END,
  104. .flags = IORESOURCE_MEM,
  105. },
  106. {
  107. .start = INT_34XX_CAM_IRQ,
  108. .flags = IORESOURCE_IRQ,
  109. }
  110. };
  111. static struct platform_device omap3isp_device = {
  112. .name = "omap3isp",
  113. .id = -1,
  114. .num_resources = ARRAY_SIZE(omap3isp_resources),
  115. .resource = omap3isp_resources,
  116. };
  117. static inline void omap_init_camera(void)
  118. {
  119. platform_device_register(&omap3isp_device);
  120. }
  121. #else
  122. static inline void omap_init_camera(void)
  123. {
  124. }
  125. #endif
  126. #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
  127. #define MBOX_REG_SIZE 0x120
  128. static struct resource omap2_mbox_resources[] = {
  129. {
  130. .start = OMAP24XX_MAILBOX_BASE,
  131. .end = OMAP24XX_MAILBOX_BASE + MBOX_REG_SIZE - 1,
  132. .flags = IORESOURCE_MEM,
  133. },
  134. {
  135. .start = INT_24XX_MAIL_U0_MPU,
  136. .flags = IORESOURCE_IRQ,
  137. },
  138. {
  139. .start = INT_24XX_MAIL_U3_MPU,
  140. .flags = IORESOURCE_IRQ,
  141. },
  142. };
  143. static struct resource omap3_mbox_resources[] = {
  144. {
  145. .start = OMAP34XX_MAILBOX_BASE,
  146. .end = OMAP34XX_MAILBOX_BASE + MBOX_REG_SIZE - 1,
  147. .flags = IORESOURCE_MEM,
  148. },
  149. {
  150. .start = INT_24XX_MAIL_U0_MPU,
  151. .flags = IORESOURCE_IRQ,
  152. },
  153. };
  154. static struct platform_device mbox_device = {
  155. .name = "omap2-mailbox",
  156. .id = -1,
  157. };
  158. static inline void omap_init_mbox(void)
  159. {
  160. if (cpu_is_omap2420()) {
  161. mbox_device.num_resources = ARRAY_SIZE(omap2_mbox_resources);
  162. mbox_device.resource = omap2_mbox_resources;
  163. } else if (cpu_is_omap3430()) {
  164. mbox_device.num_resources = ARRAY_SIZE(omap3_mbox_resources);
  165. mbox_device.resource = omap3_mbox_resources;
  166. } else {
  167. pr_err("%s: platform not supported\n", __func__);
  168. return;
  169. }
  170. platform_device_register(&mbox_device);
  171. }
  172. #else
  173. static inline void omap_init_mbox(void) { }
  174. #endif /* CONFIG_OMAP_MBOX_FWK */
  175. #if defined(CONFIG_OMAP_STI)
  176. #if defined(CONFIG_ARCH_OMAP2)
  177. #define OMAP2_STI_BASE 0x48068000
  178. #define OMAP2_STI_CHANNEL_BASE 0x54000000
  179. #define OMAP2_STI_IRQ 4
  180. static struct resource sti_resources[] = {
  181. {
  182. .start = OMAP2_STI_BASE,
  183. .end = OMAP2_STI_BASE + 0x7ff,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. {
  187. .start = OMAP2_STI_CHANNEL_BASE,
  188. .end = OMAP2_STI_CHANNEL_BASE + SZ_64K - 1,
  189. .flags = IORESOURCE_MEM,
  190. },
  191. {
  192. .start = OMAP2_STI_IRQ,
  193. .flags = IORESOURCE_IRQ,
  194. }
  195. };
  196. #elif defined(CONFIG_ARCH_OMAP3)
  197. #define OMAP3_SDTI_BASE 0x54500000
  198. #define OMAP3_SDTI_CHANNEL_BASE 0x54600000
  199. static struct resource sti_resources[] = {
  200. {
  201. .start = OMAP3_SDTI_BASE,
  202. .end = OMAP3_SDTI_BASE + 0xFFF,
  203. .flags = IORESOURCE_MEM,
  204. },
  205. {
  206. .start = OMAP3_SDTI_CHANNEL_BASE,
  207. .end = OMAP3_SDTI_CHANNEL_BASE + SZ_1M - 1,
  208. .flags = IORESOURCE_MEM,
  209. }
  210. };
  211. #endif
  212. static struct platform_device sti_device = {
  213. .name = "sti",
  214. .id = -1,
  215. .num_resources = ARRAY_SIZE(sti_resources),
  216. .resource = sti_resources,
  217. };
  218. static inline void omap_init_sti(void)
  219. {
  220. platform_device_register(&sti_device);
  221. }
  222. #else
  223. static inline void omap_init_sti(void) {}
  224. #endif
  225. #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
  226. #include <mach/mcspi.h>
  227. #define OMAP2_MCSPI1_BASE 0x48098000
  228. #define OMAP2_MCSPI2_BASE 0x4809a000
  229. #define OMAP2_MCSPI3_BASE 0x480b8000
  230. #define OMAP2_MCSPI4_BASE 0x480ba000
  231. static struct omap2_mcspi_platform_config omap2_mcspi1_config = {
  232. .num_cs = 4,
  233. };
  234. static struct resource omap2_mcspi1_resources[] = {
  235. {
  236. .start = OMAP2_MCSPI1_BASE,
  237. .end = OMAP2_MCSPI1_BASE + 0xff,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. };
  241. static struct platform_device omap2_mcspi1 = {
  242. .name = "omap2_mcspi",
  243. .id = 1,
  244. .num_resources = ARRAY_SIZE(omap2_mcspi1_resources),
  245. .resource = omap2_mcspi1_resources,
  246. .dev = {
  247. .platform_data = &omap2_mcspi1_config,
  248. },
  249. };
  250. static struct omap2_mcspi_platform_config omap2_mcspi2_config = {
  251. .num_cs = 2,
  252. };
  253. static struct resource omap2_mcspi2_resources[] = {
  254. {
  255. .start = OMAP2_MCSPI2_BASE,
  256. .end = OMAP2_MCSPI2_BASE + 0xff,
  257. .flags = IORESOURCE_MEM,
  258. },
  259. };
  260. static struct platform_device omap2_mcspi2 = {
  261. .name = "omap2_mcspi",
  262. .id = 2,
  263. .num_resources = ARRAY_SIZE(omap2_mcspi2_resources),
  264. .resource = omap2_mcspi2_resources,
  265. .dev = {
  266. .platform_data = &omap2_mcspi2_config,
  267. },
  268. };
  269. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
  270. static struct omap2_mcspi_platform_config omap2_mcspi3_config = {
  271. .num_cs = 2,
  272. };
  273. static struct resource omap2_mcspi3_resources[] = {
  274. {
  275. .start = OMAP2_MCSPI3_BASE,
  276. .end = OMAP2_MCSPI3_BASE + 0xff,
  277. .flags = IORESOURCE_MEM,
  278. },
  279. };
  280. static struct platform_device omap2_mcspi3 = {
  281. .name = "omap2_mcspi",
  282. .id = 3,
  283. .num_resources = ARRAY_SIZE(omap2_mcspi3_resources),
  284. .resource = omap2_mcspi3_resources,
  285. .dev = {
  286. .platform_data = &omap2_mcspi3_config,
  287. },
  288. };
  289. #endif
  290. #ifdef CONFIG_ARCH_OMAP3
  291. static struct omap2_mcspi_platform_config omap2_mcspi4_config = {
  292. .num_cs = 1,
  293. };
  294. static struct resource omap2_mcspi4_resources[] = {
  295. {
  296. .start = OMAP2_MCSPI4_BASE,
  297. .end = OMAP2_MCSPI4_BASE + 0xff,
  298. .flags = IORESOURCE_MEM,
  299. },
  300. };
  301. static struct platform_device omap2_mcspi4 = {
  302. .name = "omap2_mcspi",
  303. .id = 4,
  304. .num_resources = ARRAY_SIZE(omap2_mcspi4_resources),
  305. .resource = omap2_mcspi4_resources,
  306. .dev = {
  307. .platform_data = &omap2_mcspi4_config,
  308. },
  309. };
  310. #endif
  311. static void omap_init_mcspi(void)
  312. {
  313. platform_device_register(&omap2_mcspi1);
  314. platform_device_register(&omap2_mcspi2);
  315. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
  316. platform_device_register(&omap2_mcspi3);
  317. #endif
  318. #ifdef CONFIG_ARCH_OMAP3
  319. platform_device_register(&omap2_mcspi4);
  320. #endif
  321. }
  322. #else
  323. static inline void omap_init_mcspi(void) {}
  324. #endif
  325. #ifdef CONFIG_SND_OMAP24XX_EAC
  326. #define OMAP2_EAC_BASE 0x48090000
  327. static struct resource omap2_eac_resources[] = {
  328. {
  329. .start = OMAP2_EAC_BASE,
  330. .end = OMAP2_EAC_BASE + 0x109,
  331. .flags = IORESOURCE_MEM,
  332. },
  333. };
  334. static struct platform_device omap2_eac_device = {
  335. .name = "omap24xx-eac",
  336. .id = -1,
  337. .num_resources = ARRAY_SIZE(omap2_eac_resources),
  338. .resource = omap2_eac_resources,
  339. .dev = {
  340. .platform_data = NULL,
  341. },
  342. };
  343. void omap_init_eac(struct eac_platform_data *pdata)
  344. {
  345. omap2_eac_device.dev.platform_data = pdata;
  346. platform_device_register(&omap2_eac_device);
  347. }
  348. #else
  349. void omap_init_eac(struct eac_platform_data *pdata) {}
  350. #endif
  351. #ifdef CONFIG_OMAP_SHA1_MD5
  352. static struct resource sha1_md5_resources[] = {
  353. {
  354. .start = OMAP24XX_SEC_SHA1MD5_BASE,
  355. .end = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
  356. .flags = IORESOURCE_MEM,
  357. },
  358. {
  359. .start = INT_24XX_SHA1MD5,
  360. .flags = IORESOURCE_IRQ,
  361. }
  362. };
  363. static struct platform_device sha1_md5_device = {
  364. .name = "OMAP SHA1/MD5",
  365. .id = -1,
  366. .num_resources = ARRAY_SIZE(sha1_md5_resources),
  367. .resource = sha1_md5_resources,
  368. };
  369. static void omap_init_sha1_md5(void)
  370. {
  371. platform_device_register(&sha1_md5_device);
  372. }
  373. #else
  374. static inline void omap_init_sha1_md5(void) { }
  375. #endif
  376. /*-------------------------------------------------------------------------*/
  377. #ifdef CONFIG_ARCH_OMAP3
  378. #define MMCHS_SYSCONFIG 0x0010
  379. #define MMCHS_SYSCONFIG_SWRESET (1 << 1)
  380. #define MMCHS_SYSSTATUS 0x0014
  381. #define MMCHS_SYSSTATUS_RESETDONE (1 << 0)
  382. static struct platform_device dummy_pdev = {
  383. .dev = {
  384. .bus = &platform_bus_type,
  385. },
  386. };
  387. /**
  388. * omap_hsmmc_reset() - Full reset of each HS-MMC controller
  389. *
  390. * Ensure that each MMC controller is fully reset. Controllers
  391. * left in an unknown state (by bootloader) may prevent retention
  392. * or OFF-mode. This is especially important in cases where the
  393. * MMC driver is not enabled, _or_ built as a module.
  394. *
  395. * In order for reset to work, interface, functional and debounce
  396. * clocks must be enabled. The debounce clock comes from func_32k_clk
  397. * and is not under SW control, so we only enable i- and f-clocks.
  398. **/
  399. static void __init omap_hsmmc_reset(void)
  400. {
  401. u32 i, nr_controllers = cpu_is_omap34xx() ? OMAP34XX_NR_MMC :
  402. OMAP24XX_NR_MMC;
  403. for (i = 0; i < nr_controllers; i++) {
  404. u32 v, base = 0;
  405. struct clk *iclk, *fclk;
  406. struct device *dev = &dummy_pdev.dev;
  407. switch (i) {
  408. case 0:
  409. base = OMAP2_MMC1_BASE;
  410. break;
  411. case 1:
  412. base = OMAP2_MMC2_BASE;
  413. break;
  414. case 2:
  415. base = OMAP3_MMC3_BASE;
  416. break;
  417. }
  418. dummy_pdev.id = i;
  419. dev_set_name(&dummy_pdev.dev, "mmci-omap-hs.%d", i);
  420. iclk = clk_get(dev, "ick");
  421. if (iclk && clk_enable(iclk))
  422. iclk = NULL;
  423. fclk = clk_get(dev, "fck");
  424. if (fclk && clk_enable(fclk))
  425. fclk = NULL;
  426. if (!iclk || !fclk) {
  427. printk(KERN_WARNING
  428. "%s: Unable to enable clocks for MMC%d, "
  429. "cannot reset.\n", __func__, i);
  430. break;
  431. }
  432. omap_writel(MMCHS_SYSCONFIG_SWRESET, base + MMCHS_SYSCONFIG);
  433. v = omap_readl(base + MMCHS_SYSSTATUS);
  434. while (!(omap_readl(base + MMCHS_SYSSTATUS) &
  435. MMCHS_SYSSTATUS_RESETDONE))
  436. cpu_relax();
  437. if (fclk) {
  438. clk_disable(fclk);
  439. clk_put(fclk);
  440. }
  441. if (iclk) {
  442. clk_disable(iclk);
  443. clk_put(iclk);
  444. }
  445. }
  446. }
  447. #else
  448. static inline void omap_hsmmc_reset(void) {}
  449. #endif
  450. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
  451. defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  452. static inline void omap2_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
  453. int controller_nr)
  454. {
  455. if (cpu_is_omap2420() && controller_nr == 0) {
  456. omap_cfg_reg(H18_24XX_MMC_CMD);
  457. omap_cfg_reg(H15_24XX_MMC_CLKI);
  458. omap_cfg_reg(G19_24XX_MMC_CLKO);
  459. omap_cfg_reg(F20_24XX_MMC_DAT0);
  460. omap_cfg_reg(F19_24XX_MMC_DAT_DIR0);
  461. omap_cfg_reg(G18_24XX_MMC_CMD_DIR);
  462. if (mmc_controller->slots[0].wires == 4) {
  463. omap_cfg_reg(H14_24XX_MMC_DAT1);
  464. omap_cfg_reg(E19_24XX_MMC_DAT2);
  465. omap_cfg_reg(D19_24XX_MMC_DAT3);
  466. omap_cfg_reg(E20_24XX_MMC_DAT_DIR1);
  467. omap_cfg_reg(F18_24XX_MMC_DAT_DIR2);
  468. omap_cfg_reg(E18_24XX_MMC_DAT_DIR3);
  469. }
  470. /*
  471. * Use internal loop-back in MMC/SDIO Module Input Clock
  472. * selection
  473. */
  474. if (mmc_controller->slots[0].internal_clock) {
  475. u32 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  476. v |= (1 << 24);
  477. omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
  478. }
  479. }
  480. }
  481. void __init omap2_init_mmc(struct omap_mmc_platform_data **mmc_data,
  482. int nr_controllers)
  483. {
  484. int i;
  485. char *name;
  486. for (i = 0; i < nr_controllers; i++) {
  487. unsigned long base, size;
  488. unsigned int irq = 0;
  489. if (!mmc_data[i])
  490. continue;
  491. omap2_mmc_mux(mmc_data[i], i);
  492. switch (i) {
  493. case 0:
  494. base = OMAP2_MMC1_BASE;
  495. irq = INT_24XX_MMC_IRQ;
  496. break;
  497. case 1:
  498. base = OMAP2_MMC2_BASE;
  499. irq = INT_24XX_MMC2_IRQ;
  500. break;
  501. case 2:
  502. if (!cpu_is_omap34xx())
  503. return;
  504. base = OMAP3_MMC3_BASE;
  505. irq = INT_34XX_MMC3_IRQ;
  506. break;
  507. default:
  508. continue;
  509. }
  510. if (cpu_is_omap2420()) {
  511. size = OMAP2420_MMC_SIZE;
  512. name = "mmci-omap";
  513. } else {
  514. size = HSMMC_SIZE;
  515. name = "mmci-omap-hs";
  516. }
  517. omap_mmc_add(name, i, base, size, irq, mmc_data[i]);
  518. };
  519. }
  520. #endif
  521. /*-------------------------------------------------------------------------*/
  522. #if defined(CONFIG_HDQ_MASTER_OMAP) || defined(CONFIG_HDQ_MASTER_OMAP_MODULE)
  523. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
  524. #define OMAP_HDQ_BASE 0x480B2000
  525. #endif
  526. static struct resource omap_hdq_resources[] = {
  527. {
  528. .start = OMAP_HDQ_BASE,
  529. .end = OMAP_HDQ_BASE + 0x1C,
  530. .flags = IORESOURCE_MEM,
  531. },
  532. {
  533. .start = INT_24XX_HDQ_IRQ,
  534. .flags = IORESOURCE_IRQ,
  535. },
  536. };
  537. static struct platform_device omap_hdq_dev = {
  538. .name = "omap_hdq",
  539. .id = 0,
  540. .dev = {
  541. .platform_data = NULL,
  542. },
  543. .num_resources = ARRAY_SIZE(omap_hdq_resources),
  544. .resource = omap_hdq_resources,
  545. };
  546. static inline void omap_hdq_init(void)
  547. {
  548. (void) platform_device_register(&omap_hdq_dev);
  549. }
  550. #else
  551. static inline void omap_hdq_init(void) {}
  552. #endif
  553. /*-------------------------------------------------------------------------*/
  554. static int __init omap2_init_devices(void)
  555. {
  556. /* please keep these calls, and their implementations above,
  557. * in alphabetical order so they're easier to sort through.
  558. */
  559. omap_hsmmc_reset();
  560. omap_init_camera();
  561. omap_init_mbox();
  562. omap_init_mcspi();
  563. omap_hdq_init();
  564. omap_init_sti();
  565. omap_init_sha1_md5();
  566. return 0;
  567. }
  568. arch_initcall(omap2_init_devices);