devices.c 14 KB

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