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/mailbox-omap.h>
23 #include <asm/mach-types.h>
24 #include <asm/mach/map.h>
26 #include <linux/omap-dma.h>
29 #include "omap_hwmod.h"
30 #include "omap_device.h"
38 #define L3_MODULES_MAX_LEN 12
41 static int __init omap3_l3_init(void)
43 struct omap_hwmod *oh;
44 struct platform_device *pdev;
45 char oh_name[L3_MODULES_MAX_LEN];
48 * To avoid code running on other OMAPs in
51 if (!(cpu_is_omap34xx()) || of_have_populated_dt())
54 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
56 oh = omap_hwmod_lookup(oh_name);
59 pr_err("could not look up %s\n", oh_name);
61 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
63 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
65 return PTR_ERR_OR_ZERO(pdev);
67 omap_postcore_initcall(omap3_l3_init);
69 #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
70 static inline void __init omap_init_mbox(void)
72 struct omap_hwmod *oh;
73 struct platform_device *pdev;
74 struct omap_mbox_pdata *pdata;
76 oh = omap_hwmod_lookup("mailbox");
78 pr_err("%s: unable to find hwmod\n", __func__);
82 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
86 pdata = (struct omap_mbox_pdata *)oh->dev_attr;
87 pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
88 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
89 __func__, PTR_ERR(pdev));
92 static inline void omap_init_mbox(void) { }
93 #endif /* CONFIG_OMAP2PLUS_MBOX */
95 static inline void omap_init_sti(void) {}
97 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
99 #include <linux/platform_data/spi-omap2-mcspi.h>
101 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
103 struct platform_device *pdev;
104 char *name = "omap2_mcspi";
105 struct omap2_mcspi_platform_config *pdata;
107 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
109 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
111 pr_err("Memory allocation for McSPI device failed\n");
115 pdata->num_cs = mcspi_attrib->num_chipselect;
116 switch (oh->class->rev) {
117 case OMAP2_MCSPI_REV:
118 case OMAP3_MCSPI_REV:
119 pdata->regs_offset = 0;
121 case OMAP4_MCSPI_REV:
122 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
125 pr_err("Invalid McSPI Revision value\n");
131 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
132 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
138 static void omap_init_mcspi(void)
140 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
144 static inline void omap_init_mcspi(void) {}
148 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
150 * Bind the RNG hwmod to the RNG omap_device. No return value.
152 static void omap_init_rng(void)
154 struct omap_hwmod *oh;
155 struct platform_device *pdev;
157 oh = omap_hwmod_lookup("rng");
161 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
162 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
165 static void __init omap_init_sham(void)
167 struct omap_hwmod *oh;
168 struct platform_device *pdev;
170 oh = omap_hwmod_lookup("sham");
174 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
175 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
178 static void __init omap_init_aes(void)
180 struct omap_hwmod *oh;
181 struct platform_device *pdev;
183 oh = omap_hwmod_lookup("aes");
187 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
188 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
191 /*-------------------------------------------------------------------------*/
193 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
194 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
195 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
196 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
199 static struct resource omap_vout_resource[2] = {
203 static struct platform_device omap_vout_device = {
205 .num_resources = ARRAY_SIZE(omap_vout_resource),
206 .resource = &omap_vout_resource[0],
210 int __init omap_init_vout(void)
212 return platform_device_register(&omap_vout_device);
215 int __init omap_init_vout(void) { return 0; }
218 /*-------------------------------------------------------------------------*/
220 static int __init omap2_init_devices(void)
222 /* Enable dummy states for those platforms without pinctrl support */
223 if (!of_have_populated_dt())
224 pinctrl_provide_dummies();
226 /* If dtb is there, the devices will be created dynamically */
227 if (!of_have_populated_dt()) {
229 * please keep these calls, and their implementations above,
230 * in alphabetical order so they're easier to sort through.
242 omap_arch_initcall(omap2_init_devices);
244 static int __init omap_gpmc_init(void)
246 struct omap_hwmod *oh;
247 struct platform_device *pdev;
248 char *oh_name = "gpmc";
251 * if the board boots up with a populated DT, do not
252 * manually add the device from this initcall
254 if (of_have_populated_dt())
257 oh = omap_hwmod_lookup(oh_name);
259 pr_err("Could not look up %s\n", oh_name);
263 pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
264 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
266 return PTR_ERR_OR_ZERO(pdev);
268 omap_postcore_initcall(omap_gpmc_init);