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>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include <linux/omap-dma.h>
25 #include <linux/platform_data/asoc-ti-mcbsp.h>
27 #include <mach/irqs.h>
32 #define DPS_RSTCT2_PER_EN (1 << 0)
33 #define DSP_RSTCT2_WD_PER_EN (1 << 1)
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) {
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
)) {
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) {
69 if (!IS_ERR(api_clk
)) {
73 if (!IS_ERR(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
,
107 .start
= INT_7XX_McBSP1RX
,
108 .flags
= IORESOURCE_IRQ
,
112 .start
= INT_7XX_McBSP1TX
,
113 .flags
= IORESOURCE_IRQ
,
117 .start
= OMAP_DMA_MCBSP1_RX
,
118 .flags
= IORESOURCE_DMA
,
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
,
134 .start
= INT_7XX_McBSP2RX
,
135 .flags
= IORESOURCE_IRQ
,
139 .start
= INT_7XX_McBSP2TX
,
140 .flags
= IORESOURCE_IRQ
,
144 .start
= OMAP_DMA_MCBSP3_RX
,
145 .flags
= IORESOURCE_DMA
,
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)
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
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
,
184 .start
= INT_McBSP1RX
,
185 .flags
= IORESOURCE_IRQ
,
189 .start
= INT_McBSP1TX
,
190 .flags
= IORESOURCE_IRQ
,
194 .start
= OMAP_DMA_MCBSP1_RX
,
195 .flags
= IORESOURCE_DMA
,
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
,
211 .start
= INT_1510_SPI_RX
,
212 .flags
= IORESOURCE_IRQ
,
216 .start
= INT_1510_SPI_TX
,
217 .flags
= IORESOURCE_IRQ
,
221 .start
= OMAP_DMA_MCBSP2_RX
,
222 .flags
= IORESOURCE_DMA
,
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
,
238 .start
= INT_McBSP3RX
,
239 .flags
= IORESOURCE_IRQ
,
243 .start
= INT_McBSP3TX
,
244 .flags
= IORESOURCE_IRQ
,
248 .start
= OMAP_DMA_MCBSP3_RX
,
249 .flags
= IORESOURCE_DMA
,
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)
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
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
,
291 .start
= INT_McBSP1RX
,
292 .flags
= IORESOURCE_IRQ
,
296 .start
= INT_McBSP1TX
,
297 .flags
= IORESOURCE_IRQ
,
301 .start
= OMAP_DMA_MCBSP1_RX
,
302 .flags
= IORESOURCE_DMA
,
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
,
318 .start
= INT_1610_McBSP2_RX
,
319 .flags
= IORESOURCE_IRQ
,
323 .start
= INT_1610_McBSP2_TX
,
324 .flags
= IORESOURCE_IRQ
,
328 .start
= OMAP_DMA_MCBSP2_RX
,
329 .flags
= IORESOURCE_DMA
,
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
,
345 .start
= INT_McBSP3RX
,
346 .flags
= IORESOURCE_IRQ
,
350 .start
= INT_McBSP3TX
,
351 .flags
= IORESOURCE_IRQ
,
355 .start
= OMAP_DMA_MCBSP3_RX
,
356 .flags
= IORESOURCE_DMA
,
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)
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
388 static void omap_mcbsp_register_board_cfg(struct resource
*res
, int res_count
,
389 struct omap_mcbsp_platform_data
*config
, int size
)
393 omap_mcbsp_devices
= kzalloc(size
* sizeof(struct platform_device
*),
395 if (!omap_mcbsp_devices
) {
396 printk(KERN_ERR
"Could not register McBSP devices\n");
400 for (i
= 0; i
< size
; i
++) {
401 struct platform_device
*new_mcbsp
;
404 new_mcbsp
= platform_device_alloc("omap-mcbsp", i
+ 1);
407 platform_device_add_resources(new_mcbsp
, &res
[i
* 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
);
414 platform_device_put(new_mcbsp
);
417 omap_mcbsp_devices
[i
] = new_mcbsp
;
421 static int __init
omap1_mcbsp_init(void)
423 if (!cpu_class_is_omap1())
426 if (cpu_is_omap7xx())
427 omap_mcbsp_register_board_cfg(omap7xx_mcbsp_res_0
,
428 OMAP7XX_MCBSP_RES_SZ
,
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
);
447 arch_initcall(omap1_mcbsp_init
);