blob: 2afeda916432070682b5b5d07e214d309304699d [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
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080078#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
79 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
80
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -060081static struct omap_device_pm_latency omap_mcpdm_latency[] = {
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080082 {
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -060083 .deactivate_func = omap_device_idle_hwmods,
84 .activate_func = omap_device_enable_hwmods,
85 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080086 },
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -080087};
88
89static void omap_init_mcpdm(void)
90{
Jorge Eduardo Candelariac5f15aa2011-02-12 22:28:56 -060091 struct omap_hwmod *oh;
92 struct omap_device *od;
93 struct omap_mcpdm_platform_data *pdata;
94
95 oh = omap_hwmod_lookup("mcpdm");
96 if (!oh) {
97 printk(KERN_ERR "Could not look up mcpdm hw_mod\n");
98 return;
99 }
100
101 pdata = kzalloc(sizeof(struct omap_mcpdm_platform_data), GFP_KERNEL);
102 if (!pdata) {
103 printk(KERN_ERR "Could not allocate platform data\n");
104 return;
105 }
106
107 od = omap_device_build("omap-mcpdm", -1, oh, pdata,
108 sizeof(struct omap_mcpdm_platform_data),
109 omap_mcpdm_latency,
110 ARRAY_SIZE(omap_mcpdm_latency), 0);
111 if (IS_ERR(od))
112 printk(KERN_ERR "Could not build omap_device for omap-mcpdm-dai\n");
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800113}
114#else
115static inline void omap_init_mcpdm(void) {}
116#endif
117
118/*-------------------------------------------------------------------------*/
119
Tony Lindgrend8874662008-12-10 17:37:16 -0800120#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
Russell King7736c092008-09-09 10:16:22 +0100121 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000122
Tony Lindgrend8874662008-12-10 17:37:16 -0800123#define OMAP_MMC_NR_RES 2
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000124
Tony Lindgrend8874662008-12-10 17:37:16 -0800125/*
126 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
127 */
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800128int __init omap_mmc_add(const char *name, int id, unsigned long base,
129 unsigned long size, unsigned int irq,
130 struct omap_mmc_platform_data *data)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000131{
Tony Lindgrend8874662008-12-10 17:37:16 -0800132 struct platform_device *pdev;
133 struct resource res[OMAP_MMC_NR_RES];
134 int ret;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000135
Tony Lindgren0dffb5c2009-01-29 08:57:16 -0800136 pdev = platform_device_alloc(name, id);
Tony Lindgrend8874662008-12-10 17:37:16 -0800137 if (!pdev)
138 return -ENOMEM;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000139
Tony Lindgrend8874662008-12-10 17:37:16 -0800140 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
141 res[0].start = base;
142 res[0].end = base + size - 1;
143 res[0].flags = IORESOURCE_MEM;
144 res[1].start = res[1].end = irq;
145 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000146
Tony Lindgrend8874662008-12-10 17:37:16 -0800147 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
148 if (ret == 0)
149 ret = platform_device_add_data(pdev, data, sizeof(*data));
150 if (ret)
151 goto fail;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000152
Tony Lindgrend8874662008-12-10 17:37:16 -0800153 ret = platform_device_add(pdev);
154 if (ret)
155 goto fail;
David Brownell01971f62009-03-23 18:23:47 -0700156
157 /* return device handle to board setup code */
158 data->dev = &pdev->dev;
Tony Lindgrend8874662008-12-10 17:37:16 -0800159 return 0;
160
161fail:
162 platform_device_put(pdev);
163 return ret;
Russell King7736c092008-09-09 10:16:22 +0100164}
165
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000166#endif
167
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100168/*-------------------------------------------------------------------------*/
169
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800170#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
171
Tony Lindgren088ef952010-02-12 12:26:47 -0800172#ifdef CONFIG_ARCH_OMAP2
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800173#define OMAP_RNG_BASE 0x480A0000
174#else
175#define OMAP_RNG_BASE 0xfffe5000
176#endif
177
178static struct resource rng_resources[] = {
179 {
180 .start = OMAP_RNG_BASE,
181 .end = OMAP_RNG_BASE + 0x4f,
182 .flags = IORESOURCE_MEM,
183 },
184};
185
186static struct platform_device omap_rng_device = {
187 .name = "omap_rng",
188 .id = -1,
189 .num_resources = ARRAY_SIZE(rng_resources),
190 .resource = rng_resources,
191};
192
193static void omap_init_rng(void)
194{
195 (void) platform_device_register(&omap_rng_device);
196}
197#else
198static inline void omap_init_rng(void) {}
199#endif
200
201/*-------------------------------------------------------------------------*/
202
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100203/* Numbering for the SPI-capable controllers when used for SPI:
204 * spi = 1
205 * uwire = 2
206 * mmc1..2 = 3..4
207 * mcbsp1..3 = 5..7
208 */
209
210#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
211
212#define OMAP_UWIRE_BASE 0xfffb3000
213
214static struct resource uwire_resources[] = {
215 {
216 .start = OMAP_UWIRE_BASE,
217 .end = OMAP_UWIRE_BASE + 0x20,
218 .flags = IORESOURCE_MEM,
219 },
220};
221
222static struct platform_device omap_uwire_device = {
223 .name = "omap_uwire",
224 .id = -1,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100225 .num_resources = ARRAY_SIZE(uwire_resources),
226 .resource = uwire_resources,
227};
228
229static void omap_init_uwire(void)
230{
231 /* FIXME define and use a boot tag; not all boards will be hooking
232 * up devices to the microwire controller, and multi-board configs
233 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
234 */
235
236 /* board-specific code must configure chipselects (only a few
237 * are normally used) and SCLK/SDI/SDO (each has two choices).
238 */
239 (void) platform_device_register(&omap_uwire_device);
240}
241#else
242static inline void omap_init_uwire(void) {}
243#endif
244
Felipe Contreras90173882010-10-04 19:09:14 +0300245#if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE)
246
247static phys_addr_t omap_dsp_phys_mempool_base;
248
249void __init omap_dsp_reserve_sdram_memblock(void)
250{
251 phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE;
252 phys_addr_t paddr;
253
254 if (!size)
255 return;
256
Felipe Contreras89346f92010-10-19 10:37:24 +0300257 paddr = memblock_alloc(size, SZ_1M);
Felipe Contreras90173882010-10-04 19:09:14 +0300258 if (!paddr) {
259 pr_err("%s: failed to reserve %x bytes\n",
260 __func__, size);
261 return;
262 }
Felipe Contreras89346f92010-10-19 10:37:24 +0300263 memblock_free(paddr, size);
264 memblock_remove(paddr, size);
Felipe Contreras90173882010-10-04 19:09:14 +0300265
266 omap_dsp_phys_mempool_base = paddr;
267}
268
269phys_addr_t omap_dsp_get_mempool_base(void)
270{
271 return omap_dsp_phys_mempool_base;
272}
273EXPORT_SYMBOL(omap_dsp_get_mempool_base);
274#endif
275
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000276/*
277 * This gets called after board-specific INIT_MACHINE, and initializes most
278 * on-chip peripherals accessible on this board (except for few like USB):
279 *
280 * (a) Does any "standard config" pin muxing needed. Board-specific
281 * code will have muxed GPIO pins and done "nonstandard" setup;
282 * that code could live in the boot loader.
283 * (b) Populating board-specific platform_data with the data drivers
284 * rely on to handle wiring variations.
285 * (c) Creating platform devices as meaningful on this board and
286 * with this kernel configuration.
287 *
288 * Claiming GPIOs, and setting their direction and initial values, is the
289 * responsibility of the device drivers. So is responding to probe().
290 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300291 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000292 * kept out of drivers as much as possible. In particular, pin setup
293 * may be handled by the boot loader, and drivers should expect it will
294 * normally have been done by the time they're probed.
295 */
296static int __init omap_init_devices(void)
297{
298 /* please keep these calls, and their implementations above,
299 * in alphabetical order so they're easier to sort through.
300 */
Ladislav Michl3bfe8972009-12-11 16:16:36 -0800301 omap_init_rng();
Jorge Eduardo Candelariad6a2d9b2010-02-15 10:03:35 -0800302 omap_init_mcpdm();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100303 omap_init_uwire();
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000304 return 0;
305}
306arch_initcall(omap_init_devices);