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