2 * linux/arch/arm/mach-omap2/devices.c
4 * OMAP2 platform device setup/initialization
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.
11 #include <linux/gpio.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/slab.h>
20 #include <linux/pinctrl/machine.h>
21 #include <linux/platform_data/omap4-keypad.h>
22 #include <linux/platform_data/omap_ocp2scp.h>
23 #include <linux/usb/omap_control_usb.h>
25 #include <asm/mach-types.h>
26 #include <asm/mach/map.h>
28 #include <linux/omap-dma.h>
31 #include "omap_hwmod.h"
32 #include "omap_device.h"
33 #include "omap4-keypad.h"
42 #define L3_MODULES_MAX_LEN 12
45 static int __init omap3_l3_init(void)
47 struct omap_hwmod *oh;
48 struct platform_device *pdev;
49 char oh_name[L3_MODULES_MAX_LEN];
52 * To avoid code running on other OMAPs in
55 if (!(cpu_is_omap34xx()))
58 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
60 oh = omap_hwmod_lookup(oh_name);
63 pr_err("could not look up %s\n", oh_name);
65 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0,
68 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
70 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
72 omap_postcore_initcall(omap3_l3_init);
74 static int __init omap4_l3_init(void)
77 struct omap_hwmod *oh[3];
78 struct platform_device *pdev;
79 char oh_name[L3_MODULES_MAX_LEN];
81 /* If dtb is there, the devices will be created dynamically */
82 if (of_have_populated_dt())
86 * To avoid code running on other OMAPs in
89 if (!cpu_is_omap44xx() && !soc_is_omap54xx())
92 for (i = 0; i < L3_MODULES; i++) {
93 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
95 oh[i] = omap_hwmod_lookup(oh_name);
97 pr_err("could not look up %s\n", oh_name);
100 pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL,
103 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
105 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
107 omap_postcore_initcall(omap4_l3_init);
109 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
111 static struct resource omap2cam_resources[] = {
113 .start = OMAP24XX_CAMERA_BASE,
114 .end = OMAP24XX_CAMERA_BASE + 0xfff,
115 .flags = IORESOURCE_MEM,
118 .start = 24 + OMAP_INTC_START,
119 .flags = IORESOURCE_IRQ,
123 static struct platform_device omap2cam_device = {
124 .name = "omap24xxcam",
126 .num_resources = ARRAY_SIZE(omap2cam_resources),
127 .resource = omap2cam_resources,
131 #if defined(CONFIG_IOMMU_API)
133 #include <linux/platform_data/iommu-omap.h>
135 static struct resource omap3isp_resources[] = {
137 .start = OMAP3430_ISP_BASE,
138 .end = OMAP3430_ISP_END,
139 .flags = IORESOURCE_MEM,
142 .start = OMAP3430_ISP_CCP2_BASE,
143 .end = OMAP3430_ISP_CCP2_END,
144 .flags = IORESOURCE_MEM,
147 .start = OMAP3430_ISP_CCDC_BASE,
148 .end = OMAP3430_ISP_CCDC_END,
149 .flags = IORESOURCE_MEM,
152 .start = OMAP3430_ISP_HIST_BASE,
153 .end = OMAP3430_ISP_HIST_END,
154 .flags = IORESOURCE_MEM,
157 .start = OMAP3430_ISP_H3A_BASE,
158 .end = OMAP3430_ISP_H3A_END,
159 .flags = IORESOURCE_MEM,
162 .start = OMAP3430_ISP_PREV_BASE,
163 .end = OMAP3430_ISP_PREV_END,
164 .flags = IORESOURCE_MEM,
167 .start = OMAP3430_ISP_RESZ_BASE,
168 .end = OMAP3430_ISP_RESZ_END,
169 .flags = IORESOURCE_MEM,
172 .start = OMAP3430_ISP_SBL_BASE,
173 .end = OMAP3430_ISP_SBL_END,
174 .flags = IORESOURCE_MEM,
177 .start = OMAP3430_ISP_CSI2A_REGS1_BASE,
178 .end = OMAP3430_ISP_CSI2A_REGS1_END,
179 .flags = IORESOURCE_MEM,
182 .start = OMAP3430_ISP_CSIPHY2_BASE,
183 .end = OMAP3430_ISP_CSIPHY2_END,
184 .flags = IORESOURCE_MEM,
187 .start = OMAP3630_ISP_CSI2A_REGS2_BASE,
188 .end = OMAP3630_ISP_CSI2A_REGS2_END,
189 .flags = IORESOURCE_MEM,
192 .start = OMAP3630_ISP_CSI2C_REGS1_BASE,
193 .end = OMAP3630_ISP_CSI2C_REGS1_END,
194 .flags = IORESOURCE_MEM,
197 .start = OMAP3630_ISP_CSIPHY1_BASE,
198 .end = OMAP3630_ISP_CSIPHY1_END,
199 .flags = IORESOURCE_MEM,
202 .start = OMAP3630_ISP_CSI2C_REGS2_BASE,
203 .end = OMAP3630_ISP_CSI2C_REGS2_END,
204 .flags = IORESOURCE_MEM,
207 .start = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE,
208 .end = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE + 3,
209 .flags = IORESOURCE_MEM,
212 .start = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL,
213 .end = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL + 3,
214 .flags = IORESOURCE_MEM,
217 .start = 24 + OMAP_INTC_START,
218 .flags = IORESOURCE_IRQ,
222 static struct platform_device omap3isp_device = {
225 .num_resources = ARRAY_SIZE(omap3isp_resources),
226 .resource = omap3isp_resources,
229 static struct omap_iommu_arch_data omap3_isp_iommu = {
233 int omap3_init_camera(struct isp_platform_data *pdata)
235 omap3isp_device.dev.platform_data = pdata;
236 omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
238 return platform_device_register(&omap3isp_device);
241 #else /* !CONFIG_IOMMU_API */
243 int omap3_init_camera(struct isp_platform_data *pdata)
250 static inline void omap_init_camera(void)
252 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
253 if (cpu_is_omap24xx())
254 platform_device_register(&omap2cam_device);
258 #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
259 static struct omap_control_usb_platform_data omap4_control_usb_pdata = {
263 struct resource omap4_control_usb_res[] = {
265 .name = "control_dev_conf",
268 .flags = IORESOURCE_MEM,
271 .name = "otghs_control",
274 .flags = IORESOURCE_MEM,
278 static struct platform_device omap4_control_usb = {
279 .name = "omap-control-usb",
282 .platform_data = &omap4_control_usb_pdata,
285 .resource = omap4_control_usb_res,
288 static inline void __init omap_init_control_usb(void)
290 if (!cpu_is_omap44xx())
293 if (platform_device_register(&omap4_control_usb))
294 pr_err("Error registering omap_control_usb device\n");
298 static inline void omap_init_control_usb(void) { }
299 #endif /* CONFIG_OMAP_CONTROL_USB */
301 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
302 *sdp4430_keypad_data, struct omap_board_data *bdata)
304 struct platform_device *pdev;
305 struct omap_hwmod *oh;
306 struct omap4_keypad_platform_data *keypad_data;
307 unsigned int id = -1;
308 char *oh_name = "kbd";
309 char *name = "omap4-keypad";
311 oh = omap_hwmod_lookup(oh_name);
313 pr_err("Could not look up %s\n", oh_name);
317 keypad_data = sdp4430_keypad_data;
319 pdev = omap_device_build(name, id, oh, keypad_data,
320 sizeof(struct omap4_keypad_platform_data), NULL, 0, 0);
323 WARN(1, "Can't build omap_device for %s:%s.\n",
325 return PTR_ERR(pdev);
327 oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
332 #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
333 static inline void __init omap_init_mbox(void)
335 struct omap_hwmod *oh;
336 struct platform_device *pdev;
338 oh = omap_hwmod_lookup("mailbox");
340 pr_err("%s: unable to find hwmod\n", __func__);
344 pdev = omap_device_build("omap-mailbox", -1, oh, NULL, 0, NULL, 0, 0);
345 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
346 __func__, PTR_ERR(pdev));
349 static inline void omap_init_mbox(void) { }
350 #endif /* CONFIG_OMAP_MBOX_FWK */
352 static inline void omap_init_sti(void) {}
354 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
356 static struct platform_device omap_pcm = {
357 .name = "omap-pcm-audio",
361 static void omap_init_audio(void)
363 platform_device_register(&omap_pcm);
367 static inline void omap_init_audio(void) {}
370 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
371 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
373 static void __init omap_init_mcpdm(void)
375 struct omap_hwmod *oh;
376 struct platform_device *pdev;
378 oh = omap_hwmod_lookup("mcpdm");
380 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
384 pdev = omap_device_build("omap-mcpdm", -1, oh, NULL, 0, NULL, 0, 0);
385 WARN(IS_ERR(pdev), "Can't build omap_device for omap-mcpdm.\n");
388 static inline void omap_init_mcpdm(void) {}
391 #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
392 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
394 static void __init omap_init_dmic(void)
396 struct omap_hwmod *oh;
397 struct platform_device *pdev;
399 oh = omap_hwmod_lookup("dmic");
401 pr_err("Could not look up dmic hw_mod\n");
405 pdev = omap_device_build("omap-dmic", -1, oh, NULL, 0, NULL, 0, 0);
406 WARN(IS_ERR(pdev), "Can't build omap_device for omap-dmic.\n");
409 static inline void omap_init_dmic(void) {}
412 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
413 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
415 static struct platform_device omap_hdmi_audio = {
416 .name = "omap-hdmi-audio",
420 static void __init omap_init_hdmi_audio(void)
422 struct omap_hwmod *oh;
423 struct platform_device *pdev;
425 oh = omap_hwmod_lookup("dss_hdmi");
427 printk(KERN_ERR "Could not look up dss_hdmi hw_mod\n");
431 pdev = omap_device_build("omap-hdmi-audio-dai",
432 -1, oh, NULL, 0, NULL, 0, 0);
434 "Can't build omap_device for omap-hdmi-audio-dai.\n");
436 platform_device_register(&omap_hdmi_audio);
439 static inline void omap_init_hdmi_audio(void) {}
442 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
444 #include <linux/platform_data/spi-omap2-mcspi.h>
446 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
448 struct platform_device *pdev;
449 char *name = "omap2_mcspi";
450 struct omap2_mcspi_platform_config *pdata;
452 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
454 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
456 pr_err("Memory allocation for McSPI device failed\n");
460 pdata->num_cs = mcspi_attrib->num_chipselect;
461 switch (oh->class->rev) {
462 case OMAP2_MCSPI_REV:
463 case OMAP3_MCSPI_REV:
464 pdata->regs_offset = 0;
466 case OMAP4_MCSPI_REV:
467 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
470 pr_err("Invalid McSPI Revision value\n");
476 pdev = omap_device_build(name, spi_num, oh, pdata,
477 sizeof(*pdata), NULL, 0, 0);
478 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
484 static void omap_init_mcspi(void)
486 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
490 static inline void omap_init_mcspi(void) {}
494 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
496 * Bind the RNG hwmod to the RNG omap_device. No return value.
498 static void omap_init_rng(void)
500 struct omap_hwmod *oh;
501 struct platform_device *pdev;
503 oh = omap_hwmod_lookup("rng");
507 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0, NULL, 0, 0);
508 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
511 #if defined(CONFIG_CRYPTO_DEV_OMAP_SHAM) || defined(CONFIG_CRYPTO_DEV_OMAP_SHAM_MODULE)
513 #ifdef CONFIG_ARCH_OMAP2
514 static struct resource omap2_sham_resources[] = {
516 .start = OMAP24XX_SEC_SHA1MD5_BASE,
517 .end = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
518 .flags = IORESOURCE_MEM,
521 .start = 51 + OMAP_INTC_START,
522 .flags = IORESOURCE_IRQ,
525 static int omap2_sham_resources_sz = ARRAY_SIZE(omap2_sham_resources);
527 #define omap2_sham_resources NULL
528 #define omap2_sham_resources_sz 0
531 #ifdef CONFIG_ARCH_OMAP3
532 static struct resource omap3_sham_resources[] = {
534 .start = OMAP34XX_SEC_SHA1MD5_BASE,
535 .end = OMAP34XX_SEC_SHA1MD5_BASE + 0x64,
536 .flags = IORESOURCE_MEM,
539 .start = 49 + OMAP_INTC_START,
540 .flags = IORESOURCE_IRQ,
543 .start = OMAP34XX_DMA_SHA1MD5_RX,
544 .flags = IORESOURCE_DMA,
547 static int omap3_sham_resources_sz = ARRAY_SIZE(omap3_sham_resources);
549 #define omap3_sham_resources NULL
550 #define omap3_sham_resources_sz 0
553 static struct platform_device sham_device = {
558 static void omap_init_sham(void)
560 if (cpu_is_omap24xx()) {
561 sham_device.resource = omap2_sham_resources;
562 sham_device.num_resources = omap2_sham_resources_sz;
563 } else if (cpu_is_omap34xx()) {
564 sham_device.resource = omap3_sham_resources;
565 sham_device.num_resources = omap3_sham_resources_sz;
567 pr_err("%s: platform not supported\n", __func__);
570 platform_device_register(&sham_device);
573 static inline void omap_init_sham(void) { }
576 #if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)
578 #ifdef CONFIG_ARCH_OMAP2
579 static struct resource omap2_aes_resources[] = {
581 .start = OMAP24XX_SEC_AES_BASE,
582 .end = OMAP24XX_SEC_AES_BASE + 0x4C,
583 .flags = IORESOURCE_MEM,
586 .start = OMAP24XX_DMA_AES_TX,
587 .flags = IORESOURCE_DMA,
590 .start = OMAP24XX_DMA_AES_RX,
591 .flags = IORESOURCE_DMA,
594 static int omap2_aes_resources_sz = ARRAY_SIZE(omap2_aes_resources);
596 #define omap2_aes_resources NULL
597 #define omap2_aes_resources_sz 0
600 #ifdef CONFIG_ARCH_OMAP3
601 static struct resource omap3_aes_resources[] = {
603 .start = OMAP34XX_SEC_AES_BASE,
604 .end = OMAP34XX_SEC_AES_BASE + 0x4C,
605 .flags = IORESOURCE_MEM,
608 .start = OMAP34XX_DMA_AES2_TX,
609 .flags = IORESOURCE_DMA,
612 .start = OMAP34XX_DMA_AES2_RX,
613 .flags = IORESOURCE_DMA,
616 static int omap3_aes_resources_sz = ARRAY_SIZE(omap3_aes_resources);
618 #define omap3_aes_resources NULL
619 #define omap3_aes_resources_sz 0
622 static struct platform_device aes_device = {
627 static void omap_init_aes(void)
629 if (cpu_is_omap24xx()) {
630 aes_device.resource = omap2_aes_resources;
631 aes_device.num_resources = omap2_aes_resources_sz;
632 } else if (cpu_is_omap34xx()) {
633 aes_device.resource = omap3_aes_resources;
634 aes_device.num_resources = omap3_aes_resources_sz;
636 pr_err("%s: platform not supported\n", __func__);
639 platform_device_register(&aes_device);
643 static inline void omap_init_aes(void) { }
646 /*-------------------------------------------------------------------------*/
648 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
649 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
650 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
651 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
654 static struct resource omap_vout_resource[2] = {
658 static struct platform_device omap_vout_device = {
660 .num_resources = ARRAY_SIZE(omap_vout_resource),
661 .resource = &omap_vout_resource[0],
664 static void omap_init_vout(void)
666 if (platform_device_register(&omap_vout_device) < 0)
667 printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
670 static inline void omap_init_vout(void) {}
673 #if defined(CONFIG_OMAP_OCP2SCP) || defined(CONFIG_OMAP_OCP2SCP_MODULE)
674 static int count_ocp2scp_devices(struct omap_ocp2scp_dev *ocp2scp_dev)
678 while (ocp2scp_dev->drv_name != NULL) {
686 static void __init omap_init_ocp2scp(void)
688 struct omap_hwmod *oh;
689 struct platform_device *pdev;
690 int bus_id = -1, dev_cnt = 0, i;
691 struct omap_ocp2scp_dev *ocp2scp_dev;
692 const char *oh_name, *name;
693 struct omap_ocp2scp_platform_data *pdata;
695 if (!cpu_is_omap44xx())
698 oh_name = "ocp2scp_usb_phy";
699 name = "omap-ocp2scp";
701 oh = omap_hwmod_lookup(oh_name);
703 pr_err("%s: could not find omap_hwmod for %s\n", __func__,
708 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
710 pr_err("%s: No memory for ocp2scp pdata\n", __func__);
714 ocp2scp_dev = oh->dev_attr;
715 dev_cnt = count_ocp2scp_devices(ocp2scp_dev);
718 pr_err("%s: No devices connected to ocp2scp\n", __func__);
723 pdata->devices = kzalloc(sizeof(struct omap_ocp2scp_dev *)
724 * dev_cnt, GFP_KERNEL);
725 if (!pdata->devices) {
726 pr_err("%s: No memory for ocp2scp pdata devices\n", __func__);
731 for (i = 0; i < dev_cnt; i++, ocp2scp_dev++)
732 pdata->devices[i] = ocp2scp_dev;
734 pdata->dev_cnt = dev_cnt;
736 pdev = omap_device_build(name, bus_id, oh, pdata, sizeof(*pdata), NULL,
739 pr_err("Could not build omap_device for %s %s\n",
741 kfree(pdata->devices);
747 static inline void omap_init_ocp2scp(void) { }
750 /*-------------------------------------------------------------------------*/
752 static int __init omap2_init_devices(void)
754 /* Enable dummy states for those platforms without pinctrl support */
755 if (!of_have_populated_dt())
756 pinctrl_provide_dummies();
759 * please keep these calls, and their implementations above,
760 * in alphabetical order so they're easier to sort through.
764 omap_init_hdmi_audio();
766 /* If dtb is there, the devices will be created dynamically */
767 if (!of_have_populated_dt()) {
768 omap_init_control_usb();
782 omap_arch_initcall(omap2_init_devices);