]> Pileus Git - ~andy/linux/blob - arch/arm/mach-omap2/devices.c
ARM: OMAP2+: Use pdata quirks for wl12xx legacy init
[~andy/linux] / arch / arm / mach-omap2 / devices.c
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  */
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/slab.h>
19 #include <linux/of.h>
20 #include <linux/pinctrl/machine.h>
21 #include <linux/platform_data/omap4-keypad.h>
22 #include <linux/platform_data/mailbox-omap.h>
23
24 #include <asm/mach-types.h>
25 #include <asm/mach/map.h>
26
27 #include <linux/omap-dma.h>
28
29 #include "iomap.h"
30 #include "omap_hwmod.h"
31 #include "omap_device.h"
32 #include "omap4-keypad.h"
33
34 #include "soc.h"
35 #include "common.h"
36 #include "mux.h"
37 #include "control.h"
38 #include "devices.h"
39
40 #define L3_MODULES_MAX_LEN 12
41 #define L3_MODULES 3
42
43 static int __init omap3_l3_init(void)
44 {
45         struct omap_hwmod *oh;
46         struct platform_device *pdev;
47         char oh_name[L3_MODULES_MAX_LEN];
48
49         /*
50          * To avoid code running on other OMAPs in
51          * multi-omap builds
52          */
53         if (!(cpu_is_omap34xx()))
54                 return -ENODEV;
55
56         snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
57
58         oh = omap_hwmod_lookup(oh_name);
59
60         if (!oh)
61                 pr_err("could not look up %s\n", oh_name);
62
63         pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
64
65         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
66
67         return PTR_RET(pdev);
68 }
69 omap_postcore_initcall(omap3_l3_init);
70
71 static int __init omap4_l3_init(void)
72 {
73         int i;
74         struct omap_hwmod *oh[3];
75         struct platform_device *pdev;
76         char oh_name[L3_MODULES_MAX_LEN];
77
78         /* If dtb is there, the devices will be created dynamically */
79         if (of_have_populated_dt())
80                 return -ENODEV;
81
82         /*
83          * To avoid code running on other OMAPs in
84          * multi-omap builds
85          */
86         if (!cpu_is_omap44xx() && !soc_is_omap54xx())
87                 return -ENODEV;
88
89         for (i = 0; i < L3_MODULES; i++) {
90                 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
91
92                 oh[i] = omap_hwmod_lookup(oh_name);
93                 if (!(oh[i]))
94                         pr_err("could not look up %s\n", oh_name);
95         }
96
97         pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL, 0);
98
99         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
100
101         return PTR_RET(pdev);
102 }
103 omap_postcore_initcall(omap4_l3_init);
104
105 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
106
107 static struct resource omap2cam_resources[] = {
108         {
109                 .start          = OMAP24XX_CAMERA_BASE,
110                 .end            = OMAP24XX_CAMERA_BASE + 0xfff,
111                 .flags          = IORESOURCE_MEM,
112         },
113         {
114                 .start          = 24 + OMAP_INTC_START,
115                 .flags          = IORESOURCE_IRQ,
116         }
117 };
118
119 static struct platform_device omap2cam_device = {
120         .name           = "omap24xxcam",
121         .id             = -1,
122         .num_resources  = ARRAY_SIZE(omap2cam_resources),
123         .resource       = omap2cam_resources,
124 };
125 #endif
126
127 #if defined(CONFIG_IOMMU_API)
128
129 #include <linux/platform_data/iommu-omap.h>
130
131 static struct resource omap3isp_resources[] = {
132         {
133                 .start          = OMAP3430_ISP_BASE,
134                 .end            = OMAP3430_ISP_END,
135                 .flags          = IORESOURCE_MEM,
136         },
137         {
138                 .start          = OMAP3430_ISP_CCP2_BASE,
139                 .end            = OMAP3430_ISP_CCP2_END,
140                 .flags          = IORESOURCE_MEM,
141         },
142         {
143                 .start          = OMAP3430_ISP_CCDC_BASE,
144                 .end            = OMAP3430_ISP_CCDC_END,
145                 .flags          = IORESOURCE_MEM,
146         },
147         {
148                 .start          = OMAP3430_ISP_HIST_BASE,
149                 .end            = OMAP3430_ISP_HIST_END,
150                 .flags          = IORESOURCE_MEM,
151         },
152         {
153                 .start          = OMAP3430_ISP_H3A_BASE,
154                 .end            = OMAP3430_ISP_H3A_END,
155                 .flags          = IORESOURCE_MEM,
156         },
157         {
158                 .start          = OMAP3430_ISP_PREV_BASE,
159                 .end            = OMAP3430_ISP_PREV_END,
160                 .flags          = IORESOURCE_MEM,
161         },
162         {
163                 .start          = OMAP3430_ISP_RESZ_BASE,
164                 .end            = OMAP3430_ISP_RESZ_END,
165                 .flags          = IORESOURCE_MEM,
166         },
167         {
168                 .start          = OMAP3430_ISP_SBL_BASE,
169                 .end            = OMAP3430_ISP_SBL_END,
170                 .flags          = IORESOURCE_MEM,
171         },
172         {
173                 .start          = OMAP3430_ISP_CSI2A_REGS1_BASE,
174                 .end            = OMAP3430_ISP_CSI2A_REGS1_END,
175                 .flags          = IORESOURCE_MEM,
176         },
177         {
178                 .start          = OMAP3430_ISP_CSIPHY2_BASE,
179                 .end            = OMAP3430_ISP_CSIPHY2_END,
180                 .flags          = IORESOURCE_MEM,
181         },
182         {
183                 .start          = OMAP3630_ISP_CSI2A_REGS2_BASE,
184                 .end            = OMAP3630_ISP_CSI2A_REGS2_END,
185                 .flags          = IORESOURCE_MEM,
186         },
187         {
188                 .start          = OMAP3630_ISP_CSI2C_REGS1_BASE,
189                 .end            = OMAP3630_ISP_CSI2C_REGS1_END,
190                 .flags          = IORESOURCE_MEM,
191         },
192         {
193                 .start          = OMAP3630_ISP_CSIPHY1_BASE,
194                 .end            = OMAP3630_ISP_CSIPHY1_END,
195                 .flags          = IORESOURCE_MEM,
196         },
197         {
198                 .start          = OMAP3630_ISP_CSI2C_REGS2_BASE,
199                 .end            = OMAP3630_ISP_CSI2C_REGS2_END,
200                 .flags          = IORESOURCE_MEM,
201         },
202         {
203                 .start          = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE,
204                 .end            = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE + 3,
205                 .flags          = IORESOURCE_MEM,
206         },
207         {
208                 .start          = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL,
209                 .end            = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL + 3,
210                 .flags          = IORESOURCE_MEM,
211         },
212         {
213                 .start          = 24 + OMAP_INTC_START,
214                 .flags          = IORESOURCE_IRQ,
215         }
216 };
217
218 static struct platform_device omap3isp_device = {
219         .name           = "omap3isp",
220         .id             = -1,
221         .num_resources  = ARRAY_SIZE(omap3isp_resources),
222         .resource       = omap3isp_resources,
223 };
224
225 static struct omap_iommu_arch_data omap3_isp_iommu = {
226         .name = "mmu_isp",
227 };
228
229 int omap3_init_camera(struct isp_platform_data *pdata)
230 {
231         omap3isp_device.dev.platform_data = pdata;
232         omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
233
234         return platform_device_register(&omap3isp_device);
235 }
236
237 #else /* !CONFIG_IOMMU_API */
238
239 int omap3_init_camera(struct isp_platform_data *pdata)
240 {
241         return 0;
242 }
243
244 #endif
245
246 static inline void omap_init_camera(void)
247 {
248 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
249         if (cpu_is_omap24xx())
250                 platform_device_register(&omap2cam_device);
251 #endif
252 }
253
254 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
255                         *sdp4430_keypad_data, struct omap_board_data *bdata)
256 {
257         struct platform_device *pdev;
258         struct omap_hwmod *oh;
259         struct omap4_keypad_platform_data *keypad_data;
260         unsigned int id = -1;
261         char *oh_name = "kbd";
262         char *name = "omap4-keypad";
263
264         oh = omap_hwmod_lookup(oh_name);
265         if (!oh) {
266                 pr_err("Could not look up %s\n", oh_name);
267                 return -ENODEV;
268         }
269
270         keypad_data = sdp4430_keypad_data;
271
272         pdev = omap_device_build(name, id, oh, keypad_data,
273                                  sizeof(struct omap4_keypad_platform_data));
274
275         if (IS_ERR(pdev)) {
276                 WARN(1, "Can't build omap_device for %s:%s.\n",
277                                                 name, oh->name);
278                 return PTR_ERR(pdev);
279         }
280         oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
281
282         return 0;
283 }
284
285 #if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
286 static inline void __init omap_init_mbox(void)
287 {
288         struct omap_hwmod *oh;
289         struct platform_device *pdev;
290         struct omap_mbox_pdata *pdata;
291
292         oh = omap_hwmod_lookup("mailbox");
293         if (!oh) {
294                 pr_err("%s: unable to find hwmod\n", __func__);
295                 return;
296         }
297         if (!oh->dev_attr) {
298                 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
299                 return;
300         }
301
302         pdata = (struct omap_mbox_pdata *)oh->dev_attr;
303         pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
304         WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
305                                                 __func__, PTR_ERR(pdev));
306 }
307 #else
308 static inline void omap_init_mbox(void) { }
309 #endif /* CONFIG_OMAP2PLUS_MBOX */
310
311 static inline void omap_init_sti(void) {}
312
313 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
314
315 static struct platform_device omap_pcm = {
316         .name   = "omap-pcm-audio",
317         .id     = -1,
318 };
319
320 static void omap_init_audio(void)
321 {
322         platform_device_register(&omap_pcm);
323 }
324
325 #else
326 static inline void omap_init_audio(void) {}
327 #endif
328
329 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
330                 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
331
332 static struct platform_device omap_hdmi_audio = {
333         .name   = "omap-hdmi-audio",
334         .id     = -1,
335 };
336
337 static void __init omap_init_hdmi_audio(void)
338 {
339         struct omap_hwmod *oh;
340         struct platform_device *pdev;
341
342         oh = omap_hwmod_lookup("dss_hdmi");
343         if (!oh)
344                 return;
345
346         pdev = omap_device_build("omap-hdmi-audio-dai", -1, oh, NULL, 0);
347         WARN(IS_ERR(pdev),
348              "Can't build omap_device for omap-hdmi-audio-dai.\n");
349
350         platform_device_register(&omap_hdmi_audio);
351 }
352 #else
353 static inline void omap_init_hdmi_audio(void) {}
354 #endif
355
356 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
357
358 #include <linux/platform_data/spi-omap2-mcspi.h>
359
360 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
361 {
362         struct platform_device *pdev;
363         char *name = "omap2_mcspi";
364         struct omap2_mcspi_platform_config *pdata;
365         static int spi_num;
366         struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
367
368         pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
369         if (!pdata) {
370                 pr_err("Memory allocation for McSPI device failed\n");
371                 return -ENOMEM;
372         }
373
374         pdata->num_cs = mcspi_attrib->num_chipselect;
375         switch (oh->class->rev) {
376         case OMAP2_MCSPI_REV:
377         case OMAP3_MCSPI_REV:
378                         pdata->regs_offset = 0;
379                         break;
380         case OMAP4_MCSPI_REV:
381                         pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
382                         break;
383         default:
384                         pr_err("Invalid McSPI Revision value\n");
385                         kfree(pdata);
386                         return -EINVAL;
387         }
388
389         spi_num++;
390         pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
391         WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
392                                 name, oh->name);
393         kfree(pdata);
394         return 0;
395 }
396
397 static void omap_init_mcspi(void)
398 {
399         omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
400 }
401
402 #else
403 static inline void omap_init_mcspi(void) {}
404 #endif
405
406 /**
407  * omap_init_rng - bind the RNG hwmod to the RNG omap_device
408  *
409  * Bind the RNG hwmod to the RNG omap_device.  No return value.
410  */
411 static void omap_init_rng(void)
412 {
413         struct omap_hwmod *oh;
414         struct platform_device *pdev;
415
416         oh = omap_hwmod_lookup("rng");
417         if (!oh)
418                 return;
419
420         pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
421         WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
422 }
423
424 static void __init omap_init_sham(void)
425 {
426         struct omap_hwmod *oh;
427         struct platform_device *pdev;
428
429         oh = omap_hwmod_lookup("sham");
430         if (!oh)
431                 return;
432
433         pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
434         WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
435 }
436
437 static void __init omap_init_aes(void)
438 {
439         struct omap_hwmod *oh;
440         struct platform_device *pdev;
441
442         oh = omap_hwmod_lookup("aes");
443         if (!oh)
444                 return;
445
446         pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
447         WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
448 }
449
450 /*-------------------------------------------------------------------------*/
451
452 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
453         defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
454 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
455 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
456 };
457 #else
458 static struct resource omap_vout_resource[2] = {
459 };
460 #endif
461
462 static struct platform_device omap_vout_device = {
463         .name           = "omap_vout",
464         .num_resources  = ARRAY_SIZE(omap_vout_resource),
465         .resource       = &omap_vout_resource[0],
466         .id             = -1,
467 };
468 static void omap_init_vout(void)
469 {
470         if (platform_device_register(&omap_vout_device) < 0)
471                 printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
472 }
473 #else
474 static inline void omap_init_vout(void) {}
475 #endif
476
477 /*-------------------------------------------------------------------------*/
478
479 static int __init omap2_init_devices(void)
480 {
481         /* Enable dummy states for those platforms without pinctrl support */
482         if (!of_have_populated_dt())
483                 pinctrl_provide_dummies();
484
485         /*
486          * please keep these calls, and their implementations above,
487          * in alphabetical order so they're easier to sort through.
488          */
489         omap_init_audio();
490         omap_init_camera();
491         omap_init_hdmi_audio();
492         omap_init_mbox();
493         /* If dtb is there, the devices will be created dynamically */
494         if (!of_have_populated_dt()) {
495                 omap_init_mcspi();
496                 omap_init_sham();
497                 omap_init_aes();
498                 omap_init_rng();
499         }
500         omap_init_sti();
501         omap_init_vout();
502
503         return 0;
504 }
505 omap_arch_initcall(omap2_init_devices);