devices.c 11 KB

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