Merge current mainline tree into linux-omap tree
[pandora-kernel.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/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/i2c/menelaus.h>
18
19 #include <mach/hardware.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/map.h>
22
23 #include <mach/tc.h>
24 #include <mach/board.h>
25 #include <mach/mmc.h>
26 #include <mach/mux.h>
27 #include <mach/gpio.h>
28 #include <mach/dsp_common.h>
29 #include <mach/mcbsp.h>
30
31 #if     defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
32
33 static struct dsp_platform_data dsp_pdata = {
34         .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list),
35 };
36
37 static struct resource omap_dsp_resources[] = {
38         {
39                 .name   = "dsp_mmu",
40                 .start  = -1,
41                 .flags  = IORESOURCE_IRQ,
42         },
43 };
44
45 static struct platform_device omap_dsp_device = {
46         .name           = "dsp",
47         .id             = -1,
48         .num_resources  = ARRAY_SIZE(omap_dsp_resources),
49         .resource       = omap_dsp_resources,
50         .dev = {
51                 .platform_data = &dsp_pdata,
52         },
53 };
54
55 static inline void omap_init_dsp(void)
56 {
57         struct resource *res;
58         int irq;
59
60         if (cpu_is_omap15xx())
61                 irq = INT_1510_DSP_MMU;
62         else if (cpu_is_omap16xx())
63                 irq = INT_1610_DSP_MMU;
64         else if (cpu_is_omap24xx())
65                 irq = INT_24XX_DSP_MMU;
66
67         res = platform_get_resource_byname(&omap_dsp_device,
68                                            IORESOURCE_IRQ, "dsp_mmu");
69         res->start = irq;
70
71         platform_device_register(&omap_dsp_device);
72 }
73
74 int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev)
75 {
76         static DEFINE_MUTEX(dsp_pdata_lock);
77
78         spin_lock_init(&kdev->lock);
79
80         mutex_lock(&dsp_pdata_lock);
81         list_add_tail(&kdev->entry, &dsp_pdata.kdev_list);
82         mutex_unlock(&dsp_pdata_lock);
83
84         return 0;
85 }
86 EXPORT_SYMBOL(dsp_kfunc_device_register);
87
88 #else
89 static inline void omap_init_dsp(void) { }
90 #endif  /* CONFIG_OMAP_DSP */
91
92 /*-------------------------------------------------------------------------*/
93 #if     defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
94
95 static void omap_init_kp(void)
96 {
97         /* 2430 and 34xx keypad is on TWL4030 */
98         if (cpu_is_omap2430() || cpu_is_omap34xx())
99                 return;
100
101         if (machine_is_omap_h2() || machine_is_omap_h3()) {
102                 omap_cfg_reg(F18_1610_KBC0);
103                 omap_cfg_reg(D20_1610_KBC1);
104                 omap_cfg_reg(D19_1610_KBC2);
105                 omap_cfg_reg(E18_1610_KBC3);
106                 omap_cfg_reg(C21_1610_KBC4);
107
108                 omap_cfg_reg(G18_1610_KBR0);
109                 omap_cfg_reg(F19_1610_KBR1);
110                 omap_cfg_reg(H14_1610_KBR2);
111                 omap_cfg_reg(E20_1610_KBR3);
112                 omap_cfg_reg(E19_1610_KBR4);
113                 omap_cfg_reg(N19_1610_KBR5);
114         } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) {
115                 omap_cfg_reg(E2_730_KBR0);
116                 omap_cfg_reg(J7_730_KBR1);
117                 omap_cfg_reg(E1_730_KBR2);
118                 omap_cfg_reg(F3_730_KBR3);
119                 omap_cfg_reg(D2_730_KBR4);
120
121                 omap_cfg_reg(C2_730_KBC0);
122                 omap_cfg_reg(D3_730_KBC1);
123                 omap_cfg_reg(E4_730_KBC2);
124                 omap_cfg_reg(F4_730_KBC3);
125                 omap_cfg_reg(E3_730_KBC4);
126         } else if (machine_is_omap_h4()) {
127                 omap_cfg_reg(T19_24XX_KBR0);
128                 omap_cfg_reg(R19_24XX_KBR1);
129                 omap_cfg_reg(V18_24XX_KBR2);
130                 omap_cfg_reg(M21_24XX_KBR3);
131                 omap_cfg_reg(E5__24XX_KBR4);
132                 if (omap_has_menelaus()) {
133                         omap_cfg_reg(B3__24XX_KBR5);
134                         omap_cfg_reg(AA4_24XX_KBC2);
135                         omap_cfg_reg(B13_24XX_KBC6);
136                 } else {
137                         omap_cfg_reg(M18_24XX_KBR5);
138                         omap_cfg_reg(H19_24XX_KBC2);
139                         omap_cfg_reg(N19_24XX_KBC6);
140                 }
141                 omap_cfg_reg(R20_24XX_KBC0);
142                 omap_cfg_reg(M14_24XX_KBC1);
143                 omap_cfg_reg(V17_24XX_KBC3);
144                 omap_cfg_reg(P21_24XX_KBC4);
145                 omap_cfg_reg(L14_24XX_KBC5);
146         }
147 }
148 #else
149 static inline void omap_init_kp(void) {}
150 #endif
151
152 /*-------------------------------------------------------------------------*/
153 #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
154
155 static struct platform_device **omap_mcbsp_devices;
156
157 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
158                                         int size)
159 {
160         int i;
161
162         omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
163                                      GFP_KERNEL);
164         if (!omap_mcbsp_devices) {
165                 printk(KERN_ERR "Could not register McBSP devices\n");
166                 return;
167         }
168
169         for (i = 0; i < size; i++) {
170                 struct platform_device *new_mcbsp;
171                 int ret;
172
173                 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
174                 if (!new_mcbsp)
175                         continue;
176                 new_mcbsp->dev.platform_data = &config[i];
177                 ret = platform_device_add(new_mcbsp);
178                 if (ret) {
179                         platform_device_put(new_mcbsp);
180                         continue;
181                 }
182                 omap_mcbsp_devices[i] = new_mcbsp;
183         }
184 }
185
186 #else
187 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
188                                         int size)
189 {  }
190 #endif
191
192 /*-------------------------------------------------------------------------*/
193
194 #if     defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
195         defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
196
197 #define OMAP_MMC_NR_RES         2
198
199 /*
200  * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
201  */
202 int __init omap_mmc_add(int id, unsigned long base, unsigned long size,
203                 unsigned int irq, struct omap_mmc_platform_data *data)
204 {
205         struct platform_device *pdev;
206         struct resource res[OMAP_MMC_NR_RES];
207         int ret;
208
209         pdev = platform_device_alloc("mmci-omap", id);
210         if (!pdev)
211                 return -ENOMEM;
212
213         memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
214         res[0].start = base;
215         res[0].end = base + size - 1;
216         res[0].flags = IORESOURCE_MEM;
217         res[1].start = res[1].end = irq;
218         res[1].flags = IORESOURCE_IRQ;
219
220         ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
221         if (ret == 0)
222                 ret = platform_device_add_data(pdev, data, sizeof(*data));
223         if (ret)
224                 goto fail;
225
226         ret = platform_device_add(pdev);
227         if (ret)
228                 goto fail;
229         return 0;
230
231 fail:
232         platform_device_put(pdev);
233         return ret;
234 }
235
236 #endif
237
238 /*-------------------------------------------------------------------------*/
239
240 /* Numbering for the SPI-capable controllers when used for SPI:
241  * spi          = 1
242  * uwire        = 2
243  * mmc1..2      = 3..4
244  * mcbsp1..3    = 5..7
245  */
246
247 #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
248
249 #define OMAP_UWIRE_BASE         0xfffb3000
250
251 static struct resource uwire_resources[] = {
252         {
253                 .start          = OMAP_UWIRE_BASE,
254                 .end            = OMAP_UWIRE_BASE + 0x20,
255                 .flags          = IORESOURCE_MEM,
256         },
257 };
258
259 static struct platform_device omap_uwire_device = {
260         .name      = "omap_uwire",
261         .id          = -1,
262         .num_resources  = ARRAY_SIZE(uwire_resources),
263         .resource       = uwire_resources,
264 };
265
266 static void omap_init_uwire(void)
267 {
268         /* FIXME define and use a boot tag; not all boards will be hooking
269          * up devices to the microwire controller, and multi-board configs
270          * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
271          */
272
273         /* board-specific code must configure chipselects (only a few
274          * are normally used) and SCLK/SDI/SDO (each has two choices).
275          */
276         (void) platform_device_register(&omap_uwire_device);
277 }
278 #else
279 static inline void omap_init_uwire(void) {}
280 #endif
281
282 /*-------------------------------------------------------------------------*/
283
284 #if     defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
285
286 static struct resource wdt_resources[] = {
287         {
288                 .flags          = IORESOURCE_MEM,
289         },
290 };
291
292 static struct platform_device omap_wdt_device = {
293         .name      = "omap_wdt",
294         .id          = -1,
295         .num_resources  = ARRAY_SIZE(wdt_resources),
296         .resource       = wdt_resources,
297 };
298
299 static void omap_init_wdt(void)
300 {
301         if (cpu_is_omap16xx())
302                 wdt_resources[0].start = 0xfffeb000;
303         else if (cpu_is_omap2420())
304                 wdt_resources[0].start = 0x48022000; /* WDT2 */
305         else if (cpu_is_omap2430())
306                 wdt_resources[0].start = 0x49016000; /* WDT2 */
307         else if (cpu_is_omap343x())
308                 wdt_resources[0].start = 0x48314000; /* WDT2 */
309         else
310                 return;
311
312         wdt_resources[0].end = wdt_resources[0].start + 0x4f;
313
314         (void) platform_device_register(&omap_wdt_device);
315 }
316 #else
317 static inline void omap_init_wdt(void) {}
318 #endif
319
320 /*-------------------------------------------------------------------------*/
321
322 #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
323
324 #ifdef CONFIG_ARCH_OMAP24XX
325 #define OMAP_RNG_BASE           0x480A0000
326 #else
327 #define OMAP_RNG_BASE           0xfffe5000
328 #endif
329
330 static struct resource rng_resources[] = {
331         {
332                 .start          = OMAP_RNG_BASE,
333                 .end            = OMAP_RNG_BASE + 0x4f,
334                 .flags          = IORESOURCE_MEM,
335         },
336 };
337
338 static struct platform_device omap_rng_device = {
339         .name      = "omap_rng",
340         .id          = -1,
341         .num_resources  = ARRAY_SIZE(rng_resources),
342         .resource       = rng_resources,
343 };
344
345 static void omap_init_rng(void)
346 {
347         (void) platform_device_register(&omap_rng_device);
348 }
349 #else
350 static inline void omap_init_rng(void) {}
351 #endif
352
353 /*
354  * This gets called after board-specific INIT_MACHINE, and initializes most
355  * on-chip peripherals accessible on this board (except for few like USB):
356  *
357  *  (a) Does any "standard config" pin muxing needed.  Board-specific
358  *      code will have muxed GPIO pins and done "nonstandard" setup;
359  *      that code could live in the boot loader.
360  *  (b) Populating board-specific platform_data with the data drivers
361  *      rely on to handle wiring variations.
362  *  (c) Creating platform devices as meaningful on this board and
363  *      with this kernel configuration.
364  *
365  * Claiming GPIOs, and setting their direction and initial values, is the
366  * responsibility of the device drivers.  So is responding to probe().
367  *
368  * Board-specific knowlege like creating devices or pin setup is to be
369  * kept out of drivers as much as possible.  In particular, pin setup
370  * may be handled by the boot loader, and drivers should expect it will
371  * normally have been done by the time they're probed.
372  */
373 static int __init omap_init_devices(void)
374 {
375         /* please keep these calls, and their implementations above,
376          * in alphabetical order so they're easier to sort through.
377          */
378         omap_init_dsp();
379         omap_init_kp();
380         omap_init_uwire();
381         omap_init_wdt();
382         omap_init_rng();
383         return 0;
384 }
385 arch_initcall(omap_init_devices);