devices.c 11 KB

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