]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/devices.c
a80c415e7092240ab0a9a5fdaefe056a286511bf
[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/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 OMAP2_I2C_BASE2         0x48072000
41 #define OMAP_I2C_SIZE           0x3f
42 #define OMAP1_I2C_INT           INT_I2C
43 #define OMAP2_I2C_INT1          56
44 #define OMAP2_I2C_INT2          57
45
46 static struct resource i2c_resources1[] = {
47         {
48                 .start          = 0,
49                 .end            = 0,
50                 .flags          = IORESOURCE_MEM,
51         },
52         {
53                 .start          = 0,
54                 .flags          = IORESOURCE_IRQ,
55         },
56 };
57
58 /* DMA not used; works around erratum writing to non-empty i2c fifo */
59
60 static struct platform_device omap_i2c_device1 = {
61         .name           = "i2c_omap",
62         .id             = 1,
63         .dev = {
64                 .release        = omap_nop_release,
65         },
66         .num_resources  = ARRAY_SIZE(i2c_resources1),
67         .resource       = i2c_resources1,
68 };
69
70 #ifdef CONFIG_ARCH_OMAP24XX
71 static struct resource i2c_resources2[] = {
72         {
73                 .start          = OMAP2_I2C_BASE2,
74                 .end            = OMAP2_I2C_BASE2 + OMAP_I2C_SIZE,
75                 .flags          = IORESOURCE_MEM,
76         },
77         {
78                 .start          = OMAP2_I2C_INT2,
79                 .flags          = IORESOURCE_IRQ,
80         },
81 };
82
83 static struct platform_device omap_i2c_device2 = {
84         .name           = "i2c_omap",
85         .id             = 2,
86         .dev = {
87                 .release        = omap_nop_release,
88         },
89         .num_resources  = ARRAY_SIZE(i2c_resources2),
90         .resource       = i2c_resources2,
91 };
92 #else
93 #define omap_i2c_device2        NULL
94 #endif
95
96 static void omap_init_i2c(void)
97 {
98         if (cpu_is_omap24xx()) {
99                 i2c_resources1[0].start = OMAP2_I2C_BASE1;
100                 i2c_resources1[0].end = OMAP2_I2C_BASE1 + OMAP_I2C_SIZE;
101                 i2c_resources1[1].start = OMAP2_I2C_INT1;
102         } else {
103                 i2c_resources1[0].start = OMAP1_I2C_BASE;
104                 i2c_resources1[0].end = OMAP1_I2C_BASE + OMAP_I2C_SIZE;
105                 i2c_resources1[1].start = OMAP1_I2C_INT;
106         }
107
108         /* FIXME define and use a boot tag, in case of boards that
109          * either don't wire up I2C, or chips that mux it differently...
110          * it can include clocking and address info, maybe more.
111          */
112         if (cpu_is_omap24xx()) {
113                 omap_cfg_reg(M19_24XX_I2C1_SCL);
114                 omap_cfg_reg(L15_24XX_I2C1_SDA);
115                 omap_cfg_reg(J15_24XX_I2C2_SCL);
116                 omap_cfg_reg(H19_24XX_I2C2_SDA);
117         } else {
118                 omap_cfg_reg(I2C_SCL);
119                 omap_cfg_reg(I2C_SDA);
120         }
121
122         (void) platform_device_register(&omap_i2c_device1);
123
124         //if (cpu_is_omap24xx())
125         //      (void) platform_device_register(&omap_i2c_device2);
126 }
127 #else
128 static inline void omap_init_i2c(void) {}
129 #endif
130
131 /*-------------------------------------------------------------------------*/
132
133 #if     defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
134
135 #ifdef CONFIG_ARCH_OMAP24XX
136 #define OMAP_MMC1_BASE          0x4809c000
137 #define OMAP_MMC1_INT           83
138 #else
139 #define OMAP_MMC1_BASE          0xfffb7800
140 #define OMAP_MMC1_INT           INT_MMC
141 #endif
142 #define OMAP_MMC2_BASE          0xfffb7c00      /* omap16xx only */
143
144 static struct omap_mmc_conf mmc1_conf;
145
146 static u64 mmc1_dmamask = 0xffffffff;
147
148 static struct resource mmc1_resources[] = {
149         {
150                 .start          = IO_ADDRESS(OMAP_MMC1_BASE),
151                 .end            = IO_ADDRESS(OMAP_MMC1_BASE) + 0x7f,
152                 .flags          = IORESOURCE_MEM,
153         },
154         {
155                 .start          = OMAP_MMC1_INT,
156                 .flags          = IORESOURCE_IRQ,
157         },
158 };
159
160 static struct platform_device mmc_omap_device1 = {
161         .name           = "mmci-omap",
162         .id             = 1,
163         .dev = {
164                 .release        = omap_nop_release,
165                 .dma_mask       = &mmc1_dmamask,
166                 .platform_data  = &mmc1_conf,
167         },
168         .num_resources  = ARRAY_SIZE(mmc1_resources),
169         .resource       = mmc1_resources,
170 };
171
172 #ifdef  CONFIG_ARCH_OMAP16XX
173
174 static struct omap_mmc_conf mmc2_conf;
175
176 static u64 mmc2_dmamask = 0xffffffff;
177
178 static struct resource mmc2_resources[] = {
179         {
180                 .start          = IO_ADDRESS(OMAP_MMC2_BASE),
181                 .end            = IO_ADDRESS(OMAP_MMC2_BASE) + 0x7f,
182                 .flags          = IORESOURCE_MEM,
183         },
184         {
185                 .start          = INT_1610_MMC2,
186                 .flags          = IORESOURCE_IRQ,
187         },
188 };
189
190 static struct platform_device mmc_omap_device2 = {
191         .name           = "mmci-omap",
192         .id             = 2,
193         .dev = {
194                 .release        = omap_nop_release,
195                 .dma_mask       = &mmc2_dmamask,
196                 .platform_data  = &mmc2_conf,
197         },
198         .num_resources  = ARRAY_SIZE(mmc2_resources),
199         .resource       = mmc2_resources,
200 };
201 #endif
202
203 static void __init omap_init_mmc(void)
204 {
205         const struct omap_mmc_config    *mmc_conf;
206         const struct omap_mmc_conf      *mmc;
207
208         /* NOTE:  assumes MMC was never (wrongly) enabled */
209         mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
210         if (!mmc_conf)
211                 return;
212
213         /* block 1 is always available and has just one pinout option */
214         mmc = &mmc_conf->mmc[0];
215         if (mmc->enabled) {
216                 if (!cpu_is_omap24xx()) {
217                         omap_cfg_reg(MMC_CMD);
218                         omap_cfg_reg(MMC_CLK);
219                         omap_cfg_reg(MMC_DAT0);
220                         if (cpu_is_omap1710()) {
221                                 omap_cfg_reg(M15_1710_MMC_CLKI);
222                                 omap_cfg_reg(P19_1710_MMC_CMDDIR);
223                                 omap_cfg_reg(P20_1710_MMC_DATDIR0);
224                         }
225                 }
226                 if (mmc->wire4) {
227                         if (!cpu_is_omap24xx()) {
228                                 omap_cfg_reg(MMC_DAT1);
229                                 /* NOTE:  DAT2 can be on W10 (here) or M15 */
230                                 if (!mmc->nomux)
231                                         omap_cfg_reg(MMC_DAT2);
232                                 omap_cfg_reg(MMC_DAT3);
233                         }
234                 }
235                 mmc1_conf = *mmc;
236                 (void) platform_device_register(&mmc_omap_device1);
237         }
238
239 #ifdef  CONFIG_ARCH_OMAP16XX
240         /* block 2 is on newer chips, and has many pinout options */
241         mmc = &mmc_conf->mmc[1];
242         if (mmc->enabled) {
243                 if (!mmc->nomux) {
244                         omap_cfg_reg(Y8_1610_MMC2_CMD);
245                         omap_cfg_reg(Y10_1610_MMC2_CLK);
246                         omap_cfg_reg(R18_1610_MMC2_CLKIN);
247                         omap_cfg_reg(W8_1610_MMC2_DAT0);
248                         if (mmc->wire4) {
249                                 omap_cfg_reg(V8_1610_MMC2_DAT1);
250                                 omap_cfg_reg(W15_1610_MMC2_DAT2);
251                                 omap_cfg_reg(R10_1610_MMC2_DAT3);
252                         }
253
254                         /* These are needed for the level shifter */
255                         omap_cfg_reg(V9_1610_MMC2_CMDDIR);
256                         omap_cfg_reg(V5_1610_MMC2_DATDIR0);
257                         omap_cfg_reg(W19_1610_MMC2_DATDIR1);
258                 }
259
260                 /* Feedback clock must be set on OMAP-1710 MMC2 */
261                 if (cpu_is_omap1710())
262                         omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
263                                      MOD_CONF_CTRL_1);
264                 mmc2_conf = *mmc;
265                 (void) platform_device_register(&mmc_omap_device2);
266         }
267 #endif
268         return;
269 }
270 #else
271 static inline void omap_init_mmc(void) {}
272 #endif
273
274 /*
275  * This gets called after board-specific INIT_MACHINE, and initializes most
276  * on-chip peripherals accessible on this board (except for few like USB):
277  *
278  *  (a) Does any "standard config" pin muxing needed.  Board-specific
279  *      code will have muxed GPIO pins and done "nonstandard" setup;
280  *      that code could live in the boot loader.
281  *  (b) Populating board-specific platform_data with the data drivers
282  *      rely on to handle wiring variations.
283  *  (c) Creating platform devices as meaningful on this board and
284  *      with this kernel configuration.
285  *
286  * Claiming GPIOs, and setting their direction and initial values, is the
287  * responsibility of the device drivers.  So is responding to probe().
288  *
289  * Board-specific knowlege like creating devices or pin setup is to be
290  * kept out of drivers as much as possible.  In particular, pin setup
291  * may be handled by the boot loader, and drivers should expect it will
292  * normally have been done by the time they're probed.
293  */
294 static int __init omap_init_devices(void)
295 {
296         /* please keep these calls, and their implementations above,
297          * in alphabetical order so they're easier to sort through.
298          */
299         omap_init_i2c();
300         omap_init_mmc();
301
302         return 0;
303 }
304 arch_initcall(omap_init_devices);
305