devices.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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_MCPDM) || \
  281. defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
  282. static void __init omap_init_mcpdm(void)
  283. {
  284. struct omap_hwmod *oh;
  285. struct platform_device *pdev;
  286. oh = omap_hwmod_lookup("mcpdm");
  287. if (!oh)
  288. return;
  289. pdev = omap_device_build("omap-mcpdm", -1, oh, NULL, 0);
  290. WARN(IS_ERR(pdev), "Can't build omap_device for omap-mcpdm.\n");
  291. }
  292. #else
  293. static inline void omap_init_mcpdm(void) {}
  294. #endif
  295. #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
  296. defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
  297. static void __init omap_init_dmic(void)
  298. {
  299. struct omap_hwmod *oh;
  300. struct platform_device *pdev;
  301. oh = omap_hwmod_lookup("dmic");
  302. if (!oh)
  303. return;
  304. pdev = omap_device_build("omap-dmic", -1, oh, NULL, 0);
  305. WARN(IS_ERR(pdev), "Can't build omap_device for omap-dmic.\n");
  306. }
  307. #else
  308. static inline void omap_init_dmic(void) {}
  309. #endif
  310. #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
  311. defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
  312. static struct platform_device omap_hdmi_audio = {
  313. .name = "omap-hdmi-audio",
  314. .id = -1,
  315. };
  316. static void __init omap_init_hdmi_audio(void)
  317. {
  318. struct omap_hwmod *oh;
  319. struct platform_device *pdev;
  320. oh = omap_hwmod_lookup("dss_hdmi");
  321. if (!oh)
  322. return;
  323. pdev = omap_device_build("omap-hdmi-audio-dai", -1, oh, NULL, 0);
  324. WARN(IS_ERR(pdev),
  325. "Can't build omap_device for omap-hdmi-audio-dai.\n");
  326. platform_device_register(&omap_hdmi_audio);
  327. }
  328. #else
  329. static inline void omap_init_hdmi_audio(void) {}
  330. #endif
  331. #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
  332. #include <linux/platform_data/spi-omap2-mcspi.h>
  333. static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
  334. {
  335. struct platform_device *pdev;
  336. char *name = "omap2_mcspi";
  337. struct omap2_mcspi_platform_config *pdata;
  338. static int spi_num;
  339. struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
  340. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  341. if (!pdata) {
  342. pr_err("Memory allocation for McSPI device failed\n");
  343. return -ENOMEM;
  344. }
  345. pdata->num_cs = mcspi_attrib->num_chipselect;
  346. switch (oh->class->rev) {
  347. case OMAP2_MCSPI_REV:
  348. case OMAP3_MCSPI_REV:
  349. pdata->regs_offset = 0;
  350. break;
  351. case OMAP4_MCSPI_REV:
  352. pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
  353. break;
  354. default:
  355. pr_err("Invalid McSPI Revision value\n");
  356. kfree(pdata);
  357. return -EINVAL;
  358. }
  359. spi_num++;
  360. pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
  361. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
  362. name, oh->name);
  363. kfree(pdata);
  364. return 0;
  365. }
  366. static void omap_init_mcspi(void)
  367. {
  368. omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
  369. }
  370. #else
  371. static inline void omap_init_mcspi(void) {}
  372. #endif
  373. /**
  374. * omap_init_rng - bind the RNG hwmod to the RNG omap_device
  375. *
  376. * Bind the RNG hwmod to the RNG omap_device. No return value.
  377. */
  378. static void omap_init_rng(void)
  379. {
  380. struct omap_hwmod *oh;
  381. struct platform_device *pdev;
  382. oh = omap_hwmod_lookup("rng");
  383. if (!oh)
  384. return;
  385. pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
  386. WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
  387. }
  388. static void __init omap_init_sham(void)
  389. {
  390. struct omap_hwmod *oh;
  391. struct platform_device *pdev;
  392. oh = omap_hwmod_lookup("sham");
  393. if (!oh)
  394. return;
  395. pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
  396. WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
  397. }
  398. static void __init omap_init_aes(void)
  399. {
  400. struct omap_hwmod *oh;
  401. struct platform_device *pdev;
  402. oh = omap_hwmod_lookup("aes");
  403. if (!oh)
  404. return;
  405. pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
  406. WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
  407. }
  408. /*-------------------------------------------------------------------------*/
  409. #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
  410. defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
  411. #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
  412. static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
  413. };
  414. #else
  415. static struct resource omap_vout_resource[2] = {
  416. };
  417. #endif
  418. static struct platform_device omap_vout_device = {
  419. .name = "omap_vout",
  420. .num_resources = ARRAY_SIZE(omap_vout_resource),
  421. .resource = &omap_vout_resource[0],
  422. .id = -1,
  423. };
  424. static void omap_init_vout(void)
  425. {
  426. if (platform_device_register(&omap_vout_device) < 0)
  427. printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
  428. }
  429. #else
  430. static inline void omap_init_vout(void) {}
  431. #endif
  432. #if IS_ENABLED(CONFIG_WL12XX)
  433. static struct wl12xx_platform_data wl12xx __initdata;
  434. void __init omap_init_wl12xx_of(void)
  435. {
  436. int ret;
  437. if (!of_have_populated_dt())
  438. return;
  439. if (of_machine_is_compatible("ti,omap4-sdp")) {
  440. wl12xx.board_ref_clock = WL12XX_REFCLOCK_26;
  441. wl12xx.board_tcxo_clock = WL12XX_TCXOCLOCK_26;
  442. wl12xx.irq = gpio_to_irq(53);
  443. } else if (of_machine_is_compatible("ti,omap4-panda")) {
  444. wl12xx.board_ref_clock = WL12XX_REFCLOCK_38;
  445. wl12xx.irq = gpio_to_irq(53);
  446. } else {
  447. return;
  448. }
  449. ret = wl12xx_set_platform_data(&wl12xx);
  450. if (ret) {
  451. pr_err("error setting wl12xx data: %d\n", ret);
  452. return;
  453. }
  454. }
  455. #else
  456. static inline void omap_init_wl12xx_of(void)
  457. {
  458. }
  459. #endif
  460. /*-------------------------------------------------------------------------*/
  461. static int __init omap2_init_devices(void)
  462. {
  463. /* Enable dummy states for those platforms without pinctrl support */
  464. if (!of_have_populated_dt())
  465. pinctrl_provide_dummies();
  466. /*
  467. * please keep these calls, and their implementations above,
  468. * in alphabetical order so they're easier to sort through.
  469. */
  470. omap_init_audio();
  471. omap_init_camera();
  472. omap_init_hdmi_audio();
  473. omap_init_mbox();
  474. /* If dtb is there, the devices will be created dynamically */
  475. if (!of_have_populated_dt()) {
  476. omap_init_dmic();
  477. omap_init_mcpdm();
  478. omap_init_mcspi();
  479. omap_init_sham();
  480. omap_init_aes();
  481. } else {
  482. /* These can be removed when bindings are done */
  483. omap_init_wl12xx_of();
  484. }
  485. omap_init_sti();
  486. omap_init_rng();
  487. omap_init_vout();
  488. return 0;
  489. }
  490. omap_arch_initcall(omap2_init_devices);