2 * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
4 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
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.
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.
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
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>
34 #include <plat/control.h>
36 #include <plat/mcbsp.h>
37 #include "omap-mcbsp.h"
40 #define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000)
42 #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} }
50 struct omap_mcbsp_data {
52 struct omap_mcbsp_reg_cfg regs;
55 * Flags indicating is the bus already activated and configured by
65 #define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id)
67 static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
70 * Stream DMA parameters. DMA request line and port address are set runtime
71 * since they are different between OMAP1 and later OMAPs
73 static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2];
75 #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
76 static 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 },
81 static 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 },
90 static const int omap1_dma_reqs[][2] = {};
91 static const unsigned long omap1_mcbsp_port[][2] = {};
94 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
95 static const int omap24xx_dma_reqs[][2] = {
96 { OMAP24XX_DMA_MCBSP1_TX, OMAP24XX_DMA_MCBSP1_RX },
97 { OMAP24XX_DMA_MCBSP2_TX, OMAP24XX_DMA_MCBSP2_RX },
98 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
99 { 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 },
105 static const int omap24xx_dma_reqs[][2] = {};
108 #if defined(CONFIG_ARCH_OMAP2420)
109 static 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 },
116 static const unsigned long omap2420_mcbsp_port[][2] = {};
119 #if defined(CONFIG_ARCH_OMAP2430)
120 static 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 },
133 static const unsigned long omap2430_mcbsp_port[][2] = {};
136 #if defined(CONFIG_ARCH_OMAP3)
137 static 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 },
150 static const unsigned long omap34xx_mcbsp_port[][2] = {};
153 static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream)
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);
158 int dma_op_mode = omap_mcbsp_get_dma_op_mode(mcbsp_data->bus_id);
161 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
162 if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
163 /* The FIFO size depends on the McBSP word configuration */
164 words = snd_pcm_lib_period_bytes(substream) /
165 (mcbsp_data->wlen / 8);
169 /* Configure McBSP internal buffer usage */
170 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
171 omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, words);
173 omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, words);
176 static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params *params,
177 struct snd_pcm_hw_rule *rule)
179 struct snd_interval *buffer_size = hw_param_interval(params,
180 SNDRV_PCM_HW_PARAM_BUFFER_SIZE);
181 struct snd_interval *channels = hw_param_interval(params,
182 SNDRV_PCM_HW_PARAM_CHANNELS);
183 struct omap_mcbsp_data *mcbsp_data = rule->private;
184 struct snd_interval frames;
187 snd_interval_any(&frames);
188 size = omap_mcbsp_get_fifo_size(mcbsp_data->bus_id);
190 frames.min = size / channels->min;
192 return snd_interval_refine(buffer_size, &frames);
195 static int omap_mcbsp_hwrule_max_periodsize(struct snd_pcm_hw_params *params,
196 struct snd_pcm_hw_rule *rule)
198 struct snd_interval *period_size = hw_param_interval(params,
199 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
200 struct snd_interval *channels = hw_param_interval(params,
201 SNDRV_PCM_HW_PARAM_CHANNELS);
202 struct snd_pcm_substream *substream = rule->private;
203 struct snd_soc_pcm_runtime *rtd = substream->private_data;
204 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
205 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
206 struct snd_interval frames;
209 snd_interval_any(&frames);
210 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
211 size = omap_mcbsp_get_max_tx_threshold(mcbsp_data->bus_id);
213 size = omap_mcbsp_get_max_rx_threshold(mcbsp_data->bus_id);
215 frames.max = size / channels->min;
217 return snd_interval_refine(period_size, &frames);
220 static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
221 struct snd_soc_dai *dai)
223 struct snd_soc_pcm_runtime *rtd = substream->private_data;
224 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
225 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
226 int bus_id = mcbsp_data->bus_id;
229 if (!cpu_dai->active)
230 err = omap_mcbsp_request(bus_id);
233 * OMAP3 McBSP FIFO is word structured.
234 * McBSP2 has 1024 + 256 = 1280 word long buffer,
235 * McBSP1,3,4,5 has 128 word long buffer
236 * This means that the size of the FIFO depends on the sample format.
237 * For example on McBSP3:
238 * 16bit samples: size is 128 * 2 = 256 bytes
239 * 32bit samples: size is 128 * 4 = 512 bytes
240 * It is simpler to place constraint for buffer and period based on
242 * McBSP3 as example again (16 or 32 bit samples):
243 * 1 channel (mono): size is 128 frames (128 words)
244 * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words)
245 * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words)
247 if (cpu_is_omap343x()) {
248 int dma_op_mode = omap_mcbsp_get_dma_op_mode(bus_id);
251 * The first rule is for the buffer size, we should not allow
252 * smaller buffer than the FIFO size to avoid underruns
254 snd_pcm_hw_rule_add(substream->runtime, 0,
255 SNDRV_PCM_HW_PARAM_CHANNELS,
256 omap_mcbsp_hwrule_min_buffersize,
258 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1);
261 * In case of threshold mode, the rule will ensure, that the
262 * period size is not bigger than the maximum allowed threshold
265 if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
266 snd_pcm_hw_rule_add(substream->runtime, 0,
267 SNDRV_PCM_HW_PARAM_CHANNELS,
268 omap_mcbsp_hwrule_max_periodsize,
270 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1);
276 static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
277 struct snd_soc_dai *dai)
279 struct snd_soc_pcm_runtime *rtd = substream->private_data;
280 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
281 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
283 if (!cpu_dai->active) {
284 omap_mcbsp_free(mcbsp_data->bus_id);
285 mcbsp_data->configured = 0;
289 static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
290 struct snd_soc_dai *dai)
292 struct snd_soc_pcm_runtime *rtd = substream->private_data;
293 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
294 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
295 int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
298 case SNDRV_PCM_TRIGGER_START:
299 case SNDRV_PCM_TRIGGER_RESUME:
300 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
301 mcbsp_data->active++;
302 omap_mcbsp_start(mcbsp_data->bus_id, play, !play);
305 case SNDRV_PCM_TRIGGER_STOP:
306 case SNDRV_PCM_TRIGGER_SUSPEND:
307 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
308 omap_mcbsp_stop(mcbsp_data->bus_id, play, !play);
309 mcbsp_data->active--;
318 static snd_pcm_sframes_t omap_mcbsp_dai_delay(
319 struct snd_pcm_substream *substream,
320 struct snd_soc_dai *dai)
322 struct snd_soc_pcm_runtime *rtd = substream->private_data;
323 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
324 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
326 snd_pcm_sframes_t delay;
328 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
329 fifo_use = omap_mcbsp_get_tx_delay(mcbsp_data->bus_id);
331 fifo_use = omap_mcbsp_get_rx_delay(mcbsp_data->bus_id);
334 * Divide the used locations with the channel count to get the
335 * FIFO usage in samples (don't care about partial samples in the
338 delay = fifo_use / substream->runtime->channels;
343 static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
344 struct snd_pcm_hw_params *params,
345 struct snd_soc_dai *dai)
347 struct snd_soc_pcm_runtime *rtd = substream->private_data;
348 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
349 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
350 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
351 int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
352 int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
354 unsigned int format, div, framesize, master;
356 if (cpu_class_is_omap1()) {
357 dma = omap1_dma_reqs[bus_id][substream->stream];
358 port = omap1_mcbsp_port[bus_id][substream->stream];
359 } else if (cpu_is_omap2420()) {
360 dma = omap24xx_dma_reqs[bus_id][substream->stream];
361 port = omap2420_mcbsp_port[bus_id][substream->stream];
362 } else if (cpu_is_omap2430()) {
363 dma = omap24xx_dma_reqs[bus_id][substream->stream];
364 port = omap2430_mcbsp_port[bus_id][substream->stream];
365 } else if (cpu_is_omap343x()) {
366 dma = omap24xx_dma_reqs[bus_id][substream->stream];
367 port = omap34xx_mcbsp_port[bus_id][substream->stream];
368 omap_mcbsp_dai_dma_params[id][substream->stream].set_threshold =
369 omap_mcbsp_set_threshold;
370 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
371 if (omap_mcbsp_get_dma_op_mode(bus_id) ==
372 MCBSP_DMA_MODE_THRESHOLD)
373 sync_mode = OMAP_DMA_SYNC_FRAME;
377 omap_mcbsp_dai_dma_params[id][substream->stream].name =
378 substream->stream ? "Audio Capture" : "Audio Playback";
379 omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
380 omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
381 omap_mcbsp_dai_dma_params[id][substream->stream].sync_mode = sync_mode;
382 switch (params_format(params)) {
383 case SNDRV_PCM_FORMAT_S16_LE:
384 omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
385 OMAP_DMA_DATA_TYPE_S16;
387 case SNDRV_PCM_FORMAT_S32_LE:
388 omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
389 OMAP_DMA_DATA_TYPE_S32;
395 snd_soc_dai_set_dma_data(cpu_dai, substream,
396 &omap_mcbsp_dai_dma_params[id][substream->stream]);
398 if (mcbsp_data->configured) {
399 /* McBSP already configured by another stream */
403 format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
404 wpf = channels = params_channels(params);
405 if (channels == 2 && (format == SND_SOC_DAIFMT_I2S ||
406 format == SND_SOC_DAIFMT_LEFT_J)) {
407 /* Use dual-phase frames */
408 regs->rcr2 |= RPHASE;
409 regs->xcr2 |= XPHASE;
410 /* Set 1 word per (McBSP) frame for phase1 and phase2 */
412 regs->rcr2 |= RFRLEN2(wpf - 1);
413 regs->xcr2 |= XFRLEN2(wpf - 1);
416 regs->rcr1 |= RFRLEN1(wpf - 1);
417 regs->xcr1 |= XFRLEN1(wpf - 1);
419 switch (params_format(params)) {
420 case SNDRV_PCM_FORMAT_S16_LE:
421 /* Set word lengths */
423 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
424 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
425 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
426 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
428 case SNDRV_PCM_FORMAT_S32_LE:
429 /* Set word lengths */
431 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_32);
432 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_32);
433 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_32);
434 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_32);
437 /* Unsupported PCM format */
441 /* In McBSP master modes, FRAME (i.e. sample rate) is generated
442 * by _counting_ BCLKs. Calculate frame size in BCLKs */
443 master = mcbsp_data->fmt & SND_SOC_DAIFMT_MASTER_MASK;
444 if (master == SND_SOC_DAIFMT_CBS_CFS) {
445 div = mcbsp_data->clk_div ? mcbsp_data->clk_div : 1;
446 framesize = (mcbsp_data->in_freq / div) / params_rate(params);
448 if (framesize < wlen * channels) {
449 printk(KERN_ERR "%s: not enough bandwidth for desired rate and "
450 "channels\n", __func__);
454 framesize = wlen * channels;
456 /* Set FS period and length in terms of bit clock periods */
458 case SND_SOC_DAIFMT_I2S:
459 case SND_SOC_DAIFMT_LEFT_J:
460 regs->srgr2 |= FPER(framesize - 1);
461 regs->srgr1 |= FWID((framesize >> 1) - 1);
463 case SND_SOC_DAIFMT_DSP_A:
464 case SND_SOC_DAIFMT_DSP_B:
465 regs->srgr2 |= FPER(framesize - 1);
466 regs->srgr1 |= FWID(0);
470 omap_mcbsp_config(bus_id, &mcbsp_data->regs);
471 mcbsp_data->wlen = wlen;
472 mcbsp_data->configured = 1;
478 * This must be called before _set_clkdiv and _set_sysclk since McBSP register
479 * cache is initialized here
481 static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
484 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
485 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
486 unsigned int temp_fmt = fmt;
488 if (mcbsp_data->configured)
491 mcbsp_data->fmt = fmt;
492 memset(regs, 0, sizeof(*regs));
493 /* Generic McBSP register settings */
494 regs->spcr2 |= XINTM(3) | FREE;
495 regs->spcr1 |= RINTM(3);
496 /* RFIG and XFIG are not defined in 34xx */
497 if (!cpu_is_omap34xx()) {
501 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
502 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE;
503 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE;
506 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
507 case SND_SOC_DAIFMT_I2S:
508 /* 1-bit data delay */
509 regs->rcr2 |= RDATDLY(1);
510 regs->xcr2 |= XDATDLY(1);
512 case SND_SOC_DAIFMT_LEFT_J:
513 /* 0-bit data delay */
514 regs->rcr2 |= RDATDLY(0);
515 regs->xcr2 |= XDATDLY(0);
516 regs->spcr1 |= RJUST(2);
517 /* Invert FS polarity configuration */
518 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
520 case SND_SOC_DAIFMT_DSP_A:
521 /* 1-bit data delay */
522 regs->rcr2 |= RDATDLY(1);
523 regs->xcr2 |= XDATDLY(1);
524 /* Invert FS polarity configuration */
525 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
527 case SND_SOC_DAIFMT_DSP_B:
528 /* 0-bit data delay */
529 regs->rcr2 |= RDATDLY(0);
530 regs->xcr2 |= XDATDLY(0);
531 /* Invert FS polarity configuration */
532 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
535 /* Unsupported data format */
539 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
540 case SND_SOC_DAIFMT_CBS_CFS:
541 /* McBSP master. Set FS and bit clocks as outputs */
542 regs->pcr0 |= FSXM | FSRM |
544 /* Sample rate generator drives the FS */
547 case SND_SOC_DAIFMT_CBM_CFM:
551 /* Unsupported master/slave configuration */
555 /* Set bit clock (CLKX/CLKR) and FS polarities */
556 switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
557 case SND_SOC_DAIFMT_NB_NF:
560 * FS active low. TX data driven on falling edge of bit clock
561 * and RX data sampled on rising edge of bit clock.
563 regs->pcr0 |= FSXP | FSRP |
566 case SND_SOC_DAIFMT_NB_IF:
567 regs->pcr0 |= CLKXP | CLKRP;
569 case SND_SOC_DAIFMT_IB_NF:
570 regs->pcr0 |= FSXP | FSRP;
572 case SND_SOC_DAIFMT_IB_IF:
581 static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
584 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
585 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
587 if (div_id != OMAP_MCBSP_CLKGDV)
590 mcbsp_data->clk_div = div;
591 regs->srgr1 |= CLKGDV(div - 1);
596 static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
600 u16 reg, reg_devconf1 = OMAP243X_CONTROL_DEVCONF1;
602 if (cpu_class_is_omap1()) {
603 /* OMAP1's can use only external source clock */
604 if (unlikely(clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK))
610 if (cpu_is_omap2420() && mcbsp_data->bus_id > 1)
613 if (cpu_is_omap343x())
614 reg_devconf1 = OMAP343X_CONTROL_DEVCONF1;
616 switch (mcbsp_data->bus_id) {
618 reg = OMAP2_CONTROL_DEVCONF0;
622 reg = OMAP2_CONTROL_DEVCONF0;
641 if (clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK)
642 omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
644 omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
649 static int omap_mcbsp_dai_set_rcvr_src(struct omap_mcbsp_data *mcbsp_data,
652 int sel_bit, set = 0;
653 u16 reg = OMAP2_CONTROL_DEVCONF0;
655 if (cpu_class_is_omap1())
656 return -EINVAL; /* TODO: Can this be implemented for OMAP1? */
657 if (mcbsp_data->bus_id != 0)
661 case OMAP_MCBSP_CLKR_SRC_CLKX:
663 case OMAP_MCBSP_CLKR_SRC_CLKR:
666 case OMAP_MCBSP_FSR_SRC_FSX:
668 case OMAP_MCBSP_FSR_SRC_FSR:
676 omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
678 omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
683 static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
684 int clk_id, unsigned int freq,
687 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
688 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
691 mcbsp_data->in_freq = freq;
694 case OMAP_MCBSP_SYSCLK_CLK:
695 regs->srgr2 |= CLKSM;
697 case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
698 case OMAP_MCBSP_SYSCLK_CLKS_EXT:
699 err = omap_mcbsp_dai_set_clks_src(mcbsp_data, clk_id);
702 case OMAP_MCBSP_SYSCLK_CLKX_EXT:
703 regs->srgr2 |= CLKSM;
704 case OMAP_MCBSP_SYSCLK_CLKR_EXT:
705 regs->pcr0 |= SCLKME;
708 case OMAP_MCBSP_CLKR_SRC_CLKR:
709 case OMAP_MCBSP_CLKR_SRC_CLKX:
710 case OMAP_MCBSP_FSR_SRC_FSR:
711 case OMAP_MCBSP_FSR_SRC_FSX:
712 err = omap_mcbsp_dai_set_rcvr_src(mcbsp_data, clk_id);
721 static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
722 .startup = omap_mcbsp_dai_startup,
723 .shutdown = omap_mcbsp_dai_shutdown,
724 .trigger = omap_mcbsp_dai_trigger,
725 .delay = omap_mcbsp_dai_delay,
726 .hw_params = omap_mcbsp_dai_hw_params,
727 .set_fmt = omap_mcbsp_dai_set_dai_fmt,
728 .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
729 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
732 #define OMAP_MCBSP_DAI_BUILDER(link_id) \
734 .name = "omap-mcbsp-dai-"#link_id, \
738 .channels_max = 16, \
739 .rates = OMAP_MCBSP_RATES, \
740 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
741 SNDRV_PCM_FMTBIT_S32_LE, \
745 .channels_max = 16, \
746 .rates = OMAP_MCBSP_RATES, \
747 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
748 SNDRV_PCM_FMTBIT_S32_LE, \
750 .ops = &omap_mcbsp_dai_ops, \
751 .private_data = &mcbsp_data[(link_id)].bus_id, \
754 struct snd_soc_dai omap_mcbsp_dai[] = {
755 OMAP_MCBSP_DAI_BUILDER(0),
756 OMAP_MCBSP_DAI_BUILDER(1),
758 OMAP_MCBSP_DAI_BUILDER(2),
761 OMAP_MCBSP_DAI_BUILDER(3),
762 OMAP_MCBSP_DAI_BUILDER(4),
766 EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
768 int omap_mcbsp_st_info_volsw(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_info *uinfo)
771 struct soc_mixer_control *mc =
772 (struct soc_mixer_control *)kcontrol->private_value;
776 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
778 uinfo->value.integer.min = min;
779 uinfo->value.integer.max = max;
783 #define OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(id, channel) \
785 omap_mcbsp##id##_set_st_ch##channel##_volume(struct snd_kcontrol *kc, \
786 struct snd_ctl_elem_value *uc) \
788 struct soc_mixer_control *mc = \
789 (struct soc_mixer_control *)kc->private_value; \
792 int val = uc->value.integer.value[0]; \
794 if (val < min || val > max) \
797 /* OMAP McBSP implementation uses index values 0..4 */ \
798 return omap_st_set_chgain((id)-1, channel, val); \
801 #define OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(id, channel) \
803 omap_mcbsp##id##_get_st_ch##channel##_volume(struct snd_kcontrol *kc, \
804 struct snd_ctl_elem_value *uc) \
808 if (omap_st_get_chgain((id)-1, channel, &chgain)) \
811 uc->value.integer.value[0] = chgain; \
815 OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 0)
816 OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 1)
817 OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 0)
818 OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 1)
819 OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 0)
820 OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 1)
821 OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 0)
822 OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 1)
824 static int omap_mcbsp_st_put_mode(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
827 struct soc_mixer_control *mc =
828 (struct soc_mixer_control *)kcontrol->private_value;
829 u8 value = ucontrol->value.integer.value[0];
831 if (value == omap_st_is_enabled(mc->reg))
835 omap_st_enable(mc->reg);
837 omap_st_disable(mc->reg);
842 static int omap_mcbsp_st_get_mode(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
845 struct soc_mixer_control *mc =
846 (struct soc_mixer_control *)kcontrol->private_value;
848 ucontrol->value.integer.value[0] = omap_st_is_enabled(mc->reg);
852 static const struct snd_kcontrol_new omap_mcbsp2_st_controls[] = {
853 SOC_SINGLE_EXT("McBSP2 Sidetone Switch", 1, 0, 1, 0,
854 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
855 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 0 Volume",
857 omap_mcbsp2_get_st_ch0_volume,
858 omap_mcbsp2_set_st_ch0_volume),
859 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 1 Volume",
861 omap_mcbsp2_get_st_ch1_volume,
862 omap_mcbsp2_set_st_ch1_volume),
865 static const struct snd_kcontrol_new omap_mcbsp3_st_controls[] = {
866 SOC_SINGLE_EXT("McBSP3 Sidetone Switch", 2, 0, 1, 0,
867 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
868 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 0 Volume",
870 omap_mcbsp3_get_st_ch0_volume,
871 omap_mcbsp3_set_st_ch0_volume),
872 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 1 Volume",
874 omap_mcbsp3_get_st_ch1_volume,
875 omap_mcbsp3_set_st_ch1_volume),
878 int omap_mcbsp_st_add_controls(struct snd_soc_codec *codec, int mcbsp_id)
880 if (!cpu_is_omap34xx())
884 case 1: /* McBSP 2 */
885 return snd_soc_add_controls(codec, omap_mcbsp2_st_controls,
886 ARRAY_SIZE(omap_mcbsp2_st_controls));
887 case 2: /* McBSP 3 */
888 return snd_soc_add_controls(codec, omap_mcbsp3_st_controls,
889 ARRAY_SIZE(omap_mcbsp3_st_controls));
896 EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls);
898 static int __init snd_omap_mcbsp_init(void)
900 return snd_soc_register_dais(omap_mcbsp_dai,
901 ARRAY_SIZE(omap_mcbsp_dai));
903 module_init(snd_omap_mcbsp_init);
905 static void __exit snd_omap_mcbsp_exit(void)
907 snd_soc_unregister_dais(omap_mcbsp_dai, ARRAY_SIZE(omap_mcbsp_dai));
909 module_exit(snd_omap_mcbsp_exit);
911 MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
912 MODULE_DESCRIPTION("OMAP I2S SoC Interface");
913 MODULE_LICENSE("GPL");