]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/arm/plat-omap/devices.c
OMAP: split plat-omap/common.c
[net-next-2.6.git] / arch / arm / plat-omap / devices.c
CommitLineData
1a8bfa1e
TL
1/*
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
1a8bfa1e
TL
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
fced80c7 16#include <linux/io.h>
5a0e3ad6 17#include <linux/slab.h>
1a8bfa1e 18
a09e64fb 19#include <mach/hardware.h>
1a8bfa1e
TL
20#include <asm/mach-types.h>
21#include <asm/mach/map.h>
22
ce491cf8 23#include <plat/tc.h>
ce491cf8
TL
24#include <plat/board.h>
25#include <plat/mmc.h>
a09e64fb 26#include <mach/gpio.h>
ce491cf8
TL
27#include <plat/menelaus.h>
28#include <plat/mcbsp.h>
d6a2d9b8 29#include <plat/omap44xx.h>
1a8bfa1e 30
9b6553cd 31/*-------------------------------------------------------------------------*/
9b6553cd 32
bc5d0c89
EV
33#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
34
35static struct platform_device **omap_mcbsp_devices;
36
37void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
38 int size)
39{
40 int i;
41
bc5d0c89
EV
42 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;
56 new_mcbsp->dev.platform_data = &config[i];
57 ret = platform_device_add(new_mcbsp);
58 if (ret) {
59 platform_device_put(new_mcbsp);
60 continue;
61 }
62 omap_mcbsp_devices[i] = new_mcbsp;
63 }
64}
65
66#else
67void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
68 int size)
69{ }
70#endif
71
1a8bfa1e
TL
72/*-------------------------------------------------------------------------*/
73
d6a2d9b8
JEC
74#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
75 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
76
77static struct resource mcpdm_resources[] = {
78 {
79 .name = "mcpdm_mem",
80 .start = OMAP44XX_MCPDM_BASE,
81 .end = OMAP44XX_MCPDM_BASE + SZ_4K,
82 .flags = IORESOURCE_MEM,
83 },
84 {
85 .name = "mcpdm_irq",
5772ca7d
SS
86 .start = OMAP44XX_IRQ_MCPDM,
87 .end = OMAP44XX_IRQ_MCPDM,
d6a2d9b8
JEC
88 .flags = IORESOURCE_IRQ,
89 },
90};
91
92static struct platform_device omap_mcpdm_device = {
93 .name = "omap-mcpdm",
94 .id = -1,
95 .num_resources = ARRAY_SIZE(mcpdm_resources),
96 .resource = mcpdm_resources,
97};
98
99static void omap_init_mcpdm(void)
100{
101 (void) platform_device_register(&omap_mcpdm_device);
102}
103#else
104static inline void omap_init_mcpdm(void) {}
105#endif
106
107/*-------------------------------------------------------------------------*/
108
d8874665 109#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
7736c09c 110 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
1a8bfa1e 111
d8874665 112#define OMAP_MMC_NR_RES 2
7736c09c 113
d8874665
TL
114/*
115 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
116 */
0dffb5c5
TL
117int __init omap_mmc_add(const char *name, int id, unsigned long base,
118 unsigned long size, unsigned int irq,
119 struct omap_mmc_platform_data *data)
7736c09c 120{
d8874665
TL
121 struct platform_device *pdev;
122 struct resource res[OMAP_MMC_NR_RES];
123 int ret;
124
0dffb5c5 125 pdev = platform_device_alloc(name, id);
d8874665
TL
126 if (!pdev)
127 return -ENOMEM;
128
129 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
130 res[0].start = base;
131 res[0].end = base + size - 1;
132 res[0].flags = IORESOURCE_MEM;
133 res[1].start = res[1].end = irq;
134 res[1].flags = IORESOURCE_IRQ;
135
136 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
137 if (ret == 0)
138 ret = platform_device_add_data(pdev, data, sizeof(*data));
139 if (ret)
140 goto fail;
141
142 ret = platform_device_add(pdev);
143 if (ret)
144 goto fail;
01971f65
DB
145
146 /* return device handle to board setup code */
147 data->dev = &pdev->dev;
d8874665 148 return 0;
7736c09c 149
d8874665
TL
150fail:
151 platform_device_put(pdev);
152 return ret;
7736c09c
RK
153}
154
1a8bfa1e
TL
155#endif
156
9b6553cd
TL
157/*-------------------------------------------------------------------------*/
158
3bfe8971
LM
159#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
160
088ef950 161#ifdef CONFIG_ARCH_OMAP2
3bfe8971
LM
162#define OMAP_RNG_BASE 0x480A0000
163#else
164#define OMAP_RNG_BASE 0xfffe5000
165#endif
166
167static struct resource rng_resources[] = {
168 {
169 .start = OMAP_RNG_BASE,
170 .end = OMAP_RNG_BASE + 0x4f,
171 .flags = IORESOURCE_MEM,
172 },
173};
174
175static struct platform_device omap_rng_device = {
176 .name = "omap_rng",
177 .id = -1,
178 .num_resources = ARRAY_SIZE(rng_resources),
179 .resource = rng_resources,
180};
181
182static void omap_init_rng(void)
183{
184 (void) platform_device_register(&omap_rng_device);
185}
186#else
187static inline void omap_init_rng(void) {}
188#endif
189
190/*-------------------------------------------------------------------------*/
191
9b6553cd
TL
192/* Numbering for the SPI-capable controllers when used for SPI:
193 * spi = 1
194 * uwire = 2
195 * mmc1..2 = 3..4
196 * mcbsp1..3 = 5..7
197 */
198
199#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
200
201#define OMAP_UWIRE_BASE 0xfffb3000
202
203static struct resource uwire_resources[] = {
204 {
205 .start = OMAP_UWIRE_BASE,
206 .end = OMAP_UWIRE_BASE + 0x20,
207 .flags = IORESOURCE_MEM,
208 },
209};
210
211static struct platform_device omap_uwire_device = {
212 .name = "omap_uwire",
213 .id = -1,
9b6553cd
TL
214 .num_resources = ARRAY_SIZE(uwire_resources),
215 .resource = uwire_resources,
216};
217
218static void omap_init_uwire(void)
219{
220 /* FIXME define and use a boot tag; not all boards will be hooking
221 * up devices to the microwire controller, and multi-board configs
222 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
223 */
224
225 /* board-specific code must configure chipselects (only a few
226 * are normally used) and SCLK/SDI/SDO (each has two choices).
227 */
228 (void) platform_device_register(&omap_uwire_device);
229}
230#else
231static inline void omap_init_uwire(void) {}
232#endif
233
1a8bfa1e
TL
234/*
235 * This gets called after board-specific INIT_MACHINE, and initializes most
236 * on-chip peripherals accessible on this board (except for few like USB):
237 *
238 * (a) Does any "standard config" pin muxing needed. Board-specific
239 * code will have muxed GPIO pins and done "nonstandard" setup;
240 * that code could live in the boot loader.
241 * (b) Populating board-specific platform_data with the data drivers
242 * rely on to handle wiring variations.
243 * (c) Creating platform devices as meaningful on this board and
244 * with this kernel configuration.
245 *
246 * Claiming GPIOs, and setting their direction and initial values, is the
247 * responsibility of the device drivers. So is responding to probe().
248 *
249 * Board-specific knowlege like creating devices or pin setup is to be
250 * kept out of drivers as much as possible. In particular, pin setup
251 * may be handled by the boot loader, and drivers should expect it will
252 * normally have been done by the time they're probed.
253 */
254static int __init omap_init_devices(void)
255{
256 /* please keep these calls, and their implementations above,
257 * in alphabetical order so they're easier to sort through.
258 */
3bfe8971 259 omap_init_rng();
d6a2d9b8 260 omap_init_mcpdm();
9b6553cd 261 omap_init_uwire();
1a8bfa1e
TL
262 return 0;
263}
264arch_initcall(omap_init_devices);