blob: f9c9df5b5ff1d7b6d6e4a24b3cb9da2c00d88f92 [file] [log] [blame]
Eduardo Valentin78673bc2008-07-03 12:24:40 +03001/*
2 * linux/arch/arm/mach-omap2/mcbsp.c
3 *
4 * Copyright (C) 2008 Instituto Nokia de Tecnologia
5 * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
6 *
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.
10 *
11 * Multichannel mode not supported.
12 */
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/clk.h>
16#include <linux/err.h>
17#include <linux/io.h>
18#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Eduardo Valentin78673bc2008-07-03 12:24:40 +030020
Tony Lindgrendd7667a2009-01-15 13:09:51 +020021#include <mach/irqs.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070022#include <plat/dma.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070023#include <plat/cpu.h>
24#include <plat/mcbsp.h>
Paul Walmsley4814ced2010-10-08 11:40:20 -060025
26#include "control.h"
27
Eduardo Valentin78673bc2008-07-03 12:24:40 +030028
Paul Walmsleycf4c87a2010-10-08 11:40:19 -060029/* McBSP internal signal muxing functions */
30
31void omap2_mcbsp1_mux_clkr_src(u8 mux)
32{
33 u32 v;
34
35 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
36 if (mux == CLKR_SRC_CLKR)
Jarkko Nikula425925d2010-10-08 11:40:20 -060037 v &= ~OMAP2_MCBSP1_CLKR_MASK;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -060038 else if (mux == CLKR_SRC_CLKX)
39 v |= OMAP2_MCBSP1_CLKR_MASK;
40 omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
41}
42EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src);
43
44void omap2_mcbsp1_mux_fsr_src(u8 mux)
45{
46 u32 v;
47
48 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
49 if (mux == FSR_SRC_FSR)
Jarkko Nikula425925d2010-10-08 11:40:20 -060050 v &= ~OMAP2_MCBSP1_FSR_MASK;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -060051 else if (mux == FSR_SRC_FSX)
52 v |= OMAP2_MCBSP1_FSR_MASK;
53 omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
54}
55EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src);
56
Paul Walmsleyd1358652010-10-08 11:40:19 -060057/* McBSP CLKS source switching function */
58
59int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id)
60{
61 struct omap_mcbsp *mcbsp;
62 struct clk *fck_src;
63 char *fck_src_name;
64 int r;
65
66 if (!omap_mcbsp_check_valid_id(id)) {
67 pr_err("%s: Invalid id (%d)\n", __func__, id + 1);
68 return -EINVAL;
69 }
70 mcbsp = id_to_mcbsp_ptr(id);
71
72 if (fck_src_id == MCBSP_CLKS_PAD_SRC)
73 fck_src_name = "pad_fck";
74 else if (fck_src_id == MCBSP_CLKS_PRCM_SRC)
75 fck_src_name = "prcm_fck";
76 else
77 return -EINVAL;
78
79 fck_src = clk_get(mcbsp->dev, fck_src_name);
80 if (IS_ERR_OR_NULL(fck_src)) {
81 pr_err("omap-mcbsp: %s: could not clk_get() %s\n", "clks",
82 fck_src_name);
83 return -EINVAL;
84 }
85
86 clk_disable(mcbsp->fclk);
87
88 r = clk_set_parent(mcbsp->fclk, fck_src);
89 if (IS_ERR_VALUE(r)) {
90 pr_err("omap-mcbsp: %s: could not clk_set_parent() to %s\n",
91 "clks", fck_src_name);
92 clk_put(fck_src);
93 return -EINVAL;
94 }
95
96 clk_enable(mcbsp->fclk);
97
98 clk_put(fck_src);
99
100 return 0;
101}
102EXPORT_SYMBOL(omap2_mcbsp_set_clks_src);
103
104
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600105/* Platform data */
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300106
Jarkko Nikula05228c32008-10-08 10:01:40 +0300107#ifdef CONFIG_ARCH_OMAP2420
108static struct omap_mcbsp_platform_data omap2420_mcbsp_pdata[] = {
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300109 {
Russell King65846902008-09-03 23:46:18 +0100110 .phys_base = OMAP24XX_MCBSP1_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300111 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
112 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
113 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
114 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300115 },
116 {
Russell King65846902008-09-03 23:46:18 +0100117 .phys_base = OMAP24XX_MCBSP2_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300118 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
119 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
120 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
121 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300122 },
123};
Jarkko Nikula05228c32008-10-08 10:01:40 +0300124#define OMAP2420_MCBSP_PDATA_SZ ARRAY_SIZE(omap2420_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800125#define OMAP2420_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300126#else
Jarkko Nikula05228c32008-10-08 10:01:40 +0300127#define omap2420_mcbsp_pdata NULL
128#define OMAP2420_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800129#define OMAP2420_MCBSP_REG_NUM 0
Jarkko Nikula05228c32008-10-08 10:01:40 +0300130#endif
131
132#ifdef CONFIG_ARCH_OMAP2430
133static struct omap_mcbsp_platform_data omap2430_mcbsp_pdata[] = {
134 {
135 .phys_base = OMAP24XX_MCBSP1_BASE,
136 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
137 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
138 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
139 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300140 },
141 {
142 .phys_base = OMAP24XX_MCBSP2_BASE,
143 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
144 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
145 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
146 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300147 },
148 {
149 .phys_base = OMAP2430_MCBSP3_BASE,
150 .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX,
151 .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX,
152 .rx_irq = INT_24XX_MCBSP3_IRQ_RX,
153 .tx_irq = INT_24XX_MCBSP3_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300154 },
155 {
156 .phys_base = OMAP2430_MCBSP4_BASE,
157 .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX,
158 .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX,
159 .rx_irq = INT_24XX_MCBSP4_IRQ_RX,
160 .tx_irq = INT_24XX_MCBSP4_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300161 },
162 {
163 .phys_base = OMAP2430_MCBSP5_BASE,
164 .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX,
165 .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX,
166 .rx_irq = INT_24XX_MCBSP5_IRQ_RX,
167 .tx_irq = INT_24XX_MCBSP5_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300168 },
169};
170#define OMAP2430_MCBSP_PDATA_SZ ARRAY_SIZE(omap2430_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800171#define OMAP2430_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Jarkko Nikula05228c32008-10-08 10:01:40 +0300172#else
173#define omap2430_mcbsp_pdata NULL
174#define OMAP2430_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800175#define OMAP2430_MCBSP_REG_NUM 0
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300176#endif
177
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800178#ifdef CONFIG_ARCH_OMAP3
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300179static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
180 {
Russell King65846902008-09-03 23:46:18 +0100181 .phys_base = OMAP34XX_MCBSP1_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300182 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
183 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
184 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
185 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300186 .buffer_size = 0x80, /* The FIFO has 128 locations */
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300187 },
188 {
Russell King65846902008-09-03 23:46:18 +0100189 .phys_base = OMAP34XX_MCBSP2_BASE,
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000190 .phys_base_st = OMAP34XX_MCBSP2_ST_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300191 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
192 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
193 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
194 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300195 .buffer_size = 0x500, /* The FIFO has 1024 + 256 locations */
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300196 },
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300197 {
198 .phys_base = OMAP34XX_MCBSP3_BASE,
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000199 .phys_base_st = OMAP34XX_MCBSP3_ST_BASE,
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300200 .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX,
201 .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX,
202 .rx_irq = INT_24XX_MCBSP3_IRQ_RX,
203 .tx_irq = INT_24XX_MCBSP3_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300204 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300205 },
206 {
207 .phys_base = OMAP34XX_MCBSP4_BASE,
208 .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX,
209 .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX,
210 .rx_irq = INT_24XX_MCBSP4_IRQ_RX,
211 .tx_irq = INT_24XX_MCBSP4_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300212 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300213 },
214 {
215 .phys_base = OMAP34XX_MCBSP5_BASE,
216 .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX,
217 .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX,
218 .rx_irq = INT_24XX_MCBSP5_IRQ_RX,
219 .tx_irq = INT_24XX_MCBSP5_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300220 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300221 },
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300222};
223#define OMAP34XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap34xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800224#define OMAP34XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300225#else
226#define omap34xx_mcbsp_pdata NULL
227#define OMAP34XX_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800228#define OMAP34XX_MCBSP_REG_NUM 0
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300229#endif
230
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530231static struct omap_mcbsp_platform_data omap44xx_mcbsp_pdata[] = {
232 {
233 .phys_base = OMAP44XX_MCBSP1_BASE,
234 .dma_rx_sync = OMAP44XX_DMA_MCBSP1_RX,
235 .dma_tx_sync = OMAP44XX_DMA_MCBSP1_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500236 .tx_irq = OMAP44XX_IRQ_MCBSP1,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530237 },
238 {
239 .phys_base = OMAP44XX_MCBSP2_BASE,
240 .dma_rx_sync = OMAP44XX_DMA_MCBSP2_RX,
241 .dma_tx_sync = OMAP44XX_DMA_MCBSP2_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500242 .tx_irq = OMAP44XX_IRQ_MCBSP2,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530243 },
244 {
245 .phys_base = OMAP44XX_MCBSP3_BASE,
246 .dma_rx_sync = OMAP44XX_DMA_MCBSP3_RX,
247 .dma_tx_sync = OMAP44XX_DMA_MCBSP3_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500248 .tx_irq = OMAP44XX_IRQ_MCBSP3,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530249 },
250 {
251 .phys_base = OMAP44XX_MCBSP4_BASE,
252 .dma_rx_sync = OMAP44XX_DMA_MCBSP4_RX,
253 .dma_tx_sync = OMAP44XX_DMA_MCBSP4_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500254 .tx_irq = OMAP44XX_IRQ_MCBSP4,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530255 },
256};
257#define OMAP44XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap44xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800258#define OMAP44XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530259
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300260static int __init omap2_mcbsp_init(void)
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300261{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800262 if (cpu_is_omap2420()) {
Jarkko Nikula05228c32008-10-08 10:01:40 +0300263 omap_mcbsp_count = OMAP2420_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800264 omap_mcbsp_cache_size = OMAP2420_MCBSP_REG_NUM * sizeof(u16);
265 } else if (cpu_is_omap2430()) {
Jarkko Nikula05228c32008-10-08 10:01:40 +0300266 omap_mcbsp_count = OMAP2430_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800267 omap_mcbsp_cache_size = OMAP2430_MCBSP_REG_NUM * sizeof(u32);
268 } else if (cpu_is_omap34xx()) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300269 omap_mcbsp_count = OMAP34XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800270 omap_mcbsp_cache_size = OMAP34XX_MCBSP_REG_NUM * sizeof(u32);
271 } else if (cpu_is_omap44xx()) {
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530272 omap_mcbsp_count = OMAP44XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800273 omap_mcbsp_cache_size = OMAP44XX_MCBSP_REG_NUM * sizeof(u32);
274 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300275
276 mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
277 GFP_KERNEL);
278 if (!mcbsp_ptr)
279 return -ENOMEM;
280
Jarkko Nikula05228c32008-10-08 10:01:40 +0300281 if (cpu_is_omap2420())
282 omap_mcbsp_register_board_cfg(omap2420_mcbsp_pdata,
283 OMAP2420_MCBSP_PDATA_SZ);
284 if (cpu_is_omap2430())
285 omap_mcbsp_register_board_cfg(omap2430_mcbsp_pdata,
286 OMAP2430_MCBSP_PDATA_SZ);
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300287 if (cpu_is_omap34xx())
288 omap_mcbsp_register_board_cfg(omap34xx_mcbsp_pdata,
289 OMAP34XX_MCBSP_PDATA_SZ);
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530290 if (cpu_is_omap44xx())
291 omap_mcbsp_register_board_cfg(omap44xx_mcbsp_pdata,
292 OMAP44XX_MCBSP_PDATA_SZ);
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300293
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300294 return omap_mcbsp_init();
295}
296arch_initcall(omap2_mcbsp_init);