1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5660.c -- RT5660 ALSA SoC audio codec driver
5 * Copyright 2016 Realtek Semiconductor Corp.
6 * Author: Oder Chiou <oder_chiou@realtek.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
14 #include <linux/gpio.h>
15 #include <linux/i2c.h>
16 #include <linux/regmap.h>
18 #include <linux/of_gpio.h>
19 #include <linux/platform_device.h>
20 #include <linux/spi/spi.h>
21 #include <linux/acpi.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dapm.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
33 #define RT5660_DEVICE_ID 0x6338
35 #define RT5660_PR_RANGE_BASE (0xff + 1)
36 #define RT5660_PR_SPACING 0x100
38 #define RT5660_PR_BASE (RT5660_PR_RANGE_BASE + (0 * RT5660_PR_SPACING))
40 static const struct regmap_range_cfg rt5660_ranges
[] = {
41 { .name
= "PR", .range_min
= RT5660_PR_BASE
,
42 .range_max
= RT5660_PR_BASE
+ 0xf3,
43 .selector_reg
= RT5660_PRIV_INDEX
,
44 .selector_mask
= 0xff,
45 .selector_shift
= 0x0,
46 .window_start
= RT5660_PRIV_DATA
,
50 static const struct reg_sequence rt5660_patch
[] = {
51 { RT5660_ALC_PGA_CTRL2
, 0x44c3 },
52 { RT5660_PR_BASE
+ 0x3d, 0x2600 },
55 static const struct reg_default rt5660_reg
[] = {
153 static bool rt5660_volatile_register(struct device
*dev
, unsigned int reg
)
157 for (i
= 0; i
< ARRAY_SIZE(rt5660_ranges
); i
++)
158 if ((reg
>= rt5660_ranges
[i
].window_start
&&
159 reg
<= rt5660_ranges
[i
].window_start
+
160 rt5660_ranges
[i
].window_len
) ||
161 (reg
>= rt5660_ranges
[i
].range_min
&&
162 reg
<= rt5660_ranges
[i
].range_max
))
167 case RT5660_PRIV_DATA
:
168 case RT5660_EQ_CTRL1
:
169 case RT5660_IRQ_CTRL2
:
170 case RT5660_INT_IRQ_ST
:
171 case RT5660_VENDOR_ID
:
172 case RT5660_VENDOR_ID1
:
173 case RT5660_VENDOR_ID2
:
180 static bool rt5660_readable_register(struct device
*dev
, unsigned int reg
)
184 for (i
= 0; i
< ARRAY_SIZE(rt5660_ranges
); i
++)
185 if ((reg
>= rt5660_ranges
[i
].window_start
&&
186 reg
<= rt5660_ranges
[i
].window_start
+
187 rt5660_ranges
[i
].window_len
) ||
188 (reg
>= rt5660_ranges
[i
].range_min
&&
189 reg
<= rt5660_ranges
[i
].range_max
))
195 case RT5660_LOUT_VOL
:
198 case RT5660_DAC1_DIG_VOL
:
199 case RT5660_STO1_ADC_DIG_VOL
:
200 case RT5660_ADC_BST_VOL1
:
201 case RT5660_STO1_ADC_MIXER
:
202 case RT5660_AD_DA_MIXER
:
203 case RT5660_STO_DAC_MIXER
:
204 case RT5660_DIG_INF1_DATA
:
205 case RT5660_REC_L1_MIXER
:
206 case RT5660_REC_L2_MIXER
:
207 case RT5660_REC_R1_MIXER
:
208 case RT5660_REC_R2_MIXER
:
209 case RT5660_LOUT_MIXER
:
210 case RT5660_SPK_MIXER
:
211 case RT5660_SPO_MIXER
:
212 case RT5660_SPO_CLSD_RATIO
:
213 case RT5660_OUT_L_GAIN1
:
214 case RT5660_OUT_L_GAIN2
:
215 case RT5660_OUT_L1_MIXER
:
216 case RT5660_OUT_R_GAIN1
:
217 case RT5660_OUT_R_GAIN2
:
218 case RT5660_OUT_R1_MIXER
:
219 case RT5660_PWR_DIG1
:
220 case RT5660_PWR_DIG2
:
221 case RT5660_PWR_ANLG1
:
222 case RT5660_PWR_ANLG2
:
223 case RT5660_PWR_MIXER
:
225 case RT5660_PRIV_INDEX
:
226 case RT5660_PRIV_DATA
:
227 case RT5660_I2S1_SDP
:
228 case RT5660_ADDA_CLK1
:
229 case RT5660_ADDA_CLK2
:
230 case RT5660_DMIC_CTRL1
:
232 case RT5660_PLL_CTRL1
:
233 case RT5660_PLL_CTRL2
:
234 case RT5660_CLSD_AMP_OC_CTRL
:
235 case RT5660_CLSD_AMP_CTRL
:
236 case RT5660_LOUT_AMP_CTRL
:
237 case RT5660_SPK_AMP_SPKVDD
:
239 case RT5660_CLSD_OUT_CTRL1
:
240 case RT5660_CLSD_OUT_CTRL2
:
241 case RT5660_DIPOLE_MIC_CTRL1
:
242 case RT5660_DIPOLE_MIC_CTRL2
:
243 case RT5660_DIPOLE_MIC_CTRL3
:
244 case RT5660_DIPOLE_MIC_CTRL4
:
245 case RT5660_DIPOLE_MIC_CTRL5
:
246 case RT5660_DIPOLE_MIC_CTRL6
:
247 case RT5660_DIPOLE_MIC_CTRL7
:
248 case RT5660_DIPOLE_MIC_CTRL8
:
249 case RT5660_DIPOLE_MIC_CTRL9
:
250 case RT5660_DIPOLE_MIC_CTRL10
:
251 case RT5660_DIPOLE_MIC_CTRL11
:
252 case RT5660_DIPOLE_MIC_CTRL12
:
253 case RT5660_EQ_CTRL1
:
254 case RT5660_EQ_CTRL2
:
255 case RT5660_DRC_AGC_CTRL1
:
256 case RT5660_DRC_AGC_CTRL2
:
257 case RT5660_DRC_AGC_CTRL3
:
258 case RT5660_DRC_AGC_CTRL4
:
259 case RT5660_DRC_AGC_CTRL5
:
261 case RT5660_IRQ_CTRL1
:
262 case RT5660_IRQ_CTRL2
:
263 case RT5660_INT_IRQ_ST
:
264 case RT5660_GPIO_CTRL1
:
265 case RT5660_GPIO_CTRL2
:
266 case RT5660_WIND_FILTER_CTRL1
:
269 case RT5660_DRC1_LM_CTRL1
:
270 case RT5660_DRC1_LM_CTRL2
:
271 case RT5660_DRC2_LM_CTRL1
:
272 case RT5660_DRC2_LM_CTRL2
:
273 case RT5660_MULTI_DRC_CTRL
:
274 case RT5660_DRC2_CTRL1
:
275 case RT5660_DRC2_CTRL2
:
276 case RT5660_DRC2_CTRL3
:
277 case RT5660_DRC2_CTRL4
:
278 case RT5660_DRC2_CTRL5
:
279 case RT5660_ALC_PGA_CTRL1
:
280 case RT5660_ALC_PGA_CTRL2
:
281 case RT5660_ALC_PGA_CTRL3
:
282 case RT5660_ALC_PGA_CTRL4
:
283 case RT5660_ALC_PGA_CTRL5
:
284 case RT5660_ALC_PGA_CTRL6
:
285 case RT5660_ALC_PGA_CTRL7
:
286 case RT5660_GEN_CTRL1
:
287 case RT5660_GEN_CTRL2
:
288 case RT5660_GEN_CTRL3
:
289 case RT5660_VENDOR_ID
:
290 case RT5660_VENDOR_ID1
:
291 case RT5660_VENDOR_ID2
:
298 static const DECLARE_TLV_DB_SCALE(rt5660_out_vol_tlv
, -4650, 150, 0);
299 static const DECLARE_TLV_DB_SCALE(rt5660_dac_vol_tlv
, -6525, 75, 0);
300 static const DECLARE_TLV_DB_SCALE(rt5660_adc_vol_tlv
, -1725, 75, 0);
301 static const DECLARE_TLV_DB_SCALE(rt5660_adc_bst_tlv
, 0, 1200, 0);
302 static const DECLARE_TLV_DB_SCALE(rt5660_bst_tlv
, -1200, 75, 0);
304 static const struct snd_kcontrol_new rt5660_snd_controls
[] = {
305 /* Speaker Output Volume */
306 SOC_SINGLE("Speaker Playback Switch", RT5660_SPK_VOL
, RT5660_L_MUTE_SFT
,
308 SOC_SINGLE_TLV("Speaker Playback Volume", RT5660_SPK_VOL
,
309 RT5660_L_VOL_SFT
, 39, 1, rt5660_out_vol_tlv
),
312 SOC_DOUBLE("OUT Playback Switch", RT5660_LOUT_VOL
, RT5660_L_MUTE_SFT
,
313 RT5660_R_MUTE_SFT
, 1, 1),
314 SOC_DOUBLE_TLV("OUT Playback Volume", RT5660_LOUT_VOL
, RT5660_L_VOL_SFT
,
315 RT5660_R_VOL_SFT
, 39, 1, rt5660_out_vol_tlv
),
317 /* DAC Digital Volume */
318 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5660_DAC1_DIG_VOL
,
319 RT5660_DAC_L1_VOL_SFT
, RT5660_DAC_R1_VOL_SFT
, 87, 0,
322 /* IN1/IN2/IN3 Control */
323 SOC_SINGLE_TLV("IN1 Boost Volume", RT5660_IN1_IN2
, RT5660_BST_SFT1
, 69,
325 SOC_SINGLE_TLV("IN2 Boost Volume", RT5660_IN1_IN2
, RT5660_BST_SFT2
, 69,
327 SOC_SINGLE_TLV("IN3 Boost Volume", RT5660_IN3_IN4
, RT5660_BST_SFT3
, 69,
330 /* ADC Digital Volume Control */
331 SOC_DOUBLE("ADC Capture Switch", RT5660_STO1_ADC_DIG_VOL
,
332 RT5660_L_MUTE_SFT
, RT5660_R_MUTE_SFT
, 1, 1),
333 SOC_DOUBLE_TLV("ADC Capture Volume", RT5660_STO1_ADC_DIG_VOL
,
334 RT5660_ADC_L_VOL_SFT
, RT5660_ADC_R_VOL_SFT
, 63, 0,
337 /* ADC Boost Volume Control */
338 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5660_ADC_BST_VOL1
,
339 RT5660_STO1_ADC_L_BST_SFT
, RT5660_STO1_ADC_R_BST_SFT
, 3, 0,
344 * rt5660_set_dmic_clk - Set parameter of dmic.
347 * @kcontrol: The kcontrol of this widget.
351 static int rt5660_set_dmic_clk(struct snd_soc_dapm_widget
*w
,
352 struct snd_kcontrol
*kcontrol
, int event
)
354 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
355 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
358 rate
= rt5660
->sysclk
/ rl6231_get_pre_div(rt5660
->regmap
,
359 RT5660_ADDA_CLK1
, RT5660_I2S_PD1_SFT
);
360 idx
= rl6231_calc_dmic_clk(rate
);
362 dev_err(component
->dev
, "Failed to set DMIC clock\n");
364 snd_soc_component_update_bits(component
, RT5660_DMIC_CTRL1
,
365 RT5660_DMIC_CLK_MASK
, idx
<< RT5660_DMIC_CLK_SFT
);
370 static int rt5660_is_sys_clk_from_pll(struct snd_soc_dapm_widget
*source
,
371 struct snd_soc_dapm_widget
*sink
)
373 struct snd_soc_component
*component
= snd_soc_dapm_to_component(source
->dapm
);
376 val
= snd_soc_component_read32(component
, RT5660_GLB_CLK
);
377 val
&= RT5660_SCLK_SRC_MASK
;
378 if (val
== RT5660_SCLK_SRC_PLL1
)
385 static const struct snd_kcontrol_new rt5660_sto1_adc_l_mix
[] = {
386 SOC_DAPM_SINGLE("ADC1 Switch", RT5660_STO1_ADC_MIXER
,
387 RT5660_M_ADC_L1_SFT
, 1, 1),
388 SOC_DAPM_SINGLE("ADC2 Switch", RT5660_STO1_ADC_MIXER
,
389 RT5660_M_ADC_L2_SFT
, 1, 1),
392 static const struct snd_kcontrol_new rt5660_sto1_adc_r_mix
[] = {
393 SOC_DAPM_SINGLE("ADC1 Switch", RT5660_STO1_ADC_MIXER
,
394 RT5660_M_ADC_R1_SFT
, 1, 1),
395 SOC_DAPM_SINGLE("ADC2 Switch", RT5660_STO1_ADC_MIXER
,
396 RT5660_M_ADC_R2_SFT
, 1, 1),
399 static const struct snd_kcontrol_new rt5660_dac_l_mix
[] = {
400 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5660_AD_DA_MIXER
,
401 RT5660_M_ADCMIX_L_SFT
, 1, 1),
402 SOC_DAPM_SINGLE("DAC1 Switch", RT5660_AD_DA_MIXER
,
403 RT5660_M_DAC1_L_SFT
, 1, 1),
406 static const struct snd_kcontrol_new rt5660_dac_r_mix
[] = {
407 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5660_AD_DA_MIXER
,
408 RT5660_M_ADCMIX_R_SFT
, 1, 1),
409 SOC_DAPM_SINGLE("DAC1 Switch", RT5660_AD_DA_MIXER
,
410 RT5660_M_DAC1_R_SFT
, 1, 1),
413 static const struct snd_kcontrol_new rt5660_sto_dac_l_mix
[] = {
414 SOC_DAPM_SINGLE("DAC L1 Switch", RT5660_STO_DAC_MIXER
,
415 RT5660_M_DAC_L1_SFT
, 1, 1),
416 SOC_DAPM_SINGLE("DAC R1 Switch", RT5660_STO_DAC_MIXER
,
417 RT5660_M_DAC_R1_STO_L_SFT
, 1, 1),
420 static const struct snd_kcontrol_new rt5660_sto_dac_r_mix
[] = {
421 SOC_DAPM_SINGLE("DAC R1 Switch", RT5660_STO_DAC_MIXER
,
422 RT5660_M_DAC_R1_SFT
, 1, 1),
423 SOC_DAPM_SINGLE("DAC L1 Switch", RT5660_STO_DAC_MIXER
,
424 RT5660_M_DAC_L1_STO_R_SFT
, 1, 1),
427 /* Analog Input Mixer */
428 static const struct snd_kcontrol_new rt5660_rec_l_mix
[] = {
429 SOC_DAPM_SINGLE("BST3 Switch", RT5660_REC_L2_MIXER
,
430 RT5660_M_BST3_RM_L_SFT
, 1, 1),
431 SOC_DAPM_SINGLE("BST2 Switch", RT5660_REC_L2_MIXER
,
432 RT5660_M_BST2_RM_L_SFT
, 1, 1),
433 SOC_DAPM_SINGLE("BST1 Switch", RT5660_REC_L2_MIXER
,
434 RT5660_M_BST1_RM_L_SFT
, 1, 1),
435 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5660_REC_L2_MIXER
,
436 RT5660_M_OM_L_RM_L_SFT
, 1, 1),
439 static const struct snd_kcontrol_new rt5660_rec_r_mix
[] = {
440 SOC_DAPM_SINGLE("BST3 Switch", RT5660_REC_R2_MIXER
,
441 RT5660_M_BST3_RM_R_SFT
, 1, 1),
442 SOC_DAPM_SINGLE("BST2 Switch", RT5660_REC_R2_MIXER
,
443 RT5660_M_BST2_RM_R_SFT
, 1, 1),
444 SOC_DAPM_SINGLE("BST1 Switch", RT5660_REC_R2_MIXER
,
445 RT5660_M_BST1_RM_R_SFT
, 1, 1),
446 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5660_REC_R2_MIXER
,
447 RT5660_M_OM_R_RM_R_SFT
, 1, 1),
450 static const struct snd_kcontrol_new rt5660_spk_mix
[] = {
451 SOC_DAPM_SINGLE("BST3 Switch", RT5660_SPK_MIXER
,
452 RT5660_M_BST3_SM_SFT
, 1, 1),
453 SOC_DAPM_SINGLE("BST1 Switch", RT5660_SPK_MIXER
,
454 RT5660_M_BST1_SM_SFT
, 1, 1),
455 SOC_DAPM_SINGLE("DACL Switch", RT5660_SPK_MIXER
,
456 RT5660_M_DACL_SM_SFT
, 1, 1),
457 SOC_DAPM_SINGLE("DACR Switch", RT5660_SPK_MIXER
,
458 RT5660_M_DACR_SM_SFT
, 1, 1),
459 SOC_DAPM_SINGLE("OUTMIXL Switch", RT5660_SPK_MIXER
,
460 RT5660_M_OM_L_SM_SFT
, 1, 1),
463 static const struct snd_kcontrol_new rt5660_out_l_mix
[] = {
464 SOC_DAPM_SINGLE("BST3 Switch", RT5660_OUT_L1_MIXER
,
465 RT5660_M_BST3_OM_L_SFT
, 1, 1),
466 SOC_DAPM_SINGLE("BST2 Switch", RT5660_OUT_L1_MIXER
,
467 RT5660_M_BST2_OM_L_SFT
, 1, 1),
468 SOC_DAPM_SINGLE("BST1 Switch", RT5660_OUT_L1_MIXER
,
469 RT5660_M_BST1_OM_L_SFT
, 1, 1),
470 SOC_DAPM_SINGLE("RECMIXL Switch", RT5660_OUT_L1_MIXER
,
471 RT5660_M_RM_L_OM_L_SFT
, 1, 1),
472 SOC_DAPM_SINGLE("DACR Switch", RT5660_OUT_L1_MIXER
,
473 RT5660_M_DAC_R_OM_L_SFT
, 1, 1),
474 SOC_DAPM_SINGLE("DACL Switch", RT5660_OUT_L1_MIXER
,
475 RT5660_M_DAC_L_OM_L_SFT
, 1, 1),
478 static const struct snd_kcontrol_new rt5660_out_r_mix
[] = {
479 SOC_DAPM_SINGLE("BST2 Switch", RT5660_OUT_R1_MIXER
,
480 RT5660_M_BST2_OM_R_SFT
, 1, 1),
481 SOC_DAPM_SINGLE("BST1 Switch", RT5660_OUT_R1_MIXER
,
482 RT5660_M_BST1_OM_R_SFT
, 1, 1),
483 SOC_DAPM_SINGLE("RECMIXR Switch", RT5660_OUT_R1_MIXER
,
484 RT5660_M_RM_R_OM_R_SFT
, 1, 1),
485 SOC_DAPM_SINGLE("DACR Switch", RT5660_OUT_R1_MIXER
,
486 RT5660_M_DAC_R_OM_R_SFT
, 1, 1),
487 SOC_DAPM_SINGLE("DACL Switch", RT5660_OUT_R1_MIXER
,
488 RT5660_M_DAC_L_OM_R_SFT
, 1, 1),
491 static const struct snd_kcontrol_new rt5660_spo_mix
[] = {
492 SOC_DAPM_SINGLE("DACR Switch", RT5660_SPO_MIXER
,
493 RT5660_M_DAC_R_SPM_SFT
, 1, 1),
494 SOC_DAPM_SINGLE("DACL Switch", RT5660_SPO_MIXER
,
495 RT5660_M_DAC_L_SPM_SFT
, 1, 1),
496 SOC_DAPM_SINGLE("SPKVOL Switch", RT5660_SPO_MIXER
,
497 RT5660_M_SV_SPM_SFT
, 1, 1),
498 SOC_DAPM_SINGLE("BST1 Switch", RT5660_SPO_MIXER
,
499 RT5660_M_BST1_SPM_SFT
, 1, 1),
502 static const struct snd_kcontrol_new rt5660_lout_mix
[] = {
503 SOC_DAPM_SINGLE("DAC Switch", RT5660_LOUT_MIXER
,
504 RT5660_M_DAC1_LM_SFT
, 1, 1),
505 SOC_DAPM_SINGLE("OUTMIX Switch", RT5660_LOUT_MIXER
,
506 RT5660_M_LOVOL_LM_SFT
, 1, 1),
509 static const struct snd_kcontrol_new spk_vol_control
=
510 SOC_DAPM_SINGLE("Switch", RT5660_SPK_VOL
,
511 RT5660_VOL_L_SFT
, 1, 1);
513 static const struct snd_kcontrol_new lout_l_vol_control
=
514 SOC_DAPM_SINGLE("Switch", RT5660_LOUT_VOL
,
515 RT5660_VOL_L_SFT
, 1, 1);
517 static const struct snd_kcontrol_new lout_r_vol_control
=
518 SOC_DAPM_SINGLE("Switch", RT5660_LOUT_VOL
,
519 RT5660_VOL_R_SFT
, 1, 1);
521 /* Interface data select */
522 static const char * const rt5660_data_select
[] = {
523 "L/R", "R/L", "L/L", "R/R"
526 static SOC_ENUM_SINGLE_DECL(rt5660_if1_dac_enum
,
527 RT5660_DIG_INF1_DATA
, RT5660_IF1_DAC_IN_SFT
, rt5660_data_select
);
529 static SOC_ENUM_SINGLE_DECL(rt5660_if1_adc_enum
,
530 RT5660_DIG_INF1_DATA
, RT5660_IF1_ADC_IN_SFT
, rt5660_data_select
);
532 static const struct snd_kcontrol_new rt5660_if1_dac_swap_mux
=
533 SOC_DAPM_ENUM("IF1 DAC Swap Source", rt5660_if1_dac_enum
);
535 static const struct snd_kcontrol_new rt5660_if1_adc_swap_mux
=
536 SOC_DAPM_ENUM("IF1 ADC Swap Source", rt5660_if1_adc_enum
);
538 static int rt5660_lout_event(struct snd_soc_dapm_widget
*w
,
539 struct snd_kcontrol
*kcontrol
, int event
)
541 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
544 case SND_SOC_DAPM_POST_PMU
:
545 snd_soc_component_update_bits(component
, RT5660_LOUT_AMP_CTRL
,
546 RT5660_LOUT_CO_MASK
| RT5660_LOUT_CB_MASK
,
547 RT5660_LOUT_CO_EN
| RT5660_LOUT_CB_PU
);
550 case SND_SOC_DAPM_PRE_PMD
:
551 snd_soc_component_update_bits(component
, RT5660_LOUT_AMP_CTRL
,
552 RT5660_LOUT_CO_MASK
| RT5660_LOUT_CB_MASK
,
553 RT5660_LOUT_CO_DIS
| RT5660_LOUT_CB_PD
);
563 static const struct snd_soc_dapm_widget rt5660_dapm_widgets
[] = {
564 SND_SOC_DAPM_SUPPLY("LDO2", RT5660_PWR_ANLG1
,
565 RT5660_PWR_LDO2_BIT
, 0, NULL
, 0),
566 SND_SOC_DAPM_SUPPLY("PLL1", RT5660_PWR_ANLG2
,
567 RT5660_PWR_PLL_BIT
, 0, NULL
, 0),
570 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5660_PWR_ANLG2
,
571 RT5660_PWR_MB1_BIT
, 0, NULL
, 0),
572 SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5660_PWR_ANLG2
,
573 RT5660_PWR_MB2_BIT
, 0, NULL
, 0),
577 SND_SOC_DAPM_INPUT("DMIC L1"),
578 SND_SOC_DAPM_INPUT("DMIC R1"),
580 SND_SOC_DAPM_INPUT("IN1P"),
581 SND_SOC_DAPM_INPUT("IN1N"),
582 SND_SOC_DAPM_INPUT("IN2P"),
583 SND_SOC_DAPM_INPUT("IN3P"),
584 SND_SOC_DAPM_INPUT("IN3N"),
586 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
587 rt5660_set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
588 SND_SOC_DAPM_SUPPLY("DMIC Power", RT5660_DMIC_CTRL1
,
589 RT5660_DMIC_1_EN_SFT
, 0, NULL
, 0),
592 SND_SOC_DAPM_PGA("BST1", RT5660_PWR_ANLG2
, RT5660_PWR_BST1_BIT
, 0,
594 SND_SOC_DAPM_PGA("BST2", RT5660_PWR_ANLG2
, RT5660_PWR_BST2_BIT
, 0,
596 SND_SOC_DAPM_PGA("BST3", RT5660_PWR_ANLG2
, RT5660_PWR_BST3_BIT
, 0,
600 SND_SOC_DAPM_MIXER("RECMIXL", RT5660_PWR_MIXER
, RT5660_PWR_RM_L_BIT
,
601 0, rt5660_rec_l_mix
, ARRAY_SIZE(rt5660_rec_l_mix
)),
602 SND_SOC_DAPM_MIXER("RECMIXR", RT5660_PWR_MIXER
, RT5660_PWR_RM_R_BIT
,
603 0, rt5660_rec_r_mix
, ARRAY_SIZE(rt5660_rec_r_mix
)),
606 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
607 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
609 SND_SOC_DAPM_SUPPLY("ADC L power", RT5660_PWR_DIG1
,
610 RT5660_PWR_ADC_L_BIT
, 0, NULL
, 0),
611 SND_SOC_DAPM_SUPPLY("ADC R power", RT5660_PWR_DIG1
,
612 RT5660_PWR_ADC_R_BIT
, 0, NULL
, 0),
613 SND_SOC_DAPM_SUPPLY("ADC clock", RT5660_PR_BASE
+ RT5660_CHOP_DAC_ADC
,
617 SND_SOC_DAPM_SUPPLY("adc stereo1 filter", RT5660_PWR_DIG2
,
618 RT5660_PWR_ADC_S1F_BIT
, 0, NULL
, 0),
619 SND_SOC_DAPM_MIXER("Sto1 ADC MIXL", SND_SOC_NOPM
, 0, 0,
620 rt5660_sto1_adc_l_mix
, ARRAY_SIZE(rt5660_sto1_adc_l_mix
)),
621 SND_SOC_DAPM_MIXER("Sto1 ADC MIXR", SND_SOC_NOPM
, 0, 0,
622 rt5660_sto1_adc_r_mix
, ARRAY_SIZE(rt5660_sto1_adc_r_mix
)),
625 SND_SOC_DAPM_ADC("Stereo1 ADC MIXL", NULL
, RT5660_STO1_ADC_DIG_VOL
,
626 RT5660_L_MUTE_SFT
, 1),
627 SND_SOC_DAPM_ADC("Stereo1 ADC MIXR", NULL
, RT5660_STO1_ADC_DIG_VOL
,
628 RT5660_R_MUTE_SFT
, 1),
630 /* Digital Interface */
631 SND_SOC_DAPM_SUPPLY("I2S1", RT5660_PWR_DIG1
, RT5660_PWR_I2S1_BIT
, 0,
633 SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
634 SND_SOC_DAPM_PGA("IF1 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
635 SND_SOC_DAPM_PGA("IF1 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
636 SND_SOC_DAPM_MUX("IF1 DAC Swap Mux", SND_SOC_NOPM
, 0, 0,
637 &rt5660_if1_dac_swap_mux
),
638 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
639 SND_SOC_DAPM_MUX("IF1 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
640 &rt5660_if1_adc_swap_mux
),
642 /* Audio Interface */
643 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
644 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM
, 0, 0),
647 /* DAC mixer before sound effect */
648 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM
, 0, 0, rt5660_dac_l_mix
,
649 ARRAY_SIZE(rt5660_dac_l_mix
)),
650 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM
, 0, 0, rt5660_dac_r_mix
,
651 ARRAY_SIZE(rt5660_dac_r_mix
)),
654 SND_SOC_DAPM_SUPPLY("dac stereo1 filter", RT5660_PWR_DIG2
,
655 RT5660_PWR_DAC_S1F_BIT
, 0, NULL
, 0),
656 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
657 rt5660_sto_dac_l_mix
, ARRAY_SIZE(rt5660_sto_dac_l_mix
)),
658 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
659 rt5660_sto_dac_r_mix
, ARRAY_SIZE(rt5660_sto_dac_r_mix
)),
662 SND_SOC_DAPM_DAC("DAC L1", NULL
, RT5660_PWR_DIG1
,
663 RT5660_PWR_DAC_L1_BIT
, 0),
664 SND_SOC_DAPM_DAC("DAC R1", NULL
, RT5660_PWR_DIG1
,
665 RT5660_PWR_DAC_R1_BIT
, 0),
668 SND_SOC_DAPM_MIXER("SPK MIX", RT5660_PWR_MIXER
, RT5660_PWR_SM_BIT
,
669 0, rt5660_spk_mix
, ARRAY_SIZE(rt5660_spk_mix
)),
670 SND_SOC_DAPM_MIXER("OUT MIXL", RT5660_PWR_MIXER
, RT5660_PWR_OM_L_BIT
,
671 0, rt5660_out_l_mix
, ARRAY_SIZE(rt5660_out_l_mix
)),
672 SND_SOC_DAPM_MIXER("OUT MIXR", RT5660_PWR_MIXER
, RT5660_PWR_OM_R_BIT
,
673 0, rt5660_out_r_mix
, ARRAY_SIZE(rt5660_out_r_mix
)),
676 SND_SOC_DAPM_SWITCH("SPKVOL", RT5660_PWR_VOL
,
677 RT5660_PWR_SV_BIT
, 0, &spk_vol_control
),
678 SND_SOC_DAPM_PGA("DAC 1", SND_SOC_NOPM
,
680 SND_SOC_DAPM_PGA("LOUTVOL", SND_SOC_NOPM
,
682 SND_SOC_DAPM_SWITCH("LOUTVOL L", SND_SOC_NOPM
,
683 RT5660_PWR_LV_L_BIT
, 0, &lout_l_vol_control
),
684 SND_SOC_DAPM_SWITCH("LOUTVOL R", SND_SOC_NOPM
,
685 RT5660_PWR_LV_R_BIT
, 0, &lout_r_vol_control
),
687 /* HPO/LOUT/Mono Mixer */
688 SND_SOC_DAPM_MIXER("SPO MIX", SND_SOC_NOPM
, 0,
689 0, rt5660_spo_mix
, ARRAY_SIZE(rt5660_spo_mix
)),
690 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM
, 0, 0,
691 rt5660_lout_mix
, ARRAY_SIZE(rt5660_lout_mix
)),
692 SND_SOC_DAPM_SUPPLY("VREF HP", RT5660_GEN_CTRL1
,
693 RT5660_PWR_VREF_HP_SFT
, 0, NULL
, 0),
694 SND_SOC_DAPM_PGA_S("LOUT amp", 1, RT5660_PWR_ANLG1
,
695 RT5660_PWR_HA_BIT
, 0, rt5660_lout_event
,
696 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
697 SND_SOC_DAPM_PGA_S("SPK amp", 1, RT5660_PWR_DIG1
,
698 RT5660_PWR_CLS_D_BIT
, 0, NULL
, 0),
701 SND_SOC_DAPM_OUTPUT("LOUTL"),
702 SND_SOC_DAPM_OUTPUT("LOUTR"),
703 SND_SOC_DAPM_OUTPUT("SPO"),
706 static const struct snd_soc_dapm_route rt5660_dapm_routes
[] = {
707 { "MICBIAS1", NULL
, "LDO2" },
708 { "MICBIAS2", NULL
, "LDO2" },
710 { "BST1", NULL
, "IN1P" },
711 { "BST1", NULL
, "IN1N" },
712 { "BST2", NULL
, "IN2P" },
713 { "BST3", NULL
, "IN3P" },
714 { "BST3", NULL
, "IN3N" },
716 { "RECMIXL", "BST3 Switch", "BST3" },
717 { "RECMIXL", "BST2 Switch", "BST2" },
718 { "RECMIXL", "BST1 Switch", "BST1" },
719 { "RECMIXL", "OUT MIXL Switch", "OUT MIXL" },
721 { "RECMIXR", "BST3 Switch", "BST3" },
722 { "RECMIXR", "BST2 Switch", "BST2" },
723 { "RECMIXR", "BST1 Switch", "BST1" },
724 { "RECMIXR", "OUT MIXR Switch", "OUT MIXR" },
726 { "ADC L", NULL
, "RECMIXL" },
727 { "ADC L", NULL
, "ADC L power" },
728 { "ADC L", NULL
, "ADC clock" },
729 { "ADC R", NULL
, "RECMIXR" },
730 { "ADC R", NULL
, "ADC R power" },
731 { "ADC R", NULL
, "ADC clock" },
733 {"DMIC L1", NULL
, "DMIC CLK"},
734 {"DMIC L1", NULL
, "DMIC Power"},
735 {"DMIC R1", NULL
, "DMIC CLK"},
736 {"DMIC R1", NULL
, "DMIC Power"},
738 { "Sto1 ADC MIXL", "ADC1 Switch", "ADC L" },
739 { "Sto1 ADC MIXL", "ADC2 Switch", "DMIC L1" },
740 { "Sto1 ADC MIXR", "ADC1 Switch", "ADC R" },
741 { "Sto1 ADC MIXR", "ADC2 Switch", "DMIC R1" },
743 { "Stereo1 ADC MIXL", NULL
, "Sto1 ADC MIXL" },
744 { "Stereo1 ADC MIXL", NULL
, "adc stereo1 filter" },
745 { "adc stereo1 filter", NULL
, "PLL1", rt5660_is_sys_clk_from_pll
},
747 { "Stereo1 ADC MIXR", NULL
, "Sto1 ADC MIXR" },
748 { "Stereo1 ADC MIXR", NULL
, "adc stereo1 filter" },
749 { "adc stereo1 filter", NULL
, "PLL1", rt5660_is_sys_clk_from_pll
},
751 { "IF1 ADC", NULL
, "Stereo1 ADC MIXL" },
752 { "IF1 ADC", NULL
, "Stereo1 ADC MIXR" },
753 { "IF1 ADC", NULL
, "I2S1" },
755 { "IF1 ADC Swap Mux", "L/R", "IF1 ADC" },
756 { "IF1 ADC Swap Mux", "R/L", "IF1 ADC" },
757 { "IF1 ADC Swap Mux", "L/L", "IF1 ADC" },
758 { "IF1 ADC Swap Mux", "R/R", "IF1 ADC" },
759 { "AIF1TX", NULL
, "IF1 ADC Swap Mux" },
761 { "IF1 DAC", NULL
, "AIF1RX" },
762 { "IF1 DAC", NULL
, "I2S1" },
764 { "IF1 DAC Swap Mux", "L/R", "IF1 DAC" },
765 { "IF1 DAC Swap Mux", "R/L", "IF1 DAC" },
766 { "IF1 DAC Swap Mux", "L/L", "IF1 DAC" },
767 { "IF1 DAC Swap Mux", "R/R", "IF1 DAC" },
769 { "IF1 DAC L", NULL
, "IF1 DAC Swap Mux" },
770 { "IF1 DAC R", NULL
, "IF1 DAC Swap Mux" },
772 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" },
773 { "DAC1 MIXL", "DAC1 Switch", "IF1 DAC L" },
774 { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR" },
775 { "DAC1 MIXR", "DAC1 Switch", "IF1 DAC R" },
777 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
778 { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
779 { "Stereo DAC MIXL", NULL
, "dac stereo1 filter" },
780 { "dac stereo1 filter", NULL
, "PLL1", rt5660_is_sys_clk_from_pll
},
781 { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
782 { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
783 { "Stereo DAC MIXR", NULL
, "dac stereo1 filter" },
784 { "dac stereo1 filter", NULL
, "PLL1", rt5660_is_sys_clk_from_pll
},
786 { "DAC L1", NULL
, "Stereo DAC MIXL" },
787 { "DAC R1", NULL
, "Stereo DAC MIXR" },
789 { "SPK MIX", "BST3 Switch", "BST3" },
790 { "SPK MIX", "BST1 Switch", "BST1" },
791 { "SPK MIX", "DACL Switch", "DAC L1" },
792 { "SPK MIX", "DACR Switch", "DAC R1" },
793 { "SPK MIX", "OUTMIXL Switch", "OUT MIXL" },
795 { "OUT MIXL", "BST3 Switch", "BST3" },
796 { "OUT MIXL", "BST2 Switch", "BST2" },
797 { "OUT MIXL", "BST1 Switch", "BST1" },
798 { "OUT MIXL", "RECMIXL Switch", "RECMIXL" },
799 { "OUT MIXL", "DACR Switch", "DAC R1" },
800 { "OUT MIXL", "DACL Switch", "DAC L1" },
802 { "OUT MIXR", "BST2 Switch", "BST2" },
803 { "OUT MIXR", "BST1 Switch", "BST1" },
804 { "OUT MIXR", "RECMIXR Switch", "RECMIXR" },
805 { "OUT MIXR", "DACR Switch", "DAC R1" },
806 { "OUT MIXR", "DACL Switch", "DAC L1" },
808 { "SPO MIX", "DACR Switch", "DAC R1" },
809 { "SPO MIX", "DACL Switch", "DAC L1" },
810 { "SPO MIX", "SPKVOL Switch", "SPKVOL" },
811 { "SPO MIX", "BST1 Switch", "BST1" },
813 { "SPKVOL", "Switch", "SPK MIX" },
814 { "LOUTVOL L", "Switch", "OUT MIXL" },
815 { "LOUTVOL R", "Switch", "OUT MIXR" },
817 { "LOUTVOL", NULL
, "LOUTVOL L" },
818 { "LOUTVOL", NULL
, "LOUTVOL R" },
820 { "DAC 1", NULL
, "DAC L1" },
821 { "DAC 1", NULL
, "DAC R1" },
823 { "LOUT MIX", "DAC Switch", "DAC 1" },
824 { "LOUT MIX", "OUTMIX Switch", "LOUTVOL" },
826 { "LOUT amp", NULL
, "LOUT MIX" },
827 { "LOUT amp", NULL
, "VREF HP" },
828 { "LOUTL", NULL
, "LOUT amp" },
829 { "LOUTR", NULL
, "LOUT amp" },
831 { "SPK amp", NULL
, "SPO MIX" },
832 { "SPO", NULL
, "SPK amp" },
835 static int rt5660_hw_params(struct snd_pcm_substream
*substream
,
836 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
838 struct snd_soc_component
*component
= dai
->component
;
839 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
840 unsigned int val_len
= 0, val_clk
, mask_clk
;
841 int pre_div
, bclk_ms
, frame_size
;
843 rt5660
->lrck
[dai
->id
] = params_rate(params
);
844 pre_div
= rl6231_get_clk_info(rt5660
->sysclk
, rt5660
->lrck
[dai
->id
]);
846 dev_err(component
->dev
, "Unsupported clock setting %d for DAI %d\n",
847 rt5660
->lrck
[dai
->id
], dai
->id
);
851 frame_size
= snd_soc_params_to_frame_size(params
);
852 if (frame_size
< 0) {
853 dev_err(component
->dev
, "Unsupported frame size: %d\n", frame_size
);
862 rt5660
->bclk
[dai
->id
] = rt5660
->lrck
[dai
->id
] * (32 << bclk_ms
);
864 dev_dbg(dai
->dev
, "bclk is %dHz and lrck is %dHz\n",
865 rt5660
->bclk
[dai
->id
], rt5660
->lrck
[dai
->id
]);
866 dev_dbg(dai
->dev
, "bclk_ms is %d and pre_div is %d for iis %d\n",
867 bclk_ms
, pre_div
, dai
->id
);
869 switch (params_width(params
)) {
873 val_len
|= RT5660_I2S_DL_20
;
876 val_len
|= RT5660_I2S_DL_24
;
879 val_len
|= RT5660_I2S_DL_8
;
887 mask_clk
= RT5660_I2S_BCLK_MS1_MASK
| RT5660_I2S_PD1_MASK
;
888 val_clk
= bclk_ms
<< RT5660_I2S_BCLK_MS1_SFT
|
889 pre_div
<< RT5660_I2S_PD1_SFT
;
890 snd_soc_component_update_bits(component
, RT5660_I2S1_SDP
, RT5660_I2S_DL_MASK
,
892 snd_soc_component_update_bits(component
, RT5660_ADDA_CLK1
, mask_clk
, val_clk
);
896 dev_err(component
->dev
, "Invalid dai->id: %d\n", dai
->id
);
903 static int rt5660_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
905 struct snd_soc_component
*component
= dai
->component
;
906 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
907 unsigned int reg_val
= 0;
909 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
910 case SND_SOC_DAIFMT_CBM_CFM
:
911 rt5660
->master
[dai
->id
] = 1;
914 case SND_SOC_DAIFMT_CBS_CFS
:
915 reg_val
|= RT5660_I2S_MS_S
;
916 rt5660
->master
[dai
->id
] = 0;
923 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
924 case SND_SOC_DAIFMT_NB_NF
:
927 case SND_SOC_DAIFMT_IB_NF
:
928 reg_val
|= RT5660_I2S_BP_INV
;
935 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
936 case SND_SOC_DAIFMT_I2S
:
939 case SND_SOC_DAIFMT_LEFT_J
:
940 reg_val
|= RT5660_I2S_DF_LEFT
;
943 case SND_SOC_DAIFMT_DSP_A
:
944 reg_val
|= RT5660_I2S_DF_PCM_A
;
947 case SND_SOC_DAIFMT_DSP_B
:
948 reg_val
|= RT5660_I2S_DF_PCM_B
;
957 snd_soc_component_update_bits(component
, RT5660_I2S1_SDP
,
958 RT5660_I2S_MS_MASK
| RT5660_I2S_BP_MASK
|
959 RT5660_I2S_DF_MASK
, reg_val
);
963 dev_err(component
->dev
, "Invalid dai->id: %d\n", dai
->id
);
970 static int rt5660_set_dai_sysclk(struct snd_soc_dai
*dai
,
971 int clk_id
, unsigned int freq
, int dir
)
973 struct snd_soc_component
*component
= dai
->component
;
974 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
975 unsigned int reg_val
= 0;
977 if (freq
== rt5660
->sysclk
&& clk_id
== rt5660
->sysclk_src
)
981 case RT5660_SCLK_S_MCLK
:
982 reg_val
|= RT5660_SCLK_SRC_MCLK
;
985 case RT5660_SCLK_S_PLL1
:
986 reg_val
|= RT5660_SCLK_SRC_PLL1
;
989 case RT5660_SCLK_S_RCCLK
:
990 reg_val
|= RT5660_SCLK_SRC_RCCLK
;
994 dev_err(component
->dev
, "Invalid clock id (%d)\n", clk_id
);
998 snd_soc_component_update_bits(component
, RT5660_GLB_CLK
, RT5660_SCLK_SRC_MASK
,
1001 rt5660
->sysclk
= freq
;
1002 rt5660
->sysclk_src
= clk_id
;
1004 dev_dbg(dai
->dev
, "Sysclk is %dHz and clock id is %d\n", freq
, clk_id
);
1009 static int rt5660_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
1010 unsigned int freq_in
, unsigned int freq_out
)
1012 struct snd_soc_component
*component
= dai
->component
;
1013 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
1014 struct rl6231_pll_code pll_code
;
1017 if (source
== rt5660
->pll_src
&& freq_in
== rt5660
->pll_in
&&
1018 freq_out
== rt5660
->pll_out
)
1021 if (!freq_in
|| !freq_out
) {
1022 dev_dbg(component
->dev
, "PLL disabled\n");
1025 rt5660
->pll_out
= 0;
1026 snd_soc_component_update_bits(component
, RT5660_GLB_CLK
,
1027 RT5660_SCLK_SRC_MASK
, RT5660_SCLK_SRC_MCLK
);
1032 case RT5660_PLL1_S_MCLK
:
1033 snd_soc_component_update_bits(component
, RT5660_GLB_CLK
,
1034 RT5660_PLL1_SRC_MASK
, RT5660_PLL1_SRC_MCLK
);
1037 case RT5660_PLL1_S_BCLK
:
1038 snd_soc_component_update_bits(component
, RT5660_GLB_CLK
,
1039 RT5660_PLL1_SRC_MASK
, RT5660_PLL1_SRC_BCLK1
);
1043 dev_err(component
->dev
, "Unknown PLL source %d\n", source
);
1047 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
1049 dev_err(component
->dev
, "Unsupport input clock %d\n", freq_in
);
1053 dev_dbg(component
->dev
, "bypass=%d m=%d n=%d k=%d\n",
1054 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
1055 pll_code
.n_code
, pll_code
.k_code
);
1057 snd_soc_component_write(component
, RT5660_PLL_CTRL1
,
1058 pll_code
.n_code
<< RT5660_PLL_N_SFT
| pll_code
.k_code
);
1059 snd_soc_component_write(component
, RT5660_PLL_CTRL2
,
1060 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5660_PLL_M_SFT
|
1061 pll_code
.m_bp
<< RT5660_PLL_M_BP_SFT
);
1063 rt5660
->pll_in
= freq_in
;
1064 rt5660
->pll_out
= freq_out
;
1065 rt5660
->pll_src
= source
;
1070 static int rt5660_set_bias_level(struct snd_soc_component
*component
,
1071 enum snd_soc_bias_level level
)
1073 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
1077 case SND_SOC_BIAS_ON
:
1080 case SND_SOC_BIAS_PREPARE
:
1081 snd_soc_component_update_bits(component
, RT5660_GEN_CTRL1
,
1082 RT5660_DIG_GATE_CTRL
, RT5660_DIG_GATE_CTRL
);
1084 if (IS_ERR(rt5660
->mclk
))
1087 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_ON
) {
1088 clk_disable_unprepare(rt5660
->mclk
);
1090 ret
= clk_prepare_enable(rt5660
->mclk
);
1096 case SND_SOC_BIAS_STANDBY
:
1097 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
1098 snd_soc_component_update_bits(component
, RT5660_PWR_ANLG1
,
1099 RT5660_PWR_VREF1
| RT5660_PWR_MB
|
1100 RT5660_PWR_BG
| RT5660_PWR_VREF2
,
1101 RT5660_PWR_VREF1
| RT5660_PWR_MB
|
1102 RT5660_PWR_BG
| RT5660_PWR_VREF2
);
1103 usleep_range(10000, 15000);
1104 snd_soc_component_update_bits(component
, RT5660_PWR_ANLG1
,
1105 RT5660_PWR_FV1
| RT5660_PWR_FV2
,
1106 RT5660_PWR_FV1
| RT5660_PWR_FV2
);
1110 case SND_SOC_BIAS_OFF
:
1111 snd_soc_component_update_bits(component
, RT5660_GEN_CTRL1
,
1112 RT5660_DIG_GATE_CTRL
, 0);
1122 static int rt5660_probe(struct snd_soc_component
*component
)
1124 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
1126 rt5660
->component
= component
;
1131 static void rt5660_remove(struct snd_soc_component
*component
)
1133 snd_soc_component_write(component
, RT5660_RESET
, 0);
1137 static int rt5660_suspend(struct snd_soc_component
*component
)
1139 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
1141 regcache_cache_only(rt5660
->regmap
, true);
1142 regcache_mark_dirty(rt5660
->regmap
);
1147 static int rt5660_resume(struct snd_soc_component
*component
)
1149 struct rt5660_priv
*rt5660
= snd_soc_component_get_drvdata(component
);
1151 if (rt5660
->pdata
.poweroff_codec_in_suspend
)
1154 regcache_cache_only(rt5660
->regmap
, false);
1155 regcache_sync(rt5660
->regmap
);
1160 #define rt5660_suspend NULL
1161 #define rt5660_resume NULL
1164 #define RT5660_STEREO_RATES SNDRV_PCM_RATE_8000_192000
1165 #define RT5660_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1166 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
1168 static const struct snd_soc_dai_ops rt5660_aif_dai_ops
= {
1169 .hw_params
= rt5660_hw_params
,
1170 .set_fmt
= rt5660_set_dai_fmt
,
1171 .set_sysclk
= rt5660_set_dai_sysclk
,
1172 .set_pll
= rt5660_set_dai_pll
,
1175 static struct snd_soc_dai_driver rt5660_dai
[] = {
1177 .name
= "rt5660-aif1",
1180 .stream_name
= "AIF1 Playback",
1183 .rates
= RT5660_STEREO_RATES
,
1184 .formats
= RT5660_FORMATS
,
1187 .stream_name
= "AIF1 Capture",
1190 .rates
= RT5660_STEREO_RATES
,
1191 .formats
= RT5660_FORMATS
,
1193 .ops
= &rt5660_aif_dai_ops
,
1197 static const struct snd_soc_component_driver soc_component_dev_rt5660
= {
1198 .probe
= rt5660_probe
,
1199 .remove
= rt5660_remove
,
1200 .suspend
= rt5660_suspend
,
1201 .resume
= rt5660_resume
,
1202 .set_bias_level
= rt5660_set_bias_level
,
1203 .controls
= rt5660_snd_controls
,
1204 .num_controls
= ARRAY_SIZE(rt5660_snd_controls
),
1205 .dapm_widgets
= rt5660_dapm_widgets
,
1206 .num_dapm_widgets
= ARRAY_SIZE(rt5660_dapm_widgets
),
1207 .dapm_routes
= rt5660_dapm_routes
,
1208 .num_dapm_routes
= ARRAY_SIZE(rt5660_dapm_routes
),
1209 .use_pmdown_time
= 1,
1211 .non_legacy_dai_naming
= 1,
1214 static const struct regmap_config rt5660_regmap
= {
1217 .use_single_read
= true,
1218 .use_single_write
= true,
1220 .max_register
= RT5660_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5660_ranges
) *
1222 .volatile_reg
= rt5660_volatile_register
,
1223 .readable_reg
= rt5660_readable_register
,
1225 .cache_type
= REGCACHE_RBTREE
,
1226 .reg_defaults
= rt5660_reg
,
1227 .num_reg_defaults
= ARRAY_SIZE(rt5660_reg
),
1228 .ranges
= rt5660_ranges
,
1229 .num_ranges
= ARRAY_SIZE(rt5660_ranges
),
1232 static const struct i2c_device_id rt5660_i2c_id
[] = {
1236 MODULE_DEVICE_TABLE(i2c
, rt5660_i2c_id
);
1238 static const struct of_device_id rt5660_of_match
[] = {
1239 { .compatible
= "realtek,rt5660", },
1242 MODULE_DEVICE_TABLE(of
, rt5660_of_match
);
1244 static const struct acpi_device_id rt5660_acpi_match
[] = {
1249 MODULE_DEVICE_TABLE(acpi
, rt5660_acpi_match
);
1251 static int rt5660_parse_dt(struct rt5660_priv
*rt5660
, struct device
*dev
)
1253 rt5660
->pdata
.in1_diff
= device_property_read_bool(dev
,
1254 "realtek,in1-differential");
1255 rt5660
->pdata
.in3_diff
= device_property_read_bool(dev
,
1256 "realtek,in3-differential");
1257 rt5660
->pdata
.poweroff_codec_in_suspend
= device_property_read_bool(dev
,
1258 "realtek,poweroff-in-suspend");
1259 device_property_read_u32(dev
, "realtek,dmic1-data-pin",
1260 &rt5660
->pdata
.dmic1_data_pin
);
1265 static int rt5660_i2c_probe(struct i2c_client
*i2c
,
1266 const struct i2c_device_id
*id
)
1268 struct rt5660_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
1269 struct rt5660_priv
*rt5660
;
1273 rt5660
= devm_kzalloc(&i2c
->dev
, sizeof(struct rt5660_priv
),
1279 /* Check if MCLK provided */
1280 rt5660
->mclk
= devm_clk_get(&i2c
->dev
, "mclk");
1281 if (PTR_ERR(rt5660
->mclk
) == -EPROBE_DEFER
)
1282 return -EPROBE_DEFER
;
1284 i2c_set_clientdata(i2c
, rt5660
);
1287 rt5660
->pdata
= *pdata
;
1288 else if (i2c
->dev
.of_node
)
1289 rt5660_parse_dt(rt5660
, &i2c
->dev
);
1291 rt5660
->regmap
= devm_regmap_init_i2c(i2c
, &rt5660_regmap
);
1292 if (IS_ERR(rt5660
->regmap
)) {
1293 ret
= PTR_ERR(rt5660
->regmap
);
1294 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
1299 regmap_read(rt5660
->regmap
, RT5660_VENDOR_ID2
, &val
);
1300 if (val
!= RT5660_DEVICE_ID
) {
1302 "Device with ID register %#x is not rt5660\n", val
);
1306 regmap_write(rt5660
->regmap
, RT5660_RESET
, 0);
1308 ret
= regmap_register_patch(rt5660
->regmap
, rt5660_patch
,
1309 ARRAY_SIZE(rt5660_patch
));
1311 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
1313 regmap_update_bits(rt5660
->regmap
, RT5660_GEN_CTRL1
,
1314 RT5660_AUTO_DIS_AMP
| RT5660_MCLK_DET
| RT5660_POW_CLKDET
,
1315 RT5660_AUTO_DIS_AMP
| RT5660_MCLK_DET
| RT5660_POW_CLKDET
);
1317 if (rt5660
->pdata
.dmic1_data_pin
) {
1318 regmap_update_bits(rt5660
->regmap
, RT5660_GPIO_CTRL1
,
1319 RT5660_GP1_PIN_MASK
, RT5660_GP1_PIN_DMIC1_SCL
);
1321 if (rt5660
->pdata
.dmic1_data_pin
== RT5660_DMIC1_DATA_GPIO2
)
1322 regmap_update_bits(rt5660
->regmap
, RT5660_DMIC_CTRL1
,
1323 RT5660_SEL_DMIC_DATA_MASK
,
1324 RT5660_SEL_DMIC_DATA_GPIO2
);
1325 else if (rt5660
->pdata
.dmic1_data_pin
== RT5660_DMIC1_DATA_IN1P
)
1326 regmap_update_bits(rt5660
->regmap
, RT5660_DMIC_CTRL1
,
1327 RT5660_SEL_DMIC_DATA_MASK
,
1328 RT5660_SEL_DMIC_DATA_IN1P
);
1331 return devm_snd_soc_register_component(&i2c
->dev
,
1332 &soc_component_dev_rt5660
,
1333 rt5660_dai
, ARRAY_SIZE(rt5660_dai
));
1336 static struct i2c_driver rt5660_i2c_driver
= {
1339 .acpi_match_table
= ACPI_PTR(rt5660_acpi_match
),
1340 .of_match_table
= of_match_ptr(rt5660_of_match
),
1342 .probe
= rt5660_i2c_probe
,
1343 .id_table
= rt5660_i2c_id
,
1345 module_i2c_driver(rt5660_i2c_driver
);
1347 MODULE_DESCRIPTION("ASoC RT5660 driver");
1348 MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
1349 MODULE_LICENSE("GPL v2");