devices.c 11 KB

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