blob: 53c6bb1de582eb17685de5c81d45978e62b9240c [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>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000019
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/hardware.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000021#include <asm/mach-types.h>
22#include <asm/mach/map.h>
23
Tony Lindgrence491cf2009-10-20 09:40:47 -070024#include <plat/tc.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070025#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>
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -060030#include <plat/mcpdm.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/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010034
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030035#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
36
37static struct platform_device **omap_mcbsp_devices;
38
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080039void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
40 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030041{
42 int i;
43
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030044 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
45 GFP_KERNEL);
46 if (!omap_mcbsp_devices) {
47 printk(KERN_ERR "Could not register McBSP devices\n");
48 return;
49 }
50
51 for (i = 0; i < size; i++) {
52 struct platform_device *new_mcbsp;
53 int ret;
54
55 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
56 if (!new_mcbsp)
57 continue;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080058 platform_device_add_resources(new_mcbsp, &res[i * res_count],
59 res_count);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030060 new_mcbsp->dev.platform_data = &config[i];
61 ret = platform_device_add(new_mcbsp);
62 if (ret) {
63 platform_device_put(new_mcbsp);
64 continue;
65 }
66 omap_mcbsp_devices[i] = new_mcbsp;
67 }
68}
69
70#else
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080071void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
72 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030073{ }
74#endif
75
76/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000077
David Lambert8c208e12011-02-12 22:35:03 -060078#if defined(CONFIG_SND_OMAP_SOC_DMIC) || \
79 defined(CONFIG_SND_OMAP_SOC_DMIC_MODULE)
80
81static struct omap_device_pm_latency omap_dmic_latency[] = {
82 {
83 .deactivate_func = omap_device_idle_hwmods,
84 .activate_func = omap_device_enable_hwmods,
85 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
86 },
87};
88
89static void omap_init_dmic(void)
90{
91 struct omap_hwmod *oh;
92 struct omap_device *od;
93
94 oh = omap_hwmod_lookup("dmic");
95 if (!oh) {
96 printk(KERN_ERR "Could not look up dmic hw_mod\n");
97 return;
98 }
99
100 od = omap_device_build("omap-dmic-dai", -1, oh, NULL, 0,
101 omap_dmic_latency,
102 ARRAY_SIZE(omap_dmic_latency), 0);
103 if (IS_ERR(od))
104 printk(KERN_ERR "Could not build omap_device for omap-dmic-dai\n");
105}
106#else
107static inline void omap_init_dmic(void) {}
108#endif
109
110/*-------------------------------------------------------------------------*/
111
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800112#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
113 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
114
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600115static struct omap_device_pm_latency omap_mcpdm_latency[] = {
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800116 {
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600117 .deactivate_func = omap_device_idle_hwmods,
118 .activate_func = omap_device_enable_hwmods,
119 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800120 },
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800121};
122
123static void omap_init_mcpdm(void)
124{
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -0600125 struct omap_hwmod *oh;
126 struct omap_device *od;
127 struct omap_mcpdm_platform_data *pdata;
128
129 oh = omap_hwmod_lookup("mcpdm");
130 if (!oh) {
131 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
132 return;
133 }
134
135 pdata = kzalloc(sizeof(struct omap_mcpdm_platform_data), GFP_KERNEL);
136 if (!pdata) {
137 printk(KERN_ERR "Could not allocate platform data\n");
138 return;
139 }
140
141 od = omap_device_build("omap-mcpdm", -1, oh, pdata,
142 sizeof(struct omap_mcpdm_platform_data),
143 omap_mcpdm_latency,
144 ARRAY_SIZE(omap_mcpdm_latency), 0);
145 if (IS_ERR(od))
146 printk(KERN_ERR "Could not build omap_device for omap-mcpdm-dai\n");
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800147}
148#else
149static inline void omap_init_mcpdm(void) {}
150#endif
151
152/*-------------------------------------------------------------------------*/
153
Tony Lindgrend8874662008-12-10 17:37:16 -0800154#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100155 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000156
Tony Lindgrend8874662008-12-10 17:37:16 -0800157#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000158
Tony Lindgrend8874662008-12-10 17:37:16 -0800159/*
160 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
161 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800162int __init omap_mmc_add(const char *name, int id, unsigned long base,
163 unsigned long size, unsigned int irq,
164 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000165{
Tony Lindgrend8874662008-12-10 17:37:16 -0800166 struct platform_device *pdev;
167 struct resource res[OMAP_MMC_NR_RES];
168 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000169
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800170 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800171 if (!pdev)
172 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000173
Tony Lindgrend8874662008-12-10 17:37:16 -0800174 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
175 res[0].start = base;
176 res[0].end = base + size - 1;
177 res[0].flags = IORESOURCE_MEM;
178 res[1].start = res[1].end = irq;
179 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000180
Tony Lindgrend8874662008-12-10 17:37:16 -0800181 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
182 if (ret == 0)
183 ret = platform_device_add_data(pdev, data, sizeof(*data));
184 if (ret)
185 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000186
Tony Lindgrend8874662008-12-10 17:37:16 -0800187 ret = platform_device_add(pdev);
188 if (ret)
189 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700190
191 /* return device handle to board setup code */
192 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800193 return 0;
194
195fail:
196 platform_device_put(pdev);
197 return ret;
Russell King7736c092008-09-09 10:16:22 +0100198}
199
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000200#endif
201
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100202/*-------------------------------------------------------------------------*/
203
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800204#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
205
Tony Lindgren088ef952010-02-12 12:26:47 -0800206#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800207#define OMAP_RNG_BASE 0x480A0000
208#else
209#define OMAP_RNG_BASE 0xfffe5000
210#endif
211
212static struct resource rng_resources[] = {
213 {
214 .start = OMAP_RNG_BASE,
215 .end = OMAP_RNG_BASE + 0x4f,
216 .flags = IORESOURCE_MEM,
217 },
218};
219
220static struct platform_device omap_rng_device = {
221 .name = "omap_rng",
222 .id = -1,
223 .num_resources = ARRAY_SIZE(rng_resources),
224 .resource = rng_resources,
225};
226
227static void omap_init_rng(void)
228{
229 (void) platform_device_register(&omap_rng_device);
230}
231#else
232static inline void omap_init_rng(void) {}
233#endif
234
235/*-------------------------------------------------------------------------*/
236
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100237/* Numbering for the SPI-capable controllers when used for SPI:
238 * spi = 1
239 * uwire = 2
240 * mmc1..2 = 3..4
241 * mcbsp1..3 = 5..7
242 */
243
244#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
245
246#define OMAP_UWIRE_BASE 0xfffb3000
247
248static struct resource uwire_resources[] = {
249 {
250 .start = OMAP_UWIRE_BASE,
251 .end = OMAP_UWIRE_BASE + 0x20,
252 .flags = IORESOURCE_MEM,
253 },
254};
255
256static struct platform_device omap_uwire_device = {
257 .name = "omap_uwire",
258 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100259 .num_resources = ARRAY_SIZE(uwire_resources),
260 .resource = uwire_resources,
261};
262
263static void omap_init_uwire(void)
264{
265 /* FIXME define and use a boot tag; not all boards will be hooking
266 * up devices to the microwire controller, and multi-board configs
267 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
268 */
269
270 /* board-specific code must configure chipselects (only a few
271 * are normally used) and SCLK/SDI/SDO (each has two choices).
272 */
273 (void) platform_device_register(&omap_uwire_device);
274}
275#else
276static inline void omap_init_uwire(void) {}
277#endif
278
Felipe Contreras90173882010-10-04 19:09:14 +0300279#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
280
281static phys_addr_t omap_dsp_phys_mempool_base;
282
283void __init omap_dsp_reserve_sdram_memblock(void)
284{
285 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
286 phys_addr_t paddr;
287
288 if (!size)
289 return;
290
Felipe Contreras89346f92010-10-19 10:37:24 +0300291 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300292 if (!paddr) {
293 pr_err("%s: failed to reserve %x bytes\n",
294 __func__, size);
295 return;
296 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300297 memblock_free(paddr, size);
298 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300299
300 omap_dsp_phys_mempool_base = paddr;
301}
302
303phys_addr_t omap_dsp_get_mempool_base(void)
304{
305 return omap_dsp_phys_mempool_base;
306}
307EXPORT_SYMBOL(omap_dsp_get_mempool_base);
308#endif
309
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000310/*
311 * This gets called after board-specific INIT_MACHINE, and initializes most
312 * on-chip peripherals accessible on this board (except for few like USB):
313 *
314 * (a) Does any "standard config" pin muxing needed. Board-specific
315 * code will have muxed GPIO pins and done "nonstandard" setup;
316 * that code could live in the boot loader.
317 * (b) Populating board-specific platform_data with the data drivers
318 * rely on to handle wiring variations.
319 * (c) Creating platform devices as meaningful on this board and
320 * with this kernel configuration.
321 *
322 * Claiming GPIOs, and setting their direction and initial values, is the
323 * responsibility of the device drivers. So is responding to probe().
324 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300325 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000326 * kept out of drivers as much as possible. In particular, pin setup
327 * may be handled by the boot loader, and drivers should expect it will
328 * normally have been done by the time they're probed.
329 */
330static int __init omap_init_devices(void)
331{
332 /* please keep these calls, and their implementations above,
333 * in alphabetical order so they're easier to sort through.
334 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800335 omap_init_rng();
David Lambert8c208e12011-02-12 22:35:03 -0600336 omap_init_dmic();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800337 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100338 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000339 return 0;
340}
341arch_initcall(omap_init_devices);