devices.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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()))
  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_RET(pdev);
  54. }
  55. omap_postcore_initcall(omap3_l3_init);
  56. static int __init omap4_l3_init(void)
  57. {
  58. int i;
  59. struct omap_hwmod *oh[3];
  60. struct platform_device *pdev;
  61. char oh_name[L3_MODULES_MAX_LEN];
  62. /* If dtb is there, the devices will be created dynamically */
  63. if (of_have_populated_dt())
  64. return -ENODEV;
  65. /*
  66. * To avoid code running on other OMAPs in
  67. * multi-omap builds
  68. */
  69. if (!cpu_is_omap44xx() && !soc_is_omap54xx())
  70. return -ENODEV;
  71. for (i = 0; i < L3_MODULES; i++) {
  72. snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
  73. oh[i] = omap_hwmod_lookup(oh_name);
  74. if (!(oh[i]))
  75. pr_err("could not look up %s\n", oh_name);
  76. }
  77. pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL, 0);
  78. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  79. return PTR_RET(pdev);
  80. }
  81. omap_postcore_initcall(omap4_l3_init);
  82. #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
  83. static struct resource omap2cam_resources[] = {
  84. {
  85. .start = OMAP24XX_CAMERA_BASE,
  86. .end = OMAP24XX_CAMERA_BASE + 0xfff,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. {
  90. .start = 24 + OMAP_INTC_START,
  91. .flags = IORESOURCE_IRQ,
  92. }
  93. };
  94. static struct platform_device omap2cam_device = {
  95. .name = "omap24xxcam",
  96. .id = -1,
  97. .num_resources = ARRAY_SIZE(omap2cam_resources),
  98. .resource = omap2cam_resources,
  99. };
  100. #endif
  101. #if defined(CONFIG_IOMMU_API)
  102. #include <linux/platform_data/iommu-omap.h>
  103. static struct resource omap3isp_resources[] = {
  104. {
  105. .start = OMAP3430_ISP_BASE,
  106. .end = OMAP3430_ISP_END,
  107. .flags = IORESOURCE_MEM,
  108. },
  109. {
  110. .start = OMAP3430_ISP_CCP2_BASE,
  111. .end = OMAP3430_ISP_CCP2_END,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. {
  115. .start = OMAP3430_ISP_CCDC_BASE,
  116. .end = OMAP3430_ISP_CCDC_END,
  117. .flags = IORESOURCE_MEM,
  118. },
  119. {
  120. .start = OMAP3430_ISP_HIST_BASE,
  121. .end = OMAP3430_ISP_HIST_END,
  122. .flags = IORESOURCE_MEM,
  123. },
  124. {
  125. .start = OMAP3430_ISP_H3A_BASE,
  126. .end = OMAP3430_ISP_H3A_END,
  127. .flags = IORESOURCE_MEM,
  128. },
  129. {
  130. .start = OMAP3430_ISP_PREV_BASE,
  131. .end = OMAP3430_ISP_PREV_END,
  132. .flags = IORESOURCE_MEM,
  133. },
  134. {
  135. .start = OMAP3430_ISP_RESZ_BASE,
  136. .end = OMAP3430_ISP_RESZ_END,
  137. .flags = IORESOURCE_MEM,
  138. },
  139. {
  140. .start = OMAP3430_ISP_SBL_BASE,
  141. .end = OMAP3430_ISP_SBL_END,
  142. .flags = IORESOURCE_MEM,
  143. },
  144. {
  145. .start = OMAP3430_ISP_CSI2A_REGS1_BASE,
  146. .end = OMAP3430_ISP_CSI2A_REGS1_END,
  147. .flags = IORESOURCE_MEM,
  148. },
  149. {
  150. .start = OMAP3430_ISP_CSIPHY2_BASE,
  151. .end = OMAP3430_ISP_CSIPHY2_END,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. {
  155. .start = OMAP3630_ISP_CSI2A_REGS2_BASE,
  156. .end = OMAP3630_ISP_CSI2A_REGS2_END,
  157. .flags = IORESOURCE_MEM,
  158. },
  159. {
  160. .start = OMAP3630_ISP_CSI2C_REGS1_BASE,
  161. .end = OMAP3630_ISP_CSI2C_REGS1_END,
  162. .flags = IORESOURCE_MEM,
  163. },
  164. {
  165. .start = OMAP3630_ISP_CSIPHY1_BASE,
  166. .end = OMAP3630_ISP_CSIPHY1_END,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. {
  170. .start = OMAP3630_ISP_CSI2C_REGS2_BASE,
  171. .end = OMAP3630_ISP_CSI2C_REGS2_END,
  172. .flags = IORESOURCE_MEM,
  173. },
  174. {
  175. .start = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE,
  176. .end = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE + 3,
  177. .flags = IORESOURCE_MEM,
  178. },
  179. {
  180. .start = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL,
  181. .end = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL + 3,
  182. .flags = IORESOURCE_MEM,
  183. },
  184. {
  185. .start = 24 + OMAP_INTC_START,
  186. .flags = IORESOURCE_IRQ,
  187. }
  188. };
  189. static struct platform_device omap3isp_device = {
  190. .name = "omap3isp",
  191. .id = -1,
  192. .num_resources = ARRAY_SIZE(omap3isp_resources),
  193. .resource = omap3isp_resources,
  194. };
  195. static struct omap_iommu_arch_data omap3_isp_iommu = {
  196. .name = "mmu_isp",
  197. };
  198. int omap3_init_camera(struct isp_platform_data *pdata)
  199. {
  200. if (of_have_populated_dt())
  201. omap3_isp_iommu.name = "480bd400.mmu";
  202. omap3isp_device.dev.platform_data = pdata;
  203. omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
  204. return platform_device_register(&omap3isp_device);
  205. }
  206. #else /* !CONFIG_IOMMU_API */
  207. int omap3_init_camera(struct isp_platform_data *pdata)
  208. {
  209. return 0;
  210. }
  211. #endif
  212. static inline void omap_init_camera(void)
  213. {
  214. #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
  215. if (cpu_is_omap24xx())
  216. platform_device_register(&omap2cam_device);
  217. #endif
  218. }
  219. #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
  220. static inline void __init omap_init_mbox(void)
  221. {
  222. struct omap_hwmod *oh;
  223. struct platform_device *pdev;
  224. struct omap_mbox_pdata *pdata;
  225. oh = omap_hwmod_lookup("mailbox");
  226. if (!oh) {
  227. pr_err("%s: unable to find hwmod\n", __func__);
  228. return;
  229. }
  230. if (!oh->dev_attr) {
  231. pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
  232. return;
  233. }
  234. pdata = (struct omap_mbox_pdata *)oh->dev_attr;
  235. pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
  236. WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
  237. __func__, PTR_ERR(pdev));
  238. }
  239. #else
  240. static inline void omap_init_mbox(void) { }
  241. #endif /* CONFIG_OMAP2PLUS_MBOX */
  242. static inline void omap_init_sti(void) {}
  243. #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
  244. static struct platform_device omap_pcm = {
  245. .name = "omap-pcm-audio",
  246. .id = -1,
  247. };
  248. static void omap_init_audio(void)
  249. {
  250. platform_device_register(&omap_pcm);
  251. }
  252. #else
  253. static inline void omap_init_audio(void) {}
  254. #endif
  255. #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
  256. #include <linux/platform_data/spi-omap2-mcspi.h>
  257. static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
  258. {
  259. struct platform_device *pdev;
  260. char *name = "omap2_mcspi";
  261. struct omap2_mcspi_platform_config *pdata;
  262. static int spi_num;
  263. struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
  264. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  265. if (!pdata) {
  266. pr_err("Memory allocation for McSPI device failed\n");
  267. return -ENOMEM;
  268. }
  269. pdata->num_cs = mcspi_attrib->num_chipselect;
  270. switch (oh->class->rev) {
  271. case OMAP2_MCSPI_REV:
  272. case OMAP3_MCSPI_REV:
  273. pdata->regs_offset = 0;
  274. break;
  275. case OMAP4_MCSPI_REV:
  276. pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
  277. break;
  278. default:
  279. pr_err("Invalid McSPI Revision value\n");
  280. kfree(pdata);
  281. return -EINVAL;
  282. }
  283. spi_num++;
  284. pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
  285. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
  286. name, oh->name);
  287. kfree(pdata);
  288. return 0;
  289. }
  290. static void omap_init_mcspi(void)
  291. {
  292. omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
  293. }
  294. #else
  295. static inline void omap_init_mcspi(void) {}
  296. #endif
  297. /**
  298. * omap_init_rng - bind the RNG hwmod to the RNG omap_device
  299. *
  300. * Bind the RNG hwmod to the RNG omap_device. No return value.
  301. */
  302. static void omap_init_rng(void)
  303. {
  304. struct omap_hwmod *oh;
  305. struct platform_device *pdev;
  306. oh = omap_hwmod_lookup("rng");
  307. if (!oh)
  308. return;
  309. pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
  310. WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
  311. }
  312. static void __init omap_init_sham(void)
  313. {
  314. struct omap_hwmod *oh;
  315. struct platform_device *pdev;
  316. oh = omap_hwmod_lookup("sham");
  317. if (!oh)
  318. return;
  319. pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
  320. WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
  321. }
  322. static void __init omap_init_aes(void)
  323. {
  324. struct omap_hwmod *oh;
  325. struct platform_device *pdev;
  326. oh = omap_hwmod_lookup("aes");
  327. if (!oh)
  328. return;
  329. pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
  330. WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
  331. }
  332. /*-------------------------------------------------------------------------*/
  333. #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
  334. defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
  335. #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
  336. static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
  337. };
  338. #else
  339. static struct resource omap_vout_resource[2] = {
  340. };
  341. #endif
  342. static struct platform_device omap_vout_device = {
  343. .name = "omap_vout",
  344. .num_resources = ARRAY_SIZE(omap_vout_resource),
  345. .resource = &omap_vout_resource[0],
  346. .id = -1,
  347. };
  348. int __init omap_init_vout(void)
  349. {
  350. return platform_device_register(&omap_vout_device);
  351. }
  352. #else
  353. int __init omap_init_vout(void) { return 0; }
  354. #endif
  355. /*-------------------------------------------------------------------------*/
  356. static int __init omap2_init_devices(void)
  357. {
  358. /* Enable dummy states for those platforms without pinctrl support */
  359. if (!of_have_populated_dt())
  360. pinctrl_provide_dummies();
  361. /*
  362. * please keep these calls, and their implementations above,
  363. * in alphabetical order so they're easier to sort through.
  364. */
  365. omap_init_audio();
  366. omap_init_camera();
  367. /* If dtb is there, the devices will be created dynamically */
  368. if (!of_have_populated_dt()) {
  369. omap_init_mbox();
  370. omap_init_mcspi();
  371. omap_init_sham();
  372. omap_init_aes();
  373. omap_init_rng();
  374. }
  375. omap_init_sti();
  376. return 0;
  377. }
  378. omap_arch_initcall(omap2_init_devices);