devices.c 13 KB

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