]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/devices.c
Merge branch 'for-tony-mailbox'
[linux-2.6-omap-h63xx.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
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/io.h>
17 #include <linux/clk.h>
18
19 #include <mach/hardware.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/map.h>
22
23 #include <mach/control.h>
24 #include <mach/tc.h>
25 #include <mach/board.h>
26 #include <mach/mux.h>
27 #include <mach/gpio.h>
28 #include <mach/eac.h>
29 #include <mach/mmc.h>
30
31 #if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
32
33 static struct resource cam_resources[] = {
34         {
35                 .start          = OMAP24XX_CAMERA_BASE,
36                 .end            = OMAP24XX_CAMERA_BASE + 0xfff,
37                 .flags          = IORESOURCE_MEM,
38         },
39         {
40                 .start          = INT_24XX_CAM_IRQ,
41                 .flags          = IORESOURCE_IRQ,
42         }
43 };
44
45 static struct platform_device omap_cam_device = {
46         .name           = "omap24xxcam",
47         .id             = -1,
48         .num_resources  = ARRAY_SIZE(cam_resources),
49         .resource       = cam_resources,
50 };
51
52 static inline void omap_init_camera(void)
53 {
54         platform_device_register(&omap_cam_device);
55 }
56
57 #elif defined(CONFIG_VIDEO_OMAP3) || defined(CONFIG_VIDEO_OMAP3_MODULE)
58
59 static struct resource cam_resources[] = {
60         {
61                 .start          = OMAP34XX_CAMERA_BASE,
62                 .end            = OMAP34XX_CAMERA_BASE + 0x1B70,
63                 .flags          = IORESOURCE_MEM,
64         },
65         {
66                 .start          = INT_34XX_CAM_IRQ,
67                 .flags          = IORESOURCE_IRQ,
68         }
69 };
70
71 static struct platform_device omap_cam_device = {
72         .name           = "omap34xxcam",
73         .id             = -1,
74         .num_resources  = ARRAY_SIZE(cam_resources),
75         .resource       = cam_resources,
76 };
77
78 static inline void omap_init_camera(void)
79 {
80         platform_device_register(&omap_cam_device);
81 }
82 #else
83 static inline void omap_init_camera(void)
84 {
85 }
86 #endif
87
88 #if defined(CONFIG_OMAP_MBOX_FWK) || defined(CONFIG_OMAP_MBOX_FWK_MODULE)
89
90 #define MBOX_REG_SIZE   0x120
91
92 static struct resource omap2_mbox_resources[] = {
93         {
94                 .start          = OMAP24XX_MAILBOX_BASE,
95                 .end            = OMAP24XX_MAILBOX_BASE + MBOX_REG_SIZE - 1,
96                 .flags          = IORESOURCE_MEM,
97         },
98         {
99                 .start          = INT_24XX_MAIL_U0_MPU,
100                 .flags          = IORESOURCE_IRQ,
101         },
102         {
103                 .start          = INT_24XX_MAIL_U3_MPU,
104                 .flags          = IORESOURCE_IRQ,
105         },
106 };
107
108 static struct resource omap3_mbox_resources[] = {
109         {
110                 .start          = OMAP34XX_MAILBOX_BASE,
111                 .end            = OMAP34XX_MAILBOX_BASE + MBOX_REG_SIZE - 1,
112                 .flags          = IORESOURCE_MEM,
113         },
114         {
115                 .start          = INT_34XX_MAIL_U0_MPU,
116                 .flags          = IORESOURCE_IRQ,
117         },
118 };
119
120 static struct platform_device mbox_device = {
121         .name           = "omap2-mailbox",
122         .id             = -1,
123 };
124
125 static inline void omap_init_mbox(void)
126 {
127         if (cpu_is_omap2420()) {
128                 mbox_device.num_resources = ARRAY_SIZE(omap2_mbox_resources);
129                 mbox_device.resource = omap2_mbox_resources;
130         } else if (cpu_is_omap3430()) {
131                 mbox_device.num_resources = ARRAY_SIZE(omap3_mbox_resources);
132                 mbox_device.resource = omap3_mbox_resources;
133         } else {
134                 return;
135         }
136         platform_device_register(&mbox_device);
137 }
138 #else
139 static inline void omap_init_mbox(void) { }
140 #endif /* CONFIG_OMAP_MBOX_FWK */
141
142 #if defined(CONFIG_OMAP_STI)
143
144 #if defined(CONFIG_ARCH_OMAP2)
145
146 #define OMAP2_STI_BASE          0x48068000
147 #define OMAP2_STI_CHANNEL_BASE  0x54000000
148 #define OMAP2_STI_IRQ           4
149
150 static struct resource sti_resources[] = {
151         {
152                 .start          = OMAP2_STI_BASE,
153                 .end            = OMAP2_STI_BASE + 0x7ff,
154                 .flags          = IORESOURCE_MEM,
155         },
156         {
157                 .start          = OMAP2_STI_CHANNEL_BASE,
158                 .end            = OMAP2_STI_CHANNEL_BASE + SZ_64K - 1,
159                 .flags          = IORESOURCE_MEM,
160         },
161         {
162                 .start          = OMAP2_STI_IRQ,
163                 .flags          = IORESOURCE_IRQ,
164         }
165 };
166 #elif defined(CONFIG_ARCH_OMAP3)
167
168 #define OMAP3_SDTI_BASE         0x54500000
169 #define OMAP3_SDTI_CHANNEL_BASE 0x54600000
170
171 static struct resource sti_resources[] = {
172         {
173                 .start          = OMAP3_SDTI_BASE,
174                 .end            = OMAP3_SDTI_BASE + 0xFFF,
175                 .flags          = IORESOURCE_MEM,
176         },
177         {
178                 .start          = OMAP3_SDTI_CHANNEL_BASE,
179                 .end            = OMAP3_SDTI_CHANNEL_BASE + SZ_1M - 1,
180                 .flags          = IORESOURCE_MEM,
181         }
182 };
183
184 #endif
185
186 static struct platform_device sti_device = {
187         .name           = "sti",
188         .id             = -1,
189         .num_resources  = ARRAY_SIZE(sti_resources),
190         .resource       = sti_resources,
191 };
192
193 static inline void omap_init_sti(void)
194 {
195         platform_device_register(&sti_device);
196 }
197 #else
198 static inline void omap_init_sti(void) {}
199 #endif
200
201 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
202
203 #include <mach/mcspi.h>
204
205 #define OMAP2_MCSPI1_BASE               0x48098000
206 #define OMAP2_MCSPI2_BASE               0x4809a000
207 #define OMAP2_MCSPI3_BASE               0x480b8000
208 #define OMAP2_MCSPI4_BASE               0x480ba000
209
210 static struct omap2_mcspi_platform_config omap2_mcspi1_config = {
211         .num_cs         = 4,
212 };
213
214 static struct resource omap2_mcspi1_resources[] = {
215         {
216                 .start          = OMAP2_MCSPI1_BASE,
217                 .end            = OMAP2_MCSPI1_BASE + 0xff,
218                 .flags          = IORESOURCE_MEM,
219         },
220 };
221
222 static struct platform_device omap2_mcspi1 = {
223         .name           = "omap2_mcspi",
224         .id             = 1,
225         .num_resources  = ARRAY_SIZE(omap2_mcspi1_resources),
226         .resource       = omap2_mcspi1_resources,
227         .dev            = {
228                 .platform_data = &omap2_mcspi1_config,
229         },
230 };
231
232 static struct omap2_mcspi_platform_config omap2_mcspi2_config = {
233         .num_cs         = 2,
234 };
235
236 static struct resource omap2_mcspi2_resources[] = {
237         {
238                 .start          = OMAP2_MCSPI2_BASE,
239                 .end            = OMAP2_MCSPI2_BASE + 0xff,
240                 .flags          = IORESOURCE_MEM,
241         },
242 };
243
244 static struct platform_device omap2_mcspi2 = {
245         .name           = "omap2_mcspi",
246         .id             = 2,
247         .num_resources  = ARRAY_SIZE(omap2_mcspi2_resources),
248         .resource       = omap2_mcspi2_resources,
249         .dev            = {
250                 .platform_data = &omap2_mcspi2_config,
251         },
252 };
253
254 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
255 static struct omap2_mcspi_platform_config omap2_mcspi3_config = {
256         .num_cs         = 2,
257 };
258
259 static struct resource omap2_mcspi3_resources[] = {
260         {
261         .start          = OMAP2_MCSPI3_BASE,
262         .end            = OMAP2_MCSPI3_BASE + 0xff,
263         .flags          = IORESOURCE_MEM,
264         },
265 };
266
267 static struct platform_device omap2_mcspi3 = {
268         .name           = "omap2_mcspi",
269         .id             = 3,
270         .num_resources  = ARRAY_SIZE(omap2_mcspi3_resources),
271         .resource       = omap2_mcspi3_resources,
272         .dev            = {
273                 .platform_data = &omap2_mcspi3_config,
274         },
275 };
276 #endif
277
278 #ifdef CONFIG_ARCH_OMAP3
279 static struct omap2_mcspi_platform_config omap2_mcspi4_config = {
280         .num_cs         = 1,
281 };
282
283 static struct resource omap2_mcspi4_resources[] = {
284         {
285                 .start          = OMAP2_MCSPI4_BASE,
286                 .end            = OMAP2_MCSPI4_BASE + 0xff,
287                 .flags          = IORESOURCE_MEM,
288         },
289 };
290
291 static struct platform_device omap2_mcspi4 = {
292         .name           = "omap2_mcspi",
293         .id             = 4,
294         .num_resources  = ARRAY_SIZE(omap2_mcspi4_resources),
295         .resource       = omap2_mcspi4_resources,
296         .dev            = {
297                 .platform_data = &omap2_mcspi4_config,
298         },
299 };
300 #endif
301
302 static void omap_init_mcspi(void)
303 {
304         platform_device_register(&omap2_mcspi1);
305         platform_device_register(&omap2_mcspi2);
306 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
307         if (cpu_is_omap2430() || cpu_is_omap343x())
308                 platform_device_register(&omap2_mcspi3);
309 #endif
310 #ifdef CONFIG_ARCH_OMAP3
311         if (cpu_is_omap343x())
312                 platform_device_register(&omap2_mcspi4);
313 #endif
314 }
315
316 #else
317 static inline void omap_init_mcspi(void) {}
318 #endif
319
320 #ifdef CONFIG_SND_OMAP24XX_EAC
321
322 #define OMAP2_EAC_BASE                  (L4_24XX_BASE + 0x90000)
323
324 static struct resource omap2_eac_resources[] = {
325         {
326                 .start          = OMAP2_EAC_BASE,
327                 .end            = OMAP2_EAC_BASE + 0xfff,
328                 .flags          = IORESOURCE_MEM,
329         },
330 };
331
332 static struct platform_device omap2_eac_device = {
333         .name           = "omap24xx-eac",
334         .id             = -1,
335         .num_resources  = ARRAY_SIZE(omap2_eac_resources),
336         .resource       = omap2_eac_resources,
337         .dev = {
338                 .platform_data = NULL,
339         },
340 };
341
342 void omap_init_eac(struct eac_platform_data *pdata)
343 {
344         omap2_eac_device.dev.platform_data = pdata;
345         platform_device_register(&omap2_eac_device);
346 }
347
348 #else
349 void omap_init_eac(struct eac_platform_data *pdata) {}
350 #endif
351
352 #ifdef CONFIG_OMAP_SHA1_MD5
353 static struct resource sha1_md5_resources[] = {
354         {
355                 .start  = OMAP24XX_SEC_SHA1MD5_BASE,
356                 .end    = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
357                 .flags  = IORESOURCE_MEM,
358         },
359         {
360                 .start  = INT_24XX_SHA1MD5,
361                 .flags  = IORESOURCE_IRQ,
362         }
363 };
364
365 static struct platform_device sha1_md5_device = {
366         .name           = "OMAP SHA1/MD5",
367         .id             = -1,
368         .num_resources  = ARRAY_SIZE(sha1_md5_resources),
369         .resource       = sha1_md5_resources,
370 };
371
372 static void omap_init_sha1_md5(void)
373 {
374         platform_device_register(&sha1_md5_device);
375 }
376 #else
377 static inline void omap_init_sha1_md5(void) { }
378 #endif
379
380 /*-------------------------------------------------------------------------*/
381
382 #ifdef CONFIG_ARCH_OMAP3
383
384 #define MMCHS_SYSCONFIG                 0x0010
385 #define MMCHS_SYSCONFIG_SWRESET         (1 << 1)
386 #define MMCHS_SYSSTATUS                 0x0014
387 #define MMCHS_SYSSTATUS_RESETDONE       (1 << 0)
388
389 static struct platform_device dummy_pdev = {
390         .dev = {
391                 .bus = &platform_bus_type,
392         },
393 };
394
395 /**
396  * omap_hsmmc_reset() - Full reset of each HS-MMC controller
397  *
398  * Ensure that each MMC controller is fully reset.  Controllers
399  * left in an unknown state (by bootloader) may prevent retention
400  * or OFF-mode.  This is especially important in cases where the
401  * MMC driver is not enabled, _or_ built as a module.
402  *
403  * In order for reset to work, interface, functional and debounce
404  * clocks must be enabled.  The debounce clock comes from func_32k_clk
405  * and is not under SW control, so we only enable i- and f-clocks.
406  **/
407 static void __init omap_hsmmc_reset(void)
408 {
409         u32 i, nr_controllers = cpu_is_omap34xx() ? OMAP34XX_NR_MMC :
410                 OMAP24XX_NR_MMC;
411
412         for (i = 0; i < nr_controllers; i++) {
413                 u32 v, base = 0;
414                 struct clk *iclk, *fclk;
415                 struct device *dev = &dummy_pdev.dev;
416
417                 switch (i) {
418                 case 0:
419                         base = OMAP2_MMC1_BASE;
420                         break;
421                 case 1:
422                         base = OMAP2_MMC2_BASE;
423                         break;
424                 case 2:
425                         base = OMAP3_MMC3_BASE;
426                         break;
427                 }
428
429                 dummy_pdev.id = i;
430                 iclk = clk_get(dev, "mmchs_ick");
431                 if (iclk && clk_enable(iclk))
432                         iclk = NULL;
433
434                 fclk = clk_get(dev, "mmchs_fck");
435                 if (fclk && clk_enable(fclk))
436                         fclk = NULL;
437
438                 if (!iclk || !fclk) {
439                         printk(KERN_WARNING
440                                "%s: Unable to enable clocks for MMC%d, "
441                                "cannot reset.\n",  __func__, i);
442                         break;
443                 }
444
445                 omap_writel(MMCHS_SYSCONFIG_SWRESET, base + MMCHS_SYSCONFIG);
446                 v = omap_readl(base + MMCHS_SYSSTATUS);
447                 while (!(omap_readl(base + MMCHS_SYSSTATUS) &
448                          MMCHS_SYSSTATUS_RESETDONE))
449                         cpu_relax();
450
451                 if (fclk) {
452                         clk_disable(fclk);
453                         clk_put(fclk);
454                 }
455                 if (iclk) {
456                         clk_disable(iclk);
457                         clk_put(iclk);
458                 }
459         }
460 }
461 #else
462 static inline void omap_hsmmc_reset(void) {}
463 #endif
464
465 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
466         defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
467
468 static inline void omap2_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
469                         int controller_nr)
470 {
471         if (cpu_is_omap2420() && controller_nr == 0) {
472                 omap_cfg_reg(H18_24XX_MMC_CMD);
473                 omap_cfg_reg(H15_24XX_MMC_CLKI);
474                 omap_cfg_reg(G19_24XX_MMC_CLKO);
475                 omap_cfg_reg(F20_24XX_MMC_DAT0);
476                 omap_cfg_reg(F19_24XX_MMC_DAT_DIR0);
477                 omap_cfg_reg(G18_24XX_MMC_CMD_DIR);
478                 if (mmc_controller->slots[0].wires == 4) {
479                         omap_cfg_reg(H14_24XX_MMC_DAT1);
480                         omap_cfg_reg(E19_24XX_MMC_DAT2);
481                         omap_cfg_reg(D19_24XX_MMC_DAT3);
482                         omap_cfg_reg(E20_24XX_MMC_DAT_DIR1);
483                         omap_cfg_reg(F18_24XX_MMC_DAT_DIR2);
484                         omap_cfg_reg(E18_24XX_MMC_DAT_DIR3);
485                 }
486
487                 /*
488                  * Use internal loop-back in MMC/SDIO Module Input Clock
489                  * selection
490                  */
491                 if (mmc_controller->slots[0].internal_clock) {
492                         u32 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
493                         v |= (1 << 24);
494                         omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
495                 }
496         }
497 }
498
499 void __init omap2_init_mmc(struct omap_mmc_platform_data **mmc_data,
500                         int nr_controllers)
501 {
502         int i;
503
504         for (i = 0; i < nr_controllers; i++) {
505                 unsigned long base, size;
506                 unsigned int irq = 0;
507
508                 if (!mmc_data[i])
509                         continue;
510
511                 omap2_mmc_mux(mmc_data[i], i);
512
513                 switch (i) {
514                 case 0:
515                         base = OMAP2_MMC1_BASE;
516                         irq = INT_24XX_MMC_IRQ;
517                         break;
518                 case 1:
519                         base = OMAP2_MMC2_BASE;
520                         irq = INT_24XX_MMC2_IRQ;
521                         break;
522                 case 2:
523                         if (!cpu_is_omap34xx())
524                                 return;
525                         base = OMAP3_MMC3_BASE;
526                         irq = INT_34XX_MMC3_IRQ;
527                         break;
528                 default:
529                         continue;
530                 }
531
532                 if (cpu_is_omap2420())
533                         size = OMAP2420_MMC_SIZE;
534                 else
535                         size = HSMMC_SIZE;
536
537                 omap_mmc_add(i, base, size, irq, mmc_data[i]);
538         };
539 }
540
541 #endif
542
543 /*-------------------------------------------------------------------------*/
544
545 #if defined(CONFIG_HDQ_MASTER_OMAP) || defined(CONFIG_HDQ_MASTER_OMAP_MODULE)
546 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
547 #define OMAP_HDQ_BASE   0x480B2000
548 #endif
549 static struct resource omap_hdq_resources[] = {
550         {
551                 .start          = OMAP_HDQ_BASE,
552                 .end            = OMAP_HDQ_BASE + 0x1C,
553                 .flags          = IORESOURCE_MEM,
554         },
555         {
556                 .start          = INT_24XX_HDQ_IRQ,
557                 .flags          = IORESOURCE_IRQ,
558         },
559 };
560 static struct platform_device omap_hdq_dev = {
561         .name = "omap_hdq",
562         .id = 0,
563         .dev = {
564                 .platform_data = NULL,
565         },
566         .num_resources  = ARRAY_SIZE(omap_hdq_resources),
567         .resource       = omap_hdq_resources,
568 };
569 static inline void omap_hdq_init(void)
570 {
571         (void) platform_device_register(&omap_hdq_dev);
572 }
573 #else
574 static inline void omap_hdq_init(void) {}
575 #endif
576
577 /*-------------------------------------------------------------------------*/
578
579 static int __init omap2_init_devices(void)
580 {
581         /* please keep these calls, and their implementations above,
582          * in alphabetical order so they're easier to sort through.
583          */
584         omap_hsmmc_reset();
585         omap_init_camera();
586         omap_init_mbox();
587         omap_init_mcspi();
588         omap_hdq_init();
589         omap_init_sti();
590         omap_init_sha1_md5();
591
592         return 0;
593 }
594 arch_initcall(omap2_init_devices);