blob: 7e84f24b9a88bf56ef0d000901d6c69d39f7461c [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/dma.h>
35#include <plat/mcbsp.h>
Jarkko Nikula2e747962008-04-25 13:55:19 +020036#include "omap-mcbsp.h"
37#include "omap-pcm.h"
38
Jarkko Nikula0b604852008-11-12 17:05:51 +020039#define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000)
Jarkko Nikula2e747962008-04-25 13:55:19 +020040
Ilkka Koskinen83905c12010-02-22 12:21:12 +000041#define OMAP_MCBSP_SOC_SINGLE_S16_EXT(xname, xmin, xmax, \
42 xhandler_get, xhandler_put) \
43{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
44 .info = omap_mcbsp_st_info_volsw, \
45 .get = xhandler_get, .put = xhandler_put, \
46 .private_value = (unsigned long) &(struct soc_mixer_control) \
47 {.min = xmin, .max = xmax} }
48
Jarkko Nikula2e747962008-04-25 13:55:19 +020049struct omap_mcbsp_data {
50 unsigned int bus_id;
51 struct omap_mcbsp_reg_cfg regs;
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +030052 unsigned int fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +020053 /*
54 * Flags indicating is the bus already activated and configured by
55 * another substream
56 */
57 int active;
58 int configured;
Graeme Gregory5f63ef92009-11-09 19:02:15 +000059 unsigned int in_freq;
60 int clk_div;
Peter Ujfalusi3f024032010-06-03 07:39:35 +030061 int wlen;
Jarkko Nikula2e747962008-04-25 13:55:19 +020062};
63
Jarkko Nikula2e747962008-04-25 13:55:19 +020064static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
65
66/*
67 * Stream DMA parameters. DMA request line and port address are set runtime
68 * since they are different between OMAP1 and later OMAPs
69 */
Jarkko Nikula2e897132008-10-09 15:57:21 +030070static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2];
Jarkko Nikula2e747962008-04-25 13:55:19 +020071
72#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
73static const int omap1_dma_reqs[][2] = {
74 { OMAP_DMA_MCBSP1_TX, OMAP_DMA_MCBSP1_RX },
75 { OMAP_DMA_MCBSP2_TX, OMAP_DMA_MCBSP2_RX },
76 { OMAP_DMA_MCBSP3_TX, OMAP_DMA_MCBSP3_RX },
77};
78static const unsigned long omap1_mcbsp_port[][2] = {
79 { OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
80 OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
81 { OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
82 OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
83 { OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DXR1,
84 OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DRR1 },
85};
86#else
87static const int omap1_dma_reqs[][2] = {};
88static const unsigned long omap1_mcbsp_port[][2] = {};
89#endif
Jarkko Nikula406e2c42008-10-09 15:57:20 +030090
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -080091#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +030092static const int omap24xx_dma_reqs[][2] = {
Jarkko Nikula2e747962008-04-25 13:55:19 +020093 { OMAP24XX_DMA_MCBSP1_TX, OMAP24XX_DMA_MCBSP1_RX },
94 { OMAP24XX_DMA_MCBSP2_TX, OMAP24XX_DMA_MCBSP2_RX },
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -080095#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +030096 { OMAP24XX_DMA_MCBSP3_TX, OMAP24XX_DMA_MCBSP3_RX },
97 { OMAP24XX_DMA_MCBSP4_TX, OMAP24XX_DMA_MCBSP4_RX },
98 { OMAP24XX_DMA_MCBSP5_TX, OMAP24XX_DMA_MCBSP5_RX },
99#endif
Jarkko Nikula2e747962008-04-25 13:55:19 +0200100};
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300101#else
102static const int omap24xx_dma_reqs[][2] = {};
103#endif
104
105#if defined(CONFIG_ARCH_OMAP2420)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200106static const unsigned long omap2420_mcbsp_port[][2] = {
107 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
108 OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
109 { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
110 OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
111};
112#else
Jarkko Nikula2e747962008-04-25 13:55:19 +0200113static const unsigned long omap2420_mcbsp_port[][2] = {};
114#endif
115
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300116#if defined(CONFIG_ARCH_OMAP2430)
117static const unsigned long omap2430_mcbsp_port[][2] = {
118 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
119 OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
120 { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
121 OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
122 { OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
123 OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
124 { OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
125 OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
126 { OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
127 OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
128};
129#else
130static const unsigned long omap2430_mcbsp_port[][2] = {};
131#endif
132
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800133#if defined(CONFIG_ARCH_OMAP3)
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300134static const unsigned long omap34xx_mcbsp_port[][2] = {
135 { OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
136 OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
137 { OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
138 OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
139 { OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
140 OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
141 { OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
142 OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
143 { OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
144 OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
145};
146#else
147static const unsigned long omap34xx_mcbsp_port[][2] = {};
148#endif
149
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300150static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream)
151{
152 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
154 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300155 struct omap_pcm_dma_data *dma_data;
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300156 int dma_op_mode = omap_mcbsp_get_dma_op_mode(mcbsp_data->bus_id);
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300157 int words;
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300158
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000159 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300160
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300161 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
162 if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300163 /*
164 * Configure McBSP threshold based on either:
165 * packet_size, when the sDMA is in packet mode, or
166 * based on the period size.
167 */
168 if (dma_data->packet_size)
169 words = dma_data->packet_size;
170 else
171 words = snd_pcm_lib_period_bytes(substream) /
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300172 (mcbsp_data->wlen / 8);
Eduardo Valentina0a499c2009-08-20 16:18:26 +0300173 else
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300174 words = 1;
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300175
176 /* Configure McBSP internal buffer usage */
177 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300178 omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, words);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300179 else
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300180 omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, words);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300181}
182
Peter Ujfalusiddc29b02010-06-03 07:39:36 +0300183static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params *params,
184 struct snd_pcm_hw_rule *rule)
185{
186 struct snd_interval *buffer_size = hw_param_interval(params,
187 SNDRV_PCM_HW_PARAM_BUFFER_SIZE);
188 struct snd_interval *channels = hw_param_interval(params,
189 SNDRV_PCM_HW_PARAM_CHANNELS);
190 struct omap_mcbsp_data *mcbsp_data = rule->private;
191 struct snd_interval frames;
192 int size;
193
194 snd_interval_any(&frames);
195 size = omap_mcbsp_get_fifo_size(mcbsp_data->bus_id);
196
197 frames.min = size / channels->min;
198 frames.integer = 1;
199 return snd_interval_refine(buffer_size, &frames);
200}
201
Mark Browndee89c42008-11-18 22:11:38 +0000202static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000203 struct snd_soc_dai *cpu_dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200204{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000205 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300206 int bus_id = mcbsp_data->bus_id;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200207 int err = 0;
208
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300209 if (!cpu_dai->active)
210 err = omap_mcbsp_request(bus_id);
211
Peter Ujfalusiddc29b02010-06-03 07:39:36 +0300212 /*
213 * OMAP3 McBSP FIFO is word structured.
214 * McBSP2 has 1024 + 256 = 1280 word long buffer,
215 * McBSP1,3,4,5 has 128 word long buffer
216 * This means that the size of the FIFO depends on the sample format.
217 * For example on McBSP3:
218 * 16bit samples: size is 128 * 2 = 256 bytes
219 * 32bit samples: size is 128 * 4 = 512 bytes
220 * It is simpler to place constraint for buffer and period based on
221 * channels.
222 * McBSP3 as example again (16 or 32 bit samples):
223 * 1 channel (mono): size is 128 frames (128 words)
224 * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words)
225 * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words)
226 */
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300227 if (cpu_is_omap343x()) {
Jarkko Nikula69849922009-03-27 15:32:01 +0200228 /*
Peter Ujfalusi998a8a62010-07-29 09:51:28 +0300229 * Rule for the buffer size. We should not allow
Peter Ujfalusiddc29b02010-06-03 07:39:36 +0300230 * smaller buffer than the FIFO size to avoid underruns
231 */
232 snd_pcm_hw_rule_add(substream->runtime, 0,
233 SNDRV_PCM_HW_PARAM_CHANNELS,
234 omap_mcbsp_hwrule_min_buffersize,
235 mcbsp_data,
236 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1);
237
Peter Ujfalusi998a8a62010-07-29 09:51:28 +0300238 /* Make sure, that the period size is always even */
239 snd_pcm_hw_constraint_step(substream->runtime, 0,
240 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2);
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300241 }
Jarkko Nikula2e747962008-04-25 13:55:19 +0200242
243 return err;
244}
245
Mark Browndee89c42008-11-18 22:11:38 +0000246static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000247 struct snd_soc_dai *cpu_dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200248{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000249 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200250
251 if (!cpu_dai->active) {
252 omap_mcbsp_free(mcbsp_data->bus_id);
253 mcbsp_data->configured = 0;
254 }
255}
256
Mark Browndee89c42008-11-18 22:11:38 +0000257static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000258 struct snd_soc_dai *cpu_dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200259{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000260 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300261 int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200262
263 switch (cmd) {
264 case SNDRV_PCM_TRIGGER_START:
265 case SNDRV_PCM_TRIGGER_RESUME:
266 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300267 mcbsp_data->active++;
268 omap_mcbsp_start(mcbsp_data->bus_id, play, !play);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200269 break;
270
271 case SNDRV_PCM_TRIGGER_STOP:
272 case SNDRV_PCM_TRIGGER_SUSPEND:
273 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300274 omap_mcbsp_stop(mcbsp_data->bus_id, play, !play);
275 mcbsp_data->active--;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200276 break;
277 default:
278 err = -EINVAL;
279 }
280
281 return err;
282}
283
Peter Ujfalusi75581d22010-03-03 15:08:09 +0200284static snd_pcm_sframes_t omap_mcbsp_dai_delay(
285 struct snd_pcm_substream *substream,
286 struct snd_soc_dai *dai)
287{
288 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000289 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
290 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Peter Ujfalusi75581d22010-03-03 15:08:09 +0200291 u16 fifo_use;
292 snd_pcm_sframes_t delay;
293
294 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
295 fifo_use = omap_mcbsp_get_tx_delay(mcbsp_data->bus_id);
296 else
297 fifo_use = omap_mcbsp_get_rx_delay(mcbsp_data->bus_id);
298
299 /*
300 * Divide the used locations with the channel count to get the
301 * FIFO usage in samples (don't care about partial samples in the
302 * buffer).
303 */
304 delay = fifo_use / substream->runtime->channels;
305
306 return delay;
307}
308
Jarkko Nikula2e747962008-04-25 13:55:19 +0200309static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000310 struct snd_pcm_hw_params *params,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000311 struct snd_soc_dai *cpu_dai)
Jarkko Nikula2e747962008-04-25 13:55:19 +0200312{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000313 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200314 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
Peter Ujfalusi81ec0272010-07-29 09:51:26 +0300315 struct omap_pcm_dma_data *dma_data;
316 int dma, bus_id = mcbsp_data->bus_id;
Eduardo Valentincaebc0c2009-08-20 16:18:25 +0300317 int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300318 int pkt_size = 0;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200319 unsigned long port;
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000320 unsigned int format, div, framesize, master;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200321
Peter Ujfalusi81ec0272010-07-29 09:51:26 +0300322 dma_data = &omap_mcbsp_dai_dma_params[cpu_dai->id][substream->stream];
Jarkko Nikula2e747962008-04-25 13:55:19 +0200323 if (cpu_class_is_omap1()) {
324 dma = omap1_dma_reqs[bus_id][substream->stream];
325 port = omap1_mcbsp_port[bus_id][substream->stream];
326 } else if (cpu_is_omap2420()) {
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300327 dma = omap24xx_dma_reqs[bus_id][substream->stream];
Jarkko Nikula2e747962008-04-25 13:55:19 +0200328 port = omap2420_mcbsp_port[bus_id][substream->stream];
Jarkko Nikula406e2c42008-10-09 15:57:20 +0300329 } else if (cpu_is_omap2430()) {
330 dma = omap24xx_dma_reqs[bus_id][substream->stream];
331 port = omap2430_mcbsp_port[bus_id][substream->stream];
332 } else if (cpu_is_omap343x()) {
333 dma = omap24xx_dma_reqs[bus_id][substream->stream];
334 port = omap34xx_mcbsp_port[bus_id][substream->stream];
Jarkko Nikula2e747962008-04-25 13:55:19 +0200335 } else {
Jarkko Nikula2e747962008-04-25 13:55:19 +0200336 return -ENODEV;
337 }
Sergey Lapind98508a2010-05-13 19:48:16 +0400338 switch (params_format(params)) {
339 case SNDRV_PCM_FORMAT_S16_LE:
Peter Ujfalusi81ec0272010-07-29 09:51:26 +0300340 dma_data->data_type = OMAP_DMA_DATA_TYPE_S16;
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300341 wlen = 16;
Sergey Lapind98508a2010-05-13 19:48:16 +0400342 break;
343 case SNDRV_PCM_FORMAT_S32_LE:
Peter Ujfalusi81ec0272010-07-29 09:51:26 +0300344 dma_data->data_type = OMAP_DMA_DATA_TYPE_S32;
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300345 wlen = 32;
Sergey Lapind98508a2010-05-13 19:48:16 +0400346 break;
347 default:
348 return -EINVAL;
349 }
Peter Ujfalusi15d01432010-07-29 09:51:25 +0300350 if (cpu_is_omap343x()) {
351 dma_data->set_threshold = omap_mcbsp_set_threshold;
352 /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
353 if (omap_mcbsp_get_dma_op_mode(bus_id) ==
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300354 MCBSP_DMA_MODE_THRESHOLD) {
355 int period_words, max_thrsh;
356
357 period_words = params_period_bytes(params) / (wlen / 8);
358 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
359 max_thrsh = omap_mcbsp_get_max_tx_threshold(
360 mcbsp_data->bus_id);
361 else
362 max_thrsh = omap_mcbsp_get_max_rx_threshold(
363 mcbsp_data->bus_id);
364 /*
365 * If the period contains less or equal number of words,
366 * we are using the original threshold mode setup:
367 * McBSP threshold = sDMA frame size = period_size
368 * Otherwise we switch to sDMA packet mode:
369 * McBSP threshold = sDMA packet size
370 * sDMA frame size = period size
371 */
372 if (period_words > max_thrsh) {
373 int divider = 0;
374
375 /*
376 * Look for the biggest threshold value, which
377 * divides the period size evenly.
378 */
379 divider = period_words / max_thrsh;
380 if (period_words % max_thrsh)
381 divider++;
382 while (period_words % divider &&
383 divider < period_words)
384 divider++;
385 if (divider == period_words)
386 return -EINVAL;
387
388 pkt_size = period_words / divider;
389 sync_mode = OMAP_DMA_SYNC_PACKET;
390 } else {
391 sync_mode = OMAP_DMA_SYNC_FRAME;
392 }
393 }
Peter Ujfalusi15d01432010-07-29 09:51:25 +0300394 }
395
396 dma_data->name = substream->stream ? "Audio Capture" : "Audio Playback";
397 dma_data->dma_req = dma;
398 dma_data->port_addr = port;
399 dma_data->sync_mode = sync_mode;
Peter Ujfalusicf80e152010-07-29 09:51:27 +0300400 dma_data->packet_size = pkt_size;
Daniel Mackfd23b7d2010-03-19 14:52:55 +0000401
Peter Ujfalusi81ec0272010-07-29 09:51:26 +0300402 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200403
404 if (mcbsp_data->configured) {
405 /* McBSP already configured by another stream */
406 return 0;
407 }
408
Peter Ujfalusic29b2062009-04-15 15:38:55 +0300409 format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
410 wpf = channels = params_channels(params);
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200411 if (channels == 2 && (format == SND_SOC_DAIFMT_I2S ||
412 format == SND_SOC_DAIFMT_LEFT_J)) {
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000413 /* Use dual-phase frames */
414 regs->rcr2 |= RPHASE;
415 regs->xcr2 |= XPHASE;
416 /* Set 1 word per (McBSP) frame for phase1 and phase2 */
417 wpf--;
418 regs->rcr2 |= RFRLEN2(wpf - 1);
419 regs->xcr2 |= XFRLEN2(wpf - 1);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200420 }
421
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000422 regs->rcr1 |= RFRLEN1(wpf - 1);
423 regs->xcr1 |= XFRLEN1(wpf - 1);
424
Jarkko Nikula2e747962008-04-25 13:55:19 +0200425 switch (params_format(params)) {
426 case SNDRV_PCM_FORMAT_S16_LE:
427 /* Set word lengths */
428 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
429 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
430 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
431 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200432 break;
Sergey Lapind98508a2010-05-13 19:48:16 +0400433 case SNDRV_PCM_FORMAT_S32_LE:
434 /* Set word lengths */
Sergey Lapind98508a2010-05-13 19:48:16 +0400435 regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_32);
436 regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_32);
437 regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_32);
438 regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_32);
439 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200440 default:
441 /* Unsupported PCM format */
442 return -EINVAL;
443 }
444
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000445 /* In McBSP master modes, FRAME (i.e. sample rate) is generated
446 * by _counting_ BCLKs. Calculate frame size in BCLKs */
447 master = mcbsp_data->fmt & SND_SOC_DAIFMT_MASTER_MASK;
448 if (master == SND_SOC_DAIFMT_CBS_CFS) {
449 div = mcbsp_data->clk_div ? mcbsp_data->clk_div : 1;
450 framesize = (mcbsp_data->in_freq / div) / params_rate(params);
451
452 if (framesize < wlen * channels) {
453 printk(KERN_ERR "%s: not enough bandwidth for desired rate and "
454 "channels\n", __func__);
455 return -EINVAL;
456 }
457 } else
458 framesize = wlen * channels;
459
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300460 /* Set FS period and length in terms of bit clock periods */
Peter Ujfalusic29b2062009-04-15 15:38:55 +0300461 switch (format) {
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300462 case SND_SOC_DAIFMT_I2S:
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200463 case SND_SOC_DAIFMT_LEFT_J:
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000464 regs->srgr2 |= FPER(framesize - 1);
465 regs->srgr1 |= FWID((framesize >> 1) - 1);
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300466 break;
Peter Ujfalusi3ba191c2009-04-15 15:38:56 +0300467 case SND_SOC_DAIFMT_DSP_A:
Jarkko Nikulabd258672008-12-22 10:21:36 +0200468 case SND_SOC_DAIFMT_DSP_B:
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000469 regs->srgr2 |= FPER(framesize - 1);
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300470 regs->srgr1 |= FWID(0);
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300471 break;
472 }
473
Jarkko Nikula2e747962008-04-25 13:55:19 +0200474 omap_mcbsp_config(bus_id, &mcbsp_data->regs);
Peter Ujfalusi3f024032010-06-03 07:39:35 +0300475 mcbsp_data->wlen = wlen;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200476 mcbsp_data->configured = 1;
477
478 return 0;
479}
480
481/*
482 * This must be called before _set_clkdiv and _set_sysclk since McBSP register
483 * cache is initialized here
484 */
Liam Girdwood8687eb82008-07-07 16:08:07 +0100485static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200486 unsigned int fmt)
487{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000488 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200489 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300490 unsigned int temp_fmt = fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200491
492 if (mcbsp_data->configured)
493 return 0;
494
Jarkko Nikulaba9d0fd2008-10-20 15:29:59 +0300495 mcbsp_data->fmt = fmt;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200496 memset(regs, 0, sizeof(*regs));
497 /* Generic McBSP register settings */
498 regs->spcr2 |= XINTM(3) | FREE;
499 regs->spcr1 |= RINTM(3);
Eero Nurkkalac721bbd2009-08-20 16:18:23 +0300500 /* RFIG and XFIG are not defined in 34xx */
501 if (!cpu_is_omap34xx()) {
502 regs->rcr2 |= RFIG;
503 regs->xcr2 |= XFIG;
504 }
Misael Lopez Cruzef390c02009-01-29 13:29:46 +0200505 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
Jarkko Nikula32080af2009-08-23 12:24:26 +0300506 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE;
507 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE;
Misael Lopez Cruzef390c02009-01-29 13:29:46 +0200508 }
Jarkko Nikula2e747962008-04-25 13:55:19 +0200509
510 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
511 case SND_SOC_DAIFMT_I2S:
512 /* 1-bit data delay */
513 regs->rcr2 |= RDATDLY(1);
514 regs->xcr2 |= XDATDLY(1);
515 break;
Peter Ujfalusi299a1512010-03-19 12:27:31 +0200516 case SND_SOC_DAIFMT_LEFT_J:
517 /* 0-bit data delay */
518 regs->rcr2 |= RDATDLY(0);
519 regs->xcr2 |= XDATDLY(0);
520 regs->spcr1 |= RJUST(2);
521 /* Invert FS polarity configuration */
522 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
523 break;
Peter Ujfalusi3ba191c2009-04-15 15:38:56 +0300524 case SND_SOC_DAIFMT_DSP_A:
525 /* 1-bit data delay */
526 regs->rcr2 |= RDATDLY(1);
527 regs->xcr2 |= XDATDLY(1);
528 /* Invert FS polarity configuration */
529 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
530 break;
Jarkko Nikulabd258672008-12-22 10:21:36 +0200531 case SND_SOC_DAIFMT_DSP_B:
Arun KS3336c5b2008-10-02 15:07:06 +0530532 /* 0-bit data delay */
533 regs->rcr2 |= RDATDLY(0);
534 regs->xcr2 |= XDATDLY(0);
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300535 /* Invert FS polarity configuration */
536 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
Arun KS3336c5b2008-10-02 15:07:06 +0530537 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200538 default:
539 /* Unsupported data format */
540 return -EINVAL;
541 }
542
543 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
544 case SND_SOC_DAIFMT_CBS_CFS:
545 /* McBSP master. Set FS and bit clocks as outputs */
546 regs->pcr0 |= FSXM | FSRM |
547 CLKXM | CLKRM;
548 /* Sample rate generator drives the FS */
549 regs->srgr2 |= FSGM;
550 break;
551 case SND_SOC_DAIFMT_CBM_CFM:
552 /* McBSP slave */
553 break;
554 default:
555 /* Unsupported master/slave configuration */
556 return -EINVAL;
557 }
558
559 /* Set bit clock (CLKX/CLKR) and FS polarities */
Jarkko Nikula36ce8582009-04-15 13:48:16 +0300560 switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
Jarkko Nikula2e747962008-04-25 13:55:19 +0200561 case SND_SOC_DAIFMT_NB_NF:
562 /*
563 * Normal BCLK + FS.
564 * FS active low. TX data driven on falling edge of bit clock
565 * and RX data sampled on rising edge of bit clock.
566 */
567 regs->pcr0 |= FSXP | FSRP |
568 CLKXP | CLKRP;
569 break;
570 case SND_SOC_DAIFMT_NB_IF:
571 regs->pcr0 |= CLKXP | CLKRP;
572 break;
573 case SND_SOC_DAIFMT_IB_NF:
574 regs->pcr0 |= FSXP | FSRP;
575 break;
576 case SND_SOC_DAIFMT_IB_IF:
577 break;
578 default:
579 return -EINVAL;
580 }
581
582 return 0;
583}
584
Liam Girdwood8687eb82008-07-07 16:08:07 +0100585static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200586 int div_id, int div)
587{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000588 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200589 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
590
591 if (div_id != OMAP_MCBSP_CLKGDV)
592 return -ENODEV;
593
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000594 mcbsp_data->clk_div = div;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200595 regs->srgr1 |= CLKGDV(div - 1);
596
597 return 0;
598}
599
Liam Girdwood8687eb82008-07-07 16:08:07 +0100600static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200601 int clk_id, unsigned int freq,
602 int dir)
603{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000604 struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200605 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
606 int err = 0;
607
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600608 /* The McBSP signal muxing functions are only available on McBSP1 */
609 if (clk_id == OMAP_MCBSP_CLKR_SRC_CLKR ||
610 clk_id == OMAP_MCBSP_CLKR_SRC_CLKX ||
611 clk_id == OMAP_MCBSP_FSR_SRC_FSR ||
612 clk_id == OMAP_MCBSP_FSR_SRC_FSX)
613 if (cpu_class_is_omap1() || mcbsp_data->bus_id != 0)
614 return -EINVAL;
615
Graeme Gregory5f63ef92009-11-09 19:02:15 +0000616 mcbsp_data->in_freq = freq;
617
Jarkko Nikula2e747962008-04-25 13:55:19 +0200618 switch (clk_id) {
619 case OMAP_MCBSP_SYSCLK_CLK:
620 regs->srgr2 |= CLKSM;
621 break;
622 case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
Paul Walmsleyd1358652010-10-08 11:40:19 -0600623 if (cpu_class_is_omap1()) {
624 err = -EINVAL;
625 break;
626 }
627 err = omap2_mcbsp_set_clks_src(mcbsp_data->bus_id,
628 MCBSP_CLKS_PRCM_SRC);
629 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200630 case OMAP_MCBSP_SYSCLK_CLKS_EXT:
Paul Walmsleyd1358652010-10-08 11:40:19 -0600631 if (cpu_class_is_omap1()) {
632 err = 0;
633 break;
634 }
635 err = omap2_mcbsp_set_clks_src(mcbsp_data->bus_id,
636 MCBSP_CLKS_PAD_SRC);
Jarkko Nikula2e747962008-04-25 13:55:19 +0200637 break;
638
639 case OMAP_MCBSP_SYSCLK_CLKX_EXT:
640 regs->srgr2 |= CLKSM;
641 case OMAP_MCBSP_SYSCLK_CLKR_EXT:
642 regs->pcr0 |= SCLKME;
643 break;
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300644
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600645
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300646 case OMAP_MCBSP_CLKR_SRC_CLKR:
Janusz Krzysztofik23353852010-11-02 15:50:32 +0100647 if (cpu_class_is_omap1())
648 break;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600649 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKR);
650 break;
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300651 case OMAP_MCBSP_CLKR_SRC_CLKX:
Janusz Krzysztofik23353852010-11-02 15:50:32 +0100652 if (cpu_class_is_omap1())
653 break;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600654 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKX);
655 break;
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300656 case OMAP_MCBSP_FSR_SRC_FSR:
Janusz Krzysztofik23353852010-11-02 15:50:32 +0100657 if (cpu_class_is_omap1())
658 break;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600659 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSR);
660 break;
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300661 case OMAP_MCBSP_FSR_SRC_FSX:
Janusz Krzysztofik23353852010-11-02 15:50:32 +0100662 if (cpu_class_is_omap1())
663 break;
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600664 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSX);
Jarkko Nikulad2c0bda2009-08-28 15:35:35 +0300665 break;
Jarkko Nikula2e747962008-04-25 13:55:19 +0200666 default:
667 err = -ENODEV;
668 }
669
670 return err;
671}
672
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000673static struct snd_soc_dai_ops mcbsp_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800674 .startup = omap_mcbsp_dai_startup,
675 .shutdown = omap_mcbsp_dai_shutdown,
676 .trigger = omap_mcbsp_dai_trigger,
Peter Ujfalusi75581d22010-03-03 15:08:09 +0200677 .delay = omap_mcbsp_dai_delay,
Eric Miao6335d052009-03-03 09:41:00 +0800678 .hw_params = omap_mcbsp_dai_hw_params,
679 .set_fmt = omap_mcbsp_dai_set_dai_fmt,
680 .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
681 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
682};
683
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000684static int mcbsp_dai_probe(struct snd_soc_dai *dai)
685{
686 mcbsp_data[dai->id].bus_id = dai->id;
687 snd_soc_dai_set_drvdata(dai, &mcbsp_data[dai->id].bus_id);
688 return 0;
Jarkko Nikula8def4642008-10-09 15:57:22 +0300689}
690
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000691static struct snd_soc_dai_driver omap_mcbsp_dai =
692{
693 .probe = mcbsp_dai_probe,
694 .playback = {
695 .channels_min = 1,
696 .channels_max = 16,
697 .rates = OMAP_MCBSP_RATES,
698 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
699 },
700 .capture = {
701 .channels_min = 1,
702 .channels_max = 16,
703 .rates = OMAP_MCBSP_RATES,
704 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
705 },
706 .ops = &mcbsp_dai_ops,
Jarkko Nikula2e747962008-04-25 13:55:19 +0200707};
Jarkko Nikula8def4642008-10-09 15:57:22 +0300708
G, Manjunath Kondaiah34844572010-09-08 08:53:43 +0530709static int omap_mcbsp_st_info_volsw(struct snd_kcontrol *kcontrol,
Ilkka Koskinen83905c12010-02-22 12:21:12 +0000710 struct snd_ctl_elem_info *uinfo)
711{
712 struct soc_mixer_control *mc =
713 (struct soc_mixer_control *)kcontrol->private_value;
714 int max = mc->max;
715 int min = mc->min;
716
717 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
718 uinfo->count = 1;
719 uinfo->value.integer.min = min;
720 uinfo->value.integer.max = max;
721 return 0;
722}
723
724#define OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(id, channel) \
725static int \
726omap_mcbsp##id##_set_st_ch##channel##_volume(struct snd_kcontrol *kc, \
727 struct snd_ctl_elem_value *uc) \
728{ \
729 struct soc_mixer_control *mc = \
730 (struct soc_mixer_control *)kc->private_value; \
731 int max = mc->max; \
732 int min = mc->min; \
733 int val = uc->value.integer.value[0]; \
734 \
735 if (val < min || val > max) \
736 return -EINVAL; \
737 \
738 /* OMAP McBSP implementation uses index values 0..4 */ \
739 return omap_st_set_chgain((id)-1, channel, val); \
740}
741
742#define OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(id, channel) \
743static int \
744omap_mcbsp##id##_get_st_ch##channel##_volume(struct snd_kcontrol *kc, \
745 struct snd_ctl_elem_value *uc) \
746{ \
747 s16 chgain; \
748 \
749 if (omap_st_get_chgain((id)-1, channel, &chgain)) \
750 return -EAGAIN; \
751 \
752 uc->value.integer.value[0] = chgain; \
753 return 0; \
754}
755
756OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 0)
757OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 1)
758OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 0)
759OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 1)
760OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 0)
761OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 1)
762OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 0)
763OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 1)
764
765static int omap_mcbsp_st_put_mode(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value *ucontrol)
767{
768 struct soc_mixer_control *mc =
769 (struct soc_mixer_control *)kcontrol->private_value;
770 u8 value = ucontrol->value.integer.value[0];
771
772 if (value == omap_st_is_enabled(mc->reg))
773 return 0;
774
775 if (value)
776 omap_st_enable(mc->reg);
777 else
778 omap_st_disable(mc->reg);
779
780 return 1;
781}
782
783static int omap_mcbsp_st_get_mode(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_value *ucontrol)
785{
786 struct soc_mixer_control *mc =
787 (struct soc_mixer_control *)kcontrol->private_value;
788
789 ucontrol->value.integer.value[0] = omap_st_is_enabled(mc->reg);
790 return 0;
791}
792
793static const struct snd_kcontrol_new omap_mcbsp2_st_controls[] = {
794 SOC_SINGLE_EXT("McBSP2 Sidetone Switch", 1, 0, 1, 0,
795 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
796 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 0 Volume",
797 -32768, 32767,
798 omap_mcbsp2_get_st_ch0_volume,
799 omap_mcbsp2_set_st_ch0_volume),
800 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 1 Volume",
801 -32768, 32767,
802 omap_mcbsp2_get_st_ch1_volume,
803 omap_mcbsp2_set_st_ch1_volume),
804};
805
806static const struct snd_kcontrol_new omap_mcbsp3_st_controls[] = {
807 SOC_SINGLE_EXT("McBSP3 Sidetone Switch", 2, 0, 1, 0,
808 omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode),
809 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 0 Volume",
810 -32768, 32767,
811 omap_mcbsp3_get_st_ch0_volume,
812 omap_mcbsp3_set_st_ch0_volume),
813 OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 1 Volume",
814 -32768, 32767,
815 omap_mcbsp3_get_st_ch1_volume,
816 omap_mcbsp3_set_st_ch1_volume),
817};
818
819int omap_mcbsp_st_add_controls(struct snd_soc_codec *codec, int mcbsp_id)
820{
821 if (!cpu_is_omap34xx())
822 return -ENODEV;
823
824 switch (mcbsp_id) {
825 case 1: /* McBSP 2 */
826 return snd_soc_add_controls(codec, omap_mcbsp2_st_controls,
827 ARRAY_SIZE(omap_mcbsp2_st_controls));
828 case 2: /* McBSP 3 */
829 return snd_soc_add_controls(codec, omap_mcbsp3_st_controls,
830 ARRAY_SIZE(omap_mcbsp3_st_controls));
831 default:
832 break;
833 }
834
835 return -EINVAL;
836}
837EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls);
838
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000839static __devinit int asoc_mcbsp_probe(struct platform_device *pdev)
840{
841 return snd_soc_register_dai(&pdev->dev, &omap_mcbsp_dai);
842}
843
844static int __devexit asoc_mcbsp_remove(struct platform_device *pdev)
845{
846 snd_soc_unregister_dai(&pdev->dev);
847 return 0;
848}
849
850static struct platform_driver asoc_mcbsp_driver = {
851 .driver = {
852 .name = "omap-mcbsp-dai",
853 .owner = THIS_MODULE,
854 },
855
856 .probe = asoc_mcbsp_probe,
857 .remove = __devexit_p(asoc_mcbsp_remove),
858};
859
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100860static int __init snd_omap_mcbsp_init(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000861{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000862 return platform_driver_register(&asoc_mcbsp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000863}
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100864module_init(snd_omap_mcbsp_init);
Mark Brown3f4b7832008-12-03 19:26:35 +0000865
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100866static void __exit snd_omap_mcbsp_exit(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000867{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000868 platform_driver_unregister(&asoc_mcbsp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000869}
Takashi Iwaif73f2a62008-12-10 07:59:33 +0100870module_exit(snd_omap_mcbsp_exit);
Mark Brown3f4b7832008-12-03 19:26:35 +0000871
Jarkko Nikulab08f7a62009-04-17 14:42:26 +0300872MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
Jarkko Nikula2e747962008-04-25 13:55:19 +0200873MODULE_DESCRIPTION("OMAP I2S SoC Interface");
874MODULE_LICENSE("GPL");