devices.c 7.5 KB

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