devices.c 9.0 KB

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