Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[pandora-kernel.git] / arch / arm / plat-omap / devices.c
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/board.h>
25 #include <plat/mmc.h>
26 #include <mach/gpio.h>
27 #include <plat/menelaus.h>
28 #include <plat/mcbsp.h>
29 #include <plat/omap44xx.h>
30
31 /*-------------------------------------------------------------------------*/
32
33 #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
34
35 static struct platform_device **omap_mcbsp_devices;
36
37 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
38                                         int size)
39 {
40         int i;
41
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
67 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
68                                         int size)
69 {  }
70 #endif
71
72 /*-------------------------------------------------------------------------*/
73
74 #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \
75                 defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE)
76
77 static 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
92 static 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
99 static void omap_init_mcpdm(void)
100 {
101         (void) platform_device_register(&omap_mcpdm_device);
102 }
103 #else
104 static 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  */
117 int __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
150 fail:
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
167 static struct resource rng_resources[] = {
168         {
169                 .start          = OMAP_RNG_BASE,
170                 .end            = OMAP_RNG_BASE + 0x4f,
171                 .flags          = IORESOURCE_MEM,
172         },
173 };
174
175 static 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
182 static void omap_init_rng(void)
183 {
184         (void) platform_device_register(&omap_rng_device);
185 }
186 #else
187 static 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
203 static struct resource uwire_resources[] = {
204         {
205                 .start          = OMAP_UWIRE_BASE,
206                 .end            = OMAP_UWIRE_BASE + 0x20,
207                 .flags          = IORESOURCE_MEM,
208         },
209 };
210
211 static 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
218 static 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
231 static inline void omap_init_uwire(void) {}
232 #endif
233
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  */
254 static 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          */
259         omap_init_rng();
260         omap_init_mcpdm();
261         omap_init_uwire();
262         return 0;
263 }
264 arch_initcall(omap_init_devices);