blob: 3a3f3f2343d75e7ee8b9b29abd3ee6887c1437f4 [file] [log] [blame]
Barry Songa1533d92010-03-19 14:48:33 +08001/*
2 * AD193X Audio Codec driver supporting AD1936/7/8/9
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
Barry Songa1533d92010-03-19 14:48:33 +08009#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/device.h>
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +010012#include <linux/regmap.h>
Stephen Rothwell1b132ea2010-03-29 15:32:18 +110013#include <linux/slab.h>
Barry Songa1533d92010-03-19 14:48:33 +080014#include <sound/core.h>
15#include <sound/pcm.h>
16#include <sound/pcm_params.h>
17#include <sound/initval.h>
18#include <sound/soc.h>
19#include <sound/tlv.h>
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +010020
Barry Songa1533d92010-03-19 14:48:33 +080021#include "ad193x.h"
22
23/* codec private data */
24struct ad193x_priv {
Lars-Peter Clausen30ab1e72011-09-05 20:46:33 +020025 struct regmap *regmap;
Cyrille Pitchene5224f52015-09-29 16:41:43 +020026 enum ad193x_type type;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000027 int sysclk;
Barry Songa1533d92010-03-19 14:48:33 +080028};
29
Barry Songa1533d92010-03-19 14:48:33 +080030/*
31 * AD193X volume/mute/de-emphasis etc. controls
32 */
Lars-Peter Clausenc4e7a4a2011-11-28 17:28:08 +010033static const char * const ad193x_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"};
Barry Songa1533d92010-03-19 14:48:33 +080034
Takashi Iwaib6592d82014-02-18 09:55:27 +010035static SOC_ENUM_SINGLE_DECL(ad193x_deemp_enum, AD193X_DAC_CTRL2, 1,
36 ad193x_deemp);
Barry Songa1533d92010-03-19 14:48:33 +080037
Lars-Peter Clausen591c0342011-11-28 17:28:07 +010038static const DECLARE_TLV_DB_MINMAX(adau193x_tlv, -9563, 0);
39
Barry Songa1533d92010-03-19 14:48:33 +080040static const struct snd_kcontrol_new ad193x_snd_controls[] = {
41 /* DAC volume control */
Lars-Peter Clausen591c0342011-11-28 17:28:07 +010042 SOC_DOUBLE_R_TLV("DAC1 Volume", AD193X_DAC_L1_VOL,
43 AD193X_DAC_R1_VOL, 0, 0xFF, 1, adau193x_tlv),
44 SOC_DOUBLE_R_TLV("DAC2 Volume", AD193X_DAC_L2_VOL,
45 AD193X_DAC_R2_VOL, 0, 0xFF, 1, adau193x_tlv),
46 SOC_DOUBLE_R_TLV("DAC3 Volume", AD193X_DAC_L3_VOL,
47 AD193X_DAC_R3_VOL, 0, 0xFF, 1, adau193x_tlv),
48 SOC_DOUBLE_R_TLV("DAC4 Volume", AD193X_DAC_L4_VOL,
49 AD193X_DAC_R4_VOL, 0, 0xFF, 1, adau193x_tlv),
Barry Songa1533d92010-03-19 14:48:33 +080050
Barry Songa1533d92010-03-19 14:48:33 +080051 /* DAC switch control */
52 SOC_DOUBLE("DAC1 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL1_MUTE,
53 AD193X_DACR1_MUTE, 1, 1),
54 SOC_DOUBLE("DAC2 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL2_MUTE,
55 AD193X_DACR2_MUTE, 1, 1),
56 SOC_DOUBLE("DAC3 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL3_MUTE,
57 AD193X_DACR3_MUTE, 1, 1),
58 SOC_DOUBLE("DAC4 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL4_MUTE,
59 AD193X_DACR4_MUTE, 1, 1),
60
Cyrille Pitchene5224f52015-09-29 16:41:43 +020061 /* DAC de-emphasis */
62 SOC_ENUM("Playback Deemphasis", ad193x_deemp_enum),
63};
64
65static const struct snd_kcontrol_new ad193x_adc_snd_controls[] = {
66 /* ADC switch control */
67 SOC_DOUBLE("ADC1 Switch", AD193X_ADC_CTRL0, AD193X_ADCL1_MUTE,
68 AD193X_ADCR1_MUTE, 1, 1),
69 SOC_DOUBLE("ADC2 Switch", AD193X_ADC_CTRL0, AD193X_ADCL2_MUTE,
70 AD193X_ADCR2_MUTE, 1, 1),
71
Barry Songa1533d92010-03-19 14:48:33 +080072 /* ADC high-pass filter */
73 SOC_SINGLE("ADC High Pass Filter Switch", AD193X_ADC_CTRL0,
74 AD193X_ADC_HIGHPASS_FILTER, 1, 0),
Barry Songa1533d92010-03-19 14:48:33 +080075};
76
77static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = {
Lars-Peter Clausen1b86a3f2014-11-05 17:19:53 +010078 SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
79 SND_SOC_DAPM_PGA("DAC Output", AD193X_DAC_CTRL0, 0, 1, NULL, 0),
Barry Songa1533d92010-03-19 14:48:33 +080080 SND_SOC_DAPM_SUPPLY("PLL_PWR", AD193X_PLL_CLK_CTRL0, 0, 1, NULL, 0),
Lars-Peter Clausen0718fd22011-11-28 17:28:10 +010081 SND_SOC_DAPM_SUPPLY("SYSCLK", AD193X_PLL_CLK_CTRL0, 7, 0, NULL, 0),
Lars-Peter Clausen1b86a3f2014-11-05 17:19:53 +010082 SND_SOC_DAPM_VMID("VMID"),
Barry Songa1533d92010-03-19 14:48:33 +080083 SND_SOC_DAPM_OUTPUT("DAC1OUT"),
84 SND_SOC_DAPM_OUTPUT("DAC2OUT"),
85 SND_SOC_DAPM_OUTPUT("DAC3OUT"),
86 SND_SOC_DAPM_OUTPUT("DAC4OUT"),
Cyrille Pitchene5224f52015-09-29 16:41:43 +020087};
88
89static const struct snd_soc_dapm_widget ad193x_adc_widgets[] = {
90 SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
91 SND_SOC_DAPM_SUPPLY("ADC_PWR", AD193X_ADC_CTRL0, 0, 1, NULL, 0),
Barry Songa1533d92010-03-19 14:48:33 +080092 SND_SOC_DAPM_INPUT("ADC1IN"),
93 SND_SOC_DAPM_INPUT("ADC2IN"),
94};
95
96static const struct snd_soc_dapm_route audio_paths[] = {
Lars-Peter Clausen0718fd22011-11-28 17:28:10 +010097 { "DAC", NULL, "SYSCLK" },
Lars-Peter Clausen1b86a3f2014-11-05 17:19:53 +010098 { "DAC Output", NULL, "DAC" },
99 { "DAC Output", NULL, "VMID" },
Lars-Peter Clausen1b86a3f2014-11-05 17:19:53 +0100100 { "DAC1OUT", NULL, "DAC Output" },
101 { "DAC2OUT", NULL, "DAC Output" },
102 { "DAC3OUT", NULL, "DAC Output" },
103 { "DAC4OUT", NULL, "DAC Output" },
Lars-Peter Clausen0718fd22011-11-28 17:28:10 +0100104 { "SYSCLK", NULL, "PLL_PWR" },
Barry Songa1533d92010-03-19 14:48:33 +0800105};
106
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200107static const struct snd_soc_dapm_route ad193x_adc_audio_paths[] = {
108 { "ADC", NULL, "SYSCLK" },
109 { "ADC", NULL, "ADC_PWR" },
110 { "ADC", NULL, "ADC1IN" },
111 { "ADC", NULL, "ADC2IN" },
112};
113
114static inline bool ad193x_has_adc(const struct ad193x_priv *ad193x)
115{
116 switch (ad193x->type) {
117 case AD1933:
118 case AD1934:
119 return false;
120 default:
121 break;
122 }
123
124 return true;
125}
126
Barry Songa1533d92010-03-19 14:48:33 +0800127/*
128 * DAI ops entries
129 */
130
131static int ad193x_mute(struct snd_soc_dai *dai, int mute)
132{
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100133 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(dai->codec);
Barry Songa1533d92010-03-19 14:48:33 +0800134
Axel Lin54c96cf2011-10-18 06:25:08 +0800135 if (mute)
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100136 regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL2,
Axel Lin54c96cf2011-10-18 06:25:08 +0800137 AD193X_DAC_MASTER_MUTE,
138 AD193X_DAC_MASTER_MUTE);
139 else
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100140 regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL2,
Axel Lin54c96cf2011-10-18 06:25:08 +0800141 AD193X_DAC_MASTER_MUTE, 0);
Barry Songa1533d92010-03-19 14:48:33 +0800142
143 return 0;
144}
145
146static int ad193x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
147 unsigned int rx_mask, int slots, int width)
148{
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100149 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(dai->codec);
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100150 unsigned int channels;
Barry Songa1533d92010-03-19 14:48:33 +0800151
152 switch (slots) {
153 case 2:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100154 channels = AD193X_2_CHANNELS;
Barry Songa1533d92010-03-19 14:48:33 +0800155 break;
156 case 4:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100157 channels = AD193X_4_CHANNELS;
Barry Songa1533d92010-03-19 14:48:33 +0800158 break;
159 case 8:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100160 channels = AD193X_8_CHANNELS;
Barry Songa1533d92010-03-19 14:48:33 +0800161 break;
162 case 16:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100163 channels = AD193X_16_CHANNELS;
Barry Songa1533d92010-03-19 14:48:33 +0800164 break;
165 default:
166 return -EINVAL;
167 }
168
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100169 regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL1,
170 AD193X_DAC_CHAN_MASK, channels << AD193X_DAC_CHAN_SHFT);
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200171 if (ad193x_has_adc(ad193x))
172 regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL2,
173 AD193X_ADC_CHAN_MASK,
174 channels << AD193X_ADC_CHAN_SHFT);
Barry Songa1533d92010-03-19 14:48:33 +0800175
176 return 0;
177}
178
179static int ad193x_set_dai_fmt(struct snd_soc_dai *codec_dai,
180 unsigned int fmt)
181{
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100182 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec_dai->codec);
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100183 unsigned int adc_serfmt = 0;
184 unsigned int adc_fmt = 0;
185 unsigned int dac_fmt = 0;
Barry Songa1533d92010-03-19 14:48:33 +0800186
187 /* At present, the driver only support AUX ADC mode(SND_SOC_DAIFMT_I2S
188 * with TDM) and ADC&DAC TDM mode(SND_SOC_DAIFMT_DSP_A)
189 */
190 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
191 case SND_SOC_DAIFMT_I2S:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100192 adc_serfmt |= AD193X_ADC_SERFMT_TDM;
Barry Songa1533d92010-03-19 14:48:33 +0800193 break;
194 case SND_SOC_DAIFMT_DSP_A:
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100195 adc_serfmt |= AD193X_ADC_SERFMT_AUX;
Barry Songa1533d92010-03-19 14:48:33 +0800196 break;
197 default:
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200198 if (ad193x_has_adc(ad193x))
199 return -EINVAL;
200 break;
Barry Songa1533d92010-03-19 14:48:33 +0800201 }
202
203 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
204 case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
Barry Songa1533d92010-03-19 14:48:33 +0800205 break;
206 case SND_SOC_DAIFMT_NB_IF: /* normal bclk + invert frm */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100207 adc_fmt |= AD193X_ADC_LEFT_HIGH;
208 dac_fmt |= AD193X_DAC_LEFT_HIGH;
Barry Songa1533d92010-03-19 14:48:33 +0800209 break;
210 case SND_SOC_DAIFMT_IB_NF: /* invert bclk + normal frm */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100211 adc_fmt |= AD193X_ADC_BCLK_INV;
212 dac_fmt |= AD193X_DAC_BCLK_INV;
Barry Songa1533d92010-03-19 14:48:33 +0800213 break;
Barry Songa1533d92010-03-19 14:48:33 +0800214 case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100215 adc_fmt |= AD193X_ADC_LEFT_HIGH;
216 adc_fmt |= AD193X_ADC_BCLK_INV;
217 dac_fmt |= AD193X_DAC_LEFT_HIGH;
218 dac_fmt |= AD193X_DAC_BCLK_INV;
Barry Songa1533d92010-03-19 14:48:33 +0800219 break;
220 default:
221 return -EINVAL;
222 }
223
224 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
225 case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100226 adc_fmt |= AD193X_ADC_LCR_MASTER;
227 adc_fmt |= AD193X_ADC_BCLK_MASTER;
228 dac_fmt |= AD193X_DAC_LCR_MASTER;
229 dac_fmt |= AD193X_DAC_BCLK_MASTER;
Barry Songa1533d92010-03-19 14:48:33 +0800230 break;
231 case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & frm master */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100232 adc_fmt |= AD193X_ADC_LCR_MASTER;
233 dac_fmt |= AD193X_DAC_LCR_MASTER;
Barry Songa1533d92010-03-19 14:48:33 +0800234 break;
235 case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */
Lars-Peter Clausenb82ca572011-11-28 17:28:11 +0100236 adc_fmt |= AD193X_ADC_BCLK_MASTER;
237 dac_fmt |= AD193X_DAC_BCLK_MASTER;
Barry Songa1533d92010-03-19 14:48:33 +0800238 break;
239 case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */
Barry Songa1533d92010-03-19 14:48:33 +0800240 break;
241 default:
242 return -EINVAL;
243 }
244
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200245 if (ad193x_has_adc(ad193x)) {
246 regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL1,
247 AD193X_ADC_SERFMT_MASK, adc_serfmt);
248 regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL2,
249 AD193X_ADC_FMT_MASK, adc_fmt);
250 }
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100251 regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL1,
252 AD193X_DAC_FMT_MASK, dac_fmt);
Barry Songa1533d92010-03-19 14:48:33 +0800253
254 return 0;
255}
256
Barry Songfab90aa2010-05-21 11:57:01 +0800257static int ad193x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
258 int clk_id, unsigned int freq, int dir)
259{
260 struct snd_soc_codec *codec = codec_dai->codec;
261 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
262 switch (freq) {
263 case 12288000:
264 case 18432000:
265 case 24576000:
266 case 36864000:
267 ad193x->sysclk = freq;
268 return 0;
269 }
270 return -EINVAL;
271}
272
Barry Songa1533d92010-03-19 14:48:33 +0800273static int ad193x_hw_params(struct snd_pcm_substream *substream,
274 struct snd_pcm_hw_params *params,
275 struct snd_soc_dai *dai)
276{
Axel Lin54c96cf2011-10-18 06:25:08 +0800277 int word_len = 0, master_rate = 0;
Mark Browne6968a12012-04-04 15:58:16 +0100278 struct snd_soc_codec *codec = dai->codec;
Barry Songfab90aa2010-05-21 11:57:01 +0800279 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
Barry Songa1533d92010-03-19 14:48:33 +0800280
281 /* bit size */
Mark Brownd4dd1fd2014-01-08 18:38:20 +0000282 switch (params_width(params)) {
283 case 16:
Barry Songa1533d92010-03-19 14:48:33 +0800284 word_len = 3;
285 break;
Mark Brownd4dd1fd2014-01-08 18:38:20 +0000286 case 20:
Barry Songa1533d92010-03-19 14:48:33 +0800287 word_len = 1;
288 break;
Mark Brownd4dd1fd2014-01-08 18:38:20 +0000289 case 24:
290 case 32:
Barry Songa1533d92010-03-19 14:48:33 +0800291 word_len = 0;
292 break;
293 }
294
Barry Songfab90aa2010-05-21 11:57:01 +0800295 switch (ad193x->sysclk) {
296 case 12288000:
297 master_rate = AD193X_PLL_INPUT_256;
298 break;
299 case 18432000:
300 master_rate = AD193X_PLL_INPUT_384;
301 break;
302 case 24576000:
303 master_rate = AD193X_PLL_INPUT_512;
304 break;
305 case 36864000:
306 master_rate = AD193X_PLL_INPUT_768;
307 break;
308 }
309
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100310 regmap_update_bits(ad193x->regmap, AD193X_PLL_CLK_CTRL0,
Axel Lin54c96cf2011-10-18 06:25:08 +0800311 AD193X_PLL_INPUT_MASK, master_rate);
Barry Songfab90aa2010-05-21 11:57:01 +0800312
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100313 regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL2,
Axel Lin54c96cf2011-10-18 06:25:08 +0800314 AD193X_DAC_WORD_LEN_MASK,
315 word_len << AD193X_DAC_WORD_LEN_SHFT);
Barry Songa1533d92010-03-19 14:48:33 +0800316
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200317 if (ad193x_has_adc(ad193x))
318 regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL1,
319 AD193X_ADC_WORD_LEN_MASK, word_len);
Barry Songa1533d92010-03-19 14:48:33 +0800320
321 return 0;
322}
323
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100324static const struct snd_soc_dai_ops ad193x_dai_ops = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000325 .hw_params = ad193x_hw_params,
326 .digital_mute = ad193x_mute,
327 .set_tdm_slot = ad193x_set_tdm_slot,
328 .set_sysclk = ad193x_set_dai_sysclk,
329 .set_fmt = ad193x_set_dai_fmt,
330};
331
332/* codec DAI instance */
333static struct snd_soc_dai_driver ad193x_dai = {
334 .name = "ad193x-hifi",
335 .playback = {
336 .stream_name = "Playback",
337 .channels_min = 2,
338 .channels_max = 8,
339 .rates = SNDRV_PCM_RATE_48000,
340 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
341 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
342 },
343 .capture = {
344 .stream_name = "Capture",
345 .channels_min = 2,
346 .channels_max = 4,
347 .rates = SNDRV_PCM_RATE_48000,
348 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
349 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
350 },
351 .ops = &ad193x_dai_ops,
352};
353
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100354static int ad193x_codec_probe(struct snd_soc_codec *codec)
Barry Songa1533d92010-03-19 14:48:33 +0800355{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000356 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200357 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
358 int num, ret;
Barry Songa1533d92010-03-19 14:48:33 +0800359
360 /* default setting for ad193x */
361
362 /* unmute dac channels */
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100363 regmap_write(ad193x->regmap, AD193X_DAC_CHNL_MUTE, 0x0);
Barry Songa1533d92010-03-19 14:48:33 +0800364 /* de-emphasis: 48kHz, powedown dac */
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100365 regmap_write(ad193x->regmap, AD193X_DAC_CTRL2, 0x1A);
Lars-Peter Clausenbdb2c742015-01-12 13:54:13 +0100366 /* dac in tdm mode */
367 regmap_write(ad193x->regmap, AD193X_DAC_CTRL0, 0x40);
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200368
369 /* adc only */
370 if (ad193x_has_adc(ad193x)) {
371 /* high-pass filter enable */
372 regmap_write(ad193x->regmap, AD193X_ADC_CTRL0, 0x3);
373 /* sata delay=1, adc aux mode */
374 regmap_write(ad193x->regmap, AD193X_ADC_CTRL1, 0x43);
375 }
376
Barry Songa1533d92010-03-19 14:48:33 +0800377 /* pll input: mclki/xi */
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100378 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */
379 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL1, 0x04);
Barry Songa1533d92010-03-19 14:48:33 +0800380
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200381 /* adc only */
382 if (ad193x_has_adc(ad193x)) {
383 /* add adc controls */
384 num = ARRAY_SIZE(ad193x_adc_snd_controls);
385 ret = snd_soc_add_codec_controls(codec,
386 ad193x_adc_snd_controls,
387 num);
388 if (ret)
389 return ret;
390
391 /* add adc widgets */
392 num = ARRAY_SIZE(ad193x_adc_widgets);
393 ret = snd_soc_dapm_new_controls(dapm,
394 ad193x_adc_widgets,
395 num);
396 if (ret)
397 return ret;
398
399 /* add adc routes */
400 num = ARRAY_SIZE(ad193x_adc_audio_paths);
401 ret = snd_soc_dapm_add_routes(dapm,
402 ad193x_adc_audio_paths,
403 num);
404 if (ret)
405 return ret;
406 }
407
Xiubo Li5d6be5a2014-03-11 12:43:20 +0800408 return 0;
Barry Songa1533d92010-03-19 14:48:33 +0800409}
410
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000411static struct snd_soc_codec_driver soc_codec_dev_ad193x = {
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100412 .probe = ad193x_codec_probe,
Lars-Peter Clausenb90d4182011-11-28 17:28:06 +0100413 .controls = ad193x_snd_controls,
414 .num_controls = ARRAY_SIZE(ad193x_snd_controls),
415 .dapm_widgets = ad193x_dapm_widgets,
416 .num_dapm_widgets = ARRAY_SIZE(ad193x_dapm_widgets),
417 .dapm_routes = audio_paths,
418 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Barry Songa1533d92010-03-19 14:48:33 +0800419};
Barry Songa1533d92010-03-19 14:48:33 +0800420
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100421const struct regmap_config ad193x_regmap_config = {
Lars-Peter Clausen34cbe162011-11-28 17:28:12 +0100422 .max_register = AD193X_NUM_REGS - 1,
Lars-Peter Clausen30ab1e72011-09-05 20:46:33 +0200423};
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100424EXPORT_SYMBOL_GPL(ad193x_regmap_config);
Lars-Peter Clausen30ab1e72011-09-05 20:46:33 +0200425
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200426int ad193x_probe(struct device *dev, struct regmap *regmap,
427 enum ad193x_type type)
Barry Songa1533d92010-03-19 14:48:33 +0800428{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000429 struct ad193x_priv *ad193x;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000430
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100431 if (IS_ERR(regmap))
432 return PTR_ERR(regmap);
433
434 ad193x = devm_kzalloc(dev, sizeof(*ad193x), GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000435 if (ad193x == NULL)
436 return -ENOMEM;
437
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100438 ad193x->regmap = regmap;
Cyrille Pitchene5224f52015-09-29 16:41:43 +0200439 ad193x->type = type;
Lars-Peter Clausen30ab1e72011-09-05 20:46:33 +0200440
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100441 dev_set_drvdata(dev, ad193x);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000442
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100443 return snd_soc_register_codec(dev, &soc_codec_dev_ad193x,
444 &ad193x_dai, 1);
Barry Songa1533d92010-03-19 14:48:33 +0800445}
Lars-Peter Clausen6c3d7132014-02-17 13:16:54 +0100446EXPORT_SYMBOL_GPL(ad193x_probe);
Barry Songa1533d92010-03-19 14:48:33 +0800447
448MODULE_DESCRIPTION("ASoC ad193x driver");
449MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
450MODULE_LICENSE("GPL");