1 // SPDX-License-Identifier: GPL-2.0
3 // mt6358.c -- mt6358 ALSA SoC audio codec driver
5 // Copyright (c) 2018 MediaTek Inc.
6 // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
8 #include <linux/platform_device.h>
9 #include <linux/module.h>
10 #include <linux/of_device.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/sched.h>
14 #include <linux/mfd/mt6397/core.h>
15 #include <linux/regulator/consumer.h>
17 #include <sound/soc.h>
18 #include <sound/tlv.h>
23 AUDIO_ANALOG_VOLUME_HSOUTL
,
24 AUDIO_ANALOG_VOLUME_HSOUTR
,
25 AUDIO_ANALOG_VOLUME_HPOUTL
,
26 AUDIO_ANALOG_VOLUME_HPOUTR
,
27 AUDIO_ANALOG_VOLUME_LINEOUTL
,
28 AUDIO_ANALOG_VOLUME_LINEOUTR
,
29 AUDIO_ANALOG_VOLUME_MICAMP1
,
30 AUDIO_ANALOG_VOLUME_MICAMP2
,
31 AUDIO_ANALOG_VOLUME_TYPE_MAX
54 /* Supply widget subseq */
60 SUPPLY_SEQ_VOW_AUD_LPW
,
65 SUPPLY_SEQ_TOP_CK_LAST
,
67 SUPPLY_SEQ_AUD_TOP_LAST
,
70 SUPPLY_SEQ_ADC_SUPPLY
,
83 struct regmap
*regmap
;
88 int ana_gain
[AUDIO_ANALOG_VOLUME_TYPE_MAX
];
89 unsigned int mux_select
[MUX_NUM
];
91 int dev_counter
[DEVICE_NUM
];
95 struct regulator
*avdd_reg
;
100 int mt6358_set_mtkaif_protocol(struct snd_soc_component
*cmpnt
,
103 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
105 priv
->mtkaif_protocol
= mtkaif_protocol
;
109 static void playback_gpio_set(struct mt6358_priv
*priv
)
111 /* set gpio mosi mode */
112 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_CLR
,
114 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_SET
,
116 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2
,
120 static void playback_gpio_reset(struct mt6358_priv
*priv
)
122 /* set pad_aud_*_mosi to GPIO mode and dir input
124 * pad_aud_dat_mosi*, because the pin is used as boot strap
125 * don't clean clk/sync, for mtkaif protocol 2
127 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_CLR
,
129 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2
,
131 regmap_update_bits(priv
->regmap
, MT6358_GPIO_DIR0
,
135 static void capture_gpio_set(struct mt6358_priv
*priv
)
137 /* set gpio miso mode */
138 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_CLR
,
140 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_SET
,
142 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
,
146 static void capture_gpio_reset(struct mt6358_priv
*priv
)
148 /* set pad_aud_*_miso to GPIO mode and dir input
150 * pad_aud_clk_miso, because when playback only the miso_clk
151 * will also have 26m, so will have power leak
152 * pad_aud_dat_miso*, because the pin is used as boot strap
154 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_CLR
,
156 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
,
158 regmap_update_bits(priv
->regmap
, MT6358_GPIO_DIR0
,
162 /* use only when not govern by DAPM */
163 static int mt6358_set_dcxo(struct mt6358_priv
*priv
, bool enable
)
165 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
,
166 0x1 << RG_XO_AUDIO_EN_M_SFT
,
167 (enable
? 1 : 0) << RG_XO_AUDIO_EN_M_SFT
);
171 /* use only when not govern by DAPM */
172 static int mt6358_set_clksq(struct mt6358_priv
*priv
, bool enable
)
174 /* audio clk source from internal dcxo */
175 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
176 RG_CLKSQ_IN_SEL_TEST_MASK_SFT
,
179 /* Enable/disable CLKSQ 26MHz */
180 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
181 RG_CLKSQ_EN_MASK_SFT
,
182 (enable
? 1 : 0) << RG_CLKSQ_EN_SFT
);
186 /* use only when not govern by DAPM */
187 static int mt6358_set_aud_global_bias(struct mt6358_priv
*priv
, bool enable
)
189 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
190 RG_AUDGLB_PWRDN_VA28_MASK_SFT
,
191 (enable
? 0 : 1) << RG_AUDGLB_PWRDN_VA28_SFT
);
195 /* use only when not govern by DAPM */
196 static int mt6358_set_topck(struct mt6358_priv
*priv
, bool enable
)
198 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
199 0x0066, enable
? 0x0 : 0x66);
203 static int mt6358_mtkaif_tx_enable(struct mt6358_priv
*priv
)
205 switch (priv
->mtkaif_protocol
) {
206 case MT6358_MTKAIF_PROTOCOL_2_CLK_P2
:
207 /* MTKAIF TX format setting */
208 regmap_update_bits(priv
->regmap
,
209 MT6358_AFE_ADDA_MTKAIF_CFG0
,
211 /* enable aud_pad TX fifos */
212 regmap_update_bits(priv
->regmap
,
213 MT6358_AFE_AUD_PAD_TOP
,
215 regmap_update_bits(priv
->regmap
,
216 MT6358_AFE_AUD_PAD_TOP
,
219 case MT6358_MTKAIF_PROTOCOL_2
:
220 /* MTKAIF TX format setting */
221 regmap_update_bits(priv
->regmap
,
222 MT6358_AFE_ADDA_MTKAIF_CFG0
,
224 /* enable aud_pad TX fifos */
225 regmap_update_bits(priv
->regmap
,
226 MT6358_AFE_AUD_PAD_TOP
,
229 case MT6358_MTKAIF_PROTOCOL_1
:
231 /* MTKAIF TX format setting */
232 regmap_update_bits(priv
->regmap
,
233 MT6358_AFE_ADDA_MTKAIF_CFG0
,
235 /* enable aud_pad TX fifos */
236 regmap_update_bits(priv
->regmap
,
237 MT6358_AFE_AUD_PAD_TOP
,
244 static int mt6358_mtkaif_tx_disable(struct mt6358_priv
*priv
)
246 /* disable aud_pad TX fifos */
247 regmap_update_bits(priv
->regmap
, MT6358_AFE_AUD_PAD_TOP
,
252 int mt6358_mtkaif_calibration_enable(struct snd_soc_component
*cmpnt
)
254 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
256 playback_gpio_set(priv
);
257 capture_gpio_set(priv
);
258 mt6358_mtkaif_tx_enable(priv
);
260 mt6358_set_dcxo(priv
, true);
261 mt6358_set_aud_global_bias(priv
, true);
262 mt6358_set_clksq(priv
, true);
263 mt6358_set_topck(priv
, true);
265 /* set dat_miso_loopback on */
266 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
267 RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT
,
268 1 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT
);
269 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
270 RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT
,
271 1 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT
);
275 int mt6358_mtkaif_calibration_disable(struct snd_soc_component
*cmpnt
)
277 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
279 /* set dat_miso_loopback off */
280 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
281 RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT
,
282 0 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT
);
283 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
284 RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT
,
285 0 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT
);
287 mt6358_set_topck(priv
, false);
288 mt6358_set_clksq(priv
, false);
289 mt6358_set_aud_global_bias(priv
, false);
290 mt6358_set_dcxo(priv
, false);
292 mt6358_mtkaif_tx_disable(priv
);
293 playback_gpio_reset(priv
);
294 capture_gpio_reset(priv
);
298 int mt6358_set_mtkaif_calibration_phase(struct snd_soc_component
*cmpnt
,
299 int phase_1
, int phase_2
)
301 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
303 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
304 RG_AUD_PAD_TOP_PHASE_MODE_MASK_SFT
,
305 phase_1
<< RG_AUD_PAD_TOP_PHASE_MODE_SFT
);
306 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
307 RG_AUD_PAD_TOP_PHASE_MODE2_MASK_SFT
,
308 phase_2
<< RG_AUD_PAD_TOP_PHASE_MODE2_SFT
);
318 DL_GAIN_N_40DB
= 0x1f,
321 #define DL_GAIN_N_10DB_REG (DL_GAIN_N_10DB << 7 | DL_GAIN_N_10DB)
322 #define DL_GAIN_N_40DB_REG (DL_GAIN_N_40DB << 7 | DL_GAIN_N_40DB)
323 #define DL_GAIN_REG_MASK 0x0f9f
325 static void hp_zcd_disable(struct mt6358_priv
*priv
)
327 regmap_write(priv
->regmap
, MT6358_ZCD_CON0
, 0x0000);
330 static void hp_main_output_ramp(struct mt6358_priv
*priv
, bool up
)
332 int i
= 0, stage
= 0;
335 /* Enable/Reduce HPL/R main output stage step by step */
336 for (i
= 0; i
<= target
; i
++) {
337 stage
= up
? i
: target
- i
;
338 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
339 0x7 << 8, stage
<< 8);
340 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
341 0x7 << 11, stage
<< 11);
342 usleep_range(100, 150);
346 static void hp_aux_feedback_loop_gain_ramp(struct mt6358_priv
*priv
, bool up
)
348 int i
= 0, stage
= 0;
350 /* Reduce HP aux feedback loop gain step by step */
351 for (i
= 0; i
<= 0xf; i
++) {
352 stage
= up
? i
: 0xf - i
;
353 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
354 0xf << 12, stage
<< 12);
355 usleep_range(100, 150);
359 static void hp_pull_down(struct mt6358_priv
*priv
, bool enable
)
364 for (i
= 0x0; i
<= 0x6; i
++) {
365 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
367 usleep_range(600, 700);
370 for (i
= 0x6; i
>= 0x1; i
--) {
371 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
373 usleep_range(600, 700);
378 static bool is_valid_hp_pga_idx(int reg_idx
)
380 return (reg_idx
>= DL_GAIN_8DB
&& reg_idx
<= DL_GAIN_N_10DB
) ||
381 reg_idx
== DL_GAIN_N_40DB
;
384 static void headset_volume_ramp(struct mt6358_priv
*priv
, int from
, int to
)
386 int offset
= 0, count
= 0, reg_idx
;
388 if (!is_valid_hp_pga_idx(from
) || !is_valid_hp_pga_idx(to
))
389 dev_warn(priv
->dev
, "%s(), volume index is not valid, from %d, to %d\n",
392 dev_info(priv
->dev
, "%s(), from %d, to %d\n",
400 while (offset
>= 0) {
402 reg_idx
= from
+ count
;
404 reg_idx
= from
- count
;
406 if (is_valid_hp_pga_idx(reg_idx
)) {
407 regmap_update_bits(priv
->regmap
,
410 (reg_idx
<< 7) | reg_idx
);
411 usleep_range(200, 300);
418 static int mt6358_put_volsw(struct snd_kcontrol
*kcontrol
,
419 struct snd_ctl_elem_value
*ucontrol
)
421 struct snd_soc_component
*component
=
422 snd_soc_kcontrol_component(kcontrol
);
423 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(component
);
424 struct soc_mixer_control
*mc
=
425 (struct soc_mixer_control
*)kcontrol
->private_value
;
429 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
434 case MT6358_ZCD_CON2
:
435 regmap_read(priv
->regmap
, MT6358_ZCD_CON2
, ®
);
436 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
] =
437 (reg
>> RG_AUDHPLGAIN_SFT
) & RG_AUDHPLGAIN_MASK
;
438 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTR
] =
439 (reg
>> RG_AUDHPRGAIN_SFT
) & RG_AUDHPRGAIN_MASK
;
441 case MT6358_ZCD_CON1
:
442 regmap_read(priv
->regmap
, MT6358_ZCD_CON1
, ®
);
443 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTL
] =
444 (reg
>> RG_AUDLOLGAIN_SFT
) & RG_AUDLOLGAIN_MASK
;
445 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTR
] =
446 (reg
>> RG_AUDLORGAIN_SFT
) & RG_AUDLORGAIN_MASK
;
448 case MT6358_ZCD_CON3
:
449 regmap_read(priv
->regmap
, MT6358_ZCD_CON3
, ®
);
450 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HSOUTL
] =
451 (reg
>> RG_AUDHSGAIN_SFT
) & RG_AUDHSGAIN_MASK
;
452 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HSOUTR
] =
453 (reg
>> RG_AUDHSGAIN_SFT
) & RG_AUDHSGAIN_MASK
;
455 case MT6358_AUDENC_ANA_CON0
:
456 case MT6358_AUDENC_ANA_CON1
:
457 regmap_read(priv
->regmap
, MT6358_AUDENC_ANA_CON0
, ®
);
458 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP1
] =
459 (reg
>> RG_AUDPREAMPLGAIN_SFT
) & RG_AUDPREAMPLGAIN_MASK
;
460 regmap_read(priv
->regmap
, MT6358_AUDENC_ANA_CON1
, ®
);
461 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP2
] =
462 (reg
>> RG_AUDPREAMPRGAIN_SFT
) & RG_AUDPREAMPRGAIN_MASK
;
469 static void mt6358_restore_pga(struct mt6358_priv
*priv
);
471 static int mt6358_enable_wov_phase2(struct mt6358_priv
*priv
)
474 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
476 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
, 0xffff, 0xa2b5);
477 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
479 mt6358_restore_pga(priv
);
481 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW13
, 0xffff, 0x9929);
482 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
484 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON8
,
488 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
490 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
, 0xffff, 0x0120);
491 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG0
, 0xffff, 0xffff);
492 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG1
, 0xffff, 0x0200);
493 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG2
, 0xffff, 0x2424);
494 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG3
, 0xffff, 0xdbac);
495 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG4
, 0xffff, 0x029e);
496 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG5
, 0xffff, 0x0000);
497 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_POSDIV_CFG0
,
499 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_HPF_CFG0
,
501 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_TOP
, 0xffff, 0x68d1);
506 static int mt6358_disable_wov_phase2(struct mt6358_priv
*priv
)
509 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_TOP
, 0xffff, 0xc000);
510 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_HPF_CFG0
,
512 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_POSDIV_CFG0
,
514 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG5
, 0xffff, 0x0100);
515 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG4
, 0xffff, 0x006c);
516 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG3
, 0xffff, 0xa879);
517 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG2
, 0xffff, 0x2323);
518 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG1
, 0xffff, 0x0400);
519 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG0
, 0xffff, 0x0000);
520 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
, 0xffff, 0x02d8);
521 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
525 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON8
,
527 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
529 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW13
, 0xffff, 0x9829);
530 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
532 mt6358_restore_pga(priv
);
533 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
, 0xffff, 0xa2b5);
534 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
540 static int mt6358_get_wov(struct snd_kcontrol
*kcontrol
,
541 struct snd_ctl_elem_value
*ucontrol
)
543 struct snd_soc_component
*c
= snd_soc_kcontrol_component(kcontrol
);
544 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(c
);
546 ucontrol
->value
.integer
.value
[0] = priv
->wov_enabled
;
550 static int mt6358_put_wov(struct snd_kcontrol
*kcontrol
,
551 struct snd_ctl_elem_value
*ucontrol
)
553 struct snd_soc_component
*c
= snd_soc_kcontrol_component(kcontrol
);
554 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(c
);
555 int enabled
= ucontrol
->value
.integer
.value
[0];
557 if (priv
->wov_enabled
!= enabled
) {
559 mt6358_enable_wov_phase2(priv
);
561 mt6358_disable_wov_phase2(priv
);
563 priv
->wov_enabled
= enabled
;
569 static const DECLARE_TLV_DB_SCALE(playback_tlv
, -1000, 100, 0);
570 static const DECLARE_TLV_DB_SCALE(pga_tlv
, 0, 600, 0);
572 static const struct snd_kcontrol_new mt6358_snd_controls
[] = {
574 SOC_DOUBLE_EXT_TLV("Headphone Volume",
575 MT6358_ZCD_CON2
, 0, 7, 0x12, 1,
576 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
577 SOC_DOUBLE_EXT_TLV("Lineout Volume",
578 MT6358_ZCD_CON1
, 0, 7, 0x12, 1,
579 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
580 SOC_SINGLE_EXT_TLV("Handset Volume",
581 MT6358_ZCD_CON3
, 0, 0x12, 1,
582 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
584 SOC_DOUBLE_R_EXT_TLV("PGA Volume",
585 MT6358_AUDENC_ANA_CON0
, MT6358_AUDENC_ANA_CON1
,
587 snd_soc_get_volsw
, mt6358_put_volsw
, pga_tlv
),
589 SOC_SINGLE_BOOL_EXT("Wake-on-Voice Phase2 Switch", 0,
590 mt6358_get_wov
, mt6358_put_wov
),
595 static const char * const lo_in_mux_map
[] = {
596 "Open", "Mute", "Playback", "Test Mode"
599 static int lo_in_mux_map_value
[] = {
603 static SOC_VALUE_ENUM_SINGLE_DECL(lo_in_mux_map_enum
,
604 MT6358_AUDDEC_ANA_CON7
,
605 RG_AUDLOLMUXINPUTSEL_VAUDP15_SFT
,
606 RG_AUDLOLMUXINPUTSEL_VAUDP15_MASK
,
608 lo_in_mux_map_value
);
610 static const struct snd_kcontrol_new lo_in_mux_control
=
611 SOC_DAPM_ENUM("In Select", lo_in_mux_map_enum
);
623 static const char * const hp_in_mux_map
[] = {
634 static int hp_in_mux_map_value
[] = {
645 static SOC_VALUE_ENUM_SINGLE_DECL(hpl_in_mux_map_enum
,
650 hp_in_mux_map_value
);
652 static const struct snd_kcontrol_new hpl_in_mux_control
=
653 SOC_DAPM_ENUM("HPL Select", hpl_in_mux_map_enum
);
655 static SOC_VALUE_ENUM_SINGLE_DECL(hpr_in_mux_map_enum
,
660 hp_in_mux_map_value
);
662 static const struct snd_kcontrol_new hpr_in_mux_control
=
663 SOC_DAPM_ENUM("HPR Select", hpr_in_mux_map_enum
);
669 RCV_MUX_VOICE_PLAYBACK
,
674 static const char * const rcv_in_mux_map
[] = {
675 "Open", "Mute", "Voice Playback", "Test Mode"
678 static int rcv_in_mux_map_value
[] = {
681 RCV_MUX_VOICE_PLAYBACK
,
685 static SOC_VALUE_ENUM_SINGLE_DECL(rcv_in_mux_map_enum
,
690 rcv_in_mux_map_value
);
692 static const struct snd_kcontrol_new rcv_in_mux_control
=
693 SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum
);
696 static const char * const dac_in_mux_map
[] = {
697 "Normal Path", "Sgen"
700 static int dac_in_mux_map_value
[] = {
704 static SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum
,
709 dac_in_mux_map_value
);
711 static const struct snd_kcontrol_new dac_in_mux_control
=
712 SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum
);
715 static SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum
,
720 dac_in_mux_map_value
);
722 static const struct snd_kcontrol_new aif_out_mux_control
=
723 SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum
);
727 MIC_TYPE_MUX_IDLE
= 0,
731 MIC_TYPE_MUX_DCC_ECM_DIFF
,
732 MIC_TYPE_MUX_DCC_ECM_SINGLE
,
733 MIC_TYPE_MUX_MASK
= 0x7,
736 #define IS_DCC_BASE(type) ((type) == MIC_TYPE_MUX_DCC || \
737 (type) == MIC_TYPE_MUX_DCC_ECM_DIFF || \
738 (type) == MIC_TYPE_MUX_DCC_ECM_SINGLE)
740 static const char * const mic_type_mux_map
[] = {
749 static int mic_type_mux_map_value
[] = {
754 MIC_TYPE_MUX_DCC_ECM_DIFF
,
755 MIC_TYPE_MUX_DCC_ECM_SINGLE
,
758 static SOC_VALUE_ENUM_SINGLE_DECL(mic_type_mux_map_enum
,
763 mic_type_mux_map_value
);
765 static const struct snd_kcontrol_new mic_type_mux_control
=
766 SOC_DAPM_ENUM("Mic Type Select", mic_type_mux_map_enum
);
772 ADC_MUX_PREAMPLIFIER
,
777 static const char * const adc_left_mux_map
[] = {
778 "Idle", "AIN0", "Left Preamplifier", "Idle_1"
781 static int adc_mux_map_value
[] = {
784 ADC_MUX_PREAMPLIFIER
,
788 static SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum
,
795 static const struct snd_kcontrol_new adc_left_mux_control
=
796 SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum
);
799 static const char * const adc_right_mux_map
[] = {
800 "Idle", "AIN0", "Right Preamplifier", "Idle_1"
803 static SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum
,
810 static const struct snd_kcontrol_new adc_right_mux_control
=
811 SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum
);
822 static const char * const pga_mux_map
[] = {
823 "None", "AIN0", "AIN1", "AIN2"
826 static int pga_mux_map_value
[] = {
833 static SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum
,
840 static const struct snd_kcontrol_new pga_left_mux_control
=
841 SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum
);
844 static SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum
,
851 static const struct snd_kcontrol_new pga_right_mux_control
=
852 SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum
);
854 static int mt_clksq_event(struct snd_soc_dapm_widget
*w
,
855 struct snd_kcontrol
*kcontrol
,
858 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
859 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
861 dev_dbg(priv
->dev
, "%s(), event = 0x%x\n", __func__
, event
);
864 case SND_SOC_DAPM_PRE_PMU
:
865 /* audio clk source from internal dcxo */
866 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
867 RG_CLKSQ_IN_SEL_TEST_MASK_SFT
,
877 static int mt_sgen_event(struct snd_soc_dapm_widget
*w
,
878 struct snd_kcontrol
*kcontrol
,
881 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
882 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
884 dev_dbg(priv
->dev
, "%s(), event = 0x%x\n", __func__
, event
);
887 case SND_SOC_DAPM_PRE_PMU
:
888 /* sdm audio fifo clock power on */
889 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0006);
890 /* scrambler clock on enable */
891 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xCBA1);
893 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0003);
894 /* sdm fifo enable */
895 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x000B);
897 regmap_update_bits(priv
->regmap
, MT6358_AFE_SGEN_CFG0
,
900 regmap_update_bits(priv
->regmap
, MT6358_AFE_SGEN_CFG1
,
904 case SND_SOC_DAPM_POST_PMD
:
905 /* DL scrambler disabling sequence */
906 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0000);
907 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xcba0);
916 static int mt_aif_in_event(struct snd_soc_dapm_widget
*w
,
917 struct snd_kcontrol
*kcontrol
,
920 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
921 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
923 dev_info(priv
->dev
, "%s(), event 0x%x, rate %d\n",
924 __func__
, event
, priv
->dl_rate
);
927 case SND_SOC_DAPM_PRE_PMU
:
928 playback_gpio_set(priv
);
930 /* sdm audio fifo clock power on */
931 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0006);
932 /* scrambler clock on enable */
933 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xCBA1);
935 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0003);
936 /* sdm fifo enable */
937 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x000B);
939 case SND_SOC_DAPM_POST_PMD
:
940 /* DL scrambler disabling sequence */
941 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0000);
942 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xcba0);
944 playback_gpio_reset(priv
);
953 static int mtk_hp_enable(struct mt6358_priv
*priv
)
955 /* Pull-down HPL/R to AVSS28_AUD */
956 hp_pull_down(priv
, true);
957 /* release HP CMFB gate rstb */
958 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
961 /* Reduce ESD resistance of AU_REFN */
962 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
964 /* Set HPR/HPL gain as minimum (~ -40dB) */
965 regmap_write(priv
->regmap
, MT6358_ZCD_CON2
, DL_GAIN_N_40DB_REG
);
967 /* Turn on DA_600K_NCP_VA18 */
968 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
969 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
970 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
971 /* Toggle RG_DIVCKS_CHG */
972 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
973 /* Set NCP soft start mode as default mode: 100us */
974 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
976 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
977 usleep_range(250, 270);
979 /* Enable cap-less LDOs (1.5V) */
980 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
982 /* Enable NV regulator (-1.2V) */
983 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
984 usleep_range(100, 120);
986 /* Disable AUD_ZCD */
987 hp_zcd_disable(priv
);
989 /* Disable headphone short-circuit protection */
990 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3000);
993 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
995 /* Set HP DR bias current optimization, 010: 6uA */
996 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
997 /* Set HP & ZCD bias current optimization */
998 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
999 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1000 /* Set HPP/N STB enhance circuits */
1001 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4033);
1003 /* Enable HP aux output stage */
1004 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x000c);
1005 /* Enable HP aux feedback loop */
1006 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x003c);
1007 /* Enable HP aux CMFB loop */
1008 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0c00);
1009 /* Enable HP driver bias circuits */
1010 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30c0);
1011 /* Enable HP driver core circuits */
1012 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f0);
1013 /* Short HP main output to HP aux output stage */
1014 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x00fc);
1016 /* Enable HP main CMFB loop */
1017 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0e00);
1018 /* Disable HP aux CMFB loop */
1019 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0200);
1021 /* Select CMFB resistor bulk to AC mode */
1022 /* Selec HS/LO cap size (6.5pF default) */
1023 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1025 /* Enable HP main output stage */
1026 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x00ff);
1027 /* Enable HPR/L main output stage step by step */
1028 hp_main_output_ramp(priv
, true);
1030 /* Reduce HP aux feedback loop gain */
1031 hp_aux_feedback_loop_gain_ramp(priv
, true);
1032 /* Disable HP aux feedback loop */
1033 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1035 /* apply volume setting */
1036 headset_volume_ramp(priv
,
1038 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
]);
1040 /* Disable HP aux output stage */
1041 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1042 /* Unshort HP main output to HP aux output stage */
1043 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3f03);
1044 usleep_range(100, 120);
1046 /* Enable AUD_CLK */
1047 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x1);
1048 /* Enable Audio DAC */
1049 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30ff);
1050 /* Enable low-noise mode of DAC */
1051 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0xf201);
1052 usleep_range(100, 120);
1054 /* Switch HPL MUX to audio DAC */
1055 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x32ff);
1056 /* Switch HPR MUX to audio DAC */
1057 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3aff);
1059 /* Disable Pull-down HPL/R to AVSS28_AUD */
1060 hp_pull_down(priv
, false);
1065 static int mtk_hp_disable(struct mt6358_priv
*priv
)
1067 /* Pull-down HPL/R to AVSS28_AUD */
1068 hp_pull_down(priv
, true);
1070 /* HPR/HPL mux to open */
1071 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1074 /* Disable low-noise mode of DAC */
1075 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1078 /* Disable Audio DAC */
1079 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1082 /* Disable AUD_CLK */
1083 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x0);
1085 /* Short HP main output to HP aux output stage */
1086 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1087 /* Enable HP aux output stage */
1088 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1090 /* decrease HPL/R gain to normal gain step by step */
1091 headset_volume_ramp(priv
,
1092 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
],
1095 /* Enable HP aux feedback loop */
1096 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fff);
1098 /* Reduce HP aux feedback loop gain */
1099 hp_aux_feedback_loop_gain_ramp(priv
, false);
1101 /* decrease HPR/L main output stage step by step */
1102 hp_main_output_ramp(priv
, false);
1104 /* Disable HP main output stage */
1105 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3, 0x0);
1107 /* Enable HP aux CMFB loop */
1108 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0e00);
1110 /* Disable HP main CMFB loop */
1111 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0c00);
1113 /* Unshort HP main output to HP aux output stage */
1114 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1117 /* Disable HP driver core circuits */
1118 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1121 /* Disable HP driver bias circuits */
1122 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1125 /* Disable HP aux CMFB loop */
1126 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0000);
1128 /* Disable HP aux feedback loop */
1129 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1132 /* Disable HP aux output stage */
1133 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1137 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1138 0x1 << 8, 0x1 << 8);
1140 /* Disable NV regulator (-1.2V) */
1141 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x1, 0x0);
1142 /* Disable cap-less LDOs (1.5V) */
1143 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1146 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
,
1149 /* Increase ESD resistance of AU_REFN */
1150 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
,
1153 /* Set HP CMFB gate rstb */
1154 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1156 /* disable Pull-down HPL/R to AVSS28_AUD */
1157 hp_pull_down(priv
, false);
1162 static int mtk_hp_spk_enable(struct mt6358_priv
*priv
)
1164 /* Pull-down HPL/R to AVSS28_AUD */
1165 hp_pull_down(priv
, true);
1166 /* release HP CMFB gate rstb */
1167 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1168 0x1 << 6, 0x1 << 6);
1170 /* Reduce ESD resistance of AU_REFN */
1171 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
1173 /* Set HPR/HPL gain to -10dB */
1174 regmap_write(priv
->regmap
, MT6358_ZCD_CON2
, DL_GAIN_N_10DB_REG
);
1176 /* Turn on DA_600K_NCP_VA18 */
1177 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
1178 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
1179 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
1180 /* Toggle RG_DIVCKS_CHG */
1181 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
1182 /* Set NCP soft start mode as default mode: 100us */
1183 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
1185 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
1186 usleep_range(250, 270);
1188 /* Enable cap-less LDOs (1.5V) */
1189 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1191 /* Enable NV regulator (-1.2V) */
1192 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
1193 usleep_range(100, 120);
1195 /* Disable AUD_ZCD */
1196 hp_zcd_disable(priv
);
1198 /* Disable headphone short-circuit protection */
1199 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3000);
1202 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1204 /* Set HP DR bias current optimization, 010: 6uA */
1205 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
1206 /* Set HP & ZCD bias current optimization */
1207 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
1208 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1209 /* Set HPP/N STB enhance circuits */
1210 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4033);
1212 /* Disable Pull-down HPL/R to AVSS28_AUD */
1213 hp_pull_down(priv
, false);
1215 /* Enable HP driver bias circuits */
1216 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30c0);
1217 /* Enable HP driver core circuits */
1218 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f0);
1219 /* Enable HP main CMFB loop */
1220 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0200);
1222 /* Select CMFB resistor bulk to AC mode */
1223 /* Selec HS/LO cap size (6.5pF default) */
1224 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1226 /* Enable HP main output stage */
1227 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x0003);
1228 /* Enable HPR/L main output stage step by step */
1229 hp_main_output_ramp(priv
, true);
1231 /* Set LO gain as minimum (~ -40dB) */
1232 regmap_write(priv
->regmap
, MT6358_ZCD_CON1
, DL_GAIN_N_40DB_REG
);
1233 /* apply volume setting */
1234 headset_volume_ramp(priv
,
1236 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
]);
1238 /* Set LO STB enhance circuits */
1239 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0110);
1240 /* Enable LO driver bias circuits */
1241 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0112);
1242 /* Enable LO driver core circuits */
1243 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0113);
1245 /* Set LOL gain to normal gain step by step */
1246 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1247 RG_AUDLOLGAIN_MASK_SFT
,
1248 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTL
] <<
1250 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1251 RG_AUDLORGAIN_MASK_SFT
,
1252 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTR
] <<
1255 /* Enable AUD_CLK */
1256 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x1);
1257 /* Enable Audio DAC */
1258 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f9);
1259 /* Enable low-noise mode of DAC */
1260 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0201);
1261 /* Switch LOL MUX to audio DAC */
1262 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x011b);
1263 /* Switch HPL/R MUX to Line-out */
1264 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x35f9);
1269 static int mtk_hp_spk_disable(struct mt6358_priv
*priv
)
1271 /* HPR/HPL mux to open */
1272 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1274 /* LOL mux to open */
1275 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1278 /* Disable Audio DAC */
1279 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1282 /* Disable AUD_CLK */
1283 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x0);
1285 /* decrease HPL/R gain to normal gain step by step */
1286 headset_volume_ramp(priv
,
1287 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
],
1290 /* decrease LOL gain to minimum gain step by step */
1291 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1292 DL_GAIN_REG_MASK
, DL_GAIN_N_40DB_REG
);
1294 /* decrease HPR/L main output stage step by step */
1295 hp_main_output_ramp(priv
, false);
1297 /* Disable HP main output stage */
1298 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3, 0x0);
1300 /* Short HP main output to HP aux output stage */
1301 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1302 /* Enable HP aux output stage */
1303 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1305 /* Enable HP aux feedback loop */
1306 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fff);
1308 /* Reduce HP aux feedback loop gain */
1309 hp_aux_feedback_loop_gain_ramp(priv
, false);
1311 /* Disable HP driver core circuits */
1312 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1314 /* Disable LO driver core circuits */
1315 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1318 /* Disable HP driver bias circuits */
1319 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1321 /* Disable LO driver bias circuits */
1322 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1325 /* Disable HP aux CMFB loop */
1326 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1330 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1331 0x1 << 8, 0x1 << 8);
1332 /* Disable NV regulator (-1.2V) */
1333 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x1, 0x0);
1334 /* Disable cap-less LDOs (1.5V) */
1335 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
, 0x1055, 0x0);
1337 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x1, 0x1);
1339 /* Set HP CMFB gate rstb */
1340 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1342 /* disable Pull-down HPL/R to AVSS28_AUD */
1343 hp_pull_down(priv
, false);
1348 static int mt_hp_event(struct snd_soc_dapm_widget
*w
,
1349 struct snd_kcontrol
*kcontrol
,
1352 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1353 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1354 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1355 int device
= DEVICE_HP
;
1357 dev_info(priv
->dev
, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
1360 priv
->dev_counter
[device
],
1364 case SND_SOC_DAPM_PRE_PMU
:
1365 priv
->dev_counter
[device
]++;
1366 if (priv
->dev_counter
[device
] > 1)
1367 break; /* already enabled, do nothing */
1368 else if (priv
->dev_counter
[device
] <= 0)
1369 dev_warn(priv
->dev
, "%s(), dev_counter[DEV_HP] %d <= 0\n",
1371 priv
->dev_counter
[device
]);
1373 priv
->mux_select
[MUX_HP_L
] = mux
;
1375 if (mux
== HP_MUX_HP
)
1376 mtk_hp_enable(priv
);
1377 else if (mux
== HP_MUX_HPSPK
)
1378 mtk_hp_spk_enable(priv
);
1380 case SND_SOC_DAPM_PRE_PMD
:
1381 priv
->dev_counter
[device
]--;
1382 if (priv
->dev_counter
[device
] > 0) {
1383 break; /* still being used, don't close */
1384 } else if (priv
->dev_counter
[device
] < 0) {
1385 dev_warn(priv
->dev
, "%s(), dev_counter[DEV_HP] %d < 0\n",
1387 priv
->dev_counter
[device
]);
1388 priv
->dev_counter
[device
] = 0;
1392 if (priv
->mux_select
[MUX_HP_L
] == HP_MUX_HP
)
1393 mtk_hp_disable(priv
);
1394 else if (priv
->mux_select
[MUX_HP_L
] == HP_MUX_HPSPK
)
1395 mtk_hp_spk_disable(priv
);
1397 priv
->mux_select
[MUX_HP_L
] = mux
;
1406 static int mt_rcv_event(struct snd_soc_dapm_widget
*w
,
1407 struct snd_kcontrol
*kcontrol
,
1410 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1411 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1413 dev_info(priv
->dev
, "%s(), event 0x%x, mux %u\n",
1416 dapm_kcontrol_get_value(w
->kcontrols
[0]));
1419 case SND_SOC_DAPM_PRE_PMU
:
1420 /* Reduce ESD resistance of AU_REFN */
1421 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
1423 /* Turn on DA_600K_NCP_VA18 */
1424 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
1425 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
1426 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
1427 /* Toggle RG_DIVCKS_CHG */
1428 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
1429 /* Set NCP soft start mode as default mode: 100us */
1430 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
1432 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
1433 usleep_range(250, 270);
1435 /* Enable cap-less LDOs (1.5V) */
1436 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1438 /* Enable NV regulator (-1.2V) */
1439 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
1440 usleep_range(100, 120);
1442 /* Disable AUD_ZCD */
1443 hp_zcd_disable(priv
);
1445 /* Disable handset short-circuit protection */
1446 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0010);
1449 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1450 /* Set HP DR bias current optimization, 010: 6uA */
1451 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
1452 /* Set HP & ZCD bias current optimization */
1453 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
1454 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1455 /* Set HS STB enhance circuits */
1456 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0090);
1458 /* Disable HP main CMFB loop */
1459 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0000);
1460 /* Select CMFB resistor bulk to AC mode */
1461 /* Selec HS/LO cap size (6.5pF default) */
1462 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1464 /* Enable HS driver bias circuits */
1465 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0092);
1466 /* Enable HS driver core circuits */
1467 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0093);
1469 /* Enable AUD_CLK */
1470 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1473 /* Enable Audio DAC */
1474 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x0009);
1475 /* Enable low-noise mode of DAC */
1476 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0001);
1477 /* Switch HS MUX to audio DAC */
1478 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x009b);
1480 case SND_SOC_DAPM_PRE_PMD
:
1481 /* HS mux to open */
1482 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1483 RG_AUDHSMUXINPUTSEL_VAUDP15_MASK_SFT
,
1486 /* Disable Audio DAC */
1487 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1490 /* Disable AUD_CLK */
1491 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1494 /* decrease HS gain to minimum gain step by step */
1495 regmap_write(priv
->regmap
, MT6358_ZCD_CON3
, DL_GAIN_N_40DB
);
1497 /* Disable HS driver core circuits */
1498 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1501 /* Disable HS driver bias circuits */
1502 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1505 /* Disable HP aux CMFB loop */
1506 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1509 /* Enable HP main CMFB Switch */
1510 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1511 0xff << 8, 0x2 << 8);
1514 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1515 0x1 << 8, 0x1 << 8);
1517 /* Disable NV regulator (-1.2V) */
1518 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
,
1520 /* Disable cap-less LDOs (1.5V) */
1521 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1524 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
,
1534 static int mt_aif_out_event(struct snd_soc_dapm_widget
*w
,
1535 struct snd_kcontrol
*kcontrol
,
1538 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1539 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1541 dev_dbg(priv
->dev
, "%s(), event 0x%x, rate %d\n",
1542 __func__
, event
, priv
->ul_rate
);
1545 case SND_SOC_DAPM_PRE_PMU
:
1546 capture_gpio_set(priv
);
1548 case SND_SOC_DAPM_POST_PMD
:
1549 capture_gpio_reset(priv
);
1558 static int mt_adc_supply_event(struct snd_soc_dapm_widget
*w
,
1559 struct snd_kcontrol
*kcontrol
,
1562 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1563 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1565 dev_dbg(priv
->dev
, "%s(), event 0x%x\n",
1569 case SND_SOC_DAPM_PRE_PMU
:
1570 /* Enable audio ADC CLKGEN */
1571 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1572 0x1 << 5, 0x1 << 5);
1573 /* ADC CLK from CLKGEN (13MHz) */
1574 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON3
,
1576 /* Enable LCLDO_ENC 1P8V */
1577 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1579 /* LCLDO_ENC remote sense */
1580 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1583 case SND_SOC_DAPM_POST_PMD
:
1584 /* LCLDO_ENC remote sense off */
1585 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1587 /* disable LCLDO_ENC 1P8V */
1588 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1591 /* ADC CLK from CLKGEN (13MHz) */
1592 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON3
, 0x0000);
1593 /* disable audio ADC CLKGEN */
1594 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1595 0x1 << 5, 0x0 << 5);
1604 static int mt6358_amic_enable(struct mt6358_priv
*priv
)
1606 unsigned int mic_type
= priv
->mux_select
[MUX_MIC_TYPE
];
1607 unsigned int mux_pga_l
= priv
->mux_select
[MUX_PGA_L
];
1608 unsigned int mux_pga_r
= priv
->mux_select
[MUX_PGA_R
];
1610 dev_info(priv
->dev
, "%s(), mux, mic %u, pga l %u, pga r %u\n",
1611 __func__
, mic_type
, mux_pga_l
, mux_pga_r
);
1613 if (IS_DCC_BASE(mic_type
)) {
1614 /* DCC 50k CLK (from 26M) */
1615 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1616 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1617 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2060);
1618 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2061);
1619 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG1
, 0x0100);
1623 if (mux_pga_l
== PGA_MUX_AIN0
|| mux_pga_l
== PGA_MUX_AIN2
||
1624 mux_pga_r
== PGA_MUX_AIN0
|| mux_pga_r
== PGA_MUX_AIN2
) {
1626 case MIC_TYPE_MUX_DCC_ECM_DIFF
:
1627 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1630 case MIC_TYPE_MUX_DCC_ECM_SINGLE
:
1631 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1635 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1639 /* Enable MICBIAS0, MISBIAS0 = 1P9V */
1640 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1645 if (mux_pga_l
== PGA_MUX_AIN1
|| mux_pga_r
== PGA_MUX_AIN1
) {
1646 /* Enable MICBIAS1, MISBIAS1 = 2P6V */
1647 if (mic_type
== MIC_TYPE_MUX_DCC_ECM_SINGLE
)
1648 regmap_write(priv
->regmap
,
1649 MT6358_AUDENC_ANA_CON10
, 0x0161);
1651 regmap_write(priv
->regmap
,
1652 MT6358_AUDENC_ANA_CON10
, 0x0061);
1655 if (IS_DCC_BASE(mic_type
)) {
1656 /* Audio L/R preamplifier DCC precharge */
1657 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1659 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1663 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1665 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1669 if (mux_pga_l
!= PGA_MUX_NONE
) {
1670 /* L preamplifier input sel */
1671 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1672 RG_AUDPREAMPLINPUTSEL_MASK_SFT
,
1673 mux_pga_l
<< RG_AUDPREAMPLINPUTSEL_SFT
);
1675 /* L preamplifier enable */
1676 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1677 RG_AUDPREAMPLON_MASK_SFT
,
1678 0x1 << RG_AUDPREAMPLON_SFT
);
1680 if (IS_DCC_BASE(mic_type
)) {
1681 /* L preamplifier DCCEN */
1682 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1683 RG_AUDPREAMPLDCCEN_MASK_SFT
,
1684 0x1 << RG_AUDPREAMPLDCCEN_SFT
);
1687 /* L ADC input sel : L PGA. Enable audio L ADC */
1688 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1689 RG_AUDADCLINPUTSEL_MASK_SFT
,
1690 ADC_MUX_PREAMPLIFIER
<<
1691 RG_AUDADCLINPUTSEL_SFT
);
1692 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1693 RG_AUDADCLPWRUP_MASK_SFT
,
1694 0x1 << RG_AUDADCLPWRUP_SFT
);
1697 if (mux_pga_r
!= PGA_MUX_NONE
) {
1698 /* R preamplifier input sel */
1699 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1700 RG_AUDPREAMPRINPUTSEL_MASK_SFT
,
1701 mux_pga_r
<< RG_AUDPREAMPRINPUTSEL_SFT
);
1703 /* R preamplifier enable */
1704 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1705 RG_AUDPREAMPRON_MASK_SFT
,
1706 0x1 << RG_AUDPREAMPRON_SFT
);
1708 if (IS_DCC_BASE(mic_type
)) {
1709 /* R preamplifier DCCEN */
1710 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1711 RG_AUDPREAMPRDCCEN_MASK_SFT
,
1712 0x1 << RG_AUDPREAMPRDCCEN_SFT
);
1715 /* R ADC input sel : R PGA. Enable audio R ADC */
1716 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1717 RG_AUDADCRINPUTSEL_MASK_SFT
,
1718 ADC_MUX_PREAMPLIFIER
<<
1719 RG_AUDADCRINPUTSEL_SFT
);
1720 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1721 RG_AUDADCRPWRUP_MASK_SFT
,
1722 0x1 << RG_AUDADCRPWRUP_SFT
);
1725 if (IS_DCC_BASE(mic_type
)) {
1726 usleep_range(100, 150);
1727 /* Audio L preamplifier DCC precharge off */
1728 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1729 RG_AUDPREAMPLDCPRECHARGE_MASK_SFT
, 0x0);
1730 /* Audio R preamplifier DCC precharge off */
1731 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1732 RG_AUDPREAMPRDCPRECHARGE_MASK_SFT
, 0x0);
1734 /* Short body to ground in PGA */
1735 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON3
,
1739 /* here to set digital part */
1740 mt6358_mtkaif_tx_enable(priv
);
1742 /* UL dmic setting off */
1743 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_H
, 0x0000);
1746 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
, 0x0001);
1751 static void mt6358_amic_disable(struct mt6358_priv
*priv
)
1753 unsigned int mic_type
= priv
->mux_select
[MUX_MIC_TYPE
];
1754 unsigned int mux_pga_l
= priv
->mux_select
[MUX_PGA_L
];
1755 unsigned int mux_pga_r
= priv
->mux_select
[MUX_PGA_R
];
1757 dev_info(priv
->dev
, "%s(), mux, mic %u, pga l %u, pga r %u\n",
1758 __func__
, mic_type
, mux_pga_l
, mux_pga_r
);
1761 regmap_update_bits(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
,
1764 /* disable aud_pad TX fifos */
1765 mt6358_mtkaif_tx_disable(priv
);
1767 /* L ADC input sel : off, disable L ADC */
1768 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1770 /* L preamplifier DCCEN */
1771 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1773 /* L preamplifier input sel : off, L PGA 0 dB gain */
1774 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1777 /* disable L preamplifier DCC precharge */
1778 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1781 /* R ADC input sel : off, disable R ADC */
1782 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1784 /* R preamplifier DCCEN */
1785 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1787 /* R preamplifier input sel : off, R PGA 0 dB gain */
1788 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1791 /* disable R preamplifier DCC precharge */
1792 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1796 /* Disable MICBIAS0, MISBIAS0 = 1P7V */
1797 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0000);
1799 /* Disable MICBIAS1 */
1800 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1803 if (IS_DCC_BASE(mic_type
)) {
1804 /* dcclk_gen_on=1'b0 */
1805 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2060);
1806 /* dcclk_pdn=1'b1 */
1807 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1808 /* dcclk_ref_ck_sel=2'b00 */
1809 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1810 /* dcclk_div=11'b00100000011 */
1811 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1815 static int mt6358_dmic_enable(struct mt6358_priv
*priv
)
1817 dev_info(priv
->dev
, "%s()\n", __func__
);
1820 /* Enable MICBIAS0, MISBIAS0 = 1P9V */
1821 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0021);
1823 /* RG_BANDGAPGEN=1'b0 */
1824 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1828 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON8
, 0x0005);
1830 /* here to set digital part */
1831 mt6358_mtkaif_tx_enable(priv
);
1833 /* UL dmic setting */
1834 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_H
, 0x0080);
1837 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
, 0x0003);
1839 /* Prevent pop noise form dmic hw */
1845 static void mt6358_dmic_disable(struct mt6358_priv
*priv
)
1847 dev_info(priv
->dev
, "%s()\n", __func__
);
1850 regmap_update_bits(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
,
1853 /* disable aud_pad TX fifos */
1854 mt6358_mtkaif_tx_disable(priv
);
1857 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON8
, 0x0000);
1860 /* MISBIAS0 = 1P7V */
1861 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0001);
1863 /* RG_BANDGAPGEN=1'b0 */
1864 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1867 /* MICBIA0 disable */
1868 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0000);
1871 static void mt6358_restore_pga(struct mt6358_priv
*priv
)
1873 unsigned int gain_l
, gain_r
;
1875 gain_l
= priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP1
];
1876 gain_r
= priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP2
];
1878 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1879 RG_AUDPREAMPLGAIN_MASK_SFT
,
1880 gain_l
<< RG_AUDPREAMPLGAIN_SFT
);
1881 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1882 RG_AUDPREAMPRGAIN_MASK_SFT
,
1883 gain_r
<< RG_AUDPREAMPRGAIN_SFT
);
1886 static int mt_mic_type_event(struct snd_soc_dapm_widget
*w
,
1887 struct snd_kcontrol
*kcontrol
,
1890 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1891 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1892 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1894 dev_dbg(priv
->dev
, "%s(), event 0x%x, mux %u\n",
1895 __func__
, event
, mux
);
1898 case SND_SOC_DAPM_WILL_PMU
:
1899 priv
->mux_select
[MUX_MIC_TYPE
] = mux
;
1901 case SND_SOC_DAPM_PRE_PMU
:
1903 case MIC_TYPE_MUX_DMIC
:
1904 mt6358_dmic_enable(priv
);
1907 mt6358_amic_enable(priv
);
1910 mt6358_restore_pga(priv
);
1913 case SND_SOC_DAPM_POST_PMD
:
1914 switch (priv
->mux_select
[MUX_MIC_TYPE
]) {
1915 case MIC_TYPE_MUX_DMIC
:
1916 mt6358_dmic_disable(priv
);
1919 mt6358_amic_disable(priv
);
1923 priv
->mux_select
[MUX_MIC_TYPE
] = mux
;
1932 static int mt_adc_l_event(struct snd_soc_dapm_widget
*w
,
1933 struct snd_kcontrol
*kcontrol
,
1936 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1937 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1938 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1940 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1941 __func__
, event
, mux
);
1943 priv
->mux_select
[MUX_ADC_L
] = mux
;
1948 static int mt_adc_r_event(struct snd_soc_dapm_widget
*w
,
1949 struct snd_kcontrol
*kcontrol
,
1952 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1953 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1954 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1956 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1957 __func__
, event
, mux
);
1959 priv
->mux_select
[MUX_ADC_R
] = mux
;
1964 static int mt_pga_left_event(struct snd_soc_dapm_widget
*w
,
1965 struct snd_kcontrol
*kcontrol
,
1968 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1969 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1970 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1972 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1973 __func__
, event
, mux
);
1975 priv
->mux_select
[MUX_PGA_L
] = mux
;
1980 static int mt_pga_right_event(struct snd_soc_dapm_widget
*w
,
1981 struct snd_kcontrol
*kcontrol
,
1984 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1985 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1986 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1988 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1989 __func__
, event
, mux
);
1991 priv
->mux_select
[MUX_PGA_R
] = mux
;
1996 static int mt_delay_250_event(struct snd_soc_dapm_widget
*w
,
1997 struct snd_kcontrol
*kcontrol
,
2001 case SND_SOC_DAPM_POST_PMU
:
2002 usleep_range(250, 270);
2004 case SND_SOC_DAPM_PRE_PMD
:
2005 usleep_range(250, 270);
2015 static const struct snd_soc_dapm_widget mt6358_dapm_widgets
[] = {
2017 SND_SOC_DAPM_SUPPLY_S("CLK_BUF", SUPPLY_SEQ_CLK_BUF
,
2019 RG_XO_AUDIO_EN_M_SFT
, 0, NULL
, 0),
2020 SND_SOC_DAPM_SUPPLY_S("AUDGLB", SUPPLY_SEQ_AUD_GLB
,
2021 MT6358_AUDDEC_ANA_CON13
,
2022 RG_AUDGLB_PWRDN_VA28_SFT
, 1, NULL
, 0),
2023 SND_SOC_DAPM_SUPPLY_S("CLKSQ Audio", SUPPLY_SEQ_CLKSQ
,
2024 MT6358_AUDENC_ANA_CON6
,
2027 SND_SOC_DAPM_PRE_PMU
),
2028 SND_SOC_DAPM_SUPPLY_S("AUDNCP_CK", SUPPLY_SEQ_TOP_CK
,
2029 MT6358_AUD_TOP_CKPDN_CON0
,
2030 RG_AUDNCP_CK_PDN_SFT
, 1, NULL
, 0),
2031 SND_SOC_DAPM_SUPPLY_S("ZCD13M_CK", SUPPLY_SEQ_TOP_CK
,
2032 MT6358_AUD_TOP_CKPDN_CON0
,
2033 RG_ZCD13M_CK_PDN_SFT
, 1, NULL
, 0),
2034 SND_SOC_DAPM_SUPPLY_S("AUD_CK", SUPPLY_SEQ_TOP_CK_LAST
,
2035 MT6358_AUD_TOP_CKPDN_CON0
,
2036 RG_AUD_CK_PDN_SFT
, 1,
2038 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
2039 SND_SOC_DAPM_SUPPLY_S("AUDIF_CK", SUPPLY_SEQ_TOP_CK
,
2040 MT6358_AUD_TOP_CKPDN_CON0
,
2041 RG_AUDIF_CK_PDN_SFT
, 1, NULL
, 0),
2044 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_AFE_CTL", SUPPLY_SEQ_AUD_TOP_LAST
,
2045 MT6358_AUDIO_TOP_CON0
,
2048 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
2049 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_DAC_CTL", SUPPLY_SEQ_AUD_TOP
,
2050 MT6358_AUDIO_TOP_CON0
,
2051 PDN_DAC_CTL_SFT
, 1, NULL
, 0),
2052 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_ADC_CTL", SUPPLY_SEQ_AUD_TOP
,
2053 MT6358_AUDIO_TOP_CON0
,
2054 PDN_ADC_CTL_SFT
, 1, NULL
, 0),
2055 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_I2S_DL", SUPPLY_SEQ_AUD_TOP
,
2056 MT6358_AUDIO_TOP_CON0
,
2057 PDN_I2S_DL_CTL_SFT
, 1, NULL
, 0),
2058 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PWR_CLK", SUPPLY_SEQ_AUD_TOP
,
2059 MT6358_AUDIO_TOP_CON0
,
2060 PWR_CLK_DIS_CTL_SFT
, 1, NULL
, 0),
2061 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_AFE_TESTMODEL", SUPPLY_SEQ_AUD_TOP
,
2062 MT6358_AUDIO_TOP_CON0
,
2063 PDN_AFE_TESTMODEL_CTL_SFT
, 1, NULL
, 0),
2064 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_RESERVED", SUPPLY_SEQ_AUD_TOP
,
2065 MT6358_AUDIO_TOP_CON0
,
2066 PDN_RESERVED_SFT
, 1, NULL
, 0),
2068 SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM
,
2072 SND_SOC_DAPM_SUPPLY_S("AFE_ON", SUPPLY_SEQ_AFE
,
2073 MT6358_AFE_UL_DL_CON0
, AFE_ON_SFT
, 0,
2077 SND_SOC_DAPM_AIF_IN_E("AIF_RX", "AIF1 Playback", 0,
2078 MT6358_AFE_DL_SRC2_CON0_L
,
2079 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0,
2081 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2084 SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM
,
2088 SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM
, 0, 0, &dac_in_mux_control
),
2090 SND_SOC_DAPM_DAC("DACL", NULL
, SND_SOC_NOPM
, 0, 0),
2092 SND_SOC_DAPM_DAC("DACR", NULL
, SND_SOC_NOPM
, 0, 0),
2095 SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM
, 0, 0, &lo_in_mux_control
),
2097 SND_SOC_DAPM_SUPPLY("LO Stability Enh", MT6358_AUDDEC_ANA_CON7
,
2098 RG_LOOUTPUTSTBENH_VAUDP15_SFT
, 0, NULL
, 0),
2100 SND_SOC_DAPM_OUT_DRV("LOL Buffer", MT6358_AUDDEC_ANA_CON7
,
2101 RG_AUDLOLPWRUP_VAUDP15_SFT
, 0, NULL
, 0),
2104 SND_SOC_DAPM_MUX_E("HPL Mux", SND_SOC_NOPM
, 0, 0,
2105 &hpl_in_mux_control
,
2107 SND_SOC_DAPM_PRE_PMU
|
2108 SND_SOC_DAPM_PRE_PMD
),
2110 SND_SOC_DAPM_MUX_E("HPR Mux", SND_SOC_NOPM
, 0, 0,
2111 &hpr_in_mux_control
,
2113 SND_SOC_DAPM_PRE_PMU
|
2114 SND_SOC_DAPM_PRE_PMD
),
2117 SND_SOC_DAPM_MUX_E("RCV Mux", SND_SOC_NOPM
, 0, 0,
2118 &rcv_in_mux_control
,
2120 SND_SOC_DAPM_PRE_PMU
|
2121 SND_SOC_DAPM_PRE_PMD
),
2124 SND_SOC_DAPM_OUTPUT("Receiver"),
2125 SND_SOC_DAPM_OUTPUT("Headphone L"),
2126 SND_SOC_DAPM_OUTPUT("Headphone R"),
2127 SND_SOC_DAPM_OUTPUT("Headphone L Ext Spk Amp"),
2128 SND_SOC_DAPM_OUTPUT("Headphone R Ext Spk Amp"),
2129 SND_SOC_DAPM_OUTPUT("LINEOUT L"),
2130 SND_SOC_DAPM_OUTPUT("LINEOUT L HSSPK"),
2133 SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6358_AFE_SGEN_CFG0
,
2134 SGEN_DAC_EN_CTL_SFT
, 0, NULL
, 0),
2135 SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6358_AFE_SGEN_CFG0
,
2136 SGEN_MUTE_SW_CTL_SFT
, 1,
2138 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2139 SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6358_AFE_DL_SRC2_CON0_L
,
2140 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0, NULL
, 0),
2142 SND_SOC_DAPM_INPUT("SGEN DL"),
2145 SND_SOC_DAPM_AIF_OUT_E("AIF1TX", "AIF1 Capture", 0,
2148 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2150 SND_SOC_DAPM_SUPPLY_S("ADC Supply", SUPPLY_SEQ_ADC_SUPPLY
,
2152 mt_adc_supply_event
,
2153 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2156 SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM
, 0, 0,
2157 &aif_out_mux_control
),
2159 SND_SOC_DAPM_MUX_E("Mic Type Mux", SND_SOC_NOPM
, 0, 0,
2160 &mic_type_mux_control
,
2162 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
|
2163 SND_SOC_DAPM_WILL_PMU
),
2165 SND_SOC_DAPM_MUX_E("ADC L Mux", SND_SOC_NOPM
, 0, 0,
2166 &adc_left_mux_control
,
2168 SND_SOC_DAPM_WILL_PMU
),
2169 SND_SOC_DAPM_MUX_E("ADC R Mux", SND_SOC_NOPM
, 0, 0,
2170 &adc_right_mux_control
,
2172 SND_SOC_DAPM_WILL_PMU
),
2174 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
2175 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
2177 SND_SOC_DAPM_MUX_E("PGA L Mux", SND_SOC_NOPM
, 0, 0,
2178 &pga_left_mux_control
,
2180 SND_SOC_DAPM_WILL_PMU
),
2181 SND_SOC_DAPM_MUX_E("PGA R Mux", SND_SOC_NOPM
, 0, 0,
2182 &pga_right_mux_control
,
2184 SND_SOC_DAPM_WILL_PMU
),
2186 SND_SOC_DAPM_PGA("PGA L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2187 SND_SOC_DAPM_PGA("PGA R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2190 SND_SOC_DAPM_INPUT("AIN0"),
2191 SND_SOC_DAPM_INPUT("AIN1"),
2192 SND_SOC_DAPM_INPUT("AIN2"),
2195 static const struct snd_soc_dapm_route mt6358_dapm_routes
[] = {
2197 {"AIF1TX", NULL
, "AIF Out Mux"},
2198 {"AIF1TX", NULL
, "CLK_BUF"},
2199 {"AIF1TX", NULL
, "AUDGLB"},
2200 {"AIF1TX", NULL
, "CLKSQ Audio"},
2202 {"AIF1TX", NULL
, "AUD_CK"},
2203 {"AIF1TX", NULL
, "AUDIF_CK"},
2205 {"AIF1TX", NULL
, "AUDIO_TOP_AFE_CTL"},
2206 {"AIF1TX", NULL
, "AUDIO_TOP_ADC_CTL"},
2207 {"AIF1TX", NULL
, "AUDIO_TOP_PWR_CLK"},
2208 {"AIF1TX", NULL
, "AUDIO_TOP_PDN_RESERVED"},
2209 {"AIF1TX", NULL
, "AUDIO_TOP_I2S_DL"},
2211 {"AIF1TX", NULL
, "AFE_ON"},
2213 {"AIF Out Mux", NULL
, "Mic Type Mux"},
2215 {"Mic Type Mux", "ACC", "ADC L"},
2216 {"Mic Type Mux", "ACC", "ADC R"},
2217 {"Mic Type Mux", "DCC", "ADC L"},
2218 {"Mic Type Mux", "DCC", "ADC R"},
2219 {"Mic Type Mux", "DCC_ECM_DIFF", "ADC L"},
2220 {"Mic Type Mux", "DCC_ECM_DIFF", "ADC R"},
2221 {"Mic Type Mux", "DCC_ECM_SINGLE", "ADC L"},
2222 {"Mic Type Mux", "DCC_ECM_SINGLE", "ADC R"},
2223 {"Mic Type Mux", "DMIC", "AIN0"},
2224 {"Mic Type Mux", "DMIC", "AIN2"},
2226 {"ADC L", NULL
, "ADC L Mux"},
2227 {"ADC L", NULL
, "ADC Supply"},
2228 {"ADC R", NULL
, "ADC R Mux"},
2229 {"ADC R", NULL
, "ADC Supply"},
2231 {"ADC L Mux", "Left Preamplifier", "PGA L"},
2233 {"ADC R Mux", "Right Preamplifier", "PGA R"},
2235 {"PGA L", NULL
, "PGA L Mux"},
2236 {"PGA R", NULL
, "PGA R Mux"},
2238 {"PGA L Mux", "AIN0", "AIN0"},
2239 {"PGA L Mux", "AIN1", "AIN1"},
2240 {"PGA L Mux", "AIN2", "AIN2"},
2242 {"PGA R Mux", "AIN0", "AIN0"},
2243 {"PGA R Mux", "AIN1", "AIN1"},
2244 {"PGA R Mux", "AIN2", "AIN2"},
2247 {"DL Power Supply", NULL
, "CLK_BUF"},
2248 {"DL Power Supply", NULL
, "AUDGLB"},
2249 {"DL Power Supply", NULL
, "CLKSQ Audio"},
2251 {"DL Power Supply", NULL
, "AUDNCP_CK"},
2252 {"DL Power Supply", NULL
, "ZCD13M_CK"},
2253 {"DL Power Supply", NULL
, "AUD_CK"},
2254 {"DL Power Supply", NULL
, "AUDIF_CK"},
2256 /* DL Digital Supply */
2257 {"DL Digital Clock", NULL
, "AUDIO_TOP_AFE_CTL"},
2258 {"DL Digital Clock", NULL
, "AUDIO_TOP_DAC_CTL"},
2259 {"DL Digital Clock", NULL
, "AUDIO_TOP_PWR_CLK"},
2261 {"DL Digital Clock", NULL
, "AFE_ON"},
2263 {"AIF_RX", NULL
, "DL Digital Clock"},
2266 {"DAC In Mux", "Normal Path", "AIF_RX"},
2268 {"DAC In Mux", "Sgen", "SGEN DL"},
2269 {"SGEN DL", NULL
, "SGEN DL SRC"},
2270 {"SGEN DL", NULL
, "SGEN MUTE"},
2271 {"SGEN DL", NULL
, "SGEN DL Enable"},
2272 {"SGEN DL", NULL
, "DL Digital Clock"},
2273 {"SGEN DL", NULL
, "AUDIO_TOP_PDN_AFE_TESTMODEL"},
2275 {"DACL", NULL
, "DAC In Mux"},
2276 {"DACL", NULL
, "DL Power Supply"},
2278 {"DACR", NULL
, "DAC In Mux"},
2279 {"DACR", NULL
, "DL Power Supply"},
2282 {"LOL Mux", "Playback", "DACL"},
2284 {"LOL Buffer", NULL
, "LOL Mux"},
2285 {"LOL Buffer", NULL
, "LO Stability Enh"},
2287 {"LINEOUT L", NULL
, "LOL Buffer"},
2289 /* Headphone Path */
2290 {"HPL Mux", "Audio Playback", "DACL"},
2291 {"HPR Mux", "Audio Playback", "DACR"},
2292 {"HPL Mux", "HP Impedance", "DACL"},
2293 {"HPR Mux", "HP Impedance", "DACR"},
2294 {"HPL Mux", "LoudSPK Playback", "DACL"},
2295 {"HPR Mux", "LoudSPK Playback", "DACR"},
2297 {"Headphone L", NULL
, "HPL Mux"},
2298 {"Headphone R", NULL
, "HPR Mux"},
2299 {"Headphone L Ext Spk Amp", NULL
, "HPL Mux"},
2300 {"Headphone R Ext Spk Amp", NULL
, "HPR Mux"},
2301 {"LINEOUT L HSSPK", NULL
, "HPL Mux"},
2304 {"RCV Mux", "Voice Playback", "DACL"},
2305 {"Receiver", NULL
, "RCV Mux"},
2308 static int mt6358_codec_dai_hw_params(struct snd_pcm_substream
*substream
,
2309 struct snd_pcm_hw_params
*params
,
2310 struct snd_soc_dai
*dai
)
2312 struct snd_soc_component
*cmpnt
= dai
->component
;
2313 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
2314 unsigned int rate
= params_rate(params
);
2316 dev_info(priv
->dev
, "%s(), substream->stream %d, rate %d, number %d\n",
2322 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2323 priv
->dl_rate
= rate
;
2324 else if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2325 priv
->ul_rate
= rate
;
2330 static const struct snd_soc_dai_ops mt6358_codec_dai_ops
= {
2331 .hw_params
= mt6358_codec_dai_hw_params
,
2334 #define MT6358_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
2335 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
2336 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
2337 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
2338 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
2339 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)
2341 static struct snd_soc_dai_driver mt6358_dai_driver
[] = {
2343 .name
= "mt6358-snd-codec-aif1",
2345 .stream_name
= "AIF1 Playback",
2348 .rates
= SNDRV_PCM_RATE_8000_48000
|
2349 SNDRV_PCM_RATE_96000
|
2350 SNDRV_PCM_RATE_192000
,
2351 .formats
= MT6358_FORMATS
,
2354 .stream_name
= "AIF1 Capture",
2357 .rates
= SNDRV_PCM_RATE_8000
|
2358 SNDRV_PCM_RATE_16000
|
2359 SNDRV_PCM_RATE_32000
|
2360 SNDRV_PCM_RATE_48000
,
2361 .formats
= MT6358_FORMATS
,
2363 .ops
= &mt6358_codec_dai_ops
,
2367 static void mt6358_codec_init_reg(struct mt6358_priv
*priv
)
2369 /* Disable HeadphoneL/HeadphoneR short circuit protection */
2370 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
2371 RG_AUDHPLSCDISABLE_VAUDP15_MASK_SFT
,
2372 0x1 << RG_AUDHPLSCDISABLE_VAUDP15_SFT
);
2373 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
2374 RG_AUDHPRSCDISABLE_VAUDP15_MASK_SFT
,
2375 0x1 << RG_AUDHPRSCDISABLE_VAUDP15_SFT
);
2376 /* Disable voice short circuit protection */
2377 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
2378 RG_AUDHSSCDISABLE_VAUDP15_MASK_SFT
,
2379 0x1 << RG_AUDHSSCDISABLE_VAUDP15_SFT
);
2380 /* disable LO buffer left short circuit protection */
2381 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
2382 RG_AUDLOLSCDISABLE_VAUDP15_MASK_SFT
,
2383 0x1 << RG_AUDLOLSCDISABLE_VAUDP15_SFT
);
2385 /* accdet s/w enable */
2386 regmap_update_bits(priv
->regmap
, MT6358_ACCDET_CON13
,
2389 /* gpio miso driving set to 4mA */
2390 regmap_write(priv
->regmap
, MT6358_DRV_CON3
, 0x8888);
2393 playback_gpio_reset(priv
);
2394 capture_gpio_reset(priv
);
2397 static int mt6358_codec_probe(struct snd_soc_component
*cmpnt
)
2399 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
2402 snd_soc_component_init_regmap(cmpnt
, priv
->regmap
);
2404 mt6358_codec_init_reg(priv
);
2406 priv
->avdd_reg
= devm_regulator_get(priv
->dev
, "Avdd");
2407 if (IS_ERR(priv
->avdd_reg
)) {
2408 dev_err(priv
->dev
, "%s() have no Avdd supply", __func__
);
2409 return PTR_ERR(priv
->avdd_reg
);
2412 ret
= regulator_enable(priv
->avdd_reg
);
2419 static const struct snd_soc_component_driver mt6358_soc_component_driver
= {
2420 .probe
= mt6358_codec_probe
,
2421 .controls
= mt6358_snd_controls
,
2422 .num_controls
= ARRAY_SIZE(mt6358_snd_controls
),
2423 .dapm_widgets
= mt6358_dapm_widgets
,
2424 .num_dapm_widgets
= ARRAY_SIZE(mt6358_dapm_widgets
),
2425 .dapm_routes
= mt6358_dapm_routes
,
2426 .num_dapm_routes
= ARRAY_SIZE(mt6358_dapm_routes
),
2429 static int mt6358_platform_driver_probe(struct platform_device
*pdev
)
2431 struct mt6358_priv
*priv
;
2432 struct mt6397_chip
*mt6397
= dev_get_drvdata(pdev
->dev
.parent
);
2434 priv
= devm_kzalloc(&pdev
->dev
,
2435 sizeof(struct mt6358_priv
),
2440 dev_set_drvdata(&pdev
->dev
, priv
);
2442 priv
->dev
= &pdev
->dev
;
2444 priv
->regmap
= mt6397
->regmap
;
2445 if (IS_ERR(priv
->regmap
))
2446 return PTR_ERR(priv
->regmap
);
2448 dev_info(priv
->dev
, "%s(), dev name %s\n",
2449 __func__
, dev_name(&pdev
->dev
));
2451 return devm_snd_soc_register_component(&pdev
->dev
,
2452 &mt6358_soc_component_driver
,
2454 ARRAY_SIZE(mt6358_dai_driver
));
2457 static const struct of_device_id mt6358_of_match
[] = {
2458 {.compatible
= "mediatek,mt6358-sound",},
2461 MODULE_DEVICE_TABLE(of
, mt6358_of_match
);
2463 static struct platform_driver mt6358_platform_driver
= {
2465 .name
= "mt6358-sound",
2466 .of_match_table
= mt6358_of_match
,
2468 .probe
= mt6358_platform_driver_probe
,
2471 module_platform_driver(mt6358_platform_driver
)
2473 /* Module information */
2474 MODULE_DESCRIPTION("MT6358 ALSA SoC codec driver");
2475 MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
2476 MODULE_LICENSE("GPL v2");