devices.c 8.3 KB

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