Kai Chieh Chuang | a74d51b | 2018-04-26 10:41:44 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * mt6351.c -- mt6351 ALSA SoC audio codec driver |
| 4 | * |
| 5 | * Copyright (c) 2018 MediaTek Inc. |
| 6 | * Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/dma-mapping.h> |
| 10 | #include <linux/platform_device.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/of_device.h> |
| 14 | #include <linux/delay.h> |
| 15 | |
| 16 | #include <sound/core.h> |
| 17 | #include <sound/pcm.h> |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/tlv.h> |
| 20 | |
| 21 | #include "mt6351.h" |
| 22 | |
| 23 | /* MT6351_TOP_CLKSQ */ |
| 24 | #define RG_CLKSQ_EN_AUD_BIT (0) |
| 25 | |
| 26 | /* MT6351_TOP_CKPDN_CON0 */ |
| 27 | #define RG_AUDNCP_CK_PDN_BIT (12) |
| 28 | #define RG_AUDIF_CK_PDN_BIT (13) |
| 29 | #define RG_AUD_CK_PDN_BIT (14) |
| 30 | #define RG_ZCD13M_CK_PDN_BIT (15) |
| 31 | |
| 32 | /* MT6351_AUDDEC_ANA_CON0 */ |
| 33 | #define RG_AUDDACLPWRUP_VAUDP32_BIT (0) |
| 34 | #define RG_AUDDACRPWRUP_VAUDP32_BIT (1) |
| 35 | #define RG_AUD_DAC_PWR_UP_VA32_BIT (2) |
| 36 | #define RG_AUD_DAC_PWL_UP_VA32_BIT (3) |
| 37 | |
| 38 | #define RG_AUDHSPWRUP_VAUDP32_BIT (4) |
| 39 | |
| 40 | #define RG_AUDHPLPWRUP_VAUDP32_BIT (5) |
| 41 | #define RG_AUDHPRPWRUP_VAUDP32_BIT (6) |
| 42 | |
| 43 | #define RG_AUDHSMUXINPUTSEL_VAUDP32_SFT (7) |
| 44 | #define RG_AUDHSMUXINPUTSEL_VAUDP32_MASK (0x3) |
| 45 | |
| 46 | #define RG_AUDHPLMUXINPUTSEL_VAUDP32_SFT (9) |
| 47 | #define RG_AUDHPLMUXINPUTSEL_VAUDP32_MASK (0x3) |
| 48 | |
| 49 | #define RG_AUDHPRMUXINPUTSEL_VAUDP32_SFT (11) |
| 50 | #define RG_AUDHPRMUXINPUTSEL_VAUDP32_MASK (0x3) |
| 51 | |
| 52 | #define RG_AUDHSSCDISABLE_VAUDP32 (13) |
| 53 | #define RG_AUDHPLSCDISABLE_VAUDP32_BIT (14) |
| 54 | #define RG_AUDHPRSCDISABLE_VAUDP32_BIT (15) |
| 55 | |
| 56 | /* MT6351_AUDDEC_ANA_CON1 */ |
| 57 | #define RG_HSOUTPUTSTBENH_VAUDP32_BIT (8) |
| 58 | |
| 59 | /* MT6351_AUDDEC_ANA_CON3 */ |
| 60 | #define RG_AUDLOLPWRUP_VAUDP32_BIT (2) |
| 61 | |
| 62 | #define RG_AUDLOLMUXINPUTSEL_VAUDP32_SFT (3) |
| 63 | #define RG_AUDLOLMUXINPUTSEL_VAUDP32_MASK (0x3) |
| 64 | |
| 65 | #define RG_AUDLOLSCDISABLE_VAUDP32_BIT (5) |
| 66 | #define RG_LOOUTPUTSTBENH_VAUDP32_BIT (9) |
| 67 | |
| 68 | /* MT6351_AUDDEC_ANA_CON6 */ |
| 69 | #define RG_ABIDEC_RSVD0_VAUDP32_HPL_BIT (8) |
| 70 | #define RG_ABIDEC_RSVD0_VAUDP32_HPR_BIT (9) |
| 71 | #define RG_ABIDEC_RSVD0_VAUDP32_HS_BIT (10) |
| 72 | #define RG_ABIDEC_RSVD0_VAUDP32_LOL_BIT (11) |
| 73 | |
| 74 | /* MT6351_AUDDEC_ANA_CON9 */ |
| 75 | #define RG_AUDIBIASPWRDN_VAUDP32_BIT (8) |
| 76 | #define RG_RSTB_DECODER_VA32_BIT (9) |
| 77 | #define RG_AUDGLB_PWRDN_VA32_BIT (12) |
| 78 | |
| 79 | #define RG_LCLDO_DEC_EN_VA32_BIT (13) |
| 80 | #define RG_LCLDO_DEC_REMOTE_SENSE_VA18_BIT (15) |
| 81 | /* MT6351_AUDDEC_ANA_CON10 */ |
| 82 | #define RG_NVREG_EN_VAUDP32_BIT (8) |
| 83 | |
| 84 | #define RG_AUDGLB_LP2_VOW_EN_VA32 10 |
| 85 | |
| 86 | /* MT6351_AFE_UL_DL_CON0 */ |
| 87 | #define RG_AFE_ON_BIT (0) |
| 88 | |
| 89 | /* MT6351_AFE_DL_SRC2_CON0_L */ |
| 90 | #define RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT (0) |
| 91 | |
| 92 | /* MT6351_AFE_UL_SRC_CON0_L */ |
| 93 | #define UL_SRC_ON_TMP_CTL (0) |
| 94 | |
| 95 | /* MT6351_AFE_TOP_CON0 */ |
| 96 | #define RG_DL_SINE_ON_SFT (0) |
| 97 | #define RG_DL_SINE_ON_MASK (0x1) |
| 98 | |
| 99 | #define RG_UL_SINE_ON_SFT (1) |
| 100 | #define RG_UL_SINE_ON_MASK (0x1) |
| 101 | |
| 102 | /* MT6351_AUDIO_TOP_CON0 */ |
| 103 | #define AUD_TOP_PDN_RESERVED_BIT 0 |
| 104 | #define AUD_TOP_PWR_CLK_DIS_CTL_BIT 2 |
| 105 | #define AUD_TOP_PDN_ADC_CTL_BIT 5 |
| 106 | #define AUD_TOP_PDN_DAC_CTL_BIT 6 |
| 107 | #define AUD_TOP_PDN_AFE_CTL_BIT 7 |
| 108 | |
| 109 | /* MT6351_AFE_SGEN_CFG0 */ |
| 110 | #define SGEN_C_MUTE_SW_CTL_BIT 6 |
| 111 | #define SGEN_C_DAC_EN_CTL_BIT 7 |
| 112 | |
| 113 | /* MT6351_AFE_NCP_CFG0 */ |
| 114 | #define RG_NCP_ON_BIT 0 |
| 115 | |
| 116 | /* MT6351_LDO_VUSB33_CON0 */ |
| 117 | #define RG_VUSB33_EN 1 |
| 118 | #define RG_VUSB33_ON_CTRL 3 |
| 119 | |
| 120 | /* MT6351_LDO_VA18_CON0 */ |
| 121 | #define RG_VA18_EN 1 |
| 122 | #define RG_VA18_ON_CTRL 3 |
| 123 | |
| 124 | /* MT6351_AUDENC_ANA_CON0 */ |
| 125 | #define RG_AUDPREAMPLON 0 |
| 126 | #define RG_AUDPREAMPLDCCEN 1 |
| 127 | #define RG_AUDPREAMPLDCPRECHARGE 2 |
| 128 | |
| 129 | #define RG_AUDPREAMPLINPUTSEL_SFT (4) |
| 130 | #define RG_AUDPREAMPLINPUTSEL_MASK (0x3) |
| 131 | |
| 132 | #define RG_AUDADCLPWRUP 12 |
| 133 | |
| 134 | #define RG_AUDADCLINPUTSEL_SFT (13) |
| 135 | #define RG_AUDADCLINPUTSEL_MASK (0x3) |
| 136 | |
| 137 | /* MT6351_AUDENC_ANA_CON1 */ |
| 138 | #define RG_AUDPREAMPRON 0 |
| 139 | #define RG_AUDPREAMPRDCCEN 1 |
| 140 | #define RG_AUDPREAMPRDCPRECHARGE 2 |
| 141 | |
| 142 | #define RG_AUDPREAMPRINPUTSEL_SFT (4) |
| 143 | #define RG_AUDPREAMPRINPUTSEL_MASK (0x3) |
| 144 | |
| 145 | #define RG_AUDADCRPWRUP 12 |
| 146 | |
| 147 | #define RG_AUDADCRINPUTSEL_SFT (13) |
| 148 | #define RG_AUDADCRINPUTSEL_MASK (0x3) |
| 149 | |
| 150 | /* MT6351_AUDENC_ANA_CON3 */ |
| 151 | #define RG_AUDADCCLKRSTB 6 |
| 152 | |
| 153 | /* MT6351_AUDENC_ANA_CON9 */ |
| 154 | #define RG_AUDPWDBMICBIAS0 0 |
| 155 | #define RG_AUDMICBIAS0VREF 4 |
| 156 | #define RG_AUDMICBIAS0LOWPEN 7 |
| 157 | |
| 158 | #define RG_AUDPWDBMICBIAS2 8 |
| 159 | #define RG_AUDMICBIAS2VREF 12 |
| 160 | #define RG_AUDMICBIAS2LOWPEN 15 |
| 161 | |
| 162 | /* MT6351_AUDENC_ANA_CON10 */ |
| 163 | #define RG_AUDPWDBMICBIAS1 0 |
| 164 | #define RG_AUDMICBIAS1DCSW1NEN 2 |
| 165 | #define RG_AUDMICBIAS1VREF 4 |
| 166 | #define RG_AUDMICBIAS1LOWPEN 7 |
| 167 | |
| 168 | enum { |
| 169 | AUDIO_ANALOG_VOLUME_HSOUTL, |
| 170 | AUDIO_ANALOG_VOLUME_HSOUTR, |
| 171 | AUDIO_ANALOG_VOLUME_HPOUTL, |
| 172 | AUDIO_ANALOG_VOLUME_HPOUTR, |
| 173 | AUDIO_ANALOG_VOLUME_LINEOUTL, |
| 174 | AUDIO_ANALOG_VOLUME_LINEOUTR, |
| 175 | AUDIO_ANALOG_VOLUME_MICAMP1, |
| 176 | AUDIO_ANALOG_VOLUME_MICAMP2, |
| 177 | AUDIO_ANALOG_VOLUME_TYPE_MAX |
| 178 | }; |
| 179 | |
| 180 | /* Supply subseq */ |
| 181 | enum { |
| 182 | SUPPLY_SUBSEQ_SETTING, |
| 183 | SUPPLY_SUBSEQ_ENABLE, |
| 184 | SUPPLY_SUBSEQ_MICBIAS, |
| 185 | }; |
| 186 | |
| 187 | #define REG_STRIDE 2 |
| 188 | |
| 189 | struct mt6351_priv { |
| 190 | struct device *dev; |
| 191 | struct regmap *regmap; |
| 192 | |
| 193 | unsigned int dl_rate; |
| 194 | unsigned int ul_rate; |
| 195 | |
| 196 | int ana_gain[AUDIO_ANALOG_VOLUME_TYPE_MAX]; |
| 197 | |
| 198 | int hp_en_counter; |
| 199 | }; |
| 200 | |
| 201 | static void set_hp_gain_zero(struct snd_soc_component *cmpnt) |
| 202 | { |
| 203 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2, |
| 204 | 0x1f << 7, 0x8 << 7); |
| 205 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2, |
| 206 | 0x1f << 0, 0x8 << 0); |
| 207 | } |
| 208 | |
| 209 | static unsigned int get_cap_reg_val(struct snd_soc_component *cmpnt, |
| 210 | unsigned int rate) |
| 211 | { |
| 212 | switch (rate) { |
| 213 | case 8000: |
| 214 | return 0; |
| 215 | case 16000: |
| 216 | return 1; |
| 217 | case 32000: |
| 218 | return 2; |
| 219 | case 48000: |
| 220 | return 3; |
| 221 | case 96000: |
| 222 | return 4; |
| 223 | case 192000: |
| 224 | return 5; |
| 225 | default: |
| 226 | dev_warn(cmpnt->dev, "%s(), error rate %d, return 3", |
| 227 | __func__, rate); |
| 228 | return 3; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static unsigned int get_play_reg_val(struct snd_soc_component *cmpnt, |
| 233 | unsigned int rate) |
| 234 | { |
| 235 | switch (rate) { |
| 236 | case 8000: |
| 237 | return 0; |
| 238 | case 11025: |
| 239 | return 1; |
| 240 | case 12000: |
| 241 | return 2; |
| 242 | case 16000: |
| 243 | return 3; |
| 244 | case 22050: |
| 245 | return 4; |
| 246 | case 24000: |
| 247 | return 5; |
| 248 | case 32000: |
| 249 | return 6; |
| 250 | case 44100: |
| 251 | return 7; |
| 252 | case 48000: |
| 253 | case 96000: |
| 254 | case 192000: |
| 255 | return 8; |
| 256 | default: |
| 257 | dev_warn(cmpnt->dev, "%s(), error rate %d, return 8", |
| 258 | __func__, rate); |
| 259 | return 8; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | static int mt6351_codec_dai_hw_params(struct snd_pcm_substream *substream, |
| 264 | struct snd_pcm_hw_params *params, |
| 265 | struct snd_soc_dai *dai) |
| 266 | { |
| 267 | struct snd_soc_component *cmpnt = dai->component; |
| 268 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 269 | unsigned int rate = params_rate(params); |
| 270 | |
| 271 | dev_dbg(priv->dev, "%s(), substream->stream %d, rate %d\n", |
| 272 | __func__, substream->stream, rate); |
| 273 | |
| 274 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 275 | priv->dl_rate = rate; |
| 276 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 277 | priv->ul_rate = rate; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static const struct snd_soc_dai_ops mt6351_codec_dai_ops = { |
| 283 | .hw_params = mt6351_codec_dai_hw_params, |
| 284 | }; |
| 285 | |
| 286 | #define MT6351_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 287 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\ |
| 288 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\ |
| 289 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\ |
| 290 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\ |
| 291 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE) |
| 292 | |
| 293 | static struct snd_soc_dai_driver mt6351_dai_driver[] = { |
| 294 | { |
| 295 | .name = "mt6351-snd-codec-aif1", |
| 296 | .playback = { |
| 297 | .stream_name = "AIF1 Playback", |
| 298 | .channels_min = 1, |
| 299 | .channels_max = 2, |
| 300 | .rates = SNDRV_PCM_RATE_8000_48000 | |
| 301 | SNDRV_PCM_RATE_96000 | |
| 302 | SNDRV_PCM_RATE_192000, |
| 303 | .formats = MT6351_FORMATS, |
| 304 | }, |
| 305 | .capture = { |
| 306 | .stream_name = "AIF1 Capture", |
| 307 | .channels_min = 1, |
| 308 | .channels_max = 2, |
| 309 | .rates = SNDRV_PCM_RATE_8000 | |
| 310 | SNDRV_PCM_RATE_16000 | |
| 311 | SNDRV_PCM_RATE_32000 | |
| 312 | SNDRV_PCM_RATE_48000 | |
| 313 | SNDRV_PCM_RATE_96000 | |
| 314 | SNDRV_PCM_RATE_192000, |
| 315 | .formats = MT6351_FORMATS, |
| 316 | }, |
| 317 | .ops = &mt6351_codec_dai_ops, |
| 318 | }, |
| 319 | }; |
| 320 | |
| 321 | enum { |
| 322 | HP_GAIN_SET_ZERO, |
| 323 | HP_GAIN_RESTORE, |
| 324 | }; |
| 325 | |
| 326 | static void hp_gain_ramp_set(struct snd_soc_component *cmpnt, int hp_gain_ctl) |
| 327 | { |
| 328 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 329 | int idx, old_idx, offset, reg_idx; |
| 330 | |
| 331 | if (hp_gain_ctl == HP_GAIN_SET_ZERO) { |
| 332 | idx = 8; /* 0dB */ |
| 333 | old_idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]; |
| 334 | } else { |
| 335 | idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]; |
| 336 | old_idx = 8; /* 0dB */ |
| 337 | } |
| 338 | dev_dbg(priv->dev, "%s(), idx %d, old_idx %d\n", |
| 339 | __func__, idx, old_idx); |
| 340 | |
| 341 | if (idx > old_idx) |
| 342 | offset = idx - old_idx; |
| 343 | else |
| 344 | offset = old_idx - idx; |
| 345 | |
| 346 | reg_idx = old_idx; |
| 347 | |
| 348 | while (offset > 0) { |
| 349 | reg_idx = idx > old_idx ? reg_idx + 1 : reg_idx - 1; |
| 350 | |
| 351 | /* check valid range, and set value */ |
| 352 | if ((reg_idx >= 0 && reg_idx <= 0x12) || reg_idx == 0x1f) { |
| 353 | regmap_update_bits(cmpnt->regmap, |
| 354 | MT6351_ZCD_CON2, |
| 355 | 0xf9f, |
| 356 | (reg_idx << 7) | reg_idx); |
| 357 | usleep_range(100, 120); |
| 358 | } |
| 359 | offset--; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | static void hp_zcd_enable(struct snd_soc_component *cmpnt) |
| 364 | { |
| 365 | /* Enable ZCD, for minimize pop noise */ |
| 366 | /* when adjust gain during HP buffer on */ |
| 367 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 8, 0x1 << 8); |
| 368 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 7, 0x0 << 7); |
| 369 | |
| 370 | /* timeout, 1=5ms, 0=30ms */ |
| 371 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 6, 0x1 << 6); |
| 372 | |
| 373 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x3 << 4, 0x0 << 4); |
| 374 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 1, 0x5 << 1); |
| 375 | regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 0, 0x1 << 0); |
| 376 | } |
| 377 | |
| 378 | static void hp_zcd_disable(struct snd_soc_component *cmpnt) |
| 379 | { |
| 380 | regmap_write(cmpnt->regmap, MT6351_ZCD_CON0, 0x0000); |
| 381 | } |
| 382 | |
| 383 | static const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0); |
| 384 | static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 600, 0); |
| 385 | |
| 386 | static const struct snd_kcontrol_new mt6351_snd_controls[] = { |
| 387 | /* dl pga gain */ |
| 388 | SOC_DOUBLE_TLV("Headphone Volume", |
| 389 | MT6351_ZCD_CON2, 0, 7, 0x12, 1, |
| 390 | playback_tlv), |
| 391 | SOC_DOUBLE_TLV("Lineout Volume", |
| 392 | MT6351_ZCD_CON1, 0, 7, 0x12, 1, |
| 393 | playback_tlv), |
| 394 | SOC_SINGLE_TLV("Handset Volume", |
| 395 | MT6351_ZCD_CON3, 0, 0x12, 1, |
| 396 | playback_tlv), |
| 397 | /* ul pga gain */ |
| 398 | SOC_DOUBLE_R_TLV("PGA Volume", |
| 399 | MT6351_AUDENC_ANA_CON0, MT6351_AUDENC_ANA_CON1, |
| 400 | 8, 4, 0, |
| 401 | pga_tlv), |
| 402 | }; |
| 403 | |
| 404 | /* MUX */ |
| 405 | |
| 406 | /* LOL MUX */ |
| 407 | static const char *const lo_in_mux_map[] = { |
| 408 | "Open", "Mute", "Playback", "Test Mode", |
| 409 | }; |
| 410 | |
| 411 | static int lo_in_mux_map_value[] = { |
| 412 | 0x0, 0x1, 0x2, 0x3, |
| 413 | }; |
| 414 | |
| 415 | static SOC_VALUE_ENUM_SINGLE_DECL(lo_in_mux_map_enum, |
| 416 | MT6351_AUDDEC_ANA_CON3, |
| 417 | RG_AUDLOLMUXINPUTSEL_VAUDP32_SFT, |
| 418 | RG_AUDLOLMUXINPUTSEL_VAUDP32_MASK, |
| 419 | lo_in_mux_map, |
| 420 | lo_in_mux_map_value); |
| 421 | |
| 422 | static const struct snd_kcontrol_new lo_in_mux_control = |
| 423 | SOC_DAPM_ENUM("In Select", lo_in_mux_map_enum); |
| 424 | |
| 425 | /*HP MUX */ |
| 426 | static const char *const hp_in_mux_map[] = { |
| 427 | "Open", "LoudSPK Playback", "Audio Playback", "Test Mode", |
| 428 | }; |
| 429 | |
| 430 | static int hp_in_mux_map_value[] = { |
| 431 | 0x0, 0x1, 0x2, 0x3, |
| 432 | }; |
| 433 | |
| 434 | static SOC_VALUE_ENUM_SINGLE_DECL(hpl_in_mux_map_enum, |
| 435 | MT6351_AUDDEC_ANA_CON0, |
| 436 | RG_AUDHPLMUXINPUTSEL_VAUDP32_SFT, |
| 437 | RG_AUDHPLMUXINPUTSEL_VAUDP32_MASK, |
| 438 | hp_in_mux_map, |
| 439 | hp_in_mux_map_value); |
| 440 | |
| 441 | static const struct snd_kcontrol_new hpl_in_mux_control = |
| 442 | SOC_DAPM_ENUM("HPL Select", hpl_in_mux_map_enum); |
| 443 | |
| 444 | static SOC_VALUE_ENUM_SINGLE_DECL(hpr_in_mux_map_enum, |
| 445 | MT6351_AUDDEC_ANA_CON0, |
| 446 | RG_AUDHPRMUXINPUTSEL_VAUDP32_SFT, |
| 447 | RG_AUDHPRMUXINPUTSEL_VAUDP32_MASK, |
| 448 | hp_in_mux_map, |
| 449 | hp_in_mux_map_value); |
| 450 | |
| 451 | static const struct snd_kcontrol_new hpr_in_mux_control = |
| 452 | SOC_DAPM_ENUM("HPR Select", hpr_in_mux_map_enum); |
| 453 | |
| 454 | /* RCV MUX */ |
| 455 | static const char *const rcv_in_mux_map[] = { |
| 456 | "Open", "Mute", "Voice Playback", "Test Mode", |
| 457 | }; |
| 458 | |
| 459 | static int rcv_in_mux_map_value[] = { |
| 460 | 0x0, 0x1, 0x2, 0x3, |
| 461 | }; |
| 462 | |
| 463 | static SOC_VALUE_ENUM_SINGLE_DECL(rcv_in_mux_map_enum, |
| 464 | MT6351_AUDDEC_ANA_CON0, |
| 465 | RG_AUDHSMUXINPUTSEL_VAUDP32_SFT, |
| 466 | RG_AUDHSMUXINPUTSEL_VAUDP32_MASK, |
| 467 | rcv_in_mux_map, |
| 468 | rcv_in_mux_map_value); |
| 469 | |
| 470 | static const struct snd_kcontrol_new rcv_in_mux_control = |
| 471 | SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum); |
| 472 | |
| 473 | /* DAC In MUX */ |
| 474 | static const char *const dac_in_mux_map[] = { |
| 475 | "Normal Path", "Sgen", |
| 476 | }; |
| 477 | |
| 478 | static int dac_in_mux_map_value[] = { |
| 479 | 0x0, 0x1, |
| 480 | }; |
| 481 | |
| 482 | static SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum, |
| 483 | MT6351_AFE_TOP_CON0, |
| 484 | RG_DL_SINE_ON_SFT, |
| 485 | RG_DL_SINE_ON_MASK, |
| 486 | dac_in_mux_map, |
| 487 | dac_in_mux_map_value); |
| 488 | |
| 489 | static const struct snd_kcontrol_new dac_in_mux_control = |
| 490 | SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum); |
| 491 | |
| 492 | /* AIF Out MUX */ |
| 493 | static SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum, |
| 494 | MT6351_AFE_TOP_CON0, |
| 495 | RG_UL_SINE_ON_SFT, |
| 496 | RG_UL_SINE_ON_MASK, |
| 497 | dac_in_mux_map, |
| 498 | dac_in_mux_map_value); |
| 499 | |
| 500 | static const struct snd_kcontrol_new aif_out_mux_control = |
| 501 | SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum); |
| 502 | |
| 503 | /* ADC L MUX */ |
| 504 | static const char *const adc_left_mux_map[] = { |
| 505 | "Idle", "AIN0", "Left Preamplifier", "Idle_1", |
| 506 | }; |
| 507 | |
| 508 | static int adc_left_mux_map_value[] = { |
| 509 | 0x0, 0x1, 0x2, 0x3, |
| 510 | }; |
| 511 | |
| 512 | static SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum, |
| 513 | MT6351_AUDENC_ANA_CON0, |
| 514 | RG_AUDADCLINPUTSEL_SFT, |
| 515 | RG_AUDADCLINPUTSEL_MASK, |
| 516 | adc_left_mux_map, |
| 517 | adc_left_mux_map_value); |
| 518 | |
| 519 | static const struct snd_kcontrol_new adc_left_mux_control = |
| 520 | SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum); |
| 521 | |
| 522 | /* ADC R MUX */ |
| 523 | static const char *const adc_right_mux_map[] = { |
| 524 | "Idle", "AIN0", "Right Preamplifier", "Idle_1", |
| 525 | }; |
| 526 | |
| 527 | static int adc_right_mux_map_value[] = { |
| 528 | 0x0, 0x1, 0x2, 0x3, |
| 529 | }; |
| 530 | |
| 531 | static SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum, |
| 532 | MT6351_AUDENC_ANA_CON1, |
| 533 | RG_AUDADCRINPUTSEL_SFT, |
| 534 | RG_AUDADCRINPUTSEL_MASK, |
| 535 | adc_right_mux_map, |
| 536 | adc_right_mux_map_value); |
| 537 | |
| 538 | static const struct snd_kcontrol_new adc_right_mux_control = |
| 539 | SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum); |
| 540 | |
| 541 | /* PGA L MUX */ |
| 542 | static const char *const pga_left_mux_map[] = { |
| 543 | "None", "AIN0", "AIN1", "AIN2", |
| 544 | }; |
| 545 | |
| 546 | static int pga_left_mux_map_value[] = { |
| 547 | 0x0, 0x1, 0x2, 0x3, |
| 548 | }; |
| 549 | |
| 550 | static SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum, |
| 551 | MT6351_AUDENC_ANA_CON0, |
| 552 | RG_AUDPREAMPLINPUTSEL_SFT, |
| 553 | RG_AUDPREAMPLINPUTSEL_MASK, |
| 554 | pga_left_mux_map, |
| 555 | pga_left_mux_map_value); |
| 556 | |
| 557 | static const struct snd_kcontrol_new pga_left_mux_control = |
| 558 | SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum); |
| 559 | |
| 560 | /* PGA R MUX */ |
| 561 | static const char *const pga_right_mux_map[] = { |
| 562 | "None", "AIN0", "AIN3", "AIN2", |
| 563 | }; |
| 564 | |
| 565 | static int pga_right_mux_map_value[] = { |
| 566 | 0x0, 0x1, 0x2, 0x3, |
| 567 | }; |
| 568 | |
| 569 | static SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum, |
| 570 | MT6351_AUDENC_ANA_CON1, |
| 571 | RG_AUDPREAMPRINPUTSEL_SFT, |
| 572 | RG_AUDPREAMPRINPUTSEL_MASK, |
| 573 | pga_right_mux_map, |
| 574 | pga_right_mux_map_value); |
| 575 | |
| 576 | static const struct snd_kcontrol_new pga_right_mux_control = |
| 577 | SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum); |
| 578 | |
| 579 | static int mt_reg_set_clr_event(struct snd_soc_dapm_widget *w, |
| 580 | struct snd_kcontrol *kcontrol, |
| 581 | int event) |
| 582 | { |
| 583 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 584 | |
| 585 | switch (event) { |
| 586 | case SND_SOC_DAPM_POST_PMU: |
| 587 | if (w->on_val) { |
| 588 | /* SET REG */ |
| 589 | regmap_update_bits(cmpnt->regmap, |
| 590 | w->reg + REG_STRIDE, |
| 591 | 0x1 << w->shift, |
| 592 | 0x1 << w->shift); |
| 593 | } else { |
| 594 | /* CLR REG */ |
| 595 | regmap_update_bits(cmpnt->regmap, |
| 596 | w->reg + REG_STRIDE * 2, |
| 597 | 0x1 << w->shift, |
| 598 | 0x1 << w->shift); |
| 599 | } |
| 600 | break; |
| 601 | case SND_SOC_DAPM_PRE_PMD: |
| 602 | if (w->off_val) { |
| 603 | /* SET REG */ |
| 604 | regmap_update_bits(cmpnt->regmap, |
| 605 | w->reg + REG_STRIDE, |
| 606 | 0x1 << w->shift, |
| 607 | 0x1 << w->shift); |
| 608 | } else { |
| 609 | /* CLR REG */ |
| 610 | regmap_update_bits(cmpnt->regmap, |
| 611 | w->reg + REG_STRIDE * 2, |
| 612 | 0x1 << w->shift, |
| 613 | 0x1 << w->shift); |
| 614 | } |
| 615 | break; |
| 616 | default: |
| 617 | break; |
| 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int mt_ncp_event(struct snd_soc_dapm_widget *w, |
| 624 | struct snd_kcontrol *kcontrol, |
| 625 | int event) |
| 626 | { |
| 627 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 628 | |
| 629 | switch (event) { |
| 630 | case SND_SOC_DAPM_PRE_PMU: |
| 631 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG1, |
| 632 | 0xffff, 0x1515); |
| 633 | /* NCP: ck1 and ck2 clock frequecy adjust configure */ |
| 634 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG0, |
| 635 | 0xfffe, 0x8C00); |
| 636 | break; |
| 637 | case SND_SOC_DAPM_POST_PMU: |
| 638 | usleep_range(250, 270); |
| 639 | break; |
| 640 | default: |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static int mt_sgen_event(struct snd_soc_dapm_widget *w, |
| 648 | struct snd_kcontrol *kcontrol, |
| 649 | int event) |
| 650 | { |
| 651 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 652 | |
| 653 | switch (event) { |
| 654 | case SND_SOC_DAPM_PRE_PMU: |
| 655 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG0, |
| 656 | 0xffef, 0x0008); |
| 657 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG1, |
| 658 | 0xffff, 0x0101); |
| 659 | break; |
| 660 | default: |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int mt_aif_in_event(struct snd_soc_dapm_widget *w, |
| 668 | struct snd_kcontrol *kcontrol, |
| 669 | int event) |
| 670 | { |
| 671 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 672 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 673 | |
| 674 | dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n", |
| 675 | __func__, event, priv->dl_rate); |
| 676 | |
| 677 | switch (event) { |
| 678 | case SND_SOC_DAPM_PRE_PMU: |
| 679 | /* sdm audio fifo clock power on */ |
| 680 | regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, |
| 681 | 0xffff, 0x0006); |
| 682 | /* scrambler clock on enable */ |
| 683 | regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON0, |
| 684 | 0xffff, 0xC3A1); |
| 685 | /* sdm power on */ |
| 686 | regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, |
| 687 | 0xffff, 0x0003); |
| 688 | /* sdm fifo enable */ |
| 689 | regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, |
| 690 | 0xffff, 0x000B); |
| 691 | /* set attenuation gain */ |
| 692 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_DL_SDM_CON1, |
| 693 | 0xffff, 0x001E); |
| 694 | |
| 695 | regmap_write(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG0, |
| 696 | (get_play_reg_val(cmpnt, priv->dl_rate) << 12) | |
| 697 | 0x330); |
| 698 | regmap_write(cmpnt->regmap, MT6351_AFE_DL_SRC2_CON0_H, |
| 699 | (get_play_reg_val(cmpnt, priv->dl_rate) << 12) | |
| 700 | 0x300); |
| 701 | |
| 702 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2, |
| 703 | 0x8000, 0x8000); |
| 704 | break; |
| 705 | default: |
| 706 | break; |
| 707 | } |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static int mt_hp_event(struct snd_soc_dapm_widget *w, |
| 713 | struct snd_kcontrol *kcontrol, |
| 714 | int event) |
| 715 | { |
| 716 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 717 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 718 | int reg; |
| 719 | |
| 720 | dev_dbg(priv->dev, "%s(), event 0x%x, hp_en_counter %d\n", |
| 721 | __func__, event, priv->hp_en_counter); |
| 722 | |
| 723 | switch (event) { |
| 724 | case SND_SOC_DAPM_PRE_PMU: |
| 725 | priv->hp_en_counter++; |
| 726 | if (priv->hp_en_counter > 1) |
| 727 | break; /* already enabled, do nothing */ |
| 728 | else if (priv->hp_en_counter <= 0) |
| 729 | dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", |
| 730 | __func__, |
| 731 | priv->hp_en_counter); |
| 732 | |
| 733 | hp_zcd_disable(cmpnt); |
| 734 | |
| 735 | /* from yoyo HQA script */ |
| 736 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6, |
| 737 | 0x0700, 0x0700); |
| 738 | |
| 739 | /* save target gain to restore after hardware open complete */ |
| 740 | regmap_read(cmpnt->regmap, MT6351_ZCD_CON2, ®); |
| 741 | priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = reg & 0x1f; |
| 742 | priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = (reg >> 7) & 0x1f; |
| 743 | |
| 744 | /* Set HPR/HPL gain as minimum (~ -40dB) */ |
| 745 | regmap_update_bits(cmpnt->regmap, |
| 746 | MT6351_ZCD_CON2, 0xffff, 0x0F9F); |
| 747 | /* Set HS gain as minimum (~ -40dB) */ |
| 748 | regmap_update_bits(cmpnt->regmap, |
| 749 | MT6351_ZCD_CON3, 0xffff, 0x001F); |
| 750 | /* De_OSC of HP */ |
| 751 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON2, |
| 752 | 0x0001, 0x0001); |
| 753 | /* enable output STBENH */ |
| 754 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, |
| 755 | 0xffff, 0x2000); |
| 756 | /* De_OSC of voice, enable output STBENH */ |
| 757 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, |
| 758 | 0xffff, 0x2100); |
| 759 | /* Enable voice driver */ |
| 760 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, |
| 761 | 0x0010, 0xE090); |
| 762 | /* Enable pre-charge buffer */ |
| 763 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, |
| 764 | 0xffff, 0x2140); |
| 765 | |
| 766 | usleep_range(50, 60); |
| 767 | |
| 768 | /* Apply digital DC compensation value to DAC */ |
| 769 | set_hp_gain_zero(cmpnt); |
| 770 | |
| 771 | /* Enable HPR/HPL */ |
| 772 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, |
| 773 | 0xffff, 0x2100); |
| 774 | /* Disable pre-charge buffer */ |
| 775 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, |
| 776 | 0xffff, 0x2000); |
| 777 | /* Disable De_OSC of voice */ |
| 778 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, |
| 779 | 0x0010, 0xF4EF); |
| 780 | /* Disable voice buffer */ |
| 781 | |
| 782 | /* from yoyo HQ */ |
| 783 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6, |
| 784 | 0x0700, 0x0300); |
| 785 | |
| 786 | /* Enable ZCD, for minimize pop noise */ |
| 787 | /* when adjust gain during HP buffer on */ |
| 788 | hp_zcd_enable(cmpnt); |
| 789 | |
| 790 | /* apply volume setting */ |
| 791 | hp_gain_ramp_set(cmpnt, HP_GAIN_RESTORE); |
| 792 | |
| 793 | break; |
| 794 | case SND_SOC_DAPM_PRE_PMD: |
| 795 | priv->hp_en_counter--; |
| 796 | if (priv->hp_en_counter > 0) |
| 797 | break; /* still being used, don't close */ |
| 798 | else if (priv->hp_en_counter < 0) |
| 799 | dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", |
| 800 | __func__, |
| 801 | priv->hp_en_counter); |
| 802 | |
| 803 | /* Disable AUD_ZCD */ |
| 804 | hp_zcd_disable(cmpnt); |
| 805 | |
| 806 | /* Set HPR/HPL gain as -1dB, step by step */ |
| 807 | hp_gain_ramp_set(cmpnt, HP_GAIN_SET_ZERO); |
| 808 | |
| 809 | set_hp_gain_zero(cmpnt); |
| 810 | break; |
| 811 | case SND_SOC_DAPM_POST_PMD: |
| 812 | if (priv->hp_en_counter > 0) |
| 813 | break; /* still being used, don't close */ |
| 814 | else if (priv->hp_en_counter < 0) |
| 815 | dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", |
| 816 | __func__, |
| 817 | priv->hp_en_counter); |
| 818 | |
| 819 | /* reset*/ |
| 820 | regmap_update_bits(cmpnt->regmap, |
| 821 | MT6351_AUDDEC_ANA_CON6, |
| 822 | 0x0700, |
| 823 | 0x0000); |
| 824 | /* De_OSC of HP */ |
| 825 | regmap_update_bits(cmpnt->regmap, |
| 826 | MT6351_AUDDEC_ANA_CON2, |
| 827 | 0x0001, |
| 828 | 0x0000); |
| 829 | |
| 830 | /* apply volume setting */ |
| 831 | hp_gain_ramp_set(cmpnt, HP_GAIN_RESTORE); |
| 832 | break; |
| 833 | default: |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static int mt_aif_out_event(struct snd_soc_dapm_widget *w, |
| 841 | struct snd_kcontrol *kcontrol, |
| 842 | int event) |
| 843 | { |
| 844 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 845 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 846 | |
| 847 | dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n", |
| 848 | __func__, event, priv->ul_rate); |
| 849 | |
| 850 | switch (event) { |
| 851 | case SND_SOC_DAPM_PRE_PMU: |
| 852 | /* dcclk_div=11'b00100000011, dcclk_ref_ck_sel=2'b00 */ |
| 853 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, |
| 854 | 0xffff, 0x2062); |
| 855 | /* dcclk_pdn=1'b0 */ |
| 856 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, |
| 857 | 0xffff, 0x2060); |
| 858 | /* dcclk_gen_on=1'b1 */ |
| 859 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, |
| 860 | 0xffff, 0x2061); |
| 861 | |
| 862 | /* UL sample rate and mode configure */ |
| 863 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_UL_SRC_CON0_H, |
| 864 | 0x000E, |
| 865 | get_cap_reg_val(cmpnt, priv->ul_rate) << 1); |
| 866 | |
| 867 | /* fixed 260k path for 8/16/32/48 */ |
| 868 | if (priv->ul_rate <= 48000) { |
| 869 | /* anc ul path src on */ |
| 870 | regmap_update_bits(cmpnt->regmap, |
| 871 | MT6351_AFE_HPANC_CFG0, |
| 872 | 0x1 << 1, |
| 873 | 0x1 << 1); |
| 874 | /* ANC clk pdn release */ |
| 875 | regmap_update_bits(cmpnt->regmap, |
| 876 | MT6351_AFE_HPANC_CFG0, |
| 877 | 0x1 << 0, |
| 878 | 0x0 << 0); |
| 879 | } |
| 880 | break; |
| 881 | case SND_SOC_DAPM_PRE_PMD: |
| 882 | /* fixed 260k path for 8/16/32/48 */ |
| 883 | if (priv->ul_rate <= 48000) { |
| 884 | /* anc ul path src on */ |
| 885 | regmap_update_bits(cmpnt->regmap, |
| 886 | MT6351_AFE_HPANC_CFG0, |
| 887 | 0x1 << 1, |
| 888 | 0x0 << 1); |
| 889 | /* ANC clk pdn release */ |
| 890 | regmap_update_bits(cmpnt->regmap, |
| 891 | MT6351_AFE_HPANC_CFG0, |
| 892 | 0x1 << 0, |
| 893 | 0x1 << 0); |
| 894 | } |
| 895 | break; |
| 896 | default: |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static int mt_adc_clkgen_event(struct snd_soc_dapm_widget *w, |
| 904 | struct snd_kcontrol *kcontrol, |
| 905 | int event) |
| 906 | { |
| 907 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 908 | |
| 909 | switch (event) { |
| 910 | case SND_SOC_DAPM_PRE_PMU: |
| 911 | /* Audio ADC clock gen. mode: 00_divided by 2 (Normal) */ |
| 912 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3, |
| 913 | 0x3 << 4, 0x0); |
| 914 | break; |
| 915 | case SND_SOC_DAPM_POST_PMU: |
| 916 | /* ADC CLK from: 00_13MHz from CLKSQ (Default) */ |
| 917 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3, |
| 918 | 0x3 << 2, 0x0); |
| 919 | break; |
| 920 | default: |
| 921 | break; |
| 922 | } |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | static int mt_pga_left_event(struct snd_soc_dapm_widget *w, |
| 927 | struct snd_kcontrol *kcontrol, |
| 928 | int event) |
| 929 | { |
| 930 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 931 | |
| 932 | switch (event) { |
| 933 | case SND_SOC_DAPM_PRE_PMU: |
| 934 | /* Audio L PGA precharge on */ |
| 935 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, |
| 936 | 0x3 << RG_AUDPREAMPLDCPRECHARGE, |
| 937 | 0x1 << RG_AUDPREAMPLDCPRECHARGE); |
| 938 | /* Audio L PGA mode: 1_DCC */ |
| 939 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, |
| 940 | 0x3 << RG_AUDPREAMPLDCCEN, |
| 941 | 0x1 << RG_AUDPREAMPLDCCEN); |
| 942 | break; |
| 943 | case SND_SOC_DAPM_POST_PMU: |
| 944 | usleep_range(100, 120); |
| 945 | /* Audio L PGA precharge off */ |
| 946 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, |
| 947 | 0x3 << RG_AUDPREAMPLDCPRECHARGE, |
| 948 | 0x0 << RG_AUDPREAMPLDCPRECHARGE); |
| 949 | break; |
| 950 | default: |
| 951 | break; |
| 952 | } |
| 953 | return 0; |
| 954 | } |
| 955 | |
| 956 | static int mt_pga_right_event(struct snd_soc_dapm_widget *w, |
| 957 | struct snd_kcontrol *kcontrol, |
| 958 | int event) |
| 959 | { |
| 960 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 961 | |
| 962 | switch (event) { |
| 963 | case SND_SOC_DAPM_PRE_PMU: |
| 964 | /* Audio R PGA precharge on */ |
| 965 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, |
| 966 | 0x3 << RG_AUDPREAMPRDCPRECHARGE, |
| 967 | 0x1 << RG_AUDPREAMPRDCPRECHARGE); |
| 968 | /* Audio R PGA mode: 1_DCC */ |
| 969 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, |
| 970 | 0x3 << RG_AUDPREAMPRDCCEN, |
| 971 | 0x1 << RG_AUDPREAMPRDCCEN); |
| 972 | break; |
| 973 | case SND_SOC_DAPM_POST_PMU: |
| 974 | usleep_range(100, 120); |
| 975 | /* Audio R PGA precharge off */ |
| 976 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, |
| 977 | 0x3 << RG_AUDPREAMPRDCPRECHARGE, |
| 978 | 0x0 << RG_AUDPREAMPRDCPRECHARGE); |
| 979 | break; |
| 980 | default: |
| 981 | break; |
| 982 | } |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static int mt_mic_bias_0_event(struct snd_soc_dapm_widget *w, |
| 987 | struct snd_kcontrol *kcontrol, |
| 988 | int event) |
| 989 | { |
| 990 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 991 | |
| 992 | switch (event) { |
| 993 | case SND_SOC_DAPM_PRE_PMU: |
| 994 | /* MIC Bias 0 LowPower: 0_Normal */ |
| 995 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 996 | 0x3 << RG_AUDMICBIAS0LOWPEN, 0x0); |
| 997 | /* MISBIAS0 = 1P9V */ |
| 998 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 999 | 0x7 << RG_AUDMICBIAS0VREF, |
| 1000 | 0x2 << RG_AUDMICBIAS0VREF); |
| 1001 | break; |
| 1002 | case SND_SOC_DAPM_POST_PMD: |
| 1003 | /* MISBIAS0 = 1P97 */ |
| 1004 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 1005 | 0x7 << RG_AUDMICBIAS0VREF, |
| 1006 | 0x0 << RG_AUDMICBIAS0VREF); |
| 1007 | break; |
| 1008 | default: |
| 1009 | break; |
| 1010 | } |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | static int mt_mic_bias_1_event(struct snd_soc_dapm_widget *w, |
| 1015 | struct snd_kcontrol *kcontrol, |
| 1016 | int event) |
| 1017 | { |
| 1018 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 1019 | |
| 1020 | switch (event) { |
| 1021 | case SND_SOC_DAPM_PRE_PMU: |
| 1022 | /* MIC Bias 1 LowPower: 0_Normal */ |
| 1023 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, |
| 1024 | 0x3 << RG_AUDMICBIAS1LOWPEN, 0x0); |
| 1025 | /* MISBIAS1 = 2P7V */ |
| 1026 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, |
| 1027 | 0x7 << RG_AUDMICBIAS1VREF, |
| 1028 | 0x7 << RG_AUDMICBIAS1VREF); |
| 1029 | break; |
| 1030 | case SND_SOC_DAPM_POST_PMD: |
| 1031 | /* MISBIAS1 = 1P7V */ |
| 1032 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, |
| 1033 | 0x7 << RG_AUDMICBIAS1VREF, |
| 1034 | 0x0 << RG_AUDMICBIAS1VREF); |
| 1035 | break; |
| 1036 | default: |
| 1037 | break; |
| 1038 | } |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | static int mt_mic_bias_2_event(struct snd_soc_dapm_widget *w, |
| 1043 | struct snd_kcontrol *kcontrol, |
| 1044 | int event) |
| 1045 | { |
| 1046 | struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); |
| 1047 | |
| 1048 | switch (event) { |
| 1049 | case SND_SOC_DAPM_PRE_PMU: |
| 1050 | /* MIC Bias 2 LowPower: 0_Normal */ |
| 1051 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 1052 | 0x3 << RG_AUDMICBIAS2LOWPEN, 0x0); |
| 1053 | /* MISBIAS2 = 1P9V */ |
| 1054 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 1055 | 0x7 << RG_AUDMICBIAS2VREF, |
| 1056 | 0x2 << RG_AUDMICBIAS2VREF); |
| 1057 | break; |
| 1058 | case SND_SOC_DAPM_POST_PMD: |
| 1059 | /* MISBIAS2 = 1P97 */ |
| 1060 | regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, |
| 1061 | 0x7 << RG_AUDMICBIAS2VREF, |
| 1062 | 0x0 << RG_AUDMICBIAS2VREF); |
| 1063 | break; |
| 1064 | default: |
| 1065 | break; |
| 1066 | } |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | /* DAPM Kcontrols */ |
| 1071 | static const struct snd_kcontrol_new mt_lineout_control = |
| 1072 | SOC_DAPM_SINGLE("Switch", MT6351_AUDDEC_ANA_CON3, |
| 1073 | RG_AUDLOLPWRUP_VAUDP32_BIT, 1, 0); |
| 1074 | |
| 1075 | /* DAPM Widgets */ |
| 1076 | static const struct snd_soc_dapm_widget mt6351_dapm_widgets[] = { |
| 1077 | /* Digital Clock */ |
| 1078 | SND_SOC_DAPM_SUPPLY("AUDIO_TOP_AFE_CTL", MT6351_AUDIO_TOP_CON0, |
| 1079 | AUD_TOP_PDN_AFE_CTL_BIT, 1, NULL, 0), |
| 1080 | SND_SOC_DAPM_SUPPLY("AUDIO_TOP_DAC_CTL", MT6351_AUDIO_TOP_CON0, |
| 1081 | AUD_TOP_PDN_DAC_CTL_BIT, 1, NULL, 0), |
| 1082 | SND_SOC_DAPM_SUPPLY("AUDIO_TOP_ADC_CTL", MT6351_AUDIO_TOP_CON0, |
| 1083 | AUD_TOP_PDN_ADC_CTL_BIT, 1, NULL, 0), |
| 1084 | SND_SOC_DAPM_SUPPLY("AUDIO_TOP_PWR_CLK", MT6351_AUDIO_TOP_CON0, |
| 1085 | AUD_TOP_PWR_CLK_DIS_CTL_BIT, 1, NULL, 0), |
| 1086 | SND_SOC_DAPM_SUPPLY("AUDIO_TOP_PDN_RESERVED", MT6351_AUDIO_TOP_CON0, |
| 1087 | AUD_TOP_PDN_RESERVED_BIT, 1, NULL, 0), |
| 1088 | |
| 1089 | SND_SOC_DAPM_SUPPLY("NCP", MT6351_AFE_NCP_CFG0, |
| 1090 | RG_NCP_ON_BIT, 0, |
| 1091 | mt_ncp_event, |
| 1092 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
| 1093 | |
| 1094 | SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM, |
| 1095 | 0, 0, NULL, 0), |
| 1096 | |
| 1097 | /* Global Supply*/ |
| 1098 | SND_SOC_DAPM_SUPPLY("AUDGLB", MT6351_AUDDEC_ANA_CON9, |
| 1099 | RG_AUDGLB_PWRDN_VA32_BIT, 1, NULL, 0), |
| 1100 | SND_SOC_DAPM_SUPPLY("CLKSQ Audio", MT6351_TOP_CLKSQ, |
| 1101 | RG_CLKSQ_EN_AUD_BIT, 0, |
| 1102 | mt_reg_set_clr_event, |
| 1103 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1104 | SND_SOC_DAPM_SUPPLY("ZCD13M_CK", MT6351_TOP_CKPDN_CON0, |
| 1105 | RG_ZCD13M_CK_PDN_BIT, 1, |
| 1106 | mt_reg_set_clr_event, |
| 1107 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1108 | SND_SOC_DAPM_SUPPLY("AUD_CK", MT6351_TOP_CKPDN_CON0, |
| 1109 | RG_AUD_CK_PDN_BIT, 1, |
| 1110 | mt_reg_set_clr_event, |
| 1111 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1112 | SND_SOC_DAPM_SUPPLY("AUDIF_CK", MT6351_TOP_CKPDN_CON0, |
| 1113 | RG_AUDIF_CK_PDN_BIT, 1, |
| 1114 | mt_reg_set_clr_event, |
| 1115 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1116 | SND_SOC_DAPM_SUPPLY("AUDNCP_CK", MT6351_TOP_CKPDN_CON0, |
| 1117 | RG_AUDNCP_CK_PDN_BIT, 1, |
| 1118 | mt_reg_set_clr_event, |
| 1119 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1120 | |
| 1121 | SND_SOC_DAPM_SUPPLY("AFE_ON", MT6351_AFE_UL_DL_CON0, RG_AFE_ON_BIT, 0, |
| 1122 | NULL, 0), |
| 1123 | |
| 1124 | /* AIF Rx*/ |
| 1125 | SND_SOC_DAPM_AIF_IN_E("AIF_RX", "AIF1 Playback", 0, |
| 1126 | MT6351_AFE_DL_SRC2_CON0_L, |
| 1127 | RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT, 0, |
| 1128 | mt_aif_in_event, SND_SOC_DAPM_PRE_PMU), |
| 1129 | |
| 1130 | /* DL Supply */ |
| 1131 | SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM, |
| 1132 | 0, 0, NULL, 0), |
| 1133 | SND_SOC_DAPM_SUPPLY("NV Regulator", MT6351_AUDDEC_ANA_CON10, |
| 1134 | RG_NVREG_EN_VAUDP32_BIT, 0, NULL, 0), |
| 1135 | SND_SOC_DAPM_SUPPLY("AUD_CLK", MT6351_AUDDEC_ANA_CON9, |
| 1136 | RG_RSTB_DECODER_VA32_BIT, 0, NULL, 0), |
| 1137 | SND_SOC_DAPM_SUPPLY("IBIST", MT6351_AUDDEC_ANA_CON9, |
| 1138 | RG_AUDIBIASPWRDN_VAUDP32_BIT, 1, NULL, 0), |
| 1139 | SND_SOC_DAPM_SUPPLY("LDO", MT6351_AUDDEC_ANA_CON9, |
| 1140 | RG_LCLDO_DEC_EN_VA32_BIT, 0, NULL, 0), |
| 1141 | SND_SOC_DAPM_SUPPLY("LDO_REMOTE_SENSE", MT6351_AUDDEC_ANA_CON9, |
| 1142 | RG_LCLDO_DEC_REMOTE_SENSE_VA18_BIT, 0, NULL, 0), |
| 1143 | |
| 1144 | /* DAC */ |
| 1145 | SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM, 0, 0, &dac_in_mux_control), |
| 1146 | |
| 1147 | SND_SOC_DAPM_DAC("DACL", NULL, MT6351_AUDDEC_ANA_CON0, |
| 1148 | RG_AUDDACLPWRUP_VAUDP32_BIT, 0), |
| 1149 | SND_SOC_DAPM_SUPPLY("DACL_BIASGEN", MT6351_AUDDEC_ANA_CON0, |
| 1150 | RG_AUD_DAC_PWL_UP_VA32_BIT, 0, NULL, 0), |
| 1151 | |
| 1152 | SND_SOC_DAPM_DAC("DACR", NULL, MT6351_AUDDEC_ANA_CON0, |
| 1153 | RG_AUDDACRPWRUP_VAUDP32_BIT, 0), |
| 1154 | SND_SOC_DAPM_SUPPLY("DACR_BIASGEN", MT6351_AUDDEC_ANA_CON0, |
| 1155 | RG_AUD_DAC_PWR_UP_VA32_BIT, 0, NULL, 0), |
| 1156 | /* LOL */ |
| 1157 | SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM, 0, 0, &lo_in_mux_control), |
| 1158 | |
| 1159 | SND_SOC_DAPM_SUPPLY("LO Stability Enh", MT6351_AUDDEC_ANA_CON3, |
| 1160 | RG_LOOUTPUTSTBENH_VAUDP32_BIT, 0, NULL, 0), |
| 1161 | SND_SOC_DAPM_SUPPLY("LOL Bias Gen", MT6351_AUDDEC_ANA_CON6, |
| 1162 | RG_ABIDEC_RSVD0_VAUDP32_LOL_BIT, 0, NULL, 0), |
| 1163 | |
| 1164 | SND_SOC_DAPM_OUT_DRV("LOL Buffer", MT6351_AUDDEC_ANA_CON3, |
| 1165 | RG_AUDLOLPWRUP_VAUDP32_BIT, 0, NULL, 0), |
| 1166 | |
| 1167 | /* Headphone */ |
| 1168 | SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0, &hpl_in_mux_control), |
| 1169 | SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0, &hpr_in_mux_control), |
| 1170 | |
| 1171 | SND_SOC_DAPM_OUT_DRV_E("HPL Power", MT6351_AUDDEC_ANA_CON0, |
| 1172 | RG_AUDHPLPWRUP_VAUDP32_BIT, 0, NULL, 0, |
| 1173 | mt_hp_event, |
| 1174 | SND_SOC_DAPM_PRE_PMU | |
| 1175 | SND_SOC_DAPM_PRE_PMD | |
| 1176 | SND_SOC_DAPM_POST_PMD), |
| 1177 | SND_SOC_DAPM_OUT_DRV_E("HPR Power", MT6351_AUDDEC_ANA_CON0, |
| 1178 | RG_AUDHPRPWRUP_VAUDP32_BIT, 0, NULL, 0, |
| 1179 | mt_hp_event, |
| 1180 | SND_SOC_DAPM_PRE_PMU | |
| 1181 | SND_SOC_DAPM_PRE_PMD | |
| 1182 | SND_SOC_DAPM_POST_PMD), |
| 1183 | |
| 1184 | /* Receiver */ |
| 1185 | SND_SOC_DAPM_MUX("RCV Mux", SND_SOC_NOPM, 0, 0, &rcv_in_mux_control), |
| 1186 | |
| 1187 | SND_SOC_DAPM_SUPPLY("RCV Stability Enh", MT6351_AUDDEC_ANA_CON1, |
| 1188 | RG_HSOUTPUTSTBENH_VAUDP32_BIT, 0, NULL, 0), |
| 1189 | SND_SOC_DAPM_SUPPLY("RCV Bias Gen", MT6351_AUDDEC_ANA_CON6, |
| 1190 | RG_ABIDEC_RSVD0_VAUDP32_HS_BIT, 0, NULL, 0), |
| 1191 | |
| 1192 | SND_SOC_DAPM_OUT_DRV("RCV Buffer", MT6351_AUDDEC_ANA_CON0, |
| 1193 | RG_AUDHSPWRUP_VAUDP32_BIT, 0, NULL, 0), |
| 1194 | |
| 1195 | /* Outputs */ |
| 1196 | SND_SOC_DAPM_OUTPUT("Receiver"), |
| 1197 | SND_SOC_DAPM_OUTPUT("Headphone L"), |
| 1198 | SND_SOC_DAPM_OUTPUT("Headphone R"), |
| 1199 | SND_SOC_DAPM_OUTPUT("LINEOUT L"), |
| 1200 | |
| 1201 | /* SGEN */ |
| 1202 | SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6351_AFE_SGEN_CFG0, |
| 1203 | SGEN_C_DAC_EN_CTL_BIT, 0, NULL, 0), |
| 1204 | SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6351_AFE_SGEN_CFG0, |
| 1205 | SGEN_C_MUTE_SW_CTL_BIT, 1, |
| 1206 | mt_sgen_event, SND_SOC_DAPM_PRE_PMU), |
| 1207 | SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6351_AFE_DL_SRC2_CON0_L, |
| 1208 | RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT, 0, NULL, 0), |
| 1209 | |
| 1210 | SND_SOC_DAPM_INPUT("SGEN DL"), |
| 1211 | |
| 1212 | /* Uplinks */ |
| 1213 | SND_SOC_DAPM_AIF_OUT_E("AIF1TX", "AIF1 Capture", 0, |
| 1214 | MT6351_AFE_UL_SRC_CON0_L, |
| 1215 | UL_SRC_ON_TMP_CTL, 0, |
| 1216 | mt_aif_out_event, |
| 1217 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1218 | |
| 1219 | SND_SOC_DAPM_SUPPLY_S("VUSB33_LDO", SUPPLY_SUBSEQ_ENABLE, |
| 1220 | MT6351_LDO_VUSB33_CON0, RG_VUSB33_EN, 0, |
| 1221 | NULL, 0), |
| 1222 | SND_SOC_DAPM_SUPPLY_S("VUSB33_LDO_CTRL", SUPPLY_SUBSEQ_SETTING, |
| 1223 | MT6351_LDO_VUSB33_CON0, RG_VUSB33_ON_CTRL, 1, |
| 1224 | NULL, 0), |
| 1225 | |
| 1226 | SND_SOC_DAPM_SUPPLY_S("VA18_LDO", SUPPLY_SUBSEQ_ENABLE, |
| 1227 | MT6351_LDO_VA18_CON0, RG_VA18_EN, 0, NULL, 0), |
| 1228 | SND_SOC_DAPM_SUPPLY_S("VA18_LDO_CTRL", SUPPLY_SUBSEQ_SETTING, |
| 1229 | MT6351_LDO_VA18_CON0, RG_VA18_ON_CTRL, 1, |
| 1230 | NULL, 0), |
| 1231 | |
| 1232 | SND_SOC_DAPM_SUPPLY_S("ADC CLKGEN", SUPPLY_SUBSEQ_ENABLE, |
| 1233 | MT6351_AUDENC_ANA_CON3, RG_AUDADCCLKRSTB, 0, |
| 1234 | mt_adc_clkgen_event, |
| 1235 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
| 1236 | |
| 1237 | /* Uplinks MUX */ |
| 1238 | SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM, 0, 0, |
| 1239 | &aif_out_mux_control), |
| 1240 | |
| 1241 | SND_SOC_DAPM_MUX("ADC L Mux", SND_SOC_NOPM, 0, 0, |
| 1242 | &adc_left_mux_control), |
| 1243 | SND_SOC_DAPM_MUX("ADC R Mux", SND_SOC_NOPM, 0, 0, |
| 1244 | &adc_right_mux_control), |
| 1245 | |
| 1246 | SND_SOC_DAPM_ADC("ADC L", NULL, |
| 1247 | MT6351_AUDENC_ANA_CON0, RG_AUDADCLPWRUP, 0), |
| 1248 | SND_SOC_DAPM_ADC("ADC R", NULL, |
| 1249 | MT6351_AUDENC_ANA_CON1, RG_AUDADCRPWRUP, 0), |
| 1250 | |
| 1251 | SND_SOC_DAPM_MUX("PGA L Mux", SND_SOC_NOPM, 0, 0, |
| 1252 | &pga_left_mux_control), |
| 1253 | SND_SOC_DAPM_MUX("PGA R Mux", SND_SOC_NOPM, 0, 0, |
| 1254 | &pga_right_mux_control), |
| 1255 | |
| 1256 | SND_SOC_DAPM_PGA_E("PGA L", MT6351_AUDENC_ANA_CON0, RG_AUDPREAMPLON, 0, |
| 1257 | NULL, 0, |
| 1258 | mt_pga_left_event, |
| 1259 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
| 1260 | SND_SOC_DAPM_PGA_E("PGA R", MT6351_AUDENC_ANA_CON1, RG_AUDPREAMPRON, 0, |
| 1261 | NULL, 0, |
| 1262 | mt_pga_right_event, |
| 1263 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
| 1264 | |
| 1265 | /* main mic mic bias */ |
| 1266 | SND_SOC_DAPM_SUPPLY_S("Mic Bias 0", SUPPLY_SUBSEQ_MICBIAS, |
| 1267 | MT6351_AUDENC_ANA_CON9, RG_AUDPWDBMICBIAS0, 0, |
| 1268 | mt_mic_bias_0_event, |
| 1269 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1270 | /* ref mic mic bias */ |
| 1271 | SND_SOC_DAPM_SUPPLY_S("Mic Bias 2", SUPPLY_SUBSEQ_MICBIAS, |
| 1272 | MT6351_AUDENC_ANA_CON9, RG_AUDPWDBMICBIAS2, 0, |
| 1273 | mt_mic_bias_2_event, |
| 1274 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1275 | /* headset mic1/2 mic bias */ |
| 1276 | SND_SOC_DAPM_SUPPLY_S("Mic Bias 1", SUPPLY_SUBSEQ_MICBIAS, |
| 1277 | MT6351_AUDENC_ANA_CON10, RG_AUDPWDBMICBIAS1, 0, |
| 1278 | mt_mic_bias_1_event, |
| 1279 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1280 | SND_SOC_DAPM_SUPPLY_S("Mic Bias 1 DCC pull high", SUPPLY_SUBSEQ_MICBIAS, |
| 1281 | MT6351_AUDENC_ANA_CON10, |
| 1282 | RG_AUDMICBIAS1DCSW1NEN, 0, |
| 1283 | NULL, 0), |
| 1284 | |
| 1285 | /* UL input */ |
| 1286 | SND_SOC_DAPM_INPUT("AIN0"), |
| 1287 | SND_SOC_DAPM_INPUT("AIN1"), |
| 1288 | SND_SOC_DAPM_INPUT("AIN2"), |
| 1289 | SND_SOC_DAPM_INPUT("AIN3"), |
| 1290 | }; |
| 1291 | |
| 1292 | static const struct snd_soc_dapm_route mt6351_dapm_routes[] = { |
| 1293 | /* Capture */ |
| 1294 | {"AIF1TX", NULL, "AIF Out Mux"}, |
| 1295 | {"AIF1TX", NULL, "VUSB33_LDO"}, |
| 1296 | {"VUSB33_LDO", NULL, "VUSB33_LDO_CTRL"}, |
| 1297 | {"AIF1TX", NULL, "VA18_LDO"}, |
| 1298 | {"VA18_LDO", NULL, "VA18_LDO_CTRL"}, |
| 1299 | |
| 1300 | {"AIF1TX", NULL, "AUDGLB"}, |
| 1301 | {"AIF1TX", NULL, "CLKSQ Audio"}, |
| 1302 | |
| 1303 | {"AIF1TX", NULL, "AFE_ON"}, |
| 1304 | |
| 1305 | {"AIF1TX", NULL, "AUDIO_TOP_AFE_CTL"}, |
| 1306 | {"AIF1TX", NULL, "AUDIO_TOP_ADC_CTL"}, |
| 1307 | {"AIF1TX", NULL, "AUDIO_TOP_PWR_CLK"}, |
| 1308 | {"AIF1TX", NULL, "AUDIO_TOP_PDN_RESERVED"}, |
| 1309 | |
| 1310 | {"AIF Out Mux", "Normal Path", "ADC L"}, |
| 1311 | {"AIF Out Mux", "Normal Path", "ADC R"}, |
| 1312 | |
| 1313 | {"ADC L", NULL, "ADC L Mux"}, |
| 1314 | {"ADC L", NULL, "AUD_CK"}, |
| 1315 | {"ADC L", NULL, "AUDIF_CK"}, |
| 1316 | {"ADC L", NULL, "ADC CLKGEN"}, |
| 1317 | {"ADC R", NULL, "ADC R Mux"}, |
| 1318 | {"ADC R", NULL, "AUD_CK"}, |
| 1319 | {"ADC R", NULL, "AUDIF_CK"}, |
| 1320 | {"ADC R", NULL, "ADC CLKGEN"}, |
| 1321 | |
| 1322 | {"ADC L Mux", "AIN0", "AIN0"}, |
| 1323 | {"ADC L Mux", "Left Preamplifier", "PGA L"}, |
| 1324 | |
| 1325 | {"ADC R Mux", "AIN0", "AIN0"}, |
| 1326 | {"ADC R Mux", "Right Preamplifier", "PGA R"}, |
| 1327 | |
| 1328 | {"PGA L", NULL, "PGA L Mux"}, |
| 1329 | {"PGA R", NULL, "PGA R Mux"}, |
| 1330 | |
| 1331 | {"PGA L Mux", "AIN0", "AIN0"}, |
| 1332 | {"PGA L Mux", "AIN1", "AIN1"}, |
| 1333 | {"PGA L Mux", "AIN2", "AIN2"}, |
| 1334 | |
| 1335 | {"PGA R Mux", "AIN0", "AIN0"}, |
| 1336 | {"PGA R Mux", "AIN3", "AIN3"}, |
| 1337 | {"PGA R Mux", "AIN2", "AIN2"}, |
| 1338 | |
| 1339 | {"AIN0", NULL, "Mic Bias 0"}, |
| 1340 | {"AIN2", NULL, "Mic Bias 2"}, |
| 1341 | |
| 1342 | {"AIN1", NULL, "Mic Bias 1"}, |
| 1343 | {"AIN1", NULL, "Mic Bias 1 DCC pull high"}, |
| 1344 | |
| 1345 | /* DL Supply */ |
| 1346 | {"DL Power Supply", NULL, "AUDGLB"}, |
| 1347 | {"DL Power Supply", NULL, "CLKSQ Audio"}, |
| 1348 | {"DL Power Supply", NULL, "ZCD13M_CK"}, |
| 1349 | {"DL Power Supply", NULL, "AUD_CK"}, |
| 1350 | {"DL Power Supply", NULL, "AUDIF_CK"}, |
| 1351 | {"DL Power Supply", NULL, "AUDNCP_CK"}, |
| 1352 | |
| 1353 | {"DL Power Supply", NULL, "NV Regulator"}, |
| 1354 | {"DL Power Supply", NULL, "AUD_CLK"}, |
| 1355 | {"DL Power Supply", NULL, "IBIST"}, |
| 1356 | {"DL Power Supply", NULL, "LDO"}, |
| 1357 | {"LDO", NULL, "LDO_REMOTE_SENSE"}, |
| 1358 | |
| 1359 | /* DL Digital Supply */ |
| 1360 | {"DL Digital Clock", NULL, "AUDIO_TOP_AFE_CTL"}, |
| 1361 | {"DL Digital Clock", NULL, "AUDIO_TOP_DAC_CTL"}, |
| 1362 | {"DL Digital Clock", NULL, "AUDIO_TOP_PWR_CLK"}, |
| 1363 | {"DL Digital Clock", NULL, "AUDIO_TOP_PDN_RESERVED"}, |
| 1364 | {"DL Digital Clock", NULL, "NCP"}, |
| 1365 | {"DL Digital Clock", NULL, "AFE_ON"}, |
| 1366 | |
| 1367 | {"AIF_RX", NULL, "DL Digital Clock"}, |
| 1368 | |
| 1369 | /* DL Path */ |
| 1370 | {"DAC In Mux", "Normal Path", "AIF_RX"}, |
| 1371 | |
| 1372 | {"DAC In Mux", "Sgen", "SGEN DL"}, |
| 1373 | {"SGEN DL", NULL, "SGEN DL SRC"}, |
| 1374 | {"SGEN DL", NULL, "SGEN MUTE"}, |
| 1375 | {"SGEN DL", NULL, "SGEN DL Enable"}, |
| 1376 | {"SGEN DL", NULL, "DL Digital Clock"}, |
| 1377 | |
| 1378 | {"DACL", NULL, "DAC In Mux"}, |
| 1379 | {"DACL", NULL, "DL Power Supply"}, |
| 1380 | {"DACL", NULL, "DACL_BIASGEN"}, |
| 1381 | |
| 1382 | {"DACR", NULL, "DAC In Mux"}, |
| 1383 | {"DACR", NULL, "DL Power Supply"}, |
| 1384 | {"DACR", NULL, "DACR_BIASGEN"}, |
| 1385 | |
| 1386 | {"LOL Mux", "Playback", "DACL"}, |
| 1387 | |
| 1388 | {"LOL Buffer", NULL, "LOL Mux"}, |
| 1389 | {"LOL Buffer", NULL, "LO Stability Enh"}, |
| 1390 | {"LOL Buffer", NULL, "LOL Bias Gen"}, |
| 1391 | |
| 1392 | {"LINEOUT L", NULL, "LOL Buffer"}, |
| 1393 | |
| 1394 | /* Headphone Path */ |
| 1395 | {"HPL Mux", "Audio Playback", "DACL"}, |
| 1396 | {"HPR Mux", "Audio Playback", "DACR"}, |
| 1397 | |
| 1398 | {"HPL Mux", "LoudSPK Playback", "DACL"}, |
| 1399 | {"HPR Mux", "LoudSPK Playback", "DACR"}, |
| 1400 | |
| 1401 | {"HPL Power", NULL, "HPL Mux"}, |
| 1402 | {"HPR Power", NULL, "HPR Mux"}, |
| 1403 | |
| 1404 | {"Headphone L", NULL, "HPL Power"}, |
| 1405 | {"Headphone R", NULL, "HPR Power"}, |
| 1406 | |
| 1407 | /* Receiver Path */ |
| 1408 | {"RCV Mux", "Voice Playback", "DACL"}, |
| 1409 | |
| 1410 | {"RCV Buffer", NULL, "RCV Mux"}, |
| 1411 | {"RCV Buffer", NULL, "RCV Stability Enh"}, |
| 1412 | {"RCV Buffer", NULL, "RCV Bias Gen"}, |
| 1413 | |
| 1414 | {"Receiver", NULL, "RCV Buffer"}, |
| 1415 | }; |
| 1416 | |
| 1417 | static int mt6351_codec_init_reg(struct snd_soc_component *cmpnt) |
| 1418 | { |
| 1419 | int ret = 0; |
| 1420 | |
| 1421 | /* Disable CLKSQ 26MHz */ |
| 1422 | regmap_update_bits(cmpnt->regmap, MT6351_TOP_CLKSQ, 0x0001, 0x0); |
| 1423 | /* disable AUDGLB */ |
| 1424 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON9, |
| 1425 | 0x1000, 0x1000); |
| 1426 | /* Turn off AUDNCP_CLKDIV engine clock,Turn off AUD 26M */ |
| 1427 | regmap_update_bits(cmpnt->regmap, MT6351_TOP_CKPDN_CON0_SET, |
| 1428 | 0x3800, 0x3800); |
| 1429 | /* Disable HeadphoneL/HeadphoneR/voice short circuit protection */ |
| 1430 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, |
| 1431 | 0xe000, 0xe000); |
| 1432 | /* [5] = 1, disable LO buffer left short circuit protection */ |
| 1433 | regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON3, |
| 1434 | 0x20, 0x20); |
| 1435 | /* Reverse the PMIC clock*/ |
| 1436 | regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2, |
| 1437 | 0x8000, 0x8000); |
| 1438 | return ret; |
| 1439 | } |
| 1440 | |
| 1441 | static int mt6351_codec_probe(struct snd_soc_component *cmpnt) |
| 1442 | { |
| 1443 | struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt); |
| 1444 | |
| 1445 | snd_soc_component_init_regmap(cmpnt, priv->regmap); |
| 1446 | |
| 1447 | mt6351_codec_init_reg(cmpnt); |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | static const struct snd_soc_component_driver mt6351_soc_component_driver = { |
| 1452 | .probe = mt6351_codec_probe, |
| 1453 | .controls = mt6351_snd_controls, |
| 1454 | .num_controls = ARRAY_SIZE(mt6351_snd_controls), |
| 1455 | .dapm_widgets = mt6351_dapm_widgets, |
| 1456 | .num_dapm_widgets = ARRAY_SIZE(mt6351_dapm_widgets), |
| 1457 | .dapm_routes = mt6351_dapm_routes, |
| 1458 | .num_dapm_routes = ARRAY_SIZE(mt6351_dapm_routes), |
| 1459 | }; |
| 1460 | |
| 1461 | static int mt6351_codec_driver_probe(struct platform_device *pdev) |
| 1462 | { |
| 1463 | struct mt6351_priv *priv; |
| 1464 | |
| 1465 | priv = devm_kzalloc(&pdev->dev, |
| 1466 | sizeof(struct mt6351_priv), |
| 1467 | GFP_KERNEL); |
| 1468 | if (!priv) |
| 1469 | return -ENOMEM; |
| 1470 | |
| 1471 | dev_set_drvdata(&pdev->dev, priv); |
| 1472 | |
| 1473 | priv->dev = &pdev->dev; |
| 1474 | |
| 1475 | priv->regmap = dev_get_regmap(pdev->dev.parent, NULL); |
| 1476 | if (IS_ERR(priv->regmap)) |
| 1477 | return PTR_ERR(priv->regmap); |
| 1478 | |
| 1479 | dev_dbg(priv->dev, "%s(), dev name %s\n", |
| 1480 | __func__, dev_name(&pdev->dev)); |
| 1481 | |
| 1482 | return devm_snd_soc_register_component(&pdev->dev, |
| 1483 | &mt6351_soc_component_driver, |
| 1484 | mt6351_dai_driver, |
| 1485 | ARRAY_SIZE(mt6351_dai_driver)); |
| 1486 | } |
| 1487 | |
| 1488 | static const struct of_device_id mt6351_of_match[] = { |
| 1489 | {.compatible = "mediatek,mt6351-sound",}, |
| 1490 | {} |
| 1491 | }; |
| 1492 | |
| 1493 | static struct platform_driver mt6351_codec_driver = { |
| 1494 | .driver = { |
| 1495 | .name = "mt6351-sound", |
| 1496 | .of_match_table = mt6351_of_match, |
| 1497 | }, |
| 1498 | .probe = mt6351_codec_driver_probe, |
| 1499 | }; |
| 1500 | |
| 1501 | module_platform_driver(mt6351_codec_driver) |
| 1502 | |
| 1503 | /* Module information */ |
| 1504 | MODULE_DESCRIPTION("MT6351 ALSA SoC codec driver"); |
| 1505 | MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>"); |
| 1506 | MODULE_LICENSE("GPL v2"); |