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);
67 WARN(IS_ERR(pdev
), "could not build omap_device for %s\n", oh_name
);
69 return IS_ERR(pdev
) ? PTR_ERR(pdev
) : 0;
71 omap_postcore_initcall(omap3_l3_init
);
73 static int __init
omap4_l3_init(void)
76 struct omap_hwmod
*oh
[3];
77 struct platform_device
*pdev
;
78 char oh_name
[L3_MODULES_MAX_LEN
];
80 /* If dtb is there, the devices will be created dynamically */
81 if (of_have_populated_dt())
85 * To avoid code running on other OMAPs in
88 if (!cpu_is_omap44xx() && !soc_is_omap54xx())
91 for (i
= 0; i
< L3_MODULES
; i
++) {
92 snprintf(oh_name
, L3_MODULES_MAX_LEN
, "l3_main_%d", i
+1);
94 oh
[i
] = omap_hwmod_lookup(oh_name
);
96 pr_err("could not look up %s\n", oh_name
);
99 pdev
= omap_device_build_ss("omap_l3_noc", 0, oh
, 3, NULL
, 0);
101 WARN(IS_ERR(pdev
), "could not build omap_device for %s\n", oh_name
);
103 return IS_ERR(pdev
) ? PTR_ERR(pdev
) : 0;
105 omap_postcore_initcall(omap4_l3_init
);
107 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
109 static struct resource omap2cam_resources
[] = {
111 .start
= OMAP24XX_CAMERA_BASE
,
112 .end
= OMAP24XX_CAMERA_BASE
+ 0xfff,
113 .flags
= IORESOURCE_MEM
,
116 .start
= 24 + OMAP_INTC_START
,
117 .flags
= IORESOURCE_IRQ
,
121 static struct platform_device omap2cam_device
= {
122 .name
= "omap24xxcam",
124 .num_resources
= ARRAY_SIZE(omap2cam_resources
),
125 .resource
= omap2cam_resources
,
129 #if defined(CONFIG_IOMMU_API)
131 #include <linux/platform_data/iommu-omap.h>
133 static struct resource omap3isp_resources
[] = {
135 .start
= OMAP3430_ISP_BASE
,
136 .end
= OMAP3430_ISP_END
,
137 .flags
= IORESOURCE_MEM
,
140 .start
= OMAP3430_ISP_CCP2_BASE
,
141 .end
= OMAP3430_ISP_CCP2_END
,
142 .flags
= IORESOURCE_MEM
,
145 .start
= OMAP3430_ISP_CCDC_BASE
,
146 .end
= OMAP3430_ISP_CCDC_END
,
147 .flags
= IORESOURCE_MEM
,
150 .start
= OMAP3430_ISP_HIST_BASE
,
151 .end
= OMAP3430_ISP_HIST_END
,
152 .flags
= IORESOURCE_MEM
,
155 .start
= OMAP3430_ISP_H3A_BASE
,
156 .end
= OMAP3430_ISP_H3A_END
,
157 .flags
= IORESOURCE_MEM
,
160 .start
= OMAP3430_ISP_PREV_BASE
,
161 .end
= OMAP3430_ISP_PREV_END
,
162 .flags
= IORESOURCE_MEM
,
165 .start
= OMAP3430_ISP_RESZ_BASE
,
166 .end
= OMAP3430_ISP_RESZ_END
,
167 .flags
= IORESOURCE_MEM
,
170 .start
= OMAP3430_ISP_SBL_BASE
,
171 .end
= OMAP3430_ISP_SBL_END
,
172 .flags
= IORESOURCE_MEM
,
175 .start
= OMAP3430_ISP_CSI2A_REGS1_BASE
,
176 .end
= OMAP3430_ISP_CSI2A_REGS1_END
,
177 .flags
= IORESOURCE_MEM
,
180 .start
= OMAP3430_ISP_CSIPHY2_BASE
,
181 .end
= OMAP3430_ISP_CSIPHY2_END
,
182 .flags
= IORESOURCE_MEM
,
185 .start
= OMAP3630_ISP_CSI2A_REGS2_BASE
,
186 .end
= OMAP3630_ISP_CSI2A_REGS2_END
,
187 .flags
= IORESOURCE_MEM
,
190 .start
= OMAP3630_ISP_CSI2C_REGS1_BASE
,
191 .end
= OMAP3630_ISP_CSI2C_REGS1_END
,
192 .flags
= IORESOURCE_MEM
,
195 .start
= OMAP3630_ISP_CSIPHY1_BASE
,
196 .end
= OMAP3630_ISP_CSIPHY1_END
,
197 .flags
= IORESOURCE_MEM
,
200 .start
= OMAP3630_ISP_CSI2C_REGS2_BASE
,
201 .end
= OMAP3630_ISP_CSI2C_REGS2_END
,
202 .flags
= IORESOURCE_MEM
,
205 .start
= OMAP343X_CTRL_BASE
+ OMAP343X_CONTROL_CSIRXFE
,
206 .end
= OMAP343X_CTRL_BASE
+ OMAP343X_CONTROL_CSIRXFE
+ 3,
207 .flags
= IORESOURCE_MEM
,
210 .start
= OMAP343X_CTRL_BASE
+ OMAP3630_CONTROL_CAMERA_PHY_CTRL
,
211 .end
= OMAP343X_CTRL_BASE
+ OMAP3630_CONTROL_CAMERA_PHY_CTRL
+ 3,
212 .flags
= IORESOURCE_MEM
,
215 .start
= 24 + OMAP_INTC_START
,
216 .flags
= IORESOURCE_IRQ
,
220 static struct platform_device omap3isp_device
= {
223 .num_resources
= ARRAY_SIZE(omap3isp_resources
),
224 .resource
= omap3isp_resources
,
227 static struct omap_iommu_arch_data omap3_isp_iommu
= {
231 int omap3_init_camera(struct isp_platform_data
*pdata
)
233 omap3isp_device
.dev
.platform_data
= pdata
;
234 omap3isp_device
.dev
.archdata
.iommu
= &omap3_isp_iommu
;
236 return platform_device_register(&omap3isp_device
);
239 #else /* !CONFIG_IOMMU_API */
241 int omap3_init_camera(struct isp_platform_data
*pdata
)
248 static inline void omap_init_camera(void)
250 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
251 if (cpu_is_omap24xx())
252 platform_device_register(&omap2cam_device
);
256 #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
257 static struct omap_control_usb_platform_data omap4_control_usb_pdata
= {
261 struct resource omap4_control_usb_res
[] = {
263 .name
= "control_dev_conf",
266 .flags
= IORESOURCE_MEM
,
269 .name
= "otghs_control",
272 .flags
= IORESOURCE_MEM
,
276 static struct platform_device omap4_control_usb
= {
277 .name
= "omap-control-usb",
280 .platform_data
= &omap4_control_usb_pdata
,
283 .resource
= omap4_control_usb_res
,
286 static inline void __init
omap_init_control_usb(void)
288 if (!cpu_is_omap44xx())
291 if (platform_device_register(&omap4_control_usb
))
292 pr_err("Error registering omap_control_usb device\n");
296 static inline void omap_init_control_usb(void) { }
297 #endif /* CONFIG_OMAP_CONTROL_USB */
299 int __init
omap4_keyboard_init(struct omap4_keypad_platform_data
300 *sdp4430_keypad_data
, struct omap_board_data
*bdata
)
302 struct platform_device
*pdev
;
303 struct omap_hwmod
*oh
;
304 struct omap4_keypad_platform_data
*keypad_data
;
305 unsigned int id
= -1;
306 char *oh_name
= "kbd";
307 char *name
= "omap4-keypad";
309 oh
= omap_hwmod_lookup(oh_name
);
311 pr_err("Could not look up %s\n", oh_name
);
315 keypad_data
= sdp4430_keypad_data
;
317 pdev
= omap_device_build(name
, id
, oh
, keypad_data
,
318 sizeof(struct omap4_keypad_platform_data
));
321 WARN(1, "Can't build omap_device for %s:%s.\n",
323 return PTR_ERR(pdev
);
325 oh
->mux
= omap_hwmod_mux_init(bdata
->pads
, bdata
->pads_cnt
);
330 #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
331 static inline void __init
omap_init_mbox(void)
333 struct omap_hwmod
*oh
;
334 struct platform_device
*pdev
;
336 oh
= omap_hwmod_lookup("mailbox");
338 pr_err("%s: unable to find hwmod\n", __func__
);
342 pdev
= omap_device_build("omap-mailbox", -1, oh
, NULL
, 0);
343 WARN(IS_ERR(pdev
), "%s: could not build device, err %ld\n",
344 __func__
, PTR_ERR(pdev
));
347 static inline void omap_init_mbox(void) { }
348 #endif /* CONFIG_OMAP_MBOX_FWK */
350 static inline void omap_init_sti(void) {}
352 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
354 static struct platform_device omap_pcm
= {
355 .name
= "omap-pcm-audio",
359 static void omap_init_audio(void)
361 platform_device_register(&omap_pcm
);
365 static inline void omap_init_audio(void) {}
368 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
369 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
371 static void __init
omap_init_mcpdm(void)
373 struct omap_hwmod
*oh
;
374 struct platform_device
*pdev
;
376 oh
= omap_hwmod_lookup("mcpdm");
378 printk(KERN_ERR
"Could not look up mcpdm hw_mod\n");
382 pdev
= omap_device_build("omap-mcpdm", -1, oh
, NULL
, 0);
383 WARN(IS_ERR(pdev
), "Can't build omap_device for omap-mcpdm.\n");
386 static inline void omap_init_mcpdm(void) {}
389 #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
390 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
392 static void __init
omap_init_dmic(void)
394 struct omap_hwmod
*oh
;
395 struct platform_device
*pdev
;
397 oh
= omap_hwmod_lookup("dmic");
399 pr_err("Could not look up dmic hw_mod\n");
403 pdev
= omap_device_build("omap-dmic", -1, oh
, NULL
, 0);
404 WARN(IS_ERR(pdev
), "Can't build omap_device for omap-dmic.\n");
407 static inline void omap_init_dmic(void) {}
410 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
411 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
413 static struct platform_device omap_hdmi_audio
= {
414 .name
= "omap-hdmi-audio",
418 static void __init
omap_init_hdmi_audio(void)
420 struct omap_hwmod
*oh
;
421 struct platform_device
*pdev
;
423 oh
= omap_hwmod_lookup("dss_hdmi");
425 printk(KERN_ERR
"Could not look up dss_hdmi hw_mod\n");
429 pdev
= omap_device_build("omap-hdmi-audio-dai", -1, oh
, NULL
, 0);
431 "Can't build omap_device for omap-hdmi-audio-dai.\n");
433 platform_device_register(&omap_hdmi_audio
);
436 static inline void omap_init_hdmi_audio(void) {}
439 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
441 #include <linux/platform_data/spi-omap2-mcspi.h>
443 static int __init
omap_mcspi_init(struct omap_hwmod
*oh
, void *unused
)
445 struct platform_device
*pdev
;
446 char *name
= "omap2_mcspi";
447 struct omap2_mcspi_platform_config
*pdata
;
449 struct omap2_mcspi_dev_attr
*mcspi_attrib
= oh
->dev_attr
;
451 pdata
= kzalloc(sizeof(*pdata
), GFP_KERNEL
);
453 pr_err("Memory allocation for McSPI device failed\n");
457 pdata
->num_cs
= mcspi_attrib
->num_chipselect
;
458 switch (oh
->class->rev
) {
459 case OMAP2_MCSPI_REV
:
460 case OMAP3_MCSPI_REV
:
461 pdata
->regs_offset
= 0;
463 case OMAP4_MCSPI_REV
:
464 pdata
->regs_offset
= OMAP4_MCSPI_REG_OFFSET
;
467 pr_err("Invalid McSPI Revision value\n");
473 pdev
= omap_device_build(name
, spi_num
, oh
, pdata
, sizeof(*pdata
));
474 WARN(IS_ERR(pdev
), "Can't build omap_device for %s:%s\n",
480 static void omap_init_mcspi(void)
482 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init
, NULL
);
486 static inline void omap_init_mcspi(void) {}
490 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
492 * Bind the RNG hwmod to the RNG omap_device. No return value.
494 static void omap_init_rng(void)
496 struct omap_hwmod
*oh
;
497 struct platform_device
*pdev
;
499 oh
= omap_hwmod_lookup("rng");
503 pdev
= omap_device_build("omap_rng", -1, oh
, NULL
, 0);
504 WARN(IS_ERR(pdev
), "Can't build omap_device for omap_rng\n");
507 #if defined(CONFIG_CRYPTO_DEV_OMAP_SHAM) || defined(CONFIG_CRYPTO_DEV_OMAP_SHAM_MODULE)
509 #ifdef CONFIG_ARCH_OMAP2
510 static struct resource omap2_sham_resources
[] = {
512 .start
= OMAP24XX_SEC_SHA1MD5_BASE
,
513 .end
= OMAP24XX_SEC_SHA1MD5_BASE
+ 0x64,
514 .flags
= IORESOURCE_MEM
,
517 .start
= 51 + OMAP_INTC_START
,
518 .flags
= IORESOURCE_IRQ
,
521 static int omap2_sham_resources_sz
= ARRAY_SIZE(omap2_sham_resources
);
523 #define omap2_sham_resources NULL
524 #define omap2_sham_resources_sz 0
527 #ifdef CONFIG_ARCH_OMAP3
528 static struct resource omap3_sham_resources
[] = {
530 .start
= OMAP34XX_SEC_SHA1MD5_BASE
,
531 .end
= OMAP34XX_SEC_SHA1MD5_BASE
+ 0x64,
532 .flags
= IORESOURCE_MEM
,
535 .start
= 49 + OMAP_INTC_START
,
536 .flags
= IORESOURCE_IRQ
,
539 .start
= OMAP34XX_DMA_SHA1MD5_RX
,
540 .flags
= IORESOURCE_DMA
,
543 static int omap3_sham_resources_sz
= ARRAY_SIZE(omap3_sham_resources
);
545 #define omap3_sham_resources NULL
546 #define omap3_sham_resources_sz 0
549 static struct platform_device sham_device
= {
554 static void omap_init_sham(void)
556 if (cpu_is_omap24xx()) {
557 sham_device
.resource
= omap2_sham_resources
;
558 sham_device
.num_resources
= omap2_sham_resources_sz
;
559 } else if (cpu_is_omap34xx()) {
560 sham_device
.resource
= omap3_sham_resources
;
561 sham_device
.num_resources
= omap3_sham_resources_sz
;
563 pr_err("%s: platform not supported\n", __func__
);
566 platform_device_register(&sham_device
);
569 static inline void omap_init_sham(void) { }
572 #if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)
574 #ifdef CONFIG_ARCH_OMAP2
575 static struct resource omap2_aes_resources
[] = {
577 .start
= OMAP24XX_SEC_AES_BASE
,
578 .end
= OMAP24XX_SEC_AES_BASE
+ 0x4C,
579 .flags
= IORESOURCE_MEM
,
582 .start
= OMAP24XX_DMA_AES_TX
,
583 .flags
= IORESOURCE_DMA
,
586 .start
= OMAP24XX_DMA_AES_RX
,
587 .flags
= IORESOURCE_DMA
,
590 static int omap2_aes_resources_sz
= ARRAY_SIZE(omap2_aes_resources
);
592 #define omap2_aes_resources NULL
593 #define omap2_aes_resources_sz 0
596 #ifdef CONFIG_ARCH_OMAP3
597 static struct resource omap3_aes_resources
[] = {
599 .start
= OMAP34XX_SEC_AES_BASE
,
600 .end
= OMAP34XX_SEC_AES_BASE
+ 0x4C,
601 .flags
= IORESOURCE_MEM
,
604 .start
= OMAP34XX_DMA_AES2_TX
,
605 .flags
= IORESOURCE_DMA
,
608 .start
= OMAP34XX_DMA_AES2_RX
,
609 .flags
= IORESOURCE_DMA
,
612 static int omap3_aes_resources_sz
= ARRAY_SIZE(omap3_aes_resources
);
614 #define omap3_aes_resources NULL
615 #define omap3_aes_resources_sz 0
618 static struct platform_device aes_device
= {
623 static void omap_init_aes(void)
625 if (cpu_is_omap24xx()) {
626 aes_device
.resource
= omap2_aes_resources
;
627 aes_device
.num_resources
= omap2_aes_resources_sz
;
628 } else if (cpu_is_omap34xx()) {
629 aes_device
.resource
= omap3_aes_resources
;
630 aes_device
.num_resources
= omap3_aes_resources_sz
;
632 pr_err("%s: platform not supported\n", __func__
);
635 platform_device_register(&aes_device
);
639 static inline void omap_init_aes(void) { }
642 /*-------------------------------------------------------------------------*/
644 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
645 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
646 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
647 static struct resource omap_vout_resource
[3 - CONFIG_FB_OMAP2_NUM_FBS
] = {
650 static struct resource omap_vout_resource
[2] = {
654 static struct platform_device omap_vout_device
= {
656 .num_resources
= ARRAY_SIZE(omap_vout_resource
),
657 .resource
= &omap_vout_resource
[0],
660 static void omap_init_vout(void)
662 if (platform_device_register(&omap_vout_device
) < 0)
663 printk(KERN_ERR
"Unable to register OMAP-VOUT device\n");
666 static inline void omap_init_vout(void) {}
669 #if defined(CONFIG_OMAP_OCP2SCP) || defined(CONFIG_OMAP_OCP2SCP_MODULE)
670 static int count_ocp2scp_devices(struct omap_ocp2scp_dev
*ocp2scp_dev
)
674 while (ocp2scp_dev
->drv_name
!= NULL
) {
682 static void __init
omap_init_ocp2scp(void)
684 struct omap_hwmod
*oh
;
685 struct platform_device
*pdev
;
686 int bus_id
= -1, dev_cnt
= 0, i
;
687 struct omap_ocp2scp_dev
*ocp2scp_dev
;
688 const char *oh_name
, *name
;
689 struct omap_ocp2scp_platform_data
*pdata
;
691 if (!cpu_is_omap44xx())
694 oh_name
= "ocp2scp_usb_phy";
695 name
= "omap-ocp2scp";
697 oh
= omap_hwmod_lookup(oh_name
);
699 pr_err("%s: could not find omap_hwmod for %s\n", __func__
,
704 pdata
= kzalloc(sizeof(*pdata
), GFP_KERNEL
);
706 pr_err("%s: No memory for ocp2scp pdata\n", __func__
);
710 ocp2scp_dev
= oh
->dev_attr
;
711 dev_cnt
= count_ocp2scp_devices(ocp2scp_dev
);
714 pr_err("%s: No devices connected to ocp2scp\n", __func__
);
719 pdata
->devices
= kzalloc(sizeof(struct omap_ocp2scp_dev
*)
720 * dev_cnt
, GFP_KERNEL
);
721 if (!pdata
->devices
) {
722 pr_err("%s: No memory for ocp2scp pdata devices\n", __func__
);
727 for (i
= 0; i
< dev_cnt
; i
++, ocp2scp_dev
++)
728 pdata
->devices
[i
] = ocp2scp_dev
;
730 pdata
->dev_cnt
= dev_cnt
;
732 pdev
= omap_device_build(name
, bus_id
, oh
, pdata
, sizeof(*pdata
));
734 pr_err("Could not build omap_device for %s %s\n",
736 kfree(pdata
->devices
);
742 static inline void omap_init_ocp2scp(void) { }
745 /*-------------------------------------------------------------------------*/
747 static int __init
omap2_init_devices(void)
749 /* Enable dummy states for those platforms without pinctrl support */
750 if (!of_have_populated_dt())
751 pinctrl_provide_dummies();
754 * please keep these calls, and their implementations above,
755 * in alphabetical order so they're easier to sort through.
759 omap_init_hdmi_audio();
761 /* If dtb is there, the devices will be created dynamically */
762 if (!of_have_populated_dt()) {
763 omap_init_control_usb();
777 omap_arch_initcall(omap2_init_devices
);