blob: a66a4686942ac2d387c6c95ad40b7b10f732f13f [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>
Felipe Contreras90173882010-10-04 19:09:14 +030018#include <linux/memblock.h>
Liam Girdwood089aef32011-02-12 22:19:09 -060019#include <linux/err.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000020
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/hardware.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000022#include <asm/mach-types.h>
23#include <asm/mach/map.h>
24
Liam Girdwood089aef32011-02-12 22:19:09 -060025#include <plat/omap_hwmod.h>
26#include <plat/omap_device.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070027#include <plat/tc.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070028#include <plat/board.h>
29#include <plat/mmc.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070031#include <plat/menelaus.h>
32#include <plat/mcbsp.h>
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -060033#include <plat/mcpdm.h>
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080034#include <plat/omap44xx.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000035
Liam Girdwood089aef32011-02-12 22:19:09 -060036#include <sound/omap-abe-dsp.h>
37
Tony Lindgrenc40fae92006-12-07 13:58:10 -080038/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010039
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030040#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
41
42static struct platform_device **omap_mcbsp_devices;
43
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080044void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
45 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030046{
47 int i;
48
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030049 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
50 GFP_KERNEL);
51 if (!omap_mcbsp_devices) {
52 printk(KERN_ERR "Could not register McBSP devices\n");
53 return;
54 }
55
56 for (i = 0; i < size; i++) {
57 struct platform_device *new_mcbsp;
58 int ret;
59
60 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
61 if (!new_mcbsp)
62 continue;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080063 platform_device_add_resources(new_mcbsp, &res[i * res_count],
64 res_count);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030065 new_mcbsp->dev.platform_data = &config[i];
66 ret = platform_device_add(new_mcbsp);
67 if (ret) {
68 platform_device_put(new_mcbsp);
69 continue;
70 }
71 omap_mcbsp_devices[i] = new_mcbsp;
72 }
73}
74
75#else
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080076void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
77 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030078{ }
79#endif
80
81/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000082
David Lambert8c208e12011-02-12 22:35:03 -060083#if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
84 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
85
86static struct omap_device_pm_latency omap_dmic_latency[] = {
87 {
88 .deactivate_func = omap_device_idle_hwmods,
89 .activate_func = omap_device_enable_hwmods,
90 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
91 },
92};
93
94static void omap_init_dmic(void)
95{
96 struct omap_hwmod *oh;
97 struct omap_device *od;
98
99 oh = omap_hwmod_lookup("dmic");
100 if (!oh) {
101 printk(KERN_ERR "Could not look up dmic hw_mod\n");
102 return;
103 }
104
105 od = omap_device_build("omap-dmic-dai", -1, oh, NULL, 0,
106 omap_dmic_latency,
107 ARRAY_SIZE(omap_dmic_latency), 0);
108 if (IS_ERR(od))
109 printk(KERN_ERR "Could not build omap_device for omap-dmic-dai\n");
110}
111#else
112static inline void omap_init_dmic(void) {}
113#endif
114
115/*-------------------------------------------------------------------------*/
116
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800117#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
118 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
119
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600120static struct omap_device_pm_latency omap_mcpdm_latency[] = {
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800121 {
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600122 .deactivate_func = omap_device_idle_hwmods,
123 .activate_func = omap_device_enable_hwmods,
124 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800125 },
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800126};
127
128static void omap_init_mcpdm(void)
129{
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600130 struct omap_hwmod *oh;
131 struct omap_device *od;
132 struct omap_mcpdm_platform_data *pdata;
133
134 oh = omap_hwmod_lookup("mcpdm");
135 if (!oh) {
136 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
137 return;
138 }
139
140 pdata = kzalloc(sizeof(struct omap_mcpdm_platform_data), GFP_KERNEL);
141 if (!pdata) {
142 printk(KERN_ERR "Could not allocate platform data\n");
143 return;
144 }
145
146 od = omap_device_build("omap-mcpdm", -1, oh, pdata,
147 sizeof(struct omap_mcpdm_platform_data),
148 omap_mcpdm_latency,
149 ARRAY_SIZE(omap_mcpdm_latency), 0);
150 if (IS_ERR(od))
151 printk(KERN_ERR "Could not build omap_device for omap-mcpdm-dai\n");
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800152}
153#else
154static inline void omap_init_mcpdm(void) {}
155#endif
156
157/*-------------------------------------------------------------------------*/
158
Tony Lindgrend8874662008-12-10 17:37:16 -0800159#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100160 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000161
Tony Lindgrend8874662008-12-10 17:37:16 -0800162#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000163
Tony Lindgrend8874662008-12-10 17:37:16 -0800164/*
165 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
166 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800167int __init omap_mmc_add(const char *name, int id, unsigned long base,
168 unsigned long size, unsigned int irq,
169 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000170{
Tony Lindgrend8874662008-12-10 17:37:16 -0800171 struct platform_device *pdev;
172 struct resource res[OMAP_MMC_NR_RES];
173 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000174
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800175 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800176 if (!pdev)
177 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000178
Tony Lindgrend8874662008-12-10 17:37:16 -0800179 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
180 res[0].start = base;
181 res[0].end = base + size - 1;
182 res[0].flags = IORESOURCE_MEM;
183 res[1].start = res[1].end = irq;
184 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000185
Tony Lindgrend8874662008-12-10 17:37:16 -0800186 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
187 if (ret == 0)
188 ret = platform_device_add_data(pdev, data, sizeof(*data));
189 if (ret)
190 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000191
Tony Lindgrend8874662008-12-10 17:37:16 -0800192 ret = platform_device_add(pdev);
193 if (ret)
194 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700195
196 /* return device handle to board setup code */
197 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800198 return 0;
199
200fail:
201 platform_device_put(pdev);
202 return ret;
Russell King7736c092008-09-09 10:16:22 +0100203}
204
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000205#endif
206
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100207/*-------------------------------------------------------------------------*/
208
Liam Girdwood089aef32011-02-12 22:19:09 -0600209#if defined(CONFIG_SND_OMAP_SOC_ABE_DSP) || \
210 defined(CONFIG_SND_OMAP_SOC_ABE_DSP_MODULE)
211
212static struct omap_device_pm_latency omap_aess_latency[] = {
213 {
214 .deactivate_func = omap_device_idle_hwmods,
215 .activate_func = omap_device_enable_hwmods,
216 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
217 },
218};
219
220static void omap_init_aess(void)
221{
222 struct omap_hwmod *oh;
223 struct omap_device *od;
224 struct omap4_abe_dsp_pdata *pdata;
225
226 oh = omap_hwmod_lookup("aess");
227 if (!oh) {
228 printk (KERN_ERR "Could not look up aess hw_mod\n");
229 return;
230 }
231
232 pdata = kzalloc(sizeof(struct omap4_abe_dsp_pdata), GFP_KERNEL);
233 if (!pdata) {
234 printk(KERN_ERR "Could not allocate platform data\n");
235 return;
236 }
237
238 /* FIXME: Add correct context loss counter */
239 //pdata->get_context_loss_count = omap_pm_get_dev_context_loss_count;
240
241 od = omap_device_build("aess", -1, oh, pdata,
242 sizeof(struct omap4_abe_dsp_pdata),
243 omap_aess_latency,
244 ARRAY_SIZE(omap_aess_latency), 0);
245
246 kfree(pdata);
247
248 if (IS_ERR(od))
249 printk(KERN_ERR "Could not build omap_device for omap-aess-audio\n");
250}
251#else
252static inline void omap_init_aess(void) {}
253#endif
254
255
256/*-------------------------------------------------------------------------*/
257
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800258#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
259
Tony Lindgren088ef952010-02-12 12:26:47 -0800260#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800261#define OMAP_RNG_BASE 0x480A0000
262#else
263#define OMAP_RNG_BASE 0xfffe5000
264#endif
265
266static struct resource rng_resources[] = {
267 {
268 .start = OMAP_RNG_BASE,
269 .end = OMAP_RNG_BASE + 0x4f,
270 .flags = IORESOURCE_MEM,
271 },
272};
273
274static struct platform_device omap_rng_device = {
275 .name = "omap_rng",
276 .id = -1,
277 .num_resources = ARRAY_SIZE(rng_resources),
278 .resource = rng_resources,
279};
280
281static void omap_init_rng(void)
282{
283 (void) platform_device_register(&omap_rng_device);
284}
285#else
286static inline void omap_init_rng(void) {}
287#endif
288
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100289/* Numbering for the SPI-capable controllers when used for SPI:
290 * spi = 1
291 * uwire = 2
292 * mmc1..2 = 3..4
293 * mcbsp1..3 = 5..7
294 */
295
296#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
297
298#define OMAP_UWIRE_BASE 0xfffb3000
299
300static struct resource uwire_resources[] = {
301 {
302 .start = OMAP_UWIRE_BASE,
303 .end = OMAP_UWIRE_BASE + 0x20,
304 .flags = IORESOURCE_MEM,
305 },
306};
307
308static struct platform_device omap_uwire_device = {
309 .name = "omap_uwire",
310 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100311 .num_resources = ARRAY_SIZE(uwire_resources),
312 .resource = uwire_resources,
313};
314
315static void omap_init_uwire(void)
316{
317 /* FIXME define and use a boot tag; not all boards will be hooking
318 * up devices to the microwire controller, and multi-board configs
319 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
320 */
321
322 /* board-specific code must configure chipselects (only a few
323 * are normally used) and SCLK/SDI/SDO (each has two choices).
324 */
325 (void) platform_device_register(&omap_uwire_device);
326}
327#else
328static inline void omap_init_uwire(void) {}
329#endif
330
Felipe Contreras90173882010-10-04 19:09:14 +0300331#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
332
333static phys_addr_t omap_dsp_phys_mempool_base;
334
335void __init omap_dsp_reserve_sdram_memblock(void)
336{
337 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
338 phys_addr_t paddr;
339
340 if (!size)
341 return;
342
Felipe Contreras89346f92010-10-19 10:37:24 +0300343 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300344 if (!paddr) {
345 pr_err("%s: failed to reserve %x bytes\n",
346 __func__, size);
347 return;
348 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300349 memblock_free(paddr, size);
350 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300351
352 omap_dsp_phys_mempool_base = paddr;
353}
354
355phys_addr_t omap_dsp_get_mempool_base(void)
356{
357 return omap_dsp_phys_mempool_base;
358}
359EXPORT_SYMBOL(omap_dsp_get_mempool_base);
360#endif
361
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000362/*
363 * This gets called after board-specific INIT_MACHINE, and initializes most
364 * on-chip peripherals accessible on this board (except for few like USB):
365 *
366 * (a) Does any "standard config" pin muxing needed. Board-specific
367 * code will have muxed GPIO pins and done "nonstandard" setup;
368 * that code could live in the boot loader.
369 * (b) Populating board-specific platform_data with the data drivers
370 * rely on to handle wiring variations.
371 * (c) Creating platform devices as meaningful on this board and
372 * with this kernel configuration.
373 *
374 * Claiming GPIOs, and setting their direction and initial values, is the
375 * responsibility of the device drivers. So is responding to probe().
376 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300377 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000378 * kept out of drivers as much as possible. In particular, pin setup
379 * may be handled by the boot loader, and drivers should expect it will
380 * normally have been done by the time they're probed.
381 */
382static int __init omap_init_devices(void)
383{
384 /* please keep these calls, and their implementations above,
385 * in alphabetical order so they're easier to sort through.
386 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800387 omap_init_rng();
David Lambert8c208e12011-02-12 22:35:03 -0600388 omap_init_dmic();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800389 omap_init_mcpdm();
Liam Girdwood089aef32011-02-12 22:19:09 -0600390 omap_init_aess();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100391 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000392 return 0;
393}
394arch_initcall(omap_init_devices);