blob: 2625ce32e6020f060dd874968322475f11708116 [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>
16
Russell Kinga09e64f2008-08-05 16:14:15 +010017#include <mach/hardware.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000018#include <asm/io.h>
19#include <asm/mach-types.h>
20#include <asm/mach/map.h>
21
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/tc.h>
Tony Lindgren646e3ed2008-10-06 15:49:36 +030023#include <mach/control.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/board.h>
25#include <mach/mux.h>
26#include <mach/gpio.h>
27#include <mach/menelaus.h>
28#include <mach/mcbsp.h>
Tony Lindgren646e3ed2008-10-06 15:49:36 +030029#include <mach/dsp_common.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000030
Tony Lindgrenc40fae952006-12-07 13:58:10 -080031#if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
32
Tony Lindgrenc40fae952006-12-07 13:58:10 -080033static struct dsp_platform_data dsp_pdata = {
34 .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list),
35};
36
37static struct resource omap_dsp_resources[] = {
38 {
39 .name = "dsp_mmu",
40 .start = -1,
41 .flags = IORESOURCE_IRQ,
42 },
43};
44
45static 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
55static 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
74int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev)
75{
76 static DEFINE_MUTEX(dsp_pdata_lock);
77
Tony Lindgren646e3ed2008-10-06 15:49:36 +030078 spin_lock_init(&kdev->lock);
Tony Lindgrenc40fae952006-12-07 13:58:10 -080079
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}
86EXPORT_SYMBOL(dsp_kfunc_device_register);
87
88#else
89static inline void omap_init_dsp(void) { }
90#endif /* CONFIG_OMAP_DSP */
91
92/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010093#if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
94
95static void omap_init_kp(void)
96{
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030097 /* 2430 and 34xx keypad is on TWL4030 */
98 if (cpu_is_omap2430() || cpu_is_omap34xx())
99 return;
100
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100101 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);
Brian Swetland495f71d2006-06-26 16:16:03 -0700114 } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) {
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100115 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
149static inline void omap_init_kp(void) {}
150#endif
151
152/*-------------------------------------------------------------------------*/
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300153#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
154
155static struct platform_device **omap_mcbsp_devices;
156
157void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
158 int size)
159{
160 int i;
161
162 if (size > OMAP_MAX_MCBSP_COUNT) {
163 printk(KERN_WARNING "Registered too many McBSPs platform_data."
164 " Using maximum (%d) available.\n",
165 OMAP_MAX_MCBSP_COUNT);
166 size = OMAP_MAX_MCBSP_COUNT;
167 }
168
169 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
170 GFP_KERNEL);
171 if (!omap_mcbsp_devices) {
172 printk(KERN_ERR "Could not register McBSP devices\n");
173 return;
174 }
175
176 for (i = 0; i < size; i++) {
177 struct platform_device *new_mcbsp;
178 int ret;
179
180 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
181 if (!new_mcbsp)
182 continue;
183 new_mcbsp->dev.platform_data = &config[i];
184 ret = platform_device_add(new_mcbsp);
185 if (ret) {
186 platform_device_put(new_mcbsp);
187 continue;
188 }
189 omap_mcbsp_devices[i] = new_mcbsp;
190 }
191}
192
193#else
194void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
195 int size)
196{ }
197#endif
198
199/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000200
201#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
202
203#ifdef CONFIG_ARCH_OMAP24XX
204#define OMAP_MMC1_BASE 0x4809c000
Kyungmin Parkabc45e12006-09-25 12:41:25 +0300205#define OMAP_MMC1_INT INT_24XX_MMC_IRQ
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000206#else
207#define OMAP_MMC1_BASE 0xfffb7800
208#define OMAP_MMC1_INT INT_MMC
209#endif
210#define OMAP_MMC2_BASE 0xfffb7c00 /* omap16xx only */
211
212static struct omap_mmc_conf mmc1_conf;
213
214static u64 mmc1_dmamask = 0xffffffff;
215
216static struct resource mmc1_resources[] = {
217 {
Tony Lindgrence9c1a82006-07-01 19:56:44 +0100218 .start = OMAP_MMC1_BASE,
219 .end = OMAP_MMC1_BASE + 0x7f,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000220 .flags = IORESOURCE_MEM,
221 },
222 {
223 .start = OMAP_MMC1_INT,
224 .flags = IORESOURCE_IRQ,
225 },
226};
227
228static struct platform_device mmc_omap_device1 = {
229 .name = "mmci-omap",
230 .id = 1,
231 .dev = {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000232 .dma_mask = &mmc1_dmamask,
233 .platform_data = &mmc1_conf,
234 },
235 .num_resources = ARRAY_SIZE(mmc1_resources),
236 .resource = mmc1_resources,
237};
238
239#ifdef CONFIG_ARCH_OMAP16XX
240
241static struct omap_mmc_conf mmc2_conf;
242
243static u64 mmc2_dmamask = 0xffffffff;
244
245static struct resource mmc2_resources[] = {
246 {
Tony Lindgrence9c1a82006-07-01 19:56:44 +0100247 .start = OMAP_MMC2_BASE,
248 .end = OMAP_MMC2_BASE + 0x7f,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000249 .flags = IORESOURCE_MEM,
250 },
251 {
252 .start = INT_1610_MMC2,
253 .flags = IORESOURCE_IRQ,
254 },
255};
256
257static struct platform_device mmc_omap_device2 = {
258 .name = "mmci-omap",
259 .id = 2,
260 .dev = {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000261 .dma_mask = &mmc2_dmamask,
262 .platform_data = &mmc2_conf,
263 },
264 .num_resources = ARRAY_SIZE(mmc2_resources),
265 .resource = mmc2_resources,
266};
267#endif
268
269static void __init omap_init_mmc(void)
270{
271 const struct omap_mmc_config *mmc_conf;
272 const struct omap_mmc_conf *mmc;
273
274 /* NOTE: assumes MMC was never (wrongly) enabled */
275 mmc_conf = omap_get_config(OMAP_TAG_MMC, struct omap_mmc_config);
276 if (!mmc_conf)
277 return;
278
279 /* block 1 is always available and has just one pinout option */
280 mmc = &mmc_conf->mmc[0];
281 if (mmc->enabled) {
Kyungmin Parkabc45e12006-09-25 12:41:25 +0300282 if (cpu_is_omap24xx()) {
283 omap_cfg_reg(H18_24XX_MMC_CMD);
284 omap_cfg_reg(H15_24XX_MMC_CLKI);
285 omap_cfg_reg(G19_24XX_MMC_CLKO);
286 omap_cfg_reg(F20_24XX_MMC_DAT0);
287 omap_cfg_reg(F19_24XX_MMC_DAT_DIR0);
288 omap_cfg_reg(G18_24XX_MMC_CMD_DIR);
289 } else {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000290 omap_cfg_reg(MMC_CMD);
291 omap_cfg_reg(MMC_CLK);
292 omap_cfg_reg(MMC_DAT0);
293 if (cpu_is_omap1710()) {
294 omap_cfg_reg(M15_1710_MMC_CLKI);
295 omap_cfg_reg(P19_1710_MMC_CMDDIR);
296 omap_cfg_reg(P20_1710_MMC_DATDIR0);
297 }
298 }
299 if (mmc->wire4) {
Kyungmin Parkabc45e12006-09-25 12:41:25 +0300300 if (cpu_is_omap24xx()) {
301 omap_cfg_reg(H14_24XX_MMC_DAT1);
302 omap_cfg_reg(E19_24XX_MMC_DAT2);
303 omap_cfg_reg(D19_24XX_MMC_DAT3);
304 omap_cfg_reg(E20_24XX_MMC_DAT_DIR1);
305 omap_cfg_reg(F18_24XX_MMC_DAT_DIR2);
306 omap_cfg_reg(E18_24XX_MMC_DAT_DIR3);
307 } else {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000308 omap_cfg_reg(MMC_DAT1);
309 /* NOTE: DAT2 can be on W10 (here) or M15 */
310 if (!mmc->nomux)
311 omap_cfg_reg(MMC_DAT2);
312 omap_cfg_reg(MMC_DAT3);
313 }
314 }
315 mmc1_conf = *mmc;
316 (void) platform_device_register(&mmc_omap_device1);
317 }
318
319#ifdef CONFIG_ARCH_OMAP16XX
320 /* block 2 is on newer chips, and has many pinout options */
321 mmc = &mmc_conf->mmc[1];
322 if (mmc->enabled) {
323 if (!mmc->nomux) {
324 omap_cfg_reg(Y8_1610_MMC2_CMD);
325 omap_cfg_reg(Y10_1610_MMC2_CLK);
326 omap_cfg_reg(R18_1610_MMC2_CLKIN);
327 omap_cfg_reg(W8_1610_MMC2_DAT0);
328 if (mmc->wire4) {
329 omap_cfg_reg(V8_1610_MMC2_DAT1);
330 omap_cfg_reg(W15_1610_MMC2_DAT2);
331 omap_cfg_reg(R10_1610_MMC2_DAT3);
332 }
333
334 /* These are needed for the level shifter */
335 omap_cfg_reg(V9_1610_MMC2_CMDDIR);
336 omap_cfg_reg(V5_1610_MMC2_DATDIR0);
337 omap_cfg_reg(W19_1610_MMC2_DATDIR1);
338 }
339
340 /* Feedback clock must be set on OMAP-1710 MMC2 */
341 if (cpu_is_omap1710())
342 omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
343 MOD_CONF_CTRL_1);
344 mmc2_conf = *mmc;
345 (void) platform_device_register(&mmc_omap_device2);
346 }
347#endif
348 return;
349}
350#else
351static inline void omap_init_mmc(void) {}
352#endif
353
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100354/*-------------------------------------------------------------------------*/
355
356/* Numbering for the SPI-capable controllers when used for SPI:
357 * spi = 1
358 * uwire = 2
359 * mmc1..2 = 3..4
360 * mcbsp1..3 = 5..7
361 */
362
363#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
364
365#define OMAP_UWIRE_BASE 0xfffb3000
366
367static struct resource uwire_resources[] = {
368 {
369 .start = OMAP_UWIRE_BASE,
370 .end = OMAP_UWIRE_BASE + 0x20,
371 .flags = IORESOURCE_MEM,
372 },
373};
374
375static struct platform_device omap_uwire_device = {
376 .name = "omap_uwire",
377 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100378 .num_resources = ARRAY_SIZE(uwire_resources),
379 .resource = uwire_resources,
380};
381
382static void omap_init_uwire(void)
383{
384 /* FIXME define and use a boot tag; not all boards will be hooking
385 * up devices to the microwire controller, and multi-board configs
386 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
387 */
388
389 /* board-specific code must configure chipselects (only a few
390 * are normally used) and SCLK/SDI/SDO (each has two choices).
391 */
392 (void) platform_device_register(&omap_uwire_device);
393}
394#else
395static inline void omap_init_uwire(void) {}
396#endif
397
398/*-------------------------------------------------------------------------*/
399
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000400#if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
401
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300402#if defined(CONFIG_ARCH_OMAP34XX)
403#define OMAP_WDT_BASE 0x48314000
404#elif defined(CONFIG_ARCH_OMAP24XX)
405
406#ifdef CONFIG_ARCH_OMAP2430
407/* WDT2 */
408#define OMAP_WDT_BASE 0x49016000
409#else
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000410#define OMAP_WDT_BASE 0x48022000
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300411#endif
412
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000413#else
414#define OMAP_WDT_BASE 0xfffeb000
415#endif
416
417static struct resource wdt_resources[] = {
418 {
419 .start = OMAP_WDT_BASE,
420 .end = OMAP_WDT_BASE + 0x4f,
421 .flags = IORESOURCE_MEM,
422 },
423};
424
425static struct platform_device omap_wdt_device = {
426 .name = "omap_wdt",
427 .id = -1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000428 .num_resources = ARRAY_SIZE(wdt_resources),
429 .resource = wdt_resources,
430};
431
432static void omap_init_wdt(void)
433{
434 (void) platform_device_register(&omap_wdt_device);
435}
436#else
437static inline void omap_init_wdt(void) {}
438#endif
439
440/*-------------------------------------------------------------------------*/
441
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800442#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000443
444#ifdef CONFIG_ARCH_OMAP24XX
445#define OMAP_RNG_BASE 0x480A0000
446#else
447#define OMAP_RNG_BASE 0xfffe5000
448#endif
449
450static struct resource rng_resources[] = {
451 {
452 .start = OMAP_RNG_BASE,
453 .end = OMAP_RNG_BASE + 0x4f,
454 .flags = IORESOURCE_MEM,
455 },
456};
457
458static struct platform_device omap_rng_device = {
459 .name = "omap_rng",
460 .id = -1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000461 .num_resources = ARRAY_SIZE(rng_resources),
462 .resource = rng_resources,
463};
464
465static void omap_init_rng(void)
466{
467 (void) platform_device_register(&omap_rng_device);
468}
469#else
470static inline void omap_init_rng(void) {}
471#endif
472
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000473/*
474 * This gets called after board-specific INIT_MACHINE, and initializes most
475 * on-chip peripherals accessible on this board (except for few like USB):
476 *
477 * (a) Does any "standard config" pin muxing needed. Board-specific
478 * code will have muxed GPIO pins and done "nonstandard" setup;
479 * that code could live in the boot loader.
480 * (b) Populating board-specific platform_data with the data drivers
481 * rely on to handle wiring variations.
482 * (c) Creating platform devices as meaningful on this board and
483 * with this kernel configuration.
484 *
485 * Claiming GPIOs, and setting their direction and initial values, is the
486 * responsibility of the device drivers. So is responding to probe().
487 *
488 * Board-specific knowlege like creating devices or pin setup is to be
489 * kept out of drivers as much as possible. In particular, pin setup
490 * may be handled by the boot loader, and drivers should expect it will
491 * normally have been done by the time they're probed.
492 */
493static int __init omap_init_devices(void)
494{
495 /* please keep these calls, and their implementations above,
496 * in alphabetical order so they're easier to sort through.
497 */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800498 omap_init_dsp();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100499 omap_init_kp();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000500 omap_init_mmc();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100501 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000502 omap_init_wdt();
503 omap_init_rng();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000504 return 0;
505}
506arch_initcall(omap_init_devices);