devices.c 9.1 KB

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