devices.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. }
  272. #ifdef CONFIG_ARCH_OMAP16XX
  273. /* block 2 is on newer chips, and has many pinout options */
  274. if (mmc_conf->mmc[1].enabled) {
  275. if (!mmc_conf->mmc[1].nomux) {
  276. omap_cfg_reg(Y8_1610_MMC2_CMD);
  277. omap_cfg_reg(Y10_1610_MMC2_CLK);
  278. omap_cfg_reg(R18_1610_MMC2_CLKIN);
  279. omap_cfg_reg(W8_1610_MMC2_DAT0);
  280. if (mmc_conf->mmc[1].wire4) {
  281. omap_cfg_reg(V8_1610_MMC2_DAT1);
  282. omap_cfg_reg(W15_1610_MMC2_DAT2);
  283. omap_cfg_reg(R10_1610_MMC2_DAT3);
  284. }
  285. /* These are needed for the level shifter */
  286. omap_cfg_reg(V9_1610_MMC2_CMDDIR);
  287. omap_cfg_reg(V5_1610_MMC2_DATDIR0);
  288. omap_cfg_reg(W19_1610_MMC2_DATDIR1);
  289. }
  290. /* Feedback clock must be set on OMAP-1710 MMC2 */
  291. if (cpu_is_omap1710())
  292. omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
  293. MOD_CONF_CTRL_1);
  294. }
  295. #endif
  296. }
  297. static void __init omap_init_mmc(void)
  298. {
  299. const struct omap_mmc_config *mmc_conf;
  300. /* NOTE: assumes MMC was never (wrongly) enabled */
  301. mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
  302. if (!mmc_conf)
  303. return;
  304. omap_init_mmc_conf(mmc_conf);
  305. if (mmc_conf->mmc[0].enabled) {
  306. mmc1_data.conf = mmc_conf->mmc[0];
  307. (void) platform_device_register(&mmc_omap_device1);
  308. }
  309. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2430) || \
  310. defined(CONFIG_ARCH_OMAP34XX)
  311. if (mmc_conf->mmc[1].enabled) {
  312. mmc2_data.conf = mmc_conf->mmc[1];
  313. (void) platform_device_register(&mmc_omap_device2);
  314. }
  315. #endif
  316. }
  317. void omap_set_mmc_info(int host, const struct omap_mmc_platform_data *info)
  318. {
  319. switch (host) {
  320. case 1:
  321. mmc1_data = *info;
  322. break;
  323. #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2430) || \
  324. defined(CONFIG_ARCH_OMAP34XX)
  325. case 2:
  326. mmc2_data = *info;
  327. break;
  328. #endif
  329. default:
  330. BUG();
  331. }
  332. }
  333. #else
  334. static inline void omap_init_mmc(void) {}
  335. void omap_set_mmc_info(int host, const struct omap_mmc_platform_data *info) {}
  336. #endif
  337. /*-------------------------------------------------------------------------*/
  338. /* Numbering for the SPI-capable controllers when used for SPI:
  339. * spi = 1
  340. * uwire = 2
  341. * mmc1..2 = 3..4
  342. * mcbsp1..3 = 5..7
  343. */
  344. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  345. #define OMAP_UWIRE_BASE 0xfffb3000
  346. static struct resource uwire_resources[] = {
  347. {
  348. .start = OMAP_UWIRE_BASE,
  349. .end = OMAP_UWIRE_BASE + 0x20,
  350. .flags = IORESOURCE_MEM,
  351. },
  352. };
  353. static struct platform_device omap_uwire_device = {
  354. .name = "omap_uwire",
  355. .id = -1,
  356. .num_resources = ARRAY_SIZE(uwire_resources),
  357. .resource = uwire_resources,
  358. };
  359. static void omap_init_uwire(void)
  360. {
  361. /* FIXME define and use a boot tag; not all boards will be hooking
  362. * up devices to the microwire controller, and multi-board configs
  363. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  364. */
  365. /* board-specific code must configure chipselects (only a few
  366. * are normally used) and SCLK/SDI/SDO (each has two choices).
  367. */
  368. (void) platform_device_register(&omap_uwire_device);
  369. }
  370. #else
  371. static inline void omap_init_uwire(void) {}
  372. #endif
  373. /*-------------------------------------------------------------------------*/
  374. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  375. #ifdef CONFIG_ARCH_OMAP24XX
  376. #define OMAP_WDT_BASE 0x48022000
  377. #else
  378. #define OMAP_WDT_BASE 0xfffeb000
  379. #endif
  380. static struct resource wdt_resources[] = {
  381. {
  382. .start = OMAP_WDT_BASE,
  383. .end = OMAP_WDT_BASE + 0x4f,
  384. .flags = IORESOURCE_MEM,
  385. },
  386. };
  387. static struct platform_device omap_wdt_device = {
  388. .name = "omap_wdt",
  389. .id = -1,
  390. .num_resources = ARRAY_SIZE(wdt_resources),
  391. .resource = wdt_resources,
  392. };
  393. static void omap_init_wdt(void)
  394. {
  395. (void) platform_device_register(&omap_wdt_device);
  396. }
  397. #else
  398. static inline void omap_init_wdt(void) {}
  399. #endif
  400. /*-------------------------------------------------------------------------*/
  401. #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
  402. #ifdef CONFIG_ARCH_OMAP24XX
  403. #define OMAP_RNG_BASE 0x480A0000
  404. #else
  405. #define OMAP_RNG_BASE 0xfffe5000
  406. #endif
  407. static struct resource rng_resources[] = {
  408. {
  409. .start = OMAP_RNG_BASE,
  410. .end = OMAP_RNG_BASE + 0x4f,
  411. .flags = IORESOURCE_MEM,
  412. },
  413. };
  414. static struct platform_device omap_rng_device = {
  415. .name = "omap_rng",
  416. .id = -1,
  417. .num_resources = ARRAY_SIZE(rng_resources),
  418. .resource = rng_resources,
  419. };
  420. static void omap_init_rng(void)
  421. {
  422. (void) platform_device_register(&omap_rng_device);
  423. }
  424. #else
  425. static inline void omap_init_rng(void) {}
  426. #endif
  427. /*
  428. * This gets called after board-specific INIT_MACHINE, and initializes most
  429. * on-chip peripherals accessible on this board (except for few like USB):
  430. *
  431. * (a) Does any "standard config" pin muxing needed. Board-specific
  432. * code will have muxed GPIO pins and done "nonstandard" setup;
  433. * that code could live in the boot loader.
  434. * (b) Populating board-specific platform_data with the data drivers
  435. * rely on to handle wiring variations.
  436. * (c) Creating platform devices as meaningful on this board and
  437. * with this kernel configuration.
  438. *
  439. * Claiming GPIOs, and setting their direction and initial values, is the
  440. * responsibility of the device drivers. So is responding to probe().
  441. *
  442. * Board-specific knowlege like creating devices or pin setup is to be
  443. * kept out of drivers as much as possible. In particular, pin setup
  444. * may be handled by the boot loader, and drivers should expect it will
  445. * normally have been done by the time they're probed.
  446. */
  447. static int __init omap_init_devices(void)
  448. {
  449. /*
  450. * Need to enable relevant once for 2430 SDP
  451. */
  452. #ifndef CONFIG_MACH_OMAP_2430SDP
  453. /* please keep these calls, and their implementations above,
  454. * in alphabetical order so they're easier to sort through.
  455. */
  456. omap_init_dsp();
  457. omap_init_kp();
  458. omap_init_mmc();
  459. omap_init_uwire();
  460. omap_init_wdt();
  461. omap_init_rng();
  462. #endif
  463. return 0;
  464. }
  465. arch_initcall(omap_init_devices);