Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / arch / arm / mach-omap1 / devices.c
1 /*
2  * linux/arch/arm/mach-omap1/devices.c
3  *
4  * OMAP1 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
17 #include <mach/hardware.h>
18 #include <asm/io.h>
19 #include <asm/mach/map.h>
20
21 #include <mach/tc.h>
22 #include <mach/board.h>
23 #include <mach/mux.h>
24 #include <mach/gpio.h>
25 #include <mach/mmc.h>
26
27 /*-------------------------------------------------------------------------*/
28
29 #if defined(CONFIG_RTC_DRV_OMAP) || defined(CONFIG_RTC_DRV_OMAP_MODULE)
30
31 #define OMAP_RTC_BASE           0xfffb4800
32
33 static struct resource rtc_resources[] = {
34         {
35                 .start          = OMAP_RTC_BASE,
36                 .end            = OMAP_RTC_BASE + 0x5f,
37                 .flags          = IORESOURCE_MEM,
38         },
39         {
40                 .start          = INT_RTC_TIMER,
41                 .flags          = IORESOURCE_IRQ,
42         },
43         {
44                 .start          = INT_RTC_ALARM,
45                 .flags          = IORESOURCE_IRQ,
46         },
47 };
48
49 static struct platform_device omap_rtc_device = {
50         .name           = "omap_rtc",
51         .id             = -1,
52         .num_resources  = ARRAY_SIZE(rtc_resources),
53         .resource       = rtc_resources,
54 };
55
56 static void omap_init_rtc(void)
57 {
58         (void) platform_device_register(&omap_rtc_device);
59 }
60 #else
61 static inline void omap_init_rtc(void) {}
62 #endif
63
64 #if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
65
66 #if defined(CONFIG_ARCH_OMAP15XX)
67 #  define OMAP1_MBOX_SIZE       0x23
68 #  define INT_DSP_MAILBOX1      INT_1510_DSP_MAILBOX1
69 #elif defined(CONFIG_ARCH_OMAP16XX)
70 #  define OMAP1_MBOX_SIZE       0x2f
71 #  define INT_DSP_MAILBOX1      INT_1610_DSP_MAILBOX1
72 #endif
73
74 #define OMAP1_MBOX_BASE         IO_ADDRESS(OMAP16XX_MAILBOX_BASE)
75
76 static struct resource mbox_resources[] = {
77         {
78                 .start          = OMAP1_MBOX_BASE,
79                 .end            = OMAP1_MBOX_BASE + OMAP1_MBOX_SIZE,
80                 .flags          = IORESOURCE_MEM,
81         },
82         {
83                 .start          = INT_DSP_MAILBOX1,
84                 .flags          = IORESOURCE_IRQ,
85         },
86 };
87
88 static struct platform_device mbox_device = {
89         .name           = "mailbox",
90         .id             = -1,
91         .num_resources  = ARRAY_SIZE(mbox_resources),
92         .resource       = mbox_resources,
93 };
94
95 static inline void omap_init_mbox(void)
96 {
97         platform_device_register(&mbox_device);
98 }
99 #else
100 static inline void omap_init_mbox(void) { }
101 #endif
102
103 /*-------------------------------------------------------------------------*/
104
105 #if     defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
106
107 #define OMAP1_MMC1_BASE         0xfffb7800
108 #define OMAP1_MMC1_END          (OMAP1_MMC1_BASE + 0x7f)
109 #define OMAP1_MMC1_INT          INT_MMC
110
111 #define OMAP1_MMC2_BASE         0xfffb7c00      /* omap16xx only */
112 #define OMAP1_MMC2_END          (OMAP1_MMC2_BASE + 0x7f)
113 #define OMAP1_MMC2_INT          INT_1610_MMC2
114
115 static u64 omap1_mmc1_dmamask = 0xffffffff;
116
117 static struct resource omap1_mmc1_resources[] = {
118         {
119                 .start          = OMAP1_MMC1_BASE,
120                 .end            = OMAP1_MMC1_END,
121                 .flags          = IORESOURCE_MEM,
122         },
123         {
124                 .start          = OMAP1_MMC1_INT,
125                 .flags          = IORESOURCE_IRQ,
126         },
127 };
128
129 static struct platform_device omap1_mmc1_device = {
130         .name           = "mmci-omap",
131         .id             = 1,
132         .dev = {
133                 .dma_mask       = &omap1_mmc1_dmamask,
134         },
135         .num_resources  = ARRAY_SIZE(omap1_mmc1_resources),
136         .resource       = omap1_mmc1_resources,
137 };
138
139 #if defined(CONFIG_ARCH_OMAP16XX)
140
141 static u64 omap1_mmc2_dmamask = 0xffffffff;
142
143 static struct resource omap1_mmc2_resources[] = {
144         {
145                 .start          = OMAP1_MMC2_BASE,
146                 .end            = OMAP1_MMC2_END,
147                 .flags          = IORESOURCE_MEM,
148         },
149         {
150                 .start          = OMAP1_MMC2_INT,
151                 .flags          = IORESOURCE_IRQ,
152         },
153 };
154
155 static struct platform_device omap1_mmc2_device = {
156         .name           = "mmci-omap",
157         .id             = 2,
158         .dev = {
159                 .dma_mask       = &omap1_mmc2_dmamask,
160         },
161         .num_resources  = ARRAY_SIZE(omap1_mmc2_resources),
162         .resource       = omap1_mmc2_resources,
163 };
164 #define OMAP1_MMC2_DEVICE       &omap1_mmc2_device
165 #else
166 #define OMAP1_MMC2_DEVICE       &omap1_mmc1_device      /* Dummy */
167 #endif
168
169 static inline void omap1_mmc_mux(struct omap_mmc_platform_data *info)
170 {
171         if (info->slots[0].enabled) {
172                 omap_cfg_reg(MMC_CMD);
173                 omap_cfg_reg(MMC_CLK);
174                 omap_cfg_reg(MMC_DAT0);
175                 if (cpu_is_omap1710()) {
176                         omap_cfg_reg(M15_1710_MMC_CLKI);
177                         omap_cfg_reg(P19_1710_MMC_CMDDIR);
178                         omap_cfg_reg(P20_1710_MMC_DATDIR0);
179                 }
180                 if (info->slots[0].wire4) {
181                         omap_cfg_reg(MMC_DAT1);
182                         /* NOTE: DAT2 can be on W10 (here) or M15 */
183                         if (!info->slots[0].nomux)
184                                 omap_cfg_reg(MMC_DAT2);
185                         omap_cfg_reg(MMC_DAT3);
186                 }
187         }
188
189         /* Block 2 is on newer chips, and has many pinout options */
190         if (cpu_is_omap16xx() && info->slots[1].enabled) {
191                 if (!info->slots[1].nomux) {
192                         omap_cfg_reg(Y8_1610_MMC2_CMD);
193                         omap_cfg_reg(Y10_1610_MMC2_CLK);
194                         omap_cfg_reg(R18_1610_MMC2_CLKIN);
195                         omap_cfg_reg(W8_1610_MMC2_DAT0);
196                         if (info->slots[1].wire4) {
197                                 omap_cfg_reg(V8_1610_MMC2_DAT1);
198                                 omap_cfg_reg(W15_1610_MMC2_DAT2);
199                                 omap_cfg_reg(R10_1610_MMC2_DAT3);
200                         }
201
202                         /* These are needed for the level shifter */
203                         omap_cfg_reg(V9_1610_MMC2_CMDDIR);
204                         omap_cfg_reg(V5_1610_MMC2_DATDIR0);
205                         omap_cfg_reg(W19_1610_MMC2_DATDIR1);
206                 }
207
208                 /* Feedback clock must be set on OMAP-1710 MMC2 */
209                 if (cpu_is_omap1710())
210                         omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
211                                         MOD_CONF_CTRL_1);
212         }
213 }
214
215 void omap1_init_mmc(struct omap_mmc_platform_data *info)
216 {
217         if (!info)
218                 return;
219
220         omap1_mmc_mux(info);
221         platform_set_drvdata(&omap1_mmc1_device, info);
222
223         if (cpu_is_omap16xx())
224                 platform_set_drvdata(OMAP1_MMC2_DEVICE, info);
225
226         omap_init_mmc(info, &omap1_mmc1_device, OMAP1_MMC2_DEVICE);
227 }
228
229 #endif
230
231 /*-------------------------------------------------------------------------*/
232
233 #if defined(CONFIG_OMAP_STI)
234
235 #define OMAP1_STI_BASE          0xfffea000
236 #define OMAP1_STI_CHANNEL_BASE  (OMAP1_STI_BASE + 0x400)
237
238 static struct resource sti_resources[] = {
239         {
240                 .start          = OMAP1_STI_BASE,
241                 .end            = OMAP1_STI_BASE + SZ_1K - 1,
242                 .flags          = IORESOURCE_MEM,
243         },
244         {
245                 .start          = OMAP1_STI_CHANNEL_BASE,
246                 .end            = OMAP1_STI_CHANNEL_BASE + SZ_1K - 1,
247                 .flags          = IORESOURCE_MEM,
248         },
249         {
250                 .start          = INT_1610_STI,
251                 .flags          = IORESOURCE_IRQ,
252         }
253 };
254
255 static struct platform_device sti_device = {
256         .name           = "sti",
257         .id             = -1,
258         .num_resources  = ARRAY_SIZE(sti_resources),
259         .resource       = sti_resources,
260 };
261
262 static inline void omap_init_sti(void)
263 {
264         platform_device_register(&sti_device);
265 }
266 #else
267 static inline void omap_init_sti(void) {}
268 #endif
269
270 /*-------------------------------------------------------------------------*/
271
272 /*
273  * This gets called after board-specific INIT_MACHINE, and initializes most
274  * on-chip peripherals accessible on this board (except for few like USB):
275  *
276  *  (a) Does any "standard config" pin muxing needed.  Board-specific
277  *      code will have muxed GPIO pins and done "nonstandard" setup;
278  *      that code could live in the boot loader.
279  *  (b) Populating board-specific platform_data with the data drivers
280  *      rely on to handle wiring variations.
281  *  (c) Creating platform devices as meaningful on this board and
282  *      with this kernel configuration.
283  *
284  * Claiming GPIOs, and setting their direction and initial values, is the
285  * responsibility of the device drivers.  So is responding to probe().
286  *
287  * Board-specific knowlege like creating devices or pin setup is to be
288  * kept out of drivers as much as possible.  In particular, pin setup
289  * may be handled by the boot loader, and drivers should expect it will
290  * normally have been done by the time they're probed.
291  */
292 static int __init omap1_init_devices(void)
293 {
294         /* please keep these calls, and their implementations above,
295          * in alphabetical order so they're easier to sort through.
296          */
297
298         omap_init_mbox();
299         omap_init_rtc();
300         omap_init_sti();
301
302         return 0;
303 }
304 arch_initcall(omap1_init_devices);
305