devices.c 6.7 KB

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