devices.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 <linux/io.h>
  16. #include <linux/slab.h>
  17. #include <mach/hardware.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/mach/map.h>
  20. #include <plat/tc.h>
  21. #include <plat/control.h>
  22. #include <plat/board.h>
  23. #include <plat/mmc.h>
  24. #include <mach/gpio.h>
  25. #include <plat/menelaus.h>
  26. #include <plat/mcbsp.h>
  27. #include <plat/omap44xx.h>
  28. /*-------------------------------------------------------------------------*/
  29. #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
  30. static struct platform_device **omap_mcbsp_devices;
  31. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  32. int size)
  33. {
  34. int i;
  35. omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
  36. GFP_KERNEL);
  37. if (!omap_mcbsp_devices) {
  38. printk(KERN_ERR "Could not register McBSP devices\n");
  39. return;
  40. }
  41. for (i = 0; i < size; i++) {
  42. struct platform_device *new_mcbsp;
  43. int ret;
  44. new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
  45. if (!new_mcbsp)
  46. continue;
  47. new_mcbsp->dev.platform_data = &config[i];
  48. ret = platform_device_add(new_mcbsp);
  49. if (ret) {
  50. platform_device_put(new_mcbsp);
  51. continue;
  52. }
  53. omap_mcbsp_devices[i] = new_mcbsp;
  54. }
  55. }
  56. #else
  57. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  58. int size)
  59. { }
  60. #endif
  61. /*-------------------------------------------------------------------------*/
  62. #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
  63. defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
  64. static struct resource mcpdm_resources[] = {
  65. {
  66. .name = "mcpdm_mem",
  67. .start = OMAP44XX_MCPDM_BASE,
  68. .end = OMAP44XX_MCPDM_BASE + SZ_4K,
  69. .flags = IORESOURCE_MEM,
  70. },
  71. {
  72. .name = "mcpdm_irq",
  73. .start = OMAP44XX_IRQ_MCPDM,
  74. .end = OMAP44XX_IRQ_MCPDM,
  75. .flags = IORESOURCE_IRQ,
  76. },
  77. };
  78. static struct platform_device omap_mcpdm_device = {
  79. .name = "omap-mcpdm",
  80. .id = -1,
  81. .num_resources = ARRAY_SIZE(mcpdm_resources),
  82. .resource = mcpdm_resources,
  83. };
  84. static void omap_init_mcpdm(void)
  85. {
  86. (void) platform_device_register(&omap_mcpdm_device);
  87. }
  88. #else
  89. static inline void omap_init_mcpdm(void) {}
  90. #endif
  91. /*-------------------------------------------------------------------------*/
  92. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
  93. defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  94. #define OMAP_MMC_NR_RES 2
  95. /*
  96. * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
  97. */
  98. int __init omap_mmc_add(const char *name, int id, unsigned long base,
  99. unsigned long size, unsigned int irq,
  100. struct omap_mmc_platform_data *data)
  101. {
  102. struct platform_device *pdev;
  103. struct resource res[OMAP_MMC_NR_RES];
  104. int ret;
  105. pdev = platform_device_alloc(name, id);
  106. if (!pdev)
  107. return -ENOMEM;
  108. memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
  109. res[0].start = base;
  110. res[0].end = base + size - 1;
  111. res[0].flags = IORESOURCE_MEM;
  112. res[1].start = res[1].end = irq;
  113. res[1].flags = IORESOURCE_IRQ;
  114. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  115. if (ret == 0)
  116. ret = platform_device_add_data(pdev, data, sizeof(*data));
  117. if (ret)
  118. goto fail;
  119. ret = platform_device_add(pdev);
  120. if (ret)
  121. goto fail;
  122. /* return device handle to board setup code */
  123. data->dev = &pdev->dev;
  124. return 0;
  125. fail:
  126. platform_device_put(pdev);
  127. return ret;
  128. }
  129. #endif
  130. /*-------------------------------------------------------------------------*/
  131. #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
  132. #ifdef CONFIG_ARCH_OMAP2
  133. #define OMAP_RNG_BASE 0x480A0000
  134. #else
  135. #define OMAP_RNG_BASE 0xfffe5000
  136. #endif
  137. static struct resource rng_resources[] = {
  138. {
  139. .start = OMAP_RNG_BASE,
  140. .end = OMAP_RNG_BASE + 0x4f,
  141. .flags = IORESOURCE_MEM,
  142. },
  143. };
  144. static struct platform_device omap_rng_device = {
  145. .name = "omap_rng",
  146. .id = -1,
  147. .num_resources = ARRAY_SIZE(rng_resources),
  148. .resource = rng_resources,
  149. };
  150. static void omap_init_rng(void)
  151. {
  152. (void) platform_device_register(&omap_rng_device);
  153. }
  154. #else
  155. static inline void omap_init_rng(void) {}
  156. #endif
  157. /*-------------------------------------------------------------------------*/
  158. /* Numbering for the SPI-capable controllers when used for SPI:
  159. * spi = 1
  160. * uwire = 2
  161. * mmc1..2 = 3..4
  162. * mcbsp1..3 = 5..7
  163. */
  164. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  165. #define OMAP_UWIRE_BASE 0xfffb3000
  166. static struct resource uwire_resources[] = {
  167. {
  168. .start = OMAP_UWIRE_BASE,
  169. .end = OMAP_UWIRE_BASE + 0x20,
  170. .flags = IORESOURCE_MEM,
  171. },
  172. };
  173. static struct platform_device omap_uwire_device = {
  174. .name = "omap_uwire",
  175. .id = -1,
  176. .num_resources = ARRAY_SIZE(uwire_resources),
  177. .resource = uwire_resources,
  178. };
  179. static void omap_init_uwire(void)
  180. {
  181. /* FIXME define and use a boot tag; not all boards will be hooking
  182. * up devices to the microwire controller, and multi-board configs
  183. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  184. */
  185. /* board-specific code must configure chipselects (only a few
  186. * are normally used) and SCLK/SDI/SDO (each has two choices).
  187. */
  188. (void) platform_device_register(&omap_uwire_device);
  189. }
  190. #else
  191. static inline void omap_init_uwire(void) {}
  192. #endif
  193. /*-------------------------------------------------------------------------*/
  194. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  195. static struct resource wdt_resources[] = {
  196. {
  197. .flags = IORESOURCE_MEM,
  198. },
  199. };
  200. static struct platform_device omap_wdt_device = {
  201. .name = "omap_wdt",
  202. .id = -1,
  203. .num_resources = ARRAY_SIZE(wdt_resources),
  204. .resource = wdt_resources,
  205. };
  206. static void omap_init_wdt(void)
  207. {
  208. if (cpu_is_omap16xx())
  209. wdt_resources[0].start = 0xfffeb000;
  210. else if (cpu_is_omap2420())
  211. wdt_resources[0].start = 0x48022000; /* WDT2 */
  212. else if (cpu_is_omap2430())
  213. wdt_resources[0].start = 0x49016000; /* WDT2 */
  214. else if (cpu_is_omap343x())
  215. wdt_resources[0].start = 0x48314000; /* WDT2 */
  216. else if (cpu_is_omap44xx())
  217. wdt_resources[0].start = 0x4a314000;
  218. else
  219. return;
  220. wdt_resources[0].end = wdt_resources[0].start + 0x4f;
  221. (void) platform_device_register(&omap_wdt_device);
  222. }
  223. #else
  224. static inline void omap_init_wdt(void) {}
  225. #endif
  226. /*
  227. * This gets called after board-specific INIT_MACHINE, and initializes most
  228. * on-chip peripherals accessible on this board (except for few like USB):
  229. *
  230. * (a) Does any "standard config" pin muxing needed. Board-specific
  231. * code will have muxed GPIO pins and done "nonstandard" setup;
  232. * that code could live in the boot loader.
  233. * (b) Populating board-specific platform_data with the data drivers
  234. * rely on to handle wiring variations.
  235. * (c) Creating platform devices as meaningful on this board and
  236. * with this kernel configuration.
  237. *
  238. * Claiming GPIOs, and setting their direction and initial values, is the
  239. * responsibility of the device drivers. So is responding to probe().
  240. *
  241. * Board-specific knowlege like creating devices or pin setup is to be
  242. * kept out of drivers as much as possible. In particular, pin setup
  243. * may be handled by the boot loader, and drivers should expect it will
  244. * normally have been done by the time they're probed.
  245. */
  246. static int __init omap_init_devices(void)
  247. {
  248. /* please keep these calls, and their implementations above,
  249. * in alphabetical order so they're easier to sort through.
  250. */
  251. omap_init_rng();
  252. omap_init_mcpdm();
  253. omap_init_uwire();
  254. omap_init_wdt();
  255. return 0;
  256. }
  257. arch_initcall(omap_init_devices);