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>
24 #include <asm/mach-types.h>
25 #include <asm/mach/map.h>
29 #include <plat/omap_hwmod.h>
30 #include <plat/omap_device.h>
31 #include "omap4-keypad.h"
39 #define L3_MODULES_MAX_LEN 12
42 static int __init omap3_l3_init(void)
44 struct omap_hwmod *oh;
45 struct platform_device *pdev;
46 char oh_name[L3_MODULES_MAX_LEN];
49 * To avoid code running on other OMAPs in
52 if (!(cpu_is_omap34xx()))
55 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
57 oh = omap_hwmod_lookup(oh_name);
60 pr_err("could not look up %s\n", oh_name);
62 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0,
65 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
67 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
69 postcore_initcall(omap3_l3_init);
71 static int __init omap4_l3_init(void)
74 struct omap_hwmod *oh[3];
75 struct platform_device *pdev;
76 char oh_name[L3_MODULES_MAX_LEN];
78 /* If dtb is there, the devices will be created dynamically */
79 if (of_have_populated_dt())
83 * To avoid code running on other OMAPs in
86 if (!cpu_is_omap44xx() && !soc_is_omap54xx())
89 for (i = 0; i < L3_MODULES; i++) {
90 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
92 oh[i] = omap_hwmod_lookup(oh_name);
94 pr_err("could not look up %s\n", oh_name);
97 pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL,
100 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
102 return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
104 postcore_initcall(omap4_l3_init);
106 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
108 static struct resource omap2cam_resources[] = {
110 .start = OMAP24XX_CAMERA_BASE,
111 .end = OMAP24XX_CAMERA_BASE + 0xfff,
112 .flags = IORESOURCE_MEM,
115 .start = 24 + OMAP_INTC_START,
116 .flags = IORESOURCE_IRQ,
120 static struct platform_device omap2cam_device = {
121 .name = "omap24xxcam",
123 .num_resources = ARRAY_SIZE(omap2cam_resources),
124 .resource = omap2cam_resources,
128 #if defined(CONFIG_IOMMU_API)
130 #include <plat/iommu.h>
132 static struct resource omap3isp_resources[] = {
134 .start = OMAP3430_ISP_BASE,
135 .end = OMAP3430_ISP_END,
136 .flags = IORESOURCE_MEM,
139 .start = OMAP3430_ISP_CCP2_BASE,
140 .end = OMAP3430_ISP_CCP2_END,
141 .flags = IORESOURCE_MEM,
144 .start = OMAP3430_ISP_CCDC_BASE,
145 .end = OMAP3430_ISP_CCDC_END,
146 .flags = IORESOURCE_MEM,
149 .start = OMAP3430_ISP_HIST_BASE,
150 .end = OMAP3430_ISP_HIST_END,
151 .flags = IORESOURCE_MEM,
154 .start = OMAP3430_ISP_H3A_BASE,
155 .end = OMAP3430_ISP_H3A_END,
156 .flags = IORESOURCE_MEM,
159 .start = OMAP3430_ISP_PREV_BASE,
160 .end = OMAP3430_ISP_PREV_END,
161 .flags = IORESOURCE_MEM,
164 .start = OMAP3430_ISP_RESZ_BASE,
165 .end = OMAP3430_ISP_RESZ_END,
166 .flags = IORESOURCE_MEM,
169 .start = OMAP3430_ISP_SBL_BASE,
170 .end = OMAP3430_ISP_SBL_END,
171 .flags = IORESOURCE_MEM,
174 .start = OMAP3430_ISP_CSI2A_REGS1_BASE,
175 .end = OMAP3430_ISP_CSI2A_REGS1_END,
176 .flags = IORESOURCE_MEM,
179 .start = OMAP3430_ISP_CSIPHY2_BASE,
180 .end = OMAP3430_ISP_CSIPHY2_END,
181 .flags = IORESOURCE_MEM,
184 .start = OMAP3630_ISP_CSI2A_REGS2_BASE,
185 .end = OMAP3630_ISP_CSI2A_REGS2_END,
186 .flags = IORESOURCE_MEM,
189 .start = OMAP3630_ISP_CSI2C_REGS1_BASE,
190 .end = OMAP3630_ISP_CSI2C_REGS1_END,
191 .flags = IORESOURCE_MEM,
194 .start = OMAP3630_ISP_CSIPHY1_BASE,
195 .end = OMAP3630_ISP_CSIPHY1_END,
196 .flags = IORESOURCE_MEM,
199 .start = OMAP3630_ISP_CSI2C_REGS2_BASE,
200 .end = OMAP3630_ISP_CSI2C_REGS2_END,
201 .flags = IORESOURCE_MEM,
204 .start = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE,
205 .end = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE + 3,
206 .flags = IORESOURCE_MEM,
209 .start = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL,
210 .end = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL + 3,
211 .flags = IORESOURCE_MEM,
214 .start = 24 + OMAP_INTC_START,
215 .flags = IORESOURCE_IRQ,
219 static struct platform_device omap3isp_device = {
222 .num_resources = ARRAY_SIZE(omap3isp_resources),
223 .resource = omap3isp_resources,
226 static struct omap_iommu_arch_data omap3_isp_iommu = {
230 int omap3_init_camera(struct isp_platform_data *pdata)
232 omap3isp_device.dev.platform_data = pdata;
233 omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
235 return platform_device_register(&omap3isp_device);
238 #else /* !CONFIG_IOMMU_API */
240 int omap3_init_camera(struct isp_platform_data *pdata)
247 static inline void omap_init_camera(void)
249 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
250 if (cpu_is_omap24xx())
251 platform_device_register(&omap2cam_device);
255 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
256 *sdp4430_keypad_data, struct omap_board_data *bdata)
258 struct platform_device *pdev;
259 struct omap_hwmod *oh;
260 struct omap4_keypad_platform_data *keypad_data;
261 unsigned int id = -1;
262 char *oh_name = "kbd";
263 char *name = "omap4-keypad";
265 oh = omap_hwmod_lookup(oh_name);
267 pr_err("Could not look up %s\n", oh_name);
271 keypad_data = sdp4430_keypad_data;
273 pdev = omap_device_build(name, id, oh, keypad_data,
274 sizeof(struct omap4_keypad_platform_data), NULL, 0, 0);
277 WARN(1, "Can't build omap_device for %s:%s.\n",
279 return PTR_ERR(pdev);
281 oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
286 #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
287 static inline void __init omap_init_mbox(void)
289 struct omap_hwmod *oh;
290 struct platform_device *pdev;
292 oh = omap_hwmod_lookup("mailbox");
294 pr_err("%s: unable to find hwmod\n", __func__);
298 pdev = omap_device_build("omap-mailbox", -1, oh, NULL, 0, NULL, 0, 0);
299 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
300 __func__, PTR_ERR(pdev));
303 static inline void omap_init_mbox(void) { }
304 #endif /* CONFIG_OMAP_MBOX_FWK */
306 static inline void omap_init_sti(void) {}
308 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
310 static struct platform_device omap_pcm = {
311 .name = "omap-pcm-audio",
315 static void omap_init_audio(void)
317 platform_device_register(&omap_pcm);
321 static inline void omap_init_audio(void) {}
324 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
325 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
327 static void __init omap_init_mcpdm(void)
329 struct omap_hwmod *oh;
330 struct platform_device *pdev;
332 oh = omap_hwmod_lookup("mcpdm");
334 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
338 pdev = omap_device_build("omap-mcpdm", -1, oh, NULL, 0, NULL, 0, 0);
339 WARN(IS_ERR(pdev), "Can't build omap_device for omap-mcpdm.\n");
342 static inline void omap_init_mcpdm(void) {}
345 #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
346 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
348 static void __init omap_init_dmic(void)
350 struct omap_hwmod *oh;
351 struct platform_device *pdev;
353 oh = omap_hwmod_lookup("dmic");
355 pr_err("Could not look up dmic hw_mod\n");
359 pdev = omap_device_build("omap-dmic", -1, oh, NULL, 0, NULL, 0, 0);
360 WARN(IS_ERR(pdev), "Can't build omap_device for omap-dmic.\n");
363 static inline void omap_init_dmic(void) {}
366 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
367 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
369 static struct platform_device omap_hdmi_audio = {
370 .name = "omap-hdmi-audio",
374 static void __init omap_init_hdmi_audio(void)
376 struct omap_hwmod *oh;
377 struct platform_device *pdev;
379 oh = omap_hwmod_lookup("dss_hdmi");
381 printk(KERN_ERR "Could not look up dss_hdmi hw_mod\n");
385 pdev = omap_device_build("omap-hdmi-audio-dai",
386 -1, oh, NULL, 0, NULL, 0, 0);
388 "Can't build omap_device for omap-hdmi-audio-dai.\n");
390 platform_device_register(&omap_hdmi_audio);
393 static inline void omap_init_hdmi_audio(void) {}
396 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
398 #include <linux/platform_data/spi-omap2-mcspi.h>
400 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
402 struct platform_device *pdev;
403 char *name = "omap2_mcspi";
404 struct omap2_mcspi_platform_config *pdata;
406 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
408 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
410 pr_err("Memory allocation for McSPI device failed\n");
414 pdata->num_cs = mcspi_attrib->num_chipselect;
415 switch (oh->class->rev) {
416 case OMAP2_MCSPI_REV:
417 case OMAP3_MCSPI_REV:
418 pdata->regs_offset = 0;
420 case OMAP4_MCSPI_REV:
421 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
424 pr_err("Invalid McSPI Revision value\n");
430 pdev = omap_device_build(name, spi_num, oh, pdata,
431 sizeof(*pdata), NULL, 0, 0);
432 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
438 static void omap_init_mcspi(void)
440 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
444 static inline void omap_init_mcspi(void) {}
448 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
450 * Bind the RNG hwmod to the RNG omap_device. No return value.
452 static void omap_init_rng(void)
454 struct omap_hwmod *oh;
455 struct platform_device *pdev;
457 oh = omap_hwmod_lookup("rng");
461 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0, NULL, 0, 0);
462 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
465 #if defined(CONFIG_CRYPTO_DEV_OMAP_SHAM) || defined(CONFIG_CRYPTO_DEV_OMAP_SHAM_MODULE)
467 #ifdef CONFIG_ARCH_OMAP2
468 static struct resource omap2_sham_resources[] = {
470 .start = OMAP24XX_SEC_SHA1MD5_BASE,
471 .end = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
472 .flags = IORESOURCE_MEM,
475 .start = 51 + OMAP_INTC_START,
476 .flags = IORESOURCE_IRQ,
479 static int omap2_sham_resources_sz = ARRAY_SIZE(omap2_sham_resources);
481 #define omap2_sham_resources NULL
482 #define omap2_sham_resources_sz 0
485 #ifdef CONFIG_ARCH_OMAP3
486 static struct resource omap3_sham_resources[] = {
488 .start = OMAP34XX_SEC_SHA1MD5_BASE,
489 .end = OMAP34XX_SEC_SHA1MD5_BASE + 0x64,
490 .flags = IORESOURCE_MEM,
493 .start = 49 + OMAP_INTC_START,
494 .flags = IORESOURCE_IRQ,
497 .start = OMAP34XX_DMA_SHA1MD5_RX,
498 .flags = IORESOURCE_DMA,
501 static int omap3_sham_resources_sz = ARRAY_SIZE(omap3_sham_resources);
503 #define omap3_sham_resources NULL
504 #define omap3_sham_resources_sz 0
507 static struct platform_device sham_device = {
512 static void omap_init_sham(void)
514 if (cpu_is_omap24xx()) {
515 sham_device.resource = omap2_sham_resources;
516 sham_device.num_resources = omap2_sham_resources_sz;
517 } else if (cpu_is_omap34xx()) {
518 sham_device.resource = omap3_sham_resources;
519 sham_device.num_resources = omap3_sham_resources_sz;
521 pr_err("%s: platform not supported\n", __func__);
524 platform_device_register(&sham_device);
527 static inline void omap_init_sham(void) { }
530 #if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)
532 #ifdef CONFIG_ARCH_OMAP2
533 static struct resource omap2_aes_resources[] = {
535 .start = OMAP24XX_SEC_AES_BASE,
536 .end = OMAP24XX_SEC_AES_BASE + 0x4C,
537 .flags = IORESOURCE_MEM,
540 .start = OMAP24XX_DMA_AES_TX,
541 .flags = IORESOURCE_DMA,
544 .start = OMAP24XX_DMA_AES_RX,
545 .flags = IORESOURCE_DMA,
548 static int omap2_aes_resources_sz = ARRAY_SIZE(omap2_aes_resources);
550 #define omap2_aes_resources NULL
551 #define omap2_aes_resources_sz 0
554 #ifdef CONFIG_ARCH_OMAP3
555 static struct resource omap3_aes_resources[] = {
557 .start = OMAP34XX_SEC_AES_BASE,
558 .end = OMAP34XX_SEC_AES_BASE + 0x4C,
559 .flags = IORESOURCE_MEM,
562 .start = OMAP34XX_DMA_AES2_TX,
563 .flags = IORESOURCE_DMA,
566 .start = OMAP34XX_DMA_AES2_RX,
567 .flags = IORESOURCE_DMA,
570 static int omap3_aes_resources_sz = ARRAY_SIZE(omap3_aes_resources);
572 #define omap3_aes_resources NULL
573 #define omap3_aes_resources_sz 0
576 static struct platform_device aes_device = {
581 static void omap_init_aes(void)
583 if (cpu_is_omap24xx()) {
584 aes_device.resource = omap2_aes_resources;
585 aes_device.num_resources = omap2_aes_resources_sz;
586 } else if (cpu_is_omap34xx()) {
587 aes_device.resource = omap3_aes_resources;
588 aes_device.num_resources = omap3_aes_resources_sz;
590 pr_err("%s: platform not supported\n", __func__);
593 platform_device_register(&aes_device);
597 static inline void omap_init_aes(void) { }
600 /*-------------------------------------------------------------------------*/
602 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
603 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
604 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
605 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
608 static struct resource omap_vout_resource[2] = {
612 static struct platform_device omap_vout_device = {
614 .num_resources = ARRAY_SIZE(omap_vout_resource),
615 .resource = &omap_vout_resource[0],
618 static void omap_init_vout(void)
620 if (platform_device_register(&omap_vout_device) < 0)
621 printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
624 static inline void omap_init_vout(void) {}
627 #if defined(CONFIG_OMAP_OCP2SCP) || defined(CONFIG_OMAP_OCP2SCP_MODULE)
628 static int count_ocp2scp_devices(struct omap_ocp2scp_dev *ocp2scp_dev)
632 while (ocp2scp_dev->drv_name != NULL) {
640 static void omap_init_ocp2scp(void)
642 struct omap_hwmod *oh;
643 struct platform_device *pdev;
644 int bus_id = -1, dev_cnt = 0, i;
645 struct omap_ocp2scp_dev *ocp2scp_dev;
646 const char *oh_name, *name;
647 struct omap_ocp2scp_platform_data *pdata;
649 if (!cpu_is_omap44xx())
652 oh_name = "ocp2scp_usb_phy";
653 name = "omap-ocp2scp";
655 oh = omap_hwmod_lookup(oh_name);
657 pr_err("%s: could not find omap_hwmod for %s\n", __func__,
662 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
664 pr_err("%s: No memory for ocp2scp pdata\n", __func__);
668 ocp2scp_dev = oh->dev_attr;
669 dev_cnt = count_ocp2scp_devices(ocp2scp_dev);
672 pr_err("%s: No devices connected to ocp2scp\n", __func__);
677 pdata->devices = kzalloc(sizeof(struct omap_ocp2scp_dev *)
678 * dev_cnt, GFP_KERNEL);
679 if (!pdata->devices) {
680 pr_err("%s: No memory for ocp2scp pdata devices\n", __func__);
685 for (i = 0; i < dev_cnt; i++, ocp2scp_dev++)
686 pdata->devices[i] = ocp2scp_dev;
688 pdata->dev_cnt = dev_cnt;
690 pdev = omap_device_build(name, bus_id, oh, pdata, sizeof(*pdata), NULL,
693 pr_err("Could not build omap_device for %s %s\n",
695 kfree(pdata->devices);
701 static inline void omap_init_ocp2scp(void) { }
704 /*-------------------------------------------------------------------------*/
706 static int __init omap2_init_devices(void)
708 /* Enable dummy states for those platforms without pinctrl support */
709 if (!of_have_populated_dt())
710 pinctrl_provide_dummies();
713 * please keep these calls, and their implementations above,
714 * in alphabetical order so they're easier to sort through.
718 omap_init_hdmi_audio();
720 /* If dtb is there, the devices will be created dynamically */
721 if (!of_have_populated_dt()) {
735 arch_initcall(omap2_init_devices);
737 #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
738 static int __init omap_init_wdt(void)
741 struct platform_device *pdev;
742 struct omap_hwmod *oh;
743 char *oh_name = "wd_timer2";
744 char *dev_name = "omap_wdt";
746 if (!cpu_class_is_omap2() || of_have_populated_dt())
749 oh = omap_hwmod_lookup(oh_name);
751 pr_err("Could not look up wd_timer%d hwmod\n", id);
755 pdev = omap_device_build(dev_name, id, oh, NULL, 0, NULL, 0, 0);
756 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
760 subsys_initcall(omap_init_wdt);