]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/devices.c
Merge with /home/tmlind/src/kernel/linux-2.6
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / devices.c
1 /*
2  * linux/arch/arm/plat-omap/devices.c
3  *
4  * Common platform device setup/initialization for OMAP1 and OMAP2
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/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17
18 #include <asm/hardware.h>
19 #include <asm/io.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/map.h>
22
23 #include <asm/arch/tc.h>
24 #include <asm/arch/board.h>
25 #include <asm/arch/mux.h>
26 #include <asm/arch/gpio.h>
27
28
29 void omap_nop_release(struct device *dev)
30 {
31         /* Nothing */
32 }
33
34 /*-------------------------------------------------------------------------*/
35
36 #if     defined(CONFIG_I2C_OMAP) || defined(CONFIG_I2C_OMAP_MODULE)
37
38 #define OMAP1_I2C_BASE          0xfffb3800
39 #define OMAP2_I2C_BASE1         0x48070000
40 #define OMAP_I2C_SIZE           0x3f
41 #define OMAP1_I2C_INT           INT_I2C
42 #define OMAP2_I2C_INT1          56
43
44 static struct resource i2c_resources1[] = {
45         {
46                 .start          = 0,
47                 .end            = 0,
48                 .flags          = IORESOURCE_MEM,
49         },
50         {
51                 .start          = 0,
52                 .flags          = IORESOURCE_IRQ,
53         },
54 };
55
56 /* DMA not used; works around erratum writing to non-empty i2c fifo */
57
58 static struct platform_device omap_i2c_device1 = {
59         .name           = "i2c_omap",
60         .id             = 1,
61         .dev = {
62                 .release        = omap_nop_release,
63         },
64         .num_resources  = ARRAY_SIZE(i2c_resources1),
65         .resource       = i2c_resources1,
66 };
67
68 /* See also arch/arm/mach-omap2/devices.c for second I2C on 24xx */
69 static void omap_init_i2c(void)
70 {
71         if (cpu_is_omap24xx()) {
72                 i2c_resources1[0].start = OMAP2_I2C_BASE1;
73                 i2c_resources1[0].end = OMAP2_I2C_BASE1 + OMAP_I2C_SIZE;
74                 i2c_resources1[1].start = OMAP2_I2C_INT1;
75         } else {
76                 i2c_resources1[0].start = OMAP1_I2C_BASE;
77                 i2c_resources1[0].end = OMAP1_I2C_BASE + OMAP_I2C_SIZE;
78                 i2c_resources1[1].start = OMAP1_I2C_INT;
79         }
80
81         /* FIXME define and use a boot tag, in case of boards that
82          * either don't wire up I2C, or chips that mux it differently...
83          * it can include clocking and address info, maybe more.
84          */
85         if (cpu_is_omap24xx()) {
86                 omap_cfg_reg(M19_24XX_I2C1_SCL);
87                 omap_cfg_reg(L15_24XX_I2C1_SDA);
88         } else {
89                 omap_cfg_reg(I2C_SCL);
90                 omap_cfg_reg(I2C_SDA);
91         }
92
93         (void) platform_device_register(&omap_i2c_device1);
94 }
95
96 #else
97 static inline void omap_init_i2c(void) {}
98 #endif
99
100 /*-------------------------------------------------------------------------*/
101 #if     defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
102 static struct platform_device omap_kp_device = {
103         .name      = "omap-keypad",
104         .id          = -1,
105 };
106
107 static void omap_init_kp(void)
108 {
109         if (machine_is_omap_h2() || machine_is_omap_h3()) {
110                 omap_cfg_reg(F18_1610_KBC0);
111                 omap_cfg_reg(D20_1610_KBC1);
112                 omap_cfg_reg(D19_1610_KBC2);
113                 omap_cfg_reg(E18_1610_KBC3);
114                 omap_cfg_reg(C21_1610_KBC4);
115
116                 omap_cfg_reg(G18_1610_KBR0);
117                 omap_cfg_reg(F19_1610_KBR1);
118                 omap_cfg_reg(H14_1610_KBR2);
119                 omap_cfg_reg(E20_1610_KBR3);
120                 omap_cfg_reg(E19_1610_KBR4);
121                 omap_cfg_reg(N19_1610_KBR5);
122         } else if (machine_is_omap_perseus2()) {
123                 omap_cfg_reg(E2_730_KBR0);
124                 omap_cfg_reg(J7_730_KBR1);
125                 omap_cfg_reg(E1_730_KBR2);
126                 omap_cfg_reg(F3_730_KBR3);
127                 omap_cfg_reg(D2_730_KBR4);
128
129                 omap_cfg_reg(C2_730_KBC0);
130                 omap_cfg_reg(D3_730_KBC1);
131                 omap_cfg_reg(E4_730_KBC2);
132                 omap_cfg_reg(F4_730_KBC3);
133                 omap_cfg_reg(E3_730_KBC4);
134         }
135
136         (void) platform_device_register(&omap_kp_device);
137 }
138 #else
139 static inline void omap_init_kp(void) {}
140 #endif
141
142 /*-------------------------------------------------------------------------*/
143
144 #if     defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
145
146 #ifdef CONFIG_ARCH_OMAP24XX
147 #define OMAP_MMC1_BASE          0x4809c000
148 #define OMAP_MMC1_INT           83
149 #else
150 #define OMAP_MMC1_BASE          0xfffb7800
151 #define OMAP_MMC1_INT           INT_MMC
152 #endif
153 #define OMAP_MMC2_BASE          0xfffb7c00      /* omap16xx only */
154
155 static struct omap_mmc_conf mmc1_conf;
156
157 static u64 mmc1_dmamask = 0xffffffff;
158
159 static struct resource mmc1_resources[] = {
160         {
161                 .start          = IO_ADDRESS(OMAP_MMC1_BASE),
162                 .end            = IO_ADDRESS(OMAP_MMC1_BASE) + 0x7f,
163                 .flags          = IORESOURCE_MEM,
164         },
165         {
166                 .start          = OMAP_MMC1_INT,
167                 .flags          = IORESOURCE_IRQ,
168         },
169 };
170
171 static struct platform_device mmc_omap_device1 = {
172         .name           = "mmci-omap",
173         .id             = 1,
174         .dev = {
175                 .release        = omap_nop_release,
176                 .dma_mask       = &mmc1_dmamask,
177                 .platform_data  = &mmc1_conf,
178         },
179         .num_resources  = ARRAY_SIZE(mmc1_resources),
180         .resource       = mmc1_resources,
181 };
182
183 #ifdef  CONFIG_ARCH_OMAP16XX
184
185 static struct omap_mmc_conf mmc2_conf;
186
187 static u64 mmc2_dmamask = 0xffffffff;
188
189 static struct resource mmc2_resources[] = {
190         {
191                 .start          = IO_ADDRESS(OMAP_MMC2_BASE),
192                 .end            = IO_ADDRESS(OMAP_MMC2_BASE) + 0x7f,
193                 .flags          = IORESOURCE_MEM,
194         },
195         {
196                 .start          = INT_1610_MMC2,
197                 .flags          = IORESOURCE_IRQ,
198         },
199 };
200
201 static struct platform_device mmc_omap_device2 = {
202         .name           = "mmci-omap",
203         .id             = 2,
204         .dev = {
205                 .release        = omap_nop_release,
206                 .dma_mask       = &mmc2_dmamask,
207                 .platform_data  = &mmc2_conf,
208         },
209         .num_resources  = ARRAY_SIZE(mmc2_resources),
210         .resource       = mmc2_resources,
211 };
212 #endif
213
214 static void __init omap_init_mmc(void)
215 {
216         const struct omap_mmc_config    *mmc_conf;
217         const struct omap_mmc_conf      *mmc;
218
219         /* NOTE:  assumes MMC was never (wrongly) enabled */
220         mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
221         if (!mmc_conf)
222                 return;
223
224         /* block 1 is always available and has just one pinout option */
225         mmc = &mmc_conf->mmc[0];
226         if (mmc->enabled) {
227                 if (!cpu_is_omap24xx()) {
228                         omap_cfg_reg(MMC_CMD);
229                         omap_cfg_reg(MMC_CLK);
230                         omap_cfg_reg(MMC_DAT0);
231                         if (cpu_is_omap1710()) {
232                                 omap_cfg_reg(M15_1710_MMC_CLKI);
233                                 omap_cfg_reg(P19_1710_MMC_CMDDIR);
234                                 omap_cfg_reg(P20_1710_MMC_DATDIR0);
235                         }
236                 }
237                 if (mmc->wire4) {
238                         if (!cpu_is_omap24xx()) {
239                                 omap_cfg_reg(MMC_DAT1);
240                                 /* NOTE:  DAT2 can be on W10 (here) or M15 */
241                                 if (!mmc->nomux)
242                                         omap_cfg_reg(MMC_DAT2);
243                                 omap_cfg_reg(MMC_DAT3);
244                         }
245                 }
246                 mmc1_conf = *mmc;
247                 (void) platform_device_register(&mmc_omap_device1);
248         }
249
250 #ifdef  CONFIG_ARCH_OMAP16XX
251         /* block 2 is on newer chips, and has many pinout options */
252         mmc = &mmc_conf->mmc[1];
253         if (mmc->enabled) {
254                 if (!mmc->nomux) {
255                         omap_cfg_reg(Y8_1610_MMC2_CMD);
256                         omap_cfg_reg(Y10_1610_MMC2_CLK);
257                         omap_cfg_reg(R18_1610_MMC2_CLKIN);
258                         omap_cfg_reg(W8_1610_MMC2_DAT0);
259                         if (mmc->wire4) {
260                                 omap_cfg_reg(V8_1610_MMC2_DAT1);
261                                 omap_cfg_reg(W15_1610_MMC2_DAT2);
262                                 omap_cfg_reg(R10_1610_MMC2_DAT3);
263                         }
264
265                         /* These are needed for the level shifter */
266                         omap_cfg_reg(V9_1610_MMC2_CMDDIR);
267                         omap_cfg_reg(V5_1610_MMC2_DATDIR0);
268                         omap_cfg_reg(W19_1610_MMC2_DATDIR1);
269                 }
270
271                 /* Feedback clock must be set on OMAP-1710 MMC2 */
272                 if (cpu_is_omap1710())
273                         omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
274                                      MOD_CONF_CTRL_1);
275                 mmc2_conf = *mmc;
276                 (void) platform_device_register(&mmc_omap_device2);
277         }
278 #endif
279         return;
280 }
281 #else
282 static inline void omap_init_mmc(void) {}
283 #endif
284
285 #if     defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
286
287 #ifdef CONFIG_ARCH_OMAP24XX
288 #define OMAP_WDT_BASE           0x48022000
289 #else
290 #define OMAP_WDT_BASE           0xfffeb000
291 #endif
292
293 static struct resource wdt_resources[] = {
294         {
295                 .start          = OMAP_WDT_BASE,
296                 .end            = OMAP_WDT_BASE + 0x4f,
297                 .flags          = IORESOURCE_MEM,
298         },
299 };
300
301 static struct platform_device omap_wdt_device = {
302         .name      = "omap_wdt",
303         .id          = -1,
304         .dev = {
305                 .release        = omap_nop_release,
306         },
307         .num_resources  = ARRAY_SIZE(wdt_resources),
308         .resource       = wdt_resources,
309 };
310
311 static void omap_init_wdt(void)
312 {
313         (void) platform_device_register(&omap_wdt_device);
314 }
315 #else
316 static inline void omap_init_wdt(void) {}
317 #endif
318
319 /*-------------------------------------------------------------------------*/
320
321 #if     defined(CONFIG_OMAP_RNG) || defined(CONFIG_OMAP_RNG_MODULE)
322
323 #ifdef CONFIG_ARCH_OMAP24XX
324 #define OMAP_RNG_BASE           0x480A0000
325 #else
326 #define OMAP_RNG_BASE           0xfffe5000
327 #endif
328
329 static struct resource rng_resources[] = {
330         {
331                 .start          = OMAP_RNG_BASE,
332                 .end            = OMAP_RNG_BASE + 0x4f,
333                 .flags          = IORESOURCE_MEM,
334         },
335 };
336
337 static struct platform_device omap_rng_device = {
338         .name      = "omap_rng",
339         .id          = -1,
340         .dev = {
341                 .release        = omap_nop_release,
342         },
343         .num_resources  = ARRAY_SIZE(rng_resources),
344         .resource       = rng_resources,
345 };
346
347 static void omap_init_rng(void)
348 {
349         (void) platform_device_register(&omap_rng_device);
350 }
351 #else
352 static inline void omap_init_rng(void) {}
353 #endif
354
355 #if defined(CONFIG_FB_OMAP) || defined(CONFIG_FB_OMAP_MODULE)
356
357 static struct omap_lcd_config omap_fb_conf;
358
359 static u64 omap_fb_dma_mask = ~(u32)0;
360
361 static struct platform_device omap_fb_device = {
362         .name           = "omapfb",
363         .id             = -1,
364         .dev = {
365                 .release                = omap_nop_release,
366                 .dma_mask               = &omap_fb_dma_mask,
367                 .coherent_dma_mask      = ~(u32)0,
368                 .platform_data          = &omap_fb_conf,
369         },
370         .num_resources = 0,
371 };
372
373 static inline void omap_init_fb(void)
374 {
375         const struct omap_lcd_config *conf;
376
377         conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
378         if (conf != NULL)
379                 omap_fb_conf = *conf;
380         platform_device_register(&omap_fb_device);
381 }
382
383 #else
384
385 static inline void omap_init_fb(void) {}
386
387 #endif
388
389 /*
390  * This gets called after board-specific INIT_MACHINE, and initializes most
391  * on-chip peripherals accessible on this board (except for few like USB):
392  *
393  *  (a) Does any "standard config" pin muxing needed.  Board-specific
394  *      code will have muxed GPIO pins and done "nonstandard" setup;
395  *      that code could live in the boot loader.
396  *  (b) Populating board-specific platform_data with the data drivers
397  *      rely on to handle wiring variations.
398  *  (c) Creating platform devices as meaningful on this board and
399  *      with this kernel configuration.
400  *
401  * Claiming GPIOs, and setting their direction and initial values, is the
402  * responsibility of the device drivers.  So is responding to probe().
403  *
404  * Board-specific knowlege like creating devices or pin setup is to be
405  * kept out of drivers as much as possible.  In particular, pin setup
406  * may be handled by the boot loader, and drivers should expect it will
407  * normally have been done by the time they're probed.
408  */
409 static int __init omap_init_devices(void)
410 {
411         /* please keep these calls, and their implementations above,
412          * in alphabetical order so they're easier to sort through.
413          */
414         omap_init_fb();
415         omap_init_i2c();
416         omap_init_kp();
417         omap_init_mmc();
418         omap_init_wdt();
419         omap_init_rng();
420
421         return 0;
422 }
423 arch_initcall(omap_init_devices);
424