devices.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * linux/arch/arm/mach-omap2/devices.c
  3. *
  4. * OMAP2 platform device setup/initialization
  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/gpio.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/clk.h>
  17. #include <linux/err.h>
  18. #include <linux/slab.h>
  19. #include <linux/of.h>
  20. #include <linux/pinctrl/machine.h>
  21. #include <linux/platform_data/mailbox-omap.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/map.h>
  24. #include <linux/omap-dma.h>
  25. #include "iomap.h"
  26. #include "omap_hwmod.h"
  27. #include "omap_device.h"
  28. #include "soc.h"
  29. #include "common.h"
  30. #include "mux.h"
  31. #include "control.h"
  32. #include "devices.h"
  33. #include "display.h"
  34. #define L3_MODULES_MAX_LEN 12
  35. #define L3_MODULES 3
  36. static int __init omap3_l3_init(void)
  37. {
  38. struct omap_hwmod *oh;
  39. struct platform_device *pdev;
  40. char oh_name[L3_MODULES_MAX_LEN];
  41. /*
  42. * To avoid code running on other OMAPs in
  43. * multi-omap builds
  44. */
  45. if (!(cpu_is_omap34xx()) || of_have_populated_dt())
  46. return -ENODEV;
  47. snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
  48. oh = omap_hwmod_lookup(oh_name);
  49. if (!oh)
  50. pr_err("could not look up %s\n", oh_name);
  51. pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
  52. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  53. return PTR_ERR_OR_ZERO(pdev);
  54. }
  55. omap_postcore_initcall(omap3_l3_init);
  56. #if defined(CONFIG_IOMMU_API)
  57. #include <linux/platform_data/iommu-omap.h>
  58. static struct resource omap3isp_resources[] = {
  59. {
  60. .start = OMAP3430_ISP_BASE,
  61. .end = OMAP3430_ISP_BASE + 0x12fc,
  62. .flags = IORESOURCE_MEM,
  63. },
  64. {
  65. .start = OMAP3430_ISP_BASE2,
  66. .end = OMAP3430_ISP_BASE2 + 0x0600,
  67. .flags = IORESOURCE_MEM,
  68. },
  69. {
  70. .start = 24 + OMAP_INTC_START,
  71. .flags = IORESOURCE_IRQ,
  72. }
  73. };
  74. static struct platform_device omap3isp_device = {
  75. .name = "omap3isp",
  76. .id = -1,
  77. .num_resources = ARRAY_SIZE(omap3isp_resources),
  78. .resource = omap3isp_resources,
  79. };
  80. static struct omap_iommu_arch_data omap3_isp_iommu = {
  81. .name = "mmu_isp",
  82. };
  83. int omap3_init_camera(struct isp_platform_data *pdata)
  84. {
  85. if (of_have_populated_dt())
  86. omap3_isp_iommu.name = "480bd400.mmu";
  87. omap3isp_device.dev.platform_data = pdata;
  88. omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
  89. return platform_device_register(&omap3isp_device);
  90. }
  91. #else /* !CONFIG_IOMMU_API */
  92. int omap3_init_camera(struct isp_platform_data *pdata)
  93. {
  94. return 0;
  95. }
  96. #endif
  97. #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
  98. static inline void __init omap_init_mbox(void)
  99. {
  100. struct omap_hwmod *oh;
  101. struct platform_device *pdev;
  102. struct omap_mbox_pdata *pdata;
  103. oh = omap_hwmod_lookup("mailbox");
  104. if (!oh) {
  105. pr_err("%s: unable to find hwmod\n", __func__);
  106. return;
  107. }
  108. if (!oh->dev_attr) {
  109. pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
  110. return;
  111. }
  112. pdata = (struct omap_mbox_pdata *)oh->dev_attr;
  113. pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
  114. WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
  115. __func__, PTR_ERR(pdev));
  116. }
  117. #else
  118. static inline void omap_init_mbox(void) { }
  119. #endif /* CONFIG_OMAP2PLUS_MBOX */
  120. static inline void omap_init_sti(void) {}
  121. #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
  122. static struct platform_device omap_pcm = {
  123. .name = "omap-pcm-audio",
  124. .id = -1,
  125. };
  126. static void omap_init_audio(void)
  127. {
  128. platform_device_register(&omap_pcm);
  129. }
  130. #else
  131. static inline void omap_init_audio(void) {}
  132. #endif
  133. #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
  134. #include <linux/platform_data/spi-omap2-mcspi.h>
  135. static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
  136. {
  137. struct platform_device *pdev;
  138. char *name = "omap2_mcspi";
  139. struct omap2_mcspi_platform_config *pdata;
  140. static int spi_num;
  141. struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
  142. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  143. if (!pdata) {
  144. pr_err("Memory allocation for McSPI device failed\n");
  145. return -ENOMEM;
  146. }
  147. pdata->num_cs = mcspi_attrib->num_chipselect;
  148. switch (oh->class->rev) {
  149. case OMAP2_MCSPI_REV:
  150. case OMAP3_MCSPI_REV:
  151. pdata->regs_offset = 0;
  152. break;
  153. case OMAP4_MCSPI_REV:
  154. pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
  155. break;
  156. default:
  157. pr_err("Invalid McSPI Revision value\n");
  158. kfree(pdata);
  159. return -EINVAL;
  160. }
  161. spi_num++;
  162. pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
  163. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
  164. name, oh->name);
  165. kfree(pdata);
  166. return 0;
  167. }
  168. static void omap_init_mcspi(void)
  169. {
  170. omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
  171. }
  172. #else
  173. static inline void omap_init_mcspi(void) {}
  174. #endif
  175. /**
  176. * omap_init_rng - bind the RNG hwmod to the RNG omap_device
  177. *
  178. * Bind the RNG hwmod to the RNG omap_device. No return value.
  179. */
  180. static void omap_init_rng(void)
  181. {
  182. struct omap_hwmod *oh;
  183. struct platform_device *pdev;
  184. oh = omap_hwmod_lookup("rng");
  185. if (!oh)
  186. return;
  187. pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
  188. WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
  189. }
  190. static void __init omap_init_sham(void)
  191. {
  192. struct omap_hwmod *oh;
  193. struct platform_device *pdev;
  194. oh = omap_hwmod_lookup("sham");
  195. if (!oh)
  196. return;
  197. pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
  198. WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
  199. }
  200. static void __init omap_init_aes(void)
  201. {
  202. struct omap_hwmod *oh;
  203. struct platform_device *pdev;
  204. oh = omap_hwmod_lookup("aes");
  205. if (!oh)
  206. return;
  207. pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
  208. WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
  209. }
  210. /*-------------------------------------------------------------------------*/
  211. #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
  212. defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
  213. #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
  214. static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
  215. };
  216. #else
  217. static struct resource omap_vout_resource[2] = {
  218. };
  219. #endif
  220. static struct platform_device omap_vout_device = {
  221. .name = "omap_vout",
  222. .num_resources = ARRAY_SIZE(omap_vout_resource),
  223. .resource = &omap_vout_resource[0],
  224. .id = -1,
  225. };
  226. int __init omap_init_vout(void)
  227. {
  228. return platform_device_register(&omap_vout_device);
  229. }
  230. #else
  231. int __init omap_init_vout(void) { return 0; }
  232. #endif
  233. /*-------------------------------------------------------------------------*/
  234. static int __init omap2_init_devices(void)
  235. {
  236. /* Enable dummy states for those platforms without pinctrl support */
  237. if (!of_have_populated_dt())
  238. pinctrl_provide_dummies();
  239. /*
  240. * please keep these calls, and their implementations above,
  241. * in alphabetical order so they're easier to sort through.
  242. */
  243. omap_init_audio();
  244. /* If dtb is there, the devices will be created dynamically */
  245. if (!of_have_populated_dt()) {
  246. omap_init_mbox();
  247. omap_init_mcspi();
  248. omap_init_sham();
  249. omap_init_aes();
  250. omap_init_rng();
  251. }
  252. omap_init_sti();
  253. return 0;
  254. }
  255. omap_arch_initcall(omap2_init_devices);
  256. static int __init omap_gpmc_init(void)
  257. {
  258. struct omap_hwmod *oh;
  259. struct platform_device *pdev;
  260. char *oh_name = "gpmc";
  261. /*
  262. * if the board boots up with a populated DT, do not
  263. * manually add the device from this initcall
  264. */
  265. if (of_have_populated_dt())
  266. return -ENODEV;
  267. oh = omap_hwmod_lookup(oh_name);
  268. if (!oh) {
  269. pr_err("Could not look up %s\n", oh_name);
  270. return -ENODEV;
  271. }
  272. pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
  273. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  274. return PTR_ERR_OR_ZERO(pdev);
  275. }
  276. omap_postcore_initcall(omap_gpmc_init);