devices.c 12 KB

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