blob: 701bd620474709dcf500687cef0eb0292862c1a7 [file] [log] [blame]
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001/*
2 * DA7213 ALSA SoC Codec Driver
3 *
4 * Copyright (c) 2013 Dialog Semiconductor
5 *
6 * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
7 * Based on DA9055 ALSA SoC codec driver.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
Adam Thomson6e7c4442015-10-07 14:27:11 +010015#include <linux/clk.h>
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000016#include <linux/delay.h>
17#include <linux/i2c.h>
18#include <linux/regmap.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
24#include <sound/initval.h>
25#include <sound/tlv.h>
26
27#include <sound/da7213.h>
28#include "da7213.h"
29
30
31/* Gain and Volume */
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020032static const DECLARE_TLV_DB_RANGE(aux_vol_tlv,
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000033 /* -54dB */
34 0x0, 0x11, TLV_DB_SCALE_ITEM(-5400, 0, 0),
35 /* -52.5dB to 15dB */
36 0x12, 0x3f, TLV_DB_SCALE_ITEM(-5250, 150, 0)
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020037);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000038
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020039static const DECLARE_TLV_DB_RANGE(digital_gain_tlv,
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000040 0x0, 0x07, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
41 /* -78dB to 12dB */
42 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7800, 75, 0)
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020043);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000044
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020045static const DECLARE_TLV_DB_RANGE(alc_analog_gain_tlv,
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000046 0x0, 0x0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
47 /* 0dB to 36dB */
48 0x01, 0x07, TLV_DB_SCALE_ITEM(0, 600, 0)
Lars-Peter Clausen32e933b2015-08-02 17:19:38 +020049);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000050
51static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
52static const DECLARE_TLV_DB_SCALE(mixin_gain_tlv, -450, 150, 0);
53static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
54static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -5700, 100, 0);
55static const DECLARE_TLV_DB_SCALE(lineout_vol_tlv, -4800, 100, 0);
56static const DECLARE_TLV_DB_SCALE(alc_threshold_tlv, -9450, 150, 0);
57static const DECLARE_TLV_DB_SCALE(alc_gain_tlv, 0, 600, 0);
58
59/* ADC and DAC voice mode (8kHz) high pass cutoff value */
60static const char * const da7213_voice_hpf_corner_txt[] = {
61 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
62};
63
Takashi Iwaic99f8b22014-02-18 10:06:47 +010064static SOC_ENUM_SINGLE_DECL(da7213_dac_voice_hpf_corner,
65 DA7213_DAC_FILTERS1,
66 DA7213_VOICE_HPF_CORNER_SHIFT,
67 da7213_voice_hpf_corner_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000068
Takashi Iwaic99f8b22014-02-18 10:06:47 +010069static SOC_ENUM_SINGLE_DECL(da7213_adc_voice_hpf_corner,
70 DA7213_ADC_FILTERS1,
71 DA7213_VOICE_HPF_CORNER_SHIFT,
72 da7213_voice_hpf_corner_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000073
74/* ADC and DAC high pass filter cutoff value */
75static const char * const da7213_audio_hpf_corner_txt[] = {
76 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
77};
78
Takashi Iwaic99f8b22014-02-18 10:06:47 +010079static SOC_ENUM_SINGLE_DECL(da7213_dac_audio_hpf_corner,
80 DA7213_DAC_FILTERS1
81 , DA7213_AUDIO_HPF_CORNER_SHIFT,
82 da7213_audio_hpf_corner_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000083
Takashi Iwaic99f8b22014-02-18 10:06:47 +010084static SOC_ENUM_SINGLE_DECL(da7213_adc_audio_hpf_corner,
85 DA7213_ADC_FILTERS1,
86 DA7213_AUDIO_HPF_CORNER_SHIFT,
87 da7213_audio_hpf_corner_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000088
89/* Gain ramping rate value */
90static const char * const da7213_gain_ramp_rate_txt[] = {
91 "nominal rate * 8", "nominal rate * 16", "nominal rate / 16",
92 "nominal rate / 32"
93};
94
Takashi Iwaic99f8b22014-02-18 10:06:47 +010095static SOC_ENUM_SINGLE_DECL(da7213_gain_ramp_rate,
96 DA7213_GAIN_RAMP_CTRL,
97 DA7213_GAIN_RAMP_RATE_SHIFT,
98 da7213_gain_ramp_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +000099
100/* DAC noise gate setup time value */
101static const char * const da7213_dac_ng_setup_time_txt[] = {
102 "256 samples", "512 samples", "1024 samples", "2048 samples"
103};
104
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100105static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_setup_time,
106 DA7213_DAC_NG_SETUP_TIME,
107 DA7213_DAC_NG_SETUP_TIME_SHIFT,
108 da7213_dac_ng_setup_time_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000109
110/* DAC noise gate rampup rate value */
111static const char * const da7213_dac_ng_rampup_txt[] = {
112 "0.02 ms/dB", "0.16 ms/dB"
113};
114
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100115static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampup_rate,
116 DA7213_DAC_NG_SETUP_TIME,
117 DA7213_DAC_NG_RAMPUP_RATE_SHIFT,
118 da7213_dac_ng_rampup_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000119
120/* DAC noise gate rampdown rate value */
121static const char * const da7213_dac_ng_rampdown_txt[] = {
122 "0.64 ms/dB", "20.48 ms/dB"
123};
124
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100125static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampdown_rate,
126 DA7213_DAC_NG_SETUP_TIME,
127 DA7213_DAC_NG_RAMPDN_RATE_SHIFT,
128 da7213_dac_ng_rampdown_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000129
130/* DAC soft mute rate value */
131static const char * const da7213_dac_soft_mute_rate_txt[] = {
132 "1", "2", "4", "8", "16", "32", "64"
133};
134
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100135static SOC_ENUM_SINGLE_DECL(da7213_dac_soft_mute_rate,
136 DA7213_DAC_FILTERS5,
137 DA7213_DAC_SOFTMUTE_RATE_SHIFT,
138 da7213_dac_soft_mute_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000139
140/* ALC Attack Rate select */
141static const char * const da7213_alc_attack_rate_txt[] = {
142 "44/fs", "88/fs", "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs",
143 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
144};
145
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100146static SOC_ENUM_SINGLE_DECL(da7213_alc_attack_rate,
147 DA7213_ALC_CTRL2,
148 DA7213_ALC_ATTACK_SHIFT,
149 da7213_alc_attack_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000150
151/* ALC Release Rate select */
152static const char * const da7213_alc_release_rate_txt[] = {
153 "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs", "5632/fs",
154 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
155};
156
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100157static SOC_ENUM_SINGLE_DECL(da7213_alc_release_rate,
158 DA7213_ALC_CTRL2,
159 DA7213_ALC_RELEASE_SHIFT,
160 da7213_alc_release_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000161
162/* ALC Hold Time select */
163static const char * const da7213_alc_hold_time_txt[] = {
164 "62/fs", "124/fs", "248/fs", "496/fs", "992/fs", "1984/fs", "3968/fs",
165 "7936/fs", "15872/fs", "31744/fs", "63488/fs", "126976/fs",
166 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs"
167};
168
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100169static SOC_ENUM_SINGLE_DECL(da7213_alc_hold_time,
170 DA7213_ALC_CTRL3,
171 DA7213_ALC_HOLD_SHIFT,
172 da7213_alc_hold_time_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000173
174/* ALC Input Signal Tracking rate select */
175static const char * const da7213_alc_integ_rate_txt[] = {
176 "1/4", "1/16", "1/256", "1/65536"
177};
178
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100179static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_attack_rate,
180 DA7213_ALC_CTRL3,
181 DA7213_ALC_INTEG_ATTACK_SHIFT,
182 da7213_alc_integ_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000183
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100184static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_release_rate,
185 DA7213_ALC_CTRL3,
186 DA7213_ALC_INTEG_RELEASE_SHIFT,
187 da7213_alc_integ_rate_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000188
189
190/*
191 * Control Functions
192 */
193
194static int da7213_get_alc_data(struct snd_soc_codec *codec, u8 reg_val)
195{
196 int mid_data, top_data;
197 int sum = 0;
198 u8 iteration;
199
200 for (iteration = 0; iteration < DA7213_ALC_AVG_ITERATIONS;
201 iteration++) {
202 /* Select the left or right channel and capture data */
203 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL, reg_val);
204
205 /* Select middle 8 bits for read back from data register */
206 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL,
207 reg_val | DA7213_ALC_DATA_MIDDLE);
208 mid_data = snd_soc_read(codec, DA7213_ALC_CIC_OP_LVL_DATA);
209
210 /* Select top 8 bits for read back from data register */
211 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL,
212 reg_val | DA7213_ALC_DATA_TOP);
213 top_data = snd_soc_read(codec, DA7213_ALC_CIC_OP_LVL_DATA);
214
215 sum += ((mid_data << 8) | (top_data << 16));
216 }
217
218 return sum / DA7213_ALC_AVG_ITERATIONS;
219}
220
221static void da7213_alc_calib_man(struct snd_soc_codec *codec)
222{
223 u8 reg_val;
224 int avg_left_data, avg_right_data, offset_l, offset_r;
225
226 /* Calculate average for Left and Right data */
227 /* Left Data */
228 avg_left_data = da7213_get_alc_data(codec,
229 DA7213_ALC_CIC_OP_CHANNEL_LEFT);
230 /* Right Data */
231 avg_right_data = da7213_get_alc_data(codec,
232 DA7213_ALC_CIC_OP_CHANNEL_RIGHT);
233
234 /* Calculate DC offset */
235 offset_l = -avg_left_data;
236 offset_r = -avg_right_data;
237
238 reg_val = (offset_l & DA7213_ALC_OFFSET_15_8) >> 8;
239 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_M_L, reg_val);
240 reg_val = (offset_l & DA7213_ALC_OFFSET_19_16) >> 16;
241 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_U_L, reg_val);
242
243 reg_val = (offset_r & DA7213_ALC_OFFSET_15_8) >> 8;
244 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_M_R, reg_val);
245 reg_val = (offset_r & DA7213_ALC_OFFSET_19_16) >> 16;
246 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_U_R, reg_val);
247
248 /* Enable analog/digital gain mode & offset cancellation */
249 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
250 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
251 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE);
252}
253
254static void da7213_alc_calib_auto(struct snd_soc_codec *codec)
255{
256 u8 alc_ctrl1;
257
258 /* Begin auto calibration and wait for completion */
259 snd_soc_update_bits(codec, DA7213_ALC_CTRL1, DA7213_ALC_AUTO_CALIB_EN,
260 DA7213_ALC_AUTO_CALIB_EN);
261 do {
262 alc_ctrl1 = snd_soc_read(codec, DA7213_ALC_CTRL1);
263 } while (alc_ctrl1 & DA7213_ALC_AUTO_CALIB_EN);
264
265 /* If auto calibration fails, fall back to digital gain only mode */
266 if (alc_ctrl1 & DA7213_ALC_CALIB_OVERFLOW) {
267 dev_warn(codec->dev,
268 "ALC auto calibration failed with overflow\n");
269 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
270 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
271 0);
272 } else {
273 /* Enable analog/digital gain mode & offset cancellation */
274 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
275 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
276 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE);
277 }
278
279}
280
281static void da7213_alc_calib(struct snd_soc_codec *codec)
282{
283 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
284 u8 adc_l_ctrl, adc_r_ctrl;
285 u8 mixin_l_sel, mixin_r_sel;
286 u8 mic_1_ctrl, mic_2_ctrl;
287
288 /* Save current values from ADC control registers */
289 adc_l_ctrl = snd_soc_read(codec, DA7213_ADC_L_CTRL);
290 adc_r_ctrl = snd_soc_read(codec, DA7213_ADC_R_CTRL);
291
292 /* Save current values from MIXIN_L/R_SELECT registers */
293 mixin_l_sel = snd_soc_read(codec, DA7213_MIXIN_L_SELECT);
294 mixin_r_sel = snd_soc_read(codec, DA7213_MIXIN_R_SELECT);
295
296 /* Save current values from MIC control registers */
297 mic_1_ctrl = snd_soc_read(codec, DA7213_MIC_1_CTRL);
298 mic_2_ctrl = snd_soc_read(codec, DA7213_MIC_2_CTRL);
299
300 /* Enable ADC Left and Right */
301 snd_soc_update_bits(codec, DA7213_ADC_L_CTRL, DA7213_ADC_EN,
302 DA7213_ADC_EN);
303 snd_soc_update_bits(codec, DA7213_ADC_R_CTRL, DA7213_ADC_EN,
304 DA7213_ADC_EN);
305
306 /* Enable MIC paths */
307 snd_soc_update_bits(codec, DA7213_MIXIN_L_SELECT,
308 DA7213_MIXIN_L_MIX_SELECT_MIC_1 |
309 DA7213_MIXIN_L_MIX_SELECT_MIC_2,
310 DA7213_MIXIN_L_MIX_SELECT_MIC_1 |
311 DA7213_MIXIN_L_MIX_SELECT_MIC_2);
312 snd_soc_update_bits(codec, DA7213_MIXIN_R_SELECT,
313 DA7213_MIXIN_R_MIX_SELECT_MIC_2 |
314 DA7213_MIXIN_R_MIX_SELECT_MIC_1,
315 DA7213_MIXIN_R_MIX_SELECT_MIC_2 |
316 DA7213_MIXIN_R_MIX_SELECT_MIC_1);
317
318 /* Mute MIC PGAs */
319 snd_soc_update_bits(codec, DA7213_MIC_1_CTRL, DA7213_MUTE_EN,
320 DA7213_MUTE_EN);
321 snd_soc_update_bits(codec, DA7213_MIC_2_CTRL, DA7213_MUTE_EN,
322 DA7213_MUTE_EN);
323
324 /* Perform calibration */
325 if (da7213->alc_calib_auto)
326 da7213_alc_calib_auto(codec);
327 else
328 da7213_alc_calib_man(codec);
329
330 /* Restore MIXIN_L/R_SELECT registers to their original states */
331 snd_soc_write(codec, DA7213_MIXIN_L_SELECT, mixin_l_sel);
332 snd_soc_write(codec, DA7213_MIXIN_R_SELECT, mixin_r_sel);
333
334 /* Restore ADC control registers to their original states */
335 snd_soc_write(codec, DA7213_ADC_L_CTRL, adc_l_ctrl);
336 snd_soc_write(codec, DA7213_ADC_R_CTRL, adc_r_ctrl);
337
338 /* Restore original values of MIC control registers */
339 snd_soc_write(codec, DA7213_MIC_1_CTRL, mic_1_ctrl);
340 snd_soc_write(codec, DA7213_MIC_2_CTRL, mic_2_ctrl);
341}
342
343static int da7213_put_mixin_gain(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
345{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100346 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000347 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
348 int ret;
349
350 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
351
352 /* If ALC in operation, make sure calibrated offsets are updated */
353 if ((!ret) && (da7213->alc_en))
354 da7213_alc_calib(codec);
355
356 return ret;
357}
358
359static int da7213_put_alc_sw(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100362 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000363 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
364
365 /* Force ALC offset calibration if enabling ALC */
366 if (ucontrol->value.integer.value[0] ||
367 ucontrol->value.integer.value[1]) {
368 if (!da7213->alc_en) {
369 da7213_alc_calib(codec);
370 da7213->alc_en = true;
371 }
372 } else {
373 da7213->alc_en = false;
374 }
375
376 return snd_soc_put_volsw(kcontrol, ucontrol);
377}
378
379
380/*
381 * KControls
382 */
383
384static const struct snd_kcontrol_new da7213_snd_controls[] = {
385
386 /* Volume controls */
387 SOC_SINGLE_TLV("Mic 1 Volume", DA7213_MIC_1_GAIN,
388 DA7213_MIC_AMP_GAIN_SHIFT, DA7213_MIC_AMP_GAIN_MAX,
389 DA7213_NO_INVERT, mic_vol_tlv),
390 SOC_SINGLE_TLV("Mic 2 Volume", DA7213_MIC_2_GAIN,
391 DA7213_MIC_AMP_GAIN_SHIFT, DA7213_MIC_AMP_GAIN_MAX,
392 DA7213_NO_INVERT, mic_vol_tlv),
393 SOC_DOUBLE_R_TLV("Aux Volume", DA7213_AUX_L_GAIN, DA7213_AUX_R_GAIN,
394 DA7213_AUX_AMP_GAIN_SHIFT, DA7213_AUX_AMP_GAIN_MAX,
395 DA7213_NO_INVERT, aux_vol_tlv),
396 SOC_DOUBLE_R_EXT_TLV("Mixin PGA Volume", DA7213_MIXIN_L_GAIN,
397 DA7213_MIXIN_R_GAIN, DA7213_MIXIN_AMP_GAIN_SHIFT,
398 DA7213_MIXIN_AMP_GAIN_MAX, DA7213_NO_INVERT,
399 snd_soc_get_volsw_2r, da7213_put_mixin_gain,
400 mixin_gain_tlv),
401 SOC_DOUBLE_R_TLV("ADC Volume", DA7213_ADC_L_GAIN, DA7213_ADC_R_GAIN,
402 DA7213_ADC_AMP_GAIN_SHIFT, DA7213_ADC_AMP_GAIN_MAX,
403 DA7213_NO_INVERT, digital_gain_tlv),
404 SOC_DOUBLE_R_TLV("DAC Volume", DA7213_DAC_L_GAIN, DA7213_DAC_R_GAIN,
405 DA7213_DAC_AMP_GAIN_SHIFT, DA7213_DAC_AMP_GAIN_MAX,
406 DA7213_NO_INVERT, digital_gain_tlv),
407 SOC_DOUBLE_R_TLV("Headphone Volume", DA7213_HP_L_GAIN, DA7213_HP_R_GAIN,
408 DA7213_HP_AMP_GAIN_SHIFT, DA7213_HP_AMP_GAIN_MAX,
409 DA7213_NO_INVERT, hp_vol_tlv),
410 SOC_SINGLE_TLV("Lineout Volume", DA7213_LINE_GAIN,
411 DA7213_LINE_AMP_GAIN_SHIFT, DA7213_LINE_AMP_GAIN_MAX,
412 DA7213_NO_INVERT, lineout_vol_tlv),
413
414 /* DAC Equalizer controls */
415 SOC_SINGLE("DAC EQ Switch", DA7213_DAC_FILTERS4, DA7213_DAC_EQ_EN_SHIFT,
416 DA7213_DAC_EQ_EN_MAX, DA7213_NO_INVERT),
417 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7213_DAC_FILTERS2,
418 DA7213_DAC_EQ_BAND1_SHIFT, DA7213_DAC_EQ_BAND_MAX,
419 DA7213_NO_INVERT, eq_gain_tlv),
420 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7213_DAC_FILTERS2,
421 DA7213_DAC_EQ_BAND2_SHIFT, DA7213_DAC_EQ_BAND_MAX,
422 DA7213_NO_INVERT, eq_gain_tlv),
423 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7213_DAC_FILTERS3,
424 DA7213_DAC_EQ_BAND3_SHIFT, DA7213_DAC_EQ_BAND_MAX,
425 DA7213_NO_INVERT, eq_gain_tlv),
426 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7213_DAC_FILTERS3,
427 DA7213_DAC_EQ_BAND4_SHIFT, DA7213_DAC_EQ_BAND_MAX,
428 DA7213_NO_INVERT, eq_gain_tlv),
429 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7213_DAC_FILTERS4,
430 DA7213_DAC_EQ_BAND5_SHIFT, DA7213_DAC_EQ_BAND_MAX,
431 DA7213_NO_INVERT, eq_gain_tlv),
432
433 /* High Pass Filter and Voice Mode controls */
434 SOC_SINGLE("ADC HPF Switch", DA7213_ADC_FILTERS1, DA7213_HPF_EN_SHIFT,
435 DA7213_HPF_EN_MAX, DA7213_NO_INVERT),
436 SOC_ENUM("ADC HPF Cutoff", da7213_adc_audio_hpf_corner),
437 SOC_SINGLE("ADC Voice Mode Switch", DA7213_ADC_FILTERS1,
438 DA7213_VOICE_EN_SHIFT, DA7213_VOICE_EN_MAX,
439 DA7213_NO_INVERT),
440 SOC_ENUM("ADC Voice Cutoff", da7213_adc_voice_hpf_corner),
441
442 SOC_SINGLE("DAC HPF Switch", DA7213_DAC_FILTERS1, DA7213_HPF_EN_SHIFT,
443 DA7213_HPF_EN_MAX, DA7213_NO_INVERT),
444 SOC_ENUM("DAC HPF Cutoff", da7213_dac_audio_hpf_corner),
445 SOC_SINGLE("DAC Voice Mode Switch", DA7213_DAC_FILTERS1,
446 DA7213_VOICE_EN_SHIFT, DA7213_VOICE_EN_MAX,
447 DA7213_NO_INVERT),
448 SOC_ENUM("DAC Voice Cutoff", da7213_dac_voice_hpf_corner),
449
450 /* Mute controls */
451 SOC_SINGLE("Mic 1 Switch", DA7213_MIC_1_CTRL, DA7213_MUTE_EN_SHIFT,
452 DA7213_MUTE_EN_MAX, DA7213_INVERT),
453 SOC_SINGLE("Mic 2 Switch", DA7213_MIC_2_CTRL, DA7213_MUTE_EN_SHIFT,
454 DA7213_MUTE_EN_MAX, DA7213_INVERT),
455 SOC_DOUBLE_R("Aux Switch", DA7213_AUX_L_CTRL, DA7213_AUX_R_CTRL,
456 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
457 SOC_DOUBLE_R("Mixin PGA Switch", DA7213_MIXIN_L_CTRL,
458 DA7213_MIXIN_R_CTRL, DA7213_MUTE_EN_SHIFT,
459 DA7213_MUTE_EN_MAX, DA7213_INVERT),
460 SOC_DOUBLE_R("ADC Switch", DA7213_ADC_L_CTRL, DA7213_ADC_R_CTRL,
461 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
462 SOC_DOUBLE_R("Headphone Switch", DA7213_HP_L_CTRL, DA7213_HP_R_CTRL,
463 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
464 SOC_SINGLE("Lineout Switch", DA7213_LINE_CTRL, DA7213_MUTE_EN_SHIFT,
465 DA7213_MUTE_EN_MAX, DA7213_INVERT),
466 SOC_SINGLE("DAC Soft Mute Switch", DA7213_DAC_FILTERS5,
467 DA7213_DAC_SOFTMUTE_EN_SHIFT, DA7213_DAC_SOFTMUTE_EN_MAX,
468 DA7213_NO_INVERT),
469 SOC_ENUM("DAC Soft Mute Rate", da7213_dac_soft_mute_rate),
470
471 /* Zero Cross controls */
472 SOC_DOUBLE_R("Aux ZC Switch", DA7213_AUX_L_CTRL, DA7213_AUX_R_CTRL,
473 DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX, DA7213_NO_INVERT),
474 SOC_DOUBLE_R("Mixin PGA ZC Switch", DA7213_MIXIN_L_CTRL,
475 DA7213_MIXIN_R_CTRL, DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX,
476 DA7213_NO_INVERT),
477 SOC_DOUBLE_R("Headphone ZC Switch", DA7213_HP_L_CTRL, DA7213_HP_R_CTRL,
478 DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX, DA7213_NO_INVERT),
479
480 /* Gain Ramping controls */
481 SOC_DOUBLE_R("Aux Gain Ramping Switch", DA7213_AUX_L_CTRL,
482 DA7213_AUX_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
483 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
484 SOC_DOUBLE_R("Mixin Gain Ramping Switch", DA7213_MIXIN_L_CTRL,
485 DA7213_MIXIN_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
486 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
487 SOC_DOUBLE_R("ADC Gain Ramping Switch", DA7213_ADC_L_CTRL,
488 DA7213_ADC_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
489 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
490 SOC_DOUBLE_R("DAC Gain Ramping Switch", DA7213_DAC_L_CTRL,
491 DA7213_DAC_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
492 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
493 SOC_DOUBLE_R("Headphone Gain Ramping Switch", DA7213_HP_L_CTRL,
494 DA7213_HP_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
495 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
496 SOC_SINGLE("Lineout Gain Ramping Switch", DA7213_LINE_CTRL,
497 DA7213_GAIN_RAMP_EN_SHIFT, DA7213_GAIN_RAMP_EN_MAX,
498 DA7213_NO_INVERT),
499 SOC_ENUM("Gain Ramping Rate", da7213_gain_ramp_rate),
500
501 /* DAC Noise Gate controls */
502 SOC_SINGLE("DAC NG Switch", DA7213_DAC_NG_CTRL, DA7213_DAC_NG_EN_SHIFT,
503 DA7213_DAC_NG_EN_MAX, DA7213_NO_INVERT),
504 SOC_ENUM("DAC NG Setup Time", da7213_dac_ng_setup_time),
505 SOC_ENUM("DAC NG Rampup Rate", da7213_dac_ng_rampup_rate),
506 SOC_ENUM("DAC NG Rampdown Rate", da7213_dac_ng_rampdown_rate),
507 SOC_SINGLE("DAC NG OFF Threshold", DA7213_DAC_NG_OFF_THRESHOLD,
508 DA7213_DAC_NG_THRESHOLD_SHIFT, DA7213_DAC_NG_THRESHOLD_MAX,
509 DA7213_NO_INVERT),
510 SOC_SINGLE("DAC NG ON Threshold", DA7213_DAC_NG_ON_THRESHOLD,
511 DA7213_DAC_NG_THRESHOLD_SHIFT, DA7213_DAC_NG_THRESHOLD_MAX,
512 DA7213_NO_INVERT),
513
514 /* DAC Routing & Inversion */
515 SOC_DOUBLE("DAC Mono Switch", DA7213_DIG_ROUTING_DAC,
516 DA7213_DAC_L_MONO_SHIFT, DA7213_DAC_R_MONO_SHIFT,
517 DA7213_DAC_MONO_MAX, DA7213_NO_INVERT),
518 SOC_DOUBLE("DAC Invert Switch", DA7213_DIG_CTRL, DA7213_DAC_L_INV_SHIFT,
519 DA7213_DAC_R_INV_SHIFT, DA7213_DAC_INV_MAX,
520 DA7213_NO_INVERT),
521
522 /* DMIC controls */
523 SOC_DOUBLE_R("DMIC Switch", DA7213_MIXIN_L_SELECT,
524 DA7213_MIXIN_R_SELECT, DA7213_DMIC_EN_SHIFT,
525 DA7213_DMIC_EN_MAX, DA7213_NO_INVERT),
526
527 /* ALC Controls */
528 SOC_DOUBLE_EXT("ALC Switch", DA7213_ALC_CTRL1, DA7213_ALC_L_EN_SHIFT,
529 DA7213_ALC_R_EN_SHIFT, DA7213_ALC_EN_MAX,
530 DA7213_NO_INVERT, snd_soc_get_volsw, da7213_put_alc_sw),
531 SOC_ENUM("ALC Attack Rate", da7213_alc_attack_rate),
532 SOC_ENUM("ALC Release Rate", da7213_alc_release_rate),
533 SOC_ENUM("ALC Hold Time", da7213_alc_hold_time),
534 /*
535 * Rate at which input signal envelope is tracked as the signal gets
536 * larger
537 */
538 SOC_ENUM("ALC Integ Attack Rate", da7213_alc_integ_attack_rate),
539 /*
540 * Rate at which input signal envelope is tracked as the signal gets
541 * smaller
542 */
543 SOC_ENUM("ALC Integ Release Rate", da7213_alc_integ_release_rate),
544 SOC_SINGLE_TLV("ALC Noise Threshold Volume", DA7213_ALC_NOISE,
545 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
546 DA7213_INVERT, alc_threshold_tlv),
547 SOC_SINGLE_TLV("ALC Min Threshold Volume", DA7213_ALC_TARGET_MIN,
548 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
549 DA7213_INVERT, alc_threshold_tlv),
550 SOC_SINGLE_TLV("ALC Max Threshold Volume", DA7213_ALC_TARGET_MAX,
551 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
552 DA7213_INVERT, alc_threshold_tlv),
553 SOC_SINGLE_TLV("ALC Max Attenuation Volume", DA7213_ALC_GAIN_LIMITS,
554 DA7213_ALC_ATTEN_MAX_SHIFT,
555 DA7213_ALC_ATTEN_GAIN_MAX_MAX, DA7213_NO_INVERT,
556 alc_gain_tlv),
557 SOC_SINGLE_TLV("ALC Max Gain Volume", DA7213_ALC_GAIN_LIMITS,
558 DA7213_ALC_GAIN_MAX_SHIFT, DA7213_ALC_ATTEN_GAIN_MAX_MAX,
559 DA7213_NO_INVERT, alc_gain_tlv),
560 SOC_SINGLE_TLV("ALC Min Analog Gain Volume", DA7213_ALC_ANA_GAIN_LIMITS,
561 DA7213_ALC_ANA_GAIN_MIN_SHIFT, DA7213_ALC_ANA_GAIN_MAX,
562 DA7213_NO_INVERT, alc_analog_gain_tlv),
563 SOC_SINGLE_TLV("ALC Max Analog Gain Volume", DA7213_ALC_ANA_GAIN_LIMITS,
564 DA7213_ALC_ANA_GAIN_MAX_SHIFT, DA7213_ALC_ANA_GAIN_MAX,
565 DA7213_NO_INVERT, alc_analog_gain_tlv),
566 SOC_SINGLE("ALC Anticlip Mode Switch", DA7213_ALC_ANTICLIP_CTRL,
567 DA7213_ALC_ANTICLIP_EN_SHIFT, DA7213_ALC_ANTICLIP_EN_MAX,
568 DA7213_NO_INVERT),
569 SOC_SINGLE("ALC Anticlip Level", DA7213_ALC_ANTICLIP_LEVEL,
570 DA7213_ALC_ANTICLIP_LEVEL_SHIFT,
571 DA7213_ALC_ANTICLIP_LEVEL_MAX, DA7213_NO_INVERT),
572};
573
574
575/*
576 * DAPM
577 */
578
579/*
580 * Enums
581 */
582
583/* MIC PGA source select */
584static const char * const da7213_mic_amp_in_sel_txt[] = {
585 "Differential", "MIC_P", "MIC_N"
586};
587
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100588static SOC_ENUM_SINGLE_DECL(da7213_mic_1_amp_in_sel,
589 DA7213_MIC_1_CTRL,
590 DA7213_MIC_AMP_IN_SEL_SHIFT,
591 da7213_mic_amp_in_sel_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000592static const struct snd_kcontrol_new da7213_mic_1_amp_in_sel_mux =
593 SOC_DAPM_ENUM("Mic 1 Amp Source MUX", da7213_mic_1_amp_in_sel);
594
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100595static SOC_ENUM_SINGLE_DECL(da7213_mic_2_amp_in_sel,
596 DA7213_MIC_2_CTRL,
597 DA7213_MIC_AMP_IN_SEL_SHIFT,
598 da7213_mic_amp_in_sel_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000599static const struct snd_kcontrol_new da7213_mic_2_amp_in_sel_mux =
600 SOC_DAPM_ENUM("Mic 2 Amp Source MUX", da7213_mic_2_amp_in_sel);
601
602/* DAI routing select */
603static const char * const da7213_dai_src_txt[] = {
604 "ADC Left", "ADC Right", "DAI Input Left", "DAI Input Right"
605};
606
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100607static SOC_ENUM_SINGLE_DECL(da7213_dai_l_src,
608 DA7213_DIG_ROUTING_DAI,
609 DA7213_DAI_L_SRC_SHIFT,
610 da7213_dai_src_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000611static const struct snd_kcontrol_new da7213_dai_l_src_mux =
612 SOC_DAPM_ENUM("DAI Left Source MUX", da7213_dai_l_src);
613
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100614static SOC_ENUM_SINGLE_DECL(da7213_dai_r_src,
615 DA7213_DIG_ROUTING_DAI,
616 DA7213_DAI_R_SRC_SHIFT,
617 da7213_dai_src_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000618static const struct snd_kcontrol_new da7213_dai_r_src_mux =
619 SOC_DAPM_ENUM("DAI Right Source MUX", da7213_dai_r_src);
620
621/* DAC routing select */
622static const char * const da7213_dac_src_txt[] = {
623 "ADC Output Left", "ADC Output Right", "DAI Input Left",
624 "DAI Input Right"
625};
626
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100627static SOC_ENUM_SINGLE_DECL(da7213_dac_l_src,
628 DA7213_DIG_ROUTING_DAC,
629 DA7213_DAC_L_SRC_SHIFT,
630 da7213_dac_src_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000631static const struct snd_kcontrol_new da7213_dac_l_src_mux =
632 SOC_DAPM_ENUM("DAC Left Source MUX", da7213_dac_l_src);
633
Takashi Iwaic99f8b22014-02-18 10:06:47 +0100634static SOC_ENUM_SINGLE_DECL(da7213_dac_r_src,
635 DA7213_DIG_ROUTING_DAC,
636 DA7213_DAC_R_SRC_SHIFT,
637 da7213_dac_src_txt);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000638static const struct snd_kcontrol_new da7213_dac_r_src_mux =
639 SOC_DAPM_ENUM("DAC Right Source MUX", da7213_dac_r_src);
640
641/*
642 * Mixer Controls
643 */
644
645/* Mixin Left */
646static const struct snd_kcontrol_new da7213_dapm_mixinl_controls[] = {
647 SOC_DAPM_SINGLE("Aux Left Switch", DA7213_MIXIN_L_SELECT,
648 DA7213_MIXIN_L_MIX_SELECT_AUX_L_SHIFT,
649 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
650 SOC_DAPM_SINGLE("Mic 1 Switch", DA7213_MIXIN_L_SELECT,
651 DA7213_MIXIN_L_MIX_SELECT_MIC_1_SHIFT,
652 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
653 SOC_DAPM_SINGLE("Mic 2 Switch", DA7213_MIXIN_L_SELECT,
654 DA7213_MIXIN_L_MIX_SELECT_MIC_2_SHIFT,
655 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
656 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXIN_L_SELECT,
657 DA7213_MIXIN_L_MIX_SELECT_MIXIN_R_SHIFT,
658 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
659};
660
661/* Mixin Right */
662static const struct snd_kcontrol_new da7213_dapm_mixinr_controls[] = {
663 SOC_DAPM_SINGLE("Aux Right Switch", DA7213_MIXIN_R_SELECT,
664 DA7213_MIXIN_R_MIX_SELECT_AUX_R_SHIFT,
665 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
666 SOC_DAPM_SINGLE("Mic 2 Switch", DA7213_MIXIN_R_SELECT,
667 DA7213_MIXIN_R_MIX_SELECT_MIC_2_SHIFT,
668 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
669 SOC_DAPM_SINGLE("Mic 1 Switch", DA7213_MIXIN_R_SELECT,
670 DA7213_MIXIN_R_MIX_SELECT_MIC_1_SHIFT,
671 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
672 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXIN_R_SELECT,
673 DA7213_MIXIN_R_MIX_SELECT_MIXIN_L_SHIFT,
674 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
675};
676
677/* Mixout Left */
678static const struct snd_kcontrol_new da7213_dapm_mixoutl_controls[] = {
679 SOC_DAPM_SINGLE("Aux Left Switch", DA7213_MIXOUT_L_SELECT,
680 DA7213_MIXOUT_L_MIX_SELECT_AUX_L_SHIFT,
681 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
682 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXOUT_L_SELECT,
683 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_SHIFT,
684 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
685 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXOUT_L_SELECT,
686 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_SHIFT,
687 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
688 SOC_DAPM_SINGLE("DAC Left Switch", DA7213_MIXOUT_L_SELECT,
689 DA7213_MIXOUT_L_MIX_SELECT_DAC_L_SHIFT,
690 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
691 SOC_DAPM_SINGLE("Aux Left Invert Switch", DA7213_MIXOUT_L_SELECT,
692 DA7213_MIXOUT_L_MIX_SELECT_AUX_L_INVERTED_SHIFT,
693 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
694 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA7213_MIXOUT_L_SELECT,
695 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_INVERTED_SHIFT,
696 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
697 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA7213_MIXOUT_L_SELECT,
698 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_INVERTED_SHIFT,
699 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
700};
701
702/* Mixout Right */
703static const struct snd_kcontrol_new da7213_dapm_mixoutr_controls[] = {
704 SOC_DAPM_SINGLE("Aux Right Switch", DA7213_MIXOUT_R_SELECT,
705 DA7213_MIXOUT_R_MIX_SELECT_AUX_R_SHIFT,
706 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
707 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXOUT_R_SELECT,
708 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_SHIFT,
709 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
710 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXOUT_R_SELECT,
711 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_SHIFT,
712 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
713 SOC_DAPM_SINGLE("DAC Right Switch", DA7213_MIXOUT_R_SELECT,
714 DA7213_MIXOUT_R_MIX_SELECT_DAC_R_SHIFT,
715 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
716 SOC_DAPM_SINGLE("Aux Right Invert Switch", DA7213_MIXOUT_R_SELECT,
717 DA7213_MIXOUT_R_MIX_SELECT_AUX_R_INVERTED_SHIFT,
718 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
719 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA7213_MIXOUT_R_SELECT,
720 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_INVERTED_SHIFT,
721 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
722 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA7213_MIXOUT_R_SELECT,
723 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_INVERTED_SHIFT,
724 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
725};
726
727
728/*
Adam Thomsona0d5cae2016-05-10 16:11:04 +0100729 * DAPM Events
730 */
731
732static int da7213_dai_event(struct snd_soc_dapm_widget *w,
733 struct snd_kcontrol *kcontrol, int event)
734{
735 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
736 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
737
738 switch (event) {
739 case SND_SOC_DAPM_PRE_PMU:
740 /* Enable DAI clks for master mode */
741 if (da7213->master)
742 snd_soc_update_bits(codec, DA7213_DAI_CLK_MODE,
743 DA7213_DAI_CLK_EN_MASK,
744 DA7213_DAI_CLK_EN_MASK);
745 return 0;
746 case SND_SOC_DAPM_POST_PMD:
747 /* Disable DAI clks if in master mode */
748 if (da7213->master)
749 snd_soc_update_bits(codec, DA7213_DAI_CLK_MODE,
750 DA7213_DAI_CLK_EN_MASK, 0);
751 return 0;
752 default:
753 return -EINVAL;
754 }
755}
756
757
758/*
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000759 * DAPM widgets
760 */
761
762static const struct snd_soc_dapm_widget da7213_dapm_widgets[] = {
763 /*
764 * Input & Output
765 */
766
767 /* Use a supply here as this controls both input & output DAIs */
768 SND_SOC_DAPM_SUPPLY("DAI", DA7213_DAI_CTRL, DA7213_DAI_EN_SHIFT,
Adam Thomsona0d5cae2016-05-10 16:11:04 +0100769 DA7213_NO_INVERT, da7213_dai_event,
770 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000771
772 /*
773 * Input
774 */
775
776 /* Input Lines */
777 SND_SOC_DAPM_INPUT("MIC1"),
778 SND_SOC_DAPM_INPUT("MIC2"),
779 SND_SOC_DAPM_INPUT("AUXL"),
780 SND_SOC_DAPM_INPUT("AUXR"),
781
782 /* MUXs for Mic PGA source selection */
783 SND_SOC_DAPM_MUX("Mic 1 Amp Source MUX", SND_SOC_NOPM, 0, 0,
784 &da7213_mic_1_amp_in_sel_mux),
785 SND_SOC_DAPM_MUX("Mic 2 Amp Source MUX", SND_SOC_NOPM, 0, 0,
786 &da7213_mic_2_amp_in_sel_mux),
787
788 /* Input PGAs */
789 SND_SOC_DAPM_PGA("Mic 1 PGA", DA7213_MIC_1_CTRL, DA7213_AMP_EN_SHIFT,
790 DA7213_NO_INVERT, NULL, 0),
791 SND_SOC_DAPM_PGA("Mic 2 PGA", DA7213_MIC_2_CTRL, DA7213_AMP_EN_SHIFT,
792 DA7213_NO_INVERT, NULL, 0),
793 SND_SOC_DAPM_PGA("Aux Left PGA", DA7213_AUX_L_CTRL, DA7213_AMP_EN_SHIFT,
794 DA7213_NO_INVERT, NULL, 0),
795 SND_SOC_DAPM_PGA("Aux Right PGA", DA7213_AUX_R_CTRL,
796 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
797 SND_SOC_DAPM_PGA("Mixin Left PGA", DA7213_MIXIN_L_CTRL,
798 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
799 SND_SOC_DAPM_PGA("Mixin Right PGA", DA7213_MIXIN_R_CTRL,
800 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
801
802 /* Mic Biases */
803 SND_SOC_DAPM_SUPPLY("Mic Bias 1", DA7213_MICBIAS_CTRL,
804 DA7213_MICBIAS1_EN_SHIFT, DA7213_NO_INVERT,
805 NULL, 0),
806 SND_SOC_DAPM_SUPPLY("Mic Bias 2", DA7213_MICBIAS_CTRL,
807 DA7213_MICBIAS2_EN_SHIFT, DA7213_NO_INVERT,
808 NULL, 0),
809
810 /* Input Mixers */
811 SND_SOC_DAPM_MIXER("Mixin Left", SND_SOC_NOPM, 0, 0,
812 &da7213_dapm_mixinl_controls[0],
813 ARRAY_SIZE(da7213_dapm_mixinl_controls)),
814 SND_SOC_DAPM_MIXER("Mixin Right", SND_SOC_NOPM, 0, 0,
815 &da7213_dapm_mixinr_controls[0],
816 ARRAY_SIZE(da7213_dapm_mixinr_controls)),
817
818 /* ADCs */
819 SND_SOC_DAPM_ADC("ADC Left", NULL, DA7213_ADC_L_CTRL,
820 DA7213_ADC_EN_SHIFT, DA7213_NO_INVERT),
821 SND_SOC_DAPM_ADC("ADC Right", NULL, DA7213_ADC_R_CTRL,
822 DA7213_ADC_EN_SHIFT, DA7213_NO_INVERT),
823
824 /* DAI */
825 SND_SOC_DAPM_MUX("DAI Left Source MUX", SND_SOC_NOPM, 0, 0,
826 &da7213_dai_l_src_mux),
827 SND_SOC_DAPM_MUX("DAI Right Source MUX", SND_SOC_NOPM, 0, 0,
828 &da7213_dai_r_src_mux),
829 SND_SOC_DAPM_AIF_OUT("DAIOUTL", "Capture", 0, SND_SOC_NOPM, 0, 0),
830 SND_SOC_DAPM_AIF_OUT("DAIOUTR", "Capture", 1, SND_SOC_NOPM, 0, 0),
831
832 /*
833 * Output
834 */
835
836 /* DAI */
837 SND_SOC_DAPM_AIF_IN("DAIINL", "Playback", 0, SND_SOC_NOPM, 0, 0),
838 SND_SOC_DAPM_AIF_IN("DAIINR", "Playback", 1, SND_SOC_NOPM, 0, 0),
839 SND_SOC_DAPM_MUX("DAC Left Source MUX", SND_SOC_NOPM, 0, 0,
840 &da7213_dac_l_src_mux),
841 SND_SOC_DAPM_MUX("DAC Right Source MUX", SND_SOC_NOPM, 0, 0,
842 &da7213_dac_r_src_mux),
843
844 /* DACs */
845 SND_SOC_DAPM_DAC("DAC Left", NULL, DA7213_DAC_L_CTRL,
846 DA7213_DAC_EN_SHIFT, DA7213_NO_INVERT),
847 SND_SOC_DAPM_DAC("DAC Right", NULL, DA7213_DAC_R_CTRL,
848 DA7213_DAC_EN_SHIFT, DA7213_NO_INVERT),
849
850 /* Output Mixers */
851 SND_SOC_DAPM_MIXER("Mixout Left", SND_SOC_NOPM, 0, 0,
852 &da7213_dapm_mixoutl_controls[0],
853 ARRAY_SIZE(da7213_dapm_mixoutl_controls)),
854 SND_SOC_DAPM_MIXER("Mixout Right", SND_SOC_NOPM, 0, 0,
855 &da7213_dapm_mixoutr_controls[0],
856 ARRAY_SIZE(da7213_dapm_mixoutr_controls)),
857
858 /* Output PGAs */
859 SND_SOC_DAPM_PGA("Mixout Left PGA", DA7213_MIXOUT_L_CTRL,
860 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
861 SND_SOC_DAPM_PGA("Mixout Right PGA", DA7213_MIXOUT_R_CTRL,
862 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
863 SND_SOC_DAPM_PGA("Lineout PGA", DA7213_LINE_CTRL, DA7213_AMP_EN_SHIFT,
864 DA7213_NO_INVERT, NULL, 0),
865 SND_SOC_DAPM_PGA("Headphone Left PGA", DA7213_HP_L_CTRL,
866 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
867 SND_SOC_DAPM_PGA("Headphone Right PGA", DA7213_HP_R_CTRL,
868 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
869
870 /* Charge Pump */
871 SND_SOC_DAPM_SUPPLY("Charge Pump", DA7213_CP_CTRL, DA7213_CP_EN_SHIFT,
872 DA7213_NO_INVERT, NULL, 0),
873
874 /* Output Lines */
875 SND_SOC_DAPM_OUTPUT("HPL"),
876 SND_SOC_DAPM_OUTPUT("HPR"),
877 SND_SOC_DAPM_OUTPUT("LINE"),
878};
879
880
881/*
882 * DAPM audio route definition
883 */
884
885static const struct snd_soc_dapm_route da7213_audio_map[] = {
886 /* Dest Connecting Widget source */
887
888 /* Input path */
889 {"MIC1", NULL, "Mic Bias 1"},
890 {"MIC2", NULL, "Mic Bias 2"},
891
892 {"Mic 1 Amp Source MUX", "Differential", "MIC1"},
893 {"Mic 1 Amp Source MUX", "MIC_P", "MIC1"},
894 {"Mic 1 Amp Source MUX", "MIC_N", "MIC1"},
895
896 {"Mic 2 Amp Source MUX", "Differential", "MIC2"},
897 {"Mic 2 Amp Source MUX", "MIC_P", "MIC2"},
898 {"Mic 2 Amp Source MUX", "MIC_N", "MIC2"},
899
900 {"Mic 1 PGA", NULL, "Mic 1 Amp Source MUX"},
901 {"Mic 2 PGA", NULL, "Mic 2 Amp Source MUX"},
902
903 {"Aux Left PGA", NULL, "AUXL"},
904 {"Aux Right PGA", NULL, "AUXR"},
905
906 {"Mixin Left", "Aux Left Switch", "Aux Left PGA"},
907 {"Mixin Left", "Mic 1 Switch", "Mic 1 PGA"},
908 {"Mixin Left", "Mic 2 Switch", "Mic 2 PGA"},
909 {"Mixin Left", "Mixin Right Switch", "Mixin Right PGA"},
910
911 {"Mixin Right", "Aux Right Switch", "Aux Right PGA"},
912 {"Mixin Right", "Mic 2 Switch", "Mic 2 PGA"},
913 {"Mixin Right", "Mic 1 Switch", "Mic 1 PGA"},
914 {"Mixin Right", "Mixin Left Switch", "Mixin Left PGA"},
915
916 {"Mixin Left PGA", NULL, "Mixin Left"},
917 {"ADC Left", NULL, "Mixin Left PGA"},
918
919 {"Mixin Right PGA", NULL, "Mixin Right"},
920 {"ADC Right", NULL, "Mixin Right PGA"},
921
922 {"DAI Left Source MUX", "ADC Left", "ADC Left"},
923 {"DAI Left Source MUX", "ADC Right", "ADC Right"},
924 {"DAI Left Source MUX", "DAI Input Left", "DAIINL"},
925 {"DAI Left Source MUX", "DAI Input Right", "DAIINR"},
926
927 {"DAI Right Source MUX", "ADC Left", "ADC Left"},
928 {"DAI Right Source MUX", "ADC Right", "ADC Right"},
929 {"DAI Right Source MUX", "DAI Input Left", "DAIINL"},
930 {"DAI Right Source MUX", "DAI Input Right", "DAIINR"},
931
932 {"DAIOUTL", NULL, "DAI Left Source MUX"},
933 {"DAIOUTR", NULL, "DAI Right Source MUX"},
934
935 {"DAIOUTL", NULL, "DAI"},
936 {"DAIOUTR", NULL, "DAI"},
937
938 /* Output path */
939 {"DAIINL", NULL, "DAI"},
940 {"DAIINR", NULL, "DAI"},
941
942 {"DAC Left Source MUX", "ADC Output Left", "ADC Left"},
943 {"DAC Left Source MUX", "ADC Output Right", "ADC Right"},
944 {"DAC Left Source MUX", "DAI Input Left", "DAIINL"},
945 {"DAC Left Source MUX", "DAI Input Right", "DAIINR"},
946
947 {"DAC Right Source MUX", "ADC Output Left", "ADC Left"},
948 {"DAC Right Source MUX", "ADC Output Right", "ADC Right"},
949 {"DAC Right Source MUX", "DAI Input Left", "DAIINL"},
950 {"DAC Right Source MUX", "DAI Input Right", "DAIINR"},
951
952 {"DAC Left", NULL, "DAC Left Source MUX"},
953 {"DAC Right", NULL, "DAC Right Source MUX"},
954
955 {"Mixout Left", "Aux Left Switch", "Aux Left PGA"},
956 {"Mixout Left", "Mixin Left Switch", "Mixin Left PGA"},
957 {"Mixout Left", "Mixin Right Switch", "Mixin Right PGA"},
958 {"Mixout Left", "DAC Left Switch", "DAC Left"},
959 {"Mixout Left", "Aux Left Invert Switch", "Aux Left PGA"},
960 {"Mixout Left", "Mixin Left Invert Switch", "Mixin Left PGA"},
961 {"Mixout Left", "Mixin Right Invert Switch", "Mixin Right PGA"},
962
963 {"Mixout Right", "Aux Right Switch", "Aux Right PGA"},
964 {"Mixout Right", "Mixin Right Switch", "Mixin Right PGA"},
965 {"Mixout Right", "Mixin Left Switch", "Mixin Left PGA"},
966 {"Mixout Right", "DAC Right Switch", "DAC Right"},
967 {"Mixout Right", "Aux Right Invert Switch", "Aux Right PGA"},
968 {"Mixout Right", "Mixin Right Invert Switch", "Mixin Right PGA"},
969 {"Mixout Right", "Mixin Left Invert Switch", "Mixin Left PGA"},
970
971 {"Mixout Left PGA", NULL, "Mixout Left"},
972 {"Mixout Right PGA", NULL, "Mixout Right"},
973
974 {"Headphone Left PGA", NULL, "Mixout Left PGA"},
975 {"Headphone Left PGA", NULL, "Charge Pump"},
976 {"HPL", NULL, "Headphone Left PGA"},
977
978 {"Headphone Right PGA", NULL, "Mixout Right PGA"},
979 {"Headphone Right PGA", NULL, "Charge Pump"},
980 {"HPR", NULL, "Headphone Right PGA"},
981
982 {"Lineout PGA", NULL, "Mixout Right PGA"},
983 {"LINE", NULL, "Lineout PGA"},
984};
985
Axel Linc418a842015-07-05 17:48:29 +0800986static const struct reg_default da7213_reg_defaults[] = {
Adam Thomsonef5c2eb2013-02-14 12:02:51 +0000987 { DA7213_DIG_ROUTING_DAI, 0x10 },
988 { DA7213_SR, 0x0A },
989 { DA7213_REFERENCES, 0x80 },
990 { DA7213_PLL_FRAC_TOP, 0x00 },
991 { DA7213_PLL_FRAC_BOT, 0x00 },
992 { DA7213_PLL_INTEGER, 0x20 },
993 { DA7213_PLL_CTRL, 0x0C },
994 { DA7213_DAI_CLK_MODE, 0x01 },
995 { DA7213_DAI_CTRL, 0x08 },
996 { DA7213_DIG_ROUTING_DAC, 0x32 },
997 { DA7213_AUX_L_GAIN, 0x35 },
998 { DA7213_AUX_R_GAIN, 0x35 },
999 { DA7213_MIXIN_L_SELECT, 0x00 },
1000 { DA7213_MIXIN_R_SELECT, 0x00 },
1001 { DA7213_MIXIN_L_GAIN, 0x03 },
1002 { DA7213_MIXIN_R_GAIN, 0x03 },
1003 { DA7213_ADC_L_GAIN, 0x6F },
1004 { DA7213_ADC_R_GAIN, 0x6F },
1005 { DA7213_ADC_FILTERS1, 0x80 },
1006 { DA7213_MIC_1_GAIN, 0x01 },
1007 { DA7213_MIC_2_GAIN, 0x01 },
1008 { DA7213_DAC_FILTERS5, 0x00 },
1009 { DA7213_DAC_FILTERS2, 0x88 },
1010 { DA7213_DAC_FILTERS3, 0x88 },
1011 { DA7213_DAC_FILTERS4, 0x08 },
1012 { DA7213_DAC_FILTERS1, 0x80 },
1013 { DA7213_DAC_L_GAIN, 0x6F },
1014 { DA7213_DAC_R_GAIN, 0x6F },
1015 { DA7213_CP_CTRL, 0x61 },
1016 { DA7213_HP_L_GAIN, 0x39 },
1017 { DA7213_HP_R_GAIN, 0x39 },
1018 { DA7213_LINE_GAIN, 0x30 },
1019 { DA7213_MIXOUT_L_SELECT, 0x00 },
1020 { DA7213_MIXOUT_R_SELECT, 0x00 },
1021 { DA7213_SYSTEM_MODES_INPUT, 0x00 },
1022 { DA7213_SYSTEM_MODES_OUTPUT, 0x00 },
1023 { DA7213_AUX_L_CTRL, 0x44 },
1024 { DA7213_AUX_R_CTRL, 0x44 },
1025 { DA7213_MICBIAS_CTRL, 0x11 },
1026 { DA7213_MIC_1_CTRL, 0x40 },
1027 { DA7213_MIC_2_CTRL, 0x40 },
1028 { DA7213_MIXIN_L_CTRL, 0x40 },
1029 { DA7213_MIXIN_R_CTRL, 0x40 },
1030 { DA7213_ADC_L_CTRL, 0x40 },
1031 { DA7213_ADC_R_CTRL, 0x40 },
1032 { DA7213_DAC_L_CTRL, 0x48 },
1033 { DA7213_DAC_R_CTRL, 0x40 },
1034 { DA7213_HP_L_CTRL, 0x41 },
1035 { DA7213_HP_R_CTRL, 0x40 },
1036 { DA7213_LINE_CTRL, 0x40 },
1037 { DA7213_MIXOUT_L_CTRL, 0x10 },
1038 { DA7213_MIXOUT_R_CTRL, 0x10 },
1039 { DA7213_LDO_CTRL, 0x00 },
1040 { DA7213_IO_CTRL, 0x00 },
1041 { DA7213_GAIN_RAMP_CTRL, 0x00},
1042 { DA7213_MIC_CONFIG, 0x00 },
1043 { DA7213_PC_COUNT, 0x00 },
1044 { DA7213_CP_VOL_THRESHOLD1, 0x32 },
1045 { DA7213_CP_DELAY, 0x95 },
1046 { DA7213_CP_DETECTOR, 0x00 },
1047 { DA7213_DAI_OFFSET, 0x00 },
1048 { DA7213_DIG_CTRL, 0x00 },
1049 { DA7213_ALC_CTRL2, 0x00 },
1050 { DA7213_ALC_CTRL3, 0x00 },
1051 { DA7213_ALC_NOISE, 0x3F },
1052 { DA7213_ALC_TARGET_MIN, 0x3F },
1053 { DA7213_ALC_TARGET_MAX, 0x00 },
1054 { DA7213_ALC_GAIN_LIMITS, 0xFF },
1055 { DA7213_ALC_ANA_GAIN_LIMITS, 0x71 },
1056 { DA7213_ALC_ANTICLIP_CTRL, 0x00 },
1057 { DA7213_ALC_ANTICLIP_LEVEL, 0x00 },
1058 { DA7213_ALC_OFFSET_MAN_M_L, 0x00 },
1059 { DA7213_ALC_OFFSET_MAN_U_L, 0x00 },
1060 { DA7213_ALC_OFFSET_MAN_M_R, 0x00 },
1061 { DA7213_ALC_OFFSET_MAN_U_R, 0x00 },
1062 { DA7213_ALC_CIC_OP_LVL_CTRL, 0x00 },
1063 { DA7213_DAC_NG_SETUP_TIME, 0x00 },
1064 { DA7213_DAC_NG_OFF_THRESHOLD, 0x00 },
1065 { DA7213_DAC_NG_ON_THRESHOLD, 0x00 },
1066 { DA7213_DAC_NG_CTRL, 0x00 },
1067};
1068
1069static bool da7213_volatile_register(struct device *dev, unsigned int reg)
1070{
1071 switch (reg) {
1072 case DA7213_STATUS1:
1073 case DA7213_PLL_STATUS:
1074 case DA7213_AUX_L_GAIN_STATUS:
1075 case DA7213_AUX_R_GAIN_STATUS:
1076 case DA7213_MIC_1_GAIN_STATUS:
1077 case DA7213_MIC_2_GAIN_STATUS:
1078 case DA7213_MIXIN_L_GAIN_STATUS:
1079 case DA7213_MIXIN_R_GAIN_STATUS:
1080 case DA7213_ADC_L_GAIN_STATUS:
1081 case DA7213_ADC_R_GAIN_STATUS:
1082 case DA7213_DAC_L_GAIN_STATUS:
1083 case DA7213_DAC_R_GAIN_STATUS:
1084 case DA7213_HP_L_GAIN_STATUS:
1085 case DA7213_HP_R_GAIN_STATUS:
1086 case DA7213_LINE_GAIN_STATUS:
1087 case DA7213_ALC_CTRL1:
1088 case DA7213_ALC_OFFSET_AUTO_M_L:
1089 case DA7213_ALC_OFFSET_AUTO_U_L:
1090 case DA7213_ALC_OFFSET_AUTO_M_R:
1091 case DA7213_ALC_OFFSET_AUTO_U_R:
1092 case DA7213_ALC_CIC_OP_LVL_DATA:
1093 return 1;
1094 default:
1095 return 0;
1096 }
1097}
1098
1099static int da7213_hw_params(struct snd_pcm_substream *substream,
1100 struct snd_pcm_hw_params *params,
1101 struct snd_soc_dai *dai)
1102{
1103 struct snd_soc_codec *codec = dai->codec;
1104 u8 dai_ctrl = 0;
1105 u8 fs;
1106
1107 /* Set DAI format */
Mark Browne7610742014-01-08 19:49:51 +00001108 switch (params_width(params)) {
1109 case 16:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001110 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S16_LE;
1111 break;
Mark Browne7610742014-01-08 19:49:51 +00001112 case 20:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001113 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S20_LE;
1114 break;
Mark Browne7610742014-01-08 19:49:51 +00001115 case 24:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001116 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S24_LE;
1117 break;
Mark Browne7610742014-01-08 19:49:51 +00001118 case 32:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001119 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S32_LE;
1120 break;
1121 default:
1122 return -EINVAL;
1123 }
1124
1125 /* Set sampling rate */
1126 switch (params_rate(params)) {
1127 case 8000:
1128 fs = DA7213_SR_8000;
1129 break;
1130 case 11025:
1131 fs = DA7213_SR_11025;
1132 break;
1133 case 12000:
1134 fs = DA7213_SR_12000;
1135 break;
1136 case 16000:
1137 fs = DA7213_SR_16000;
1138 break;
1139 case 22050:
1140 fs = DA7213_SR_22050;
1141 break;
1142 case 32000:
1143 fs = DA7213_SR_32000;
1144 break;
1145 case 44100:
1146 fs = DA7213_SR_44100;
1147 break;
1148 case 48000:
1149 fs = DA7213_SR_48000;
1150 break;
1151 case 88200:
1152 fs = DA7213_SR_88200;
1153 break;
1154 case 96000:
1155 fs = DA7213_SR_96000;
1156 break;
1157 default:
1158 return -EINVAL;
1159 }
1160
1161 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_WORD_LENGTH_MASK,
1162 dai_ctrl);
1163 snd_soc_write(codec, DA7213_SR, fs);
1164
1165 return 0;
1166}
1167
1168static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1169{
1170 struct snd_soc_codec *codec = codec_dai->codec;
1171 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1172 u8 dai_clk_mode = 0, dai_ctrl = 0;
1173
1174 /* Set master/slave mode */
1175 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1176 case SND_SOC_DAIFMT_CBM_CFM:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001177 da7213->master = true;
1178 break;
1179 case SND_SOC_DAIFMT_CBS_CFS:
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001180 da7213->master = false;
1181 break;
1182 default:
1183 return -EINVAL;
1184 }
1185
1186 /* Set clock normal/inverted */
1187 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1188 case SND_SOC_DAIFMT_NB_NF:
1189 break;
1190 case SND_SOC_DAIFMT_NB_IF:
1191 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV;
1192 break;
1193 case SND_SOC_DAIFMT_IB_NF:
1194 dai_clk_mode |= DA7213_DAI_CLK_POL_INV;
1195 break;
1196 case SND_SOC_DAIFMT_IB_IF:
1197 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV | DA7213_DAI_CLK_POL_INV;
1198 break;
1199 default:
1200 return -EINVAL;
1201 }
1202
1203 /* Only I2S is supported */
1204 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1205 case SND_SOC_DAIFMT_I2S:
1206 dai_ctrl |= DA7213_DAI_FORMAT_I2S_MODE;
1207 break;
1208 case SND_SOC_DAIFMT_LEFT_J:
1209 dai_ctrl |= DA7213_DAI_FORMAT_LEFT_J;
1210 break;
1211 case SND_SOC_DAIFMT_RIGHT_J:
1212 dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J;
1213 break;
1214 default:
1215 return -EINVAL;
1216 }
1217
1218 /* By default only 32 BCLK per WCLK is supported */
1219 dai_clk_mode |= DA7213_DAI_BCLKS_PER_WCLK_32;
1220
1221 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode);
1222 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK,
1223 dai_ctrl);
1224
1225 return 0;
1226}
1227
1228static int da7213_mute(struct snd_soc_dai *dai, int mute)
1229{
1230 struct snd_soc_codec *codec = dai->codec;
1231
1232 if (mute) {
1233 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1234 DA7213_MUTE_EN, DA7213_MUTE_EN);
1235 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1236 DA7213_MUTE_EN, DA7213_MUTE_EN);
1237 } else {
1238 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1239 DA7213_MUTE_EN, 0);
1240 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1241 DA7213_MUTE_EN, 0);
1242 }
1243
1244 return 0;
1245}
1246
1247#define DA7213_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1248 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1249
1250static int da7213_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1251 int clk_id, unsigned int freq, int dir)
1252{
1253 struct snd_soc_codec *codec = codec_dai->codec;
1254 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
Adam Thomson6e7c4442015-10-07 14:27:11 +01001255 int ret = 0;
1256
1257 if ((da7213->clk_src == clk_id) && (da7213->mclk_rate == freq))
1258 return 0;
1259
1260 if (((freq < 5000000) && (freq != 32768)) || (freq > 54000000)) {
1261 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
1262 freq);
1263 return -EINVAL;
1264 }
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001265
1266 switch (clk_id) {
1267 case DA7213_CLKSRC_MCLK:
Adam Thomson6e7c4442015-10-07 14:27:11 +01001268 da7213->mclk_squarer_en = false;
1269 break;
1270 case DA7213_CLKSRC_MCLK_SQR:
1271 da7213->mclk_squarer_en = true;
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001272 break;
1273 default:
1274 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
1275 return -EINVAL;
1276 }
Adam Thomson6e7c4442015-10-07 14:27:11 +01001277
1278 da7213->clk_src = clk_id;
1279
1280 if (da7213->mclk) {
1281 freq = clk_round_rate(da7213->mclk, freq);
1282 ret = clk_set_rate(da7213->mclk, freq);
1283 if (ret) {
1284 dev_err(codec_dai->dev, "Failed to set clock rate %d\n",
1285 freq);
1286 return ret;
1287 }
1288 }
1289
1290 da7213->mclk_rate = freq;
1291
1292 return 0;
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001293}
1294
1295/* Supported PLL input frequencies are 5MHz - 54MHz. */
1296static int da7213_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1297 int source, unsigned int fref, unsigned int fout)
1298{
1299 struct snd_soc_codec *codec = codec_dai->codec;
1300 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1301
1302 u8 pll_ctrl, indiv_bits, indiv;
1303 u8 pll_frac_top, pll_frac_bot, pll_integer;
1304 u32 freq_ref;
1305 u64 frac_div;
1306
1307 /* Reset PLL configuration */
1308 snd_soc_write(codec, DA7213_PLL_CTRL, 0);
1309
1310 pll_ctrl = 0;
1311
1312 /* Workout input divider based on MCLK rate */
1313 if ((da7213->mclk_rate == 32768) && (source == DA7213_SYSCLK_PLL)) {
1314 /* 32KHz PLL Mode */
1315 indiv_bits = DA7213_PLL_INDIV_10_20_MHZ;
1316 indiv = DA7213_PLL_INDIV_10_20_MHZ_VAL;
1317 freq_ref = 3750000;
1318 pll_ctrl |= DA7213_PLL_32K_MODE;
1319 } else {
1320 /* 5 - 54MHz MCLK */
1321 if (da7213->mclk_rate < 5000000) {
1322 goto pll_err;
1323 } else if (da7213->mclk_rate <= 10000000) {
1324 indiv_bits = DA7213_PLL_INDIV_5_10_MHZ;
1325 indiv = DA7213_PLL_INDIV_5_10_MHZ_VAL;
1326 } else if (da7213->mclk_rate <= 20000000) {
1327 indiv_bits = DA7213_PLL_INDIV_10_20_MHZ;
1328 indiv = DA7213_PLL_INDIV_10_20_MHZ_VAL;
1329 } else if (da7213->mclk_rate <= 40000000) {
1330 indiv_bits = DA7213_PLL_INDIV_20_40_MHZ;
1331 indiv = DA7213_PLL_INDIV_20_40_MHZ_VAL;
1332 } else if (da7213->mclk_rate <= 54000000) {
1333 indiv_bits = DA7213_PLL_INDIV_40_54_MHZ;
1334 indiv = DA7213_PLL_INDIV_40_54_MHZ_VAL;
1335 } else {
1336 goto pll_err;
1337 }
1338 freq_ref = (da7213->mclk_rate / indiv);
1339 }
1340
1341 pll_ctrl |= indiv_bits;
1342
1343 /* PLL Bypass mode */
1344 if (source == DA7213_SYSCLK_MCLK) {
1345 snd_soc_write(codec, DA7213_PLL_CTRL, pll_ctrl);
1346 return 0;
1347 }
1348
1349 /*
1350 * If Codec is slave and SRM enabled,
1351 * freq_out is (98304000 + 90316800)/2 = 94310400
1352 */
1353 if (!da7213->master && da7213->srm_en) {
1354 fout = DA7213_PLL_FREQ_OUT_94310400;
1355 pll_ctrl |= DA7213_PLL_SRM_EN;
1356 }
1357
1358 /* Enable MCLK squarer if required */
1359 if (da7213->mclk_squarer_en)
1360 pll_ctrl |= DA7213_PLL_MCLK_SQR_EN;
1361
1362 /* Calculate dividers for PLL */
1363 pll_integer = fout / freq_ref;
1364 frac_div = (u64)(fout % freq_ref) * 8192ULL;
1365 do_div(frac_div, freq_ref);
1366 pll_frac_top = (frac_div >> DA7213_BYTE_SHIFT) & DA7213_BYTE_MASK;
1367 pll_frac_bot = (frac_div) & DA7213_BYTE_MASK;
1368
1369 /* Write PLL dividers */
1370 snd_soc_write(codec, DA7213_PLL_FRAC_TOP, pll_frac_top);
1371 snd_soc_write(codec, DA7213_PLL_FRAC_BOT, pll_frac_bot);
1372 snd_soc_write(codec, DA7213_PLL_INTEGER, pll_integer);
1373
1374 /* Enable PLL */
1375 pll_ctrl |= DA7213_PLL_EN;
1376 snd_soc_write(codec, DA7213_PLL_CTRL, pll_ctrl);
1377
1378 return 0;
1379
1380pll_err:
1381 dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n",
1382 da7213->mclk_rate);
1383 return -EINVAL;
1384}
1385
1386/* DAI operations */
1387static const struct snd_soc_dai_ops da7213_dai_ops = {
1388 .hw_params = da7213_hw_params,
1389 .set_fmt = da7213_set_dai_fmt,
1390 .set_sysclk = da7213_set_dai_sysclk,
1391 .set_pll = da7213_set_dai_pll,
1392 .digital_mute = da7213_mute,
1393};
1394
1395static struct snd_soc_dai_driver da7213_dai = {
1396 .name = "da7213-hifi",
1397 /* Playback Capabilities */
1398 .playback = {
1399 .stream_name = "Playback",
1400 .channels_min = 1,
1401 .channels_max = 2,
1402 .rates = SNDRV_PCM_RATE_8000_96000,
1403 .formats = DA7213_FORMATS,
1404 },
1405 /* Capture Capabilities */
1406 .capture = {
1407 .stream_name = "Capture",
1408 .channels_min = 1,
1409 .channels_max = 2,
1410 .rates = SNDRV_PCM_RATE_8000_96000,
1411 .formats = DA7213_FORMATS,
1412 },
1413 .ops = &da7213_dai_ops,
1414 .symmetric_rates = 1,
1415};
1416
1417static int da7213_set_bias_level(struct snd_soc_codec *codec,
1418 enum snd_soc_bias_level level)
1419{
Adam Thomson6e7c4442015-10-07 14:27:11 +01001420 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1421 int ret;
1422
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001423 switch (level) {
1424 case SND_SOC_BIAS_ON:
1425 case SND_SOC_BIAS_PREPARE:
1426 break;
1427 case SND_SOC_BIAS_STANDBY:
Lars-Peter Clausen9c414c62015-05-14 11:19:56 +02001428 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
Adam Thomson6e7c4442015-10-07 14:27:11 +01001429 /* MCLK */
1430 if (da7213->mclk) {
1431 ret = clk_prepare_enable(da7213->mclk);
1432 if (ret) {
1433 dev_err(codec->dev,
1434 "Failed to enable mclk\n");
1435 return ret;
1436 }
1437 }
1438
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001439 /* Enable VMID reference & master bias */
1440 snd_soc_update_bits(codec, DA7213_REFERENCES,
1441 DA7213_VMID_EN | DA7213_BIAS_EN,
1442 DA7213_VMID_EN | DA7213_BIAS_EN);
1443 }
1444 break;
1445 case SND_SOC_BIAS_OFF:
1446 /* Disable VMID reference & master bias */
1447 snd_soc_update_bits(codec, DA7213_REFERENCES,
1448 DA7213_VMID_EN | DA7213_BIAS_EN, 0);
Adam Thomson6e7c4442015-10-07 14:27:11 +01001449
1450 /* MCLK */
1451 if (da7213->mclk)
1452 clk_disable_unprepare(da7213->mclk);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001453 break;
1454 }
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001455 return 0;
1456}
1457
Adam Thomsone90996a2015-10-07 14:27:08 +01001458/* DT */
1459static const struct of_device_id da7213_of_match[] = {
1460 { .compatible = "dlg,da7213", },
1461 { }
1462};
1463MODULE_DEVICE_TABLE(of, da7213_of_match);
1464
1465static enum da7213_micbias_voltage
1466 da7213_of_micbias_lvl(struct snd_soc_codec *codec, u32 val)
1467{
1468 switch (val) {
1469 case 1600:
1470 return DA7213_MICBIAS_1_6V;
1471 case 2200:
1472 return DA7213_MICBIAS_2_2V;
1473 case 2500:
1474 return DA7213_MICBIAS_2_5V;
1475 case 3000:
1476 return DA7213_MICBIAS_3_0V;
1477 default:
1478 dev_warn(codec->dev, "Invalid micbias level\n");
1479 return DA7213_MICBIAS_2_2V;
1480 }
1481}
1482
1483static enum da7213_dmic_data_sel
1484 da7213_of_dmic_data_sel(struct snd_soc_codec *codec, const char *str)
1485{
1486 if (!strcmp(str, "lrise_rfall")) {
1487 return DA7213_DMIC_DATA_LRISE_RFALL;
1488 } else if (!strcmp(str, "lfall_rrise")) {
1489 return DA7213_DMIC_DATA_LFALL_RRISE;
1490 } else {
1491 dev_warn(codec->dev, "Invalid DMIC data select type\n");
1492 return DA7213_DMIC_DATA_LRISE_RFALL;
1493 }
1494}
1495
1496static enum da7213_dmic_samplephase
1497 da7213_of_dmic_samplephase(struct snd_soc_codec *codec, const char *str)
1498{
1499 if (!strcmp(str, "on_clkedge")) {
1500 return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1501 } else if (!strcmp(str, "between_clkedge")) {
1502 return DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE;
1503 } else {
1504 dev_warn(codec->dev, "Invalid DMIC sample phase\n");
1505 return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1506 }
1507}
1508
1509static enum da7213_dmic_clk_rate
1510 da7213_of_dmic_clkrate(struct snd_soc_codec *codec, u32 val)
1511{
1512 switch (val) {
1513 case 1500000:
1514 return DA7213_DMIC_CLK_1_5MHZ;
1515 case 3000000:
1516 return DA7213_DMIC_CLK_3_0MHZ;
1517 default:
1518 dev_warn(codec->dev, "Invalid DMIC clock rate\n");
1519 return DA7213_DMIC_CLK_1_5MHZ;
1520 }
1521}
1522
1523static struct da7213_platform_data
1524 *da7213_of_to_pdata(struct snd_soc_codec *codec)
1525{
1526 struct device_node *np = codec->dev->of_node;
1527 struct da7213_platform_data *pdata;
1528 const char *of_str;
1529 u32 of_val32;
1530
1531 pdata = devm_kzalloc(codec->dev, sizeof(*pdata), GFP_KERNEL);
1532 if (!pdata) {
1533 dev_warn(codec->dev, "Failed to allocate memory for pdata\n");
1534 return NULL;
1535 }
1536
1537 if (of_property_read_u32(np, "dlg,micbias1-lvl", &of_val32) >= 0)
1538 pdata->micbias1_lvl = da7213_of_micbias_lvl(codec, of_val32);
1539 else
1540 pdata->micbias1_lvl = DA7213_MICBIAS_2_2V;
1541
1542 if (of_property_read_u32(np, "dlg,micbias2-lvl", &of_val32) >= 0)
1543 pdata->micbias2_lvl = da7213_of_micbias_lvl(codec, of_val32);
1544 else
1545 pdata->micbias2_lvl = DA7213_MICBIAS_2_2V;
1546
1547 if (!of_property_read_string(np, "dlg,dmic-data-sel", &of_str))
1548 pdata->dmic_data_sel = da7213_of_dmic_data_sel(codec, of_str);
1549 else
1550 pdata->dmic_data_sel = DA7213_DMIC_DATA_LRISE_RFALL;
1551
1552 if (!of_property_read_string(np, "dlg,dmic-samplephase", &of_str))
1553 pdata->dmic_samplephase =
1554 da7213_of_dmic_samplephase(codec, of_str);
1555 else
1556 pdata->dmic_samplephase = DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1557
1558 if (of_property_read_u32(np, "dlg,dmic-clkrate", &of_val32) >= 0)
1559 pdata->dmic_clk_rate = da7213_of_dmic_clkrate(codec, of_val32);
1560 else
1561 pdata->dmic_clk_rate = DA7213_DMIC_CLK_3_0MHZ;
1562
1563 return pdata;
1564}
1565
1566
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001567static int da7213_probe(struct snd_soc_codec *codec)
1568{
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001569 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001570
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001571 /* Default to using ALC auto offset calibration mode. */
1572 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
1573 DA7213_ALC_CALIB_MODE_MAN, 0);
1574 da7213->alc_calib_auto = true;
1575
1576 /* Default to using SRM for slave mode */
1577 da7213->srm_en = true;
1578
1579 /* Enable all Gain Ramps */
1580 snd_soc_update_bits(codec, DA7213_AUX_L_CTRL,
1581 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1582 snd_soc_update_bits(codec, DA7213_AUX_R_CTRL,
1583 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1584 snd_soc_update_bits(codec, DA7213_MIXIN_L_CTRL,
1585 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1586 snd_soc_update_bits(codec, DA7213_MIXIN_R_CTRL,
1587 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1588 snd_soc_update_bits(codec, DA7213_ADC_L_CTRL,
1589 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1590 snd_soc_update_bits(codec, DA7213_ADC_R_CTRL,
1591 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1592 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1593 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1594 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1595 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1596 snd_soc_update_bits(codec, DA7213_HP_L_CTRL,
1597 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1598 snd_soc_update_bits(codec, DA7213_HP_R_CTRL,
1599 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1600 snd_soc_update_bits(codec, DA7213_LINE_CTRL,
1601 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1602
1603 /*
1604 * There are two separate control bits for input and output mixers as
1605 * well as headphone and line outs.
1606 * One to enable corresponding amplifier and other to enable its
1607 * output. As amplifier bits are related to power control, they are
1608 * being managed by DAPM while other (non power related) bits are
1609 * enabled here
1610 */
1611 snd_soc_update_bits(codec, DA7213_MIXIN_L_CTRL,
1612 DA7213_MIXIN_MIX_EN, DA7213_MIXIN_MIX_EN);
1613 snd_soc_update_bits(codec, DA7213_MIXIN_R_CTRL,
1614 DA7213_MIXIN_MIX_EN, DA7213_MIXIN_MIX_EN);
1615
1616 snd_soc_update_bits(codec, DA7213_MIXOUT_L_CTRL,
1617 DA7213_MIXOUT_MIX_EN, DA7213_MIXOUT_MIX_EN);
1618 snd_soc_update_bits(codec, DA7213_MIXOUT_R_CTRL,
1619 DA7213_MIXOUT_MIX_EN, DA7213_MIXOUT_MIX_EN);
1620
1621 snd_soc_update_bits(codec, DA7213_HP_L_CTRL,
1622 DA7213_HP_AMP_OE, DA7213_HP_AMP_OE);
1623 snd_soc_update_bits(codec, DA7213_HP_R_CTRL,
1624 DA7213_HP_AMP_OE, DA7213_HP_AMP_OE);
1625
1626 snd_soc_update_bits(codec, DA7213_LINE_CTRL,
1627 DA7213_LINE_AMP_OE, DA7213_LINE_AMP_OE);
1628
Adam Thomsone90996a2015-10-07 14:27:08 +01001629 /* Handle DT/Platform data */
1630 if (codec->dev->of_node)
1631 da7213->pdata = da7213_of_to_pdata(codec);
1632 else
1633 da7213->pdata = dev_get_platdata(codec->dev);
1634
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001635 /* Set platform data values */
1636 if (da7213->pdata) {
Adam Thomsone90996a2015-10-07 14:27:08 +01001637 struct da7213_platform_data *pdata = da7213->pdata;
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001638 u8 micbias_lvl = 0, dmic_cfg = 0;
1639
1640 /* Set Mic Bias voltages */
1641 switch (pdata->micbias1_lvl) {
1642 case DA7213_MICBIAS_1_6V:
1643 case DA7213_MICBIAS_2_2V:
1644 case DA7213_MICBIAS_2_5V:
1645 case DA7213_MICBIAS_3_0V:
1646 micbias_lvl |= (pdata->micbias1_lvl <<
1647 DA7213_MICBIAS1_LEVEL_SHIFT);
1648 break;
1649 }
1650 switch (pdata->micbias2_lvl) {
1651 case DA7213_MICBIAS_1_6V:
1652 case DA7213_MICBIAS_2_2V:
1653 case DA7213_MICBIAS_2_5V:
1654 case DA7213_MICBIAS_3_0V:
1655 micbias_lvl |= (pdata->micbias2_lvl <<
1656 DA7213_MICBIAS2_LEVEL_SHIFT);
1657 break;
1658 }
1659 snd_soc_update_bits(codec, DA7213_MICBIAS_CTRL,
1660 DA7213_MICBIAS1_LEVEL_MASK |
1661 DA7213_MICBIAS2_LEVEL_MASK, micbias_lvl);
1662
1663 /* Set DMIC configuration */
1664 switch (pdata->dmic_data_sel) {
1665 case DA7213_DMIC_DATA_LFALL_RRISE:
1666 case DA7213_DMIC_DATA_LRISE_RFALL:
1667 dmic_cfg |= (pdata->dmic_data_sel <<
1668 DA7213_DMIC_DATA_SEL_SHIFT);
1669 break;
1670 }
Axel Lin61559af2013-05-09 21:14:20 +08001671 switch (pdata->dmic_samplephase) {
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001672 case DA7213_DMIC_SAMPLE_ON_CLKEDGE:
1673 case DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE:
Axel Lin61559af2013-05-09 21:14:20 +08001674 dmic_cfg |= (pdata->dmic_samplephase <<
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001675 DA7213_DMIC_SAMPLEPHASE_SHIFT);
1676 break;
1677 }
Axel Lin61559af2013-05-09 21:14:20 +08001678 switch (pdata->dmic_clk_rate) {
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001679 case DA7213_DMIC_CLK_3_0MHZ:
1680 case DA7213_DMIC_CLK_1_5MHZ:
Axel Lin61559af2013-05-09 21:14:20 +08001681 dmic_cfg |= (pdata->dmic_clk_rate <<
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001682 DA7213_DMIC_CLK_RATE_SHIFT);
1683 break;
1684 }
1685 snd_soc_update_bits(codec, DA7213_MIC_CONFIG,
1686 DA7213_DMIC_DATA_SEL_MASK |
1687 DA7213_DMIC_SAMPLEPHASE_MASK |
1688 DA7213_DMIC_CLK_RATE_MASK, dmic_cfg);
Adam Thomson6e7c4442015-10-07 14:27:11 +01001689 }
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001690
Adam Thomson6e7c4442015-10-07 14:27:11 +01001691 /* Check if MCLK provided */
1692 da7213->mclk = devm_clk_get(codec->dev, "mclk");
1693 if (IS_ERR(da7213->mclk)) {
1694 if (PTR_ERR(da7213->mclk) != -ENOENT)
1695 return PTR_ERR(da7213->mclk);
1696 else
1697 da7213->mclk = NULL;
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001698 }
Adam Thomsone90996a2015-10-07 14:27:08 +01001699
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001700 return 0;
1701}
1702
1703static struct snd_soc_codec_driver soc_codec_dev_da7213 = {
1704 .probe = da7213_probe,
1705 .set_bias_level = da7213_set_bias_level,
1706
1707 .controls = da7213_snd_controls,
1708 .num_controls = ARRAY_SIZE(da7213_snd_controls),
1709
1710 .dapm_widgets = da7213_dapm_widgets,
1711 .num_dapm_widgets = ARRAY_SIZE(da7213_dapm_widgets),
1712 .dapm_routes = da7213_audio_map,
1713 .num_dapm_routes = ARRAY_SIZE(da7213_audio_map),
1714};
1715
1716static const struct regmap_config da7213_regmap_config = {
1717 .reg_bits = 8,
1718 .val_bits = 8,
1719
1720 .reg_defaults = da7213_reg_defaults,
1721 .num_reg_defaults = ARRAY_SIZE(da7213_reg_defaults),
1722 .volatile_reg = da7213_volatile_register,
1723 .cache_type = REGCACHE_RBTREE,
1724};
1725
1726static int da7213_i2c_probe(struct i2c_client *i2c,
1727 const struct i2c_device_id *id)
1728{
1729 struct da7213_priv *da7213;
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001730 int ret;
1731
1732 da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv),
1733 GFP_KERNEL);
1734 if (!da7213)
1735 return -ENOMEM;
1736
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001737 i2c_set_clientdata(i2c, da7213);
1738
1739 da7213->regmap = devm_regmap_init_i2c(i2c, &da7213_regmap_config);
1740 if (IS_ERR(da7213->regmap)) {
1741 ret = PTR_ERR(da7213->regmap);
1742 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1743 return ret;
1744 }
1745
1746 ret = snd_soc_register_codec(&i2c->dev,
1747 &soc_codec_dev_da7213, &da7213_dai, 1);
1748 if (ret < 0) {
1749 dev_err(&i2c->dev, "Failed to register da7213 codec: %d\n",
1750 ret);
1751 }
1752 return ret;
1753}
1754
1755static int da7213_remove(struct i2c_client *client)
1756{
1757 snd_soc_unregister_codec(&client->dev);
1758 return 0;
1759}
1760
1761static const struct i2c_device_id da7213_i2c_id[] = {
1762 { "da7213", 0 },
1763 { }
1764};
1765MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);
1766
1767/* I2C codec control layer */
1768static struct i2c_driver da7213_i2c_driver = {
1769 .driver = {
1770 .name = "da7213",
Adam Thomsone90996a2015-10-07 14:27:08 +01001771 .of_match_table = of_match_ptr(da7213_of_match),
Adam Thomsonef5c2eb2013-02-14 12:02:51 +00001772 },
1773 .probe = da7213_i2c_probe,
1774 .remove = da7213_remove,
1775 .id_table = da7213_i2c_id,
1776};
1777
1778module_i2c_driver(da7213_i2c_driver);
1779
1780MODULE_DESCRIPTION("ASoC DA7213 Codec driver");
1781MODULE_AUTHOR("Adam Thomson <Adam.Thomson.Opensource@diasemi.com>");
1782MODULE_LICENSE("GPL");