devices.c 11 KB

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