devices.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * linux/arch/arm/mach-omap1/devices.c
  3. *
  4. * OMAP1 platform device setup/initialization
  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/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. static 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 OMAP_I2C_BASE 0xfffb3800
  31. static struct resource i2c_resources[] = {
  32. {
  33. .start = OMAP_I2C_BASE,
  34. .end = OMAP_I2C_BASE + 0x3f,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. {
  38. .start = INT_I2C,
  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_device = {
  44. .name = "i2c_omap",
  45. .id = -1,
  46. .dev = {
  47. .release = omap_nop_release,
  48. },
  49. .num_resources = ARRAY_SIZE(i2c_resources),
  50. .resource = i2c_resources,
  51. };
  52. static void omap_init_i2c(void)
  53. {
  54. /* FIXME define and use a boot tag, in case of boards that
  55. * either don't wire up I2C, or chips that mux it differently...
  56. * it can include clocking and address info, maybe more.
  57. */
  58. omap_cfg_reg(I2C_SCL);
  59. omap_cfg_reg(I2C_SDA);
  60. (void) platform_device_register(&omap_i2c_device);
  61. }
  62. #else
  63. static inline void omap_init_i2c(void) {}
  64. #endif
  65. /*-------------------------------------------------------------------------*/
  66. #if defined(CONFIG_OMAP1610_IR) || defined(CONFIG_OMAP161O_IR_MODULE)
  67. static u64 irda_dmamask = 0xffffffff;
  68. static struct platform_device omap1610ir_device = {
  69. .name = "omap1610-ir",
  70. .id = -1,
  71. .dev = {
  72. .release = omap_nop_release,
  73. .dma_mask = &irda_dmamask,
  74. },
  75. };
  76. static void omap_init_irda(void)
  77. {
  78. /* FIXME define and use a boot tag, members something like:
  79. * u8 uart; // uart1, or uart3
  80. * ... but driver only handles uart3 for now
  81. * s16 fir_sel; // gpio for SIR vs FIR
  82. * ... may prefer a callback for SIR/MIR/FIR mode select;
  83. * while h2 uses a GPIO, H3 uses a gpio expander
  84. */
  85. if (machine_is_omap_h2()
  86. || machine_is_omap_h3())
  87. (void) platform_device_register(&omap1610ir_device);
  88. }
  89. #else
  90. static inline void omap_init_irda(void) {}
  91. #endif
  92. /*-------------------------------------------------------------------------*/
  93. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
  94. #define OMAP_MMC1_BASE 0xfffb7800
  95. #define OMAP_MMC2_BASE 0xfffb7c00 /* omap16xx only */
  96. static struct omap_mmc_conf mmc1_conf;
  97. static u64 mmc1_dmamask = 0xffffffff;
  98. static struct resource mmc1_resources[] = {
  99. {
  100. .start = IO_ADDRESS(OMAP_MMC1_BASE),
  101. .end = IO_ADDRESS(OMAP_MMC1_BASE) + 0x7f,
  102. .flags = IORESOURCE_MEM,
  103. },
  104. {
  105. .start = INT_MMC,
  106. .flags = IORESOURCE_IRQ,
  107. },
  108. };
  109. static struct platform_device mmc_omap_device1 = {
  110. .name = "mmci-omap",
  111. .id = 1,
  112. .dev = {
  113. .release = omap_nop_release,
  114. .dma_mask = &mmc1_dmamask,
  115. .platform_data = &mmc1_conf,
  116. },
  117. .num_resources = ARRAY_SIZE(mmc1_resources),
  118. .resource = mmc1_resources,
  119. };
  120. #ifdef CONFIG_ARCH_OMAP16XX
  121. static struct omap_mmc_conf mmc2_conf;
  122. static u64 mmc2_dmamask = 0xffffffff;
  123. static struct resource mmc2_resources[] = {
  124. {
  125. .start = IO_ADDRESS(OMAP_MMC2_BASE),
  126. .end = IO_ADDRESS(OMAP_MMC2_BASE) + 0x7f,
  127. .flags = IORESOURCE_MEM,
  128. },
  129. {
  130. .start = INT_1610_MMC2,
  131. .flags = IORESOURCE_IRQ,
  132. },
  133. };
  134. static struct platform_device mmc_omap_device2 = {
  135. .name = "mmci-omap",
  136. .id = 2,
  137. .dev = {
  138. .release = omap_nop_release,
  139. .dma_mask = &mmc2_dmamask,
  140. .platform_data = &mmc2_conf,
  141. },
  142. .num_resources = ARRAY_SIZE(mmc2_resources),
  143. .resource = mmc2_resources,
  144. };
  145. #endif
  146. static void __init omap_init_mmc(void)
  147. {
  148. const struct omap_mmc_config *mmc_conf;
  149. const struct omap_mmc_conf *mmc;
  150. /* NOTE: assumes MMC was never (wrongly) enabled */
  151. mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
  152. if (!mmc_conf)
  153. return;
  154. /* block 1 is always available and has just one pinout option */
  155. mmc = &mmc_conf->mmc[0];
  156. if (mmc->enabled) {
  157. omap_cfg_reg(MMC_CMD);
  158. omap_cfg_reg(MMC_CLK);
  159. omap_cfg_reg(MMC_DAT0);
  160. if (cpu_is_omap1710()) {
  161. omap_cfg_reg(M15_1710_MMC_CLKI);
  162. omap_cfg_reg(P19_1710_MMC_CMDDIR);
  163. omap_cfg_reg(P20_1710_MMC_DATDIR0);
  164. }
  165. if (mmc->wire4) {
  166. omap_cfg_reg(MMC_DAT1);
  167. /* NOTE: DAT2 can be on W10 (here) or M15 */
  168. if (!mmc->nomux)
  169. omap_cfg_reg(MMC_DAT2);
  170. omap_cfg_reg(MMC_DAT3);
  171. }
  172. mmc1_conf = *mmc;
  173. (void) platform_device_register(&mmc_omap_device1);
  174. }
  175. #ifdef CONFIG_ARCH_OMAP16XX
  176. /* block 2 is on newer chips, and has many pinout options */
  177. mmc = &mmc_conf->mmc[1];
  178. if (mmc->enabled) {
  179. if (!mmc->nomux) {
  180. omap_cfg_reg(Y8_1610_MMC2_CMD);
  181. omap_cfg_reg(Y10_1610_MMC2_CLK);
  182. omap_cfg_reg(R18_1610_MMC2_CLKIN);
  183. omap_cfg_reg(W8_1610_MMC2_DAT0);
  184. if (mmc->wire4) {
  185. omap_cfg_reg(V8_1610_MMC2_DAT1);
  186. omap_cfg_reg(W15_1610_MMC2_DAT2);
  187. omap_cfg_reg(R10_1610_MMC2_DAT3);
  188. }
  189. /* These are needed for the level shifter */
  190. omap_cfg_reg(V9_1610_MMC2_CMDDIR);
  191. omap_cfg_reg(V5_1610_MMC2_DATDIR0);
  192. omap_cfg_reg(W19_1610_MMC2_DATDIR1);
  193. }
  194. /* Feedback clock must be set on OMAP-1710 MMC2 */
  195. if (cpu_is_omap1710())
  196. omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
  197. MOD_CONF_CTRL_1);
  198. mmc2_conf = *mmc;
  199. (void) platform_device_register(&mmc_omap_device2);
  200. }
  201. #endif
  202. return;
  203. }
  204. #else
  205. static inline void omap_init_mmc(void) {}
  206. #endif
  207. #if defined(CONFIG_OMAP_RTC) || defined(CONFIG_OMAP_RTC)
  208. #define OMAP_RTC_BASE 0xfffb4800
  209. static struct resource rtc_resources[] = {
  210. {
  211. .start = OMAP_RTC_BASE,
  212. .end = OMAP_RTC_BASE + 0x5f,
  213. .flags = IORESOURCE_MEM,
  214. },
  215. {
  216. .start = INT_RTC_TIMER,
  217. .flags = IORESOURCE_IRQ,
  218. },
  219. {
  220. .start = INT_RTC_ALARM,
  221. .flags = IORESOURCE_IRQ,
  222. },
  223. };
  224. static struct platform_device omap_rtc_device = {
  225. .name = "omap_rtc",
  226. .id = -1,
  227. .dev = {
  228. .release = omap_nop_release,
  229. },
  230. .num_resources = ARRAY_SIZE(rtc_resources),
  231. .resource = rtc_resources,
  232. };
  233. static void omap_init_rtc(void)
  234. {
  235. (void) platform_device_register(&omap_rtc_device);
  236. }
  237. #else
  238. static inline void omap_init_rtc(void) {}
  239. #endif
  240. /*-------------------------------------------------------------------------*/
  241. #if defined(CONFIG_OMAP16XX_WATCHDOG) || defined(CONFIG_OMAP16XX_WATCHDOG_MODULE)
  242. #define OMAP_WDT_BASE 0xfffeb000
  243. static struct resource wdt_resources[] = {
  244. {
  245. .start = OMAP_WDT_BASE,
  246. .end = OMAP_WDT_BASE + 0x4f,
  247. .flags = IORESOURCE_MEM,
  248. },
  249. };
  250. static struct platform_device omap_wdt_device = {
  251. .name = "omap1610_wdt",
  252. .id = -1,
  253. .dev = {
  254. .release = omap_nop_release,
  255. },
  256. .num_resources = ARRAY_SIZE(wdt_resources),
  257. .resource = wdt_resources,
  258. };
  259. static void omap_init_wdt(void)
  260. {
  261. (void) platform_device_register(&omap_wdt_device);
  262. }
  263. #else
  264. static inline void omap_init_wdt(void) {}
  265. #endif
  266. /*-------------------------------------------------------------------------*/
  267. /*
  268. * This gets called after board-specific INIT_MACHINE, and initializes most
  269. * on-chip peripherals accessible on this board (except for few like USB):
  270. *
  271. * (a) Does any "standard config" pin muxing needed. Board-specific
  272. * code will have muxed GPIO pins and done "nonstandard" setup;
  273. * that code could live in the boot loader.
  274. * (b) Populating board-specific platform_data with the data drivers
  275. * rely on to handle wiring variations.
  276. * (c) Creating platform devices as meaningful on this board and
  277. * with this kernel configuration.
  278. *
  279. * Claiming GPIOs, and setting their direction and initial values, is the
  280. * responsibility of the device drivers. So is responding to probe().
  281. *
  282. * Board-specific knowlege like creating devices or pin setup is to be
  283. * kept out of drivers as much as possible. In particular, pin setup
  284. * may be handled by the boot loader, and drivers should expect it will
  285. * normally have been done by the time they're probed.
  286. */
  287. static int __init omap_init_devices(void)
  288. {
  289. /* please keep these calls, and their implementations above,
  290. * in alphabetical order so they're easier to sort through.
  291. */
  292. omap_init_i2c();
  293. omap_init_irda();
  294. omap_init_mmc();
  295. omap_init_rtc();
  296. omap_init_wdt();
  297. return 0;
  298. }
  299. arch_initcall(omap_init_devices);