devices.c 6.7 KB

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