blob: 4a4cd8774aaa74f440e4d0da6094e9d541d4aff6 [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>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000017
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/hardware.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000019#include <asm/mach-types.h>
20#include <asm/mach/map.h>
21
Tony Lindgrence491cf2009-10-20 09:40:47 -070022#include <plat/tc.h>
23#include <plat/control.h>
24#include <plat/board.h>
25#include <plat/mmc.h>
26#include <plat/mux.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 Lindgrenc40fae952006-12-07 13:58:10 -080033#if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
34
Tony Lindgrenc40fae952006-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 Lindgrenc40fae952006-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#if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
96
97static void omap_init_kp(void)
98{
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030099 /* 2430 and 34xx keypad is on TWL4030 */
100 if (cpu_is_omap2430() || cpu_is_omap34xx())
101 return;
102
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100103 if (machine_is_omap_h2() || machine_is_omap_h3()) {
104 omap_cfg_reg(F18_1610_KBC0);
105 omap_cfg_reg(D20_1610_KBC1);
106 omap_cfg_reg(D19_1610_KBC2);
107 omap_cfg_reg(E18_1610_KBC3);
108 omap_cfg_reg(C21_1610_KBC4);
109
110 omap_cfg_reg(G18_1610_KBR0);
111 omap_cfg_reg(F19_1610_KBR1);
112 omap_cfg_reg(H14_1610_KBR2);
113 omap_cfg_reg(E20_1610_KBR3);
114 omap_cfg_reg(E19_1610_KBR4);
115 omap_cfg_reg(N19_1610_KBR5);
Brian Swetland495f71d2006-06-26 16:16:03 -0700116 } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) {
Alistair Buxton7c006922009-09-22 10:02:58 +0100117 omap_cfg_reg(E2_7XX_KBR0);
118 omap_cfg_reg(J7_7XX_KBR1);
119 omap_cfg_reg(E1_7XX_KBR2);
120 omap_cfg_reg(F3_7XX_KBR3);
121 omap_cfg_reg(D2_7XX_KBR4);
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100122
Alistair Buxton7c006922009-09-22 10:02:58 +0100123 omap_cfg_reg(C2_7XX_KBC0);
124 omap_cfg_reg(D3_7XX_KBC1);
125 omap_cfg_reg(E4_7XX_KBC2);
126 omap_cfg_reg(F4_7XX_KBC3);
127 omap_cfg_reg(E3_7XX_KBC4);
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100128 } else if (machine_is_omap_h4()) {
129 omap_cfg_reg(T19_24XX_KBR0);
130 omap_cfg_reg(R19_24XX_KBR1);
131 omap_cfg_reg(V18_24XX_KBR2);
132 omap_cfg_reg(M21_24XX_KBR3);
133 omap_cfg_reg(E5__24XX_KBR4);
134 if (omap_has_menelaus()) {
135 omap_cfg_reg(B3__24XX_KBR5);
136 omap_cfg_reg(AA4_24XX_KBC2);
137 omap_cfg_reg(B13_24XX_KBC6);
138 } else {
139 omap_cfg_reg(M18_24XX_KBR5);
140 omap_cfg_reg(H19_24XX_KBC2);
141 omap_cfg_reg(N19_24XX_KBC6);
142 }
143 omap_cfg_reg(R20_24XX_KBC0);
144 omap_cfg_reg(M14_24XX_KBC1);
145 omap_cfg_reg(V17_24XX_KBC3);
146 omap_cfg_reg(P21_24XX_KBC4);
147 omap_cfg_reg(L14_24XX_KBC5);
148 }
149}
150#else
151static inline void omap_init_kp(void) {}
152#endif
153
154/*-------------------------------------------------------------------------*/
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300155#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
156
157static struct platform_device **omap_mcbsp_devices;
158
159void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
160 int size)
161{
162 int i;
163
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300164 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
165 GFP_KERNEL);
166 if (!omap_mcbsp_devices) {
167 printk(KERN_ERR "Could not register McBSP devices\n");
168 return;
169 }
170
171 for (i = 0; i < size; i++) {
172 struct platform_device *new_mcbsp;
173 int ret;
174
175 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
176 if (!new_mcbsp)
177 continue;
178 new_mcbsp->dev.platform_data = &config[i];
179 ret = platform_device_add(new_mcbsp);
180 if (ret) {
181 platform_device_put(new_mcbsp);
182 continue;
183 }
184 omap_mcbsp_devices[i] = new_mcbsp;
185 }
186}
187
188#else
189void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
190 int size)
191{ }
192#endif
193
194/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000195
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800196#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
197 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
198
199static struct resource mcpdm_resources[] = {
200 {
201 .name = "mcpdm_mem",
202 .start = OMAP44XX_MCPDM_BASE,
203 .end = OMAP44XX_MCPDM_BASE + SZ_4K,
204 .flags = IORESOURCE_MEM,
205 },
206 {
207 .name = "mcpdm_irq",
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530208 .start = OMAP44XX_IRQ_MCPDM,
209 .end = OMAP44XX_IRQ_MCPDM,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800210 .flags = IORESOURCE_IRQ,
211 },
212};
213
214static struct platform_device omap_mcpdm_device = {
215 .name = "omap-mcpdm",
216 .id = -1,
217 .num_resources = ARRAY_SIZE(mcpdm_resources),
218 .resource = mcpdm_resources,
219};
220
221static void omap_init_mcpdm(void)
222{
223 (void) platform_device_register(&omap_mcpdm_device);
224}
225#else
226static inline void omap_init_mcpdm(void) {}
227#endif
228
229/*-------------------------------------------------------------------------*/
230
Tony Lindgrend8874662008-12-10 17:37:16 -0800231#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100232 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000233
Tony Lindgrend8874662008-12-10 17:37:16 -0800234#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000235
Tony Lindgrend8874662008-12-10 17:37:16 -0800236/*
237 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
238 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800239int __init omap_mmc_add(const char *name, int id, unsigned long base,
240 unsigned long size, unsigned int irq,
241 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000242{
Tony Lindgrend8874662008-12-10 17:37:16 -0800243 struct platform_device *pdev;
244 struct resource res[OMAP_MMC_NR_RES];
245 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000246
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800247 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800248 if (!pdev)
249 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000250
Tony Lindgrend8874662008-12-10 17:37:16 -0800251 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
252 res[0].start = base;
253 res[0].end = base + size - 1;
254 res[0].flags = IORESOURCE_MEM;
255 res[1].start = res[1].end = irq;
256 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000257
Tony Lindgrend8874662008-12-10 17:37:16 -0800258 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
259 if (ret == 0)
260 ret = platform_device_add_data(pdev, data, sizeof(*data));
261 if (ret)
262 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000263
Tony Lindgrend8874662008-12-10 17:37:16 -0800264 ret = platform_device_add(pdev);
265 if (ret)
266 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700267
268 /* return device handle to board setup code */
269 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800270 return 0;
271
272fail:
273 platform_device_put(pdev);
274 return ret;
Russell King7736c092008-09-09 10:16:22 +0100275}
276
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000277#endif
278
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100279/*-------------------------------------------------------------------------*/
280
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800281#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
282
Tony Lindgren088ef952010-02-12 12:26:47 -0800283#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800284#define OMAP_RNG_BASE 0x480A0000
285#else
286#define OMAP_RNG_BASE 0xfffe5000
287#endif
288
289static struct resource rng_resources[] = {
290 {
291 .start = OMAP_RNG_BASE,
292 .end = OMAP_RNG_BASE + 0x4f,
293 .flags = IORESOURCE_MEM,
294 },
295};
296
297static struct platform_device omap_rng_device = {
298 .name = "omap_rng",
299 .id = -1,
300 .num_resources = ARRAY_SIZE(rng_resources),
301 .resource = rng_resources,
302};
303
304static void omap_init_rng(void)
305{
306 (void) platform_device_register(&omap_rng_device);
307}
308#else
309static inline void omap_init_rng(void) {}
310#endif
311
312/*-------------------------------------------------------------------------*/
313
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100314/* Numbering for the SPI-capable controllers when used for SPI:
315 * spi = 1
316 * uwire = 2
317 * mmc1..2 = 3..4
318 * mcbsp1..3 = 5..7
319 */
320
321#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
322
323#define OMAP_UWIRE_BASE 0xfffb3000
324
325static struct resource uwire_resources[] = {
326 {
327 .start = OMAP_UWIRE_BASE,
328 .end = OMAP_UWIRE_BASE + 0x20,
329 .flags = IORESOURCE_MEM,
330 },
331};
332
333static struct platform_device omap_uwire_device = {
334 .name = "omap_uwire",
335 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100336 .num_resources = ARRAY_SIZE(uwire_resources),
337 .resource = uwire_resources,
338};
339
340static void omap_init_uwire(void)
341{
342 /* FIXME define and use a boot tag; not all boards will be hooking
343 * up devices to the microwire controller, and multi-board configs
344 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
345 */
346
347 /* board-specific code must configure chipselects (only a few
348 * are normally used) and SCLK/SDI/SDO (each has two choices).
349 */
350 (void) platform_device_register(&omap_uwire_device);
351}
352#else
353static inline void omap_init_uwire(void) {}
354#endif
355
356/*-------------------------------------------------------------------------*/
357
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000358#if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
359
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000360static struct resource wdt_resources[] = {
361 {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000362 .flags = IORESOURCE_MEM,
363 },
364};
365
366static struct platform_device omap_wdt_device = {
367 .name = "omap_wdt",
368 .id = -1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000369 .num_resources = ARRAY_SIZE(wdt_resources),
370 .resource = wdt_resources,
371};
372
373static void omap_init_wdt(void)
374{
Felipe Balbi28171422008-09-20 04:14:01 +0300375 if (cpu_is_omap16xx())
376 wdt_resources[0].start = 0xfffeb000;
377 else if (cpu_is_omap2420())
378 wdt_resources[0].start = 0x48022000; /* WDT2 */
379 else if (cpu_is_omap2430())
380 wdt_resources[0].start = 0x49016000; /* WDT2 */
381 else if (cpu_is_omap343x())
382 wdt_resources[0].start = 0x48314000; /* WDT2 */
Santosh Shilimkar44169072009-05-28 14:16:04 -0700383 else if (cpu_is_omap44xx())
384 wdt_resources[0].start = 0x4a314000;
Felipe Balbi28171422008-09-20 04:14:01 +0300385 else
386 return;
387
388 wdt_resources[0].end = wdt_resources[0].start + 0x4f;
389
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000390 (void) platform_device_register(&omap_wdt_device);
391}
392#else
393static inline void omap_init_wdt(void) {}
394#endif
395
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000396/*
397 * This gets called after board-specific INIT_MACHINE, and initializes most
398 * on-chip peripherals accessible on this board (except for few like USB):
399 *
400 * (a) Does any "standard config" pin muxing needed. Board-specific
401 * code will have muxed GPIO pins and done "nonstandard" setup;
402 * that code could live in the boot loader.
403 * (b) Populating board-specific platform_data with the data drivers
404 * rely on to handle wiring variations.
405 * (c) Creating platform devices as meaningful on this board and
406 * with this kernel configuration.
407 *
408 * Claiming GPIOs, and setting their direction and initial values, is the
409 * responsibility of the device drivers. So is responding to probe().
410 *
411 * Board-specific knowlege like creating devices or pin setup is to be
412 * kept out of drivers as much as possible. In particular, pin setup
413 * may be handled by the boot loader, and drivers should expect it will
414 * normally have been done by the time they're probed.
415 */
416static int __init omap_init_devices(void)
417{
418 /* please keep these calls, and their implementations above,
419 * in alphabetical order so they're easier to sort through.
420 */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800421 omap_init_dsp();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100422 omap_init_kp();
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800423 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800424 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100425 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000426 omap_init_wdt();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000427 return 0;
428}
429arch_initcall(omap_init_devices);