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