devices.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * linux/arch/arm/plat-omap/devices.c
  3. *
  4. * Common platform device setup/initialization for OMAP1 and OMAP2
  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 <mach/hardware.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/mach/map.h>
  19. #include <mach/tc.h>
  20. #include <mach/control.h>
  21. #include <mach/board.h>
  22. #include <mach/mmc.h>
  23. #include <mach/mux.h>
  24. #include <mach/gpio.h>
  25. #include <mach/menelaus.h>
  26. #include <mach/mcbsp.h>
  27. #include <mach/dsp_common.h>
  28. #if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
  29. static struct dsp_platform_data dsp_pdata = {
  30. .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list),
  31. };
  32. static struct resource omap_dsp_resources[] = {
  33. {
  34. .name = "dsp_mmu",
  35. .start = -1,
  36. .flags = IORESOURCE_IRQ,
  37. },
  38. };
  39. static struct platform_device omap_dsp_device = {
  40. .name = "dsp",
  41. .id = -1,
  42. .num_resources = ARRAY_SIZE(omap_dsp_resources),
  43. .resource = omap_dsp_resources,
  44. .dev = {
  45. .platform_data = &dsp_pdata,
  46. },
  47. };
  48. static inline void omap_init_dsp(void)
  49. {
  50. struct resource *res;
  51. int irq;
  52. if (cpu_is_omap15xx())
  53. irq = INT_1510_DSP_MMU;
  54. else if (cpu_is_omap16xx())
  55. irq = INT_1610_DSP_MMU;
  56. else if (cpu_is_omap24xx())
  57. irq = INT_24XX_DSP_MMU;
  58. res = platform_get_resource_byname(&omap_dsp_device,
  59. IORESOURCE_IRQ, "dsp_mmu");
  60. res->start = irq;
  61. platform_device_register(&omap_dsp_device);
  62. }
  63. int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev)
  64. {
  65. static DEFINE_MUTEX(dsp_pdata_lock);
  66. spin_lock_init(&kdev->lock);
  67. mutex_lock(&dsp_pdata_lock);
  68. list_add_tail(&kdev->entry, &dsp_pdata.kdev_list);
  69. mutex_unlock(&dsp_pdata_lock);
  70. return 0;
  71. }
  72. EXPORT_SYMBOL(dsp_kfunc_device_register);
  73. #else
  74. static inline void omap_init_dsp(void) { }
  75. #endif /* CONFIG_OMAP_DSP */
  76. /*-------------------------------------------------------------------------*/
  77. #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
  78. static void omap_init_kp(void)
  79. {
  80. /* 2430 and 34xx keypad is on TWL4030 */
  81. if (cpu_is_omap2430() || cpu_is_omap34xx())
  82. return;
  83. if (machine_is_omap_h2() || machine_is_omap_h3()) {
  84. omap_cfg_reg(F18_1610_KBC0);
  85. omap_cfg_reg(D20_1610_KBC1);
  86. omap_cfg_reg(D19_1610_KBC2);
  87. omap_cfg_reg(E18_1610_KBC3);
  88. omap_cfg_reg(C21_1610_KBC4);
  89. omap_cfg_reg(G18_1610_KBR0);
  90. omap_cfg_reg(F19_1610_KBR1);
  91. omap_cfg_reg(H14_1610_KBR2);
  92. omap_cfg_reg(E20_1610_KBR3);
  93. omap_cfg_reg(E19_1610_KBR4);
  94. omap_cfg_reg(N19_1610_KBR5);
  95. } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) {
  96. omap_cfg_reg(E2_730_KBR0);
  97. omap_cfg_reg(J7_730_KBR1);
  98. omap_cfg_reg(E1_730_KBR2);
  99. omap_cfg_reg(F3_730_KBR3);
  100. omap_cfg_reg(D2_730_KBR4);
  101. omap_cfg_reg(C2_730_KBC0);
  102. omap_cfg_reg(D3_730_KBC1);
  103. omap_cfg_reg(E4_730_KBC2);
  104. omap_cfg_reg(F4_730_KBC3);
  105. omap_cfg_reg(E3_730_KBC4);
  106. } else if (machine_is_omap_h4()) {
  107. omap_cfg_reg(T19_24XX_KBR0);
  108. omap_cfg_reg(R19_24XX_KBR1);
  109. omap_cfg_reg(V18_24XX_KBR2);
  110. omap_cfg_reg(M21_24XX_KBR3);
  111. omap_cfg_reg(E5__24XX_KBR4);
  112. if (omap_has_menelaus()) {
  113. omap_cfg_reg(B3__24XX_KBR5);
  114. omap_cfg_reg(AA4_24XX_KBC2);
  115. omap_cfg_reg(B13_24XX_KBC6);
  116. } else {
  117. omap_cfg_reg(M18_24XX_KBR5);
  118. omap_cfg_reg(H19_24XX_KBC2);
  119. omap_cfg_reg(N19_24XX_KBC6);
  120. }
  121. omap_cfg_reg(R20_24XX_KBC0);
  122. omap_cfg_reg(M14_24XX_KBC1);
  123. omap_cfg_reg(V17_24XX_KBC3);
  124. omap_cfg_reg(P21_24XX_KBC4);
  125. omap_cfg_reg(L14_24XX_KBC5);
  126. }
  127. }
  128. #else
  129. static inline void omap_init_kp(void) {}
  130. #endif
  131. /*-------------------------------------------------------------------------*/
  132. #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
  133. static struct platform_device **omap_mcbsp_devices;
  134. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  135. int size)
  136. {
  137. int i;
  138. omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
  139. GFP_KERNEL);
  140. if (!omap_mcbsp_devices) {
  141. printk(KERN_ERR "Could not register McBSP devices\n");
  142. return;
  143. }
  144. for (i = 0; i < size; i++) {
  145. struct platform_device *new_mcbsp;
  146. int ret;
  147. new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
  148. if (!new_mcbsp)
  149. continue;
  150. new_mcbsp->dev.platform_data = &config[i];
  151. ret = platform_device_add(new_mcbsp);
  152. if (ret) {
  153. platform_device_put(new_mcbsp);
  154. continue;
  155. }
  156. omap_mcbsp_devices[i] = new_mcbsp;
  157. }
  158. }
  159. #else
  160. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  161. int size)
  162. { }
  163. #endif
  164. /*-------------------------------------------------------------------------*/
  165. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
  166. defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  167. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  168. #define OMAP_MMC1_BASE 0x4809c000
  169. #define OMAP_MMC1_END (OMAP_MMC1_BASE + 0x1fc)
  170. #define OMAP_MMC1_INT INT_24XX_MMC_IRQ
  171. #define OMAP_MMC2_BASE 0x480b4000
  172. #define OMAP_MMC2_END (OMAP_MMC2_BASE + 0x1fc)
  173. #define OMAP_MMC2_INT INT_24XX_MMC2_IRQ
  174. #else
  175. #define OMAP_MMC1_BASE 0xfffb7800
  176. #define OMAP_MMC1_END (OMAP_MMC1_BASE + 0x7f)
  177. #define OMAP_MMC1_INT INT_MMC
  178. #define OMAP_MMC2_BASE 0xfffb7c00 /* omap16xx only */
  179. #define OMAP_MMC2_END (OMAP_MMC2_BASE + 0x7f)
  180. #define OMAP_MMC2_INT INT_1610_MMC2
  181. #endif
  182. static struct omap_mmc_platform_data mmc1_data;
  183. static u64 mmc1_dmamask = 0xffffffff;
  184. static struct resource mmc1_resources[] = {
  185. {
  186. .start = OMAP_MMC1_BASE,
  187. .end = OMAP_MMC1_END,
  188. .flags = IORESOURCE_MEM,
  189. },
  190. {
  191. .start = OMAP_MMC1_INT,
  192. .flags = IORESOURCE_IRQ,
  193. },
  194. };
  195. static struct platform_device mmc_omap_device1 = {
  196. .name = "mmci-omap",
  197. .id = 1,
  198. .dev = {
  199. .dma_mask = &mmc1_dmamask,
  200. .platform_data = &mmc1_data,
  201. },
  202. .num_resources = ARRAY_SIZE(mmc1_resources),
  203. .resource = mmc1_resources,
  204. };
  205. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2430) || \
  206. defined(CONFIG_ARCH_OMAP34XX)
  207. static struct omap_mmc_platform_data mmc2_data;
  208. static u64 mmc2_dmamask = 0xffffffff;
  209. static struct resource mmc2_resources[] = {
  210. {
  211. .start = OMAP_MMC2_BASE,
  212. .end = OMAP_MMC2_END,
  213. .flags = IORESOURCE_MEM,
  214. },
  215. {
  216. .start = OMAP_MMC2_INT,
  217. .flags = IORESOURCE_IRQ,
  218. },
  219. };
  220. static struct platform_device mmc_omap_device2 = {
  221. .name = "mmci-omap",
  222. .id = 2,
  223. .dev = {
  224. .dma_mask = &mmc2_dmamask,
  225. .platform_data = &mmc2_data,
  226. },
  227. .num_resources = ARRAY_SIZE(mmc2_resources),
  228. .resource = mmc2_resources,
  229. };
  230. #endif
  231. static inline void omap_init_mmc_conf(const struct omap_mmc_config *mmc_conf)
  232. {
  233. if (cpu_is_omap2430() || cpu_is_omap34xx())
  234. return;
  235. if (mmc_conf->mmc[0].enabled) {
  236. if (cpu_is_omap24xx()) {
  237. omap_cfg_reg(H18_24XX_MMC_CMD);
  238. omap_cfg_reg(H15_24XX_MMC_CLKI);
  239. omap_cfg_reg(G19_24XX_MMC_CLKO);
  240. omap_cfg_reg(F20_24XX_MMC_DAT0);
  241. omap_cfg_reg(F19_24XX_MMC_DAT_DIR0);
  242. omap_cfg_reg(G18_24XX_MMC_CMD_DIR);
  243. } else {
  244. omap_cfg_reg(MMC_CMD);
  245. omap_cfg_reg(MMC_CLK);
  246. omap_cfg_reg(MMC_DAT0);
  247. if (cpu_is_omap1710()) {
  248. omap_cfg_reg(M15_1710_MMC_CLKI);
  249. omap_cfg_reg(P19_1710_MMC_CMDDIR);
  250. omap_cfg_reg(P20_1710_MMC_DATDIR0);
  251. }
  252. }
  253. if (mmc_conf->mmc[0].wire4) {
  254. if (cpu_is_omap24xx()) {
  255. omap_cfg_reg(H14_24XX_MMC_DAT1);
  256. omap_cfg_reg(E19_24XX_MMC_DAT2);
  257. omap_cfg_reg(D19_24XX_MMC_DAT3);
  258. omap_cfg_reg(E20_24XX_MMC_DAT_DIR1);
  259. omap_cfg_reg(F18_24XX_MMC_DAT_DIR2);
  260. omap_cfg_reg(E18_24XX_MMC_DAT_DIR3);
  261. } else {
  262. omap_cfg_reg(MMC_DAT1);
  263. /* NOTE: DAT2 can be on W10 (here) or M15 */
  264. if (!mmc_conf->mmc[0].nomux)
  265. omap_cfg_reg(MMC_DAT2);
  266. omap_cfg_reg(MMC_DAT3);
  267. }
  268. }
  269. }
  270. #ifdef CONFIG_ARCH_OMAP16XX
  271. /* block 2 is on newer chips, and has many pinout options */
  272. if (mmc_conf->mmc[1].enabled) {
  273. if (!mmc_conf->mmc[1].nomux) {
  274. omap_cfg_reg(Y8_1610_MMC2_CMD);
  275. omap_cfg_reg(Y10_1610_MMC2_CLK);
  276. omap_cfg_reg(R18_1610_MMC2_CLKIN);
  277. omap_cfg_reg(W8_1610_MMC2_DAT0);
  278. if (mmc_conf->mmc[1].wire4) {
  279. omap_cfg_reg(V8_1610_MMC2_DAT1);
  280. omap_cfg_reg(W15_1610_MMC2_DAT2);
  281. omap_cfg_reg(R10_1610_MMC2_DAT3);
  282. }
  283. /* These are needed for the level shifter */
  284. omap_cfg_reg(V9_1610_MMC2_CMDDIR);
  285. omap_cfg_reg(V5_1610_MMC2_DATDIR0);
  286. omap_cfg_reg(W19_1610_MMC2_DATDIR1);
  287. }
  288. /* Feedback clock must be set on OMAP-1710 MMC2 */
  289. if (cpu_is_omap1710())
  290. omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
  291. MOD_CONF_CTRL_1);
  292. }
  293. #endif
  294. }
  295. static void __init omap_init_mmc(void)
  296. {
  297. const struct omap_mmc_config *mmc_conf;
  298. /* NOTE: assumes MMC was never (wrongly) enabled */
  299. mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
  300. if (!mmc_conf)
  301. return;
  302. omap_init_mmc_conf(mmc_conf);
  303. if (mmc_conf->mmc[0].enabled) {
  304. mmc1_data.conf = mmc_conf->mmc[0];
  305. (void) platform_device_register(&mmc_omap_device1);
  306. }
  307. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2430) || \
  308. defined(CONFIG_ARCH_OMAP34XX)
  309. if (mmc_conf->mmc[1].enabled) {
  310. mmc2_data.conf = mmc_conf->mmc[1];
  311. (void) platform_device_register(&mmc_omap_device2);
  312. }
  313. #endif
  314. }
  315. void omap_set_mmc_info(int host, const struct omap_mmc_platform_data *info)
  316. {
  317. switch (host) {
  318. case 1:
  319. mmc1_data = *info;
  320. break;
  321. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2430) || \
  322. defined(CONFIG_ARCH_OMAP34XX)
  323. case 2:
  324. mmc2_data = *info;
  325. break;
  326. #endif
  327. default:
  328. BUG();
  329. }
  330. }
  331. #else
  332. static inline void omap_init_mmc(void) {}
  333. void omap_set_mmc_info(int host, const struct omap_mmc_platform_data *info) {}
  334. #endif
  335. /*-------------------------------------------------------------------------*/
  336. /* Numbering for the SPI-capable controllers when used for SPI:
  337. * spi = 1
  338. * uwire = 2
  339. * mmc1..2 = 3..4
  340. * mcbsp1..3 = 5..7
  341. */
  342. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  343. #define OMAP_UWIRE_BASE 0xfffb3000
  344. static struct resource uwire_resources[] = {
  345. {
  346. .start = OMAP_UWIRE_BASE,
  347. .end = OMAP_UWIRE_BASE + 0x20,
  348. .flags = IORESOURCE_MEM,
  349. },
  350. };
  351. static struct platform_device omap_uwire_device = {
  352. .name = "omap_uwire",
  353. .id = -1,
  354. .num_resources = ARRAY_SIZE(uwire_resources),
  355. .resource = uwire_resources,
  356. };
  357. static void omap_init_uwire(void)
  358. {
  359. /* FIXME define and use a boot tag; not all boards will be hooking
  360. * up devices to the microwire controller, and multi-board configs
  361. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  362. */
  363. /* board-specific code must configure chipselects (only a few
  364. * are normally used) and SCLK/SDI/SDO (each has two choices).
  365. */
  366. (void) platform_device_register(&omap_uwire_device);
  367. }
  368. #else
  369. static inline void omap_init_uwire(void) {}
  370. #endif
  371. /*-------------------------------------------------------------------------*/
  372. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  373. static struct resource wdt_resources[] = {
  374. {
  375. .flags = IORESOURCE_MEM,
  376. },
  377. };
  378. static struct platform_device omap_wdt_device = {
  379. .name = "omap_wdt",
  380. .id = -1,
  381. .num_resources = ARRAY_SIZE(wdt_resources),
  382. .resource = wdt_resources,
  383. };
  384. static void omap_init_wdt(void)
  385. {
  386. if (cpu_is_omap16xx())
  387. wdt_resources[0].start = 0xfffeb000;
  388. else if (cpu_is_omap2420())
  389. wdt_resources[0].start = 0x48022000; /* WDT2 */
  390. else if (cpu_is_omap2430())
  391. wdt_resources[0].start = 0x49016000; /* WDT2 */
  392. else if (cpu_is_omap343x())
  393. wdt_resources[0].start = 0x48314000; /* WDT2 */
  394. else
  395. return;
  396. wdt_resources[0].end = wdt_resources[0].start + 0x4f;
  397. (void) platform_device_register(&omap_wdt_device);
  398. }
  399. #else
  400. static inline void omap_init_wdt(void) {}
  401. #endif
  402. /*-------------------------------------------------------------------------*/
  403. #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
  404. #ifdef CONFIG_ARCH_OMAP24XX
  405. #define OMAP_RNG_BASE 0x480A0000
  406. #else
  407. #define OMAP_RNG_BASE 0xfffe5000
  408. #endif
  409. static struct resource rng_resources[] = {
  410. {
  411. .start = OMAP_RNG_BASE,
  412. .end = OMAP_RNG_BASE + 0x4f,
  413. .flags = IORESOURCE_MEM,
  414. },
  415. };
  416. static struct platform_device omap_rng_device = {
  417. .name = "omap_rng",
  418. .id = -1,
  419. .num_resources = ARRAY_SIZE(rng_resources),
  420. .resource = rng_resources,
  421. };
  422. static void omap_init_rng(void)
  423. {
  424. (void) platform_device_register(&omap_rng_device);
  425. }
  426. #else
  427. static inline void omap_init_rng(void) {}
  428. #endif
  429. /*
  430. * This gets called after board-specific INIT_MACHINE, and initializes most
  431. * on-chip peripherals accessible on this board (except for few like USB):
  432. *
  433. * (a) Does any "standard config" pin muxing needed. Board-specific
  434. * code will have muxed GPIO pins and done "nonstandard" setup;
  435. * that code could live in the boot loader.
  436. * (b) Populating board-specific platform_data with the data drivers
  437. * rely on to handle wiring variations.
  438. * (c) Creating platform devices as meaningful on this board and
  439. * with this kernel configuration.
  440. *
  441. * Claiming GPIOs, and setting their direction and initial values, is the
  442. * responsibility of the device drivers. So is responding to probe().
  443. *
  444. * Board-specific knowlege like creating devices or pin setup is to be
  445. * kept out of drivers as much as possible. In particular, pin setup
  446. * may be handled by the boot loader, and drivers should expect it will
  447. * normally have been done by the time they're probed.
  448. */
  449. static int __init omap_init_devices(void)
  450. {
  451. /* please keep these calls, and their implementations above,
  452. * in alphabetical order so they're easier to sort through.
  453. */
  454. omap_init_dsp();
  455. omap_init_kp();
  456. omap_init_mmc();
  457. omap_init_uwire();
  458. omap_init_wdt();
  459. omap_init_rng();
  460. return 0;
  461. }
  462. arch_initcall(omap_init_devices);