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