blob: 10245b837c10d170c7addead6eb4e71ac3fc4194 [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
38void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
39 int size)
40{
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;
57 new_mcbsp->dev.platform_data = &config[i];
58 ret = platform_device_add(new_mcbsp);
59 if (ret) {
60 platform_device_put(new_mcbsp);
61 continue;
62 }
63 omap_mcbsp_devices[i] = new_mcbsp;
64 }
65}
66
67#else
68void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
69 int size)
70{ }
71#endif
72
73/*-------------------------------------------------------------------------*/
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000074
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080075#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
76 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
77
78static struct resource mcpdm_resources[] = {
79 {
80 .name = "mcpdm_mem",
81 .start = OMAP44XX_MCPDM_BASE,
82 .end = OMAP44XX_MCPDM_BASE + SZ_4K,
83 .flags = IORESOURCE_MEM,
84 },
85 {
86 .name = "mcpdm_irq",
Santosh Shilimkar5772ca72010-02-18 03:14:12 +053087 .start = OMAP44XX_IRQ_MCPDM,
88 .end = OMAP44XX_IRQ_MCPDM,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080089 .flags = IORESOURCE_IRQ,
90 },
91};
92
93static struct platform_device omap_mcpdm_device = {
94 .name = "omap-mcpdm",
95 .id = -1,
96 .num_resources = ARRAY_SIZE(mcpdm_resources),
97 .resource = mcpdm_resources,
98};
99
100static void omap_init_mcpdm(void)
101{
102 (void) platform_device_register(&omap_mcpdm_device);
103}
104#else
105static inline void omap_init_mcpdm(void) {}
106#endif
107
108/*-------------------------------------------------------------------------*/
109
Tony Lindgrend8874662008-12-10 17:37:16 -0800110#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100111 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000112
Tony Lindgrend8874662008-12-10 17:37:16 -0800113#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000114
Tony Lindgrend8874662008-12-10 17:37:16 -0800115/*
116 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
117 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800118int __init omap_mmc_add(const char *name, int id, unsigned long base,
119 unsigned long size, unsigned int irq,
120 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000121{
Tony Lindgrend8874662008-12-10 17:37:16 -0800122 struct platform_device *pdev;
123 struct resource res[OMAP_MMC_NR_RES];
124 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000125
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800126 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800127 if (!pdev)
128 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000129
Tony Lindgrend8874662008-12-10 17:37:16 -0800130 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
131 res[0].start = base;
132 res[0].end = base + size - 1;
133 res[0].flags = IORESOURCE_MEM;
134 res[1].start = res[1].end = irq;
135 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000136
Tony Lindgrend8874662008-12-10 17:37:16 -0800137 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
138 if (ret == 0)
139 ret = platform_device_add_data(pdev, data, sizeof(*data));
140 if (ret)
141 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000142
Tony Lindgrend8874662008-12-10 17:37:16 -0800143 ret = platform_device_add(pdev);
144 if (ret)
145 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700146
147 /* return device handle to board setup code */
148 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800149 return 0;
150
151fail:
152 platform_device_put(pdev);
153 return ret;
Russell King7736c092008-09-09 10:16:22 +0100154}
155
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000156#endif
157
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100158/*-------------------------------------------------------------------------*/
159
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800160#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
161
Tony Lindgren088ef952010-02-12 12:26:47 -0800162#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800163#define OMAP_RNG_BASE 0x480A0000
164#else
165#define OMAP_RNG_BASE 0xfffe5000
166#endif
167
168static struct resource rng_resources[] = {
169 {
170 .start = OMAP_RNG_BASE,
171 .end = OMAP_RNG_BASE + 0x4f,
172 .flags = IORESOURCE_MEM,
173 },
174};
175
176static struct platform_device omap_rng_device = {
177 .name = "omap_rng",
178 .id = -1,
179 .num_resources = ARRAY_SIZE(rng_resources),
180 .resource = rng_resources,
181};
182
183static void omap_init_rng(void)
184{
185 (void) platform_device_register(&omap_rng_device);
186}
187#else
188static inline void omap_init_rng(void) {}
189#endif
190
191/*-------------------------------------------------------------------------*/
192
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100193/* Numbering for the SPI-capable controllers when used for SPI:
194 * spi = 1
195 * uwire = 2
196 * mmc1..2 = 3..4
197 * mcbsp1..3 = 5..7
198 */
199
200#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
201
202#define OMAP_UWIRE_BASE 0xfffb3000
203
204static struct resource uwire_resources[] = {
205 {
206 .start = OMAP_UWIRE_BASE,
207 .end = OMAP_UWIRE_BASE + 0x20,
208 .flags = IORESOURCE_MEM,
209 },
210};
211
212static struct platform_device omap_uwire_device = {
213 .name = "omap_uwire",
214 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100215 .num_resources = ARRAY_SIZE(uwire_resources),
216 .resource = uwire_resources,
217};
218
219static void omap_init_uwire(void)
220{
221 /* FIXME define and use a boot tag; not all boards will be hooking
222 * up devices to the microwire controller, and multi-board configs
223 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
224 */
225
226 /* board-specific code must configure chipselects (only a few
227 * are normally used) and SCLK/SDI/SDO (each has two choices).
228 */
229 (void) platform_device_register(&omap_uwire_device);
230}
231#else
232static inline void omap_init_uwire(void) {}
233#endif
234
Felipe Contreras90173882010-10-04 19:09:14 +0300235#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
236
237static phys_addr_t omap_dsp_phys_mempool_base;
238
239void __init omap_dsp_reserve_sdram_memblock(void)
240{
241 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
242 phys_addr_t paddr;
243
244 if (!size)
245 return;
246
Felipe Contreras89346f92010-10-19 10:37:24 +0300247 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300248 if (!paddr) {
249 pr_err("%s: failed to reserve %x bytes\n",
250 __func__, size);
251 return;
252 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300253 memblock_free(paddr, size);
254 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300255
256 omap_dsp_phys_mempool_base = paddr;
257}
258
259phys_addr_t omap_dsp_get_mempool_base(void)
260{
261 return omap_dsp_phys_mempool_base;
262}
263EXPORT_SYMBOL(omap_dsp_get_mempool_base);
264#endif
265
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000266/*
267 * This gets called after board-specific INIT_MACHINE, and initializes most
268 * on-chip peripherals accessible on this board (except for few like USB):
269 *
270 * (a) Does any "standard config" pin muxing needed. Board-specific
271 * code will have muxed GPIO pins and done "nonstandard" setup;
272 * that code could live in the boot loader.
273 * (b) Populating board-specific platform_data with the data drivers
274 * rely on to handle wiring variations.
275 * (c) Creating platform devices as meaningful on this board and
276 * with this kernel configuration.
277 *
278 * Claiming GPIOs, and setting their direction and initial values, is the
279 * responsibility of the device drivers. So is responding to probe().
280 *
281 * Board-specific knowlege like creating devices or pin setup is to be
282 * kept out of drivers as much as possible. In particular, pin setup
283 * may be handled by the boot loader, and drivers should expect it will
284 * normally have been done by the time they're probed.
285 */
286static int __init omap_init_devices(void)
287{
288 /* please keep these calls, and their implementations above,
289 * in alphabetical order so they're easier to sort through.
290 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800291 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800292 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100293 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000294 return 0;
295}
296arch_initcall(omap_init_devices);