Merge branch 'next/devel-samsung' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / 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/platform_data/omap4-keypad.h>
21
22 #include <asm/mach-types.h>
23 #include <asm/mach/map.h>
24
25 #include "iomap.h"
26 #include <plat/dma.h>
27 #include <plat/omap_hwmod.h>
28 #include <plat/omap_device.h>
29 #include <plat/omap4-keypad.h>
30
31 #include "soc.h"
32 #include "common.h"
33 #include "mux.h"
34 #include "control.h"
35 #include "devices.h"
36
37 #define L3_MODULES_MAX_LEN 12
38 #define L3_MODULES 3
39
40 static int __init omap3_l3_init(void)
41 {
42         struct omap_hwmod *oh;
43         struct platform_device *pdev;
44         char oh_name[L3_MODULES_MAX_LEN];
45
46         /*
47          * To avoid code running on other OMAPs in
48          * multi-omap builds
49          */
50         if (!(cpu_is_omap34xx()))
51                 return -ENODEV;
52
53         snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
54
55         oh = omap_hwmod_lookup(oh_name);
56
57         if (!oh)
58                 pr_err("could not look up %s\n", oh_name);
59
60         pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0,
61                                                            NULL, 0, 0);
62
63         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
64
65         return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
66 }
67 postcore_initcall(omap3_l3_init);
68
69 static int __init omap4_l3_init(void)
70 {
71         int i;
72         struct omap_hwmod *oh[3];
73         struct platform_device *pdev;
74         char oh_name[L3_MODULES_MAX_LEN];
75
76         /* If dtb is there, the devices will be created dynamically */
77         if (of_have_populated_dt())
78                 return -ENODEV;
79
80         /*
81          * To avoid code running on other OMAPs in
82          * multi-omap builds
83          */
84         if (!cpu_is_omap44xx() && !soc_is_omap54xx())
85                 return -ENODEV;
86
87         for (i = 0; i < L3_MODULES; i++) {
88                 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
89
90                 oh[i] = omap_hwmod_lookup(oh_name);
91                 if (!(oh[i]))
92                         pr_err("could not look up %s\n", oh_name);
93         }
94
95         pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL,
96                                                      0, NULL, 0, 0);
97
98         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
99
100         return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
101 }
102 postcore_initcall(omap4_l3_init);
103
104 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
105
106 static struct resource omap2cam_resources[] = {
107         {
108                 .start          = OMAP24XX_CAMERA_BASE,
109                 .end            = OMAP24XX_CAMERA_BASE + 0xfff,
110                 .flags          = IORESOURCE_MEM,
111         },
112         {
113                 .start          = 24 + OMAP_INTC_START,
114                 .flags          = IORESOURCE_IRQ,
115         }
116 };
117
118 static struct platform_device omap2cam_device = {
119         .name           = "omap24xxcam",
120         .id             = -1,
121         .num_resources  = ARRAY_SIZE(omap2cam_resources),
122         .resource       = omap2cam_resources,
123 };
124 #endif
125
126 #if defined(CONFIG_IOMMU_API)
127
128 #include <plat/iommu.h>
129
130 static struct resource omap3isp_resources[] = {
131         {
132                 .start          = OMAP3430_ISP_BASE,
133                 .end            = OMAP3430_ISP_END,
134                 .flags          = IORESOURCE_MEM,
135         },
136         {
137                 .start          = OMAP3430_ISP_CCP2_BASE,
138                 .end            = OMAP3430_ISP_CCP2_END,
139                 .flags          = IORESOURCE_MEM,
140         },
141         {
142                 .start          = OMAP3430_ISP_CCDC_BASE,
143                 .end            = OMAP3430_ISP_CCDC_END,
144                 .flags          = IORESOURCE_MEM,
145         },
146         {
147                 .start          = OMAP3430_ISP_HIST_BASE,
148                 .end            = OMAP3430_ISP_HIST_END,
149                 .flags          = IORESOURCE_MEM,
150         },
151         {
152                 .start          = OMAP3430_ISP_H3A_BASE,
153                 .end            = OMAP3430_ISP_H3A_END,
154                 .flags          = IORESOURCE_MEM,
155         },
156         {
157                 .start          = OMAP3430_ISP_PREV_BASE,
158                 .end            = OMAP3430_ISP_PREV_END,
159                 .flags          = IORESOURCE_MEM,
160         },
161         {
162                 .start          = OMAP3430_ISP_RESZ_BASE,
163                 .end            = OMAP3430_ISP_RESZ_END,
164                 .flags          = IORESOURCE_MEM,
165         },
166         {
167                 .start          = OMAP3430_ISP_SBL_BASE,
168                 .end            = OMAP3430_ISP_SBL_END,
169                 .flags          = IORESOURCE_MEM,
170         },
171         {
172                 .start          = OMAP3430_ISP_CSI2A_REGS1_BASE,
173                 .end            = OMAP3430_ISP_CSI2A_REGS1_END,
174                 .flags          = IORESOURCE_MEM,
175         },
176         {
177                 .start          = OMAP3430_ISP_CSIPHY2_BASE,
178                 .end            = OMAP3430_ISP_CSIPHY2_END,
179                 .flags          = IORESOURCE_MEM,
180         },
181         {
182                 .start          = OMAP3630_ISP_CSI2A_REGS2_BASE,
183                 .end            = OMAP3630_ISP_CSI2A_REGS2_END,
184                 .flags          = IORESOURCE_MEM,
185         },
186         {
187                 .start          = OMAP3630_ISP_CSI2C_REGS1_BASE,
188                 .end            = OMAP3630_ISP_CSI2C_REGS1_END,
189                 .flags          = IORESOURCE_MEM,
190         },
191         {
192                 .start          = OMAP3630_ISP_CSIPHY1_BASE,
193                 .end            = OMAP3630_ISP_CSIPHY1_END,
194                 .flags          = IORESOURCE_MEM,
195         },
196         {
197                 .start          = OMAP3630_ISP_CSI2C_REGS2_BASE,
198                 .end            = OMAP3630_ISP_CSI2C_REGS2_END,
199                 .flags          = IORESOURCE_MEM,
200         },
201         {
202                 .start          = 24 + OMAP_INTC_START,
203                 .flags          = IORESOURCE_IRQ,
204         }
205 };
206
207 static struct platform_device omap3isp_device = {
208         .name           = "omap3isp",
209         .id             = -1,
210         .num_resources  = ARRAY_SIZE(omap3isp_resources),
211         .resource       = omap3isp_resources,
212 };
213
214 static struct omap_iommu_arch_data omap3_isp_iommu = {
215         .name = "isp",
216 };
217
218 int omap3_init_camera(struct isp_platform_data *pdata)
219 {
220         omap3isp_device.dev.platform_data = pdata;
221         omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
222
223         return platform_device_register(&omap3isp_device);
224 }
225
226 #else /* !CONFIG_IOMMU_API */
227
228 int omap3_init_camera(struct isp_platform_data *pdata)
229 {
230         return 0;
231 }
232
233 #endif
234
235 static inline void omap_init_camera(void)
236 {
237 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
238         if (cpu_is_omap24xx())
239                 platform_device_register(&omap2cam_device);
240 #endif
241 }
242
243 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
244                         *sdp4430_keypad_data, struct omap_board_data *bdata)
245 {
246         struct platform_device *pdev;
247         struct omap_hwmod *oh;
248         struct omap4_keypad_platform_data *keypad_data;
249         unsigned int id = -1;
250         char *oh_name = "kbd";
251         char *name = "omap4-keypad";
252
253         oh = omap_hwmod_lookup(oh_name);
254         if (!oh) {
255                 pr_err("Could not look up %s\n", oh_name);
256                 return -ENODEV;
257         }
258
259         keypad_data = sdp4430_keypad_data;
260
261         pdev = omap_device_build(name, id, oh, keypad_data,
262                         sizeof(struct omap4_keypad_platform_data), NULL, 0, 0);
263
264         if (IS_ERR(pdev)) {
265                 WARN(1, "Can't build omap_device for %s:%s.\n",
266                                                 name, oh->name);
267                 return PTR_ERR(pdev);
268         }
269         oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
270
271         return 0;
272 }
273
274 #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
275 static inline void __init omap_init_mbox(void)
276 {
277         struct omap_hwmod *oh;
278         struct platform_device *pdev;
279
280         oh = omap_hwmod_lookup("mailbox");
281         if (!oh) {
282                 pr_err("%s: unable to find hwmod\n", __func__);
283                 return;
284         }
285
286         pdev = omap_device_build("omap-mailbox", -1, oh, NULL, 0, NULL, 0, 0);
287         WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
288                                                 __func__, PTR_ERR(pdev));
289 }
290 #else
291 static inline void omap_init_mbox(void) { }
292 #endif /* CONFIG_OMAP_MBOX_FWK */
293
294 static inline void omap_init_sti(void) {}
295
296 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
297
298 static struct platform_device omap_pcm = {
299         .name   = "omap-pcm-audio",
300         .id     = -1,
301 };
302
303 static void omap_init_audio(void)
304 {
305         platform_device_register(&omap_pcm);
306 }
307
308 #else
309 static inline void omap_init_audio(void) {}
310 #endif
311
312 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
313                 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
314
315 static void __init omap_init_mcpdm(void)
316 {
317         struct omap_hwmod *oh;
318         struct platform_device *pdev;
319
320         oh = omap_hwmod_lookup("mcpdm");
321         if (!oh) {
322                 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
323                 return;
324         }
325
326         pdev = omap_device_build("omap-mcpdm", -1, oh, NULL, 0, NULL, 0, 0);
327         WARN(IS_ERR(pdev), "Can't build omap_device for omap-mcpdm.\n");
328 }
329 #else
330 static inline void omap_init_mcpdm(void) {}
331 #endif
332
333 #if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
334                 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
335
336 static void __init omap_init_dmic(void)
337 {
338         struct omap_hwmod *oh;
339         struct platform_device *pdev;
340
341         oh = omap_hwmod_lookup("dmic");
342         if (!oh) {
343                 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
344                 return;
345         }
346
347         pdev = omap_device_build("omap-dmic", -1, oh, NULL, 0, NULL, 0, 0);
348         WARN(IS_ERR(pdev), "Can't build omap_device for omap-dmic.\n");
349 }
350 #else
351 static inline void omap_init_dmic(void) {}
352 #endif
353
354 #if defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI) || \
355                 defined(CONFIG_SND_OMAP_SOC_OMAP_HDMI_MODULE)
356
357 static struct platform_device omap_hdmi_audio = {
358         .name   = "omap-hdmi-audio",
359         .id     = -1,
360 };
361
362 static void __init omap_init_hdmi_audio(void)
363 {
364         struct omap_hwmod *oh;
365         struct platform_device *pdev;
366
367         oh = omap_hwmod_lookup("dss_hdmi");
368         if (!oh) {
369                 printk(KERN_ERR "Could not look up dss_hdmi hw_mod\n");
370                 return;
371         }
372
373         pdev = omap_device_build("omap-hdmi-audio-dai",
374                 -1, oh, NULL, 0, NULL, 0, 0);
375         WARN(IS_ERR(pdev),
376              "Can't build omap_device for omap-hdmi-audio-dai.\n");
377
378         platform_device_register(&omap_hdmi_audio);
379 }
380 #else
381 static inline void omap_init_hdmi_audio(void) {}
382 #endif
383
384 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
385
386 #include <plat/mcspi.h>
387
388 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
389 {
390         struct platform_device *pdev;
391         char *name = "omap2_mcspi";
392         struct omap2_mcspi_platform_config *pdata;
393         static int spi_num;
394         struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
395
396         pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
397         if (!pdata) {
398                 pr_err("Memory allocation for McSPI device failed\n");
399                 return -ENOMEM;
400         }
401
402         pdata->num_cs = mcspi_attrib->num_chipselect;
403         switch (oh->class->rev) {
404         case OMAP2_MCSPI_REV:
405         case OMAP3_MCSPI_REV:
406                         pdata->regs_offset = 0;
407                         break;
408         case OMAP4_MCSPI_REV:
409                         pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
410                         break;
411         default:
412                         pr_err("Invalid McSPI Revision value\n");
413                         kfree(pdata);
414                         return -EINVAL;
415         }
416
417         spi_num++;
418         pdev = omap_device_build(name, spi_num, oh, pdata,
419                                 sizeof(*pdata), NULL, 0, 0);
420         WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
421                                 name, oh->name);
422         kfree(pdata);
423         return 0;
424 }
425
426 static void omap_init_mcspi(void)
427 {
428         omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
429 }
430
431 #else
432 static inline void omap_init_mcspi(void) {}
433 #endif
434
435 static struct resource omap2_pmu_resource = {
436         .start  = 3 + OMAP_INTC_START,
437         .flags  = IORESOURCE_IRQ,
438 };
439
440 static struct resource omap3_pmu_resource = {
441         .start  = 3 + OMAP_INTC_START,
442         .flags  = IORESOURCE_IRQ,
443 };
444
445 static struct platform_device omap_pmu_device = {
446         .name           = "arm-pmu",
447         .id             = -1,
448         .num_resources  = 1,
449 };
450
451 static void omap_init_pmu(void)
452 {
453         if (cpu_is_omap24xx())
454                 omap_pmu_device.resource = &omap2_pmu_resource;
455         else if (cpu_is_omap34xx())
456                 omap_pmu_device.resource = &omap3_pmu_resource;
457         else
458                 return;
459
460         platform_device_register(&omap_pmu_device);
461 }
462
463
464 #if defined(CONFIG_CRYPTO_DEV_OMAP_SHAM) || defined(CONFIG_CRYPTO_DEV_OMAP_SHAM_MODULE)
465
466 #ifdef CONFIG_ARCH_OMAP2
467 static struct resource omap2_sham_resources[] = {
468         {
469                 .start  = OMAP24XX_SEC_SHA1MD5_BASE,
470                 .end    = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
471                 .flags  = IORESOURCE_MEM,
472         },
473         {
474                 .start  = 51 + OMAP_INTC_START,
475                 .flags  = IORESOURCE_IRQ,
476         }
477 };
478 static int omap2_sham_resources_sz = ARRAY_SIZE(omap2_sham_resources);
479 #else
480 #define omap2_sham_resources            NULL
481 #define omap2_sham_resources_sz         0
482 #endif
483
484 #ifdef CONFIG_ARCH_OMAP3
485 static struct resource omap3_sham_resources[] = {
486         {
487                 .start  = OMAP34XX_SEC_SHA1MD5_BASE,
488                 .end    = OMAP34XX_SEC_SHA1MD5_BASE + 0x64,
489                 .flags  = IORESOURCE_MEM,
490         },
491         {
492                 .start  = 49 + OMAP_INTC_START,
493                 .flags  = IORESOURCE_IRQ,
494         },
495         {
496                 .start  = OMAP34XX_DMA_SHA1MD5_RX,
497                 .flags  = IORESOURCE_DMA,
498         }
499 };
500 static int omap3_sham_resources_sz = ARRAY_SIZE(omap3_sham_resources);
501 #else
502 #define omap3_sham_resources            NULL
503 #define omap3_sham_resources_sz         0
504 #endif
505
506 static struct platform_device sham_device = {
507         .name           = "omap-sham",
508         .id             = -1,
509 };
510
511 static void omap_init_sham(void)
512 {
513         if (cpu_is_omap24xx()) {
514                 sham_device.resource = omap2_sham_resources;
515                 sham_device.num_resources = omap2_sham_resources_sz;
516         } else if (cpu_is_omap34xx()) {
517                 sham_device.resource = omap3_sham_resources;
518                 sham_device.num_resources = omap3_sham_resources_sz;
519         } else {
520                 pr_err("%s: platform not supported\n", __func__);
521                 return;
522         }
523         platform_device_register(&sham_device);
524 }
525 #else
526 static inline void omap_init_sham(void) { }
527 #endif
528
529 #if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)
530
531 #ifdef CONFIG_ARCH_OMAP2
532 static struct resource omap2_aes_resources[] = {
533         {
534                 .start  = OMAP24XX_SEC_AES_BASE,
535                 .end    = OMAP24XX_SEC_AES_BASE + 0x4C,
536                 .flags  = IORESOURCE_MEM,
537         },
538         {
539                 .start  = OMAP24XX_DMA_AES_TX,
540                 .flags  = IORESOURCE_DMA,
541         },
542         {
543                 .start  = OMAP24XX_DMA_AES_RX,
544                 .flags  = IORESOURCE_DMA,
545         }
546 };
547 static int omap2_aes_resources_sz = ARRAY_SIZE(omap2_aes_resources);
548 #else
549 #define omap2_aes_resources             NULL
550 #define omap2_aes_resources_sz          0
551 #endif
552
553 #ifdef CONFIG_ARCH_OMAP3
554 static struct resource omap3_aes_resources[] = {
555         {
556                 .start  = OMAP34XX_SEC_AES_BASE,
557                 .end    = OMAP34XX_SEC_AES_BASE + 0x4C,
558                 .flags  = IORESOURCE_MEM,
559         },
560         {
561                 .start  = OMAP34XX_DMA_AES2_TX,
562                 .flags  = IORESOURCE_DMA,
563         },
564         {
565                 .start  = OMAP34XX_DMA_AES2_RX,
566                 .flags  = IORESOURCE_DMA,
567         }
568 };
569 static int omap3_aes_resources_sz = ARRAY_SIZE(omap3_aes_resources);
570 #else
571 #define omap3_aes_resources             NULL
572 #define omap3_aes_resources_sz          0
573 #endif
574
575 static struct platform_device aes_device = {
576         .name           = "omap-aes",
577         .id             = -1,
578 };
579
580 static void omap_init_aes(void)
581 {
582         if (cpu_is_omap24xx()) {
583                 aes_device.resource = omap2_aes_resources;
584                 aes_device.num_resources = omap2_aes_resources_sz;
585         } else if (cpu_is_omap34xx()) {
586                 aes_device.resource = omap3_aes_resources;
587                 aes_device.num_resources = omap3_aes_resources_sz;
588         } else {
589                 pr_err("%s: platform not supported\n", __func__);
590                 return;
591         }
592         platform_device_register(&aes_device);
593 }
594
595 #else
596 static inline void omap_init_aes(void) { }
597 #endif
598
599 /*-------------------------------------------------------------------------*/
600
601 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
602         defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
603 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
604 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
605 };
606 #else
607 static struct resource omap_vout_resource[2] = {
608 };
609 #endif
610
611 static struct platform_device omap_vout_device = {
612         .name           = "omap_vout",
613         .num_resources  = ARRAY_SIZE(omap_vout_resource),
614         .resource       = &omap_vout_resource[0],
615         .id             = -1,
616 };
617 static void omap_init_vout(void)
618 {
619         if (platform_device_register(&omap_vout_device) < 0)
620                 printk(KERN_ERR "Unable to register OMAP-VOUT device\n");
621 }
622 #else
623 static inline void omap_init_vout(void) {}
624 #endif
625
626 /*-------------------------------------------------------------------------*/
627
628 static int __init omap2_init_devices(void)
629 {
630         /*
631          * please keep these calls, and their implementations above,
632          * in alphabetical order so they're easier to sort through.
633          */
634         omap_init_audio();
635         omap_init_camera();
636         omap_init_hdmi_audio();
637         omap_init_mbox();
638         /* If dtb is there, the devices will be created dynamically */
639         if (!of_have_populated_dt()) {
640                 omap_init_dmic();
641                 omap_init_mcpdm();
642                 omap_init_mcspi();
643         }
644         omap_init_pmu();
645         omap_init_sti();
646         omap_init_sham();
647         omap_init_aes();
648         omap_init_vout();
649
650         return 0;
651 }
652 arch_initcall(omap2_init_devices);
653
654 #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
655 static int __init omap_init_wdt(void)
656 {
657         int id = -1;
658         struct platform_device *pdev;
659         struct omap_hwmod *oh;
660         char *oh_name = "wd_timer2";
661         char *dev_name = "omap_wdt";
662
663         if (!cpu_class_is_omap2() || of_have_populated_dt())
664                 return 0;
665
666         oh = omap_hwmod_lookup(oh_name);
667         if (!oh) {
668                 pr_err("Could not look up wd_timer%d hwmod\n", id);
669                 return -EINVAL;
670         }
671
672         pdev = omap_device_build(dev_name, id, oh, NULL, 0, NULL, 0, 0);
673         WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
674                                 dev_name, oh->name);
675         return 0;
676 }
677 subsys_initcall(omap_init_wdt);
678 #endif