blob: ea28f98d5d6a63da2ab5ede0327ec9188f5caf97 [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 Candelariad6a2d9b2010-02-15 10:03:35 -080030#include <plat/omap44xx.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000031
Tony Lindgrenc40fae952006-12-07 13:58:10 -080032/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010033
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030034#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
35
36static struct platform_device **omap_mcbsp_devices;
37
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080038void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
39 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030040{
41 int i;
42
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030043 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
44 GFP_KERNEL);
45 if (!omap_mcbsp_devices) {
46 printk(KERN_ERR "Could not register McBSP devices\n");
47 return;
48 }
49
50 for (i = 0; i < size; i++) {
51 struct platform_device *new_mcbsp;
52 int ret;
53
54 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
55 if (!new_mcbsp)
56 continue;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080057 platform_device_add_resources(new_mcbsp, &res[i * res_count],
58 res_count);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030059 new_mcbsp->dev.platform_data = &config[i];
60 ret = platform_device_add(new_mcbsp);
61 if (ret) {
62 platform_device_put(new_mcbsp);
63 continue;
64 }
65 omap_mcbsp_devices[i] = new_mcbsp;
66 }
67}
68
69#else
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080070void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
71 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030072{ }
73#endif
74
75/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000076
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080077#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
78 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
79
80static struct resource mcpdm_resources[] = {
81 {
82 .name = "mcpdm_mem",
83 .start = OMAP44XX_MCPDM_BASE,
84 .end = OMAP44XX_MCPDM_BASE + SZ_4K,
85 .flags = IORESOURCE_MEM,
86 },
87 {
88 .name = "mcpdm_irq",
Santosh Shilimkar5772ca72010-02-18 03:14:12 +053089 .start = OMAP44XX_IRQ_MCPDM,
90 .end = OMAP44XX_IRQ_MCPDM,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080091 .flags = IORESOURCE_IRQ,
92 },
93};
94
95static struct platform_device omap_mcpdm_device = {
96 .name = "omap-mcpdm",
97 .id = -1,
98 .num_resources = ARRAY_SIZE(mcpdm_resources),
99 .resource = mcpdm_resources,
100};
101
102static void omap_init_mcpdm(void)
103{
104 (void) platform_device_register(&omap_mcpdm_device);
105}
106#else
107static inline void omap_init_mcpdm(void) {}
108#endif
109
110/*-------------------------------------------------------------------------*/
111
Tony Lindgrend8874662008-12-10 17:37:16 -0800112#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100113 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000114
Tony Lindgrend8874662008-12-10 17:37:16 -0800115#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000116
Tony Lindgrend8874662008-12-10 17:37:16 -0800117/*
118 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
119 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800120int __init omap_mmc_add(const char *name, int id, unsigned long base,
121 unsigned long size, unsigned int irq,
122 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000123{
Tony Lindgrend8874662008-12-10 17:37:16 -0800124 struct platform_device *pdev;
125 struct resource res[OMAP_MMC_NR_RES];
126 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000127
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800128 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800129 if (!pdev)
130 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000131
Tony Lindgrend8874662008-12-10 17:37:16 -0800132 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
133 res[0].start = base;
134 res[0].end = base + size - 1;
135 res[0].flags = IORESOURCE_MEM;
136 res[1].start = res[1].end = irq;
137 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000138
Tony Lindgrend8874662008-12-10 17:37:16 -0800139 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
140 if (ret == 0)
141 ret = platform_device_add_data(pdev, data, sizeof(*data));
142 if (ret)
143 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000144
Tony Lindgrend8874662008-12-10 17:37:16 -0800145 ret = platform_device_add(pdev);
146 if (ret)
147 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700148
149 /* return device handle to board setup code */
150 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800151 return 0;
152
153fail:
154 platform_device_put(pdev);
155 return ret;
Russell King7736c092008-09-09 10:16:22 +0100156}
157
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000158#endif
159
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100160/*-------------------------------------------------------------------------*/
161
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800162#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
163
Tony Lindgren088ef952010-02-12 12:26:47 -0800164#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800165#define OMAP_RNG_BASE 0x480A0000
166#else
167#define OMAP_RNG_BASE 0xfffe5000
168#endif
169
170static struct resource rng_resources[] = {
171 {
172 .start = OMAP_RNG_BASE,
173 .end = OMAP_RNG_BASE + 0x4f,
174 .flags = IORESOURCE_MEM,
175 },
176};
177
178static struct platform_device omap_rng_device = {
179 .name = "omap_rng",
180 .id = -1,
181 .num_resources = ARRAY_SIZE(rng_resources),
182 .resource = rng_resources,
183};
184
185static void omap_init_rng(void)
186{
187 (void) platform_device_register(&omap_rng_device);
188}
189#else
190static inline void omap_init_rng(void) {}
191#endif
192
193/*-------------------------------------------------------------------------*/
194
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100195/* Numbering for the SPI-capable controllers when used for SPI:
196 * spi = 1
197 * uwire = 2
198 * mmc1..2 = 3..4
199 * mcbsp1..3 = 5..7
200 */
201
202#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
203
204#define OMAP_UWIRE_BASE 0xfffb3000
205
206static struct resource uwire_resources[] = {
207 {
208 .start = OMAP_UWIRE_BASE,
209 .end = OMAP_UWIRE_BASE + 0x20,
210 .flags = IORESOURCE_MEM,
211 },
212};
213
214static struct platform_device omap_uwire_device = {
215 .name = "omap_uwire",
216 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100217 .num_resources = ARRAY_SIZE(uwire_resources),
218 .resource = uwire_resources,
219};
220
221static void omap_init_uwire(void)
222{
223 /* FIXME define and use a boot tag; not all boards will be hooking
224 * up devices to the microwire controller, and multi-board configs
225 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
226 */
227
228 /* board-specific code must configure chipselects (only a few
229 * are normally used) and SCLK/SDI/SDO (each has two choices).
230 */
231 (void) platform_device_register(&omap_uwire_device);
232}
233#else
234static inline void omap_init_uwire(void) {}
235#endif
236
Felipe Contreras90173882010-10-04 19:09:14 +0300237#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
238
239static phys_addr_t omap_dsp_phys_mempool_base;
240
241void __init omap_dsp_reserve_sdram_memblock(void)
242{
243 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
244 phys_addr_t paddr;
245
246 if (!size)
247 return;
248
Felipe Contreras89346f92010-10-19 10:37:24 +0300249 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300250 if (!paddr) {
251 pr_err("%s: failed to reserve %x bytes\n",
252 __func__, size);
253 return;
254 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300255 memblock_free(paddr, size);
256 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300257
258 omap_dsp_phys_mempool_base = paddr;
259}
260
261phys_addr_t omap_dsp_get_mempool_base(void)
262{
263 return omap_dsp_phys_mempool_base;
264}
265EXPORT_SYMBOL(omap_dsp_get_mempool_base);
266#endif
267
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000268/*
269 * This gets called after board-specific INIT_MACHINE, and initializes most
270 * on-chip peripherals accessible on this board (except for few like USB):
271 *
272 * (a) Does any "standard config" pin muxing needed. Board-specific
273 * code will have muxed GPIO pins and done "nonstandard" setup;
274 * that code could live in the boot loader.
275 * (b) Populating board-specific platform_data with the data drivers
276 * rely on to handle wiring variations.
277 * (c) Creating platform devices as meaningful on this board and
278 * with this kernel configuration.
279 *
280 * Claiming GPIOs, and setting their direction and initial values, is the
281 * responsibility of the device drivers. So is responding to probe().
282 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300283 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000284 * kept out of drivers as much as possible. In particular, pin setup
285 * may be handled by the boot loader, and drivers should expect it will
286 * normally have been done by the time they're probed.
287 */
288static int __init omap_init_devices(void)
289{
290 /* please keep these calls, and their implementations above,
291 * in alphabetical order so they're easier to sort through.
292 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800293 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800294 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100295 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000296 return 0;
297}
298arch_initcall(omap_init_devices);