omap mmc: Add better MMC low-level init
[linux-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
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
18 #include <mach/hardware.h>
19 #include <asm/mach-types.h>
20 #include <asm/mach/map.h>
21
22 #include <mach/tc.h>
23 #include <mach/board.h>
24 #include <mach/mux.h>
25 #include <mach/gpio.h>
26 #include <mach/eac.h>
27 #include <mach/mmc.h>
28
29 #if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
30 #define OMAP2_MBOX_BASE         IO_ADDRESS(OMAP24XX_MAILBOX_BASE)
31
32 static struct resource mbox_resources[] = {
33         {
34                 .start          = OMAP2_MBOX_BASE,
35                 .end            = OMAP2_MBOX_BASE + 0x11f,
36                 .flags          = IORESOURCE_MEM,
37         },
38         {
39                 .start          = INT_24XX_MAIL_U0_MPU,
40                 .flags          = IORESOURCE_IRQ,
41         },
42         {
43                 .start          = INT_24XX_MAIL_U3_MPU,
44                 .flags          = IORESOURCE_IRQ,
45         },
46 };
47
48 static struct platform_device mbox_device = {
49         .name           = "mailbox",
50         .id             = -1,
51         .num_resources  = ARRAY_SIZE(mbox_resources),
52         .resource       = mbox_resources,
53 };
54
55 static inline void omap_init_mbox(void)
56 {
57         platform_device_register(&mbox_device);
58 }
59 #else
60 static inline void omap_init_mbox(void) { }
61 #endif
62
63 #if defined(CONFIG_OMAP_STI)
64
65 #if defined(CONFIG_ARCH_OMAP2)
66
67 #define OMAP2_STI_BASE          0x48068000
68 #define OMAP2_STI_CHANNEL_BASE  0x54000000
69 #define OMAP2_STI_IRQ           4
70
71 static struct resource sti_resources[] = {
72         {
73                 .start          = OMAP2_STI_BASE,
74                 .end            = OMAP2_STI_BASE + 0x7ff,
75                 .flags          = IORESOURCE_MEM,
76         },
77         {
78                 .start          = OMAP2_STI_CHANNEL_BASE,
79                 .end            = OMAP2_STI_CHANNEL_BASE + SZ_64K - 1,
80                 .flags          = IORESOURCE_MEM,
81         },
82         {
83                 .start          = OMAP2_STI_IRQ,
84                 .flags          = IORESOURCE_IRQ,
85         }
86 };
87 #elif defined(CONFIG_ARCH_OMAP3)
88
89 #define OMAP3_SDTI_BASE         0x54500000
90 #define OMAP3_SDTI_CHANNEL_BASE 0x54600000
91
92 static struct resource sti_resources[] = {
93         {
94                 .start          = OMAP3_SDTI_BASE,
95                 .end            = OMAP3_SDTI_BASE + 0xFFF,
96                 .flags          = IORESOURCE_MEM,
97         },
98         {
99                 .start          = OMAP3_SDTI_CHANNEL_BASE,
100                 .end            = OMAP3_SDTI_CHANNEL_BASE + SZ_1M - 1,
101                 .flags          = IORESOURCE_MEM,
102         }
103 };
104
105 #endif
106
107 static struct platform_device sti_device = {
108         .name           = "sti",
109         .id             = -1,
110         .num_resources  = ARRAY_SIZE(sti_resources),
111         .resource       = sti_resources,
112 };
113
114 static inline void omap_init_sti(void)
115 {
116         platform_device_register(&sti_device);
117 }
118 #else
119 static inline void omap_init_sti(void) {}
120 #endif
121
122 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
123
124 #include <mach/mcspi.h>
125
126 #define OMAP2_MCSPI1_BASE               0x48098000
127 #define OMAP2_MCSPI2_BASE               0x4809a000
128 #define OMAP2_MCSPI3_BASE               0x480b8000
129 #define OMAP2_MCSPI4_BASE               0x480ba000
130
131 static struct omap2_mcspi_platform_config omap2_mcspi1_config = {
132         .num_cs         = 4,
133 };
134
135 static struct resource omap2_mcspi1_resources[] = {
136         {
137                 .start          = OMAP2_MCSPI1_BASE,
138                 .end            = OMAP2_MCSPI1_BASE + 0xff,
139                 .flags          = IORESOURCE_MEM,
140         },
141 };
142
143 static struct platform_device omap2_mcspi1 = {
144         .name           = "omap2_mcspi",
145         .id             = 1,
146         .num_resources  = ARRAY_SIZE(omap2_mcspi1_resources),
147         .resource       = omap2_mcspi1_resources,
148         .dev            = {
149                 .platform_data = &omap2_mcspi1_config,
150         },
151 };
152
153 static struct omap2_mcspi_platform_config omap2_mcspi2_config = {
154         .num_cs         = 2,
155 };
156
157 static struct resource omap2_mcspi2_resources[] = {
158         {
159                 .start          = OMAP2_MCSPI2_BASE,
160                 .end            = OMAP2_MCSPI2_BASE + 0xff,
161                 .flags          = IORESOURCE_MEM,
162         },
163 };
164
165 static struct platform_device omap2_mcspi2 = {
166         .name           = "omap2_mcspi",
167         .id             = 2,
168         .num_resources  = ARRAY_SIZE(omap2_mcspi2_resources),
169         .resource       = omap2_mcspi2_resources,
170         .dev            = {
171                 .platform_data = &omap2_mcspi2_config,
172         },
173 };
174
175 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
176 static struct omap2_mcspi_platform_config omap2_mcspi3_config = {
177         .num_cs         = 2,
178 };
179
180 static struct resource omap2_mcspi3_resources[] = {
181         {
182         .start          = OMAP2_MCSPI3_BASE,
183         .end            = OMAP2_MCSPI3_BASE + 0xff,
184         .flags          = IORESOURCE_MEM,
185         },
186 };
187
188 static struct platform_device omap2_mcspi3 = {
189         .name           = "omap2_mcspi",
190         .id             = 3,
191         .num_resources  = ARRAY_SIZE(omap2_mcspi3_resources),
192         .resource       = omap2_mcspi3_resources,
193         .dev            = {
194                 .platform_data = &omap2_mcspi3_config,
195         },
196 };
197 #endif
198
199 #ifdef CONFIG_ARCH_OMAP3
200 static struct omap2_mcspi_platform_config omap2_mcspi4_config = {
201         .num_cs         = 1,
202 };
203
204 static struct resource omap2_mcspi4_resources[] = {
205         {
206                 .start          = OMAP2_MCSPI4_BASE,
207                 .end            = OMAP2_MCSPI4_BASE + 0xff,
208                 .flags          = IORESOURCE_MEM,
209         },
210 };
211
212 static struct platform_device omap2_mcspi4 = {
213         .name           = "omap2_mcspi",
214         .id             = 4,
215         .num_resources  = ARRAY_SIZE(omap2_mcspi4_resources),
216         .resource       = omap2_mcspi4_resources,
217         .dev            = {
218                 .platform_data = &omap2_mcspi4_config,
219         },
220 };
221 #endif
222
223 static void omap_init_mcspi(void)
224 {
225         platform_device_register(&omap2_mcspi1);
226         platform_device_register(&omap2_mcspi2);
227 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
228         platform_device_register(&omap2_mcspi3);
229 #endif
230 #ifdef CONFIG_ARCH_OMAP3
231         platform_device_register(&omap2_mcspi4);
232 #endif
233 }
234
235 #else
236 static inline void omap_init_mcspi(void) {}
237 #endif
238
239 #ifdef CONFIG_SND_OMAP24XX_EAC
240
241 #define OMAP2_EAC_BASE                  0x48090000
242
243 static struct resource omap2_eac_resources[] = {
244         {
245                 .start          = OMAP2_EAC_BASE,
246                 .end            = OMAP2_EAC_BASE + 0x109,
247                 .flags          = IORESOURCE_MEM,
248         },
249 };
250
251 static struct platform_device omap2_eac_device = {
252         .name           = "omap24xx-eac",
253         .id             = -1,
254         .num_resources  = ARRAY_SIZE(omap2_eac_resources),
255         .resource       = omap2_eac_resources,
256         .dev = {
257                 .platform_data = NULL,
258         },
259 };
260
261 void omap_init_eac(struct eac_platform_data *pdata)
262 {
263         omap2_eac_device.dev.platform_data = pdata;
264         platform_device_register(&omap2_eac_device);
265 }
266
267 #else
268 void omap_init_eac(struct eac_platform_data *pdata) {}
269 #endif
270
271 #ifdef CONFIG_OMAP_SHA1_MD5
272 static struct resource sha1_md5_resources[] = {
273         {
274                 .start  = OMAP24XX_SEC_SHA1MD5_BASE,
275                 .end    = OMAP24XX_SEC_SHA1MD5_BASE + 0x64,
276                 .flags  = IORESOURCE_MEM,
277         },
278         {
279                 .start  = INT_24XX_SHA1MD5,
280                 .flags  = IORESOURCE_IRQ,
281         }
282 };
283
284 static struct platform_device sha1_md5_device = {
285         .name           = "OMAP SHA1/MD5",
286         .id             = -1,
287         .num_resources  = ARRAY_SIZE(sha1_md5_resources),
288         .resource       = sha1_md5_resources,
289 };
290
291 static void omap_init_sha1_md5(void)
292 {
293         platform_device_register(&sha1_md5_device);
294 }
295 #else
296 static inline void omap_init_sha1_md5(void) { }
297 #endif
298
299 /*-------------------------------------------------------------------------*/
300
301 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
302         defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
303
304 static inline void omap2_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
305                         int controller_nr)
306 {
307         if (cpu_is_omap2420() && controller_nr == 0) {
308                 omap_cfg_reg(H18_24XX_MMC_CMD);
309                 omap_cfg_reg(H15_24XX_MMC_CLKI);
310                 omap_cfg_reg(G19_24XX_MMC_CLKO);
311                 omap_cfg_reg(F20_24XX_MMC_DAT0);
312                 omap_cfg_reg(F19_24XX_MMC_DAT_DIR0);
313                 omap_cfg_reg(G18_24XX_MMC_CMD_DIR);
314                 if (mmc_controller->slots[0].wire4) {
315                         omap_cfg_reg(H14_24XX_MMC_DAT1);
316                         omap_cfg_reg(E19_24XX_MMC_DAT2);
317                         omap_cfg_reg(D19_24XX_MMC_DAT3);
318                         omap_cfg_reg(E20_24XX_MMC_DAT_DIR1);
319                         omap_cfg_reg(F18_24XX_MMC_DAT_DIR2);
320                         omap_cfg_reg(E18_24XX_MMC_DAT_DIR3);
321                 }
322
323                 /*
324                  * Use internal loop-back in MMC/SDIO Module Input Clock
325                  * selection
326                  */
327                 if (mmc_controller->slots[0].internal_clock) {
328                         u32 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
329                         v |= (1 << 24);
330                         omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
331                 }
332         }
333 }
334
335 void __init omap2_init_mmc(struct omap_mmc_platform_data **mmc_data,
336                         int nr_controllers)
337 {
338         int i;
339
340         for (i = 0; i < nr_controllers; i++) {
341                 unsigned long base, size;
342                 unsigned int irq = 0;
343
344                 if (!mmc_data[i])
345                         continue;
346
347                 omap2_mmc_mux(mmc_data[i], i);
348
349                 switch (i) {
350                 case 0:
351                         base = OMAP2_MMC1_BASE;
352                         irq = INT_24XX_MMC_IRQ;
353                         break;
354                 case 1:
355                         base = OMAP2_MMC2_BASE;
356                         irq = INT_24XX_MMC2_IRQ;
357                         break;
358                 case 2:
359                         if (!cpu_is_omap34xx())
360                                 return;
361                         base = OMAP3_MMC3_BASE;
362                         irq = INT_34XX_MMC3_IRQ;
363                         break;
364                 default:
365                         continue;
366                 }
367
368                 if (cpu_is_omap2420())
369                         size = OMAP2420_MMC_SIZE;
370                 else
371                         size = HSMMC_SIZE;
372
373                 omap_mmc_add(i, base, size, irq, mmc_data[i]);
374         };
375 }
376
377 #endif
378
379 /*-------------------------------------------------------------------------*/
380
381 #if defined(CONFIG_HDQ_MASTER_OMAP) || defined(CONFIG_HDQ_MASTER_OMAP_MODULE)
382 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
383 #define OMAP_HDQ_BASE   0x480B2000
384 #endif
385 static struct resource omap_hdq_resources[] = {
386         {
387                 .start          = OMAP_HDQ_BASE,
388                 .end            = OMAP_HDQ_BASE + 0x1C,
389                 .flags          = IORESOURCE_MEM,
390         },
391         {
392                 .start          = INT_24XX_HDQ_IRQ,
393                 .flags          = IORESOURCE_IRQ,
394         },
395 };
396 static struct platform_device omap_hdq_dev = {
397         .name = "omap_hdq",
398         .id = 0,
399         .dev = {
400                 .platform_data = NULL,
401         },
402         .num_resources  = ARRAY_SIZE(omap_hdq_resources),
403         .resource       = omap_hdq_resources,
404 };
405 static inline void omap_hdq_init(void)
406 {
407         (void) platform_device_register(&omap_hdq_dev);
408 }
409 #else
410 static inline void omap_hdq_init(void) {}
411 #endif
412
413 /*-------------------------------------------------------------------------*/
414
415 static int __init omap2_init_devices(void)
416 {
417         /* please keep these calls, and their implementations above,
418          * in alphabetical order so they're easier to sort through.
419          */
420         omap_init_mbox();
421         omap_init_mcspi();
422         omap_hdq_init();
423         omap_init_sti();
424         omap_init_sha1_md5();
425
426         return 0;
427 }
428 arch_initcall(omap2_init_devices);