Commit | Line | Data |
---|---|---|
1dbae815 TL |
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 | */ | |
2f8163ba | 11 | #include <linux/gpio.h> |
1dbae815 TL |
12 | #include <linux/kernel.h> |
13 | #include <linux/init.h> | |
14 | #include <linux/platform_device.h> | |
fced80c7 | 15 | #include <linux/io.h> |
917fa280 | 16 | #include <linux/clk.h> |
f2ce6231 | 17 | #include <linux/err.h> |
1a5d8190 | 18 | #include <linux/slab.h> |
ad8dfac6 | 19 | #include <linux/of.h> |
484202f4 | 20 | #include <linux/pinctrl/machine.h> |
b8a7cf8e | 21 | #include <linux/platform_data/mailbox-omap.h> |
1dbae815 | 22 | |
1dbae815 TL |
23 | #include <asm/mach-types.h> |
24 | #include <asm/mach/map.h> | |
25 | ||
45c3eb7d | 26 | #include <linux/omap-dma.h> |
2a296c8f | 27 | |
ee0839c2 | 28 | #include "iomap.h" |
2a296c8f | 29 | #include "omap_hwmod.h" |
25c7d49e | 30 | #include "omap_device.h" |
1dbae815 | 31 | |
7d7e1eba TL |
32 | #include "soc.h" |
33 | #include "common.h" | |
4896e394 | 34 | #include "mux.h" |
4814ced5 | 35 | #include "control.h" |
a11f6706 | 36 | #include "devices.h" |
576e5bda | 37 | #include "display.h" |
4896e394 | 38 | |
0abcf618 | 39 | #define L3_MODULES_MAX_LEN 12 |
a4dc616a | 40 | #define L3_MODULES 3 |
0abcf618 | 41 | |
42 | static int __init omap3_l3_init(void) | |
43 | { | |
0abcf618 | 44 | struct omap_hwmod *oh; |
3528c58e | 45 | struct platform_device *pdev; |
0abcf618 | 46 | char oh_name[L3_MODULES_MAX_LEN]; |
47 | ||
48 | /* | |
49 | * To avoid code running on other OMAPs in | |
50 | * multi-omap builds | |
51 | */ | |
aa25729c | 52 | if (!(cpu_is_omap34xx()) || of_have_populated_dt()) |
0abcf618 | 53 | return -ENODEV; |
54 | ||
eeb3711b | 55 | snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main"); |
0abcf618 | 56 | |
57 | oh = omap_hwmod_lookup(oh_name); | |
58 | ||
59 | if (!oh) | |
60 | pr_err("could not look up %s\n", oh_name); | |
61 | ||
c1d1cd59 | 62 | pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0); |
0abcf618 | 63 | |
3528c58e | 64 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); |
0abcf618 | 65 | |
e44be50c | 66 | return PTR_ERR_OR_ZERO(pdev); |
0abcf618 | 67 | } |
b76c8b19 | 68 | omap_postcore_initcall(omap3_l3_init); |
0abcf618 | 69 | |
1a51a0ce OBC |
70 | #if defined(CONFIG_IOMMU_API) |
71 | ||
2ab7c848 | 72 | #include <linux/platform_data/iommu-omap.h> |
1a51a0ce | 73 | |
828c707e TL |
74 | static struct resource omap3isp_resources[] = { |
75 | { | |
76 | .start = OMAP3430_ISP_BASE, | |
8644cdf9 | 77 | .end = OMAP3430_ISP_BASE + 0x12fc, |
828c707e TL |
78 | .flags = IORESOURCE_MEM, |
79 | }, | |
828c707e | 80 | { |
8644cdf9 SA |
81 | .start = OMAP3430_ISP_BASE2, |
82 | .end = OMAP3430_ISP_BASE2 + 0x0600, | |
828c707e TL |
83 | .flags = IORESOURCE_MEM, |
84 | }, | |
85 | { | |
7d7e1eba | 86 | .start = 24 + OMAP_INTC_START, |
828c707e TL |
87 | .flags = IORESOURCE_IRQ, |
88 | } | |
89 | }; | |
90 | ||
91 | static struct platform_device omap3isp_device = { | |
92 | .name = "omap3isp", | |
93 | .id = -1, | |
94 | .num_resources = ARRAY_SIZE(omap3isp_resources), | |
95 | .resource = omap3isp_resources, | |
96 | }; | |
97 | ||
c8eaab3b | 98 | static struct omap_iommu_arch_data omap3_isp_iommu = { |
72b15b6a | 99 | .name = "mmu_isp", |
c8eaab3b OBC |
100 | }; |
101 | ||
a11f6706 | 102 | int omap3_init_camera(struct isp_platform_data *pdata) |
828c707e | 103 | { |
0ac4f03f SA |
104 | if (of_have_populated_dt()) |
105 | omap3_isp_iommu.name = "480bd400.mmu"; | |
106 | ||
a11f6706 | 107 | omap3isp_device.dev.platform_data = pdata; |
c8eaab3b OBC |
108 | omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu; |
109 | ||
a11f6706 | 110 | return platform_device_register(&omap3isp_device); |
828c707e | 111 | } |
828c707e | 112 | |
1a51a0ce OBC |
113 | #else /* !CONFIG_IOMMU_API */ |
114 | ||
115 | int omap3_init_camera(struct isp_platform_data *pdata) | |
116 | { | |
117 | return 0; | |
118 | } | |
119 | ||
120 | #endif | |
121 | ||
c869c75c | 122 | #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE) |
9cf793f9 | 123 | static inline void __init omap_init_mbox(void) |
c40fae95 | 124 | { |
69dbf857 | 125 | struct omap_hwmod *oh; |
3528c58e | 126 | struct platform_device *pdev; |
b8a7cf8e | 127 | struct omap_mbox_pdata *pdata; |
69dbf857 FC |
128 | |
129 | oh = omap_hwmod_lookup("mailbox"); | |
130 | if (!oh) { | |
131 | pr_err("%s: unable to find hwmod\n", __func__); | |
6c20a683 HD |
132 | return; |
133 | } | |
b8a7cf8e SA |
134 | if (!oh->dev_attr) { |
135 | pr_err("%s: hwmod doesn't have valid attrs\n", __func__); | |
136 | return; | |
137 | } | |
69dbf857 | 138 | |
b8a7cf8e SA |
139 | pdata = (struct omap_mbox_pdata *)oh->dev_attr; |
140 | pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata)); | |
3528c58e KH |
141 | WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n", |
142 | __func__, PTR_ERR(pdev)); | |
c40fae95 TL |
143 | } |
144 | #else | |
145 | static inline void omap_init_mbox(void) { } | |
c869c75c | 146 | #endif /* CONFIG_OMAP2PLUS_MBOX */ |
c40fae95 | 147 | |
9b6553cd | 148 | static inline void omap_init_sti(void) {} |
9b6553cd | 149 | |
f0fba2ad LG |
150 | #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE) |
151 | ||
152 | static struct platform_device omap_pcm = { | |
153 | .name = "omap-pcm-audio", | |
154 | .id = -1, | |
155 | }; | |
156 | ||
f0fba2ad LG |
157 | static void omap_init_audio(void) |
158 | { | |
f0fba2ad LG |
159 | platform_device_register(&omap_pcm); |
160 | } | |
161 | ||
162 | #else | |
163 | static inline void omap_init_audio(void) {} | |
164 | #endif | |
165 | ||
646e3ed1 | 166 | #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE) |
ed7eb9d9 | 167 | |
2203747c | 168 | #include <linux/platform_data/spi-omap2-mcspi.h> |
ed7eb9d9 | 169 | |
9cf793f9 | 170 | static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused) |
af41a12f | 171 | { |
3528c58e | 172 | struct platform_device *pdev; |
1a5d8190 C |
173 | char *name = "omap2_mcspi"; |
174 | struct omap2_mcspi_platform_config *pdata; | |
175 | static int spi_num; | |
176 | struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr; | |
177 | ||
178 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | |
179 | if (!pdata) { | |
180 | pr_err("Memory allocation for McSPI device failed\n"); | |
181 | return -ENOMEM; | |
182 | } | |
af41a12f | 183 | |
1a5d8190 C |
184 | pdata->num_cs = mcspi_attrib->num_chipselect; |
185 | switch (oh->class->rev) { | |
186 | case OMAP2_MCSPI_REV: | |
187 | case OMAP3_MCSPI_REV: | |
188 | pdata->regs_offset = 0; | |
189 | break; | |
190 | case OMAP4_MCSPI_REV: | |
191 | pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET; | |
192 | break; | |
193 | default: | |
194 | pr_err("Invalid McSPI Revision value\n"); | |
e0feca89 | 195 | kfree(pdata); |
1a5d8190 C |
196 | return -EINVAL; |
197 | } | |
af41a12f | 198 | |
1a5d8190 | 199 | spi_num++; |
c1d1cd59 | 200 | pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata)); |
3528c58e | 201 | WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n", |
1a5d8190 C |
202 | name, oh->name); |
203 | kfree(pdata); | |
204 | return 0; | |
af41a12f | 205 | } |
af41a12f TL |
206 | |
207 | static void omap_init_mcspi(void) | |
208 | { | |
1a5d8190 | 209 | omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL); |
ed7eb9d9 JY |
210 | } |
211 | ||
212 | #else | |
213 | static inline void omap_init_mcspi(void) {} | |
214 | #endif | |
215 | ||
4848d460 PW |
216 | /** |
217 | * omap_init_rng - bind the RNG hwmod to the RNG omap_device | |
218 | * | |
219 | * Bind the RNG hwmod to the RNG omap_device. No return value. | |
220 | */ | |
221 | static void omap_init_rng(void) | |
222 | { | |
223 | struct omap_hwmod *oh; | |
224 | struct platform_device *pdev; | |
225 | ||
226 | oh = omap_hwmod_lookup("rng"); | |
227 | if (!oh) | |
228 | return; | |
229 | ||
c1d1cd59 | 230 | pdev = omap_device_build("omap_rng", -1, oh, NULL, 0); |
4848d460 PW |
231 | WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n"); |
232 | } | |
88341334 | 233 | |
26f88e6e | 234 | static void __init omap_init_sham(void) |
646e3ed1 | 235 | { |
8c7bb573 MG |
236 | struct omap_hwmod *oh; |
237 | struct platform_device *pdev; | |
238 | ||
239 | oh = omap_hwmod_lookup("sham"); | |
240 | if (!oh) | |
241 | return; | |
242 | ||
243 | pdev = omap_device_build("omap-sham", -1, oh, NULL, 0); | |
244 | WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n"); | |
646e3ed1 | 245 | } |
646e3ed1 | 246 | |
14ae5564 | 247 | static void __init omap_init_aes(void) |
b744c679 | 248 | { |
77e2fd84 MG |
249 | struct omap_hwmod *oh; |
250 | struct platform_device *pdev; | |
251 | ||
252 | oh = omap_hwmod_lookup("aes"); | |
253 | if (!oh) | |
254 | return; | |
255 | ||
256 | pdev = omap_device_build("omap-aes", -1, oh, NULL, 0); | |
257 | WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n"); | |
b744c679 DK |
258 | } |
259 | ||
d8874665 TL |
260 | /*-------------------------------------------------------------------------*/ |
261 | ||
b227358d VH |
262 | #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \ |
263 | defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE) | |
264 | #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE) | |
265 | static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = { | |
266 | }; | |
267 | #else | |
268 | static struct resource omap_vout_resource[2] = { | |
269 | }; | |
270 | #endif | |
271 | ||
272 | static struct platform_device omap_vout_device = { | |
273 | .name = "omap_vout", | |
274 | .num_resources = ARRAY_SIZE(omap_vout_resource), | |
275 | .resource = &omap_vout_resource[0], | |
276 | .id = -1, | |
277 | }; | |
576e5bda AT |
278 | |
279 | int __init omap_init_vout(void) | |
b227358d | 280 | { |
576e5bda | 281 | return platform_device_register(&omap_vout_device); |
b227358d VH |
282 | } |
283 | #else | |
576e5bda | 284 | int __init omap_init_vout(void) { return 0; } |
b227358d VH |
285 | #endif |
286 | ||
1dbae815 TL |
287 | /*-------------------------------------------------------------------------*/ |
288 | ||
289 | static int __init omap2_init_devices(void) | |
290 | { | |
484202f4 MP |
291 | /* Enable dummy states for those platforms without pinctrl support */ |
292 | if (!of_have_populated_dt()) | |
293 | pinctrl_provide_dummies(); | |
294 | ||
81fbc5ef PW |
295 | /* |
296 | * please keep these calls, and their implementations above, | |
1dbae815 TL |
297 | * in alphabetical order so they're easier to sort through. |
298 | */ | |
f0fba2ad | 299 | omap_init_audio(); |
efcf1e50 | 300 | /* If dtb is there, the devices will be created dynamically */ |
259bd6ce | 301 | if (!of_have_populated_dt()) { |
dbd5f460 | 302 | omap_init_mbox(); |
efcf1e50 | 303 | omap_init_mcspi(); |
114d7a8b | 304 | omap_init_sham(); |
53335acc | 305 | omap_init_aes(); |
674ee08f | 306 | omap_init_rng(); |
259bd6ce | 307 | } |
9b6553cd | 308 | omap_init_sti(); |
1dbae815 TL |
309 | |
310 | return 0; | |
311 | } | |
b76c8b19 | 312 | omap_arch_initcall(omap2_init_devices); |
a8612809 TL |
313 | |
314 | static int __init omap_gpmc_init(void) | |
315 | { | |
316 | struct omap_hwmod *oh; | |
317 | struct platform_device *pdev; | |
318 | char *oh_name = "gpmc"; | |
319 | ||
320 | /* | |
321 | * if the board boots up with a populated DT, do not | |
322 | * manually add the device from this initcall | |
323 | */ | |
324 | if (of_have_populated_dt()) | |
325 | return -ENODEV; | |
326 | ||
327 | oh = omap_hwmod_lookup(oh_name); | |
328 | if (!oh) { | |
329 | pr_err("Could not look up %s\n", oh_name); | |
330 | return -ENODEV; | |
331 | } | |
332 | ||
333 | pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0); | |
334 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); | |
335 | ||
e44be50c | 336 | return PTR_ERR_OR_ZERO(pdev); |
a8612809 TL |
337 | } |
338 | omap_postcore_initcall(omap_gpmc_init); |