2 * DA7213 ALSA SoC Codec Driver
4 * Copyright (c) 2013 Dialog Semiconductor
6 * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
7 * Based on DA9055 ALSA SoC codec driver.
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.
15 #include <linux/clk.h>
16 #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>
27 #include <sound/da7213.h>
32 static const DECLARE_TLV_DB_RANGE(aux_vol_tlv
,
34 0x0, 0x11, TLV_DB_SCALE_ITEM(-5400, 0, 0),
36 0x12, 0x3f, TLV_DB_SCALE_ITEM(-5250, 150, 0)
39 static const DECLARE_TLV_DB_RANGE(digital_gain_tlv
,
40 0x0, 0x07, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE
, 0, 1),
42 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7800, 75, 0)
45 static const DECLARE_TLV_DB_RANGE(alc_analog_gain_tlv
,
46 0x0, 0x0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE
, 0, 1),
48 0x01, 0x07, TLV_DB_SCALE_ITEM(0, 600, 0)
51 static const DECLARE_TLV_DB_SCALE(mic_vol_tlv
, -600, 600, 0);
52 static const DECLARE_TLV_DB_SCALE(mixin_gain_tlv
, -450, 150, 0);
53 static const DECLARE_TLV_DB_SCALE(eq_gain_tlv
, -1050, 150, 0);
54 static const DECLARE_TLV_DB_SCALE(hp_vol_tlv
, -5700, 100, 0);
55 static const DECLARE_TLV_DB_SCALE(lineout_vol_tlv
, -4800, 100, 0);
56 static const DECLARE_TLV_DB_SCALE(alc_threshold_tlv
, -9450, 150, 0);
57 static const DECLARE_TLV_DB_SCALE(alc_gain_tlv
, 0, 600, 0);
59 /* ADC and DAC voice mode (8kHz) high pass cutoff value */
60 static const char * const da7213_voice_hpf_corner_txt
[] = {
61 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
64 static SOC_ENUM_SINGLE_DECL(da7213_dac_voice_hpf_corner
,
66 DA7213_VOICE_HPF_CORNER_SHIFT
,
67 da7213_voice_hpf_corner_txt
);
69 static SOC_ENUM_SINGLE_DECL(da7213_adc_voice_hpf_corner
,
71 DA7213_VOICE_HPF_CORNER_SHIFT
,
72 da7213_voice_hpf_corner_txt
);
74 /* ADC and DAC high pass filter cutoff value */
75 static const char * const da7213_audio_hpf_corner_txt
[] = {
76 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
79 static SOC_ENUM_SINGLE_DECL(da7213_dac_audio_hpf_corner
,
81 , DA7213_AUDIO_HPF_CORNER_SHIFT
,
82 da7213_audio_hpf_corner_txt
);
84 static SOC_ENUM_SINGLE_DECL(da7213_adc_audio_hpf_corner
,
86 DA7213_AUDIO_HPF_CORNER_SHIFT
,
87 da7213_audio_hpf_corner_txt
);
89 /* Gain ramping rate value */
90 static const char * const da7213_gain_ramp_rate_txt
[] = {
91 "nominal rate * 8", "nominal rate * 16", "nominal rate / 16",
95 static 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
);
100 /* DAC noise gate setup time value */
101 static const char * const da7213_dac_ng_setup_time_txt
[] = {
102 "256 samples", "512 samples", "1024 samples", "2048 samples"
105 static 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
);
110 /* DAC noise gate rampup rate value */
111 static const char * const da7213_dac_ng_rampup_txt
[] = {
112 "0.02 ms/dB", "0.16 ms/dB"
115 static 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
);
120 /* DAC noise gate rampdown rate value */
121 static const char * const da7213_dac_ng_rampdown_txt
[] = {
122 "0.64 ms/dB", "20.48 ms/dB"
125 static 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
);
130 /* DAC soft mute rate value */
131 static const char * const da7213_dac_soft_mute_rate_txt
[] = {
132 "1", "2", "4", "8", "16", "32", "64"
135 static SOC_ENUM_SINGLE_DECL(da7213_dac_soft_mute_rate
,
137 DA7213_DAC_SOFTMUTE_RATE_SHIFT
,
138 da7213_dac_soft_mute_rate_txt
);
140 /* ALC Attack Rate select */
141 static 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"
146 static SOC_ENUM_SINGLE_DECL(da7213_alc_attack_rate
,
148 DA7213_ALC_ATTACK_SHIFT
,
149 da7213_alc_attack_rate_txt
);
151 /* ALC Release Rate select */
152 static 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"
157 static SOC_ENUM_SINGLE_DECL(da7213_alc_release_rate
,
159 DA7213_ALC_RELEASE_SHIFT
,
160 da7213_alc_release_rate_txt
);
162 /* ALC Hold Time select */
163 static 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"
169 static SOC_ENUM_SINGLE_DECL(da7213_alc_hold_time
,
171 DA7213_ALC_HOLD_SHIFT
,
172 da7213_alc_hold_time_txt
);
174 /* ALC Input Signal Tracking rate select */
175 static const char * const da7213_alc_integ_rate_txt
[] = {
176 "1/4", "1/16", "1/256", "1/65536"
179 static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_attack_rate
,
181 DA7213_ALC_INTEG_ATTACK_SHIFT
,
182 da7213_alc_integ_rate_txt
);
184 static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_release_rate
,
186 DA7213_ALC_INTEG_RELEASE_SHIFT
,
187 da7213_alc_integ_rate_txt
);
194 static int da7213_get_alc_data(struct snd_soc_codec
*codec
, u8 reg_val
)
196 int mid_data
, top_data
;
200 for (iteration
= 0; iteration
< DA7213_ALC_AVG_ITERATIONS
;
202 /* Select the left or right channel and capture data */
203 snd_soc_write(codec
, DA7213_ALC_CIC_OP_LVL_CTRL
, reg_val
);
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
);
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
);
215 sum
+= ((mid_data
<< 8) | (top_data
<< 16));
218 return sum
/ DA7213_ALC_AVG_ITERATIONS
;
221 static void da7213_alc_calib_man(struct snd_soc_codec
*codec
)
224 int avg_left_data
, avg_right_data
, offset_l
, offset_r
;
226 /* Calculate average for Left and Right data */
228 avg_left_data
= da7213_get_alc_data(codec
,
229 DA7213_ALC_CIC_OP_CHANNEL_LEFT
);
231 avg_right_data
= da7213_get_alc_data(codec
,
232 DA7213_ALC_CIC_OP_CHANNEL_RIGHT
);
234 /* Calculate DC offset */
235 offset_l
= -avg_left_data
;
236 offset_r
= -avg_right_data
;
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
);
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
);
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
);
254 static void da7213_alc_calib_auto(struct snd_soc_codec
*codec
)
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
);
262 alc_ctrl1
= snd_soc_read(codec
, DA7213_ALC_CTRL1
);
263 } while (alc_ctrl1
& DA7213_ALC_AUTO_CALIB_EN
);
265 /* If auto calibration fails, fall back to digital gain only mode */
266 if (alc_ctrl1
& DA7213_ALC_CALIB_OVERFLOW
) {
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
,
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
);
281 static void da7213_alc_calib(struct snd_soc_codec
*codec
)
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
;
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
);
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
);
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
);
300 /* Enable ADC Left and Right */
301 snd_soc_update_bits(codec
, DA7213_ADC_L_CTRL
, DA7213_ADC_EN
,
303 snd_soc_update_bits(codec
, DA7213_ADC_R_CTRL
, DA7213_ADC_EN
,
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
);
319 snd_soc_update_bits(codec
, DA7213_MIC_1_CTRL
, DA7213_MUTE_EN
,
321 snd_soc_update_bits(codec
, DA7213_MIC_2_CTRL
, DA7213_MUTE_EN
,
324 /* Perform calibration */
325 if (da7213
->alc_calib_auto
)
326 da7213_alc_calib_auto(codec
);
328 da7213_alc_calib_man(codec
);
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
);
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
);
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
);
343 static int da7213_put_mixin_gain(struct snd_kcontrol
*kcontrol
,
344 struct snd_ctl_elem_value
*ucontrol
)
346 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
347 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
350 ret
= snd_soc_put_volsw_2r(kcontrol
, ucontrol
);
352 /* If ALC in operation, make sure calibrated offsets are updated */
353 if ((!ret
) && (da7213
->alc_en
))
354 da7213_alc_calib(codec
);
359 static int da7213_put_alc_sw(struct snd_kcontrol
*kcontrol
,
360 struct snd_ctl_elem_value
*ucontrol
)
362 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
363 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
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;
373 da7213
->alc_en
= false;
376 return snd_soc_put_volsw(kcontrol
, ucontrol
);
384 static const struct snd_kcontrol_new da7213_snd_controls
[] = {
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
,
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
),
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
),
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
,
440 SOC_ENUM("ADC Voice Cutoff", da7213_adc_voice_hpf_corner
),
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
,
448 SOC_ENUM("DAC Voice Cutoff", da7213_dac_voice_hpf_corner
),
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
,
469 SOC_ENUM("DAC Soft Mute Rate", da7213_dac_soft_mute_rate
),
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
,
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
),
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
,
499 SOC_ENUM("Gain Ramping Rate", da7213_gain_ramp_rate
),
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
,
510 SOC_SINGLE("DAC NG ON Threshold", DA7213_DAC_NG_ON_THRESHOLD
,
511 DA7213_DAC_NG_THRESHOLD_SHIFT
, DA7213_DAC_NG_THRESHOLD_MAX
,
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
,
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
),
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
),
535 * Rate at which input signal envelope is tracked as the signal gets
538 SOC_ENUM("ALC Integ Attack Rate", da7213_alc_integ_attack_rate
),
540 * Rate at which input signal envelope is tracked as the signal gets
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
,
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
,
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
),
583 /* MIC PGA source select */
584 static const char * const da7213_mic_amp_in_sel_txt
[] = {
585 "Differential", "MIC_P", "MIC_N"
588 static SOC_ENUM_SINGLE_DECL(da7213_mic_1_amp_in_sel
,
590 DA7213_MIC_AMP_IN_SEL_SHIFT
,
591 da7213_mic_amp_in_sel_txt
);
592 static 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
);
595 static SOC_ENUM_SINGLE_DECL(da7213_mic_2_amp_in_sel
,
597 DA7213_MIC_AMP_IN_SEL_SHIFT
,
598 da7213_mic_amp_in_sel_txt
);
599 static 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
);
602 /* DAI routing select */
603 static const char * const da7213_dai_src_txt
[] = {
604 "ADC Left", "ADC Right", "DAI Input Left", "DAI Input Right"
607 static SOC_ENUM_SINGLE_DECL(da7213_dai_l_src
,
608 DA7213_DIG_ROUTING_DAI
,
609 DA7213_DAI_L_SRC_SHIFT
,
611 static const struct snd_kcontrol_new da7213_dai_l_src_mux
=
612 SOC_DAPM_ENUM("DAI Left Source MUX", da7213_dai_l_src
);
614 static SOC_ENUM_SINGLE_DECL(da7213_dai_r_src
,
615 DA7213_DIG_ROUTING_DAI
,
616 DA7213_DAI_R_SRC_SHIFT
,
618 static const struct snd_kcontrol_new da7213_dai_r_src_mux
=
619 SOC_DAPM_ENUM("DAI Right Source MUX", da7213_dai_r_src
);
621 /* DAC routing select */
622 static const char * const da7213_dac_src_txt
[] = {
623 "ADC Output Left", "ADC Output Right", "DAI Input Left",
627 static SOC_ENUM_SINGLE_DECL(da7213_dac_l_src
,
628 DA7213_DIG_ROUTING_DAC
,
629 DA7213_DAC_L_SRC_SHIFT
,
631 static const struct snd_kcontrol_new da7213_dac_l_src_mux
=
632 SOC_DAPM_ENUM("DAC Left Source MUX", da7213_dac_l_src
);
634 static SOC_ENUM_SINGLE_DECL(da7213_dac_r_src
,
635 DA7213_DIG_ROUTING_DAC
,
636 DA7213_DAC_R_SRC_SHIFT
,
638 static const struct snd_kcontrol_new da7213_dac_r_src_mux
=
639 SOC_DAPM_ENUM("DAC Right Source MUX", da7213_dac_r_src
);
646 static 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
),
662 static 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
),
678 static 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
),
703 static 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
),
732 static const struct snd_soc_dapm_widget da7213_dapm_widgets
[] = {
737 /* Use a supply here as this controls both input & output DAIs */
738 SND_SOC_DAPM_SUPPLY("DAI", DA7213_DAI_CTRL
, DA7213_DAI_EN_SHIFT
,
739 DA7213_NO_INVERT
, NULL
, 0),
746 SND_SOC_DAPM_INPUT("MIC1"),
747 SND_SOC_DAPM_INPUT("MIC2"),
748 SND_SOC_DAPM_INPUT("AUXL"),
749 SND_SOC_DAPM_INPUT("AUXR"),
751 /* MUXs for Mic PGA source selection */
752 SND_SOC_DAPM_MUX("Mic 1 Amp Source MUX", SND_SOC_NOPM
, 0, 0,
753 &da7213_mic_1_amp_in_sel_mux
),
754 SND_SOC_DAPM_MUX("Mic 2 Amp Source MUX", SND_SOC_NOPM
, 0, 0,
755 &da7213_mic_2_amp_in_sel_mux
),
758 SND_SOC_DAPM_PGA("Mic 1 PGA", DA7213_MIC_1_CTRL
, DA7213_AMP_EN_SHIFT
,
759 DA7213_NO_INVERT
, NULL
, 0),
760 SND_SOC_DAPM_PGA("Mic 2 PGA", DA7213_MIC_2_CTRL
, DA7213_AMP_EN_SHIFT
,
761 DA7213_NO_INVERT
, NULL
, 0),
762 SND_SOC_DAPM_PGA("Aux Left PGA", DA7213_AUX_L_CTRL
, DA7213_AMP_EN_SHIFT
,
763 DA7213_NO_INVERT
, NULL
, 0),
764 SND_SOC_DAPM_PGA("Aux Right PGA", DA7213_AUX_R_CTRL
,
765 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
766 SND_SOC_DAPM_PGA("Mixin Left PGA", DA7213_MIXIN_L_CTRL
,
767 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
768 SND_SOC_DAPM_PGA("Mixin Right PGA", DA7213_MIXIN_R_CTRL
,
769 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
772 SND_SOC_DAPM_SUPPLY("Mic Bias 1", DA7213_MICBIAS_CTRL
,
773 DA7213_MICBIAS1_EN_SHIFT
, DA7213_NO_INVERT
,
775 SND_SOC_DAPM_SUPPLY("Mic Bias 2", DA7213_MICBIAS_CTRL
,
776 DA7213_MICBIAS2_EN_SHIFT
, DA7213_NO_INVERT
,
780 SND_SOC_DAPM_MIXER("Mixin Left", SND_SOC_NOPM
, 0, 0,
781 &da7213_dapm_mixinl_controls
[0],
782 ARRAY_SIZE(da7213_dapm_mixinl_controls
)),
783 SND_SOC_DAPM_MIXER("Mixin Right", SND_SOC_NOPM
, 0, 0,
784 &da7213_dapm_mixinr_controls
[0],
785 ARRAY_SIZE(da7213_dapm_mixinr_controls
)),
788 SND_SOC_DAPM_ADC("ADC Left", NULL
, DA7213_ADC_L_CTRL
,
789 DA7213_ADC_EN_SHIFT
, DA7213_NO_INVERT
),
790 SND_SOC_DAPM_ADC("ADC Right", NULL
, DA7213_ADC_R_CTRL
,
791 DA7213_ADC_EN_SHIFT
, DA7213_NO_INVERT
),
794 SND_SOC_DAPM_MUX("DAI Left Source MUX", SND_SOC_NOPM
, 0, 0,
795 &da7213_dai_l_src_mux
),
796 SND_SOC_DAPM_MUX("DAI Right Source MUX", SND_SOC_NOPM
, 0, 0,
797 &da7213_dai_r_src_mux
),
798 SND_SOC_DAPM_AIF_OUT("DAIOUTL", "Capture", 0, SND_SOC_NOPM
, 0, 0),
799 SND_SOC_DAPM_AIF_OUT("DAIOUTR", "Capture", 1, SND_SOC_NOPM
, 0, 0),
806 SND_SOC_DAPM_AIF_IN("DAIINL", "Playback", 0, SND_SOC_NOPM
, 0, 0),
807 SND_SOC_DAPM_AIF_IN("DAIINR", "Playback", 1, SND_SOC_NOPM
, 0, 0),
808 SND_SOC_DAPM_MUX("DAC Left Source MUX", SND_SOC_NOPM
, 0, 0,
809 &da7213_dac_l_src_mux
),
810 SND_SOC_DAPM_MUX("DAC Right Source MUX", SND_SOC_NOPM
, 0, 0,
811 &da7213_dac_r_src_mux
),
814 SND_SOC_DAPM_DAC("DAC Left", NULL
, DA7213_DAC_L_CTRL
,
815 DA7213_DAC_EN_SHIFT
, DA7213_NO_INVERT
),
816 SND_SOC_DAPM_DAC("DAC Right", NULL
, DA7213_DAC_R_CTRL
,
817 DA7213_DAC_EN_SHIFT
, DA7213_NO_INVERT
),
820 SND_SOC_DAPM_MIXER("Mixout Left", SND_SOC_NOPM
, 0, 0,
821 &da7213_dapm_mixoutl_controls
[0],
822 ARRAY_SIZE(da7213_dapm_mixoutl_controls
)),
823 SND_SOC_DAPM_MIXER("Mixout Right", SND_SOC_NOPM
, 0, 0,
824 &da7213_dapm_mixoutr_controls
[0],
825 ARRAY_SIZE(da7213_dapm_mixoutr_controls
)),
828 SND_SOC_DAPM_PGA("Mixout Left PGA", DA7213_MIXOUT_L_CTRL
,
829 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
830 SND_SOC_DAPM_PGA("Mixout Right PGA", DA7213_MIXOUT_R_CTRL
,
831 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
832 SND_SOC_DAPM_PGA("Lineout PGA", DA7213_LINE_CTRL
, DA7213_AMP_EN_SHIFT
,
833 DA7213_NO_INVERT
, NULL
, 0),
834 SND_SOC_DAPM_PGA("Headphone Left PGA", DA7213_HP_L_CTRL
,
835 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
836 SND_SOC_DAPM_PGA("Headphone Right PGA", DA7213_HP_R_CTRL
,
837 DA7213_AMP_EN_SHIFT
, DA7213_NO_INVERT
, NULL
, 0),
840 SND_SOC_DAPM_SUPPLY("Charge Pump", DA7213_CP_CTRL
, DA7213_CP_EN_SHIFT
,
841 DA7213_NO_INVERT
, NULL
, 0),
844 SND_SOC_DAPM_OUTPUT("HPL"),
845 SND_SOC_DAPM_OUTPUT("HPR"),
846 SND_SOC_DAPM_OUTPUT("LINE"),
851 * DAPM audio route definition
854 static const struct snd_soc_dapm_route da7213_audio_map
[] = {
855 /* Dest Connecting Widget source */
858 {"MIC1", NULL
, "Mic Bias 1"},
859 {"MIC2", NULL
, "Mic Bias 2"},
861 {"Mic 1 Amp Source MUX", "Differential", "MIC1"},
862 {"Mic 1 Amp Source MUX", "MIC_P", "MIC1"},
863 {"Mic 1 Amp Source MUX", "MIC_N", "MIC1"},
865 {"Mic 2 Amp Source MUX", "Differential", "MIC2"},
866 {"Mic 2 Amp Source MUX", "MIC_P", "MIC2"},
867 {"Mic 2 Amp Source MUX", "MIC_N", "MIC2"},
869 {"Mic 1 PGA", NULL
, "Mic 1 Amp Source MUX"},
870 {"Mic 2 PGA", NULL
, "Mic 2 Amp Source MUX"},
872 {"Aux Left PGA", NULL
, "AUXL"},
873 {"Aux Right PGA", NULL
, "AUXR"},
875 {"Mixin Left", "Aux Left Switch", "Aux Left PGA"},
876 {"Mixin Left", "Mic 1 Switch", "Mic 1 PGA"},
877 {"Mixin Left", "Mic 2 Switch", "Mic 2 PGA"},
878 {"Mixin Left", "Mixin Right Switch", "Mixin Right PGA"},
880 {"Mixin Right", "Aux Right Switch", "Aux Right PGA"},
881 {"Mixin Right", "Mic 2 Switch", "Mic 2 PGA"},
882 {"Mixin Right", "Mic 1 Switch", "Mic 1 PGA"},
883 {"Mixin Right", "Mixin Left Switch", "Mixin Left PGA"},
885 {"Mixin Left PGA", NULL
, "Mixin Left"},
886 {"ADC Left", NULL
, "Mixin Left PGA"},
888 {"Mixin Right PGA", NULL
, "Mixin Right"},
889 {"ADC Right", NULL
, "Mixin Right PGA"},
891 {"DAI Left Source MUX", "ADC Left", "ADC Left"},
892 {"DAI Left Source MUX", "ADC Right", "ADC Right"},
893 {"DAI Left Source MUX", "DAI Input Left", "DAIINL"},
894 {"DAI Left Source MUX", "DAI Input Right", "DAIINR"},
896 {"DAI Right Source MUX", "ADC Left", "ADC Left"},
897 {"DAI Right Source MUX", "ADC Right", "ADC Right"},
898 {"DAI Right Source MUX", "DAI Input Left", "DAIINL"},
899 {"DAI Right Source MUX", "DAI Input Right", "DAIINR"},
901 {"DAIOUTL", NULL
, "DAI Left Source MUX"},
902 {"DAIOUTR", NULL
, "DAI Right Source MUX"},
904 {"DAIOUTL", NULL
, "DAI"},
905 {"DAIOUTR", NULL
, "DAI"},
908 {"DAIINL", NULL
, "DAI"},
909 {"DAIINR", NULL
, "DAI"},
911 {"DAC Left Source MUX", "ADC Output Left", "ADC Left"},
912 {"DAC Left Source MUX", "ADC Output Right", "ADC Right"},
913 {"DAC Left Source MUX", "DAI Input Left", "DAIINL"},
914 {"DAC Left Source MUX", "DAI Input Right", "DAIINR"},
916 {"DAC Right Source MUX", "ADC Output Left", "ADC Left"},
917 {"DAC Right Source MUX", "ADC Output Right", "ADC Right"},
918 {"DAC Right Source MUX", "DAI Input Left", "DAIINL"},
919 {"DAC Right Source MUX", "DAI Input Right", "DAIINR"},
921 {"DAC Left", NULL
, "DAC Left Source MUX"},
922 {"DAC Right", NULL
, "DAC Right Source MUX"},
924 {"Mixout Left", "Aux Left Switch", "Aux Left PGA"},
925 {"Mixout Left", "Mixin Left Switch", "Mixin Left PGA"},
926 {"Mixout Left", "Mixin Right Switch", "Mixin Right PGA"},
927 {"Mixout Left", "DAC Left Switch", "DAC Left"},
928 {"Mixout Left", "Aux Left Invert Switch", "Aux Left PGA"},
929 {"Mixout Left", "Mixin Left Invert Switch", "Mixin Left PGA"},
930 {"Mixout Left", "Mixin Right Invert Switch", "Mixin Right PGA"},
932 {"Mixout Right", "Aux Right Switch", "Aux Right PGA"},
933 {"Mixout Right", "Mixin Right Switch", "Mixin Right PGA"},
934 {"Mixout Right", "Mixin Left Switch", "Mixin Left PGA"},
935 {"Mixout Right", "DAC Right Switch", "DAC Right"},
936 {"Mixout Right", "Aux Right Invert Switch", "Aux Right PGA"},
937 {"Mixout Right", "Mixin Right Invert Switch", "Mixin Right PGA"},
938 {"Mixout Right", "Mixin Left Invert Switch", "Mixin Left PGA"},
940 {"Mixout Left PGA", NULL
, "Mixout Left"},
941 {"Mixout Right PGA", NULL
, "Mixout Right"},
943 {"Headphone Left PGA", NULL
, "Mixout Left PGA"},
944 {"Headphone Left PGA", NULL
, "Charge Pump"},
945 {"HPL", NULL
, "Headphone Left PGA"},
947 {"Headphone Right PGA", NULL
, "Mixout Right PGA"},
948 {"Headphone Right PGA", NULL
, "Charge Pump"},
949 {"HPR", NULL
, "Headphone Right PGA"},
951 {"Lineout PGA", NULL
, "Mixout Right PGA"},
952 {"LINE", NULL
, "Lineout PGA"},
955 static const struct reg_default da7213_reg_defaults
[] = {
956 { DA7213_DIG_ROUTING_DAI
, 0x10 },
958 { DA7213_REFERENCES
, 0x80 },
959 { DA7213_PLL_FRAC_TOP
, 0x00 },
960 { DA7213_PLL_FRAC_BOT
, 0x00 },
961 { DA7213_PLL_INTEGER
, 0x20 },
962 { DA7213_PLL_CTRL
, 0x0C },
963 { DA7213_DAI_CLK_MODE
, 0x01 },
964 { DA7213_DAI_CTRL
, 0x08 },
965 { DA7213_DIG_ROUTING_DAC
, 0x32 },
966 { DA7213_AUX_L_GAIN
, 0x35 },
967 { DA7213_AUX_R_GAIN
, 0x35 },
968 { DA7213_MIXIN_L_SELECT
, 0x00 },
969 { DA7213_MIXIN_R_SELECT
, 0x00 },
970 { DA7213_MIXIN_L_GAIN
, 0x03 },
971 { DA7213_MIXIN_R_GAIN
, 0x03 },
972 { DA7213_ADC_L_GAIN
, 0x6F },
973 { DA7213_ADC_R_GAIN
, 0x6F },
974 { DA7213_ADC_FILTERS1
, 0x80 },
975 { DA7213_MIC_1_GAIN
, 0x01 },
976 { DA7213_MIC_2_GAIN
, 0x01 },
977 { DA7213_DAC_FILTERS5
, 0x00 },
978 { DA7213_DAC_FILTERS2
, 0x88 },
979 { DA7213_DAC_FILTERS3
, 0x88 },
980 { DA7213_DAC_FILTERS4
, 0x08 },
981 { DA7213_DAC_FILTERS1
, 0x80 },
982 { DA7213_DAC_L_GAIN
, 0x6F },
983 { DA7213_DAC_R_GAIN
, 0x6F },
984 { DA7213_CP_CTRL
, 0x61 },
985 { DA7213_HP_L_GAIN
, 0x39 },
986 { DA7213_HP_R_GAIN
, 0x39 },
987 { DA7213_LINE_GAIN
, 0x30 },
988 { DA7213_MIXOUT_L_SELECT
, 0x00 },
989 { DA7213_MIXOUT_R_SELECT
, 0x00 },
990 { DA7213_SYSTEM_MODES_INPUT
, 0x00 },
991 { DA7213_SYSTEM_MODES_OUTPUT
, 0x00 },
992 { DA7213_AUX_L_CTRL
, 0x44 },
993 { DA7213_AUX_R_CTRL
, 0x44 },
994 { DA7213_MICBIAS_CTRL
, 0x11 },
995 { DA7213_MIC_1_CTRL
, 0x40 },
996 { DA7213_MIC_2_CTRL
, 0x40 },
997 { DA7213_MIXIN_L_CTRL
, 0x40 },
998 { DA7213_MIXIN_R_CTRL
, 0x40 },
999 { DA7213_ADC_L_CTRL
, 0x40 },
1000 { DA7213_ADC_R_CTRL
, 0x40 },
1001 { DA7213_DAC_L_CTRL
, 0x48 },
1002 { DA7213_DAC_R_CTRL
, 0x40 },
1003 { DA7213_HP_L_CTRL
, 0x41 },
1004 { DA7213_HP_R_CTRL
, 0x40 },
1005 { DA7213_LINE_CTRL
, 0x40 },
1006 { DA7213_MIXOUT_L_CTRL
, 0x10 },
1007 { DA7213_MIXOUT_R_CTRL
, 0x10 },
1008 { DA7213_LDO_CTRL
, 0x00 },
1009 { DA7213_IO_CTRL
, 0x00 },
1010 { DA7213_GAIN_RAMP_CTRL
, 0x00},
1011 { DA7213_MIC_CONFIG
, 0x00 },
1012 { DA7213_PC_COUNT
, 0x00 },
1013 { DA7213_CP_VOL_THRESHOLD1
, 0x32 },
1014 { DA7213_CP_DELAY
, 0x95 },
1015 { DA7213_CP_DETECTOR
, 0x00 },
1016 { DA7213_DAI_OFFSET
, 0x00 },
1017 { DA7213_DIG_CTRL
, 0x00 },
1018 { DA7213_ALC_CTRL2
, 0x00 },
1019 { DA7213_ALC_CTRL3
, 0x00 },
1020 { DA7213_ALC_NOISE
, 0x3F },
1021 { DA7213_ALC_TARGET_MIN
, 0x3F },
1022 { DA7213_ALC_TARGET_MAX
, 0x00 },
1023 { DA7213_ALC_GAIN_LIMITS
, 0xFF },
1024 { DA7213_ALC_ANA_GAIN_LIMITS
, 0x71 },
1025 { DA7213_ALC_ANTICLIP_CTRL
, 0x00 },
1026 { DA7213_ALC_ANTICLIP_LEVEL
, 0x00 },
1027 { DA7213_ALC_OFFSET_MAN_M_L
, 0x00 },
1028 { DA7213_ALC_OFFSET_MAN_U_L
, 0x00 },
1029 { DA7213_ALC_OFFSET_MAN_M_R
, 0x00 },
1030 { DA7213_ALC_OFFSET_MAN_U_R
, 0x00 },
1031 { DA7213_ALC_CIC_OP_LVL_CTRL
, 0x00 },
1032 { DA7213_DAC_NG_SETUP_TIME
, 0x00 },
1033 { DA7213_DAC_NG_OFF_THRESHOLD
, 0x00 },
1034 { DA7213_DAC_NG_ON_THRESHOLD
, 0x00 },
1035 { DA7213_DAC_NG_CTRL
, 0x00 },
1038 static bool da7213_volatile_register(struct device
*dev
, unsigned int reg
)
1041 case DA7213_STATUS1
:
1042 case DA7213_PLL_STATUS
:
1043 case DA7213_AUX_L_GAIN_STATUS
:
1044 case DA7213_AUX_R_GAIN_STATUS
:
1045 case DA7213_MIC_1_GAIN_STATUS
:
1046 case DA7213_MIC_2_GAIN_STATUS
:
1047 case DA7213_MIXIN_L_GAIN_STATUS
:
1048 case DA7213_MIXIN_R_GAIN_STATUS
:
1049 case DA7213_ADC_L_GAIN_STATUS
:
1050 case DA7213_ADC_R_GAIN_STATUS
:
1051 case DA7213_DAC_L_GAIN_STATUS
:
1052 case DA7213_DAC_R_GAIN_STATUS
:
1053 case DA7213_HP_L_GAIN_STATUS
:
1054 case DA7213_HP_R_GAIN_STATUS
:
1055 case DA7213_LINE_GAIN_STATUS
:
1056 case DA7213_ALC_CTRL1
:
1057 case DA7213_ALC_OFFSET_AUTO_M_L
:
1058 case DA7213_ALC_OFFSET_AUTO_U_L
:
1059 case DA7213_ALC_OFFSET_AUTO_M_R
:
1060 case DA7213_ALC_OFFSET_AUTO_U_R
:
1061 case DA7213_ALC_CIC_OP_LVL_DATA
:
1068 static int da7213_hw_params(struct snd_pcm_substream
*substream
,
1069 struct snd_pcm_hw_params
*params
,
1070 struct snd_soc_dai
*dai
)
1072 struct snd_soc_codec
*codec
= dai
->codec
;
1076 /* Set DAI format */
1077 switch (params_width(params
)) {
1079 dai_ctrl
|= DA7213_DAI_WORD_LENGTH_S16_LE
;
1082 dai_ctrl
|= DA7213_DAI_WORD_LENGTH_S20_LE
;
1085 dai_ctrl
|= DA7213_DAI_WORD_LENGTH_S24_LE
;
1088 dai_ctrl
|= DA7213_DAI_WORD_LENGTH_S32_LE
;
1094 /* Set sampling rate */
1095 switch (params_rate(params
)) {
1097 fs
= DA7213_SR_8000
;
1100 fs
= DA7213_SR_11025
;
1103 fs
= DA7213_SR_12000
;
1106 fs
= DA7213_SR_16000
;
1109 fs
= DA7213_SR_22050
;
1112 fs
= DA7213_SR_32000
;
1115 fs
= DA7213_SR_44100
;
1118 fs
= DA7213_SR_48000
;
1121 fs
= DA7213_SR_88200
;
1124 fs
= DA7213_SR_96000
;
1130 snd_soc_update_bits(codec
, DA7213_DAI_CTRL
, DA7213_DAI_WORD_LENGTH_MASK
,
1132 snd_soc_write(codec
, DA7213_SR
, fs
);
1137 static int da7213_set_dai_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
1139 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1140 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
1141 u8 dai_clk_mode
= 0, dai_ctrl
= 0;
1143 /* Set master/slave mode */
1144 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1145 case SND_SOC_DAIFMT_CBM_CFM
:
1146 dai_clk_mode
|= DA7213_DAI_CLK_EN_MASTER_MODE
;
1147 da7213
->master
= true;
1149 case SND_SOC_DAIFMT_CBS_CFS
:
1150 dai_clk_mode
|= DA7213_DAI_CLK_EN_SLAVE_MODE
;
1151 da7213
->master
= false;
1157 /* Set clock normal/inverted */
1158 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1159 case SND_SOC_DAIFMT_NB_NF
:
1161 case SND_SOC_DAIFMT_NB_IF
:
1162 dai_clk_mode
|= DA7213_DAI_WCLK_POL_INV
;
1164 case SND_SOC_DAIFMT_IB_NF
:
1165 dai_clk_mode
|= DA7213_DAI_CLK_POL_INV
;
1167 case SND_SOC_DAIFMT_IB_IF
:
1168 dai_clk_mode
|= DA7213_DAI_WCLK_POL_INV
| DA7213_DAI_CLK_POL_INV
;
1174 /* Only I2S is supported */
1175 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1176 case SND_SOC_DAIFMT_I2S
:
1177 dai_ctrl
|= DA7213_DAI_FORMAT_I2S_MODE
;
1179 case SND_SOC_DAIFMT_LEFT_J
:
1180 dai_ctrl
|= DA7213_DAI_FORMAT_LEFT_J
;
1182 case SND_SOC_DAIFMT_RIGHT_J
:
1183 dai_ctrl
|= DA7213_DAI_FORMAT_RIGHT_J
;
1189 /* By default only 32 BCLK per WCLK is supported */
1190 dai_clk_mode
|= DA7213_DAI_BCLKS_PER_WCLK_32
;
1192 snd_soc_write(codec
, DA7213_DAI_CLK_MODE
, dai_clk_mode
);
1193 snd_soc_update_bits(codec
, DA7213_DAI_CTRL
, DA7213_DAI_FORMAT_MASK
,
1199 static int da7213_mute(struct snd_soc_dai
*dai
, int mute
)
1201 struct snd_soc_codec
*codec
= dai
->codec
;
1204 snd_soc_update_bits(codec
, DA7213_DAC_L_CTRL
,
1205 DA7213_MUTE_EN
, DA7213_MUTE_EN
);
1206 snd_soc_update_bits(codec
, DA7213_DAC_R_CTRL
,
1207 DA7213_MUTE_EN
, DA7213_MUTE_EN
);
1209 snd_soc_update_bits(codec
, DA7213_DAC_L_CTRL
,
1211 snd_soc_update_bits(codec
, DA7213_DAC_R_CTRL
,
1218 #define DA7213_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1219 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1221 static int da7213_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
1222 int clk_id
, unsigned int freq
, int dir
)
1224 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1225 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
1228 if ((da7213
->clk_src
== clk_id
) && (da7213
->mclk_rate
== freq
))
1231 if (((freq
< 5000000) && (freq
!= 32768)) || (freq
> 54000000)) {
1232 dev_err(codec_dai
->dev
, "Unsupported MCLK value %d\n",
1238 case DA7213_CLKSRC_MCLK
:
1239 da7213
->mclk_squarer_en
= false;
1241 case DA7213_CLKSRC_MCLK_SQR
:
1242 da7213
->mclk_squarer_en
= true;
1245 dev_err(codec_dai
->dev
, "Unknown clock source %d\n", clk_id
);
1249 da7213
->clk_src
= clk_id
;
1252 freq
= clk_round_rate(da7213
->mclk
, freq
);
1253 ret
= clk_set_rate(da7213
->mclk
, freq
);
1255 dev_err(codec_dai
->dev
, "Failed to set clock rate %d\n",
1261 da7213
->mclk_rate
= freq
;
1266 /* Supported PLL input frequencies are 5MHz - 54MHz. */
1267 static int da7213_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
1268 int source
, unsigned int fref
, unsigned int fout
)
1270 struct snd_soc_codec
*codec
= codec_dai
->codec
;
1271 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
1273 u8 pll_ctrl
, indiv_bits
, indiv
;
1274 u8 pll_frac_top
, pll_frac_bot
, pll_integer
;
1278 /* Reset PLL configuration */
1279 snd_soc_write(codec
, DA7213_PLL_CTRL
, 0);
1283 /* Workout input divider based on MCLK rate */
1284 if ((da7213
->mclk_rate
== 32768) && (source
== DA7213_SYSCLK_PLL
)) {
1285 /* 32KHz PLL Mode */
1286 indiv_bits
= DA7213_PLL_INDIV_10_20_MHZ
;
1287 indiv
= DA7213_PLL_INDIV_10_20_MHZ_VAL
;
1289 pll_ctrl
|= DA7213_PLL_32K_MODE
;
1291 /* 5 - 54MHz MCLK */
1292 if (da7213
->mclk_rate
< 5000000) {
1294 } else if (da7213
->mclk_rate
<= 10000000) {
1295 indiv_bits
= DA7213_PLL_INDIV_5_10_MHZ
;
1296 indiv
= DA7213_PLL_INDIV_5_10_MHZ_VAL
;
1297 } else if (da7213
->mclk_rate
<= 20000000) {
1298 indiv_bits
= DA7213_PLL_INDIV_10_20_MHZ
;
1299 indiv
= DA7213_PLL_INDIV_10_20_MHZ_VAL
;
1300 } else if (da7213
->mclk_rate
<= 40000000) {
1301 indiv_bits
= DA7213_PLL_INDIV_20_40_MHZ
;
1302 indiv
= DA7213_PLL_INDIV_20_40_MHZ_VAL
;
1303 } else if (da7213
->mclk_rate
<= 54000000) {
1304 indiv_bits
= DA7213_PLL_INDIV_40_54_MHZ
;
1305 indiv
= DA7213_PLL_INDIV_40_54_MHZ_VAL
;
1309 freq_ref
= (da7213
->mclk_rate
/ indiv
);
1312 pll_ctrl
|= indiv_bits
;
1314 /* PLL Bypass mode */
1315 if (source
== DA7213_SYSCLK_MCLK
) {
1316 snd_soc_write(codec
, DA7213_PLL_CTRL
, pll_ctrl
);
1321 * If Codec is slave and SRM enabled,
1322 * freq_out is (98304000 + 90316800)/2 = 94310400
1324 if (!da7213
->master
&& da7213
->srm_en
) {
1325 fout
= DA7213_PLL_FREQ_OUT_94310400
;
1326 pll_ctrl
|= DA7213_PLL_SRM_EN
;
1329 /* Enable MCLK squarer if required */
1330 if (da7213
->mclk_squarer_en
)
1331 pll_ctrl
|= DA7213_PLL_MCLK_SQR_EN
;
1333 /* Calculate dividers for PLL */
1334 pll_integer
= fout
/ freq_ref
;
1335 frac_div
= (u64
)(fout
% freq_ref
) * 8192ULL;
1336 do_div(frac_div
, freq_ref
);
1337 pll_frac_top
= (frac_div
>> DA7213_BYTE_SHIFT
) & DA7213_BYTE_MASK
;
1338 pll_frac_bot
= (frac_div
) & DA7213_BYTE_MASK
;
1340 /* Write PLL dividers */
1341 snd_soc_write(codec
, DA7213_PLL_FRAC_TOP
, pll_frac_top
);
1342 snd_soc_write(codec
, DA7213_PLL_FRAC_BOT
, pll_frac_bot
);
1343 snd_soc_write(codec
, DA7213_PLL_INTEGER
, pll_integer
);
1346 pll_ctrl
|= DA7213_PLL_EN
;
1347 snd_soc_write(codec
, DA7213_PLL_CTRL
, pll_ctrl
);
1352 dev_err(codec_dai
->dev
, "Unsupported PLL input frequency %d\n",
1357 /* DAI operations */
1358 static const struct snd_soc_dai_ops da7213_dai_ops
= {
1359 .hw_params
= da7213_hw_params
,
1360 .set_fmt
= da7213_set_dai_fmt
,
1361 .set_sysclk
= da7213_set_dai_sysclk
,
1362 .set_pll
= da7213_set_dai_pll
,
1363 .digital_mute
= da7213_mute
,
1366 static struct snd_soc_dai_driver da7213_dai
= {
1367 .name
= "da7213-hifi",
1368 /* Playback Capabilities */
1370 .stream_name
= "Playback",
1373 .rates
= SNDRV_PCM_RATE_8000_96000
,
1374 .formats
= DA7213_FORMATS
,
1376 /* Capture Capabilities */
1378 .stream_name
= "Capture",
1381 .rates
= SNDRV_PCM_RATE_8000_96000
,
1382 .formats
= DA7213_FORMATS
,
1384 .ops
= &da7213_dai_ops
,
1385 .symmetric_rates
= 1,
1388 static int da7213_set_bias_level(struct snd_soc_codec
*codec
,
1389 enum snd_soc_bias_level level
)
1391 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
1395 case SND_SOC_BIAS_ON
:
1396 case SND_SOC_BIAS_PREPARE
:
1398 case SND_SOC_BIAS_STANDBY
:
1399 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
1402 ret
= clk_prepare_enable(da7213
->mclk
);
1405 "Failed to enable mclk\n");
1410 /* Enable VMID reference & master bias */
1411 snd_soc_update_bits(codec
, DA7213_REFERENCES
,
1412 DA7213_VMID_EN
| DA7213_BIAS_EN
,
1413 DA7213_VMID_EN
| DA7213_BIAS_EN
);
1416 case SND_SOC_BIAS_OFF
:
1417 /* Disable VMID reference & master bias */
1418 snd_soc_update_bits(codec
, DA7213_REFERENCES
,
1419 DA7213_VMID_EN
| DA7213_BIAS_EN
, 0);
1423 clk_disable_unprepare(da7213
->mclk
);
1430 static const struct of_device_id da7213_of_match
[] = {
1431 { .compatible
= "dlg,da7213", },
1434 MODULE_DEVICE_TABLE(of
, da7213_of_match
);
1436 static enum da7213_micbias_voltage
1437 da7213_of_micbias_lvl(struct snd_soc_codec
*codec
, u32 val
)
1441 return DA7213_MICBIAS_1_6V
;
1443 return DA7213_MICBIAS_2_2V
;
1445 return DA7213_MICBIAS_2_5V
;
1447 return DA7213_MICBIAS_3_0V
;
1449 dev_warn(codec
->dev
, "Invalid micbias level\n");
1450 return DA7213_MICBIAS_2_2V
;
1454 static enum da7213_dmic_data_sel
1455 da7213_of_dmic_data_sel(struct snd_soc_codec
*codec
, const char *str
)
1457 if (!strcmp(str
, "lrise_rfall")) {
1458 return DA7213_DMIC_DATA_LRISE_RFALL
;
1459 } else if (!strcmp(str
, "lfall_rrise")) {
1460 return DA7213_DMIC_DATA_LFALL_RRISE
;
1462 dev_warn(codec
->dev
, "Invalid DMIC data select type\n");
1463 return DA7213_DMIC_DATA_LRISE_RFALL
;
1467 static enum da7213_dmic_samplephase
1468 da7213_of_dmic_samplephase(struct snd_soc_codec
*codec
, const char *str
)
1470 if (!strcmp(str
, "on_clkedge")) {
1471 return DA7213_DMIC_SAMPLE_ON_CLKEDGE
;
1472 } else if (!strcmp(str
, "between_clkedge")) {
1473 return DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE
;
1475 dev_warn(codec
->dev
, "Invalid DMIC sample phase\n");
1476 return DA7213_DMIC_SAMPLE_ON_CLKEDGE
;
1480 static enum da7213_dmic_clk_rate
1481 da7213_of_dmic_clkrate(struct snd_soc_codec
*codec
, u32 val
)
1485 return DA7213_DMIC_CLK_1_5MHZ
;
1487 return DA7213_DMIC_CLK_3_0MHZ
;
1489 dev_warn(codec
->dev
, "Invalid DMIC clock rate\n");
1490 return DA7213_DMIC_CLK_1_5MHZ
;
1494 static struct da7213_platform_data
1495 *da7213_of_to_pdata(struct snd_soc_codec
*codec
)
1497 struct device_node
*np
= codec
->dev
->of_node
;
1498 struct da7213_platform_data
*pdata
;
1502 pdata
= devm_kzalloc(codec
->dev
, sizeof(*pdata
), GFP_KERNEL
);
1504 dev_warn(codec
->dev
, "Failed to allocate memory for pdata\n");
1508 if (of_property_read_u32(np
, "dlg,micbias1-lvl", &of_val32
) >= 0)
1509 pdata
->micbias1_lvl
= da7213_of_micbias_lvl(codec
, of_val32
);
1511 pdata
->micbias1_lvl
= DA7213_MICBIAS_2_2V
;
1513 if (of_property_read_u32(np
, "dlg,micbias2-lvl", &of_val32
) >= 0)
1514 pdata
->micbias2_lvl
= da7213_of_micbias_lvl(codec
, of_val32
);
1516 pdata
->micbias2_lvl
= DA7213_MICBIAS_2_2V
;
1518 if (!of_property_read_string(np
, "dlg,dmic-data-sel", &of_str
))
1519 pdata
->dmic_data_sel
= da7213_of_dmic_data_sel(codec
, of_str
);
1521 pdata
->dmic_data_sel
= DA7213_DMIC_DATA_LRISE_RFALL
;
1523 if (!of_property_read_string(np
, "dlg,dmic-samplephase", &of_str
))
1524 pdata
->dmic_samplephase
=
1525 da7213_of_dmic_samplephase(codec
, of_str
);
1527 pdata
->dmic_samplephase
= DA7213_DMIC_SAMPLE_ON_CLKEDGE
;
1529 if (of_property_read_u32(np
, "dlg,dmic-clkrate", &of_val32
) >= 0)
1530 pdata
->dmic_clk_rate
= da7213_of_dmic_clkrate(codec
, of_val32
);
1532 pdata
->dmic_clk_rate
= DA7213_DMIC_CLK_3_0MHZ
;
1538 static int da7213_probe(struct snd_soc_codec
*codec
)
1540 struct da7213_priv
*da7213
= snd_soc_codec_get_drvdata(codec
);
1542 /* Default to using ALC auto offset calibration mode. */
1543 snd_soc_update_bits(codec
, DA7213_ALC_CTRL1
,
1544 DA7213_ALC_CALIB_MODE_MAN
, 0);
1545 da7213
->alc_calib_auto
= true;
1547 /* Default to using SRM for slave mode */
1548 da7213
->srm_en
= true;
1550 /* Enable all Gain Ramps */
1551 snd_soc_update_bits(codec
, DA7213_AUX_L_CTRL
,
1552 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1553 snd_soc_update_bits(codec
, DA7213_AUX_R_CTRL
,
1554 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1555 snd_soc_update_bits(codec
, DA7213_MIXIN_L_CTRL
,
1556 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1557 snd_soc_update_bits(codec
, DA7213_MIXIN_R_CTRL
,
1558 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1559 snd_soc_update_bits(codec
, DA7213_ADC_L_CTRL
,
1560 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1561 snd_soc_update_bits(codec
, DA7213_ADC_R_CTRL
,
1562 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1563 snd_soc_update_bits(codec
, DA7213_DAC_L_CTRL
,
1564 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1565 snd_soc_update_bits(codec
, DA7213_DAC_R_CTRL
,
1566 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1567 snd_soc_update_bits(codec
, DA7213_HP_L_CTRL
,
1568 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1569 snd_soc_update_bits(codec
, DA7213_HP_R_CTRL
,
1570 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1571 snd_soc_update_bits(codec
, DA7213_LINE_CTRL
,
1572 DA7213_GAIN_RAMP_EN
, DA7213_GAIN_RAMP_EN
);
1575 * There are two separate control bits for input and output mixers as
1576 * well as headphone and line outs.
1577 * One to enable corresponding amplifier and other to enable its
1578 * output. As amplifier bits are related to power control, they are
1579 * being managed by DAPM while other (non power related) bits are
1582 snd_soc_update_bits(codec
, DA7213_MIXIN_L_CTRL
,
1583 DA7213_MIXIN_MIX_EN
, DA7213_MIXIN_MIX_EN
);
1584 snd_soc_update_bits(codec
, DA7213_MIXIN_R_CTRL
,
1585 DA7213_MIXIN_MIX_EN
, DA7213_MIXIN_MIX_EN
);
1587 snd_soc_update_bits(codec
, DA7213_MIXOUT_L_CTRL
,
1588 DA7213_MIXOUT_MIX_EN
, DA7213_MIXOUT_MIX_EN
);
1589 snd_soc_update_bits(codec
, DA7213_MIXOUT_R_CTRL
,
1590 DA7213_MIXOUT_MIX_EN
, DA7213_MIXOUT_MIX_EN
);
1592 snd_soc_update_bits(codec
, DA7213_HP_L_CTRL
,
1593 DA7213_HP_AMP_OE
, DA7213_HP_AMP_OE
);
1594 snd_soc_update_bits(codec
, DA7213_HP_R_CTRL
,
1595 DA7213_HP_AMP_OE
, DA7213_HP_AMP_OE
);
1597 snd_soc_update_bits(codec
, DA7213_LINE_CTRL
,
1598 DA7213_LINE_AMP_OE
, DA7213_LINE_AMP_OE
);
1600 /* Handle DT/Platform data */
1601 if (codec
->dev
->of_node
)
1602 da7213
->pdata
= da7213_of_to_pdata(codec
);
1604 da7213
->pdata
= dev_get_platdata(codec
->dev
);
1606 /* Set platform data values */
1607 if (da7213
->pdata
) {
1608 struct da7213_platform_data
*pdata
= da7213
->pdata
;
1609 u8 micbias_lvl
= 0, dmic_cfg
= 0;
1611 /* Set Mic Bias voltages */
1612 switch (pdata
->micbias1_lvl
) {
1613 case DA7213_MICBIAS_1_6V
:
1614 case DA7213_MICBIAS_2_2V
:
1615 case DA7213_MICBIAS_2_5V
:
1616 case DA7213_MICBIAS_3_0V
:
1617 micbias_lvl
|= (pdata
->micbias1_lvl
<<
1618 DA7213_MICBIAS1_LEVEL_SHIFT
);
1621 switch (pdata
->micbias2_lvl
) {
1622 case DA7213_MICBIAS_1_6V
:
1623 case DA7213_MICBIAS_2_2V
:
1624 case DA7213_MICBIAS_2_5V
:
1625 case DA7213_MICBIAS_3_0V
:
1626 micbias_lvl
|= (pdata
->micbias2_lvl
<<
1627 DA7213_MICBIAS2_LEVEL_SHIFT
);
1630 snd_soc_update_bits(codec
, DA7213_MICBIAS_CTRL
,
1631 DA7213_MICBIAS1_LEVEL_MASK
|
1632 DA7213_MICBIAS2_LEVEL_MASK
, micbias_lvl
);
1634 /* Set DMIC configuration */
1635 switch (pdata
->dmic_data_sel
) {
1636 case DA7213_DMIC_DATA_LFALL_RRISE
:
1637 case DA7213_DMIC_DATA_LRISE_RFALL
:
1638 dmic_cfg
|= (pdata
->dmic_data_sel
<<
1639 DA7213_DMIC_DATA_SEL_SHIFT
);
1642 switch (pdata
->dmic_samplephase
) {
1643 case DA7213_DMIC_SAMPLE_ON_CLKEDGE
:
1644 case DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE
:
1645 dmic_cfg
|= (pdata
->dmic_samplephase
<<
1646 DA7213_DMIC_SAMPLEPHASE_SHIFT
);
1649 switch (pdata
->dmic_clk_rate
) {
1650 case DA7213_DMIC_CLK_3_0MHZ
:
1651 case DA7213_DMIC_CLK_1_5MHZ
:
1652 dmic_cfg
|= (pdata
->dmic_clk_rate
<<
1653 DA7213_DMIC_CLK_RATE_SHIFT
);
1656 snd_soc_update_bits(codec
, DA7213_MIC_CONFIG
,
1657 DA7213_DMIC_DATA_SEL_MASK
|
1658 DA7213_DMIC_SAMPLEPHASE_MASK
|
1659 DA7213_DMIC_CLK_RATE_MASK
, dmic_cfg
);
1662 /* Check if MCLK provided */
1663 da7213
->mclk
= devm_clk_get(codec
->dev
, "mclk");
1664 if (IS_ERR(da7213
->mclk
)) {
1665 if (PTR_ERR(da7213
->mclk
) != -ENOENT
)
1666 return PTR_ERR(da7213
->mclk
);
1668 da7213
->mclk
= NULL
;
1674 static struct snd_soc_codec_driver soc_codec_dev_da7213
= {
1675 .probe
= da7213_probe
,
1676 .set_bias_level
= da7213_set_bias_level
,
1678 .controls
= da7213_snd_controls
,
1679 .num_controls
= ARRAY_SIZE(da7213_snd_controls
),
1681 .dapm_widgets
= da7213_dapm_widgets
,
1682 .num_dapm_widgets
= ARRAY_SIZE(da7213_dapm_widgets
),
1683 .dapm_routes
= da7213_audio_map
,
1684 .num_dapm_routes
= ARRAY_SIZE(da7213_audio_map
),
1687 static const struct regmap_config da7213_regmap_config
= {
1691 .reg_defaults
= da7213_reg_defaults
,
1692 .num_reg_defaults
= ARRAY_SIZE(da7213_reg_defaults
),
1693 .volatile_reg
= da7213_volatile_register
,
1694 .cache_type
= REGCACHE_RBTREE
,
1697 static int da7213_i2c_probe(struct i2c_client
*i2c
,
1698 const struct i2c_device_id
*id
)
1700 struct da7213_priv
*da7213
;
1703 da7213
= devm_kzalloc(&i2c
->dev
, sizeof(struct da7213_priv
),
1708 i2c_set_clientdata(i2c
, da7213
);
1710 da7213
->regmap
= devm_regmap_init_i2c(i2c
, &da7213_regmap_config
);
1711 if (IS_ERR(da7213
->regmap
)) {
1712 ret
= PTR_ERR(da7213
->regmap
);
1713 dev_err(&i2c
->dev
, "regmap_init() failed: %d\n", ret
);
1717 ret
= snd_soc_register_codec(&i2c
->dev
,
1718 &soc_codec_dev_da7213
, &da7213_dai
, 1);
1720 dev_err(&i2c
->dev
, "Failed to register da7213 codec: %d\n",
1726 static int da7213_remove(struct i2c_client
*client
)
1728 snd_soc_unregister_codec(&client
->dev
);
1732 static const struct i2c_device_id da7213_i2c_id
[] = {
1736 MODULE_DEVICE_TABLE(i2c
, da7213_i2c_id
);
1738 /* I2C codec control layer */
1739 static struct i2c_driver da7213_i2c_driver
= {
1742 .of_match_table
= of_match_ptr(da7213_of_match
),
1744 .probe
= da7213_i2c_probe
,
1745 .remove
= da7213_remove
,
1746 .id_table
= da7213_i2c_id
,
1749 module_i2c_driver(da7213_i2c_driver
);
1751 MODULE_DESCRIPTION("ASoC DA7213 Codec driver");
1752 MODULE_AUTHOR("Adam Thomson <Adam.Thomson.Opensource@diasemi.com>");
1753 MODULE_LICENSE("GPL");