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
;
99 unsigned int dmic_one_wire_mode
;
102 int mt6358_set_mtkaif_protocol(struct snd_soc_component
*cmpnt
,
105 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
107 priv
->mtkaif_protocol
= mtkaif_protocol
;
111 static void playback_gpio_set(struct mt6358_priv
*priv
)
113 /* set gpio mosi mode */
114 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_CLR
,
116 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_SET
,
118 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2
,
122 static void playback_gpio_reset(struct mt6358_priv
*priv
)
124 /* set pad_aud_*_mosi to GPIO mode and dir input
126 * pad_aud_dat_mosi*, because the pin is used as boot strap
127 * don't clean clk/sync, for mtkaif protocol 2
129 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2_CLR
,
131 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE2
,
133 regmap_update_bits(priv
->regmap
, MT6358_GPIO_DIR0
,
137 static void capture_gpio_set(struct mt6358_priv
*priv
)
139 /* set gpio miso mode */
140 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_CLR
,
142 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_SET
,
144 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
,
148 static void capture_gpio_reset(struct mt6358_priv
*priv
)
150 /* set pad_aud_*_miso to GPIO mode and dir input
152 * pad_aud_clk_miso, because when playback only the miso_clk
153 * will also have 26m, so will have power leak
154 * pad_aud_dat_miso*, because the pin is used as boot strap
156 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3_CLR
,
158 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
,
160 regmap_update_bits(priv
->regmap
, MT6358_GPIO_DIR0
,
164 /* use only when not govern by DAPM */
165 static int mt6358_set_dcxo(struct mt6358_priv
*priv
, bool enable
)
167 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
,
168 0x1 << RG_XO_AUDIO_EN_M_SFT
,
169 (enable
? 1 : 0) << RG_XO_AUDIO_EN_M_SFT
);
173 /* use only when not govern by DAPM */
174 static int mt6358_set_clksq(struct mt6358_priv
*priv
, bool enable
)
176 /* audio clk source from internal dcxo */
177 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
178 RG_CLKSQ_IN_SEL_TEST_MASK_SFT
,
181 /* Enable/disable CLKSQ 26MHz */
182 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
183 RG_CLKSQ_EN_MASK_SFT
,
184 (enable
? 1 : 0) << RG_CLKSQ_EN_SFT
);
188 /* use only when not govern by DAPM */
189 static int mt6358_set_aud_global_bias(struct mt6358_priv
*priv
, bool enable
)
191 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
192 RG_AUDGLB_PWRDN_VA28_MASK_SFT
,
193 (enable
? 0 : 1) << RG_AUDGLB_PWRDN_VA28_SFT
);
197 /* use only when not govern by DAPM */
198 static int mt6358_set_topck(struct mt6358_priv
*priv
, bool enable
)
200 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
201 0x0066, enable
? 0x0 : 0x66);
205 static int mt6358_mtkaif_tx_enable(struct mt6358_priv
*priv
)
207 switch (priv
->mtkaif_protocol
) {
208 case MT6358_MTKAIF_PROTOCOL_2_CLK_P2
:
209 /* MTKAIF TX format setting */
210 regmap_update_bits(priv
->regmap
,
211 MT6358_AFE_ADDA_MTKAIF_CFG0
,
213 /* enable aud_pad TX fifos */
214 regmap_update_bits(priv
->regmap
,
215 MT6358_AFE_AUD_PAD_TOP
,
217 regmap_update_bits(priv
->regmap
,
218 MT6358_AFE_AUD_PAD_TOP
,
221 case MT6358_MTKAIF_PROTOCOL_2
:
222 /* MTKAIF TX format setting */
223 regmap_update_bits(priv
->regmap
,
224 MT6358_AFE_ADDA_MTKAIF_CFG0
,
226 /* enable aud_pad TX fifos */
227 regmap_update_bits(priv
->regmap
,
228 MT6358_AFE_AUD_PAD_TOP
,
231 case MT6358_MTKAIF_PROTOCOL_1
:
233 /* MTKAIF TX format setting */
234 regmap_update_bits(priv
->regmap
,
235 MT6358_AFE_ADDA_MTKAIF_CFG0
,
237 /* enable aud_pad TX fifos */
238 regmap_update_bits(priv
->regmap
,
239 MT6358_AFE_AUD_PAD_TOP
,
246 static int mt6358_mtkaif_tx_disable(struct mt6358_priv
*priv
)
248 /* disable aud_pad TX fifos */
249 regmap_update_bits(priv
->regmap
, MT6358_AFE_AUD_PAD_TOP
,
254 int mt6358_mtkaif_calibration_enable(struct snd_soc_component
*cmpnt
)
256 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
258 playback_gpio_set(priv
);
259 capture_gpio_set(priv
);
260 mt6358_mtkaif_tx_enable(priv
);
262 mt6358_set_dcxo(priv
, true);
263 mt6358_set_aud_global_bias(priv
, true);
264 mt6358_set_clksq(priv
, true);
265 mt6358_set_topck(priv
, true);
267 /* set dat_miso_loopback on */
268 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
269 RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT
,
270 1 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT
);
271 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
272 RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT
,
273 1 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT
);
277 int mt6358_mtkaif_calibration_disable(struct snd_soc_component
*cmpnt
)
279 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
281 /* set dat_miso_loopback off */
282 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
283 RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT
,
284 0 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT
);
285 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
286 RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT
,
287 0 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT
);
289 mt6358_set_topck(priv
, false);
290 mt6358_set_clksq(priv
, false);
291 mt6358_set_aud_global_bias(priv
, false);
292 mt6358_set_dcxo(priv
, false);
294 mt6358_mtkaif_tx_disable(priv
);
295 playback_gpio_reset(priv
);
296 capture_gpio_reset(priv
);
300 int mt6358_set_mtkaif_calibration_phase(struct snd_soc_component
*cmpnt
,
301 int phase_1
, int phase_2
)
303 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
305 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
306 RG_AUD_PAD_TOP_PHASE_MODE_MASK_SFT
,
307 phase_1
<< RG_AUD_PAD_TOP_PHASE_MODE_SFT
);
308 regmap_update_bits(priv
->regmap
, MT6358_AUDIO_DIG_CFG
,
309 RG_AUD_PAD_TOP_PHASE_MODE2_MASK_SFT
,
310 phase_2
<< RG_AUD_PAD_TOP_PHASE_MODE2_SFT
);
320 DL_GAIN_N_40DB
= 0x1f,
323 #define DL_GAIN_N_10DB_REG (DL_GAIN_N_10DB << 7 | DL_GAIN_N_10DB)
324 #define DL_GAIN_N_40DB_REG (DL_GAIN_N_40DB << 7 | DL_GAIN_N_40DB)
325 #define DL_GAIN_REG_MASK 0x0f9f
327 static void hp_zcd_disable(struct mt6358_priv
*priv
)
329 regmap_write(priv
->regmap
, MT6358_ZCD_CON0
, 0x0000);
332 static void hp_main_output_ramp(struct mt6358_priv
*priv
, bool up
)
334 int i
= 0, stage
= 0;
337 /* Enable/Reduce HPL/R main output stage step by step */
338 for (i
= 0; i
<= target
; i
++) {
339 stage
= up
? i
: target
- i
;
340 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
341 0x7 << 8, stage
<< 8);
342 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
343 0x7 << 11, stage
<< 11);
344 usleep_range(100, 150);
348 static void hp_aux_feedback_loop_gain_ramp(struct mt6358_priv
*priv
, bool up
)
350 int i
= 0, stage
= 0;
352 /* Reduce HP aux feedback loop gain step by step */
353 for (i
= 0; i
<= 0xf; i
++) {
354 stage
= up
? i
: 0xf - i
;
355 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
356 0xf << 12, stage
<< 12);
357 usleep_range(100, 150);
361 static void hp_pull_down(struct mt6358_priv
*priv
, bool enable
)
366 for (i
= 0x0; i
<= 0x6; i
++) {
367 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
369 usleep_range(600, 700);
372 for (i
= 0x6; i
>= 0x1; i
--) {
373 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
375 usleep_range(600, 700);
380 static bool is_valid_hp_pga_idx(int reg_idx
)
382 return (reg_idx
>= DL_GAIN_8DB
&& reg_idx
<= DL_GAIN_N_10DB
) ||
383 reg_idx
== DL_GAIN_N_40DB
;
386 static void headset_volume_ramp(struct mt6358_priv
*priv
, int from
, int to
)
388 int offset
= 0, count
= 0, reg_idx
;
390 if (!is_valid_hp_pga_idx(from
) || !is_valid_hp_pga_idx(to
))
391 dev_warn(priv
->dev
, "%s(), volume index is not valid, from %d, to %d\n",
394 dev_info(priv
->dev
, "%s(), from %d, to %d\n",
402 while (offset
>= 0) {
404 reg_idx
= from
+ count
;
406 reg_idx
= from
- count
;
408 if (is_valid_hp_pga_idx(reg_idx
)) {
409 regmap_update_bits(priv
->regmap
,
412 (reg_idx
<< 7) | reg_idx
);
413 usleep_range(200, 300);
420 static int mt6358_put_volsw(struct snd_kcontrol
*kcontrol
,
421 struct snd_ctl_elem_value
*ucontrol
)
423 struct snd_soc_component
*component
=
424 snd_soc_kcontrol_component(kcontrol
);
425 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(component
);
426 struct soc_mixer_control
*mc
=
427 (struct soc_mixer_control
*)kcontrol
->private_value
;
431 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
436 case MT6358_ZCD_CON2
:
437 regmap_read(priv
->regmap
, MT6358_ZCD_CON2
, ®
);
438 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
] =
439 (reg
>> RG_AUDHPLGAIN_SFT
) & RG_AUDHPLGAIN_MASK
;
440 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTR
] =
441 (reg
>> RG_AUDHPRGAIN_SFT
) & RG_AUDHPRGAIN_MASK
;
443 case MT6358_ZCD_CON1
:
444 regmap_read(priv
->regmap
, MT6358_ZCD_CON1
, ®
);
445 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTL
] =
446 (reg
>> RG_AUDLOLGAIN_SFT
) & RG_AUDLOLGAIN_MASK
;
447 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTR
] =
448 (reg
>> RG_AUDLORGAIN_SFT
) & RG_AUDLORGAIN_MASK
;
450 case MT6358_ZCD_CON3
:
451 regmap_read(priv
->regmap
, MT6358_ZCD_CON3
, ®
);
452 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HSOUTL
] =
453 (reg
>> RG_AUDHSGAIN_SFT
) & RG_AUDHSGAIN_MASK
;
454 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HSOUTR
] =
455 (reg
>> RG_AUDHSGAIN_SFT
) & RG_AUDHSGAIN_MASK
;
457 case MT6358_AUDENC_ANA_CON0
:
458 case MT6358_AUDENC_ANA_CON1
:
459 regmap_read(priv
->regmap
, MT6358_AUDENC_ANA_CON0
, ®
);
460 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP1
] =
461 (reg
>> RG_AUDPREAMPLGAIN_SFT
) & RG_AUDPREAMPLGAIN_MASK
;
462 regmap_read(priv
->regmap
, MT6358_AUDENC_ANA_CON1
, ®
);
463 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP2
] =
464 (reg
>> RG_AUDPREAMPRGAIN_SFT
) & RG_AUDPREAMPRGAIN_MASK
;
471 static void mt6358_restore_pga(struct mt6358_priv
*priv
);
473 static int mt6358_enable_wov_phase2(struct mt6358_priv
*priv
)
476 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
478 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
, 0xffff, 0xa2b5);
479 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
481 mt6358_restore_pga(priv
);
483 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW13
, 0xffff, 0x9929);
484 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
486 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON8
,
490 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
492 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
, 0xffff, 0x0120);
493 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG0
, 0xffff, 0xffff);
494 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG1
, 0xffff, 0x0200);
495 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG2
, 0xffff, 0x2424);
496 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG3
, 0xffff, 0xdbac);
497 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG4
, 0xffff, 0x029e);
498 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG5
, 0xffff, 0x0000);
499 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_POSDIV_CFG0
,
501 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_HPF_CFG0
,
503 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_TOP
, 0xffff, 0x68d1);
508 static int mt6358_disable_wov_phase2(struct mt6358_priv
*priv
)
511 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_TOP
, 0xffff, 0xc000);
512 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_HPF_CFG0
,
514 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_POSDIV_CFG0
,
516 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG5
, 0xffff, 0x0100);
517 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG4
, 0xffff, 0x006c);
518 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG3
, 0xffff, 0xa879);
519 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG2
, 0xffff, 0x2323);
520 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG1
, 0xffff, 0x0400);
521 regmap_update_bits(priv
->regmap
, MT6358_AFE_VOW_CFG0
, 0xffff, 0x0000);
522 regmap_update_bits(priv
->regmap
, MT6358_GPIO_MODE3
, 0xffff, 0x02d8);
523 regmap_update_bits(priv
->regmap
, MT6358_AUD_TOP_CKPDN_CON0
,
527 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON8
,
529 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
531 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW13
, 0xffff, 0x9829);
532 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
534 mt6358_restore_pga(priv
);
535 regmap_update_bits(priv
->regmap
, MT6358_DCXO_CW14
, 0xffff, 0xa2b5);
536 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
542 static int mt6358_get_wov(struct snd_kcontrol
*kcontrol
,
543 struct snd_ctl_elem_value
*ucontrol
)
545 struct snd_soc_component
*c
= snd_soc_kcontrol_component(kcontrol
);
546 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(c
);
548 ucontrol
->value
.integer
.value
[0] = priv
->wov_enabled
;
552 static int mt6358_put_wov(struct snd_kcontrol
*kcontrol
,
553 struct snd_ctl_elem_value
*ucontrol
)
555 struct snd_soc_component
*c
= snd_soc_kcontrol_component(kcontrol
);
556 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(c
);
557 int enabled
= ucontrol
->value
.integer
.value
[0];
559 if (priv
->wov_enabled
!= enabled
) {
561 mt6358_enable_wov_phase2(priv
);
563 mt6358_disable_wov_phase2(priv
);
565 priv
->wov_enabled
= enabled
;
571 static const DECLARE_TLV_DB_SCALE(playback_tlv
, -1000, 100, 0);
572 static const DECLARE_TLV_DB_SCALE(pga_tlv
, 0, 600, 0);
574 static const struct snd_kcontrol_new mt6358_snd_controls
[] = {
576 SOC_DOUBLE_EXT_TLV("Headphone Volume",
577 MT6358_ZCD_CON2
, 0, 7, 0x12, 1,
578 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
579 SOC_DOUBLE_EXT_TLV("Lineout Volume",
580 MT6358_ZCD_CON1
, 0, 7, 0x12, 1,
581 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
582 SOC_SINGLE_EXT_TLV("Handset Volume",
583 MT6358_ZCD_CON3
, 0, 0x12, 1,
584 snd_soc_get_volsw
, mt6358_put_volsw
, playback_tlv
),
586 SOC_DOUBLE_R_EXT_TLV("PGA Volume",
587 MT6358_AUDENC_ANA_CON0
, MT6358_AUDENC_ANA_CON1
,
589 snd_soc_get_volsw
, mt6358_put_volsw
, pga_tlv
),
591 SOC_SINGLE_BOOL_EXT("Wake-on-Voice Phase2 Switch", 0,
592 mt6358_get_wov
, mt6358_put_wov
),
597 static const char * const lo_in_mux_map
[] = {
598 "Open", "Mute", "Playback", "Test Mode"
601 static int lo_in_mux_map_value
[] = {
605 static SOC_VALUE_ENUM_SINGLE_DECL(lo_in_mux_map_enum
,
606 MT6358_AUDDEC_ANA_CON7
,
607 RG_AUDLOLMUXINPUTSEL_VAUDP15_SFT
,
608 RG_AUDLOLMUXINPUTSEL_VAUDP15_MASK
,
610 lo_in_mux_map_value
);
612 static const struct snd_kcontrol_new lo_in_mux_control
=
613 SOC_DAPM_ENUM("In Select", lo_in_mux_map_enum
);
625 static const char * const hp_in_mux_map
[] = {
636 static int hp_in_mux_map_value
[] = {
647 static SOC_VALUE_ENUM_SINGLE_DECL(hpl_in_mux_map_enum
,
652 hp_in_mux_map_value
);
654 static const struct snd_kcontrol_new hpl_in_mux_control
=
655 SOC_DAPM_ENUM("HPL Select", hpl_in_mux_map_enum
);
657 static SOC_VALUE_ENUM_SINGLE_DECL(hpr_in_mux_map_enum
,
662 hp_in_mux_map_value
);
664 static const struct snd_kcontrol_new hpr_in_mux_control
=
665 SOC_DAPM_ENUM("HPR Select", hpr_in_mux_map_enum
);
671 RCV_MUX_VOICE_PLAYBACK
,
676 static const char * const rcv_in_mux_map
[] = {
677 "Open", "Mute", "Voice Playback", "Test Mode"
680 static int rcv_in_mux_map_value
[] = {
683 RCV_MUX_VOICE_PLAYBACK
,
687 static SOC_VALUE_ENUM_SINGLE_DECL(rcv_in_mux_map_enum
,
692 rcv_in_mux_map_value
);
694 static const struct snd_kcontrol_new rcv_in_mux_control
=
695 SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum
);
698 static const char * const dac_in_mux_map
[] = {
699 "Normal Path", "Sgen"
702 static int dac_in_mux_map_value
[] = {
706 static SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum
,
711 dac_in_mux_map_value
);
713 static const struct snd_kcontrol_new dac_in_mux_control
=
714 SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum
);
717 static SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum
,
722 dac_in_mux_map_value
);
724 static const struct snd_kcontrol_new aif_out_mux_control
=
725 SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum
);
729 MIC_TYPE_MUX_IDLE
= 0,
733 MIC_TYPE_MUX_DCC_ECM_DIFF
,
734 MIC_TYPE_MUX_DCC_ECM_SINGLE
,
735 MIC_TYPE_MUX_MASK
= 0x7,
738 #define IS_DCC_BASE(type) ((type) == MIC_TYPE_MUX_DCC || \
739 (type) == MIC_TYPE_MUX_DCC_ECM_DIFF || \
740 (type) == MIC_TYPE_MUX_DCC_ECM_SINGLE)
742 static const char * const mic_type_mux_map
[] = {
751 static int mic_type_mux_map_value
[] = {
756 MIC_TYPE_MUX_DCC_ECM_DIFF
,
757 MIC_TYPE_MUX_DCC_ECM_SINGLE
,
760 static SOC_VALUE_ENUM_SINGLE_DECL(mic_type_mux_map_enum
,
765 mic_type_mux_map_value
);
767 static const struct snd_kcontrol_new mic_type_mux_control
=
768 SOC_DAPM_ENUM("Mic Type Select", mic_type_mux_map_enum
);
774 ADC_MUX_PREAMPLIFIER
,
779 static const char * const adc_left_mux_map
[] = {
780 "Idle", "AIN0", "Left Preamplifier", "Idle_1"
783 static int adc_mux_map_value
[] = {
786 ADC_MUX_PREAMPLIFIER
,
790 static SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum
,
797 static const struct snd_kcontrol_new adc_left_mux_control
=
798 SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum
);
801 static const char * const adc_right_mux_map
[] = {
802 "Idle", "AIN0", "Right Preamplifier", "Idle_1"
805 static SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum
,
812 static const struct snd_kcontrol_new adc_right_mux_control
=
813 SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum
);
824 static const char * const pga_mux_map
[] = {
825 "None", "AIN0", "AIN1", "AIN2"
828 static int pga_mux_map_value
[] = {
835 static SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum
,
842 static const struct snd_kcontrol_new pga_left_mux_control
=
843 SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum
);
846 static SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum
,
853 static const struct snd_kcontrol_new pga_right_mux_control
=
854 SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum
);
856 static int mt_clksq_event(struct snd_soc_dapm_widget
*w
,
857 struct snd_kcontrol
*kcontrol
,
860 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
861 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
863 dev_dbg(priv
->dev
, "%s(), event = 0x%x\n", __func__
, event
);
866 case SND_SOC_DAPM_PRE_PMU
:
867 /* audio clk source from internal dcxo */
868 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON6
,
869 RG_CLKSQ_IN_SEL_TEST_MASK_SFT
,
879 static int mt_sgen_event(struct snd_soc_dapm_widget
*w
,
880 struct snd_kcontrol
*kcontrol
,
883 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
884 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
886 dev_dbg(priv
->dev
, "%s(), event = 0x%x\n", __func__
, event
);
889 case SND_SOC_DAPM_PRE_PMU
:
890 /* sdm audio fifo clock power on */
891 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0006);
892 /* scrambler clock on enable */
893 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xCBA1);
895 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0003);
896 /* sdm fifo enable */
897 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x000B);
899 regmap_update_bits(priv
->regmap
, MT6358_AFE_SGEN_CFG0
,
902 regmap_update_bits(priv
->regmap
, MT6358_AFE_SGEN_CFG1
,
906 case SND_SOC_DAPM_POST_PMD
:
907 /* DL scrambler disabling sequence */
908 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0000);
909 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xcba0);
918 static int mt_aif_in_event(struct snd_soc_dapm_widget
*w
,
919 struct snd_kcontrol
*kcontrol
,
922 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
923 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
925 dev_info(priv
->dev
, "%s(), event 0x%x, rate %d\n",
926 __func__
, event
, priv
->dl_rate
);
929 case SND_SOC_DAPM_PRE_PMU
:
930 playback_gpio_set(priv
);
932 /* sdm audio fifo clock power on */
933 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0006);
934 /* scrambler clock on enable */
935 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xCBA1);
937 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0003);
938 /* sdm fifo enable */
939 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x000B);
941 case SND_SOC_DAPM_POST_PMD
:
942 /* DL scrambler disabling sequence */
943 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON2
, 0x0000);
944 regmap_write(priv
->regmap
, MT6358_AFUNC_AUD_CON0
, 0xcba0);
946 playback_gpio_reset(priv
);
955 static int mtk_hp_enable(struct mt6358_priv
*priv
)
957 /* Pull-down HPL/R to AVSS28_AUD */
958 hp_pull_down(priv
, true);
959 /* release HP CMFB gate rstb */
960 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
963 /* Reduce ESD resistance of AU_REFN */
964 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
966 /* Set HPR/HPL gain as minimum (~ -40dB) */
967 regmap_write(priv
->regmap
, MT6358_ZCD_CON2
, DL_GAIN_N_40DB_REG
);
969 /* Turn on DA_600K_NCP_VA18 */
970 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
971 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
972 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
973 /* Toggle RG_DIVCKS_CHG */
974 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
975 /* Set NCP soft start mode as default mode: 100us */
976 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
978 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
979 usleep_range(250, 270);
981 /* Enable cap-less LDOs (1.5V) */
982 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
984 /* Enable NV regulator (-1.2V) */
985 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
986 usleep_range(100, 120);
988 /* Disable AUD_ZCD */
989 hp_zcd_disable(priv
);
991 /* Disable headphone short-circuit protection */
992 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3000);
995 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
997 /* Set HP DR bias current optimization, 010: 6uA */
998 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
999 /* Set HP & ZCD bias current optimization */
1000 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
1001 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1002 /* Set HPP/N STB enhance circuits */
1003 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4033);
1005 /* Enable HP aux output stage */
1006 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x000c);
1007 /* Enable HP aux feedback loop */
1008 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x003c);
1009 /* Enable HP aux CMFB loop */
1010 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0c00);
1011 /* Enable HP driver bias circuits */
1012 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30c0);
1013 /* Enable HP driver core circuits */
1014 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f0);
1015 /* Short HP main output to HP aux output stage */
1016 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x00fc);
1018 /* Enable HP main CMFB loop */
1019 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0e00);
1020 /* Disable HP aux CMFB loop */
1021 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0200);
1023 /* Select CMFB resistor bulk to AC mode */
1024 /* Selec HS/LO cap size (6.5pF default) */
1025 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1027 /* Enable HP main output stage */
1028 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x00ff);
1029 /* Enable HPR/L main output stage step by step */
1030 hp_main_output_ramp(priv
, true);
1032 /* Reduce HP aux feedback loop gain */
1033 hp_aux_feedback_loop_gain_ramp(priv
, true);
1034 /* Disable HP aux feedback loop */
1035 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1037 /* apply volume setting */
1038 headset_volume_ramp(priv
,
1040 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
]);
1042 /* Disable HP aux output stage */
1043 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1044 /* Unshort HP main output to HP aux output stage */
1045 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3f03);
1046 usleep_range(100, 120);
1048 /* Enable AUD_CLK */
1049 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x1);
1050 /* Enable Audio DAC */
1051 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30ff);
1052 /* Enable low-noise mode of DAC */
1053 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0xf201);
1054 usleep_range(100, 120);
1056 /* Switch HPL MUX to audio DAC */
1057 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x32ff);
1058 /* Switch HPR MUX to audio DAC */
1059 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3aff);
1061 /* Disable Pull-down HPL/R to AVSS28_AUD */
1062 hp_pull_down(priv
, false);
1067 static int mtk_hp_disable(struct mt6358_priv
*priv
)
1069 /* Pull-down HPL/R to AVSS28_AUD */
1070 hp_pull_down(priv
, true);
1072 /* HPR/HPL mux to open */
1073 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1076 /* Disable low-noise mode of DAC */
1077 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1080 /* Disable Audio DAC */
1081 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1084 /* Disable AUD_CLK */
1085 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x0);
1087 /* Short HP main output to HP aux output stage */
1088 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1089 /* Enable HP aux output stage */
1090 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1092 /* decrease HPL/R gain to normal gain step by step */
1093 headset_volume_ramp(priv
,
1094 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
],
1097 /* Enable HP aux feedback loop */
1098 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fff);
1100 /* Reduce HP aux feedback loop gain */
1101 hp_aux_feedback_loop_gain_ramp(priv
, false);
1103 /* decrease HPR/L main output stage step by step */
1104 hp_main_output_ramp(priv
, false);
1106 /* Disable HP main output stage */
1107 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3, 0x0);
1109 /* Enable HP aux CMFB loop */
1110 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0e00);
1112 /* Disable HP main CMFB loop */
1113 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0c00);
1115 /* Unshort HP main output to HP aux output stage */
1116 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1119 /* Disable HP driver core circuits */
1120 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1123 /* Disable HP driver bias circuits */
1124 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1127 /* Disable HP aux CMFB loop */
1128 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0000);
1130 /* Disable HP aux feedback loop */
1131 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1134 /* Disable HP aux output stage */
1135 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
,
1139 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1140 0x1 << 8, 0x1 << 8);
1142 /* Disable NV regulator (-1.2V) */
1143 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x1, 0x0);
1144 /* Disable cap-less LDOs (1.5V) */
1145 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1148 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
,
1151 /* Increase ESD resistance of AU_REFN */
1152 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
,
1155 /* Set HP CMFB gate rstb */
1156 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1158 /* disable Pull-down HPL/R to AVSS28_AUD */
1159 hp_pull_down(priv
, false);
1164 static int mtk_hp_spk_enable(struct mt6358_priv
*priv
)
1166 /* Pull-down HPL/R to AVSS28_AUD */
1167 hp_pull_down(priv
, true);
1168 /* release HP CMFB gate rstb */
1169 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1170 0x1 << 6, 0x1 << 6);
1172 /* Reduce ESD resistance of AU_REFN */
1173 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
1175 /* Set HPR/HPL gain to -10dB */
1176 regmap_write(priv
->regmap
, MT6358_ZCD_CON2
, DL_GAIN_N_10DB_REG
);
1178 /* Turn on DA_600K_NCP_VA18 */
1179 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
1180 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
1181 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
1182 /* Toggle RG_DIVCKS_CHG */
1183 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
1184 /* Set NCP soft start mode as default mode: 100us */
1185 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
1187 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
1188 usleep_range(250, 270);
1190 /* Enable cap-less LDOs (1.5V) */
1191 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1193 /* Enable NV regulator (-1.2V) */
1194 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
1195 usleep_range(100, 120);
1197 /* Disable AUD_ZCD */
1198 hp_zcd_disable(priv
);
1200 /* Disable headphone short-circuit protection */
1201 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x3000);
1204 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1206 /* Set HP DR bias current optimization, 010: 6uA */
1207 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
1208 /* Set HP & ZCD bias current optimization */
1209 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
1210 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1211 /* Set HPP/N STB enhance circuits */
1212 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4033);
1214 /* Disable Pull-down HPL/R to AVSS28_AUD */
1215 hp_pull_down(priv
, false);
1217 /* Enable HP driver bias circuits */
1218 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30c0);
1219 /* Enable HP driver core circuits */
1220 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f0);
1221 /* Enable HP main CMFB loop */
1222 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0200);
1224 /* Select CMFB resistor bulk to AC mode */
1225 /* Selec HS/LO cap size (6.5pF default) */
1226 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1228 /* Enable HP main output stage */
1229 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x0003);
1230 /* Enable HPR/L main output stage step by step */
1231 hp_main_output_ramp(priv
, true);
1233 /* Set LO gain as minimum (~ -40dB) */
1234 regmap_write(priv
->regmap
, MT6358_ZCD_CON1
, DL_GAIN_N_40DB_REG
);
1235 /* apply volume setting */
1236 headset_volume_ramp(priv
,
1238 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
]);
1240 /* Set LO STB enhance circuits */
1241 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0110);
1242 /* Enable LO driver bias circuits */
1243 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0112);
1244 /* Enable LO driver core circuits */
1245 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x0113);
1247 /* Set LOL gain to normal gain step by step */
1248 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1249 RG_AUDLOLGAIN_MASK_SFT
,
1250 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTL
] <<
1252 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1253 RG_AUDLORGAIN_MASK_SFT
,
1254 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_LINEOUTR
] <<
1257 /* Enable AUD_CLK */
1258 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x1);
1259 /* Enable Audio DAC */
1260 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x30f9);
1261 /* Enable low-noise mode of DAC */
1262 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0201);
1263 /* Switch LOL MUX to audio DAC */
1264 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
, 0x011b);
1265 /* Switch HPL/R MUX to Line-out */
1266 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x35f9);
1271 static int mtk_hp_spk_disable(struct mt6358_priv
*priv
)
1273 /* HPR/HPL mux to open */
1274 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1276 /* LOL mux to open */
1277 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1280 /* Disable Audio DAC */
1281 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1284 /* Disable AUD_CLK */
1285 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
, 0x1, 0x0);
1287 /* decrease HPL/R gain to normal gain step by step */
1288 headset_volume_ramp(priv
,
1289 priv
->ana_gain
[AUDIO_ANALOG_VOLUME_HPOUTL
],
1292 /* decrease LOL gain to minimum gain step by step */
1293 regmap_update_bits(priv
->regmap
, MT6358_ZCD_CON1
,
1294 DL_GAIN_REG_MASK
, DL_GAIN_N_40DB_REG
);
1296 /* decrease HPR/L main output stage step by step */
1297 hp_main_output_ramp(priv
, false);
1299 /* Disable HP main output stage */
1300 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3, 0x0);
1302 /* Short HP main output to HP aux output stage */
1303 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fc3);
1304 /* Enable HP aux output stage */
1305 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fcf);
1307 /* Enable HP aux feedback loop */
1308 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON1
, 0x3fff);
1310 /* Reduce HP aux feedback loop gain */
1311 hp_aux_feedback_loop_gain_ramp(priv
, false);
1313 /* Disable HP driver core circuits */
1314 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1316 /* Disable LO driver core circuits */
1317 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1320 /* Disable HP driver bias circuits */
1321 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1323 /* Disable LO driver bias circuits */
1324 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
1327 /* Disable HP aux CMFB loop */
1328 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1332 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1333 0x1 << 8, 0x1 << 8);
1334 /* Disable NV regulator (-1.2V) */
1335 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x1, 0x0);
1336 /* Disable cap-less LDOs (1.5V) */
1337 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
, 0x1055, 0x0);
1339 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x1, 0x1);
1341 /* Set HP CMFB gate rstb */
1342 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON4
,
1344 /* disable Pull-down HPL/R to AVSS28_AUD */
1345 hp_pull_down(priv
, false);
1350 static int mt_hp_event(struct snd_soc_dapm_widget
*w
,
1351 struct snd_kcontrol
*kcontrol
,
1354 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1355 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1356 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1357 int device
= DEVICE_HP
;
1359 dev_info(priv
->dev
, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
1362 priv
->dev_counter
[device
],
1366 case SND_SOC_DAPM_PRE_PMU
:
1367 priv
->dev_counter
[device
]++;
1368 if (priv
->dev_counter
[device
] > 1)
1369 break; /* already enabled, do nothing */
1370 else if (priv
->dev_counter
[device
] <= 0)
1371 dev_warn(priv
->dev
, "%s(), dev_counter[DEV_HP] %d <= 0\n",
1373 priv
->dev_counter
[device
]);
1375 priv
->mux_select
[MUX_HP_L
] = mux
;
1377 if (mux
== HP_MUX_HP
)
1378 mtk_hp_enable(priv
);
1379 else if (mux
== HP_MUX_HPSPK
)
1380 mtk_hp_spk_enable(priv
);
1382 case SND_SOC_DAPM_PRE_PMD
:
1383 priv
->dev_counter
[device
]--;
1384 if (priv
->dev_counter
[device
] > 0) {
1385 break; /* still being used, don't close */
1386 } else if (priv
->dev_counter
[device
] < 0) {
1387 dev_warn(priv
->dev
, "%s(), dev_counter[DEV_HP] %d < 0\n",
1389 priv
->dev_counter
[device
]);
1390 priv
->dev_counter
[device
] = 0;
1394 if (priv
->mux_select
[MUX_HP_L
] == HP_MUX_HP
)
1395 mtk_hp_disable(priv
);
1396 else if (priv
->mux_select
[MUX_HP_L
] == HP_MUX_HPSPK
)
1397 mtk_hp_spk_disable(priv
);
1399 priv
->mux_select
[MUX_HP_L
] = mux
;
1408 static int mt_rcv_event(struct snd_soc_dapm_widget
*w
,
1409 struct snd_kcontrol
*kcontrol
,
1412 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1413 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1415 dev_info(priv
->dev
, "%s(), event 0x%x, mux %u\n",
1418 dapm_kcontrol_get_value(w
->kcontrols
[0]));
1421 case SND_SOC_DAPM_PRE_PMU
:
1422 /* Reduce ESD resistance of AU_REFN */
1423 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON2
, 0x4000);
1425 /* Turn on DA_600K_NCP_VA18 */
1426 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON1
, 0x0001);
1427 /* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
1428 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON2
, 0x002c);
1429 /* Toggle RG_DIVCKS_CHG */
1430 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON0
, 0x0001);
1431 /* Set NCP soft start mode as default mode: 100us */
1432 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON4
, 0x0003);
1434 regmap_write(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
, 0x0000);
1435 usleep_range(250, 270);
1437 /* Enable cap-less LDOs (1.5V) */
1438 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1440 /* Enable NV regulator (-1.2V) */
1441 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
, 0x0001);
1442 usleep_range(100, 120);
1444 /* Disable AUD_ZCD */
1445 hp_zcd_disable(priv
);
1447 /* Disable handset short-circuit protection */
1448 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0010);
1451 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1452 /* Set HP DR bias current optimization, 010: 6uA */
1453 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON11
, 0x4900);
1454 /* Set HP & ZCD bias current optimization */
1455 /* 01: ZCD: 4uA, HP/HS/LO: 5uA */
1456 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
, 0x0055);
1457 /* Set HS STB enhance circuits */
1458 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0090);
1460 /* Disable HP main CMFB loop */
1461 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0000);
1462 /* Select CMFB resistor bulk to AC mode */
1463 /* Selec HS/LO cap size (6.5pF default) */
1464 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON10
, 0x0000);
1466 /* Enable HS driver bias circuits */
1467 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0092);
1468 /* Enable HS driver core circuits */
1469 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x0093);
1471 /* Enable AUD_CLK */
1472 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1475 /* Enable Audio DAC */
1476 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
, 0x0009);
1477 /* Enable low-noise mode of DAC */
1478 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
, 0x0001);
1479 /* Switch HS MUX to audio DAC */
1480 regmap_write(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
, 0x009b);
1482 case SND_SOC_DAPM_PRE_PMD
:
1483 /* HS mux to open */
1484 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1485 RG_AUDHSMUXINPUTSEL_VAUDP15_MASK_SFT
,
1488 /* Disable Audio DAC */
1489 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
1492 /* Disable AUD_CLK */
1493 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1496 /* decrease HS gain to minimum gain step by step */
1497 regmap_write(priv
->regmap
, MT6358_ZCD_CON3
, DL_GAIN_N_40DB
);
1499 /* Disable HS driver core circuits */
1500 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1503 /* Disable HS driver bias circuits */
1504 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
1507 /* Disable HP aux CMFB loop */
1508 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1511 /* Enable HP main CMFB Switch */
1512 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON9
,
1513 0xff << 8, 0x2 << 8);
1516 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON12
,
1517 0x1 << 8, 0x1 << 8);
1519 /* Disable NV regulator (-1.2V) */
1520 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON15
,
1522 /* Disable cap-less LDOs (1.5V) */
1523 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1526 regmap_update_bits(priv
->regmap
, MT6358_AUDNCP_CLKDIV_CON3
,
1536 static int mt_aif_out_event(struct snd_soc_dapm_widget
*w
,
1537 struct snd_kcontrol
*kcontrol
,
1540 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1541 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1543 dev_dbg(priv
->dev
, "%s(), event 0x%x, rate %d\n",
1544 __func__
, event
, priv
->ul_rate
);
1547 case SND_SOC_DAPM_PRE_PMU
:
1548 capture_gpio_set(priv
);
1550 case SND_SOC_DAPM_POST_PMD
:
1551 capture_gpio_reset(priv
);
1560 static int mt_adc_supply_event(struct snd_soc_dapm_widget
*w
,
1561 struct snd_kcontrol
*kcontrol
,
1564 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1565 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1567 dev_dbg(priv
->dev
, "%s(), event 0x%x\n",
1571 case SND_SOC_DAPM_PRE_PMU
:
1572 /* Enable audio ADC CLKGEN */
1573 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1574 0x1 << 5, 0x1 << 5);
1575 /* ADC CLK from CLKGEN (13MHz) */
1576 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON3
,
1578 /* Enable LCLDO_ENC 1P8V */
1579 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1581 /* LCLDO_ENC remote sense */
1582 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1585 case SND_SOC_DAPM_POST_PMD
:
1586 /* LCLDO_ENC remote sense off */
1587 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1589 /* disable LCLDO_ENC 1P8V */
1590 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON14
,
1593 /* ADC CLK from CLKGEN (13MHz) */
1594 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON3
, 0x0000);
1595 /* disable audio ADC CLKGEN */
1596 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON13
,
1597 0x1 << 5, 0x0 << 5);
1606 static int mt6358_amic_enable(struct mt6358_priv
*priv
)
1608 unsigned int mic_type
= priv
->mux_select
[MUX_MIC_TYPE
];
1609 unsigned int mux_pga_l
= priv
->mux_select
[MUX_PGA_L
];
1610 unsigned int mux_pga_r
= priv
->mux_select
[MUX_PGA_R
];
1612 dev_info(priv
->dev
, "%s(), mux, mic %u, pga l %u, pga r %u\n",
1613 __func__
, mic_type
, mux_pga_l
, mux_pga_r
);
1615 if (IS_DCC_BASE(mic_type
)) {
1616 /* DCC 50k CLK (from 26M) */
1617 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1618 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1619 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2060);
1620 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2061);
1621 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG1
, 0x0100);
1625 if (mux_pga_l
== PGA_MUX_AIN0
|| mux_pga_l
== PGA_MUX_AIN2
||
1626 mux_pga_r
== PGA_MUX_AIN0
|| mux_pga_r
== PGA_MUX_AIN2
) {
1628 case MIC_TYPE_MUX_DCC_ECM_DIFF
:
1629 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1632 case MIC_TYPE_MUX_DCC_ECM_SINGLE
:
1633 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1637 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1641 /* Enable MICBIAS0, MISBIAS0 = 1P9V */
1642 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON9
,
1647 if (mux_pga_l
== PGA_MUX_AIN1
|| mux_pga_r
== PGA_MUX_AIN1
) {
1648 /* Enable MICBIAS1, MISBIAS1 = 2P6V */
1649 if (mic_type
== MIC_TYPE_MUX_DCC_ECM_SINGLE
)
1650 regmap_write(priv
->regmap
,
1651 MT6358_AUDENC_ANA_CON10
, 0x0161);
1653 regmap_write(priv
->regmap
,
1654 MT6358_AUDENC_ANA_CON10
, 0x0061);
1657 if (IS_DCC_BASE(mic_type
)) {
1658 /* Audio L/R preamplifier DCC precharge */
1659 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1661 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1665 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1667 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1671 if (mux_pga_l
!= PGA_MUX_NONE
) {
1672 /* L preamplifier input sel */
1673 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1674 RG_AUDPREAMPLINPUTSEL_MASK_SFT
,
1675 mux_pga_l
<< RG_AUDPREAMPLINPUTSEL_SFT
);
1677 /* L preamplifier enable */
1678 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1679 RG_AUDPREAMPLON_MASK_SFT
,
1680 0x1 << RG_AUDPREAMPLON_SFT
);
1682 if (IS_DCC_BASE(mic_type
)) {
1683 /* L preamplifier DCCEN */
1684 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1685 RG_AUDPREAMPLDCCEN_MASK_SFT
,
1686 0x1 << RG_AUDPREAMPLDCCEN_SFT
);
1689 /* L ADC input sel : L PGA. Enable audio L ADC */
1690 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1691 RG_AUDADCLINPUTSEL_MASK_SFT
,
1692 ADC_MUX_PREAMPLIFIER
<<
1693 RG_AUDADCLINPUTSEL_SFT
);
1694 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1695 RG_AUDADCLPWRUP_MASK_SFT
,
1696 0x1 << RG_AUDADCLPWRUP_SFT
);
1699 if (mux_pga_r
!= PGA_MUX_NONE
) {
1700 /* R preamplifier input sel */
1701 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1702 RG_AUDPREAMPRINPUTSEL_MASK_SFT
,
1703 mux_pga_r
<< RG_AUDPREAMPRINPUTSEL_SFT
);
1705 /* R preamplifier enable */
1706 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1707 RG_AUDPREAMPRON_MASK_SFT
,
1708 0x1 << RG_AUDPREAMPRON_SFT
);
1710 if (IS_DCC_BASE(mic_type
)) {
1711 /* R preamplifier DCCEN */
1712 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1713 RG_AUDPREAMPRDCCEN_MASK_SFT
,
1714 0x1 << RG_AUDPREAMPRDCCEN_SFT
);
1717 /* R ADC input sel : R PGA. Enable audio R ADC */
1718 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1719 RG_AUDADCRINPUTSEL_MASK_SFT
,
1720 ADC_MUX_PREAMPLIFIER
<<
1721 RG_AUDADCRINPUTSEL_SFT
);
1722 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1723 RG_AUDADCRPWRUP_MASK_SFT
,
1724 0x1 << RG_AUDADCRPWRUP_SFT
);
1727 if (IS_DCC_BASE(mic_type
)) {
1728 usleep_range(100, 150);
1729 /* Audio L preamplifier DCC precharge off */
1730 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1731 RG_AUDPREAMPLDCPRECHARGE_MASK_SFT
, 0x0);
1732 /* Audio R preamplifier DCC precharge off */
1733 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1734 RG_AUDPREAMPRDCPRECHARGE_MASK_SFT
, 0x0);
1736 /* Short body to ground in PGA */
1737 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON3
,
1741 /* here to set digital part */
1742 mt6358_mtkaif_tx_enable(priv
);
1744 /* UL dmic setting off */
1745 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_H
, 0x0000);
1748 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
, 0x0001);
1753 static void mt6358_amic_disable(struct mt6358_priv
*priv
)
1755 unsigned int mic_type
= priv
->mux_select
[MUX_MIC_TYPE
];
1756 unsigned int mux_pga_l
= priv
->mux_select
[MUX_PGA_L
];
1757 unsigned int mux_pga_r
= priv
->mux_select
[MUX_PGA_R
];
1759 dev_info(priv
->dev
, "%s(), mux, mic %u, pga l %u, pga r %u\n",
1760 __func__
, mic_type
, mux_pga_l
, mux_pga_r
);
1763 regmap_update_bits(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
,
1766 /* disable aud_pad TX fifos */
1767 mt6358_mtkaif_tx_disable(priv
);
1769 /* L ADC input sel : off, disable L ADC */
1770 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1772 /* L preamplifier DCCEN */
1773 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1775 /* L preamplifier input sel : off, L PGA 0 dB gain */
1776 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1779 /* disable L preamplifier DCC precharge */
1780 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1783 /* R ADC input sel : off, disable R ADC */
1784 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1786 /* R preamplifier DCCEN */
1787 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1789 /* R preamplifier input sel : off, R PGA 0 dB gain */
1790 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1793 /* disable R preamplifier DCC precharge */
1794 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1798 /* Disable MICBIAS0, MISBIAS0 = 1P7V */
1799 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0000);
1801 /* Disable MICBIAS1 */
1802 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1805 if (IS_DCC_BASE(mic_type
)) {
1806 /* dcclk_gen_on=1'b0 */
1807 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2060);
1808 /* dcclk_pdn=1'b1 */
1809 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1810 /* dcclk_ref_ck_sel=2'b00 */
1811 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1812 /* dcclk_div=11'b00100000011 */
1813 regmap_write(priv
->regmap
, MT6358_AFE_DCCLK_CFG0
, 0x2062);
1817 static int mt6358_dmic_enable(struct mt6358_priv
*priv
)
1819 dev_info(priv
->dev
, "%s()\n", __func__
);
1822 /* Enable MICBIAS0, MISBIAS0 = 1P9V */
1823 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0021);
1825 /* RG_BANDGAPGEN=1'b0 */
1826 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1830 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON8
, 0x0005);
1832 /* here to set digital part */
1833 mt6358_mtkaif_tx_enable(priv
);
1835 /* UL dmic setting */
1836 if (priv
->dmic_one_wire_mode
)
1837 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_H
, 0x0400);
1839 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_H
, 0x0080);
1842 regmap_write(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
, 0x0003);
1844 /* Prevent pop noise form dmic hw */
1850 static void mt6358_dmic_disable(struct mt6358_priv
*priv
)
1852 dev_info(priv
->dev
, "%s()\n", __func__
);
1855 regmap_update_bits(priv
->regmap
, MT6358_AFE_UL_SRC_CON0_L
,
1858 /* disable aud_pad TX fifos */
1859 mt6358_mtkaif_tx_disable(priv
);
1862 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON8
, 0x0000);
1865 /* MISBIAS0 = 1P7V */
1866 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0001);
1868 /* RG_BANDGAPGEN=1'b0 */
1869 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON10
,
1872 /* MICBIA0 disable */
1873 regmap_write(priv
->regmap
, MT6358_AUDENC_ANA_CON9
, 0x0000);
1876 static void mt6358_restore_pga(struct mt6358_priv
*priv
)
1878 unsigned int gain_l
, gain_r
;
1880 gain_l
= priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP1
];
1881 gain_r
= priv
->ana_gain
[AUDIO_ANALOG_VOLUME_MICAMP2
];
1883 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON0
,
1884 RG_AUDPREAMPLGAIN_MASK_SFT
,
1885 gain_l
<< RG_AUDPREAMPLGAIN_SFT
);
1886 regmap_update_bits(priv
->regmap
, MT6358_AUDENC_ANA_CON1
,
1887 RG_AUDPREAMPRGAIN_MASK_SFT
,
1888 gain_r
<< RG_AUDPREAMPRGAIN_SFT
);
1891 static int mt_mic_type_event(struct snd_soc_dapm_widget
*w
,
1892 struct snd_kcontrol
*kcontrol
,
1895 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1896 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1897 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1899 dev_dbg(priv
->dev
, "%s(), event 0x%x, mux %u\n",
1900 __func__
, event
, mux
);
1903 case SND_SOC_DAPM_WILL_PMU
:
1904 priv
->mux_select
[MUX_MIC_TYPE
] = mux
;
1906 case SND_SOC_DAPM_PRE_PMU
:
1908 case MIC_TYPE_MUX_DMIC
:
1909 mt6358_dmic_enable(priv
);
1912 mt6358_amic_enable(priv
);
1915 mt6358_restore_pga(priv
);
1918 case SND_SOC_DAPM_POST_PMD
:
1919 switch (priv
->mux_select
[MUX_MIC_TYPE
]) {
1920 case MIC_TYPE_MUX_DMIC
:
1921 mt6358_dmic_disable(priv
);
1924 mt6358_amic_disable(priv
);
1928 priv
->mux_select
[MUX_MIC_TYPE
] = mux
;
1937 static int mt_adc_l_event(struct snd_soc_dapm_widget
*w
,
1938 struct snd_kcontrol
*kcontrol
,
1941 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1942 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1943 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1945 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1946 __func__
, event
, mux
);
1948 priv
->mux_select
[MUX_ADC_L
] = mux
;
1953 static int mt_adc_r_event(struct snd_soc_dapm_widget
*w
,
1954 struct snd_kcontrol
*kcontrol
,
1957 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1958 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1959 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1961 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1962 __func__
, event
, mux
);
1964 priv
->mux_select
[MUX_ADC_R
] = mux
;
1969 static int mt_pga_left_event(struct snd_soc_dapm_widget
*w
,
1970 struct snd_kcontrol
*kcontrol
,
1973 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1974 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1975 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1977 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1978 __func__
, event
, mux
);
1980 priv
->mux_select
[MUX_PGA_L
] = mux
;
1985 static int mt_pga_right_event(struct snd_soc_dapm_widget
*w
,
1986 struct snd_kcontrol
*kcontrol
,
1989 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
1990 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
1991 unsigned int mux
= dapm_kcontrol_get_value(w
->kcontrols
[0]);
1993 dev_dbg(priv
->dev
, "%s(), event = 0x%x, mux %u\n",
1994 __func__
, event
, mux
);
1996 priv
->mux_select
[MUX_PGA_R
] = mux
;
2001 static int mt_delay_250_event(struct snd_soc_dapm_widget
*w
,
2002 struct snd_kcontrol
*kcontrol
,
2006 case SND_SOC_DAPM_POST_PMU
:
2007 usleep_range(250, 270);
2009 case SND_SOC_DAPM_PRE_PMD
:
2010 usleep_range(250, 270);
2020 static const struct snd_soc_dapm_widget mt6358_dapm_widgets
[] = {
2022 SND_SOC_DAPM_SUPPLY_S("CLK_BUF", SUPPLY_SEQ_CLK_BUF
,
2024 RG_XO_AUDIO_EN_M_SFT
, 0, NULL
, 0),
2025 SND_SOC_DAPM_SUPPLY_S("AUDGLB", SUPPLY_SEQ_AUD_GLB
,
2026 MT6358_AUDDEC_ANA_CON13
,
2027 RG_AUDGLB_PWRDN_VA28_SFT
, 1, NULL
, 0),
2028 SND_SOC_DAPM_SUPPLY_S("CLKSQ Audio", SUPPLY_SEQ_CLKSQ
,
2029 MT6358_AUDENC_ANA_CON6
,
2032 SND_SOC_DAPM_PRE_PMU
),
2033 SND_SOC_DAPM_SUPPLY_S("AUDNCP_CK", SUPPLY_SEQ_TOP_CK
,
2034 MT6358_AUD_TOP_CKPDN_CON0
,
2035 RG_AUDNCP_CK_PDN_SFT
, 1, NULL
, 0),
2036 SND_SOC_DAPM_SUPPLY_S("ZCD13M_CK", SUPPLY_SEQ_TOP_CK
,
2037 MT6358_AUD_TOP_CKPDN_CON0
,
2038 RG_ZCD13M_CK_PDN_SFT
, 1, NULL
, 0),
2039 SND_SOC_DAPM_SUPPLY_S("AUD_CK", SUPPLY_SEQ_TOP_CK_LAST
,
2040 MT6358_AUD_TOP_CKPDN_CON0
,
2041 RG_AUD_CK_PDN_SFT
, 1,
2043 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
2044 SND_SOC_DAPM_SUPPLY_S("AUDIF_CK", SUPPLY_SEQ_TOP_CK
,
2045 MT6358_AUD_TOP_CKPDN_CON0
,
2046 RG_AUDIF_CK_PDN_SFT
, 1, NULL
, 0),
2049 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_AFE_CTL", SUPPLY_SEQ_AUD_TOP_LAST
,
2050 MT6358_AUDIO_TOP_CON0
,
2053 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
2054 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_DAC_CTL", SUPPLY_SEQ_AUD_TOP
,
2055 MT6358_AUDIO_TOP_CON0
,
2056 PDN_DAC_CTL_SFT
, 1, NULL
, 0),
2057 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_ADC_CTL", SUPPLY_SEQ_AUD_TOP
,
2058 MT6358_AUDIO_TOP_CON0
,
2059 PDN_ADC_CTL_SFT
, 1, NULL
, 0),
2060 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_I2S_DL", SUPPLY_SEQ_AUD_TOP
,
2061 MT6358_AUDIO_TOP_CON0
,
2062 PDN_I2S_DL_CTL_SFT
, 1, NULL
, 0),
2063 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PWR_CLK", SUPPLY_SEQ_AUD_TOP
,
2064 MT6358_AUDIO_TOP_CON0
,
2065 PWR_CLK_DIS_CTL_SFT
, 1, NULL
, 0),
2066 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_AFE_TESTMODEL", SUPPLY_SEQ_AUD_TOP
,
2067 MT6358_AUDIO_TOP_CON0
,
2068 PDN_AFE_TESTMODEL_CTL_SFT
, 1, NULL
, 0),
2069 SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_RESERVED", SUPPLY_SEQ_AUD_TOP
,
2070 MT6358_AUDIO_TOP_CON0
,
2071 PDN_RESERVED_SFT
, 1, NULL
, 0),
2073 SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM
,
2077 SND_SOC_DAPM_SUPPLY_S("AFE_ON", SUPPLY_SEQ_AFE
,
2078 MT6358_AFE_UL_DL_CON0
, AFE_ON_SFT
, 0,
2082 SND_SOC_DAPM_AIF_IN_E("AIF_RX", "AIF1 Playback", 0,
2083 MT6358_AFE_DL_SRC2_CON0_L
,
2084 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0,
2086 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2089 SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM
,
2093 SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM
, 0, 0, &dac_in_mux_control
),
2095 SND_SOC_DAPM_DAC("DACL", NULL
, SND_SOC_NOPM
, 0, 0),
2097 SND_SOC_DAPM_DAC("DACR", NULL
, SND_SOC_NOPM
, 0, 0),
2100 SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM
, 0, 0, &lo_in_mux_control
),
2102 SND_SOC_DAPM_SUPPLY("LO Stability Enh", MT6358_AUDDEC_ANA_CON7
,
2103 RG_LOOUTPUTSTBENH_VAUDP15_SFT
, 0, NULL
, 0),
2105 SND_SOC_DAPM_OUT_DRV("LOL Buffer", MT6358_AUDDEC_ANA_CON7
,
2106 RG_AUDLOLPWRUP_VAUDP15_SFT
, 0, NULL
, 0),
2109 SND_SOC_DAPM_MUX_E("HPL Mux", SND_SOC_NOPM
, 0, 0,
2110 &hpl_in_mux_control
,
2112 SND_SOC_DAPM_PRE_PMU
|
2113 SND_SOC_DAPM_PRE_PMD
),
2115 SND_SOC_DAPM_MUX_E("HPR Mux", SND_SOC_NOPM
, 0, 0,
2116 &hpr_in_mux_control
,
2118 SND_SOC_DAPM_PRE_PMU
|
2119 SND_SOC_DAPM_PRE_PMD
),
2122 SND_SOC_DAPM_MUX_E("RCV Mux", SND_SOC_NOPM
, 0, 0,
2123 &rcv_in_mux_control
,
2125 SND_SOC_DAPM_PRE_PMU
|
2126 SND_SOC_DAPM_PRE_PMD
),
2129 SND_SOC_DAPM_OUTPUT("Receiver"),
2130 SND_SOC_DAPM_OUTPUT("Headphone L"),
2131 SND_SOC_DAPM_OUTPUT("Headphone R"),
2132 SND_SOC_DAPM_OUTPUT("Headphone L Ext Spk Amp"),
2133 SND_SOC_DAPM_OUTPUT("Headphone R Ext Spk Amp"),
2134 SND_SOC_DAPM_OUTPUT("LINEOUT L"),
2135 SND_SOC_DAPM_OUTPUT("LINEOUT L HSSPK"),
2138 SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6358_AFE_SGEN_CFG0
,
2139 SGEN_DAC_EN_CTL_SFT
, 0, NULL
, 0),
2140 SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6358_AFE_SGEN_CFG0
,
2141 SGEN_MUTE_SW_CTL_SFT
, 1,
2143 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2144 SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6358_AFE_DL_SRC2_CON0_L
,
2145 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0, NULL
, 0),
2147 SND_SOC_DAPM_INPUT("SGEN DL"),
2150 SND_SOC_DAPM_AIF_OUT_E("AIF1TX", "AIF1 Capture", 0,
2153 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2155 SND_SOC_DAPM_SUPPLY_S("ADC Supply", SUPPLY_SEQ_ADC_SUPPLY
,
2157 mt_adc_supply_event
,
2158 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
2161 SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM
, 0, 0,
2162 &aif_out_mux_control
),
2164 SND_SOC_DAPM_MUX_E("Mic Type Mux", SND_SOC_NOPM
, 0, 0,
2165 &mic_type_mux_control
,
2167 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
|
2168 SND_SOC_DAPM_WILL_PMU
),
2170 SND_SOC_DAPM_MUX_E("ADC L Mux", SND_SOC_NOPM
, 0, 0,
2171 &adc_left_mux_control
,
2173 SND_SOC_DAPM_WILL_PMU
),
2174 SND_SOC_DAPM_MUX_E("ADC R Mux", SND_SOC_NOPM
, 0, 0,
2175 &adc_right_mux_control
,
2177 SND_SOC_DAPM_WILL_PMU
),
2179 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
2180 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
2182 SND_SOC_DAPM_MUX_E("PGA L Mux", SND_SOC_NOPM
, 0, 0,
2183 &pga_left_mux_control
,
2185 SND_SOC_DAPM_WILL_PMU
),
2186 SND_SOC_DAPM_MUX_E("PGA R Mux", SND_SOC_NOPM
, 0, 0,
2187 &pga_right_mux_control
,
2189 SND_SOC_DAPM_WILL_PMU
),
2191 SND_SOC_DAPM_PGA("PGA L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2192 SND_SOC_DAPM_PGA("PGA R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2195 SND_SOC_DAPM_INPUT("AIN0"),
2196 SND_SOC_DAPM_INPUT("AIN1"),
2197 SND_SOC_DAPM_INPUT("AIN2"),
2200 static const struct snd_soc_dapm_route mt6358_dapm_routes
[] = {
2202 {"AIF1TX", NULL
, "AIF Out Mux"},
2203 {"AIF1TX", NULL
, "CLK_BUF"},
2204 {"AIF1TX", NULL
, "AUDGLB"},
2205 {"AIF1TX", NULL
, "CLKSQ Audio"},
2207 {"AIF1TX", NULL
, "AUD_CK"},
2208 {"AIF1TX", NULL
, "AUDIF_CK"},
2210 {"AIF1TX", NULL
, "AUDIO_TOP_AFE_CTL"},
2211 {"AIF1TX", NULL
, "AUDIO_TOP_ADC_CTL"},
2212 {"AIF1TX", NULL
, "AUDIO_TOP_PWR_CLK"},
2213 {"AIF1TX", NULL
, "AUDIO_TOP_PDN_RESERVED"},
2214 {"AIF1TX", NULL
, "AUDIO_TOP_I2S_DL"},
2216 {"AIF1TX", NULL
, "AFE_ON"},
2218 {"AIF Out Mux", NULL
, "Mic Type Mux"},
2220 {"Mic Type Mux", "ACC", "ADC L"},
2221 {"Mic Type Mux", "ACC", "ADC R"},
2222 {"Mic Type Mux", "DCC", "ADC L"},
2223 {"Mic Type Mux", "DCC", "ADC R"},
2224 {"Mic Type Mux", "DCC_ECM_DIFF", "ADC L"},
2225 {"Mic Type Mux", "DCC_ECM_DIFF", "ADC R"},
2226 {"Mic Type Mux", "DCC_ECM_SINGLE", "ADC L"},
2227 {"Mic Type Mux", "DCC_ECM_SINGLE", "ADC R"},
2228 {"Mic Type Mux", "DMIC", "AIN0"},
2229 {"Mic Type Mux", "DMIC", "AIN2"},
2231 {"ADC L", NULL
, "ADC L Mux"},
2232 {"ADC L", NULL
, "ADC Supply"},
2233 {"ADC R", NULL
, "ADC R Mux"},
2234 {"ADC R", NULL
, "ADC Supply"},
2236 {"ADC L Mux", "Left Preamplifier", "PGA L"},
2238 {"ADC R Mux", "Right Preamplifier", "PGA R"},
2240 {"PGA L", NULL
, "PGA L Mux"},
2241 {"PGA R", NULL
, "PGA R Mux"},
2243 {"PGA L Mux", "AIN0", "AIN0"},
2244 {"PGA L Mux", "AIN1", "AIN1"},
2245 {"PGA L Mux", "AIN2", "AIN2"},
2247 {"PGA R Mux", "AIN0", "AIN0"},
2248 {"PGA R Mux", "AIN1", "AIN1"},
2249 {"PGA R Mux", "AIN2", "AIN2"},
2252 {"DL Power Supply", NULL
, "CLK_BUF"},
2253 {"DL Power Supply", NULL
, "AUDGLB"},
2254 {"DL Power Supply", NULL
, "CLKSQ Audio"},
2256 {"DL Power Supply", NULL
, "AUDNCP_CK"},
2257 {"DL Power Supply", NULL
, "ZCD13M_CK"},
2258 {"DL Power Supply", NULL
, "AUD_CK"},
2259 {"DL Power Supply", NULL
, "AUDIF_CK"},
2261 /* DL Digital Supply */
2262 {"DL Digital Clock", NULL
, "AUDIO_TOP_AFE_CTL"},
2263 {"DL Digital Clock", NULL
, "AUDIO_TOP_DAC_CTL"},
2264 {"DL Digital Clock", NULL
, "AUDIO_TOP_PWR_CLK"},
2266 {"DL Digital Clock", NULL
, "AFE_ON"},
2268 {"AIF_RX", NULL
, "DL Digital Clock"},
2271 {"DAC In Mux", "Normal Path", "AIF_RX"},
2273 {"DAC In Mux", "Sgen", "SGEN DL"},
2274 {"SGEN DL", NULL
, "SGEN DL SRC"},
2275 {"SGEN DL", NULL
, "SGEN MUTE"},
2276 {"SGEN DL", NULL
, "SGEN DL Enable"},
2277 {"SGEN DL", NULL
, "DL Digital Clock"},
2278 {"SGEN DL", NULL
, "AUDIO_TOP_PDN_AFE_TESTMODEL"},
2280 {"DACL", NULL
, "DAC In Mux"},
2281 {"DACL", NULL
, "DL Power Supply"},
2283 {"DACR", NULL
, "DAC In Mux"},
2284 {"DACR", NULL
, "DL Power Supply"},
2287 {"LOL Mux", "Playback", "DACL"},
2289 {"LOL Buffer", NULL
, "LOL Mux"},
2290 {"LOL Buffer", NULL
, "LO Stability Enh"},
2292 {"LINEOUT L", NULL
, "LOL Buffer"},
2294 /* Headphone Path */
2295 {"HPL Mux", "Audio Playback", "DACL"},
2296 {"HPR Mux", "Audio Playback", "DACR"},
2297 {"HPL Mux", "HP Impedance", "DACL"},
2298 {"HPR Mux", "HP Impedance", "DACR"},
2299 {"HPL Mux", "LoudSPK Playback", "DACL"},
2300 {"HPR Mux", "LoudSPK Playback", "DACR"},
2302 {"Headphone L", NULL
, "HPL Mux"},
2303 {"Headphone R", NULL
, "HPR Mux"},
2304 {"Headphone L Ext Spk Amp", NULL
, "HPL Mux"},
2305 {"Headphone R Ext Spk Amp", NULL
, "HPR Mux"},
2306 {"LINEOUT L HSSPK", NULL
, "HPL Mux"},
2309 {"RCV Mux", "Voice Playback", "DACL"},
2310 {"Receiver", NULL
, "RCV Mux"},
2313 static int mt6358_codec_dai_hw_params(struct snd_pcm_substream
*substream
,
2314 struct snd_pcm_hw_params
*params
,
2315 struct snd_soc_dai
*dai
)
2317 struct snd_soc_component
*cmpnt
= dai
->component
;
2318 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
2319 unsigned int rate
= params_rate(params
);
2321 dev_info(priv
->dev
, "%s(), substream->stream %d, rate %d, number %d\n",
2327 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2328 priv
->dl_rate
= rate
;
2329 else if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2330 priv
->ul_rate
= rate
;
2335 static const struct snd_soc_dai_ops mt6358_codec_dai_ops
= {
2336 .hw_params
= mt6358_codec_dai_hw_params
,
2339 #define MT6358_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
2340 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
2341 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
2342 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
2343 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
2344 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)
2346 static struct snd_soc_dai_driver mt6358_dai_driver
[] = {
2348 .name
= "mt6358-snd-codec-aif1",
2350 .stream_name
= "AIF1 Playback",
2353 .rates
= SNDRV_PCM_RATE_8000_48000
|
2354 SNDRV_PCM_RATE_96000
|
2355 SNDRV_PCM_RATE_192000
,
2356 .formats
= MT6358_FORMATS
,
2359 .stream_name
= "AIF1 Capture",
2362 .rates
= SNDRV_PCM_RATE_8000
|
2363 SNDRV_PCM_RATE_16000
|
2364 SNDRV_PCM_RATE_32000
|
2365 SNDRV_PCM_RATE_48000
,
2366 .formats
= MT6358_FORMATS
,
2368 .ops
= &mt6358_codec_dai_ops
,
2372 static void mt6358_codec_init_reg(struct mt6358_priv
*priv
)
2374 /* Disable HeadphoneL/HeadphoneR short circuit protection */
2375 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
2376 RG_AUDHPLSCDISABLE_VAUDP15_MASK_SFT
,
2377 0x1 << RG_AUDHPLSCDISABLE_VAUDP15_SFT
);
2378 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON0
,
2379 RG_AUDHPRSCDISABLE_VAUDP15_MASK_SFT
,
2380 0x1 << RG_AUDHPRSCDISABLE_VAUDP15_SFT
);
2381 /* Disable voice short circuit protection */
2382 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON6
,
2383 RG_AUDHSSCDISABLE_VAUDP15_MASK_SFT
,
2384 0x1 << RG_AUDHSSCDISABLE_VAUDP15_SFT
);
2385 /* disable LO buffer left short circuit protection */
2386 regmap_update_bits(priv
->regmap
, MT6358_AUDDEC_ANA_CON7
,
2387 RG_AUDLOLSCDISABLE_VAUDP15_MASK_SFT
,
2388 0x1 << RG_AUDLOLSCDISABLE_VAUDP15_SFT
);
2390 /* accdet s/w enable */
2391 regmap_update_bits(priv
->regmap
, MT6358_ACCDET_CON13
,
2394 /* gpio miso driving set to 4mA */
2395 regmap_write(priv
->regmap
, MT6358_DRV_CON3
, 0x8888);
2398 playback_gpio_reset(priv
);
2399 capture_gpio_reset(priv
);
2402 static int mt6358_codec_probe(struct snd_soc_component
*cmpnt
)
2404 struct mt6358_priv
*priv
= snd_soc_component_get_drvdata(cmpnt
);
2407 snd_soc_component_init_regmap(cmpnt
, priv
->regmap
);
2409 mt6358_codec_init_reg(priv
);
2411 priv
->avdd_reg
= devm_regulator_get(priv
->dev
, "Avdd");
2412 if (IS_ERR(priv
->avdd_reg
)) {
2413 dev_err(priv
->dev
, "%s() have no Avdd supply", __func__
);
2414 return PTR_ERR(priv
->avdd_reg
);
2417 ret
= regulator_enable(priv
->avdd_reg
);
2424 static const struct snd_soc_component_driver mt6358_soc_component_driver
= {
2425 .probe
= mt6358_codec_probe
,
2426 .controls
= mt6358_snd_controls
,
2427 .num_controls
= ARRAY_SIZE(mt6358_snd_controls
),
2428 .dapm_widgets
= mt6358_dapm_widgets
,
2429 .num_dapm_widgets
= ARRAY_SIZE(mt6358_dapm_widgets
),
2430 .dapm_routes
= mt6358_dapm_routes
,
2431 .num_dapm_routes
= ARRAY_SIZE(mt6358_dapm_routes
),
2434 static void mt6358_parse_dt(struct mt6358_priv
*priv
)
2437 struct device
*dev
= priv
->dev
;
2439 ret
= of_property_read_u32(dev
->of_node
, "mediatek,dmic-mode",
2440 &priv
->dmic_one_wire_mode
);
2442 dev_warn(priv
->dev
, "%s() failed to read dmic-mode\n",
2444 priv
->dmic_one_wire_mode
= 0;
2448 static int mt6358_platform_driver_probe(struct platform_device
*pdev
)
2450 struct mt6358_priv
*priv
;
2451 struct mt6397_chip
*mt6397
= dev_get_drvdata(pdev
->dev
.parent
);
2453 priv
= devm_kzalloc(&pdev
->dev
,
2454 sizeof(struct mt6358_priv
),
2459 dev_set_drvdata(&pdev
->dev
, priv
);
2461 priv
->dev
= &pdev
->dev
;
2463 priv
->regmap
= mt6397
->regmap
;
2464 if (IS_ERR(priv
->regmap
))
2465 return PTR_ERR(priv
->regmap
);
2467 mt6358_parse_dt(priv
);
2469 dev_info(priv
->dev
, "%s(), dev name %s\n",
2470 __func__
, dev_name(&pdev
->dev
));
2472 return devm_snd_soc_register_component(&pdev
->dev
,
2473 &mt6358_soc_component_driver
,
2475 ARRAY_SIZE(mt6358_dai_driver
));
2478 static const struct of_device_id mt6358_of_match
[] = {
2479 {.compatible
= "mediatek,mt6358-sound",},
2482 MODULE_DEVICE_TABLE(of
, mt6358_of_match
);
2484 static struct platform_driver mt6358_platform_driver
= {
2486 .name
= "mt6358-sound",
2487 .of_match_table
= mt6358_of_match
,
2489 .probe
= mt6358_platform_driver_probe
,
2492 module_platform_driver(mt6358_platform_driver
)
2494 /* Module information */
2495 MODULE_DESCRIPTION("MT6358 ALSA SoC codec driver");
2496 MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
2497 MODULE_LICENSE("GPL v2");