• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/arm/plat-omap/
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
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/io.h>
17#include <linux/slab.h>
18
19#include <mach/hardware.h>
20#include <asm/mach-types.h>
21#include <asm/mach/map.h>
22
23#include <plat/tc.h>
24#include <plat/control.h>
25#include <plat/board.h>
26#include <plat/mmc.h>
27#include <mach/gpio.h>
28#include <plat/menelaus.h>
29#include <plat/mcbsp.h>
30#include <plat/omap44xx.h>
31
32/*-------------------------------------------------------------------------*/
33
34#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
43	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/*-------------------------------------------------------------------------*/
74
75#if defined(CONFIG_SND_OMAP_SOC_MCPDM) || 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",
86		.start		= OMAP44XX_IRQ_MCPDM,
87		.end		= OMAP44XX_IRQ_MCPDM,
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
109#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
110	defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
111
112#define OMAP_MMC_NR_RES		2
113
114/*
115 * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
116 */
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)
120{
121	struct platform_device *pdev;
122	struct resource res[OMAP_MMC_NR_RES];
123	int ret;
124
125	pdev = platform_device_alloc(name, id);
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;
145
146	/* return device handle to board setup code */
147	data->dev = &pdev->dev;
148	return 0;
149
150fail:
151	platform_device_put(pdev);
152	return ret;
153}
154
155#endif
156
157/*-------------------------------------------------------------------------*/
158
159#if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
160
161#ifdef CONFIG_ARCH_OMAP2
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
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,
214	.num_resources	= ARRAY_SIZE(uwire_resources),
215	.resource	= uwire_resources,
216};
217
218static void omap_init_uwire(void)
219{
220
221	/* board-specific code must configure chipselects (only a few
222	 * are normally used) and SCLK/SDI/SDO (each has two choices).
223	 */
224	(void) platform_device_register(&omap_uwire_device);
225}
226#else
227static inline void omap_init_uwire(void) {}
228#endif
229
230/*-------------------------------------------------------------------------*/
231
232#if	defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
233
234static struct resource wdt_resources[] = {
235	{
236		.flags		= IORESOURCE_MEM,
237	},
238};
239
240static struct platform_device omap_wdt_device = {
241	.name	   = "omap_wdt",
242	.id	     = -1,
243	.num_resources	= ARRAY_SIZE(wdt_resources),
244	.resource	= wdt_resources,
245};
246
247static void omap_init_wdt(void)
248{
249	if (cpu_is_omap16xx())
250		wdt_resources[0].start = 0xfffeb000;
251	else if (cpu_is_omap2420())
252		wdt_resources[0].start = 0x48022000; /* WDT2 */
253	else if (cpu_is_omap2430())
254		wdt_resources[0].start = 0x49016000; /* WDT2 */
255	else if (cpu_is_omap343x())
256		wdt_resources[0].start = 0x48314000; /* WDT2 */
257	else if (cpu_is_omap44xx())
258		wdt_resources[0].start = 0x4a314000;
259	else
260		return;
261
262	wdt_resources[0].end = wdt_resources[0].start + 0x4f;
263
264	(void) platform_device_register(&omap_wdt_device);
265}
266#else
267static inline void omap_init_wdt(void) {}
268#endif
269
270/*
271 * This gets called after board-specific INIT_MACHINE, and initializes most
272 * on-chip peripherals accessible on this board (except for few like USB):
273 *
274 *  (a) Does any "standard config" pin muxing needed.  Board-specific
275 *	code will have muxed GPIO pins and done "nonstandard" setup;
276 *	that code could live in the boot loader.
277 *  (b) Populating board-specific platform_data with the data drivers
278 *	rely on to handle wiring variations.
279 *  (c) Creating platform devices as meaningful on this board and
280 *	with this kernel configuration.
281 *
282 * Claiming GPIOs, and setting their direction and initial values, is the
283 * responsibility of the device drivers.  So is responding to probe().
284 *
285 * Board-specific knowlege like creating devices or pin setup is to be
286 * kept out of drivers as much as possible.  In particular, pin setup
287 * may be handled by the boot loader, and drivers should expect it will
288 * normally have been done by the time they're probed.
289 */
290static int __init omap_init_devices(void)
291{
292	/* please keep these calls, and their implementations above,
293	 * in alphabetical order so they're easier to sort through.
294	 */
295	omap_init_rng();
296	omap_init_mcpdm();
297	omap_init_uwire();
298	omap_init_wdt();
299	return 0;
300}
301arch_initcall(omap_init_devices);
302