devices.c 14 KB

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