staging:iio:adc:ad7606 move to info_mask_(shared_by_type/separate)
[linux/fpc-iii.git] / arch / arm / mach-omap1 / mcbsp.c
blobb0d4723c9a90718ccbef119dfdf95412b33c4109
1 /*
2 * linux/arch/arm/mach-omap1/mcbsp.c
4 * Copyright (C) 2008 Instituto Nokia de Tecnologia
5 * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Multichannel mode not supported.
13 #include <linux/ioport.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/io.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include <linux/omap-dma.h>
23 #include <mach/mux.h>
24 #include "soc.h"
25 #include <linux/platform_data/asoc-ti-mcbsp.h>
27 #include <mach/irqs.h>
29 #include "iomap.h"
30 #include "dma.h"
32 #define DPS_RSTCT2_PER_EN (1 << 0)
33 #define DSP_RSTCT2_WD_PER_EN (1 << 1)
35 static int dsp_use;
36 static struct clk *api_clk;
37 static struct clk *dsp_clk;
38 static struct platform_device **omap_mcbsp_devices;
40 static void omap1_mcbsp_request(unsigned int id)
43 * On 1510, 1610 and 1710, McBSP1 and McBSP3
44 * are DSP public peripherals.
46 if (id == 0 || id == 2) {
47 if (dsp_use++ == 0) {
48 api_clk = clk_get(NULL, "api_ck");
49 dsp_clk = clk_get(NULL, "dsp_ck");
50 if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
51 clk_enable(api_clk);
52 clk_enable(dsp_clk);
55 * DSP external peripheral reset
56 * FIXME: This should be moved to dsp code
58 __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
59 DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
65 static void omap1_mcbsp_free(unsigned int id)
67 if (id == 0 || id == 2) {
68 if (--dsp_use == 0) {
69 if (!IS_ERR(api_clk)) {
70 clk_disable(api_clk);
71 clk_put(api_clk);
73 if (!IS_ERR(dsp_clk)) {
74 clk_disable(dsp_clk);
75 clk_put(dsp_clk);
81 static struct omap_mcbsp_ops omap1_mcbsp_ops = {
82 .request = omap1_mcbsp_request,
83 .free = omap1_mcbsp_free,
86 #define OMAP7XX_MCBSP1_BASE 0xfffb1000
87 #define OMAP7XX_MCBSP2_BASE 0xfffb1800
89 #define OMAP1510_MCBSP1_BASE 0xe1011800
90 #define OMAP1510_MCBSP2_BASE 0xfffb1000
91 #define OMAP1510_MCBSP3_BASE 0xe1017000
93 #define OMAP1610_MCBSP1_BASE 0xe1011800
94 #define OMAP1610_MCBSP2_BASE 0xfffb1000
95 #define OMAP1610_MCBSP3_BASE 0xe1017000
97 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
98 struct resource omap7xx_mcbsp_res[][6] = {
101 .start = OMAP7XX_MCBSP1_BASE,
102 .end = OMAP7XX_MCBSP1_BASE + SZ_256,
103 .flags = IORESOURCE_MEM,
106 .name = "rx",
107 .start = INT_7XX_McBSP1RX,
108 .flags = IORESOURCE_IRQ,
111 .name = "tx",
112 .start = INT_7XX_McBSP1TX,
113 .flags = IORESOURCE_IRQ,
116 .name = "rx",
117 .start = OMAP_DMA_MCBSP1_RX,
118 .flags = IORESOURCE_DMA,
121 .name = "tx",
122 .start = OMAP_DMA_MCBSP1_TX,
123 .flags = IORESOURCE_DMA,
128 .start = OMAP7XX_MCBSP2_BASE,
129 .end = OMAP7XX_MCBSP2_BASE + SZ_256,
130 .flags = IORESOURCE_MEM,
133 .name = "rx",
134 .start = INT_7XX_McBSP2RX,
135 .flags = IORESOURCE_IRQ,
138 .name = "tx",
139 .start = INT_7XX_McBSP2TX,
140 .flags = IORESOURCE_IRQ,
143 .name = "rx",
144 .start = OMAP_DMA_MCBSP3_RX,
145 .flags = IORESOURCE_DMA,
148 .name = "tx",
149 .start = OMAP_DMA_MCBSP3_TX,
150 .flags = IORESOURCE_DMA,
155 #define omap7xx_mcbsp_res_0 omap7xx_mcbsp_res[0]
157 static struct omap_mcbsp_platform_data omap7xx_mcbsp_pdata[] = {
159 .ops = &omap1_mcbsp_ops,
162 .ops = &omap1_mcbsp_ops,
165 #define OMAP7XX_MCBSP_RES_SZ ARRAY_SIZE(omap7xx_mcbsp_res[1])
166 #define OMAP7XX_MCBSP_COUNT ARRAY_SIZE(omap7xx_mcbsp_res)
167 #else
168 #define omap7xx_mcbsp_res_0 NULL
169 #define omap7xx_mcbsp_pdata NULL
170 #define OMAP7XX_MCBSP_RES_SZ 0
171 #define OMAP7XX_MCBSP_COUNT 0
172 #endif
174 #ifdef CONFIG_ARCH_OMAP15XX
175 struct resource omap15xx_mcbsp_res[][6] = {
178 .start = OMAP1510_MCBSP1_BASE,
179 .end = OMAP1510_MCBSP1_BASE + SZ_256,
180 .flags = IORESOURCE_MEM,
183 .name = "rx",
184 .start = INT_McBSP1RX,
185 .flags = IORESOURCE_IRQ,
188 .name = "tx",
189 .start = INT_McBSP1TX,
190 .flags = IORESOURCE_IRQ,
193 .name = "rx",
194 .start = OMAP_DMA_MCBSP1_RX,
195 .flags = IORESOURCE_DMA,
198 .name = "tx",
199 .start = OMAP_DMA_MCBSP1_TX,
200 .flags = IORESOURCE_DMA,
205 .start = OMAP1510_MCBSP2_BASE,
206 .end = OMAP1510_MCBSP2_BASE + SZ_256,
207 .flags = IORESOURCE_MEM,
210 .name = "rx",
211 .start = INT_1510_SPI_RX,
212 .flags = IORESOURCE_IRQ,
215 .name = "tx",
216 .start = INT_1510_SPI_TX,
217 .flags = IORESOURCE_IRQ,
220 .name = "rx",
221 .start = OMAP_DMA_MCBSP2_RX,
222 .flags = IORESOURCE_DMA,
225 .name = "tx",
226 .start = OMAP_DMA_MCBSP2_TX,
227 .flags = IORESOURCE_DMA,
232 .start = OMAP1510_MCBSP3_BASE,
233 .end = OMAP1510_MCBSP3_BASE + SZ_256,
234 .flags = IORESOURCE_MEM,
237 .name = "rx",
238 .start = INT_McBSP3RX,
239 .flags = IORESOURCE_IRQ,
242 .name = "tx",
243 .start = INT_McBSP3TX,
244 .flags = IORESOURCE_IRQ,
247 .name = "rx",
248 .start = OMAP_DMA_MCBSP3_RX,
249 .flags = IORESOURCE_DMA,
252 .name = "tx",
253 .start = OMAP_DMA_MCBSP3_TX,
254 .flags = IORESOURCE_DMA,
259 #define omap15xx_mcbsp_res_0 omap15xx_mcbsp_res[0]
261 static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
263 .ops = &omap1_mcbsp_ops,
266 .ops = &omap1_mcbsp_ops,
269 .ops = &omap1_mcbsp_ops,
272 #define OMAP15XX_MCBSP_RES_SZ ARRAY_SIZE(omap15xx_mcbsp_res[1])
273 #define OMAP15XX_MCBSP_COUNT ARRAY_SIZE(omap15xx_mcbsp_res)
274 #else
275 #define omap15xx_mcbsp_res_0 NULL
276 #define omap15xx_mcbsp_pdata NULL
277 #define OMAP15XX_MCBSP_RES_SZ 0
278 #define OMAP15XX_MCBSP_COUNT 0
279 #endif
281 #ifdef CONFIG_ARCH_OMAP16XX
282 struct resource omap16xx_mcbsp_res[][6] = {
285 .start = OMAP1610_MCBSP1_BASE,
286 .end = OMAP1610_MCBSP1_BASE + SZ_256,
287 .flags = IORESOURCE_MEM,
290 .name = "rx",
291 .start = INT_McBSP1RX,
292 .flags = IORESOURCE_IRQ,
295 .name = "tx",
296 .start = INT_McBSP1TX,
297 .flags = IORESOURCE_IRQ,
300 .name = "rx",
301 .start = OMAP_DMA_MCBSP1_RX,
302 .flags = IORESOURCE_DMA,
305 .name = "tx",
306 .start = OMAP_DMA_MCBSP1_TX,
307 .flags = IORESOURCE_DMA,
312 .start = OMAP1610_MCBSP2_BASE,
313 .end = OMAP1610_MCBSP2_BASE + SZ_256,
314 .flags = IORESOURCE_MEM,
317 .name = "rx",
318 .start = INT_1610_McBSP2_RX,
319 .flags = IORESOURCE_IRQ,
322 .name = "tx",
323 .start = INT_1610_McBSP2_TX,
324 .flags = IORESOURCE_IRQ,
327 .name = "rx",
328 .start = OMAP_DMA_MCBSP2_RX,
329 .flags = IORESOURCE_DMA,
332 .name = "tx",
333 .start = OMAP_DMA_MCBSP2_TX,
334 .flags = IORESOURCE_DMA,
339 .start = OMAP1610_MCBSP3_BASE,
340 .end = OMAP1610_MCBSP3_BASE + SZ_256,
341 .flags = IORESOURCE_MEM,
344 .name = "rx",
345 .start = INT_McBSP3RX,
346 .flags = IORESOURCE_IRQ,
349 .name = "tx",
350 .start = INT_McBSP3TX,
351 .flags = IORESOURCE_IRQ,
354 .name = "rx",
355 .start = OMAP_DMA_MCBSP3_RX,
356 .flags = IORESOURCE_DMA,
359 .name = "tx",
360 .start = OMAP_DMA_MCBSP3_TX,
361 .flags = IORESOURCE_DMA,
366 #define omap16xx_mcbsp_res_0 omap16xx_mcbsp_res[0]
368 static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
370 .ops = &omap1_mcbsp_ops,
373 .ops = &omap1_mcbsp_ops,
376 .ops = &omap1_mcbsp_ops,
379 #define OMAP16XX_MCBSP_RES_SZ ARRAY_SIZE(omap16xx_mcbsp_res[1])
380 #define OMAP16XX_MCBSP_COUNT ARRAY_SIZE(omap16xx_mcbsp_res)
381 #else
382 #define omap16xx_mcbsp_res_0 NULL
383 #define omap16xx_mcbsp_pdata NULL
384 #define OMAP16XX_MCBSP_RES_SZ 0
385 #define OMAP16XX_MCBSP_COUNT 0
386 #endif
388 static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
389 struct omap_mcbsp_platform_data *config, int size)
391 int i;
393 omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
394 GFP_KERNEL);
395 if (!omap_mcbsp_devices) {
396 printk(KERN_ERR "Could not register McBSP devices\n");
397 return;
400 for (i = 0; i < size; i++) {
401 struct platform_device *new_mcbsp;
402 int ret;
404 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
405 if (!new_mcbsp)
406 continue;
407 platform_device_add_resources(new_mcbsp, &res[i * res_count],
408 res_count);
409 config[i].reg_size = 2;
410 config[i].reg_step = 2;
411 new_mcbsp->dev.platform_data = &config[i];
412 ret = platform_device_add(new_mcbsp);
413 if (ret) {
414 platform_device_put(new_mcbsp);
415 continue;
417 omap_mcbsp_devices[i] = new_mcbsp;
421 static int __init omap1_mcbsp_init(void)
423 if (!cpu_class_is_omap1())
424 return -ENODEV;
426 if (cpu_is_omap7xx())
427 omap_mcbsp_register_board_cfg(omap7xx_mcbsp_res_0,
428 OMAP7XX_MCBSP_RES_SZ,
429 omap7xx_mcbsp_pdata,
430 OMAP7XX_MCBSP_COUNT);
432 if (cpu_is_omap15xx())
433 omap_mcbsp_register_board_cfg(omap15xx_mcbsp_res_0,
434 OMAP15XX_MCBSP_RES_SZ,
435 omap15xx_mcbsp_pdata,
436 OMAP15XX_MCBSP_COUNT);
438 if (cpu_is_omap16xx())
439 omap_mcbsp_register_board_cfg(omap16xx_mcbsp_res_0,
440 OMAP16XX_MCBSP_RES_SZ,
441 omap16xx_mcbsp_pdata,
442 OMAP16XX_MCBSP_COUNT);
444 return 0;
447 arch_initcall(omap1_mcbsp_init);