devices.c 13 KB

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