blob: b06d8f1620d76bbe099bb0803b82592c3c4be492 [file] [log] [blame]
Jarkko Nikula2e747962008-04-25 13:55:19 +02001/*
2 * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
Jarkko Nikulab08f7a62009-04-17 14:42:26 +03006 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
Jarkko Nikula2e747962008-04-25 13:55:19 +02008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/device.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/initval.h>
32#include <sound/soc.h>
33
Tony Lindgrence491cf2009-10-20 09:40:47 -070034#include <plat/control.h>
35#include <plat/dma.h>
36#include <plat/mcbsp.h>
Jarkko Nikula2e747962008-04-25 13:55:19 +020037#include "omap-mcbsp.h"
38#include "omap-pcm.h"
39
Jarkko Nikula0b604852008-11-12 17:05:51 +020040#define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000)
Jarkko Nikula2e747962008-04-25 13:55:19 +020041
Ilkka Koskinen83905c12010-02-22 12:21:12 +000042#define OMAP_MCBSP_SOC_SINGLE_S16_EXT(xname, xmin, xmax, \
43 xhandler_get, xhandler_put) \
44{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
45 .info = omap_mcbsp_st_info_volsw, \
46 .get = xhandler_get, .put = xhandler_put, \
47 .private_value = (unsigned long) &(struct soc_mixer_control) \
48 {.min = xmin, .max = xmax} }
49
Jarkko Nikula2e747962008-04-25 13:55:19 +020050struct omap_mcbsp_data {
51 unsigned int bus_id;
52 struct omap_mcbsp_reg_cfg regs;
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +030053 unsigned int fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +020054 /*
55 * Flags indicating is the bus already activated and configured by
56 * another substream
57 */
58 int active;
59 int configured;
Graeme Gregory5f63ef92009-11-09 19:02:15 +000060 unsigned int in_freq;
61 int clk_div;
Peter Ujfalusi3f024032010-06-03 07:39:35 +030062 int wlen;
Jarkko Nikula2e747962008-04-25 13:55:19 +020063};
64
65#define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id)
66
67static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
68
69/*
70 * Stream DMA parameters. DMA request line and port address are set runtime
71 * since they are different between OMAP1 and later OMAPs
72 */
Jarkko Nikula2e897132008-10-09 15:57:21 +030073static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2];
Jarkko Nikula2e747962008-04-25 13:55:19 +020074
75#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
76static const int omap1_dma_reqs[][2] = {
77 { OMAP_DMA_MCBSP1_TX, OMAP_DMA_MCBSP1_RX },
78 { OMAP_DMA_MCBSP2_TX, OMAP_DMA_MCBSP2_RX },
79 { OMAP_DMA_MCBSP3_TX, OMAP_DMA_MCBSP3_RX },
80};
81static const unsigned long omap1_mcbsp_port[][2] = {
82 { OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
83 OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
84 { OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
85 OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
86 { OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DXR1,
87 OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DRR1 },
88};
89#else
90static const int omap1_dma_reqs[][2] = {};
91static const unsigned long omap1_mcbsp_port[][2] = {};
92#endif
Jarkko Nikula406e2c42008-10-09 15:57:20 +030093
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -080094#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +030095static const int omap24xx_dma_reqs[][2] = {
Jarkko Nikula2e747962008-04-25 13:55:19 +020096 { OMAP24XX_DMA_MCBSP1_TX, OMAP24XX_DMA_MCBSP1_RX },
97 { OMAP24XX_DMA_MCBSP2_TX, OMAP24XX_DMA_MCBSP2_RX },
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -080098#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +030099 { OMAP24XX_DMA_MCBSP3_TX, OMAP24XX_DMA_MCBSP3_RX },
100 { OMAP24XX_DMA_MCBSP4_TX, OMAP24XX_DMA_MCBSP4_RX },
101 { OMAP24XX_DMA_MCBSP5_TX, OMAP24XX_DMA_MCBSP5_RX },
102#endif
Jarkko Nikula2e747962008-04-25 13:55:19 +0200103};
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300104#else
105static const int omap24xx_dma_reqs[][2] = {};
106#endif
107
108#if defined(CONFIG_ARCH_OMAP2420)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200109static const unsigned long omap2420_mcbsp_port[][2] = {
110 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
111 OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
112 { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
113 OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
114};
115#else
Jarkko Nikula2e747962008-04-25 13:55:19 +0200116static const unsigned long omap2420_mcbsp_port[][2] = {};
117#endif
118
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300119#if defined(CONFIG_ARCH_OMAP2430)
120static const unsigned long omap2430_mcbsp_port[][2] = {
121 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
122 OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
123 { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
124 OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
125 { OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
126 OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
127 { OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
128 OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
129 { OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
130 OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
131};
132#else
133static const unsigned long omap2430_mcbsp_port[][2] = {};
134#endif
135
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800136#if defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300137static const unsigned long omap34xx_mcbsp_port[][2] = {
138 { OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
139 OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
140 { OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
141 OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
142 { OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
143 OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
144 { OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
145 OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
146 { OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
147 OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
148};
149#else
150static const unsigned long omap34xx_mcbsp_port[][2] = {};
151#endif
152
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300153static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream)
154{
155 struct snd_soc_pcm_runtime *rtd = substream->private_data;
156 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
157 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300158 int dma_op_mode = omap_mcbsp_get_dma_op_mode(mcbsp_data->bus_id);
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300159 int words;
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300160
161 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
162 if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300163 /* The FIFO size depends on the McBSP word configuration */
164 words = snd_pcm_lib_period_bytes(substream) /
165 (mcbsp_data->wlen / 8);
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300166 else
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300167 words = 1;
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300168
169 /* Configure McBSP internal buffer usage */
170 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300171 omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, words);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300172 else
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300173 omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, words);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300174}
175
Mark Browndee89c42008-11-18 22:11:38 +0000176static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
177 struct snd_soc_dai *dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200178{
179 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood8687eb82008-07-07 16:08:07 +0100180 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200181 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300182 int bus_id = mcbsp_data->bus_id;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200183 int err = 0;
184
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300185 if (!cpu_dai->active)
186 err = omap_mcbsp_request(bus_id);
187
188 if (cpu_is_omap343x()) {
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300189 int dma_op_mode = omap_mcbsp_get_dma_op_mode(bus_id);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300190 int max_period;
191
Jarkko Nikula69849922009-03-27 15:32:01 +0200192 /*
193 * McBSP2 in OMAP3 has 1024 * 32-bit internal audio buffer.
194 * Set constraint for minimum buffer size to the same than FIFO
195 * size in order to avoid underruns in playback startup because
196 * HW is keeping the DMA request active until FIFO is filled.
197 */
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300198 if (bus_id == 1)
199 snd_pcm_hw_constraint_minmax(substream->runtime,
200 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
201 4096, UINT_MAX);
Jarkko Nikula69849922009-03-27 15:32:01 +0200202
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
204 max_period = omap_mcbsp_get_max_tx_threshold(bus_id);
205 else
206 max_period = omap_mcbsp_get_max_rx_threshold(bus_id);
207
208 max_period++;
209 max_period <<= 1;
210
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300211 if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
212 snd_pcm_hw_constraint_minmax(substream->runtime,
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300213 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
214 32, max_period);
215 }
Jarkko Nikula2e747962008-04-25 13:55:19 +0200216
217 return err;
218}
219
Mark Browndee89c42008-11-18 22:11:38 +0000220static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
221 struct snd_soc_dai *dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200222{
223 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood8687eb82008-07-07 16:08:07 +0100224 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200225 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
226
227 if (!cpu_dai->active) {
228 omap_mcbsp_free(mcbsp_data->bus_id);
229 mcbsp_data->configured = 0;
230 }
231}
232
Mark Browndee89c42008-11-18 22:11:38 +0000233static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
234 struct snd_soc_dai *dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200235{
236 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood8687eb82008-07-07 16:08:07 +0100237 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200238 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300239 int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200240
241 switch (cmd) {
242 case SNDRV_PCM_TRIGGER_START:
243 case SNDRV_PCM_TRIGGER_RESUME:
244 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300245 mcbsp_data->active++;
246 omap_mcbsp_start(mcbsp_data->bus_id, play, !play);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200247 break;
248
249 case SNDRV_PCM_TRIGGER_STOP:
250 case SNDRV_PCM_TRIGGER_SUSPEND:
251 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300252 omap_mcbsp_stop(mcbsp_data->bus_id, play, !play);
253 mcbsp_data->active--;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200254 break;
255 default:
256 err = -EINVAL;
257 }
258
259 return err;
260}
261
Peter Ujfalusi75581d22010-03-03 15:08:09 +0200262static snd_pcm_sframes_t omap_mcbsp_dai_delay(
263 struct snd_pcm_substream *substream,
264 struct snd_soc_dai *dai)
265{
266 struct snd_soc_pcm_runtime *rtd = substream->private_data;
267 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
268 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
269 u16 fifo_use;
270 snd_pcm_sframes_t delay;
271
272 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
273 fifo_use = omap_mcbsp_get_tx_delay(mcbsp_data->bus_id);
274 else
275 fifo_use = omap_mcbsp_get_rx_delay(mcbsp_data->bus_id);
276
277 /*
278 * Divide the used locations with the channel count to get the
279 * FIFO usage in samples (don't care about partial samples in the
280 * buffer).
281 */
282 delay = fifo_use / substream->runtime->channels;
283
284 return delay;
285}
286
Jarkko Nikula2e747962008-04-25 13:55:19 +0200287static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000288 struct snd_pcm_hw_params *params,
289 struct snd_soc_dai *dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200290{
291 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood8687eb82008-07-07 16:08:07 +0100292 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200293 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
294 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
295 int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300296 int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200297 unsigned long port;
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000298 unsigned int format, div, framesize, master;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200299
300 if (cpu_class_is_omap1()) {
301 dma = omap1_dma_reqs[bus_id][substream->stream];
302 port = omap1_mcbsp_port[bus_id][substream->stream];
303 } else if (cpu_is_omap2420()) {
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300304 dma = omap24xx_dma_reqs[bus_id][substream->stream];
Jarkko Nikula2e747962008-04-25 13:55:19 +0200305 port = omap2420_mcbsp_port[bus_id][substream->stream];
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300306 } else if (cpu_is_omap2430()) {
307 dma = omap24xx_dma_reqs[bus_id][substream->stream];
308 port = omap2430_mcbsp_port[bus_id][substream->stream];
309 } else if (cpu_is_omap343x()) {
310 dma = omap24xx_dma_reqs[bus_id][substream->stream];
311 port = omap34xx_mcbsp_port[bus_id][substream->stream];
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300312 omap_mcbsp_dai_dma_params[id][substream->stream].set_threshold =
313 omap_mcbsp_set_threshold;
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300314 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
315 if (omap_mcbsp_get_dma_op_mode(bus_id) ==
316 MCBSP_DMA_MODE_THRESHOLD)
317 sync_mode = OMAP_DMA_SYNC_FRAME;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200318 } else {
Jarkko Nikula2e747962008-04-25 13:55:19 +0200319 return -ENODEV;
320 }
Jarkko Nikula2e897132008-10-09 15:57:21 +0300321 omap_mcbsp_dai_dma_params[id][substream->stream].name =
322 substream->stream ? "Audio Capture" : "Audio Playback";
Jarkko Nikula2e747962008-04-25 13:55:19 +0200323 omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
324 omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300325 omap_mcbsp_dai_dma_params[id][substream->stream].sync_mode = sync_mode;
Sergey Lapind98508a2010-05-13 19:48:16 +0400326 switch (params_format(params)) {
327 case SNDRV_PCM_FORMAT_S16_LE:
328 omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
329 OMAP_DMA_DATA_TYPE_S16;
330 break;
331 case SNDRV_PCM_FORMAT_S32_LE:
332 omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
333 OMAP_DMA_DATA_TYPE_S32;
334 break;
335 default:
336 return -EINVAL;
337 }
Daniel Mackfd23b7d2010-03-19 14:52:55 +0000338
339 snd_soc_dai_set_dma_data(cpu_dai, substream,
340 &omap_mcbsp_dai_dma_params[id][substream->stream]);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200341
342 if (mcbsp_data->configured) {
343 /* McBSP already configured by another stream */
344 return 0;
345 }
346
Peter Ujfalusic29b2062009-04-15 15:38:55 +0300347 format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
348 wpf = channels = params_channels(params);
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200349 if (channels == 2 && (format == SND_SOC_DAIFMT_I2S ||
350 format == SND_SOC_DAIFMT_LEFT_J)) {
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000351 /* Use dual-phase frames */
352 regs->rcr2 |= RPHASE;
353 regs->xcr2 |= XPHASE;
354 /* Set 1 word per (McBSP) frame for phase1 and phase2 */
355 wpf--;
356 regs->rcr2 |= RFRLEN2(wpf - 1);
357 regs->xcr2 |= XFRLEN2(wpf - 1);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200358 }
359
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000360 regs->rcr1 |= RFRLEN1(wpf - 1);
361 regs->xcr1 |= XFRLEN1(wpf - 1);
362
Jarkko Nikula2e747962008-04-25 13:55:19 +0200363 switch (params_format(params)) {
364 case SNDRV_PCM_FORMAT_S16_LE:
365 /* Set word lengths */
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300366 wlen = 16;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200367 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
368 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
369 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
370 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200371 break;
Sergey Lapind98508a2010-05-13 19:48:16 +0400372 case SNDRV_PCM_FORMAT_S32_LE:
373 /* Set word lengths */
374 wlen = 32;
375 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_32);
376 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_32);
377 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_32);
378 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_32);
379 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200380 default:
381 /* Unsupported PCM format */
382 return -EINVAL;
383 }
384
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000385 /* In McBSP master modes, FRAME (i.e. sample rate) is generated
386 * by _counting_ BCLKs. Calculate frame size in BCLKs */
387 master = mcbsp_data->fmt & SND_SOC_DAIFMT_MASTER_MASK;
388 if (master == SND_SOC_DAIFMT_CBS_CFS) {
389 div = mcbsp_data->clk_div ? mcbsp_data->clk_div : 1;
390 framesize = (mcbsp_data->in_freq / div) / params_rate(params);
391
392 if (framesize < wlen * channels) {
393 printk(KERN_ERR "%s: not enough bandwidth for desired rate and "
394 "channels\n", __func__);
395 return -EINVAL;
396 }
397 } else
398 framesize = wlen * channels;
399
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300400 /* Set FS period and length in terms of bit clock periods */
Peter Ujfalusic29b2062009-04-15 15:38:55 +0300401 switch (format) {
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300402 case SND_SOC_DAIFMT_I2S:
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200403 case SND_SOC_DAIFMT_LEFT_J:
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000404 regs->srgr2 |= FPER(framesize - 1);
405 regs->srgr1 |= FWID((framesize >> 1) - 1);
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300406 break;
Peter Ujfalusi3ba191c2009-04-15 15:38:56 +0300407 case SND_SOC_DAIFMT_DSP_A:
Jarkko Nikulabd258672008-12-22 10:21:36 +0200408 case SND_SOC_DAIFMT_DSP_B:
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000409 regs->srgr2 |= FPER(framesize - 1);
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300410 regs->srgr1 |= FWID(0);
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300411 break;
412 }
413
Jarkko Nikula2e747962008-04-25 13:55:19 +0200414 omap_mcbsp_config(bus_id, &mcbsp_data->regs);
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300415 mcbsp_data->wlen = wlen;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200416 mcbsp_data->configured = 1;
417
418 return 0;
419}
420
421/*
422 * This must be called before _set_clkdiv and _set_sysclk since McBSP register
423 * cache is initialized here
424 */
Liam Girdwood8687eb82008-07-07 16:08:07 +0100425static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200426 unsigned int fmt)
427{
428 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
429 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300430 unsigned int temp_fmt = fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200431
432 if (mcbsp_data->configured)
433 return 0;
434
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300435 mcbsp_data->fmt = fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200436 memset(regs, 0, sizeof(*regs));
437 /* Generic McBSP register settings */
438 regs->spcr2 |= XINTM(3) | FREE;
439 regs->spcr1 |= RINTM(3);
Eero Nurkkalac721bbd2009-08-20 16:18:23 +0300440 /* RFIG and XFIG are not defined in 34xx */
441 if (!cpu_is_omap34xx()) {
442 regs->rcr2 |= RFIG;
443 regs->xcr2 |= XFIG;
444 }
Misael Lopez Cruzef390c02009-01-29 13:29:46 +0200445 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
Jarkko Nikula32080af2009-08-23 12:24:26 +0300446 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE;
447 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE;
Misael Lopez Cruzef390c02009-01-29 13:29:46 +0200448 }
Jarkko Nikula2e747962008-04-25 13:55:19 +0200449
450 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
451 case SND_SOC_DAIFMT_I2S:
452 /* 1-bit data delay */
453 regs->rcr2 |= RDATDLY(1);
454 regs->xcr2 |= XDATDLY(1);
455 break;
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200456 case SND_SOC_DAIFMT_LEFT_J:
457 /* 0-bit data delay */
458 regs->rcr2 |= RDATDLY(0);
459 regs->xcr2 |= XDATDLY(0);
460 regs->spcr1 |= RJUST(2);
461 /* Invert FS polarity configuration */
462 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
463 break;
Peter Ujfalusi3ba191c2009-04-15 15:38:56 +0300464 case SND_SOC_DAIFMT_DSP_A:
465 /* 1-bit data delay */
466 regs->rcr2 |= RDATDLY(1);
467 regs->xcr2 |= XDATDLY(1);
468 /* Invert FS polarity configuration */
469 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
470 break;
Jarkko Nikulabd258672008-12-22 10:21:36 +0200471 case SND_SOC_DAIFMT_DSP_B:
Arun KS3336c5b2008-10-02 15:07:06 +0530472 /* 0-bit data delay */
473 regs->rcr2 |= RDATDLY(0);
474 regs->xcr2 |= XDATDLY(0);
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300475 /* Invert FS polarity configuration */
476 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
Arun KS3336c5b2008-10-02 15:07:06 +0530477 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200478 default:
479 /* Unsupported data format */
480 return -EINVAL;
481 }
482
483 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
484 case SND_SOC_DAIFMT_CBS_CFS:
485 /* McBSP master. Set FS and bit clocks as outputs */
486 regs->pcr0 |= FSXM | FSRM |
487 CLKXM | CLKRM;
488 /* Sample rate generator drives the FS */
489 regs->srgr2 |= FSGM;
490 break;
491 case SND_SOC_DAIFMT_CBM_CFM:
492 /* McBSP slave */
493 break;
494 default:
495 /* Unsupported master/slave configuration */
496 return -EINVAL;
497 }
498
499 /* Set bit clock (CLKX/CLKR) and FS polarities */
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300500 switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
Jarkko Nikula2e747962008-04-25 13:55:19 +0200501 case SND_SOC_DAIFMT_NB_NF:
502 /*
503 * Normal BCLK + FS.
504 * FS active low. TX data driven on falling edge of bit clock
505 * and RX data sampled on rising edge of bit clock.
506 */
507 regs->pcr0 |= FSXP | FSRP |
508 CLKXP | CLKRP;
509 break;
510 case SND_SOC_DAIFMT_NB_IF:
511 regs->pcr0 |= CLKXP | CLKRP;
512 break;
513 case SND_SOC_DAIFMT_IB_NF:
514 regs->pcr0 |= FSXP | FSRP;
515 break;
516 case SND_SOC_DAIFMT_IB_IF:
517 break;
518 default:
519 return -EINVAL;
520 }
521
522 return 0;
523}
524
Liam Girdwood8687eb82008-07-07 16:08:07 +0100525static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200526 int div_id, int div)
527{
528 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
529 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
530
531 if (div_id != OMAP_MCBSP_CLKGDV)
532 return -ENODEV;
533
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000534 mcbsp_data->clk_div = div;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200535 regs->srgr1 |= CLKGDV(div - 1);
536
537 return 0;
538}
539
540static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
541 int clk_id)
542{
543 int sel_bit;
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300544 u16 reg, reg_devconf1 = OMAP243X_CONTROL_DEVCONF1;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200545
546 if (cpu_class_is_omap1()) {
547 /* OMAP1's can use only external source clock */
548 if (unlikely(clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK))
549 return -EINVAL;
550 else
551 return 0;
552 }
553
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300554 if (cpu_is_omap2420() && mcbsp_data->bus_id > 1)
555 return -EINVAL;
556
557 if (cpu_is_omap343x())
558 reg_devconf1 = OMAP343X_CONTROL_DEVCONF1;
559
Jarkko Nikula2e747962008-04-25 13:55:19 +0200560 switch (mcbsp_data->bus_id) {
561 case 0:
562 reg = OMAP2_CONTROL_DEVCONF0;
563 sel_bit = 2;
564 break;
565 case 1:
566 reg = OMAP2_CONTROL_DEVCONF0;
567 sel_bit = 6;
568 break;
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300569 case 2:
570 reg = reg_devconf1;
571 sel_bit = 0;
572 break;
573 case 3:
574 reg = reg_devconf1;
575 sel_bit = 2;
576 break;
577 case 4:
578 reg = reg_devconf1;
579 sel_bit = 4;
580 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200581 default:
582 return -EINVAL;
583 }
584
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300585 if (clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK)
586 omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
587 else
588 omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200589
590 return 0;
591}
592
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300593static int omap_mcbsp_dai_set_rcvr_src(struct omap_mcbsp_data *mcbsp_data,
594 int clk_id)
595{
596 int sel_bit, set = 0;
597 u16 reg = OMAP2_CONTROL_DEVCONF0;
598
599 if (cpu_class_is_omap1())
600 return -EINVAL; /* TODO: Can this be implemented for OMAP1? */
601 if (mcbsp_data->bus_id != 0)
602 return -EINVAL;
603
604 switch (clk_id) {
605 case OMAP_MCBSP_CLKR_SRC_CLKX:
606 set = 1;
607 case OMAP_MCBSP_CLKR_SRC_CLKR:
608 sel_bit = 3;
609 break;
610 case OMAP_MCBSP_FSR_SRC_FSX:
611 set = 1;
612 case OMAP_MCBSP_FSR_SRC_FSR:
613 sel_bit = 4;
614 break;
615 default:
616 return -EINVAL;
617 }
618
619 if (set)
620 omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
621 else
622 omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
623
624 return 0;
625}
626
Liam Girdwood8687eb82008-07-07 16:08:07 +0100627static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200628 int clk_id, unsigned int freq,
629 int dir)
630{
631 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
632 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
633 int err = 0;
634
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000635 mcbsp_data->in_freq = freq;
636
Jarkko Nikula2e747962008-04-25 13:55:19 +0200637 switch (clk_id) {
638 case OMAP_MCBSP_SYSCLK_CLK:
639 regs->srgr2 |= CLKSM;
640 break;
641 case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
642 case OMAP_MCBSP_SYSCLK_CLKS_EXT:
643 err = omap_mcbsp_dai_set_clks_src(mcbsp_data, clk_id);
644 break;
645
646 case OMAP_MCBSP_SYSCLK_CLKX_EXT:
647 regs->srgr2 |= CLKSM;
648 case OMAP_MCBSP_SYSCLK_CLKR_EXT:
649 regs->pcr0 |= SCLKME;
650 break;
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300651
652 case OMAP_MCBSP_CLKR_SRC_CLKR:
653 case OMAP_MCBSP_CLKR_SRC_CLKX:
654 case OMAP_MCBSP_FSR_SRC_FSR:
655 case OMAP_MCBSP_FSR_SRC_FSX:
656 err = omap_mcbsp_dai_set_rcvr_src(mcbsp_data, clk_id);
657 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200658 default:
659 err = -ENODEV;
660 }
661
662 return err;
663}
664
Eric Miao6335d052009-03-03 09:41:00 +0800665static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
666 .startup = omap_mcbsp_dai_startup,
667 .shutdown = omap_mcbsp_dai_shutdown,
668 .trigger = omap_mcbsp_dai_trigger,
Peter Ujfalusi75581d22010-03-03 15:08:09 +0200669 .delay = omap_mcbsp_dai_delay,
Eric Miao6335d052009-03-03 09:41:00 +0800670 .hw_params = omap_mcbsp_dai_hw_params,
671 .set_fmt = omap_mcbsp_dai_set_dai_fmt,
672 .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
673 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
674};
675
Jarkko Nikula8def4642008-10-09 15:57:22 +0300676#define OMAP_MCBSP_DAI_BUILDER(link_id) \
677{ \
Jarkko Nikula0c758bd2008-11-21 14:31:33 +0200678 .name = "omap-mcbsp-dai-"#link_id, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300679 .id = (link_id), \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300680 .playback = { \
Jarkko Nikula375e8a72008-11-25 12:45:09 +0200681 .channels_min = 1, \
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000682 .channels_max = 16, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300683 .rates = OMAP_MCBSP_RATES, \
Sergey Lapind98508a2010-05-13 19:48:16 +0400684 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
685 SNDRV_PCM_FMTBIT_S32_LE, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300686 }, \
687 .capture = { \
Jarkko Nikula375e8a72008-11-25 12:45:09 +0200688 .channels_min = 1, \
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000689 .channels_max = 16, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300690 .rates = OMAP_MCBSP_RATES, \
Sergey Lapind98508a2010-05-13 19:48:16 +0400691 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
692 SNDRV_PCM_FMTBIT_S32_LE, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300693 }, \
Eric Miao6335d052009-03-03 09:41:00 +0800694 .ops = &omap_mcbsp_dai_ops, \
Jarkko Nikula8def4642008-10-09 15:57:22 +0300695 .private_data = &mcbsp_data[(link_id)].bus_id, \
696}
697
698struct snd_soc_dai omap_mcbsp_dai[] = {
699 OMAP_MCBSP_DAI_BUILDER(0),
700 OMAP_MCBSP_DAI_BUILDER(1),
701#if NUM_LINKS >= 3
702 OMAP_MCBSP_DAI_BUILDER(2),
703#endif
704#if NUM_LINKS == 5
705 OMAP_MCBSP_DAI_BUILDER(3),
706 OMAP_MCBSP_DAI_BUILDER(4),
707#endif
Jarkko Nikula2e747962008-04-25 13:55:19 +0200708};
Jarkko Nikula8def4642008-10-09 15:57:22 +0300709
Jarkko Nikula2e747962008-04-25 13:55:19 +0200710EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
711
Ilkka Koskinen83905c12010-02-22 12:21:12 +0000712int omap_mcbsp_st_info_volsw(struct snd_kcontrol *kcontrol,
713 struct snd_ctl_elem_info *uinfo)
714{
715 struct soc_mixer_control *mc =
716 (struct soc_mixer_control *)kcontrol->private_value;
717 int max = mc->max;
718 int min = mc->min;
719
720 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
721 uinfo->count = 1;
722 uinfo->value.integer.min = min;
723 uinfo->value.integer.max = max;
724 return 0;
725}
726
727#define OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(id, channel) \
728static int \
729omap_mcbsp##id##_set_st_ch##channel##_volume(struct snd_kcontrol *kc, \
730 struct snd_ctl_elem_value *uc) \
731{ \
732 struct soc_mixer_control *mc = \
733 (struct soc_mixer_control *)kc->private_value; \
734 int max = mc->max; \
735 int min = mc->min; \
736 int val = uc->value.integer.value[0]; \
737 \
738 if (val < min || val > max) \
739 return -EINVAL; \
740 \
741 /* OMAP McBSP implementation uses index values 0..4 */ \
742 return omap_st_set_chgain((id)-1, channel, val); \
743}
744
745#define OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(id, channel) \
746static int \
747omap_mcbsp##id##_get_st_ch##channel##_volume(struct snd_kcontrol *kc, \
748 struct snd_ctl_elem_value *uc) \
749{ \
750 s16 chgain; \
751 \
752 if (omap_st_get_chgain((id)-1, channel, &chgain)) \
753 return -EAGAIN; \
754 \
755 uc->value.integer.value[0] = chgain; \
756 return 0; \
757}
758
759OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 0)
760OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 1)
761OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 0)
762OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 1)
763OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 0)
764OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 1)
765OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 0)
766OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 1)
767
768static int omap_mcbsp_st_put_mode(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_value *ucontrol)
770{
771 struct soc_mixer_control *mc =
772 (struct soc_mixer_control *)kcontrol->private_value;
773 u8 value = ucontrol->value.integer.value[0];
774
775 if (value == omap_st_is_enabled(mc->reg))
776 return 0;
777
778 if (value)
779 omap_st_enable(mc->reg);
780 else
781 omap_st_disable(mc->reg);
782
783 return 1;
784}
785
786static int omap_mcbsp_st_get_mode(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
788{
789 struct soc_mixer_control *mc =
790 (struct soc_mixer_control *)kcontrol->private_value;
791
792 ucontrol->value.integer.value[0] = omap_st_is_enabled(mc->reg);
793 return 0;
794}
795
796static const struct snd_kcontrol_new omap_mcbsp2_st_controls[] = {
797 SOC_SINGLE_EXT("McBSP2 Sidetone Switch", 1, 0, 1, 0,
798 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
799 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 0 Volume",
800 -32768, 32767,
801 omap_mcbsp2_get_st_ch0_volume,
802 omap_mcbsp2_set_st_ch0_volume),
803 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 1 Volume",
804 -32768, 32767,
805 omap_mcbsp2_get_st_ch1_volume,
806 omap_mcbsp2_set_st_ch1_volume),
807};
808
809static const struct snd_kcontrol_new omap_mcbsp3_st_controls[] = {
810 SOC_SINGLE_EXT("McBSP3 Sidetone Switch", 2, 0, 1, 0,
811 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
812 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 0 Volume",
813 -32768, 32767,
814 omap_mcbsp3_get_st_ch0_volume,
815 omap_mcbsp3_set_st_ch0_volume),
816 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 1 Volume",
817 -32768, 32767,
818 omap_mcbsp3_get_st_ch1_volume,
819 omap_mcbsp3_set_st_ch1_volume),
820};
821
822int omap_mcbsp_st_add_controls(struct snd_soc_codec *codec, int mcbsp_id)
823{
824 if (!cpu_is_omap34xx())
825 return -ENODEV;
826
827 switch (mcbsp_id) {
828 case 1: /* McBSP 2 */
829 return snd_soc_add_controls(codec, omap_mcbsp2_st_controls,
830 ARRAY_SIZE(omap_mcbsp2_st_controls));
831 case 2: /* McBSP 3 */
832 return snd_soc_add_controls(codec, omap_mcbsp3_st_controls,
833 ARRAY_SIZE(omap_mcbsp3_st_controls));
834 default:
835 break;
836 }
837
838 return -EINVAL;
839}
840EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls);
841
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100842static int __init snd_omap_mcbsp_init(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000843{
844 return snd_soc_register_dais(omap_mcbsp_dai,
845 ARRAY_SIZE(omap_mcbsp_dai));
846}
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100847module_init(snd_omap_mcbsp_init);
Mark Brown3f4b7832008-12-03 19:26:35 +0000848
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100849static void __exit snd_omap_mcbsp_exit(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000850{
851 snd_soc_unregister_dais(omap_mcbsp_dai, ARRAY_SIZE(omap_mcbsp_dai));
852}
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100853module_exit(snd_omap_mcbsp_exit);
Mark Brown3f4b7832008-12-03 19:26:35 +0000854
Jarkko Nikulab08f7a62009-04-17 14:42:26 +0300855MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
Jarkko Nikula2e747962008-04-25 13:55:19 +0200856MODULE_DESCRIPTION("OMAP I2S SoC Interface");
857MODULE_LICENSE("GPL");