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