blob: ca5b2290f5a35946d4de52bde1dfcf480af8dd9d [file] [log] [blame]
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001/*
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
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000012#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010016#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000018
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/hardware.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000020#include <asm/mach-types.h>
21#include <asm/mach/map.h>
22
Tony Lindgrence491cf2009-10-20 09:40:47 -070023#include <plat/tc.h>
24#include <plat/control.h>
25#include <plat/board.h>
26#include <plat/mmc.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070028#include <plat/menelaus.h>
29#include <plat/mcbsp.h>
30#include <plat/dsp_common.h>
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080031#include <plat/omap44xx.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000032
Tony Lindgrenc40fae92006-12-07 13:58:10 -080033#if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
34
Tony Lindgrenc40fae92006-12-07 13:58:10 -080035static struct dsp_platform_data dsp_pdata = {
36 .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list),
37};
38
39static struct resource omap_dsp_resources[] = {
40 {
41 .name = "dsp_mmu",
42 .start = -1,
43 .flags = IORESOURCE_IRQ,
44 },
45};
46
47static 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
57static 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
76int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev)
77{
78 static DEFINE_MUTEX(dsp_pdata_lock);
79
Tony Lindgren646e3ed2008-10-06 15:49:36 +030080 spin_lock_init(&kdev->lock);
Tony Lindgrenc40fae92006-12-07 13:58:10 -080081
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}
88EXPORT_SYMBOL(dsp_kfunc_device_register);
89
90#else
91static inline void omap_init_dsp(void) { }
92#endif /* CONFIG_OMAP_DSP */
93
94/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010095
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030096#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
97
98static struct platform_device **omap_mcbsp_devices;
99
100void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
101 int size)
102{
103 int i;
104
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300105 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
130void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
131 int size)
132{ }
133#endif
134
135/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000136
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800137#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
138 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
139
140static 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",
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530149 .start = OMAP44XX_IRQ_MCPDM,
150 .end = OMAP44XX_IRQ_MCPDM,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800151 .flags = IORESOURCE_IRQ,
152 },
153};
154
155static 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
162static void omap_init_mcpdm(void)
163{
164 (void) platform_device_register(&omap_mcpdm_device);
165}
166#else
167static inline void omap_init_mcpdm(void) {}
168#endif
169
170/*-------------------------------------------------------------------------*/
171
Tony Lindgrend8874662008-12-10 17:37:16 -0800172#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100173 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000174
Tony Lindgrend8874662008-12-10 17:37:16 -0800175#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000176
Tony Lindgrend8874662008-12-10 17:37:16 -0800177/*
178 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
179 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800180int __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)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000183{
Tony Lindgrend8874662008-12-10 17:37:16 -0800184 struct platform_device *pdev;
185 struct resource res[OMAP_MMC_NR_RES];
186 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000187
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800188 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800189 if (!pdev)
190 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000191
Tony Lindgrend8874662008-12-10 17:37:16 -0800192 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;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000198
Tony Lindgrend8874662008-12-10 17:37:16 -0800199 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;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000204
Tony Lindgrend8874662008-12-10 17:37:16 -0800205 ret = platform_device_add(pdev);
206 if (ret)
207 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700208
209 /* return device handle to board setup code */
210 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800211 return 0;
212
213fail:
214 platform_device_put(pdev);
215 return ret;
Russell King7736c092008-09-09 10:16:22 +0100216}
217
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000218#endif
219
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100220/*-------------------------------------------------------------------------*/
221
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800222#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
223
Tony Lindgren088ef952010-02-12 12:26:47 -0800224#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800225#define OMAP_RNG_BASE 0x480A0000
226#else
227#define OMAP_RNG_BASE 0xfffe5000
228#endif
229
230static struct resource rng_resources[] = {
231 {
232 .start = OMAP_RNG_BASE,
233 .end = OMAP_RNG_BASE + 0x4f,
234 .flags = IORESOURCE_MEM,
235 },
236};
237
238static 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
245static void omap_init_rng(void)
246{
247 (void) platform_device_register(&omap_rng_device);
248}
249#else
250static inline void omap_init_rng(void) {}
251#endif
252
253/*-------------------------------------------------------------------------*/
254
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100255/* 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
266static struct resource uwire_resources[] = {
267 {
268 .start = OMAP_UWIRE_BASE,
269 .end = OMAP_UWIRE_BASE + 0x20,
270 .flags = IORESOURCE_MEM,
271 },
272};
273
274static struct platform_device omap_uwire_device = {
275 .name = "omap_uwire",
276 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100277 .num_resources = ARRAY_SIZE(uwire_resources),
278 .resource = uwire_resources,
279};
280
281static 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
294static inline void omap_init_uwire(void) {}
295#endif
296
297/*-------------------------------------------------------------------------*/
298
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000299#if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
300
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000301static struct resource wdt_resources[] = {
302 {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000303 .flags = IORESOURCE_MEM,
304 },
305};
306
307static struct platform_device omap_wdt_device = {
308 .name = "omap_wdt",
309 .id = -1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000310 .num_resources = ARRAY_SIZE(wdt_resources),
311 .resource = wdt_resources,
312};
313
314static void omap_init_wdt(void)
315{
Felipe Balbi28171422008-09-20 04:14:01 +0300316 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 */
Santosh Shilimkar44169072009-05-28 14:16:04 -0700324 else if (cpu_is_omap44xx())
325 wdt_resources[0].start = 0x4a314000;
Felipe Balbi28171422008-09-20 04:14:01 +0300326 else
327 return;
328
329 wdt_resources[0].end = wdt_resources[0].start + 0x4f;
330
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000331 (void) platform_device_register(&omap_wdt_device);
332}
333#else
334static inline void omap_init_wdt(void) {}
335#endif
336
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000337/*
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 */
357static 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 */
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800362 omap_init_dsp();
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800363 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800364 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100365 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000366 omap_init_wdt();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000367 return 0;
368}
369arch_initcall(omap_init_devices);