blob: 64c3bd4aa54ecbd43c9d4f6eeccaaf97fa0001e1 [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 */
Russell King2f8163b2011-07-26 10:53:52 +010011#include <linux/gpio.h>
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>
Tony Lindgrence491cf2009-10-20 09:40:47 -070027#include <plat/menelaus.h>
28#include <plat/mcbsp.h>
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080029#include <plat/omap44xx.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000030
Tony Lindgrenc40fae952006-12-07 13:58:10 -080031/*-------------------------------------------------------------------------*/
Tony Lindgren9b6553c2006-04-02 17:46:30 +010032
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030033#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
34
35static struct platform_device **omap_mcbsp_devices;
36
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080037void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
38 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030039{
40 int i;
41
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030042 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
43 GFP_KERNEL);
44 if (!omap_mcbsp_devices) {
45 printk(KERN_ERR "Could not register McBSP devices\n");
46 return;
47 }
48
49 for (i = 0; i < size; i++) {
50 struct platform_device *new_mcbsp;
51 int ret;
52
53 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
54 if (!new_mcbsp)
55 continue;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080056 platform_device_add_resources(new_mcbsp, &res[i * res_count],
57 res_count);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030058 new_mcbsp->dev.platform_data = &config[i];
59 ret = platform_device_add(new_mcbsp);
60 if (ret) {
61 platform_device_put(new_mcbsp);
62 continue;
63 }
64 omap_mcbsp_devices[i] = new_mcbsp;
65 }
66}
67
68#else
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -080069void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
70 struct omap_mcbsp_platform_data *config, int size)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030071{ }
72#endif
73
74/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000075
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080076#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
77 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
78
79static struct resource mcpdm_resources[] = {
80 {
81 .name = "mcpdm_mem",
82 .start = OMAP44XX_MCPDM_BASE,
83 .end = OMAP44XX_MCPDM_BASE + SZ_4K,
84 .flags = IORESOURCE_MEM,
85 },
86 {
87 .name = "mcpdm_irq",
Santosh Shilimkar5772ca72010-02-18 03:14:12 +053088 .start = OMAP44XX_IRQ_MCPDM,
89 .end = OMAP44XX_IRQ_MCPDM,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080090 .flags = IORESOURCE_IRQ,
91 },
92};
93
94static struct platform_device omap_mcpdm_device = {
95 .name = "omap-mcpdm",
96 .id = -1,
97 .num_resources = ARRAY_SIZE(mcpdm_resources),
98 .resource = mcpdm_resources,
99};
100
101static void omap_init_mcpdm(void)
102{
103 (void) platform_device_register(&omap_mcpdm_device);
104}
105#else
106static inline void omap_init_mcpdm(void) {}
107#endif
108
109/*-------------------------------------------------------------------------*/
110
Tony Lindgrend8874662008-12-10 17:37:16 -0800111#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100112 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000113
Tony Lindgrend8874662008-12-10 17:37:16 -0800114#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000115
Tony Lindgrend8874662008-12-10 17:37:16 -0800116/*
117 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
118 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800119int __init omap_mmc_add(const char *name, int id, unsigned long base,
120 unsigned long size, unsigned int irq,
121 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000122{
Tony Lindgrend8874662008-12-10 17:37:16 -0800123 struct platform_device *pdev;
124 struct resource res[OMAP_MMC_NR_RES];
125 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000126
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800127 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800128 if (!pdev)
129 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000130
Tony Lindgrend8874662008-12-10 17:37:16 -0800131 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
132 res[0].start = base;
133 res[0].end = base + size - 1;
134 res[0].flags = IORESOURCE_MEM;
135 res[1].start = res[1].end = irq;
136 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000137
Tony Lindgrend8874662008-12-10 17:37:16 -0800138 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
139 if (ret == 0)
140 ret = platform_device_add_data(pdev, data, sizeof(*data));
141 if (ret)
142 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000143
Tony Lindgrend8874662008-12-10 17:37:16 -0800144 ret = platform_device_add(pdev);
145 if (ret)
146 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700147
148 /* return device handle to board setup code */
149 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800150 return 0;
151
152fail:
153 platform_device_put(pdev);
154 return ret;
Russell King7736c092008-09-09 10:16:22 +0100155}
156
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000157#endif
158
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100159/*-------------------------------------------------------------------------*/
160
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800161#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
162
Tony Lindgren088ef952010-02-12 12:26:47 -0800163#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800164#define OMAP_RNG_BASE 0x480A0000
165#else
166#define OMAP_RNG_BASE 0xfffe5000
167#endif
168
169static struct resource rng_resources[] = {
170 {
171 .start = OMAP_RNG_BASE,
172 .end = OMAP_RNG_BASE + 0x4f,
173 .flags = IORESOURCE_MEM,
174 },
175};
176
177static struct platform_device omap_rng_device = {
178 .name = "omap_rng",
179 .id = -1,
180 .num_resources = ARRAY_SIZE(rng_resources),
181 .resource = rng_resources,
182};
183
184static void omap_init_rng(void)
185{
186 (void) platform_device_register(&omap_rng_device);
187}
188#else
189static inline void omap_init_rng(void) {}
190#endif
191
192/*-------------------------------------------------------------------------*/
193
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100194/* Numbering for the SPI-capable controllers when used for SPI:
195 * spi = 1
196 * uwire = 2
197 * mmc1..2 = 3..4
198 * mcbsp1..3 = 5..7
199 */
200
201#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
202
203#define OMAP_UWIRE_BASE 0xfffb3000
204
205static struct resource uwire_resources[] = {
206 {
207 .start = OMAP_UWIRE_BASE,
208 .end = OMAP_UWIRE_BASE + 0x20,
209 .flags = IORESOURCE_MEM,
210 },
211};
212
213static struct platform_device omap_uwire_device = {
214 .name = "omap_uwire",
215 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100216 .num_resources = ARRAY_SIZE(uwire_resources),
217 .resource = uwire_resources,
218};
219
220static void omap_init_uwire(void)
221{
222 /* FIXME define and use a boot tag; not all boards will be hooking
223 * up devices to the microwire controller, and multi-board configs
224 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
225 */
226
227 /* board-specific code must configure chipselects (only a few
228 * are normally used) and SCLK/SDI/SDO (each has two choices).
229 */
230 (void) platform_device_register(&omap_uwire_device);
231}
232#else
233static inline void omap_init_uwire(void) {}
234#endif
235
Felipe Contreras90173882010-10-04 19:09:14 +0300236#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
237
238static phys_addr_t omap_dsp_phys_mempool_base;
239
240void __init omap_dsp_reserve_sdram_memblock(void)
241{
242 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
243 phys_addr_t paddr;
244
245 if (!size)
246 return;
247
Felipe Contreras89346f92010-10-19 10:37:24 +0300248 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300249 if (!paddr) {
250 pr_err("%s: failed to reserve %x bytes\n",
251 __func__, size);
252 return;
253 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300254 memblock_free(paddr, size);
255 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300256
257 omap_dsp_phys_mempool_base = paddr;
258}
259
260phys_addr_t omap_dsp_get_mempool_base(void)
261{
262 return omap_dsp_phys_mempool_base;
263}
264EXPORT_SYMBOL(omap_dsp_get_mempool_base);
265#endif
266
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000267/*
268 * This gets called after board-specific INIT_MACHINE, and initializes most
269 * on-chip peripherals accessible on this board (except for few like USB):
270 *
271 * (a) Does any "standard config" pin muxing needed. Board-specific
272 * code will have muxed GPIO pins and done "nonstandard" setup;
273 * that code could live in the boot loader.
274 * (b) Populating board-specific platform_data with the data drivers
275 * rely on to handle wiring variations.
276 * (c) Creating platform devices as meaningful on this board and
277 * with this kernel configuration.
278 *
279 * Claiming GPIOs, and setting their direction and initial values, is the
280 * responsibility of the device drivers. So is responding to probe().
281 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300282 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000283 * kept out of drivers as much as possible. In particular, pin setup
284 * may be handled by the boot loader, and drivers should expect it will
285 * normally have been done by the time they're probed.
286 */
287static int __init omap_init_devices(void)
288{
289 /* please keep these calls, and their implementations above,
290 * in alphabetical order so they're easier to sort through.
291 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800292 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800293 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100294 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000295 return 0;
296}
297arch_initcall(omap_init_devices);