1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-omap1/mcbsp.c
5 * Copyright (C) 2008 Instituto Nokia de Tecnologia
8 * Multichannel mode not supported.
10 #include <linux/ioport.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/clk.h>
14 #include <linux/err.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/omap-dma.h>
19 #include <linux/soc/ti/omap1-io.h>
20 #include <linux/platform_data/asoc-ti-mcbsp.h>
27 #define DPS_RSTCT2_PER_EN (1 << 0)
28 #define DSP_RSTCT2_WD_PER_EN (1 << 1)
31 static struct clk *api_clk;
32 static struct clk *dsp_clk;
33 static struct platform_device **omap_mcbsp_devices;
35 static void omap1_mcbsp_request(unsigned int id)
38 * On 1510, 1610 and 1710, McBSP1 and McBSP3
39 * are DSP public peripherals.
41 if (id == 0 || id == 2) {
43 api_clk = clk_get(NULL, "api_ck");
44 dsp_clk = clk_get(NULL, "dsp_ck");
45 if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
46 clk_prepare_enable(api_clk);
47 clk_prepare_enable(dsp_clk);
50 * DSP external peripheral reset
51 * FIXME: This should be moved to dsp code
53 __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
54 DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
60 static void omap1_mcbsp_free(unsigned int id)
62 if (id == 0 || id == 2) {
64 if (!IS_ERR(api_clk)) {
65 clk_disable_unprepare(api_clk);
68 if (!IS_ERR(dsp_clk)) {
69 clk_disable_unprepare(dsp_clk);
76 static struct omap_mcbsp_ops omap1_mcbsp_ops = {
77 .request = omap1_mcbsp_request,
78 .free = omap1_mcbsp_free,
81 #define OMAP7XX_MCBSP1_BASE 0xfffb1000
82 #define OMAP7XX_MCBSP2_BASE 0xfffb1800
84 #define OMAP1510_MCBSP1_BASE 0xe1011800
85 #define OMAP1510_MCBSP2_BASE 0xfffb1000
86 #define OMAP1510_MCBSP3_BASE 0xe1017000
88 #define OMAP1610_MCBSP1_BASE 0xe1011800
89 #define OMAP1610_MCBSP2_BASE 0xfffb1000
90 #define OMAP1610_MCBSP3_BASE 0xe1017000
92 struct resource omap15xx_mcbsp_res[][6] = {
95 .start = OMAP1510_MCBSP1_BASE,
96 .end = OMAP1510_MCBSP1_BASE + SZ_256,
97 .flags = IORESOURCE_MEM,
101 .start = INT_McBSP1RX,
102 .flags = IORESOURCE_IRQ,
106 .start = INT_McBSP1TX,
107 .flags = IORESOURCE_IRQ,
112 .flags = IORESOURCE_DMA,
117 .flags = IORESOURCE_DMA,
122 .start = OMAP1510_MCBSP2_BASE,
123 .end = OMAP1510_MCBSP2_BASE + SZ_256,
124 .flags = IORESOURCE_MEM,
128 .start = INT_1510_SPI_RX,
129 .flags = IORESOURCE_IRQ,
133 .start = INT_1510_SPI_TX,
134 .flags = IORESOURCE_IRQ,
139 .flags = IORESOURCE_DMA,
144 .flags = IORESOURCE_DMA,
149 .start = OMAP1510_MCBSP3_BASE,
150 .end = OMAP1510_MCBSP3_BASE + SZ_256,
151 .flags = IORESOURCE_MEM,
155 .start = INT_McBSP3RX,
156 .flags = IORESOURCE_IRQ,
160 .start = INT_McBSP3TX,
161 .flags = IORESOURCE_IRQ,
166 .flags = IORESOURCE_DMA,
171 .flags = IORESOURCE_DMA,
176 #define omap15xx_mcbsp_res_0 omap15xx_mcbsp_res[0]
178 static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
180 .ops = &omap1_mcbsp_ops,
183 .ops = &omap1_mcbsp_ops,
186 .ops = &omap1_mcbsp_ops,
189 #define OMAP15XX_MCBSP_RES_SZ ARRAY_SIZE(omap15xx_mcbsp_res[1])
190 #define OMAP15XX_MCBSP_COUNT ARRAY_SIZE(omap15xx_mcbsp_res)
192 struct resource omap16xx_mcbsp_res[][6] = {
195 .start = OMAP1610_MCBSP1_BASE,
196 .end = OMAP1610_MCBSP1_BASE + SZ_256,
197 .flags = IORESOURCE_MEM,
201 .start = INT_McBSP1RX,
202 .flags = IORESOURCE_IRQ,
206 .start = INT_McBSP1TX,
207 .flags = IORESOURCE_IRQ,
212 .flags = IORESOURCE_DMA,
217 .flags = IORESOURCE_DMA,
222 .start = OMAP1610_MCBSP2_BASE,
223 .end = OMAP1610_MCBSP2_BASE + SZ_256,
224 .flags = IORESOURCE_MEM,
228 .start = INT_1610_McBSP2_RX,
229 .flags = IORESOURCE_IRQ,
233 .start = INT_1610_McBSP2_TX,
234 .flags = IORESOURCE_IRQ,
239 .flags = IORESOURCE_DMA,
244 .flags = IORESOURCE_DMA,
249 .start = OMAP1610_MCBSP3_BASE,
250 .end = OMAP1610_MCBSP3_BASE + SZ_256,
251 .flags = IORESOURCE_MEM,
255 .start = INT_McBSP3RX,
256 .flags = IORESOURCE_IRQ,
260 .start = INT_McBSP3TX,
261 .flags = IORESOURCE_IRQ,
266 .flags = IORESOURCE_DMA,
271 .flags = IORESOURCE_DMA,
276 #define omap16xx_mcbsp_res_0 omap16xx_mcbsp_res[0]
278 static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
280 .ops = &omap1_mcbsp_ops,
283 .ops = &omap1_mcbsp_ops,
286 .ops = &omap1_mcbsp_ops,
289 #define OMAP16XX_MCBSP_RES_SZ ARRAY_SIZE(omap16xx_mcbsp_res[1])
290 #define OMAP16XX_MCBSP_COUNT ARRAY_SIZE(omap16xx_mcbsp_res)
292 static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
293 struct omap_mcbsp_platform_data *config, int size)
297 omap_mcbsp_devices = kcalloc(size, sizeof(struct platform_device *),
299 if (!omap_mcbsp_devices) {
300 printk(KERN_ERR "Could not register McBSP devices\n");
304 for (i = 0; i < size; i++) {
305 struct platform_device *new_mcbsp;
308 new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
311 platform_device_add_resources(new_mcbsp, &res[i * res_count],
313 config[i].reg_size = 2;
314 config[i].reg_step = 2;
315 new_mcbsp->dev.platform_data = &config[i];
316 ret = platform_device_add(new_mcbsp);
318 platform_device_put(new_mcbsp);
321 omap_mcbsp_devices[i] = new_mcbsp;
325 static int __init omap1_mcbsp_init(void)
327 if (!cpu_class_is_omap1())
330 if (cpu_is_omap15xx())
331 omap_mcbsp_register_board_cfg(omap15xx_mcbsp_res_0,
332 OMAP15XX_MCBSP_RES_SZ,
333 omap15xx_mcbsp_pdata,
334 OMAP15XX_MCBSP_COUNT);
336 if (cpu_is_omap16xx())
337 omap_mcbsp_register_board_cfg(omap16xx_mcbsp_res_0,
338 OMAP16XX_MCBSP_RES_SZ,
339 omap16xx_mcbsp_pdata,
340 OMAP16XX_MCBSP_COUNT);
345 arch_initcall(omap1_mcbsp_init);