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