Merge tag 'drivers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6.git] / arch / arm / mach-omap2 / devices.c
blobaef96e45cb2049c2cebba2ad50e1e8a0a8036225
1 /*
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>
15 #include <linux/io.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/gpio.h>
19 #include <linux/slab.h>
20 #include <linux/of.h>
21 #include <linux/pinctrl/machine.h>
22 #include <linux/platform_data/omap4-keypad.h>
23 #include <linux/wl12xx.h>
24 #include <linux/platform_data/mailbox-omap.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/map.h>
29 #include <linux/omap-dma.h>
31 #include "iomap.h"
32 #include "omap_hwmod.h"
33 #include "omap_device.h"
34 #include "omap4-keypad.h"
36 #include "soc.h"
37 #include "common.h"
38 #include "mux.h"
39 #include "control.h"
40 #include "devices.h"
42 #define L3_MODULES_MAX_LEN 12
43 #define L3_MODULES 3
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
53 * multi-omap builds
55 if (!(cpu_is_omap34xx()))
56 return -ENODEV;
58 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
60 oh = omap_hwmod_lookup(oh_name);
62 if (!oh)
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)
75 int i;
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())
82 return -ENODEV;
85 * To avoid code running on other OMAPs in
86 * multi-omap builds
88 if (!cpu_is_omap44xx() && !soc_is_omap54xx())
89 return -ENODEV;
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);
95 if (!(oh[i]))
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",
123 .id = -1,
124 .num_resources = ARRAY_SIZE(omap2cam_resources),
125 .resource = omap2cam_resources,
127 #endif
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 = {
221 .name = "omap3isp",
222 .id = -1,
223 .num_resources = ARRAY_SIZE(omap3isp_resources),
224 .resource = omap3isp_resources,
227 static struct omap_iommu_arch_data omap3_isp_iommu = {
228 .name = "mmu_isp",
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)
243 return 0;
246 #endif
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);
253 #endif
256 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
257 *sdp4430_keypad_data, struct omap_board_data *bdata)
259 struct platform_device *pdev;
260 struct omap_hwmod *oh;
261 struct omap4_keypad_platform_data *keypad_data;
262 unsigned int id = -1;
263 char *oh_name = "kbd";
264 char *name = "omap4-keypad";
266 oh = omap_hwmod_lookup(oh_name);
267 if (!oh) {
268 pr_err("Could not look up %s\n", oh_name);
269 return -ENODEV;
272 keypad_data = sdp4430_keypad_data;
274 pdev = omap_device_build(name, id, oh, keypad_data,
275 sizeof(struct omap4_keypad_platform_data));
277 if (IS_ERR(pdev)) {
278 WARN(1, "Can't build omap_device for %s:%s.\n",
279 name, oh->name);
280 return PTR_ERR(pdev);
282 oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
284 return 0;
287 #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
288 static inline void __init omap_init_mbox(void)
290 struct omap_hwmod *oh;
291 struct platform_device *pdev;
292 struct omap_mbox_pdata *pdata;
294 oh = omap_hwmod_lookup("mailbox");
295 if (!oh) {
296 pr_err("%s: unable to find hwmod\n", __func__);
297 return;
299 if (!oh->dev_attr) {
300 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
301 return;
304 pdata = (struct omap_mbox_pdata *)oh->dev_attr;
305 pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
306 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
307 __func__, PTR_ERR(pdev));
309 #else
310 static inline void omap_init_mbox(void) { }
311 #endif /* CONFIG_OMAP2PLUS_MBOX */
313 static inline void omap_init_sti(void) {}
315 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
317 static struct platform_device omap_pcm = {
318 .name = "omap-pcm-audio",
319 .id = -1,
322 static void omap_init_audio(void)
324 platform_device_register(&omap_pcm);
327 #else
328 static inline void omap_init_audio(void) {}
329 #endif
331 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
332 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
334 static void __init omap_init_mcpdm(void)
336 struct omap_hwmod *oh;
337 struct platform_device *pdev;
339 oh = omap_hwmod_lookup("mcpdm");
340 if (!oh)
341 return;
343 pdev = omap_device_build("omap-mcpdm", -1, oh, NULL, 0);
344 WARN(IS_ERR(pdev), "Can't build omap_device for omap-mcpdm.\n");
346 #else
347 static inline void omap_init_mcpdm(void) {}
348 #endif
350 #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
351 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
353 static void __init omap_init_dmic(void)
355 struct omap_hwmod *oh;
356 struct platform_device *pdev;
358 oh = omap_hwmod_lookup("dmic");
359 if (!oh)
360 return;
362 pdev = omap_device_build("omap-dmic", -1, oh, NULL, 0);
363 WARN(IS_ERR(pdev), "Can't build omap_device for omap-dmic.\n");
365 #else
366 static inline void omap_init_dmic(void) {}
367 #endif
369 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
370 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
372 static struct platform_device omap_hdmi_audio = {
373 .name = "omap-hdmi-audio",
374 .id = -1,
377 static void __init omap_init_hdmi_audio(void)
379 struct omap_hwmod *oh;
380 struct platform_device *pdev;
382 oh = omap_hwmod_lookup("dss_hdmi");
383 if (!oh)
384 return;
386 pdev = omap_device_build("omap-hdmi-audio-dai", -1, oh, NULL, 0);
387 WARN(IS_ERR(pdev),
388 "Can't build omap_device for omap-hdmi-audio-dai.\n");
390 platform_device_register(&omap_hdmi_audio);
392 #else
393 static inline void omap_init_hdmi_audio(void) {}
394 #endif
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;
405 static int spi_num;
406 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
408 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
409 if (!pdata) {
410 pr_err("Memory allocation for McSPI device failed\n");
411 return -ENOMEM;
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;
419 break;
420 case OMAP4_MCSPI_REV:
421 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
422 break;
423 default:
424 pr_err("Invalid McSPI Revision value\n");
425 kfree(pdata);
426 return -EINVAL;
429 spi_num++;
430 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
431 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
432 name, oh->name);
433 kfree(pdata);
434 return 0;
437 static void omap_init_mcspi(void)
439 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
442 #else
443 static inline void omap_init_mcspi(void) {}
444 #endif
447 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
449 * Bind the RNG hwmod to the RNG omap_device. No return value.
451 static void omap_init_rng(void)
453 struct omap_hwmod *oh;
454 struct platform_device *pdev;
456 oh = omap_hwmod_lookup("rng");
457 if (!oh)
458 return;
460 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
461 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
464 static void __init omap_init_sham(void)
466 struct omap_hwmod *oh;
467 struct platform_device *pdev;
469 oh = omap_hwmod_lookup("sham");
470 if (!oh)
471 return;
473 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
474 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
477 static void __init omap_init_aes(void)
479 struct omap_hwmod *oh;
480 struct platform_device *pdev;
482 oh = omap_hwmod_lookup("aes");
483 if (!oh)
484 return;
486 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
487 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
490 /*-------------------------------------------------------------------------*/
492 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
493 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
494 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
495 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
497 #else
498 static struct resource omap_vout_resource[2] = {
500 #endif
502 static struct platform_device omap_vout_device = {
503 .name = "omap_vout",
504 .num_resources = ARRAY_SIZE(omap_vout_resource),
505 .resource = &omap_vout_resource[0],
506 .id = -1,
508 static void omap_init_vout(void)
510 if (platform_device_register(&omap_vout_device) < 0)
511 printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
513 #else
514 static inline void omap_init_vout(void) {}
515 #endif
517 #if IS_ENABLED(CONFIG_WL12XX)
519 static struct wl12xx_platform_data wl12xx __initdata;
521 void __init omap_init_wl12xx_of(void)
523 int ret;
525 if (!of_have_populated_dt())
526 return;
528 if (of_machine_is_compatible("ti,omap4-sdp")) {
529 wl12xx.board_ref_clock = WL12XX_REFCLOCK_26;
530 wl12xx.board_tcxo_clock = WL12XX_TCXOCLOCK_26;
531 wl12xx.irq = gpio_to_irq(53);
532 } else if (of_machine_is_compatible("ti,omap4-panda")) {
533 wl12xx.board_ref_clock = WL12XX_REFCLOCK_38;
534 wl12xx.irq = gpio_to_irq(53);
535 } else {
536 return;
539 ret = wl12xx_set_platform_data(&wl12xx);
540 if (ret) {
541 pr_err("error setting wl12xx data: %d\n", ret);
542 return;
545 #else
546 static inline void omap_init_wl12xx_of(void)
549 #endif
551 /*-------------------------------------------------------------------------*/
553 static int __init omap2_init_devices(void)
555 /* Enable dummy states for those platforms without pinctrl support */
556 if (!of_have_populated_dt())
557 pinctrl_provide_dummies();
560 * please keep these calls, and their implementations above,
561 * in alphabetical order so they're easier to sort through.
563 omap_init_audio();
564 omap_init_camera();
565 omap_init_hdmi_audio();
566 omap_init_mbox();
567 /* If dtb is there, the devices will be created dynamically */
568 if (!of_have_populated_dt()) {
569 omap_init_dmic();
570 omap_init_mcpdm();
571 omap_init_mcspi();
572 omap_init_sham();
573 omap_init_aes();
574 } else {
575 /* These can be removed when bindings are done */
576 omap_init_wl12xx_of();
578 omap_init_sti();
579 omap_init_rng();
580 omap_init_vout();
582 return 0;
584 omap_arch_initcall(omap2_init_devices);