xref: /openbmc/linux/sound/soc/soc-core.c (revision db2a416556af0313db028147e4a22fef6f214f2f)
1*db2a4165SFrank Mandarino /*
2*db2a4165SFrank Mandarino  * soc-core.c  --  ALSA SoC Audio Layer
3*db2a4165SFrank Mandarino  *
4*db2a4165SFrank Mandarino  * Copyright 2005 Wolfson Microelectronics PLC.
5*db2a4165SFrank Mandarino  * Author: Liam Girdwood
6*db2a4165SFrank Mandarino  *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7*db2a4165SFrank Mandarino  *
8*db2a4165SFrank Mandarino  *  This program is free software; you can redistribute  it and/or modify it
9*db2a4165SFrank Mandarino  *  under  the terms of  the GNU General  Public License as published by the
10*db2a4165SFrank Mandarino  *  Free Software Foundation;  either version 2 of the  License, or (at your
11*db2a4165SFrank Mandarino  *  option) any later version.
12*db2a4165SFrank Mandarino  *
13*db2a4165SFrank Mandarino  *  Revision history
14*db2a4165SFrank Mandarino  *    12th Aug 2005   Initial version.
15*db2a4165SFrank Mandarino  *    25th Oct 2005   Working Codec, Interface and Platform registration.
16*db2a4165SFrank Mandarino  *
17*db2a4165SFrank Mandarino  *  TODO:
18*db2a4165SFrank Mandarino  *   o Add hw rules to enforce rates, etc.
19*db2a4165SFrank Mandarino  *   o More testing with other codecs/machines.
20*db2a4165SFrank Mandarino  *   o Add more codecs and platforms to ensure good API coverage.
21*db2a4165SFrank Mandarino  *   o Support TDM on PCM and I2S
22*db2a4165SFrank Mandarino  */
23*db2a4165SFrank Mandarino 
24*db2a4165SFrank Mandarino #include <linux/module.h>
25*db2a4165SFrank Mandarino #include <linux/moduleparam.h>
26*db2a4165SFrank Mandarino #include <linux/init.h>
27*db2a4165SFrank Mandarino #include <linux/delay.h>
28*db2a4165SFrank Mandarino #include <linux/pm.h>
29*db2a4165SFrank Mandarino #include <linux/bitops.h>
30*db2a4165SFrank Mandarino #include <linux/platform_device.h>
31*db2a4165SFrank Mandarino #include <sound/driver.h>
32*db2a4165SFrank Mandarino #include <sound/core.h>
33*db2a4165SFrank Mandarino #include <sound/pcm.h>
34*db2a4165SFrank Mandarino #include <sound/pcm_params.h>
35*db2a4165SFrank Mandarino #include <sound/soc.h>
36*db2a4165SFrank Mandarino #include <sound/soc-dapm.h>
37*db2a4165SFrank Mandarino #include <sound/initval.h>
38*db2a4165SFrank Mandarino 
39*db2a4165SFrank Mandarino /* debug */
40*db2a4165SFrank Mandarino #define SOC_DEBUG 0
41*db2a4165SFrank Mandarino #if SOC_DEBUG
42*db2a4165SFrank Mandarino #define dbg(format, arg...) printk(format, ## arg)
43*db2a4165SFrank Mandarino #else
44*db2a4165SFrank Mandarino #define dbg(format, arg...)
45*db2a4165SFrank Mandarino #endif
46*db2a4165SFrank Mandarino /* debug DAI capabilities matching */
47*db2a4165SFrank Mandarino #define SOC_DEBUG_DAI 0
48*db2a4165SFrank Mandarino #if SOC_DEBUG_DAI
49*db2a4165SFrank Mandarino #define dbgc(format, arg...) printk(format, ## arg)
50*db2a4165SFrank Mandarino #else
51*db2a4165SFrank Mandarino #define dbgc(format, arg...)
52*db2a4165SFrank Mandarino #endif
53*db2a4165SFrank Mandarino 
54*db2a4165SFrank Mandarino static DEFINE_MUTEX(pcm_mutex);
55*db2a4165SFrank Mandarino static DEFINE_MUTEX(io_mutex);
56*db2a4165SFrank Mandarino static struct workqueue_struct *soc_workq;
57*db2a4165SFrank Mandarino static struct work_struct soc_stream_work;
58*db2a4165SFrank Mandarino static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
59*db2a4165SFrank Mandarino 
60*db2a4165SFrank Mandarino /* supported sample rates */
61*db2a4165SFrank Mandarino /* ATTENTION: these values depend on the definition in pcm.h! */
62*db2a4165SFrank Mandarino static const unsigned int rates[] = {
63*db2a4165SFrank Mandarino 	5512, 8000, 11025, 16000, 22050, 32000, 44100,
64*db2a4165SFrank Mandarino 	48000, 64000, 88200, 96000, 176400, 192000
65*db2a4165SFrank Mandarino };
66*db2a4165SFrank Mandarino 
67*db2a4165SFrank Mandarino /*
68*db2a4165SFrank Mandarino  * This is a timeout to do a DAPM powerdown after a stream is closed().
69*db2a4165SFrank Mandarino  * It can be used to eliminate pops between different playback streams, e.g.
70*db2a4165SFrank Mandarino  * between two audio tracks.
71*db2a4165SFrank Mandarino  */
72*db2a4165SFrank Mandarino static int pmdown_time = 5000;
73*db2a4165SFrank Mandarino module_param(pmdown_time, int, 0);
74*db2a4165SFrank Mandarino MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
75*db2a4165SFrank Mandarino 
76*db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS
77*db2a4165SFrank Mandarino /* unregister ac97 codec */
78*db2a4165SFrank Mandarino static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
79*db2a4165SFrank Mandarino {
80*db2a4165SFrank Mandarino 	if (codec->ac97->dev.bus)
81*db2a4165SFrank Mandarino 		device_unregister(&codec->ac97->dev);
82*db2a4165SFrank Mandarino 	return 0;
83*db2a4165SFrank Mandarino }
84*db2a4165SFrank Mandarino 
85*db2a4165SFrank Mandarino /* stop no dev release warning */
86*db2a4165SFrank Mandarino static void soc_ac97_device_release(struct device *dev){}
87*db2a4165SFrank Mandarino 
88*db2a4165SFrank Mandarino /* register ac97 codec to bus */
89*db2a4165SFrank Mandarino static int soc_ac97_dev_register(struct snd_soc_codec *codec)
90*db2a4165SFrank Mandarino {
91*db2a4165SFrank Mandarino 	int err;
92*db2a4165SFrank Mandarino 
93*db2a4165SFrank Mandarino 	codec->ac97->dev.bus = &ac97_bus_type;
94*db2a4165SFrank Mandarino 	codec->ac97->dev.parent = NULL;
95*db2a4165SFrank Mandarino 	codec->ac97->dev.release = soc_ac97_device_release;
96*db2a4165SFrank Mandarino 
97*db2a4165SFrank Mandarino 	snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
98*db2a4165SFrank Mandarino 		 codec->card->number, 0, codec->name);
99*db2a4165SFrank Mandarino 	err = device_register(&codec->ac97->dev);
100*db2a4165SFrank Mandarino 	if (err < 0) {
101*db2a4165SFrank Mandarino 		snd_printk(KERN_ERR "Can't register ac97 bus\n");
102*db2a4165SFrank Mandarino 		codec->ac97->dev.bus = NULL;
103*db2a4165SFrank Mandarino 		return err;
104*db2a4165SFrank Mandarino 	}
105*db2a4165SFrank Mandarino 	return 0;
106*db2a4165SFrank Mandarino }
107*db2a4165SFrank Mandarino #endif
108*db2a4165SFrank Mandarino 
109*db2a4165SFrank Mandarino static inline const char* get_dai_name(int type)
110*db2a4165SFrank Mandarino {
111*db2a4165SFrank Mandarino 	switch(type) {
112*db2a4165SFrank Mandarino 	case SND_SOC_DAI_AC97:
113*db2a4165SFrank Mandarino 		return "AC97";
114*db2a4165SFrank Mandarino 	case SND_SOC_DAI_I2S:
115*db2a4165SFrank Mandarino 		return "I2S";
116*db2a4165SFrank Mandarino 	case SND_SOC_DAI_PCM:
117*db2a4165SFrank Mandarino 		return "PCM";
118*db2a4165SFrank Mandarino 	}
119*db2a4165SFrank Mandarino 	return NULL;
120*db2a4165SFrank Mandarino }
121*db2a4165SFrank Mandarino 
122*db2a4165SFrank Mandarino /* get rate format from rate */
123*db2a4165SFrank Mandarino static inline int soc_get_rate_format(int rate)
124*db2a4165SFrank Mandarino {
125*db2a4165SFrank Mandarino 	int i;
126*db2a4165SFrank Mandarino 
127*db2a4165SFrank Mandarino 	for (i = 0; i < ARRAY_SIZE(rates); i++) {
128*db2a4165SFrank Mandarino 		if (rates[i] == rate)
129*db2a4165SFrank Mandarino 			return 1 << i;
130*db2a4165SFrank Mandarino 	}
131*db2a4165SFrank Mandarino 	return 0;
132*db2a4165SFrank Mandarino }
133*db2a4165SFrank Mandarino 
134*db2a4165SFrank Mandarino /* gets the audio system mclk/sysclk for the given parameters */
135*db2a4165SFrank Mandarino static unsigned inline int soc_get_mclk(struct snd_soc_pcm_runtime *rtd,
136*db2a4165SFrank Mandarino 	struct snd_soc_clock_info *info)
137*db2a4165SFrank Mandarino {
138*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
139*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
140*db2a4165SFrank Mandarino 	int i;
141*db2a4165SFrank Mandarino 
142*db2a4165SFrank Mandarino 	/* find the matching machine config and get it's mclk for the given
143*db2a4165SFrank Mandarino 	 * sample rate and hardware format */
144*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
145*db2a4165SFrank Mandarino 		if (machine->dai_link[i].cpu_dai == rtd->cpu_dai &&
146*db2a4165SFrank Mandarino 			machine->dai_link[i].config_sysclk)
147*db2a4165SFrank Mandarino 			return machine->dai_link[i].config_sysclk(rtd, info);
148*db2a4165SFrank Mandarino 	}
149*db2a4165SFrank Mandarino 	return 0;
150*db2a4165SFrank Mandarino }
151*db2a4165SFrank Mandarino 
152*db2a4165SFrank Mandarino /* changes a bitclk multiplier mask to a divider mask */
153*db2a4165SFrank Mandarino static u16 soc_bfs_mult_to_div(u16 bfs, int rate, unsigned int mclk,
154*db2a4165SFrank Mandarino 	unsigned int pcmfmt, unsigned int chn)
155*db2a4165SFrank Mandarino {
156*db2a4165SFrank Mandarino 	int i, j;
157*db2a4165SFrank Mandarino 	u16 bfs_ = 0;
158*db2a4165SFrank Mandarino 	int size = snd_pcm_format_physical_width(pcmfmt), min = 0;
159*db2a4165SFrank Mandarino 
160*db2a4165SFrank Mandarino 	if (size <= 0)
161*db2a4165SFrank Mandarino 		return 0;
162*db2a4165SFrank Mandarino 
163*db2a4165SFrank Mandarino 	/* the minimum bit clock that has enough bandwidth */
164*db2a4165SFrank Mandarino 	min = size * rate * chn;
165*db2a4165SFrank Mandarino 	dbgc("mult --> div min bclk %d with mclk %d\n", min, mclk);
166*db2a4165SFrank Mandarino 
167*db2a4165SFrank Mandarino 	for (i = 0; i < 16; i++) {
168*db2a4165SFrank Mandarino 		if ((bfs >> i) & 0x1) {
169*db2a4165SFrank Mandarino 			j = rate * SND_SOC_FSB_REAL(1<<i);
170*db2a4165SFrank Mandarino 
171*db2a4165SFrank Mandarino 			if (j >= min) {
172*db2a4165SFrank Mandarino 				bfs_ |= SND_SOC_FSBD(mclk/j);
173*db2a4165SFrank Mandarino 				dbgc("mult --> div support mult %d\n",
174*db2a4165SFrank Mandarino 					SND_SOC_FSB_REAL(1<<i));
175*db2a4165SFrank Mandarino 			}
176*db2a4165SFrank Mandarino 		}
177*db2a4165SFrank Mandarino 	}
178*db2a4165SFrank Mandarino 
179*db2a4165SFrank Mandarino 	return bfs_;
180*db2a4165SFrank Mandarino }
181*db2a4165SFrank Mandarino 
182*db2a4165SFrank Mandarino /* changes a bitclk divider mask to a multiplier mask */
183*db2a4165SFrank Mandarino static u16 soc_bfs_div_to_mult(u16 bfs, int rate, unsigned int mclk,
184*db2a4165SFrank Mandarino 	unsigned int pcmfmt, unsigned int chn)
185*db2a4165SFrank Mandarino {
186*db2a4165SFrank Mandarino 	int i, j;
187*db2a4165SFrank Mandarino 	u16 bfs_ = 0;
188*db2a4165SFrank Mandarino 
189*db2a4165SFrank Mandarino 	int size = snd_pcm_format_physical_width(pcmfmt), min = 0;
190*db2a4165SFrank Mandarino 
191*db2a4165SFrank Mandarino 	if (size <= 0)
192*db2a4165SFrank Mandarino 		return 0;
193*db2a4165SFrank Mandarino 
194*db2a4165SFrank Mandarino 	/* the minimum bit clock that has enough bandwidth */
195*db2a4165SFrank Mandarino 	min = size * rate * chn;
196*db2a4165SFrank Mandarino 	dbgc("div to mult min bclk %d with mclk %d\n", min, mclk);
197*db2a4165SFrank Mandarino 
198*db2a4165SFrank Mandarino 	for (i = 0; i < 16; i++) {
199*db2a4165SFrank Mandarino 		if ((bfs >> i) & 0x1) {
200*db2a4165SFrank Mandarino 			j = mclk / (SND_SOC_FSBD_REAL(1<<i));
201*db2a4165SFrank Mandarino 			if (j >= min) {
202*db2a4165SFrank Mandarino 				bfs_ |= SND_SOC_FSB(j/rate);
203*db2a4165SFrank Mandarino 				dbgc("div --> mult support div %d\n",
204*db2a4165SFrank Mandarino 					SND_SOC_FSBD_REAL(1<<i));
205*db2a4165SFrank Mandarino 			}
206*db2a4165SFrank Mandarino 		}
207*db2a4165SFrank Mandarino 	}
208*db2a4165SFrank Mandarino 
209*db2a4165SFrank Mandarino 	return bfs_;
210*db2a4165SFrank Mandarino }
211*db2a4165SFrank Mandarino 
212*db2a4165SFrank Mandarino /* Matches codec DAI and SoC CPU DAI hardware parameters */
213*db2a4165SFrank Mandarino static int soc_hw_match_params(struct snd_pcm_substream *substream,
214*db2a4165SFrank Mandarino 	struct snd_pcm_hw_params *params)
215*db2a4165SFrank Mandarino {
216*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
217*db2a4165SFrank Mandarino 	struct snd_soc_dai_mode *codec_dai_mode = NULL;
218*db2a4165SFrank Mandarino 	struct snd_soc_dai_mode *cpu_dai_mode = NULL;
219*db2a4165SFrank Mandarino 	struct snd_soc_clock_info clk_info;
220*db2a4165SFrank Mandarino 	unsigned int fs, mclk, codec_bfs, cpu_bfs, rate = params_rate(params),
221*db2a4165SFrank Mandarino 		chn, j, k, cpu_bclk, codec_bclk, pcmrate;
222*db2a4165SFrank Mandarino 	u16 fmt = 0;
223*db2a4165SFrank Mandarino 
224*db2a4165SFrank Mandarino 	dbg("asoc: match version %s\n", SND_SOC_VERSION);
225*db2a4165SFrank Mandarino 	clk_info.rate = rate;
226*db2a4165SFrank Mandarino 	pcmrate = soc_get_rate_format(rate);
227*db2a4165SFrank Mandarino 
228*db2a4165SFrank Mandarino 	/* try and find a match from the codec and cpu DAI capabilities */
229*db2a4165SFrank Mandarino 	for (j = 0; j < rtd->codec_dai->caps.num_modes; j++) {
230*db2a4165SFrank Mandarino 		for (k = 0; k < rtd->cpu_dai->caps.num_modes; k++) {
231*db2a4165SFrank Mandarino 			codec_dai_mode = &rtd->codec_dai->caps.mode[j];
232*db2a4165SFrank Mandarino 			cpu_dai_mode = &rtd->cpu_dai->caps.mode[k];
233*db2a4165SFrank Mandarino 
234*db2a4165SFrank Mandarino 			if (!(codec_dai_mode->pcmrate & cpu_dai_mode->pcmrate &
235*db2a4165SFrank Mandarino 					pcmrate)) {
236*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match rate\n", j, k);
237*db2a4165SFrank Mandarino 				continue;
238*db2a4165SFrank Mandarino 			}
239*db2a4165SFrank Mandarino 
240*db2a4165SFrank Mandarino 			fmt = codec_dai_mode->fmt & cpu_dai_mode->fmt;
241*db2a4165SFrank Mandarino 			if (!(fmt & SND_SOC_DAIFMT_FORMAT_MASK)) {
242*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match format\n", j, k);
243*db2a4165SFrank Mandarino 				continue;
244*db2a4165SFrank Mandarino 			}
245*db2a4165SFrank Mandarino 
246*db2a4165SFrank Mandarino 			if (!(fmt & SND_SOC_DAIFMT_CLOCK_MASK)) {
247*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match clock masters\n",
248*db2a4165SFrank Mandarino 					 j, k);
249*db2a4165SFrank Mandarino 				continue;
250*db2a4165SFrank Mandarino 			}
251*db2a4165SFrank Mandarino 
252*db2a4165SFrank Mandarino 			if (!(fmt & SND_SOC_DAIFMT_INV_MASK)) {
253*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match invert\n", j, k);
254*db2a4165SFrank Mandarino 				continue;
255*db2a4165SFrank Mandarino 			}
256*db2a4165SFrank Mandarino 
257*db2a4165SFrank Mandarino 			if (!(codec_dai_mode->pcmfmt & cpu_dai_mode->pcmfmt)) {
258*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match pcm format\n", j, k);
259*db2a4165SFrank Mandarino 				continue;
260*db2a4165SFrank Mandarino 			}
261*db2a4165SFrank Mandarino 
262*db2a4165SFrank Mandarino 			if (!(codec_dai_mode->pcmdir & cpu_dai_mode->pcmdir)) {
263*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match direction\n", j, k);
264*db2a4165SFrank Mandarino 				continue;
265*db2a4165SFrank Mandarino 			}
266*db2a4165SFrank Mandarino 
267*db2a4165SFrank Mandarino 			/* todo - still need to add tdm selection */
268*db2a4165SFrank Mandarino 			rtd->cpu_dai->dai_runtime.fmt =
269*db2a4165SFrank Mandarino 			rtd->codec_dai->dai_runtime.fmt =
270*db2a4165SFrank Mandarino 				1 << (ffs(fmt & SND_SOC_DAIFMT_FORMAT_MASK) -1) |
271*db2a4165SFrank Mandarino 				1 << (ffs(fmt & SND_SOC_DAIFMT_CLOCK_MASK) - 1) |
272*db2a4165SFrank Mandarino 				1 << (ffs(fmt & SND_SOC_DAIFMT_INV_MASK) - 1);
273*db2a4165SFrank Mandarino 			clk_info.bclk_master =
274*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.fmt & SND_SOC_DAIFMT_CLOCK_MASK;
275*db2a4165SFrank Mandarino 
276*db2a4165SFrank Mandarino 			/* make sure the ratio between rate and master
277*db2a4165SFrank Mandarino 			 * clock is acceptable*/
278*db2a4165SFrank Mandarino 			fs = (cpu_dai_mode->fs & codec_dai_mode->fs);
279*db2a4165SFrank Mandarino 			if (fs == 0) {
280*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match FS\n", j, k);
281*db2a4165SFrank Mandarino 				continue;
282*db2a4165SFrank Mandarino 			}
283*db2a4165SFrank Mandarino 			clk_info.fs = rtd->cpu_dai->dai_runtime.fs =
284*db2a4165SFrank Mandarino 				rtd->codec_dai->dai_runtime.fs = fs;
285*db2a4165SFrank Mandarino 
286*db2a4165SFrank Mandarino 			/* calculate audio system clocking using slowest clocks possible*/
287*db2a4165SFrank Mandarino 			mclk = soc_get_mclk(rtd, &clk_info);
288*db2a4165SFrank Mandarino 			if (mclk == 0) {
289*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] configuration not clockable\n", j, k);
290*db2a4165SFrank Mandarino 				dbgc("asoc: rate %d fs %d master %x\n", rate, fs,
291*db2a4165SFrank Mandarino 					clk_info.bclk_master);
292*db2a4165SFrank Mandarino 				continue;
293*db2a4165SFrank Mandarino 			}
294*db2a4165SFrank Mandarino 
295*db2a4165SFrank Mandarino 			/* calculate word size (per channel) and frame size */
296*db2a4165SFrank Mandarino 			rtd->codec_dai->dai_runtime.pcmfmt =
297*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.pcmfmt =
298*db2a4165SFrank Mandarino 				1 << params_format(params);
299*db2a4165SFrank Mandarino 
300*db2a4165SFrank Mandarino 			chn = params_channels(params);
301*db2a4165SFrank Mandarino 			/* i2s always has left and right */
302*db2a4165SFrank Mandarino 			if (params_channels(params) == 1 &&
303*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.fmt & (SND_SOC_DAIFMT_I2S |
304*db2a4165SFrank Mandarino 					SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_LEFT_J))
305*db2a4165SFrank Mandarino 				chn <<= 1;
306*db2a4165SFrank Mandarino 
307*db2a4165SFrank Mandarino 			/* Calculate bfs - the ratio between bitclock and the sample rate
308*db2a4165SFrank Mandarino 			 * We must take into consideration the dividers and multipliers
309*db2a4165SFrank Mandarino 			 * used in the codec and cpu DAI modes. We always choose the
310*db2a4165SFrank Mandarino 			 * lowest possible clocks to reduce power.
311*db2a4165SFrank Mandarino 			 */
312*db2a4165SFrank Mandarino 			if (codec_dai_mode->flags & cpu_dai_mode->flags &
313*db2a4165SFrank Mandarino 				SND_SOC_DAI_BFS_DIV) {
314*db2a4165SFrank Mandarino 				/* cpu & codec bfs dividers */
315*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.bfs =
316*db2a4165SFrank Mandarino 					rtd->codec_dai->dai_runtime.bfs =
317*db2a4165SFrank Mandarino 					1 << (fls(codec_dai_mode->bfs & cpu_dai_mode->bfs) - 1);
318*db2a4165SFrank Mandarino 			} else if (codec_dai_mode->flags & SND_SOC_DAI_BFS_DIV) {
319*db2a4165SFrank Mandarino 				/* normalise bfs codec divider & cpu mult */
320*db2a4165SFrank Mandarino 				codec_bfs = soc_bfs_div_to_mult(codec_dai_mode->bfs, rate,
321*db2a4165SFrank Mandarino 					mclk, rtd->codec_dai->dai_runtime.pcmfmt, chn);
322*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.bfs =
323*db2a4165SFrank Mandarino 					1 << (ffs(codec_bfs & cpu_dai_mode->bfs) - 1);
324*db2a4165SFrank Mandarino 				cpu_bfs = soc_bfs_mult_to_div(cpu_dai_mode->bfs, rate, mclk,
325*db2a4165SFrank Mandarino 						rtd->codec_dai->dai_runtime.pcmfmt, chn);
326*db2a4165SFrank Mandarino 				rtd->codec_dai->dai_runtime.bfs =
327*db2a4165SFrank Mandarino 					1 << (fls(codec_dai_mode->bfs & cpu_bfs) - 1);
328*db2a4165SFrank Mandarino 			} else if (cpu_dai_mode->flags & SND_SOC_DAI_BFS_DIV) {
329*db2a4165SFrank Mandarino 				/* normalise bfs codec mult & cpu divider */
330*db2a4165SFrank Mandarino 				codec_bfs = soc_bfs_mult_to_div(codec_dai_mode->bfs, rate,
331*db2a4165SFrank Mandarino 					mclk, rtd->codec_dai->dai_runtime.pcmfmt, chn);
332*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.bfs =
333*db2a4165SFrank Mandarino 					1 << (fls(codec_bfs & cpu_dai_mode->bfs) -1);
334*db2a4165SFrank Mandarino 				cpu_bfs = soc_bfs_div_to_mult(cpu_dai_mode->bfs, rate, mclk,
335*db2a4165SFrank Mandarino 						rtd->codec_dai->dai_runtime.pcmfmt, chn);
336*db2a4165SFrank Mandarino 				rtd->codec_dai->dai_runtime.bfs =
337*db2a4165SFrank Mandarino 					1 << (ffs(codec_dai_mode->bfs & cpu_bfs) -1);
338*db2a4165SFrank Mandarino 			} else {
339*db2a4165SFrank Mandarino 				/* codec & cpu bfs rate multipliers */
340*db2a4165SFrank Mandarino 				rtd->cpu_dai->dai_runtime.bfs =
341*db2a4165SFrank Mandarino 					rtd->codec_dai->dai_runtime.bfs =
342*db2a4165SFrank Mandarino 					1 << (ffs(codec_dai_mode->bfs & cpu_dai_mode->bfs) -1);
343*db2a4165SFrank Mandarino 			}
344*db2a4165SFrank Mandarino 
345*db2a4165SFrank Mandarino 			/* make sure the bit clock speed is acceptable */
346*db2a4165SFrank Mandarino 			if (!rtd->cpu_dai->dai_runtime.bfs ||
347*db2a4165SFrank Mandarino 				!rtd->codec_dai->dai_runtime.bfs) {
348*db2a4165SFrank Mandarino 				dbgc("asoc: DAI[%d:%d] failed to match BFS\n", j, k);
349*db2a4165SFrank Mandarino 				dbgc("asoc: cpu_dai %x codec %x\n",
350*db2a4165SFrank Mandarino 					rtd->cpu_dai->dai_runtime.bfs,
351*db2a4165SFrank Mandarino 					rtd->codec_dai->dai_runtime.bfs);
352*db2a4165SFrank Mandarino 				dbgc("asoc: mclk %d hwfmt %x\n", mclk, fmt);
353*db2a4165SFrank Mandarino 				continue;
354*db2a4165SFrank Mandarino 			}
355*db2a4165SFrank Mandarino 
356*db2a4165SFrank Mandarino 			goto found;
357*db2a4165SFrank Mandarino 		}
358*db2a4165SFrank Mandarino 	}
359*db2a4165SFrank Mandarino 	printk(KERN_ERR "asoc: no matching DAI found between codec and CPU\n");
360*db2a4165SFrank Mandarino 	return -EINVAL;
361*db2a4165SFrank Mandarino 
362*db2a4165SFrank Mandarino found:
363*db2a4165SFrank Mandarino 	/* we have matching DAI's, so complete the runtime info */
364*db2a4165SFrank Mandarino 	rtd->codec_dai->dai_runtime.pcmrate =
365*db2a4165SFrank Mandarino 		rtd->cpu_dai->dai_runtime.pcmrate =
366*db2a4165SFrank Mandarino 		soc_get_rate_format(rate);
367*db2a4165SFrank Mandarino 
368*db2a4165SFrank Mandarino 	rtd->codec_dai->dai_runtime.priv = codec_dai_mode->priv;
369*db2a4165SFrank Mandarino 	rtd->cpu_dai->dai_runtime.priv = cpu_dai_mode->priv;
370*db2a4165SFrank Mandarino 	rtd->codec_dai->dai_runtime.flags = codec_dai_mode->flags;
371*db2a4165SFrank Mandarino 	rtd->cpu_dai->dai_runtime.flags = cpu_dai_mode->flags;
372*db2a4165SFrank Mandarino 
373*db2a4165SFrank Mandarino 	/* for debug atm */
374*db2a4165SFrank Mandarino 	dbg("asoc: DAI[%d:%d] Match OK\n", j, k);
375*db2a4165SFrank Mandarino 	if (rtd->codec_dai->dai_runtime.flags == SND_SOC_DAI_BFS_DIV) {
376*db2a4165SFrank Mandarino 		codec_bclk = (rtd->codec_dai->dai_runtime.fs * params_rate(params)) /
377*db2a4165SFrank Mandarino 			SND_SOC_FSBD_REAL(rtd->codec_dai->dai_runtime.bfs);
378*db2a4165SFrank Mandarino 		dbg("asoc: codec fs %d mclk %d bfs div %d bclk %d\n",
379*db2a4165SFrank Mandarino 			rtd->codec_dai->dai_runtime.fs, mclk,
380*db2a4165SFrank Mandarino 			SND_SOC_FSBD_REAL(rtd->codec_dai->dai_runtime.bfs),	codec_bclk);
381*db2a4165SFrank Mandarino 	} else {
382*db2a4165SFrank Mandarino 		codec_bclk = params_rate(params) *
383*db2a4165SFrank Mandarino 			SND_SOC_FSB_REAL(rtd->codec_dai->dai_runtime.bfs);
384*db2a4165SFrank Mandarino 		dbg("asoc: codec fs %d mclk %d bfs mult %d bclk %d\n",
385*db2a4165SFrank Mandarino 			rtd->codec_dai->dai_runtime.fs, mclk,
386*db2a4165SFrank Mandarino 			SND_SOC_FSB_REAL(rtd->codec_dai->dai_runtime.bfs), codec_bclk);
387*db2a4165SFrank Mandarino 	}
388*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->dai_runtime.flags == SND_SOC_DAI_BFS_DIV) {
389*db2a4165SFrank Mandarino 		cpu_bclk = (rtd->cpu_dai->dai_runtime.fs * params_rate(params)) /
390*db2a4165SFrank Mandarino 			SND_SOC_FSBD_REAL(rtd->cpu_dai->dai_runtime.bfs);
391*db2a4165SFrank Mandarino 		dbg("asoc: cpu fs %d mclk %d bfs div %d bclk %d\n",
392*db2a4165SFrank Mandarino 			rtd->cpu_dai->dai_runtime.fs, mclk,
393*db2a4165SFrank Mandarino 			SND_SOC_FSBD_REAL(rtd->cpu_dai->dai_runtime.bfs), cpu_bclk);
394*db2a4165SFrank Mandarino 	} else {
395*db2a4165SFrank Mandarino 		cpu_bclk = params_rate(params) *
396*db2a4165SFrank Mandarino 			SND_SOC_FSB_REAL(rtd->cpu_dai->dai_runtime.bfs);
397*db2a4165SFrank Mandarino 		dbg("asoc: cpu fs %d mclk %d bfs mult %d bclk %d\n",
398*db2a4165SFrank Mandarino 			rtd->cpu_dai->dai_runtime.fs, mclk,
399*db2a4165SFrank Mandarino 			SND_SOC_FSB_REAL(rtd->cpu_dai->dai_runtime.bfs), cpu_bclk);
400*db2a4165SFrank Mandarino 	}
401*db2a4165SFrank Mandarino 
402*db2a4165SFrank Mandarino 	/*
403*db2a4165SFrank Mandarino 	 * Check we have matching bitclocks. If we don't then it means the
404*db2a4165SFrank Mandarino 	 * sysclock returned by either the codec or cpu DAI (selected by the
405*db2a4165SFrank Mandarino 	 * machine sysclock function) is wrong compared with the supported DAI
406*db2a4165SFrank Mandarino 	 * modes for the codec or cpu DAI.
407*db2a4165SFrank Mandarino 	 */
408*db2a4165SFrank Mandarino 	if (cpu_bclk != codec_bclk){
409*db2a4165SFrank Mandarino 		printk(KERN_ERR
410*db2a4165SFrank Mandarino 			"asoc: codec and cpu bitclocks differ, audio may be wrong speed\n"
411*db2a4165SFrank Mandarino 			);
412*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: codec %d != cpu %d\n", codec_bclk, cpu_bclk);
413*db2a4165SFrank Mandarino 	}
414*db2a4165SFrank Mandarino 
415*db2a4165SFrank Mandarino 	switch(rtd->cpu_dai->dai_runtime.fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
416*db2a4165SFrank Mandarino 	case SND_SOC_DAIFMT_CBM_CFM:
417*db2a4165SFrank Mandarino 		dbg("asoc: DAI codec BCLK master, LRC master\n");
418*db2a4165SFrank Mandarino 		break;
419*db2a4165SFrank Mandarino 	case SND_SOC_DAIFMT_CBS_CFM:
420*db2a4165SFrank Mandarino 		dbg("asoc: DAI codec BCLK slave, LRC master\n");
421*db2a4165SFrank Mandarino 		break;
422*db2a4165SFrank Mandarino 	case SND_SOC_DAIFMT_CBM_CFS:
423*db2a4165SFrank Mandarino 		dbg("asoc: DAI codec BCLK master, LRC slave\n");
424*db2a4165SFrank Mandarino 		break;
425*db2a4165SFrank Mandarino 	case SND_SOC_DAIFMT_CBS_CFS:
426*db2a4165SFrank Mandarino 		dbg("asoc: DAI codec BCLK slave, LRC slave\n");
427*db2a4165SFrank Mandarino 		break;
428*db2a4165SFrank Mandarino 	}
429*db2a4165SFrank Mandarino 	dbg("asoc: mode %x, invert %x\n",
430*db2a4165SFrank Mandarino 		rtd->cpu_dai->dai_runtime.fmt & SND_SOC_DAIFMT_FORMAT_MASK,
431*db2a4165SFrank Mandarino 		rtd->cpu_dai->dai_runtime.fmt & SND_SOC_DAIFMT_INV_MASK);
432*db2a4165SFrank Mandarino 	dbg("asoc: audio rate %d chn %d fmt %x\n", params_rate(params),
433*db2a4165SFrank Mandarino 		params_channels(params), params_format(params));
434*db2a4165SFrank Mandarino 
435*db2a4165SFrank Mandarino 	return 0;
436*db2a4165SFrank Mandarino }
437*db2a4165SFrank Mandarino 
438*db2a4165SFrank Mandarino static inline u32 get_rates(struct snd_soc_dai_mode *modes, int nmodes)
439*db2a4165SFrank Mandarino {
440*db2a4165SFrank Mandarino 	int i;
441*db2a4165SFrank Mandarino 	u32 rates = 0;
442*db2a4165SFrank Mandarino 
443*db2a4165SFrank Mandarino 	for(i = 0; i < nmodes; i++)
444*db2a4165SFrank Mandarino 		rates |= modes[i].pcmrate;
445*db2a4165SFrank Mandarino 
446*db2a4165SFrank Mandarino 	return rates;
447*db2a4165SFrank Mandarino }
448*db2a4165SFrank Mandarino 
449*db2a4165SFrank Mandarino static inline u64 get_formats(struct snd_soc_dai_mode *modes, int nmodes)
450*db2a4165SFrank Mandarino {
451*db2a4165SFrank Mandarino 	int i;
452*db2a4165SFrank Mandarino 	u64 formats = 0;
453*db2a4165SFrank Mandarino 
454*db2a4165SFrank Mandarino 	for(i = 0; i < nmodes; i++)
455*db2a4165SFrank Mandarino 		formats |= modes[i].pcmfmt;
456*db2a4165SFrank Mandarino 
457*db2a4165SFrank Mandarino 	return formats;
458*db2a4165SFrank Mandarino }
459*db2a4165SFrank Mandarino 
460*db2a4165SFrank Mandarino /*
461*db2a4165SFrank Mandarino  * Called by ALSA when a PCM substream is opened, the runtime->hw record is
462*db2a4165SFrank Mandarino  * then initialized and any private data can be allocated. This also calls
463*db2a4165SFrank Mandarino  * startup for the cpu DAI, platform, machine and codec DAI.
464*db2a4165SFrank Mandarino  */
465*db2a4165SFrank Mandarino static int soc_pcm_open(struct snd_pcm_substream *substream)
466*db2a4165SFrank Mandarino {
467*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
468*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
469*db2a4165SFrank Mandarino 	struct snd_pcm_runtime *runtime = substream->runtime;
470*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
471*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
472*db2a4165SFrank Mandarino 	struct snd_soc_codec_dai *codec_dai = rtd->codec_dai;
473*db2a4165SFrank Mandarino 	struct snd_soc_cpu_dai *cpu_dai = rtd->cpu_dai;
474*db2a4165SFrank Mandarino 	int ret = 0;
475*db2a4165SFrank Mandarino 
476*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
477*db2a4165SFrank Mandarino 
478*db2a4165SFrank Mandarino 	/* startup the audio subsystem */
479*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.startup) {
480*db2a4165SFrank Mandarino 		ret = rtd->cpu_dai->ops.startup(substream);
481*db2a4165SFrank Mandarino 		if (ret < 0) {
482*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't open interface %s\n",
483*db2a4165SFrank Mandarino 				rtd->cpu_dai->name);
484*db2a4165SFrank Mandarino 			goto out;
485*db2a4165SFrank Mandarino 		}
486*db2a4165SFrank Mandarino 	}
487*db2a4165SFrank Mandarino 
488*db2a4165SFrank Mandarino 	if (platform->pcm_ops->open) {
489*db2a4165SFrank Mandarino 		ret = platform->pcm_ops->open(substream);
490*db2a4165SFrank Mandarino 		if (ret < 0) {
491*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
492*db2a4165SFrank Mandarino 			goto platform_err;
493*db2a4165SFrank Mandarino 		}
494*db2a4165SFrank Mandarino 	}
495*db2a4165SFrank Mandarino 
496*db2a4165SFrank Mandarino 	if (machine->ops && machine->ops->startup) {
497*db2a4165SFrank Mandarino 		ret = machine->ops->startup(substream);
498*db2a4165SFrank Mandarino 		if (ret < 0) {
499*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
500*db2a4165SFrank Mandarino 			goto machine_err;
501*db2a4165SFrank Mandarino 		}
502*db2a4165SFrank Mandarino 	}
503*db2a4165SFrank Mandarino 
504*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.startup) {
505*db2a4165SFrank Mandarino 		ret = rtd->codec_dai->ops.startup(substream);
506*db2a4165SFrank Mandarino 		if (ret < 0) {
507*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't open codec %s\n",
508*db2a4165SFrank Mandarino 				rtd->codec_dai->name);
509*db2a4165SFrank Mandarino 			goto codec_dai_err;
510*db2a4165SFrank Mandarino 		}
511*db2a4165SFrank Mandarino 	}
512*db2a4165SFrank Mandarino 
513*db2a4165SFrank Mandarino 	/* create runtime params from DMA, codec and cpu DAI */
514*db2a4165SFrank Mandarino 	if (runtime->hw.rates)
515*db2a4165SFrank Mandarino 		runtime->hw.rates &=
516*db2a4165SFrank Mandarino 			get_rates(codec_dai->caps.mode, codec_dai->caps.num_modes) &
517*db2a4165SFrank Mandarino 			get_rates(cpu_dai->caps.mode, cpu_dai->caps.num_modes);
518*db2a4165SFrank Mandarino 	else
519*db2a4165SFrank Mandarino 		runtime->hw.rates =
520*db2a4165SFrank Mandarino 			get_rates(codec_dai->caps.mode, codec_dai->caps.num_modes) &
521*db2a4165SFrank Mandarino 			get_rates(cpu_dai->caps.mode, cpu_dai->caps.num_modes);
522*db2a4165SFrank Mandarino 	if (runtime->hw.formats)
523*db2a4165SFrank Mandarino 		runtime->hw.formats &=
524*db2a4165SFrank Mandarino 			get_formats(codec_dai->caps.mode, codec_dai->caps.num_modes) &
525*db2a4165SFrank Mandarino 			get_formats(cpu_dai->caps.mode, cpu_dai->caps.num_modes);
526*db2a4165SFrank Mandarino 	else
527*db2a4165SFrank Mandarino 		runtime->hw.formats =
528*db2a4165SFrank Mandarino 			get_formats(codec_dai->caps.mode, codec_dai->caps.num_modes) &
529*db2a4165SFrank Mandarino 			get_formats(cpu_dai->caps.mode, cpu_dai->caps.num_modes);
530*db2a4165SFrank Mandarino 
531*db2a4165SFrank Mandarino 	/* Check that the codec and cpu DAI's are compatible */
532*db2a4165SFrank Mandarino 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
533*db2a4165SFrank Mandarino 		runtime->hw.rate_min =
534*db2a4165SFrank Mandarino 			max(rtd->codec_dai->playback.rate_min,
535*db2a4165SFrank Mandarino 				rtd->cpu_dai->playback.rate_min);
536*db2a4165SFrank Mandarino 		runtime->hw.rate_max =
537*db2a4165SFrank Mandarino 			min(rtd->codec_dai->playback.rate_max,
538*db2a4165SFrank Mandarino 				rtd->cpu_dai->playback.rate_max);
539*db2a4165SFrank Mandarino 		runtime->hw.channels_min =
540*db2a4165SFrank Mandarino 			max(rtd->codec_dai->playback.channels_min,
541*db2a4165SFrank Mandarino 				rtd->cpu_dai->playback.channels_min);
542*db2a4165SFrank Mandarino 		runtime->hw.channels_max =
543*db2a4165SFrank Mandarino 			min(rtd->codec_dai->playback.channels_max,
544*db2a4165SFrank Mandarino 				rtd->cpu_dai->playback.channels_max);
545*db2a4165SFrank Mandarino 	} else {
546*db2a4165SFrank Mandarino 		runtime->hw.rate_min =
547*db2a4165SFrank Mandarino 			max(rtd->codec_dai->capture.rate_min,
548*db2a4165SFrank Mandarino 				rtd->cpu_dai->capture.rate_min);
549*db2a4165SFrank Mandarino 		runtime->hw.rate_max =
550*db2a4165SFrank Mandarino 			min(rtd->codec_dai->capture.rate_max,
551*db2a4165SFrank Mandarino 				rtd->cpu_dai->capture.rate_max);
552*db2a4165SFrank Mandarino 		runtime->hw.channels_min =
553*db2a4165SFrank Mandarino 			max(rtd->codec_dai->capture.channels_min,
554*db2a4165SFrank Mandarino 				rtd->cpu_dai->capture.channels_min);
555*db2a4165SFrank Mandarino 		runtime->hw.channels_max =
556*db2a4165SFrank Mandarino 			min(rtd->codec_dai->capture.channels_max,
557*db2a4165SFrank Mandarino 				rtd->cpu_dai->capture.channels_max);
558*db2a4165SFrank Mandarino 	}
559*db2a4165SFrank Mandarino 
560*db2a4165SFrank Mandarino 	snd_pcm_limit_hw_rates(runtime);
561*db2a4165SFrank Mandarino 	if (!runtime->hw.rates) {
562*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
563*db2a4165SFrank Mandarino 			rtd->codec_dai->name, rtd->cpu_dai->name);
564*db2a4165SFrank Mandarino 		goto codec_dai_err;
565*db2a4165SFrank Mandarino 	}
566*db2a4165SFrank Mandarino 	if (!runtime->hw.formats) {
567*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
568*db2a4165SFrank Mandarino 			rtd->codec_dai->name, rtd->cpu_dai->name);
569*db2a4165SFrank Mandarino 		goto codec_dai_err;
570*db2a4165SFrank Mandarino 	}
571*db2a4165SFrank Mandarino 	if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
572*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
573*db2a4165SFrank Mandarino 			rtd->codec_dai->name, rtd->cpu_dai->name);
574*db2a4165SFrank Mandarino 		goto codec_dai_err;
575*db2a4165SFrank Mandarino 	}
576*db2a4165SFrank Mandarino 
577*db2a4165SFrank Mandarino 	dbg("asoc: %s <-> %s info:\n", rtd->codec_dai->name, rtd->cpu_dai->name);
578*db2a4165SFrank Mandarino 	dbg("asoc: rate mask 0x%x \nasoc: min ch %d max ch %d\n
579*db2a4165SFrank Mandarino 		asoc: min rate %d max rate %d\n",
580*db2a4165SFrank Mandarino 		runtime->hw.rates, runtime->hw.channels_min,
581*db2a4165SFrank Mandarino 		runtime->hw.channels_max, runtime->hw.rate_min, runtime->hw.rate_max);
582*db2a4165SFrank Mandarino 
583*db2a4165SFrank Mandarino 
584*db2a4165SFrank Mandarino 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
585*db2a4165SFrank Mandarino 		rtd->cpu_dai->playback.active = rtd->codec_dai->playback.active = 1;
586*db2a4165SFrank Mandarino 	else
587*db2a4165SFrank Mandarino 		rtd->cpu_dai->capture.active = rtd->codec_dai->capture.active = 1;
588*db2a4165SFrank Mandarino 	rtd->cpu_dai->active = rtd->codec_dai->active = 1;
589*db2a4165SFrank Mandarino 	rtd->cpu_dai->runtime = runtime;
590*db2a4165SFrank Mandarino 	socdev->codec->active++;
591*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
592*db2a4165SFrank Mandarino 	return 0;
593*db2a4165SFrank Mandarino 
594*db2a4165SFrank Mandarino codec_dai_err:
595*db2a4165SFrank Mandarino 	if (machine->ops && machine->ops->shutdown)
596*db2a4165SFrank Mandarino 		machine->ops->shutdown(substream);
597*db2a4165SFrank Mandarino 
598*db2a4165SFrank Mandarino machine_err:
599*db2a4165SFrank Mandarino 	if (platform->pcm_ops->close)
600*db2a4165SFrank Mandarino 		platform->pcm_ops->close(substream);
601*db2a4165SFrank Mandarino 
602*db2a4165SFrank Mandarino platform_err:
603*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.shutdown)
604*db2a4165SFrank Mandarino 		rtd->cpu_dai->ops.shutdown(substream);
605*db2a4165SFrank Mandarino out:
606*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
607*db2a4165SFrank Mandarino 	return ret;
608*db2a4165SFrank Mandarino }
609*db2a4165SFrank Mandarino 
610*db2a4165SFrank Mandarino /*
611*db2a4165SFrank Mandarino  * Power down the audio subsytem pmdown_time msecs after close is called.
612*db2a4165SFrank Mandarino  * This is to ensure there are no pops or clicks in between any music tracks
613*db2a4165SFrank Mandarino  * due to DAPM power cycling.
614*db2a4165SFrank Mandarino  */
615*db2a4165SFrank Mandarino static void close_delayed_work(void *data)
616*db2a4165SFrank Mandarino {
617*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = data;
618*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
619*db2a4165SFrank Mandarino 	struct snd_soc_codec_dai *codec_dai;
620*db2a4165SFrank Mandarino 	int i;
621*db2a4165SFrank Mandarino 
622*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
623*db2a4165SFrank Mandarino 	for(i = 0; i < codec->num_dai; i++) {
624*db2a4165SFrank Mandarino 		codec_dai = &codec->dai[i];
625*db2a4165SFrank Mandarino 
626*db2a4165SFrank Mandarino 		dbg("pop wq checking: %s status: %s waiting: %s\n",
627*db2a4165SFrank Mandarino 			codec_dai->playback.stream_name,
628*db2a4165SFrank Mandarino 			codec_dai->playback.active ? "active" : "inactive",
629*db2a4165SFrank Mandarino 			codec_dai->pop_wait ? "yes" : "no");
630*db2a4165SFrank Mandarino 
631*db2a4165SFrank Mandarino 		/* are we waiting on this codec DAI stream */
632*db2a4165SFrank Mandarino 		if (codec_dai->pop_wait == 1) {
633*db2a4165SFrank Mandarino 
634*db2a4165SFrank Mandarino 			codec_dai->pop_wait = 0;
635*db2a4165SFrank Mandarino 			snd_soc_dapm_stream_event(codec, codec_dai->playback.stream_name,
636*db2a4165SFrank Mandarino 				SND_SOC_DAPM_STREAM_STOP);
637*db2a4165SFrank Mandarino 
638*db2a4165SFrank Mandarino 			/* power down the codec power domain if no longer active */
639*db2a4165SFrank Mandarino 			if (codec->active == 0) {
640*db2a4165SFrank Mandarino 				dbg("pop wq D3 %s %s\n", codec->name,
641*db2a4165SFrank Mandarino 					codec_dai->playback.stream_name);
642*db2a4165SFrank Mandarino 		 		if (codec->dapm_event)
643*db2a4165SFrank Mandarino 					codec->dapm_event(codec, SNDRV_CTL_POWER_D3hot);
644*db2a4165SFrank Mandarino 			}
645*db2a4165SFrank Mandarino 		}
646*db2a4165SFrank Mandarino 	}
647*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
648*db2a4165SFrank Mandarino }
649*db2a4165SFrank Mandarino 
650*db2a4165SFrank Mandarino /*
651*db2a4165SFrank Mandarino  * Called by ALSA when a PCM substream is closed. Private data can be
652*db2a4165SFrank Mandarino  * freed here. The cpu DAI, codec DAI, machine and platform are also
653*db2a4165SFrank Mandarino  * shutdown.
654*db2a4165SFrank Mandarino  */
655*db2a4165SFrank Mandarino static int soc_codec_close(struct snd_pcm_substream *substream)
656*db2a4165SFrank Mandarino {
657*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
658*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
659*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
660*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
661*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
662*db2a4165SFrank Mandarino 
663*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
664*db2a4165SFrank Mandarino 
665*db2a4165SFrank Mandarino 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
666*db2a4165SFrank Mandarino 		rtd->cpu_dai->playback.active = rtd->codec_dai->playback.active = 0;
667*db2a4165SFrank Mandarino 	else
668*db2a4165SFrank Mandarino 		rtd->cpu_dai->capture.active = rtd->codec_dai->capture.active = 0;
669*db2a4165SFrank Mandarino 
670*db2a4165SFrank Mandarino 	if (rtd->codec_dai->playback.active == 0 &&
671*db2a4165SFrank Mandarino 		rtd->codec_dai->capture.active == 0) {
672*db2a4165SFrank Mandarino 		rtd->cpu_dai->active = rtd->codec_dai->active = 0;
673*db2a4165SFrank Mandarino 	}
674*db2a4165SFrank Mandarino 	codec->active--;
675*db2a4165SFrank Mandarino 
676*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.shutdown)
677*db2a4165SFrank Mandarino 		rtd->cpu_dai->ops.shutdown(substream);
678*db2a4165SFrank Mandarino 
679*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.shutdown)
680*db2a4165SFrank Mandarino 		rtd->codec_dai->ops.shutdown(substream);
681*db2a4165SFrank Mandarino 
682*db2a4165SFrank Mandarino 	if (machine->ops && machine->ops->shutdown)
683*db2a4165SFrank Mandarino 		machine->ops->shutdown(substream);
684*db2a4165SFrank Mandarino 
685*db2a4165SFrank Mandarino 	if (platform->pcm_ops->close)
686*db2a4165SFrank Mandarino 		platform->pcm_ops->close(substream);
687*db2a4165SFrank Mandarino 	rtd->cpu_dai->runtime = NULL;
688*db2a4165SFrank Mandarino 
689*db2a4165SFrank Mandarino 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
690*db2a4165SFrank Mandarino 		/* start delayed pop wq here for playback streams */
691*db2a4165SFrank Mandarino 		rtd->codec_dai->pop_wait = 1;
692*db2a4165SFrank Mandarino 		queue_delayed_work(soc_workq, &soc_stream_work,
693*db2a4165SFrank Mandarino 			msecs_to_jiffies(pmdown_time));
694*db2a4165SFrank Mandarino 	} else {
695*db2a4165SFrank Mandarino 		/* capture streams can be powered down now */
696*db2a4165SFrank Mandarino 		snd_soc_dapm_stream_event(codec, rtd->codec_dai->capture.stream_name,
697*db2a4165SFrank Mandarino 			SND_SOC_DAPM_STREAM_STOP);
698*db2a4165SFrank Mandarino 
699*db2a4165SFrank Mandarino 		if (codec->active == 0 && rtd->codec_dai->pop_wait == 0){
700*db2a4165SFrank Mandarino 			if (codec->dapm_event)
701*db2a4165SFrank Mandarino 				codec->dapm_event(codec, SNDRV_CTL_POWER_D3hot);
702*db2a4165SFrank Mandarino 		}
703*db2a4165SFrank Mandarino 	}
704*db2a4165SFrank Mandarino 
705*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
706*db2a4165SFrank Mandarino 	return 0;
707*db2a4165SFrank Mandarino }
708*db2a4165SFrank Mandarino 
709*db2a4165SFrank Mandarino /*
710*db2a4165SFrank Mandarino  * Called by ALSA when the PCM substream is prepared, can set format, sample
711*db2a4165SFrank Mandarino  * rate, etc.  This function is non atomic and can be called multiple times,
712*db2a4165SFrank Mandarino  * it can refer to the runtime info.
713*db2a4165SFrank Mandarino  */
714*db2a4165SFrank Mandarino static int soc_pcm_prepare(struct snd_pcm_substream *substream)
715*db2a4165SFrank Mandarino {
716*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
717*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
718*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
719*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
720*db2a4165SFrank Mandarino 	int ret = 0;
721*db2a4165SFrank Mandarino 
722*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
723*db2a4165SFrank Mandarino 	if (platform->pcm_ops->prepare) {
724*db2a4165SFrank Mandarino 		ret = platform->pcm_ops->prepare(substream);
725*db2a4165SFrank Mandarino 		if (ret < 0)
726*db2a4165SFrank Mandarino 			goto out;
727*db2a4165SFrank Mandarino 	}
728*db2a4165SFrank Mandarino 
729*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.prepare) {
730*db2a4165SFrank Mandarino 		ret = rtd->codec_dai->ops.prepare(substream);
731*db2a4165SFrank Mandarino 		if (ret < 0)
732*db2a4165SFrank Mandarino 			goto out;
733*db2a4165SFrank Mandarino 	}
734*db2a4165SFrank Mandarino 
735*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.prepare)
736*db2a4165SFrank Mandarino 		ret = rtd->cpu_dai->ops.prepare(substream);
737*db2a4165SFrank Mandarino 
738*db2a4165SFrank Mandarino 	/* we only want to start a DAPM playback stream if we are not waiting
739*db2a4165SFrank Mandarino 	 * on an existing one stopping */
740*db2a4165SFrank Mandarino 	if (rtd->codec_dai->pop_wait) {
741*db2a4165SFrank Mandarino 		/* we are waiting for the delayed work to start */
742*db2a4165SFrank Mandarino 		if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
743*db2a4165SFrank Mandarino 				snd_soc_dapm_stream_event(codec,
744*db2a4165SFrank Mandarino 					rtd->codec_dai->capture.stream_name,
745*db2a4165SFrank Mandarino 					SND_SOC_DAPM_STREAM_START);
746*db2a4165SFrank Mandarino 		else {
747*db2a4165SFrank Mandarino 			rtd->codec_dai->pop_wait = 0;
748*db2a4165SFrank Mandarino 			cancel_delayed_work(&soc_stream_work);
749*db2a4165SFrank Mandarino 			if (rtd->codec_dai->digital_mute)
750*db2a4165SFrank Mandarino 				rtd->codec_dai->digital_mute(codec, rtd->codec_dai, 0);
751*db2a4165SFrank Mandarino 		}
752*db2a4165SFrank Mandarino 	} else {
753*db2a4165SFrank Mandarino 		/* no delayed work - do we need to power up codec */
754*db2a4165SFrank Mandarino 		if (codec->dapm_state != SNDRV_CTL_POWER_D0) {
755*db2a4165SFrank Mandarino 
756*db2a4165SFrank Mandarino 			if (codec->dapm_event)
757*db2a4165SFrank Mandarino 				codec->dapm_event(codec, SNDRV_CTL_POWER_D1);
758*db2a4165SFrank Mandarino 
759*db2a4165SFrank Mandarino 			if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
760*db2a4165SFrank Mandarino 				snd_soc_dapm_stream_event(codec,
761*db2a4165SFrank Mandarino 					rtd->codec_dai->playback.stream_name,
762*db2a4165SFrank Mandarino 					SND_SOC_DAPM_STREAM_START);
763*db2a4165SFrank Mandarino 			else
764*db2a4165SFrank Mandarino 				snd_soc_dapm_stream_event(codec,
765*db2a4165SFrank Mandarino 					rtd->codec_dai->capture.stream_name,
766*db2a4165SFrank Mandarino 					SND_SOC_DAPM_STREAM_START);
767*db2a4165SFrank Mandarino 
768*db2a4165SFrank Mandarino 			if (codec->dapm_event)
769*db2a4165SFrank Mandarino 				codec->dapm_event(codec, SNDRV_CTL_POWER_D0);
770*db2a4165SFrank Mandarino 			if (rtd->codec_dai->digital_mute)
771*db2a4165SFrank Mandarino 				rtd->codec_dai->digital_mute(codec, rtd->codec_dai, 0);
772*db2a4165SFrank Mandarino 
773*db2a4165SFrank Mandarino 		} else {
774*db2a4165SFrank Mandarino 			/* codec already powered - power on widgets */
775*db2a4165SFrank Mandarino 			if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
776*db2a4165SFrank Mandarino 				snd_soc_dapm_stream_event(codec,
777*db2a4165SFrank Mandarino 					rtd->codec_dai->playback.stream_name,
778*db2a4165SFrank Mandarino 					SND_SOC_DAPM_STREAM_START);
779*db2a4165SFrank Mandarino 			else
780*db2a4165SFrank Mandarino 				snd_soc_dapm_stream_event(codec,
781*db2a4165SFrank Mandarino 					rtd->codec_dai->capture.stream_name,
782*db2a4165SFrank Mandarino 					SND_SOC_DAPM_STREAM_START);
783*db2a4165SFrank Mandarino 			if (rtd->codec_dai->digital_mute)
784*db2a4165SFrank Mandarino 				rtd->codec_dai->digital_mute(codec, rtd->codec_dai, 0);
785*db2a4165SFrank Mandarino 		}
786*db2a4165SFrank Mandarino 	}
787*db2a4165SFrank Mandarino 
788*db2a4165SFrank Mandarino out:
789*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
790*db2a4165SFrank Mandarino 	return ret;
791*db2a4165SFrank Mandarino }
792*db2a4165SFrank Mandarino 
793*db2a4165SFrank Mandarino /*
794*db2a4165SFrank Mandarino  * Called by ALSA when the hardware params are set by application. This
795*db2a4165SFrank Mandarino  * function can also be called multiple times and can allocate buffers
796*db2a4165SFrank Mandarino  * (using snd_pcm_lib_* ). It's non-atomic.
797*db2a4165SFrank Mandarino  */
798*db2a4165SFrank Mandarino static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
799*db2a4165SFrank Mandarino 				struct snd_pcm_hw_params *params)
800*db2a4165SFrank Mandarino {
801*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
802*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
803*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
804*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
805*db2a4165SFrank Mandarino 	int ret = 0;
806*db2a4165SFrank Mandarino 
807*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
808*db2a4165SFrank Mandarino 
809*db2a4165SFrank Mandarino 	/* we don't need to match any AC97 params */
810*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->type != SND_SOC_DAI_AC97) {
811*db2a4165SFrank Mandarino 		ret = soc_hw_match_params(substream, params);
812*db2a4165SFrank Mandarino 		if (ret < 0)
813*db2a4165SFrank Mandarino 			goto out;
814*db2a4165SFrank Mandarino 	} else {
815*db2a4165SFrank Mandarino 		struct snd_soc_clock_info clk_info;
816*db2a4165SFrank Mandarino 		clk_info.rate = params_rate(params);
817*db2a4165SFrank Mandarino 		ret = soc_get_mclk(rtd, &clk_info);
818*db2a4165SFrank Mandarino 		if (ret < 0)
819*db2a4165SFrank Mandarino 			goto out;
820*db2a4165SFrank Mandarino 	}
821*db2a4165SFrank Mandarino 
822*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.hw_params) {
823*db2a4165SFrank Mandarino 		ret = rtd->codec_dai->ops.hw_params(substream, params);
824*db2a4165SFrank Mandarino 		if (ret < 0) {
825*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't set codec %s hw params\n",
826*db2a4165SFrank Mandarino 				rtd->codec_dai->name);
827*db2a4165SFrank Mandarino 			goto out;
828*db2a4165SFrank Mandarino 		}
829*db2a4165SFrank Mandarino 	}
830*db2a4165SFrank Mandarino 
831*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.hw_params) {
832*db2a4165SFrank Mandarino 		ret = rtd->cpu_dai->ops.hw_params(substream, params);
833*db2a4165SFrank Mandarino 		if (ret < 0) {
834*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't set interface %s hw params\n",
835*db2a4165SFrank Mandarino 				rtd->cpu_dai->name);
836*db2a4165SFrank Mandarino 			goto interface_err;
837*db2a4165SFrank Mandarino 		}
838*db2a4165SFrank Mandarino 	}
839*db2a4165SFrank Mandarino 
840*db2a4165SFrank Mandarino 	if (platform->pcm_ops->hw_params) {
841*db2a4165SFrank Mandarino 		ret = platform->pcm_ops->hw_params(substream, params);
842*db2a4165SFrank Mandarino 		if (ret < 0) {
843*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't set platform %s hw params\n",
844*db2a4165SFrank Mandarino 				platform->name);
845*db2a4165SFrank Mandarino 			goto platform_err;
846*db2a4165SFrank Mandarino 		}
847*db2a4165SFrank Mandarino 	}
848*db2a4165SFrank Mandarino 
849*db2a4165SFrank Mandarino 	if (machine->ops && machine->ops->hw_params) {
850*db2a4165SFrank Mandarino 		ret = machine->ops->hw_params(substream, params);
851*db2a4165SFrank Mandarino 		if (ret < 0) {
852*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: machine hw_params failed\n");
853*db2a4165SFrank Mandarino 			goto machine_err;
854*db2a4165SFrank Mandarino 		}
855*db2a4165SFrank Mandarino 	}
856*db2a4165SFrank Mandarino 
857*db2a4165SFrank Mandarino out:
858*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
859*db2a4165SFrank Mandarino 	return ret;
860*db2a4165SFrank Mandarino 
861*db2a4165SFrank Mandarino machine_err:
862*db2a4165SFrank Mandarino 	if (platform->pcm_ops->hw_free)
863*db2a4165SFrank Mandarino 		platform->pcm_ops->hw_free(substream);
864*db2a4165SFrank Mandarino 
865*db2a4165SFrank Mandarino platform_err:
866*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.hw_free)
867*db2a4165SFrank Mandarino 		rtd->cpu_dai->ops.hw_free(substream);
868*db2a4165SFrank Mandarino 
869*db2a4165SFrank Mandarino interface_err:
870*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.hw_free)
871*db2a4165SFrank Mandarino 		rtd->codec_dai->ops.hw_free(substream);
872*db2a4165SFrank Mandarino 
873*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
874*db2a4165SFrank Mandarino 	return ret;
875*db2a4165SFrank Mandarino }
876*db2a4165SFrank Mandarino 
877*db2a4165SFrank Mandarino /*
878*db2a4165SFrank Mandarino  * Free's resources allocated by hw_params, can be called multiple times
879*db2a4165SFrank Mandarino  */
880*db2a4165SFrank Mandarino static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
881*db2a4165SFrank Mandarino {
882*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
883*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
884*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
885*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
886*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
887*db2a4165SFrank Mandarino 
888*db2a4165SFrank Mandarino 	mutex_lock(&pcm_mutex);
889*db2a4165SFrank Mandarino 
890*db2a4165SFrank Mandarino 	/* apply codec digital mute */
891*db2a4165SFrank Mandarino 	if (!codec->active && rtd->codec_dai->digital_mute)
892*db2a4165SFrank Mandarino 		rtd->codec_dai->digital_mute(codec, rtd->codec_dai, 1);
893*db2a4165SFrank Mandarino 
894*db2a4165SFrank Mandarino 	/* free any machine hw params */
895*db2a4165SFrank Mandarino 	if (machine->ops && machine->ops->hw_free)
896*db2a4165SFrank Mandarino 		machine->ops->hw_free(substream);
897*db2a4165SFrank Mandarino 
898*db2a4165SFrank Mandarino 	/* free any DMA resources */
899*db2a4165SFrank Mandarino 	if (platform->pcm_ops->hw_free)
900*db2a4165SFrank Mandarino 		platform->pcm_ops->hw_free(substream);
901*db2a4165SFrank Mandarino 
902*db2a4165SFrank Mandarino 	/* now free hw params for the DAI's  */
903*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.hw_free)
904*db2a4165SFrank Mandarino 		rtd->codec_dai->ops.hw_free(substream);
905*db2a4165SFrank Mandarino 
906*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.hw_free)
907*db2a4165SFrank Mandarino 		rtd->cpu_dai->ops.hw_free(substream);
908*db2a4165SFrank Mandarino 
909*db2a4165SFrank Mandarino 	mutex_unlock(&pcm_mutex);
910*db2a4165SFrank Mandarino 	return 0;
911*db2a4165SFrank Mandarino }
912*db2a4165SFrank Mandarino 
913*db2a4165SFrank Mandarino static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
914*db2a4165SFrank Mandarino {
915*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
916*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = rtd->socdev;
917*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
918*db2a4165SFrank Mandarino 	int ret;
919*db2a4165SFrank Mandarino 
920*db2a4165SFrank Mandarino 	if (rtd->codec_dai->ops.trigger) {
921*db2a4165SFrank Mandarino 		ret = rtd->codec_dai->ops.trigger(substream, cmd);
922*db2a4165SFrank Mandarino 		if (ret < 0)
923*db2a4165SFrank Mandarino 			return ret;
924*db2a4165SFrank Mandarino 	}
925*db2a4165SFrank Mandarino 
926*db2a4165SFrank Mandarino 	if (platform->pcm_ops->trigger) {
927*db2a4165SFrank Mandarino 		ret = platform->pcm_ops->trigger(substream, cmd);
928*db2a4165SFrank Mandarino 		if (ret < 0)
929*db2a4165SFrank Mandarino 			return ret;
930*db2a4165SFrank Mandarino 	}
931*db2a4165SFrank Mandarino 
932*db2a4165SFrank Mandarino 	if (rtd->cpu_dai->ops.trigger) {
933*db2a4165SFrank Mandarino 		ret = rtd->cpu_dai->ops.trigger(substream, cmd);
934*db2a4165SFrank Mandarino 		if (ret < 0)
935*db2a4165SFrank Mandarino 			return ret;
936*db2a4165SFrank Mandarino 	}
937*db2a4165SFrank Mandarino 	return 0;
938*db2a4165SFrank Mandarino }
939*db2a4165SFrank Mandarino 
940*db2a4165SFrank Mandarino /* ASoC PCM operations */
941*db2a4165SFrank Mandarino static struct snd_pcm_ops soc_pcm_ops = {
942*db2a4165SFrank Mandarino 	.open		= soc_pcm_open,
943*db2a4165SFrank Mandarino 	.close		= soc_codec_close,
944*db2a4165SFrank Mandarino 	.hw_params	= soc_pcm_hw_params,
945*db2a4165SFrank Mandarino 	.hw_free	= soc_pcm_hw_free,
946*db2a4165SFrank Mandarino 	.prepare	= soc_pcm_prepare,
947*db2a4165SFrank Mandarino 	.trigger	= soc_pcm_trigger,
948*db2a4165SFrank Mandarino };
949*db2a4165SFrank Mandarino 
950*db2a4165SFrank Mandarino #ifdef CONFIG_PM
951*db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */
952*db2a4165SFrank Mandarino static int soc_suspend(struct platform_device *pdev, pm_message_t state)
953*db2a4165SFrank Mandarino {
954*db2a4165SFrank Mandarino  	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
955*db2a4165SFrank Mandarino  	struct snd_soc_machine *machine = socdev->machine;
956*db2a4165SFrank Mandarino  	struct snd_soc_platform *platform = socdev->platform;
957*db2a4165SFrank Mandarino  	struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
958*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
959*db2a4165SFrank Mandarino 	int i;
960*db2a4165SFrank Mandarino 
961*db2a4165SFrank Mandarino 	/* mute any active DAC's */
962*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
963*db2a4165SFrank Mandarino 		struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
964*db2a4165SFrank Mandarino 		if (dai->digital_mute && dai->playback.active)
965*db2a4165SFrank Mandarino 			dai->digital_mute(codec, dai, 1);
966*db2a4165SFrank Mandarino 	}
967*db2a4165SFrank Mandarino 
968*db2a4165SFrank Mandarino 	if (machine->suspend_pre)
969*db2a4165SFrank Mandarino 		machine->suspend_pre(pdev, state);
970*db2a4165SFrank Mandarino 
971*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
972*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai  *cpu_dai = machine->dai_link[i].cpu_dai;
973*db2a4165SFrank Mandarino 		if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
974*db2a4165SFrank Mandarino 			cpu_dai->suspend(pdev, cpu_dai);
975*db2a4165SFrank Mandarino 		if (platform->suspend)
976*db2a4165SFrank Mandarino 			platform->suspend(pdev, cpu_dai);
977*db2a4165SFrank Mandarino 	}
978*db2a4165SFrank Mandarino 
979*db2a4165SFrank Mandarino 	/* close any waiting streams and save state */
980*db2a4165SFrank Mandarino 	flush_workqueue(soc_workq);
981*db2a4165SFrank Mandarino 	codec->suspend_dapm_state = codec->dapm_state;
982*db2a4165SFrank Mandarino 
983*db2a4165SFrank Mandarino 	for(i = 0; i < codec->num_dai; i++) {
984*db2a4165SFrank Mandarino 		char *stream = codec->dai[i].playback.stream_name;
985*db2a4165SFrank Mandarino 		if (stream != NULL)
986*db2a4165SFrank Mandarino 			snd_soc_dapm_stream_event(codec, stream,
987*db2a4165SFrank Mandarino 				SND_SOC_DAPM_STREAM_SUSPEND);
988*db2a4165SFrank Mandarino 		stream = codec->dai[i].capture.stream_name;
989*db2a4165SFrank Mandarino 		if (stream != NULL)
990*db2a4165SFrank Mandarino 			snd_soc_dapm_stream_event(codec, stream,
991*db2a4165SFrank Mandarino 				SND_SOC_DAPM_STREAM_SUSPEND);
992*db2a4165SFrank Mandarino 	}
993*db2a4165SFrank Mandarino 
994*db2a4165SFrank Mandarino 	if (codec_dev->suspend)
995*db2a4165SFrank Mandarino 		codec_dev->suspend(pdev, state);
996*db2a4165SFrank Mandarino 
997*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
998*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
999*db2a4165SFrank Mandarino 		if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
1000*db2a4165SFrank Mandarino 			cpu_dai->suspend(pdev, cpu_dai);
1001*db2a4165SFrank Mandarino 	}
1002*db2a4165SFrank Mandarino 
1003*db2a4165SFrank Mandarino 	if (machine->suspend_post)
1004*db2a4165SFrank Mandarino 		machine->suspend_post(pdev, state);
1005*db2a4165SFrank Mandarino 
1006*db2a4165SFrank Mandarino 	return 0;
1007*db2a4165SFrank Mandarino }
1008*db2a4165SFrank Mandarino 
1009*db2a4165SFrank Mandarino /* powers up audio subsystem after a suspend */
1010*db2a4165SFrank Mandarino static int soc_resume(struct platform_device *pdev)
1011*db2a4165SFrank Mandarino {
1012*db2a4165SFrank Mandarino  	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1013*db2a4165SFrank Mandarino  	struct snd_soc_machine *machine = socdev->machine;
1014*db2a4165SFrank Mandarino  	struct snd_soc_platform *platform = socdev->platform;
1015*db2a4165SFrank Mandarino  	struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1016*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
1017*db2a4165SFrank Mandarino 	int i;
1018*db2a4165SFrank Mandarino 
1019*db2a4165SFrank Mandarino 	if (machine->resume_pre)
1020*db2a4165SFrank Mandarino 		machine->resume_pre(pdev);
1021*db2a4165SFrank Mandarino 
1022*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
1023*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
1024*db2a4165SFrank Mandarino 		if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
1025*db2a4165SFrank Mandarino 			cpu_dai->resume(pdev, cpu_dai);
1026*db2a4165SFrank Mandarino 	}
1027*db2a4165SFrank Mandarino 
1028*db2a4165SFrank Mandarino 	if (codec_dev->resume)
1029*db2a4165SFrank Mandarino 		codec_dev->resume(pdev);
1030*db2a4165SFrank Mandarino 
1031*db2a4165SFrank Mandarino 	for(i = 0; i < codec->num_dai; i++) {
1032*db2a4165SFrank Mandarino 		char* stream = codec->dai[i].playback.stream_name;
1033*db2a4165SFrank Mandarino 		if (stream != NULL)
1034*db2a4165SFrank Mandarino 			snd_soc_dapm_stream_event(codec, stream,
1035*db2a4165SFrank Mandarino 				SND_SOC_DAPM_STREAM_RESUME);
1036*db2a4165SFrank Mandarino 		stream = codec->dai[i].capture.stream_name;
1037*db2a4165SFrank Mandarino 		if (stream != NULL)
1038*db2a4165SFrank Mandarino 			snd_soc_dapm_stream_event(codec, stream,
1039*db2a4165SFrank Mandarino 				SND_SOC_DAPM_STREAM_RESUME);
1040*db2a4165SFrank Mandarino 	}
1041*db2a4165SFrank Mandarino 
1042*db2a4165SFrank Mandarino 	/* unmute any active DAC's */
1043*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
1044*db2a4165SFrank Mandarino 		struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
1045*db2a4165SFrank Mandarino 		if (dai->digital_mute && dai->playback.active)
1046*db2a4165SFrank Mandarino 			dai->digital_mute(codec, dai, 0);
1047*db2a4165SFrank Mandarino 	}
1048*db2a4165SFrank Mandarino 
1049*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
1050*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
1051*db2a4165SFrank Mandarino 		if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
1052*db2a4165SFrank Mandarino 			cpu_dai->resume(pdev, cpu_dai);
1053*db2a4165SFrank Mandarino 		if (platform->resume)
1054*db2a4165SFrank Mandarino 			platform->resume(pdev, cpu_dai);
1055*db2a4165SFrank Mandarino 	}
1056*db2a4165SFrank Mandarino 
1057*db2a4165SFrank Mandarino 	if (machine->resume_post)
1058*db2a4165SFrank Mandarino 		machine->resume_post(pdev);
1059*db2a4165SFrank Mandarino 
1060*db2a4165SFrank Mandarino 	return 0;
1061*db2a4165SFrank Mandarino }
1062*db2a4165SFrank Mandarino 
1063*db2a4165SFrank Mandarino #else
1064*db2a4165SFrank Mandarino #define soc_suspend	NULL
1065*db2a4165SFrank Mandarino #define soc_resume	NULL
1066*db2a4165SFrank Mandarino #endif
1067*db2a4165SFrank Mandarino 
1068*db2a4165SFrank Mandarino /* probes a new socdev */
1069*db2a4165SFrank Mandarino static int soc_probe(struct platform_device *pdev)
1070*db2a4165SFrank Mandarino {
1071*db2a4165SFrank Mandarino 	int ret = 0, i;
1072*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1073*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
1074*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
1075*db2a4165SFrank Mandarino 	struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1076*db2a4165SFrank Mandarino 
1077*db2a4165SFrank Mandarino 	if (machine->probe) {
1078*db2a4165SFrank Mandarino 		ret = machine->probe(pdev);
1079*db2a4165SFrank Mandarino 		if(ret < 0)
1080*db2a4165SFrank Mandarino 			return ret;
1081*db2a4165SFrank Mandarino 	}
1082*db2a4165SFrank Mandarino 
1083*db2a4165SFrank Mandarino 	for (i = 0; i < machine->num_links; i++) {
1084*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
1085*db2a4165SFrank Mandarino 		if (cpu_dai->probe) {
1086*db2a4165SFrank Mandarino 			ret = cpu_dai->probe(pdev);
1087*db2a4165SFrank Mandarino 			if(ret < 0)
1088*db2a4165SFrank Mandarino 				goto cpu_dai_err;
1089*db2a4165SFrank Mandarino 		}
1090*db2a4165SFrank Mandarino 	}
1091*db2a4165SFrank Mandarino 
1092*db2a4165SFrank Mandarino 	if (codec_dev->probe) {
1093*db2a4165SFrank Mandarino 		ret = codec_dev->probe(pdev);
1094*db2a4165SFrank Mandarino 		if(ret < 0)
1095*db2a4165SFrank Mandarino 			goto cpu_dai_err;
1096*db2a4165SFrank Mandarino 	}
1097*db2a4165SFrank Mandarino 
1098*db2a4165SFrank Mandarino 	if (platform->probe) {
1099*db2a4165SFrank Mandarino 		ret = platform->probe(pdev);
1100*db2a4165SFrank Mandarino 		if(ret < 0)
1101*db2a4165SFrank Mandarino 			goto platform_err;
1102*db2a4165SFrank Mandarino 	}
1103*db2a4165SFrank Mandarino 
1104*db2a4165SFrank Mandarino 	/* DAPM stream work */
1105*db2a4165SFrank Mandarino 	soc_workq = create_workqueue("kdapm");
1106*db2a4165SFrank Mandarino 	if (soc_workq == NULL)
1107*db2a4165SFrank Mandarino 		goto work_err;
1108*db2a4165SFrank Mandarino 	INIT_WORK(&soc_stream_work, close_delayed_work, socdev);
1109*db2a4165SFrank Mandarino 	return 0;
1110*db2a4165SFrank Mandarino 
1111*db2a4165SFrank Mandarino work_err:
1112*db2a4165SFrank Mandarino 	if (platform->remove)
1113*db2a4165SFrank Mandarino 		platform->remove(pdev);
1114*db2a4165SFrank Mandarino 
1115*db2a4165SFrank Mandarino platform_err:
1116*db2a4165SFrank Mandarino 	if (codec_dev->remove)
1117*db2a4165SFrank Mandarino 		codec_dev->remove(pdev);
1118*db2a4165SFrank Mandarino 
1119*db2a4165SFrank Mandarino cpu_dai_err:
1120*db2a4165SFrank Mandarino 	for (i--; i > 0; i--) {
1121*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
1122*db2a4165SFrank Mandarino 		if (cpu_dai->remove)
1123*db2a4165SFrank Mandarino 			cpu_dai->remove(pdev);
1124*db2a4165SFrank Mandarino 	}
1125*db2a4165SFrank Mandarino 
1126*db2a4165SFrank Mandarino 	if (machine->remove)
1127*db2a4165SFrank Mandarino 		machine->remove(pdev);
1128*db2a4165SFrank Mandarino 
1129*db2a4165SFrank Mandarino 	return ret;
1130*db2a4165SFrank Mandarino }
1131*db2a4165SFrank Mandarino 
1132*db2a4165SFrank Mandarino /* removes a socdev */
1133*db2a4165SFrank Mandarino static int soc_remove(struct platform_device *pdev)
1134*db2a4165SFrank Mandarino {
1135*db2a4165SFrank Mandarino 	int i;
1136*db2a4165SFrank Mandarino 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1137*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
1138*db2a4165SFrank Mandarino 	struct snd_soc_platform *platform = socdev->platform;
1139*db2a4165SFrank Mandarino 	struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1140*db2a4165SFrank Mandarino 
1141*db2a4165SFrank Mandarino 	if (soc_workq)
1142*db2a4165SFrank Mandarino 		destroy_workqueue(soc_workq);
1143*db2a4165SFrank Mandarino 
1144*db2a4165SFrank Mandarino 	if (platform->remove)
1145*db2a4165SFrank Mandarino 		platform->remove(pdev);
1146*db2a4165SFrank Mandarino 
1147*db2a4165SFrank Mandarino 	if (codec_dev->remove)
1148*db2a4165SFrank Mandarino 		codec_dev->remove(pdev);
1149*db2a4165SFrank Mandarino 
1150*db2a4165SFrank Mandarino 	for (i = 0; i < machine->num_links; i++) {
1151*db2a4165SFrank Mandarino 		struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
1152*db2a4165SFrank Mandarino 		if (cpu_dai->remove)
1153*db2a4165SFrank Mandarino 			cpu_dai->remove(pdev);
1154*db2a4165SFrank Mandarino 	}
1155*db2a4165SFrank Mandarino 
1156*db2a4165SFrank Mandarino 	if (machine->remove)
1157*db2a4165SFrank Mandarino 		machine->remove(pdev);
1158*db2a4165SFrank Mandarino 
1159*db2a4165SFrank Mandarino 	return 0;
1160*db2a4165SFrank Mandarino }
1161*db2a4165SFrank Mandarino 
1162*db2a4165SFrank Mandarino /* ASoC platform driver */
1163*db2a4165SFrank Mandarino static struct platform_driver soc_driver = {
1164*db2a4165SFrank Mandarino 	.driver		= {
1165*db2a4165SFrank Mandarino 		.name		= "soc-audio",
1166*db2a4165SFrank Mandarino 	},
1167*db2a4165SFrank Mandarino 	.probe		= soc_probe,
1168*db2a4165SFrank Mandarino 	.remove		= soc_remove,
1169*db2a4165SFrank Mandarino 	.suspend	= soc_suspend,
1170*db2a4165SFrank Mandarino 	.resume		= soc_resume,
1171*db2a4165SFrank Mandarino };
1172*db2a4165SFrank Mandarino 
1173*db2a4165SFrank Mandarino /* create a new pcm */
1174*db2a4165SFrank Mandarino static int soc_new_pcm(struct snd_soc_device *socdev,
1175*db2a4165SFrank Mandarino 	struct snd_soc_dai_link *dai_link, int num)
1176*db2a4165SFrank Mandarino {
1177*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
1178*db2a4165SFrank Mandarino 	struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
1179*db2a4165SFrank Mandarino 	struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
1180*db2a4165SFrank Mandarino 	struct snd_soc_pcm_runtime *rtd;
1181*db2a4165SFrank Mandarino 	struct snd_pcm *pcm;
1182*db2a4165SFrank Mandarino 	char new_name[64];
1183*db2a4165SFrank Mandarino 	int ret = 0, playback = 0, capture = 0;
1184*db2a4165SFrank Mandarino 
1185*db2a4165SFrank Mandarino 	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
1186*db2a4165SFrank Mandarino 	if (rtd == NULL)
1187*db2a4165SFrank Mandarino 		return -ENOMEM;
1188*db2a4165SFrank Mandarino 	rtd->cpu_dai = cpu_dai;
1189*db2a4165SFrank Mandarino 	rtd->codec_dai = codec_dai;
1190*db2a4165SFrank Mandarino 	rtd->socdev = socdev;
1191*db2a4165SFrank Mandarino 
1192*db2a4165SFrank Mandarino 	/* check client and interface hw capabilities */
1193*db2a4165SFrank Mandarino 	sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
1194*db2a4165SFrank Mandarino 		get_dai_name(cpu_dai->type), num);
1195*db2a4165SFrank Mandarino 
1196*db2a4165SFrank Mandarino 	if (codec_dai->playback.channels_min)
1197*db2a4165SFrank Mandarino 		playback = 1;
1198*db2a4165SFrank Mandarino 	if (codec_dai->capture.channels_min)
1199*db2a4165SFrank Mandarino 		capture = 1;
1200*db2a4165SFrank Mandarino 
1201*db2a4165SFrank Mandarino 	ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
1202*db2a4165SFrank Mandarino 		capture, &pcm);
1203*db2a4165SFrank Mandarino 	if (ret < 0) {
1204*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
1205*db2a4165SFrank Mandarino 		kfree(rtd);
1206*db2a4165SFrank Mandarino 		return ret;
1207*db2a4165SFrank Mandarino 	}
1208*db2a4165SFrank Mandarino 
1209*db2a4165SFrank Mandarino 	pcm->private_data = rtd;
1210*db2a4165SFrank Mandarino 	soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
1211*db2a4165SFrank Mandarino 	soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
1212*db2a4165SFrank Mandarino 	soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
1213*db2a4165SFrank Mandarino 	soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
1214*db2a4165SFrank Mandarino 	soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
1215*db2a4165SFrank Mandarino 	soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
1216*db2a4165SFrank Mandarino 	soc_pcm_ops.page = socdev->platform->pcm_ops->page;
1217*db2a4165SFrank Mandarino 
1218*db2a4165SFrank Mandarino 	if (playback)
1219*db2a4165SFrank Mandarino 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
1220*db2a4165SFrank Mandarino 
1221*db2a4165SFrank Mandarino 	if (capture)
1222*db2a4165SFrank Mandarino 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
1223*db2a4165SFrank Mandarino 
1224*db2a4165SFrank Mandarino 	ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
1225*db2a4165SFrank Mandarino 	if (ret < 0) {
1226*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: platform pcm constructor failed\n");
1227*db2a4165SFrank Mandarino 		kfree(rtd);
1228*db2a4165SFrank Mandarino 		return ret;
1229*db2a4165SFrank Mandarino 	}
1230*db2a4165SFrank Mandarino 
1231*db2a4165SFrank Mandarino 	pcm->private_free = socdev->platform->pcm_free;
1232*db2a4165SFrank Mandarino 	printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
1233*db2a4165SFrank Mandarino 		cpu_dai->name);
1234*db2a4165SFrank Mandarino 	return ret;
1235*db2a4165SFrank Mandarino }
1236*db2a4165SFrank Mandarino 
1237*db2a4165SFrank Mandarino /* codec register dump */
1238*db2a4165SFrank Mandarino static ssize_t codec_reg_show(struct device *dev,
1239*db2a4165SFrank Mandarino 	struct device_attribute *attr, char *buf)
1240*db2a4165SFrank Mandarino {
1241*db2a4165SFrank Mandarino 	struct snd_soc_device *devdata = dev_get_drvdata(dev);
1242*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = devdata->codec;
1243*db2a4165SFrank Mandarino 	int i, step = 1, count = 0;
1244*db2a4165SFrank Mandarino 
1245*db2a4165SFrank Mandarino 	if (!codec->reg_cache_size)
1246*db2a4165SFrank Mandarino 		return 0;
1247*db2a4165SFrank Mandarino 
1248*db2a4165SFrank Mandarino 	if (codec->reg_cache_step)
1249*db2a4165SFrank Mandarino 		step = codec->reg_cache_step;
1250*db2a4165SFrank Mandarino 
1251*db2a4165SFrank Mandarino 	count += sprintf(buf, "%s registers\n", codec->name);
1252*db2a4165SFrank Mandarino 	for(i = 0; i < codec->reg_cache_size; i += step)
1253*db2a4165SFrank Mandarino 		count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
1254*db2a4165SFrank Mandarino 
1255*db2a4165SFrank Mandarino 	return count;
1256*db2a4165SFrank Mandarino }
1257*db2a4165SFrank Mandarino static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
1258*db2a4165SFrank Mandarino 
1259*db2a4165SFrank Mandarino /**
1260*db2a4165SFrank Mandarino  * snd_soc_new_ac97_codec - initailise AC97 device
1261*db2a4165SFrank Mandarino  * @codec: audio codec
1262*db2a4165SFrank Mandarino  * @ops: AC97 bus operations
1263*db2a4165SFrank Mandarino  * @num: AC97 codec number
1264*db2a4165SFrank Mandarino  *
1265*db2a4165SFrank Mandarino  * Initialises AC97 codec resources for use by ad-hoc devices only.
1266*db2a4165SFrank Mandarino  */
1267*db2a4165SFrank Mandarino int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1268*db2a4165SFrank Mandarino 	struct snd_ac97_bus_ops *ops, int num)
1269*db2a4165SFrank Mandarino {
1270*db2a4165SFrank Mandarino 	mutex_lock(&codec->mutex);
1271*db2a4165SFrank Mandarino 
1272*db2a4165SFrank Mandarino 	codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1273*db2a4165SFrank Mandarino 	if (codec->ac97 == NULL) {
1274*db2a4165SFrank Mandarino 		mutex_unlock(&codec->mutex);
1275*db2a4165SFrank Mandarino 		return -ENOMEM;
1276*db2a4165SFrank Mandarino 	}
1277*db2a4165SFrank Mandarino 
1278*db2a4165SFrank Mandarino 	codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1279*db2a4165SFrank Mandarino 	if (codec->ac97->bus == NULL) {
1280*db2a4165SFrank Mandarino 		kfree(codec->ac97);
1281*db2a4165SFrank Mandarino 		codec->ac97 = NULL;
1282*db2a4165SFrank Mandarino 		mutex_unlock(&codec->mutex);
1283*db2a4165SFrank Mandarino 		return -ENOMEM;
1284*db2a4165SFrank Mandarino 	}
1285*db2a4165SFrank Mandarino 
1286*db2a4165SFrank Mandarino 	codec->ac97->bus->ops = ops;
1287*db2a4165SFrank Mandarino 	codec->ac97->num = num;
1288*db2a4165SFrank Mandarino 	mutex_unlock(&codec->mutex);
1289*db2a4165SFrank Mandarino 	return 0;
1290*db2a4165SFrank Mandarino }
1291*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1292*db2a4165SFrank Mandarino 
1293*db2a4165SFrank Mandarino /**
1294*db2a4165SFrank Mandarino  * snd_soc_free_ac97_codec - free AC97 codec device
1295*db2a4165SFrank Mandarino  * @codec: audio codec
1296*db2a4165SFrank Mandarino  *
1297*db2a4165SFrank Mandarino  * Frees AC97 codec device resources.
1298*db2a4165SFrank Mandarino  */
1299*db2a4165SFrank Mandarino void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1300*db2a4165SFrank Mandarino {
1301*db2a4165SFrank Mandarino 	mutex_lock(&codec->mutex);
1302*db2a4165SFrank Mandarino 	kfree(codec->ac97->bus);
1303*db2a4165SFrank Mandarino 	kfree(codec->ac97);
1304*db2a4165SFrank Mandarino 	codec->ac97 = NULL;
1305*db2a4165SFrank Mandarino 	mutex_unlock(&codec->mutex);
1306*db2a4165SFrank Mandarino }
1307*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1308*db2a4165SFrank Mandarino 
1309*db2a4165SFrank Mandarino /**
1310*db2a4165SFrank Mandarino  * snd_soc_update_bits - update codec register bits
1311*db2a4165SFrank Mandarino  * @codec: audio codec
1312*db2a4165SFrank Mandarino  * @reg: codec register
1313*db2a4165SFrank Mandarino  * @mask: register mask
1314*db2a4165SFrank Mandarino  * @value: new value
1315*db2a4165SFrank Mandarino  *
1316*db2a4165SFrank Mandarino  * Writes new register value.
1317*db2a4165SFrank Mandarino  *
1318*db2a4165SFrank Mandarino  * Returns 1 for change else 0.
1319*db2a4165SFrank Mandarino  */
1320*db2a4165SFrank Mandarino int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1321*db2a4165SFrank Mandarino 				unsigned short mask, unsigned short value)
1322*db2a4165SFrank Mandarino {
1323*db2a4165SFrank Mandarino 	int change;
1324*db2a4165SFrank Mandarino 	unsigned short old, new;
1325*db2a4165SFrank Mandarino 
1326*db2a4165SFrank Mandarino 	mutex_lock(&io_mutex);
1327*db2a4165SFrank Mandarino 	old = snd_soc_read(codec, reg);
1328*db2a4165SFrank Mandarino 	new = (old & ~mask) | value;
1329*db2a4165SFrank Mandarino 	change = old != new;
1330*db2a4165SFrank Mandarino 	if (change)
1331*db2a4165SFrank Mandarino 		snd_soc_write(codec, reg, new);
1332*db2a4165SFrank Mandarino 
1333*db2a4165SFrank Mandarino 	mutex_unlock(&io_mutex);
1334*db2a4165SFrank Mandarino 	return change;
1335*db2a4165SFrank Mandarino }
1336*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1337*db2a4165SFrank Mandarino 
1338*db2a4165SFrank Mandarino /**
1339*db2a4165SFrank Mandarino  * snd_soc_test_bits - test register for change
1340*db2a4165SFrank Mandarino  * @codec: audio codec
1341*db2a4165SFrank Mandarino  * @reg: codec register
1342*db2a4165SFrank Mandarino  * @mask: register mask
1343*db2a4165SFrank Mandarino  * @value: new value
1344*db2a4165SFrank Mandarino  *
1345*db2a4165SFrank Mandarino  * Tests a register with a new value and checks if the new value is
1346*db2a4165SFrank Mandarino  * different from the old value.
1347*db2a4165SFrank Mandarino  *
1348*db2a4165SFrank Mandarino  * Returns 1 for change else 0.
1349*db2a4165SFrank Mandarino  */
1350*db2a4165SFrank Mandarino int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1351*db2a4165SFrank Mandarino 				unsigned short mask, unsigned short value)
1352*db2a4165SFrank Mandarino {
1353*db2a4165SFrank Mandarino 	int change;
1354*db2a4165SFrank Mandarino 	unsigned short old, new;
1355*db2a4165SFrank Mandarino 
1356*db2a4165SFrank Mandarino 	mutex_lock(&io_mutex);
1357*db2a4165SFrank Mandarino 	old = snd_soc_read(codec, reg);
1358*db2a4165SFrank Mandarino 	new = (old & ~mask) | value;
1359*db2a4165SFrank Mandarino 	change = old != new;
1360*db2a4165SFrank Mandarino 	mutex_unlock(&io_mutex);
1361*db2a4165SFrank Mandarino 
1362*db2a4165SFrank Mandarino 	return change;
1363*db2a4165SFrank Mandarino }
1364*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1365*db2a4165SFrank Mandarino 
1366*db2a4165SFrank Mandarino /**
1367*db2a4165SFrank Mandarino  * snd_soc_get_rate - get int sample rate
1368*db2a4165SFrank Mandarino  * @hwpcmrate: the hardware pcm rate
1369*db2a4165SFrank Mandarino  *
1370*db2a4165SFrank Mandarino  * Returns the audio rate integaer value, else 0.
1371*db2a4165SFrank Mandarino  */
1372*db2a4165SFrank Mandarino int snd_soc_get_rate(int hwpcmrate)
1373*db2a4165SFrank Mandarino {
1374*db2a4165SFrank Mandarino 	int rate = ffs(hwpcmrate) - 1;
1375*db2a4165SFrank Mandarino 
1376*db2a4165SFrank Mandarino 	if (rate > ARRAY_SIZE(rates))
1377*db2a4165SFrank Mandarino 		return 0;
1378*db2a4165SFrank Mandarino 	return rates[rate];
1379*db2a4165SFrank Mandarino }
1380*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_rate);
1381*db2a4165SFrank Mandarino 
1382*db2a4165SFrank Mandarino /**
1383*db2a4165SFrank Mandarino  * snd_soc_new_pcms - create new sound card and pcms
1384*db2a4165SFrank Mandarino  * @socdev: the SoC audio device
1385*db2a4165SFrank Mandarino  *
1386*db2a4165SFrank Mandarino  * Create a new sound card based upon the codec and interface pcms.
1387*db2a4165SFrank Mandarino  *
1388*db2a4165SFrank Mandarino  * Returns 0 for success, else error.
1389*db2a4165SFrank Mandarino  */
1390*db2a4165SFrank Mandarino int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char * xid)
1391*db2a4165SFrank Mandarino {
1392*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
1393*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
1394*db2a4165SFrank Mandarino 	int ret = 0, i;
1395*db2a4165SFrank Mandarino 
1396*db2a4165SFrank Mandarino 	mutex_lock(&codec->mutex);
1397*db2a4165SFrank Mandarino 
1398*db2a4165SFrank Mandarino 	/* register a sound card */
1399*db2a4165SFrank Mandarino 	codec->card = snd_card_new(idx, xid, codec->owner, 0);
1400*db2a4165SFrank Mandarino 	if (!codec->card) {
1401*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1402*db2a4165SFrank Mandarino 			codec->name);
1403*db2a4165SFrank Mandarino 		mutex_unlock(&codec->mutex);
1404*db2a4165SFrank Mandarino 		return -ENODEV;
1405*db2a4165SFrank Mandarino 	}
1406*db2a4165SFrank Mandarino 
1407*db2a4165SFrank Mandarino 	codec->card->dev = socdev->dev;
1408*db2a4165SFrank Mandarino 	codec->card->private_data = codec;
1409*db2a4165SFrank Mandarino 	strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1410*db2a4165SFrank Mandarino 
1411*db2a4165SFrank Mandarino 	/* create the pcms */
1412*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
1413*db2a4165SFrank Mandarino 		ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1414*db2a4165SFrank Mandarino 		if (ret < 0) {
1415*db2a4165SFrank Mandarino 			printk(KERN_ERR "asoc: can't create pcm %s\n",
1416*db2a4165SFrank Mandarino 				machine->dai_link[i].stream_name);
1417*db2a4165SFrank Mandarino 			mutex_unlock(&codec->mutex);
1418*db2a4165SFrank Mandarino 			return ret;
1419*db2a4165SFrank Mandarino 		}
1420*db2a4165SFrank Mandarino 	}
1421*db2a4165SFrank Mandarino 
1422*db2a4165SFrank Mandarino 	mutex_unlock(&codec->mutex);
1423*db2a4165SFrank Mandarino 	return ret;
1424*db2a4165SFrank Mandarino }
1425*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1426*db2a4165SFrank Mandarino 
1427*db2a4165SFrank Mandarino /**
1428*db2a4165SFrank Mandarino  * snd_soc_register_card - register sound card
1429*db2a4165SFrank Mandarino  * @socdev: the SoC audio device
1430*db2a4165SFrank Mandarino  *
1431*db2a4165SFrank Mandarino  * Register a SoC sound card. Also registers an AC97 device if the
1432*db2a4165SFrank Mandarino  * codec is AC97 for ad hoc devices.
1433*db2a4165SFrank Mandarino  *
1434*db2a4165SFrank Mandarino  * Returns 0 for success, else error.
1435*db2a4165SFrank Mandarino  */
1436*db2a4165SFrank Mandarino int snd_soc_register_card(struct snd_soc_device *socdev)
1437*db2a4165SFrank Mandarino {
1438*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
1439*db2a4165SFrank Mandarino 	struct snd_soc_machine *machine = socdev->machine;
1440*db2a4165SFrank Mandarino 	int ret = 0, i, ac97 = 0;
1441*db2a4165SFrank Mandarino 
1442*db2a4165SFrank Mandarino 	mutex_lock(&codec->mutex);
1443*db2a4165SFrank Mandarino 	for(i = 0; i < machine->num_links; i++) {
1444*db2a4165SFrank Mandarino 		if (socdev->machine->dai_link[i].init)
1445*db2a4165SFrank Mandarino 			socdev->machine->dai_link[i].init(codec);
1446*db2a4165SFrank Mandarino 		if (socdev->machine->dai_link[i].cpu_dai->type == SND_SOC_DAI_AC97)
1447*db2a4165SFrank Mandarino 			ac97 = 1;
1448*db2a4165SFrank Mandarino 	}
1449*db2a4165SFrank Mandarino 	snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1450*db2a4165SFrank Mandarino 		 "%s", machine->name);
1451*db2a4165SFrank Mandarino 	snprintf(codec->card->longname, sizeof(codec->card->longname),
1452*db2a4165SFrank Mandarino 		 "%s (%s)", machine->name, codec->name);
1453*db2a4165SFrank Mandarino 
1454*db2a4165SFrank Mandarino 	ret = snd_card_register(codec->card);
1455*db2a4165SFrank Mandarino 	if (ret < 0) {
1456*db2a4165SFrank Mandarino 		printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
1457*db2a4165SFrank Mandarino 				codec->name);
1458*db2a4165SFrank Mandarino 		mutex_unlock(&codec->mutex);
1459*db2a4165SFrank Mandarino 		return ret;
1460*db2a4165SFrank Mandarino 	}
1461*db2a4165SFrank Mandarino 
1462*db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS
1463*db2a4165SFrank Mandarino 	if (ac97)
1464*db2a4165SFrank Mandarino 		soc_ac97_dev_register(codec);
1465*db2a4165SFrank Mandarino #endif
1466*db2a4165SFrank Mandarino 
1467*db2a4165SFrank Mandarino 	snd_soc_dapm_sys_add(socdev->dev);
1468*db2a4165SFrank Mandarino 	device_create_file(socdev->dev, &dev_attr_codec_reg);
1469*db2a4165SFrank Mandarino 	mutex_unlock(&codec->mutex);
1470*db2a4165SFrank Mandarino 	return ret;
1471*db2a4165SFrank Mandarino }
1472*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_register_card);
1473*db2a4165SFrank Mandarino 
1474*db2a4165SFrank Mandarino /**
1475*db2a4165SFrank Mandarino  * snd_soc_free_pcms - free sound card and pcms
1476*db2a4165SFrank Mandarino  * @socdev: the SoC audio device
1477*db2a4165SFrank Mandarino  *
1478*db2a4165SFrank Mandarino  * Frees sound card and pcms associated with the socdev.
1479*db2a4165SFrank Mandarino  * Also unregister the codec if it is an AC97 device.
1480*db2a4165SFrank Mandarino  */
1481*db2a4165SFrank Mandarino void snd_soc_free_pcms(struct snd_soc_device *socdev)
1482*db2a4165SFrank Mandarino {
1483*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = socdev->codec;
1484*db2a4165SFrank Mandarino 
1485*db2a4165SFrank Mandarino 	mutex_lock(&codec->mutex);
1486*db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS
1487*db2a4165SFrank Mandarino 	if (codec->ac97)
1488*db2a4165SFrank Mandarino 		soc_ac97_dev_unregister(codec);
1489*db2a4165SFrank Mandarino #endif
1490*db2a4165SFrank Mandarino 
1491*db2a4165SFrank Mandarino 	if (codec->card)
1492*db2a4165SFrank Mandarino 		snd_card_free(codec->card);
1493*db2a4165SFrank Mandarino 	device_remove_file(socdev->dev, &dev_attr_codec_reg);
1494*db2a4165SFrank Mandarino 	mutex_unlock(&codec->mutex);
1495*db2a4165SFrank Mandarino }
1496*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1497*db2a4165SFrank Mandarino 
1498*db2a4165SFrank Mandarino /**
1499*db2a4165SFrank Mandarino  * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1500*db2a4165SFrank Mandarino  * @substream: the pcm substream
1501*db2a4165SFrank Mandarino  * @hw: the hardware parameters
1502*db2a4165SFrank Mandarino  *
1503*db2a4165SFrank Mandarino  * Sets the substream runtime hardware parameters.
1504*db2a4165SFrank Mandarino  */
1505*db2a4165SFrank Mandarino int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1506*db2a4165SFrank Mandarino 	const struct snd_pcm_hardware *hw)
1507*db2a4165SFrank Mandarino {
1508*db2a4165SFrank Mandarino 	struct snd_pcm_runtime *runtime = substream->runtime;
1509*db2a4165SFrank Mandarino 	runtime->hw.info = hw->info;
1510*db2a4165SFrank Mandarino 	runtime->hw.formats = hw->formats;
1511*db2a4165SFrank Mandarino 	runtime->hw.period_bytes_min = hw->period_bytes_min;
1512*db2a4165SFrank Mandarino 	runtime->hw.period_bytes_max = hw->period_bytes_max;
1513*db2a4165SFrank Mandarino 	runtime->hw.periods_min = hw->periods_min;
1514*db2a4165SFrank Mandarino 	runtime->hw.periods_max = hw->periods_max;
1515*db2a4165SFrank Mandarino 	runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1516*db2a4165SFrank Mandarino 	runtime->hw.fifo_size = hw->fifo_size;
1517*db2a4165SFrank Mandarino 	return 0;
1518*db2a4165SFrank Mandarino }
1519*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1520*db2a4165SFrank Mandarino 
1521*db2a4165SFrank Mandarino /**
1522*db2a4165SFrank Mandarino  * snd_soc_cnew - create new control
1523*db2a4165SFrank Mandarino  * @_template: control template
1524*db2a4165SFrank Mandarino  * @data: control private data
1525*db2a4165SFrank Mandarino  * @lnng_name: control long name
1526*db2a4165SFrank Mandarino  *
1527*db2a4165SFrank Mandarino  * Create a new mixer control from a template control.
1528*db2a4165SFrank Mandarino  *
1529*db2a4165SFrank Mandarino  * Returns 0 for success, else error.
1530*db2a4165SFrank Mandarino  */
1531*db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1532*db2a4165SFrank Mandarino 	void *data, char *long_name)
1533*db2a4165SFrank Mandarino {
1534*db2a4165SFrank Mandarino 	struct snd_kcontrol_new template;
1535*db2a4165SFrank Mandarino 
1536*db2a4165SFrank Mandarino 	memcpy(&template, _template, sizeof(template));
1537*db2a4165SFrank Mandarino 	if (long_name)
1538*db2a4165SFrank Mandarino 		template.name = long_name;
1539*db2a4165SFrank Mandarino 	template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1540*db2a4165SFrank Mandarino 	template.index = 0;
1541*db2a4165SFrank Mandarino 
1542*db2a4165SFrank Mandarino 	return snd_ctl_new1(&template, data);
1543*db2a4165SFrank Mandarino }
1544*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew);
1545*db2a4165SFrank Mandarino 
1546*db2a4165SFrank Mandarino /**
1547*db2a4165SFrank Mandarino  * snd_soc_info_enum_double - enumerated double mixer info callback
1548*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1549*db2a4165SFrank Mandarino  * @uinfo: control element information
1550*db2a4165SFrank Mandarino  *
1551*db2a4165SFrank Mandarino  * Callback to provide information about a double enumerated
1552*db2a4165SFrank Mandarino  * mixer control.
1553*db2a4165SFrank Mandarino  *
1554*db2a4165SFrank Mandarino  * Returns 0 for success.
1555*db2a4165SFrank Mandarino  */
1556*db2a4165SFrank Mandarino int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1557*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1558*db2a4165SFrank Mandarino {
1559*db2a4165SFrank Mandarino 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1560*db2a4165SFrank Mandarino 
1561*db2a4165SFrank Mandarino 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1562*db2a4165SFrank Mandarino 	uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1563*db2a4165SFrank Mandarino 	uinfo->value.enumerated.items = e->mask;
1564*db2a4165SFrank Mandarino 
1565*db2a4165SFrank Mandarino 	if (uinfo->value.enumerated.item > e->mask - 1)
1566*db2a4165SFrank Mandarino 		uinfo->value.enumerated.item = e->mask - 1;
1567*db2a4165SFrank Mandarino 	strcpy(uinfo->value.enumerated.name,
1568*db2a4165SFrank Mandarino 		e->texts[uinfo->value.enumerated.item]);
1569*db2a4165SFrank Mandarino 	return 0;
1570*db2a4165SFrank Mandarino }
1571*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1572*db2a4165SFrank Mandarino 
1573*db2a4165SFrank Mandarino /**
1574*db2a4165SFrank Mandarino  * snd_soc_get_enum_double - enumerated double mixer get callback
1575*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1576*db2a4165SFrank Mandarino  * @uinfo: control element information
1577*db2a4165SFrank Mandarino  *
1578*db2a4165SFrank Mandarino  * Callback to get the value of a double enumerated mixer.
1579*db2a4165SFrank Mandarino  *
1580*db2a4165SFrank Mandarino  * Returns 0 for success.
1581*db2a4165SFrank Mandarino  */
1582*db2a4165SFrank Mandarino int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1583*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1584*db2a4165SFrank Mandarino {
1585*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1586*db2a4165SFrank Mandarino 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1587*db2a4165SFrank Mandarino 	unsigned short val, bitmask;
1588*db2a4165SFrank Mandarino 
1589*db2a4165SFrank Mandarino 	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1590*db2a4165SFrank Mandarino 		;
1591*db2a4165SFrank Mandarino 	val = snd_soc_read(codec, e->reg);
1592*db2a4165SFrank Mandarino 	ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1593*db2a4165SFrank Mandarino 	if (e->shift_l != e->shift_r)
1594*db2a4165SFrank Mandarino 		ucontrol->value.enumerated.item[1] =
1595*db2a4165SFrank Mandarino 			(val >> e->shift_r) & (bitmask - 1);
1596*db2a4165SFrank Mandarino 
1597*db2a4165SFrank Mandarino 	return 0;
1598*db2a4165SFrank Mandarino }
1599*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1600*db2a4165SFrank Mandarino 
1601*db2a4165SFrank Mandarino /**
1602*db2a4165SFrank Mandarino  * snd_soc_put_enum_double - enumerated double mixer put callback
1603*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1604*db2a4165SFrank Mandarino  * @uinfo: control element information
1605*db2a4165SFrank Mandarino  *
1606*db2a4165SFrank Mandarino  * Callback to set the value of a double enumerated mixer.
1607*db2a4165SFrank Mandarino  *
1608*db2a4165SFrank Mandarino  * Returns 0 for success.
1609*db2a4165SFrank Mandarino  */
1610*db2a4165SFrank Mandarino int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1611*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1612*db2a4165SFrank Mandarino {
1613*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1614*db2a4165SFrank Mandarino 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1615*db2a4165SFrank Mandarino 	unsigned short val;
1616*db2a4165SFrank Mandarino 	unsigned short mask, bitmask;
1617*db2a4165SFrank Mandarino 
1618*db2a4165SFrank Mandarino 	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1619*db2a4165SFrank Mandarino 		;
1620*db2a4165SFrank Mandarino 	if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1621*db2a4165SFrank Mandarino 		return -EINVAL;
1622*db2a4165SFrank Mandarino 	val = ucontrol->value.enumerated.item[0] << e->shift_l;
1623*db2a4165SFrank Mandarino 	mask = (bitmask - 1) << e->shift_l;
1624*db2a4165SFrank Mandarino 	if (e->shift_l != e->shift_r) {
1625*db2a4165SFrank Mandarino 		if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1626*db2a4165SFrank Mandarino 			return -EINVAL;
1627*db2a4165SFrank Mandarino 		val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1628*db2a4165SFrank Mandarino 		mask |= (bitmask - 1) << e->shift_r;
1629*db2a4165SFrank Mandarino 	}
1630*db2a4165SFrank Mandarino 
1631*db2a4165SFrank Mandarino 	return snd_soc_update_bits(codec, e->reg, mask, val);
1632*db2a4165SFrank Mandarino }
1633*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1634*db2a4165SFrank Mandarino 
1635*db2a4165SFrank Mandarino /**
1636*db2a4165SFrank Mandarino  * snd_soc_info_enum_ext - external enumerated single mixer info callback
1637*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1638*db2a4165SFrank Mandarino  * @uinfo: control element information
1639*db2a4165SFrank Mandarino  *
1640*db2a4165SFrank Mandarino  * Callback to provide information about an external enumerated
1641*db2a4165SFrank Mandarino  * single mixer.
1642*db2a4165SFrank Mandarino  *
1643*db2a4165SFrank Mandarino  * Returns 0 for success.
1644*db2a4165SFrank Mandarino  */
1645*db2a4165SFrank Mandarino int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1646*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1647*db2a4165SFrank Mandarino {
1648*db2a4165SFrank Mandarino 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1649*db2a4165SFrank Mandarino 
1650*db2a4165SFrank Mandarino 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1651*db2a4165SFrank Mandarino 	uinfo->count = 1;
1652*db2a4165SFrank Mandarino 	uinfo->value.enumerated.items = e->mask;
1653*db2a4165SFrank Mandarino 
1654*db2a4165SFrank Mandarino 	if (uinfo->value.enumerated.item > e->mask - 1)
1655*db2a4165SFrank Mandarino 		uinfo->value.enumerated.item = e->mask - 1;
1656*db2a4165SFrank Mandarino 	strcpy(uinfo->value.enumerated.name,
1657*db2a4165SFrank Mandarino 		e->texts[uinfo->value.enumerated.item]);
1658*db2a4165SFrank Mandarino 	return 0;
1659*db2a4165SFrank Mandarino }
1660*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1661*db2a4165SFrank Mandarino 
1662*db2a4165SFrank Mandarino /**
1663*db2a4165SFrank Mandarino  * snd_soc_info_volsw_ext - external single mixer info callback
1664*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1665*db2a4165SFrank Mandarino  * @uinfo: control element information
1666*db2a4165SFrank Mandarino  *
1667*db2a4165SFrank Mandarino  * Callback to provide information about a single external mixer control.
1668*db2a4165SFrank Mandarino  *
1669*db2a4165SFrank Mandarino  * Returns 0 for success.
1670*db2a4165SFrank Mandarino  */
1671*db2a4165SFrank Mandarino int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1672*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1673*db2a4165SFrank Mandarino {
1674*db2a4165SFrank Mandarino 	int mask = kcontrol->private_value;
1675*db2a4165SFrank Mandarino 
1676*db2a4165SFrank Mandarino 	uinfo->type =
1677*db2a4165SFrank Mandarino 		mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1678*db2a4165SFrank Mandarino 	uinfo->count = 1;
1679*db2a4165SFrank Mandarino 	uinfo->value.integer.min = 0;
1680*db2a4165SFrank Mandarino 	uinfo->value.integer.max = mask;
1681*db2a4165SFrank Mandarino 	return 0;
1682*db2a4165SFrank Mandarino }
1683*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1684*db2a4165SFrank Mandarino 
1685*db2a4165SFrank Mandarino /**
1686*db2a4165SFrank Mandarino  * snd_soc_info_bool_ext - external single boolean mixer info callback
1687*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1688*db2a4165SFrank Mandarino  * @uinfo: control element information
1689*db2a4165SFrank Mandarino  *
1690*db2a4165SFrank Mandarino  * Callback to provide information about a single boolean external mixer control.
1691*db2a4165SFrank Mandarino  *
1692*db2a4165SFrank Mandarino  * Returns 0 for success.
1693*db2a4165SFrank Mandarino  */
1694*db2a4165SFrank Mandarino int snd_soc_info_bool_ext(struct snd_kcontrol *kcontrol,
1695*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1696*db2a4165SFrank Mandarino {
1697*db2a4165SFrank Mandarino 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1698*db2a4165SFrank Mandarino 	uinfo->count = 1;
1699*db2a4165SFrank Mandarino 	uinfo->value.integer.min = 0;
1700*db2a4165SFrank Mandarino 	uinfo->value.integer.max = 1;
1701*db2a4165SFrank Mandarino 	return 0;
1702*db2a4165SFrank Mandarino }
1703*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_bool_ext);
1704*db2a4165SFrank Mandarino 
1705*db2a4165SFrank Mandarino /**
1706*db2a4165SFrank Mandarino  * snd_soc_info_volsw - single mixer info callback
1707*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1708*db2a4165SFrank Mandarino  * @uinfo: control element information
1709*db2a4165SFrank Mandarino  *
1710*db2a4165SFrank Mandarino  * Callback to provide information about a single mixer control.
1711*db2a4165SFrank Mandarino  *
1712*db2a4165SFrank Mandarino  * Returns 0 for success.
1713*db2a4165SFrank Mandarino  */
1714*db2a4165SFrank Mandarino int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1715*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1716*db2a4165SFrank Mandarino {
1717*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 16) & 0xff;
1718*db2a4165SFrank Mandarino 	int shift = (kcontrol->private_value >> 8) & 0x0f;
1719*db2a4165SFrank Mandarino 	int rshift = (kcontrol->private_value >> 12) & 0x0f;
1720*db2a4165SFrank Mandarino 
1721*db2a4165SFrank Mandarino 	uinfo->type =
1722*db2a4165SFrank Mandarino 		mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1723*db2a4165SFrank Mandarino 	uinfo->count = shift == rshift ? 1 : 2;
1724*db2a4165SFrank Mandarino 	uinfo->value.integer.min = 0;
1725*db2a4165SFrank Mandarino 	uinfo->value.integer.max = mask;
1726*db2a4165SFrank Mandarino 	return 0;
1727*db2a4165SFrank Mandarino }
1728*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1729*db2a4165SFrank Mandarino 
1730*db2a4165SFrank Mandarino /**
1731*db2a4165SFrank Mandarino  * snd_soc_get_volsw - single mixer get callback
1732*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1733*db2a4165SFrank Mandarino  * @uinfo: control element information
1734*db2a4165SFrank Mandarino  *
1735*db2a4165SFrank Mandarino  * Callback to get the value of a single mixer control.
1736*db2a4165SFrank Mandarino  *
1737*db2a4165SFrank Mandarino  * Returns 0 for success.
1738*db2a4165SFrank Mandarino  */
1739*db2a4165SFrank Mandarino int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1740*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1741*db2a4165SFrank Mandarino {
1742*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1743*db2a4165SFrank Mandarino 	int reg = kcontrol->private_value & 0xff;
1744*db2a4165SFrank Mandarino 	int shift = (kcontrol->private_value >> 8) & 0x0f;
1745*db2a4165SFrank Mandarino 	int rshift = (kcontrol->private_value >> 12) & 0x0f;
1746*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 16) & 0xff;
1747*db2a4165SFrank Mandarino 	int invert = (kcontrol->private_value >> 24) & 0x01;
1748*db2a4165SFrank Mandarino 
1749*db2a4165SFrank Mandarino 	ucontrol->value.integer.value[0] =
1750*db2a4165SFrank Mandarino 		(snd_soc_read(codec, reg) >> shift) & mask;
1751*db2a4165SFrank Mandarino 	if (shift != rshift)
1752*db2a4165SFrank Mandarino 		ucontrol->value.integer.value[1] =
1753*db2a4165SFrank Mandarino 			(snd_soc_read(codec, reg) >> rshift) & mask;
1754*db2a4165SFrank Mandarino 	if (invert) {
1755*db2a4165SFrank Mandarino 		ucontrol->value.integer.value[0] =
1756*db2a4165SFrank Mandarino 			mask - ucontrol->value.integer.value[0];
1757*db2a4165SFrank Mandarino 		if (shift != rshift)
1758*db2a4165SFrank Mandarino 			ucontrol->value.integer.value[1] =
1759*db2a4165SFrank Mandarino 				mask - ucontrol->value.integer.value[1];
1760*db2a4165SFrank Mandarino 	}
1761*db2a4165SFrank Mandarino 
1762*db2a4165SFrank Mandarino 	return 0;
1763*db2a4165SFrank Mandarino }
1764*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1765*db2a4165SFrank Mandarino 
1766*db2a4165SFrank Mandarino /**
1767*db2a4165SFrank Mandarino  * snd_soc_put_volsw - single mixer put callback
1768*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1769*db2a4165SFrank Mandarino  * @uinfo: control element information
1770*db2a4165SFrank Mandarino  *
1771*db2a4165SFrank Mandarino  * Callback to set the value of a single mixer control.
1772*db2a4165SFrank Mandarino  *
1773*db2a4165SFrank Mandarino  * Returns 0 for success.
1774*db2a4165SFrank Mandarino  */
1775*db2a4165SFrank Mandarino int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1776*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1777*db2a4165SFrank Mandarino {
1778*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1779*db2a4165SFrank Mandarino 	int reg = kcontrol->private_value & 0xff;
1780*db2a4165SFrank Mandarino 	int shift = (kcontrol->private_value >> 8) & 0x0f;
1781*db2a4165SFrank Mandarino 	int rshift = (kcontrol->private_value >> 12) & 0x0f;
1782*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 16) & 0xff;
1783*db2a4165SFrank Mandarino 	int invert = (kcontrol->private_value >> 24) & 0x01;
1784*db2a4165SFrank Mandarino 	int err;
1785*db2a4165SFrank Mandarino 	unsigned short val, val2, val_mask;
1786*db2a4165SFrank Mandarino 
1787*db2a4165SFrank Mandarino 	val = (ucontrol->value.integer.value[0] & mask);
1788*db2a4165SFrank Mandarino 	if (invert)
1789*db2a4165SFrank Mandarino 		val = mask - val;
1790*db2a4165SFrank Mandarino 	val_mask = mask << shift;
1791*db2a4165SFrank Mandarino 	val = val << shift;
1792*db2a4165SFrank Mandarino 	if (shift != rshift) {
1793*db2a4165SFrank Mandarino 		val2 = (ucontrol->value.integer.value[1] & mask);
1794*db2a4165SFrank Mandarino 		if (invert)
1795*db2a4165SFrank Mandarino 			val2 = mask - val2;
1796*db2a4165SFrank Mandarino 		val_mask |= mask << rshift;
1797*db2a4165SFrank Mandarino 		val |= val2 << rshift;
1798*db2a4165SFrank Mandarino 	}
1799*db2a4165SFrank Mandarino 	err = snd_soc_update_bits(codec, reg, val_mask, val);
1800*db2a4165SFrank Mandarino 	return err;
1801*db2a4165SFrank Mandarino }
1802*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1803*db2a4165SFrank Mandarino 
1804*db2a4165SFrank Mandarino /**
1805*db2a4165SFrank Mandarino  * snd_soc_info_volsw_2r - double mixer info callback
1806*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1807*db2a4165SFrank Mandarino  * @uinfo: control element information
1808*db2a4165SFrank Mandarino  *
1809*db2a4165SFrank Mandarino  * Callback to provide information about a double mixer control that
1810*db2a4165SFrank Mandarino  * spans 2 codec registers.
1811*db2a4165SFrank Mandarino  *
1812*db2a4165SFrank Mandarino  * Returns 0 for success.
1813*db2a4165SFrank Mandarino  */
1814*db2a4165SFrank Mandarino int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1815*db2a4165SFrank Mandarino 	struct snd_ctl_elem_info *uinfo)
1816*db2a4165SFrank Mandarino {
1817*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 12) & 0xff;
1818*db2a4165SFrank Mandarino 
1819*db2a4165SFrank Mandarino 	uinfo->type =
1820*db2a4165SFrank Mandarino 		mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1821*db2a4165SFrank Mandarino 	uinfo->count = 2;
1822*db2a4165SFrank Mandarino 	uinfo->value.integer.min = 0;
1823*db2a4165SFrank Mandarino 	uinfo->value.integer.max = mask;
1824*db2a4165SFrank Mandarino 	return 0;
1825*db2a4165SFrank Mandarino }
1826*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1827*db2a4165SFrank Mandarino 
1828*db2a4165SFrank Mandarino /**
1829*db2a4165SFrank Mandarino  * snd_soc_get_volsw_2r - double mixer get callback
1830*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1831*db2a4165SFrank Mandarino  * @uinfo: control element information
1832*db2a4165SFrank Mandarino  *
1833*db2a4165SFrank Mandarino  * Callback to get the value of a double mixer control that spans 2 registers.
1834*db2a4165SFrank Mandarino  *
1835*db2a4165SFrank Mandarino  * Returns 0 for success.
1836*db2a4165SFrank Mandarino  */
1837*db2a4165SFrank Mandarino int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1838*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1839*db2a4165SFrank Mandarino {
1840*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1841*db2a4165SFrank Mandarino 	int reg = kcontrol->private_value & 0xff;
1842*db2a4165SFrank Mandarino 	int reg2 = (kcontrol->private_value >> 24) & 0xff;
1843*db2a4165SFrank Mandarino 	int shift = (kcontrol->private_value >> 8) & 0x0f;
1844*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 12) & 0xff;
1845*db2a4165SFrank Mandarino 	int invert = (kcontrol->private_value >> 20) & 0x01;
1846*db2a4165SFrank Mandarino 
1847*db2a4165SFrank Mandarino 	ucontrol->value.integer.value[0] =
1848*db2a4165SFrank Mandarino 		(snd_soc_read(codec, reg) >> shift) & mask;
1849*db2a4165SFrank Mandarino 	ucontrol->value.integer.value[1] =
1850*db2a4165SFrank Mandarino 		(snd_soc_read(codec, reg2) >> shift) & mask;
1851*db2a4165SFrank Mandarino 	if (invert) {
1852*db2a4165SFrank Mandarino 		ucontrol->value.integer.value[0] =
1853*db2a4165SFrank Mandarino 			mask - ucontrol->value.integer.value[0];
1854*db2a4165SFrank Mandarino 		ucontrol->value.integer.value[1] =
1855*db2a4165SFrank Mandarino 			mask - ucontrol->value.integer.value[1];
1856*db2a4165SFrank Mandarino 	}
1857*db2a4165SFrank Mandarino 
1858*db2a4165SFrank Mandarino 	return 0;
1859*db2a4165SFrank Mandarino }
1860*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1861*db2a4165SFrank Mandarino 
1862*db2a4165SFrank Mandarino /**
1863*db2a4165SFrank Mandarino  * snd_soc_put_volsw_2r - double mixer set callback
1864*db2a4165SFrank Mandarino  * @kcontrol: mixer control
1865*db2a4165SFrank Mandarino  * @uinfo: control element information
1866*db2a4165SFrank Mandarino  *
1867*db2a4165SFrank Mandarino  * Callback to set the value of a double mixer control that spans 2 registers.
1868*db2a4165SFrank Mandarino  *
1869*db2a4165SFrank Mandarino  * Returns 0 for success.
1870*db2a4165SFrank Mandarino  */
1871*db2a4165SFrank Mandarino int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1872*db2a4165SFrank Mandarino 	struct snd_ctl_elem_value *ucontrol)
1873*db2a4165SFrank Mandarino {
1874*db2a4165SFrank Mandarino 	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1875*db2a4165SFrank Mandarino 	int reg = kcontrol->private_value & 0xff;
1876*db2a4165SFrank Mandarino 	int reg2 = (kcontrol->private_value >> 24) & 0xff;
1877*db2a4165SFrank Mandarino 	int shift = (kcontrol->private_value >> 8) & 0x0f;
1878*db2a4165SFrank Mandarino 	int mask = (kcontrol->private_value >> 12) & 0xff;
1879*db2a4165SFrank Mandarino 	int invert = (kcontrol->private_value >> 20) & 0x01;
1880*db2a4165SFrank Mandarino 	int err;
1881*db2a4165SFrank Mandarino 	unsigned short val, val2, val_mask;
1882*db2a4165SFrank Mandarino 
1883*db2a4165SFrank Mandarino 	val_mask = mask << shift;
1884*db2a4165SFrank Mandarino 	val = (ucontrol->value.integer.value[0] & mask);
1885*db2a4165SFrank Mandarino 	val2 = (ucontrol->value.integer.value[1] & mask);
1886*db2a4165SFrank Mandarino 
1887*db2a4165SFrank Mandarino 	if (invert) {
1888*db2a4165SFrank Mandarino 		val = mask - val;
1889*db2a4165SFrank Mandarino 		val2 = mask - val2;
1890*db2a4165SFrank Mandarino 	}
1891*db2a4165SFrank Mandarino 
1892*db2a4165SFrank Mandarino 	val = val << shift;
1893*db2a4165SFrank Mandarino 	val2 = val2 << shift;
1894*db2a4165SFrank Mandarino 
1895*db2a4165SFrank Mandarino 	if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
1896*db2a4165SFrank Mandarino 		return err;
1897*db2a4165SFrank Mandarino 
1898*db2a4165SFrank Mandarino 	err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1899*db2a4165SFrank Mandarino 	return err;
1900*db2a4165SFrank Mandarino }
1901*db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1902*db2a4165SFrank Mandarino 
1903*db2a4165SFrank Mandarino static int __devinit snd_soc_init(void)
1904*db2a4165SFrank Mandarino {
1905*db2a4165SFrank Mandarino 	printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1906*db2a4165SFrank Mandarino 	return platform_driver_register(&soc_driver);
1907*db2a4165SFrank Mandarino }
1908*db2a4165SFrank Mandarino 
1909*db2a4165SFrank Mandarino static void snd_soc_exit(void)
1910*db2a4165SFrank Mandarino {
1911*db2a4165SFrank Mandarino  	platform_driver_unregister(&soc_driver);
1912*db2a4165SFrank Mandarino }
1913*db2a4165SFrank Mandarino 
1914*db2a4165SFrank Mandarino module_init(snd_soc_init);
1915*db2a4165SFrank Mandarino module_exit(snd_soc_exit);
1916*db2a4165SFrank Mandarino 
1917*db2a4165SFrank Mandarino /* Module information */
1918*db2a4165SFrank Mandarino MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1919*db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core");
1920*db2a4165SFrank Mandarino MODULE_LICENSE("GPL");
1921