1 /* 2 * rt5670.c -- RT5670 ALSA SoC audio codec driver 3 * 4 * Copyright 2014 Realtek Semiconductor Corp. 5 * Author: Bard Liao <bardliao@realtek.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #include <linux/module.h> 13 #include <linux/moduleparam.h> 14 #include <linux/init.h> 15 #include <linux/delay.h> 16 #include <linux/pm.h> 17 #include <linux/i2c.h> 18 #include <linux/platform_device.h> 19 #include <linux/acpi.h> 20 #include <linux/spi/spi.h> 21 #include <sound/core.h> 22 #include <sound/pcm.h> 23 #include <sound/pcm_params.h> 24 #include <sound/jack.h> 25 #include <sound/soc.h> 26 #include <sound/soc-dapm.h> 27 #include <sound/initval.h> 28 #include <sound/tlv.h> 29 #include <sound/rt5670.h> 30 31 #include "rl6231.h" 32 #include "rt5670.h" 33 #include "rt5670-dsp.h" 34 35 #define RT5670_DEVICE_ID 0x6271 36 37 #define RT5670_PR_RANGE_BASE (0xff + 1) 38 #define RT5670_PR_SPACING 0x100 39 40 #define RT5670_PR_BASE (RT5670_PR_RANGE_BASE + (0 * RT5670_PR_SPACING)) 41 42 static const struct regmap_range_cfg rt5670_ranges[] = { 43 { .name = "PR", .range_min = RT5670_PR_BASE, 44 .range_max = RT5670_PR_BASE + 0xf8, 45 .selector_reg = RT5670_PRIV_INDEX, 46 .selector_mask = 0xff, 47 .selector_shift = 0x0, 48 .window_start = RT5670_PRIV_DATA, 49 .window_len = 0x1, }, 50 }; 51 52 static struct reg_default init_list[] = { 53 { RT5670_PR_BASE + 0x14, 0x9a8a }, 54 { RT5670_PR_BASE + 0x38, 0x3ba1 }, 55 { RT5670_PR_BASE + 0x3d, 0x3640 }, 56 }; 57 #define RT5670_INIT_REG_LEN ARRAY_SIZE(init_list) 58 59 static const struct reg_default rt5670_reg[] = { 60 { 0x00, 0x0000 }, 61 { 0x02, 0x8888 }, 62 { 0x03, 0x8888 }, 63 { 0x0a, 0x0001 }, 64 { 0x0b, 0x0827 }, 65 { 0x0c, 0x0000 }, 66 { 0x0d, 0x0008 }, 67 { 0x0e, 0x0000 }, 68 { 0x0f, 0x0808 }, 69 { 0x19, 0xafaf }, 70 { 0x1a, 0xafaf }, 71 { 0x1b, 0x0011 }, 72 { 0x1c, 0x2f2f }, 73 { 0x1d, 0x2f2f }, 74 { 0x1e, 0x0000 }, 75 { 0x1f, 0x2f2f }, 76 { 0x20, 0x0000 }, 77 { 0x26, 0x7860 }, 78 { 0x27, 0x7860 }, 79 { 0x28, 0x7871 }, 80 { 0x29, 0x8080 }, 81 { 0x2a, 0x5656 }, 82 { 0x2b, 0x5454 }, 83 { 0x2c, 0xaaa0 }, 84 { 0x2d, 0x0000 }, 85 { 0x2e, 0x2f2f }, 86 { 0x2f, 0x1002 }, 87 { 0x30, 0x0000 }, 88 { 0x31, 0x5f00 }, 89 { 0x32, 0x0000 }, 90 { 0x33, 0x0000 }, 91 { 0x34, 0x0000 }, 92 { 0x35, 0x0000 }, 93 { 0x36, 0x0000 }, 94 { 0x37, 0x0000 }, 95 { 0x38, 0x0000 }, 96 { 0x3b, 0x0000 }, 97 { 0x3c, 0x007f }, 98 { 0x3d, 0x0000 }, 99 { 0x3e, 0x007f }, 100 { 0x45, 0xe00f }, 101 { 0x4c, 0x5380 }, 102 { 0x4f, 0x0073 }, 103 { 0x52, 0x00d3 }, 104 { 0x53, 0xf000 }, 105 { 0x61, 0x0000 }, 106 { 0x62, 0x0001 }, 107 { 0x63, 0x00c3 }, 108 { 0x64, 0x0000 }, 109 { 0x65, 0x0001 }, 110 { 0x66, 0x0000 }, 111 { 0x6f, 0x8000 }, 112 { 0x70, 0x8000 }, 113 { 0x71, 0x8000 }, 114 { 0x72, 0x8000 }, 115 { 0x73, 0x7770 }, 116 { 0x74, 0x0e00 }, 117 { 0x75, 0x1505 }, 118 { 0x76, 0x0015 }, 119 { 0x77, 0x0c00 }, 120 { 0x78, 0x4000 }, 121 { 0x79, 0x0123 }, 122 { 0x7f, 0x1100 }, 123 { 0x80, 0x0000 }, 124 { 0x81, 0x0000 }, 125 { 0x82, 0x0000 }, 126 { 0x83, 0x0000 }, 127 { 0x84, 0x0000 }, 128 { 0x85, 0x0000 }, 129 { 0x86, 0x0004 }, 130 { 0x87, 0x0000 }, 131 { 0x88, 0x0000 }, 132 { 0x89, 0x0000 }, 133 { 0x8a, 0x0000 }, 134 { 0x8b, 0x0000 }, 135 { 0x8c, 0x0003 }, 136 { 0x8d, 0x0000 }, 137 { 0x8e, 0x0004 }, 138 { 0x8f, 0x1100 }, 139 { 0x90, 0x0646 }, 140 { 0x91, 0x0c06 }, 141 { 0x93, 0x0000 }, 142 { 0x94, 0x1270 }, 143 { 0x95, 0x1000 }, 144 { 0x97, 0x0000 }, 145 { 0x98, 0x0000 }, 146 { 0x99, 0x0000 }, 147 { 0x9a, 0x2184 }, 148 { 0x9b, 0x010a }, 149 { 0x9c, 0x0aea }, 150 { 0x9d, 0x000c }, 151 { 0x9e, 0x0400 }, 152 { 0xae, 0x7000 }, 153 { 0xaf, 0x0000 }, 154 { 0xb0, 0x7000 }, 155 { 0xb1, 0x0000 }, 156 { 0xb2, 0x0000 }, 157 { 0xb3, 0x001f }, 158 { 0xb4, 0x220c }, 159 { 0xb5, 0x1f00 }, 160 { 0xb6, 0x0000 }, 161 { 0xb7, 0x0000 }, 162 { 0xbb, 0x0000 }, 163 { 0xbc, 0x0000 }, 164 { 0xbd, 0x0000 }, 165 { 0xbe, 0x0000 }, 166 { 0xbf, 0x0000 }, 167 { 0xc0, 0x0000 }, 168 { 0xc1, 0x0000 }, 169 { 0xc2, 0x0000 }, 170 { 0xcd, 0x0000 }, 171 { 0xce, 0x0000 }, 172 { 0xcf, 0x1813 }, 173 { 0xd0, 0x0690 }, 174 { 0xd1, 0x1c17 }, 175 { 0xd3, 0xa220 }, 176 { 0xd4, 0x0000 }, 177 { 0xd6, 0x0400 }, 178 { 0xd9, 0x0809 }, 179 { 0xda, 0x0000 }, 180 { 0xdb, 0x0001 }, 181 { 0xdc, 0x0049 }, 182 { 0xdd, 0x0024 }, 183 { 0xe6, 0x8000 }, 184 { 0xe7, 0x0000 }, 185 { 0xec, 0xa200 }, 186 { 0xed, 0x0000 }, 187 { 0xee, 0xa200 }, 188 { 0xef, 0x0000 }, 189 { 0xf8, 0x0000 }, 190 { 0xf9, 0x0000 }, 191 { 0xfa, 0x8010 }, 192 { 0xfb, 0x0033 }, 193 { 0xfc, 0x0100 }, 194 }; 195 196 static bool rt5670_volatile_register(struct device *dev, unsigned int reg) 197 { 198 int i; 199 200 for (i = 0; i < ARRAY_SIZE(rt5670_ranges); i++) { 201 if ((reg >= rt5670_ranges[i].window_start && 202 reg <= rt5670_ranges[i].window_start + 203 rt5670_ranges[i].window_len) || 204 (reg >= rt5670_ranges[i].range_min && 205 reg <= rt5670_ranges[i].range_max)) { 206 return true; 207 } 208 } 209 210 switch (reg) { 211 case RT5670_RESET: 212 case RT5670_PDM_DATA_CTRL1: 213 case RT5670_PDM1_DATA_CTRL4: 214 case RT5670_PDM2_DATA_CTRL4: 215 case RT5670_PRIV_DATA: 216 case RT5670_ASRC_5: 217 case RT5670_CJ_CTRL1: 218 case RT5670_CJ_CTRL2: 219 case RT5670_CJ_CTRL3: 220 case RT5670_A_JD_CTRL1: 221 case RT5670_A_JD_CTRL2: 222 case RT5670_VAD_CTRL5: 223 case RT5670_ADC_EQ_CTRL1: 224 case RT5670_EQ_CTRL1: 225 case RT5670_ALC_CTRL_1: 226 case RT5670_IRQ_CTRL1: 227 case RT5670_IRQ_CTRL2: 228 case RT5670_INT_IRQ_ST: 229 case RT5670_IL_CMD: 230 case RT5670_DSP_CTRL1: 231 case RT5670_DSP_CTRL2: 232 case RT5670_DSP_CTRL3: 233 case RT5670_DSP_CTRL4: 234 case RT5670_DSP_CTRL5: 235 case RT5670_VENDOR_ID: 236 case RT5670_VENDOR_ID1: 237 case RT5670_VENDOR_ID2: 238 return true; 239 default: 240 return false; 241 } 242 } 243 244 static bool rt5670_readable_register(struct device *dev, unsigned int reg) 245 { 246 int i; 247 248 for (i = 0; i < ARRAY_SIZE(rt5670_ranges); i++) { 249 if ((reg >= rt5670_ranges[i].window_start && 250 reg <= rt5670_ranges[i].window_start + 251 rt5670_ranges[i].window_len) || 252 (reg >= rt5670_ranges[i].range_min && 253 reg <= rt5670_ranges[i].range_max)) { 254 return true; 255 } 256 } 257 258 switch (reg) { 259 case RT5670_RESET: 260 case RT5670_HP_VOL: 261 case RT5670_LOUT1: 262 case RT5670_CJ_CTRL1: 263 case RT5670_CJ_CTRL2: 264 case RT5670_CJ_CTRL3: 265 case RT5670_IN2: 266 case RT5670_INL1_INR1_VOL: 267 case RT5670_DAC1_DIG_VOL: 268 case RT5670_DAC2_DIG_VOL: 269 case RT5670_DAC_CTRL: 270 case RT5670_STO1_ADC_DIG_VOL: 271 case RT5670_MONO_ADC_DIG_VOL: 272 case RT5670_STO2_ADC_DIG_VOL: 273 case RT5670_ADC_BST_VOL1: 274 case RT5670_ADC_BST_VOL2: 275 case RT5670_STO2_ADC_MIXER: 276 case RT5670_STO1_ADC_MIXER: 277 case RT5670_MONO_ADC_MIXER: 278 case RT5670_AD_DA_MIXER: 279 case RT5670_STO_DAC_MIXER: 280 case RT5670_DD_MIXER: 281 case RT5670_DIG_MIXER: 282 case RT5670_DSP_PATH1: 283 case RT5670_DSP_PATH2: 284 case RT5670_DIG_INF1_DATA: 285 case RT5670_DIG_INF2_DATA: 286 case RT5670_PDM_OUT_CTRL: 287 case RT5670_PDM_DATA_CTRL1: 288 case RT5670_PDM1_DATA_CTRL2: 289 case RT5670_PDM1_DATA_CTRL3: 290 case RT5670_PDM1_DATA_CTRL4: 291 case RT5670_PDM2_DATA_CTRL2: 292 case RT5670_PDM2_DATA_CTRL3: 293 case RT5670_PDM2_DATA_CTRL4: 294 case RT5670_REC_L1_MIXER: 295 case RT5670_REC_L2_MIXER: 296 case RT5670_REC_R1_MIXER: 297 case RT5670_REC_R2_MIXER: 298 case RT5670_HPO_MIXER: 299 case RT5670_MONO_MIXER: 300 case RT5670_OUT_L1_MIXER: 301 case RT5670_OUT_R1_MIXER: 302 case RT5670_LOUT_MIXER: 303 case RT5670_PWR_DIG1: 304 case RT5670_PWR_DIG2: 305 case RT5670_PWR_ANLG1: 306 case RT5670_PWR_ANLG2: 307 case RT5670_PWR_MIXER: 308 case RT5670_PWR_VOL: 309 case RT5670_PRIV_INDEX: 310 case RT5670_PRIV_DATA: 311 case RT5670_I2S4_SDP: 312 case RT5670_I2S1_SDP: 313 case RT5670_I2S2_SDP: 314 case RT5670_I2S3_SDP: 315 case RT5670_ADDA_CLK1: 316 case RT5670_ADDA_CLK2: 317 case RT5670_DMIC_CTRL1: 318 case RT5670_DMIC_CTRL2: 319 case RT5670_TDM_CTRL_1: 320 case RT5670_TDM_CTRL_2: 321 case RT5670_TDM_CTRL_3: 322 case RT5670_DSP_CLK: 323 case RT5670_GLB_CLK: 324 case RT5670_PLL_CTRL1: 325 case RT5670_PLL_CTRL2: 326 case RT5670_ASRC_1: 327 case RT5670_ASRC_2: 328 case RT5670_ASRC_3: 329 case RT5670_ASRC_4: 330 case RT5670_ASRC_5: 331 case RT5670_ASRC_7: 332 case RT5670_ASRC_8: 333 case RT5670_ASRC_9: 334 case RT5670_ASRC_10: 335 case RT5670_ASRC_11: 336 case RT5670_ASRC_12: 337 case RT5670_ASRC_13: 338 case RT5670_ASRC_14: 339 case RT5670_DEPOP_M1: 340 case RT5670_DEPOP_M2: 341 case RT5670_DEPOP_M3: 342 case RT5670_CHARGE_PUMP: 343 case RT5670_MICBIAS: 344 case RT5670_A_JD_CTRL1: 345 case RT5670_A_JD_CTRL2: 346 case RT5670_VAD_CTRL1: 347 case RT5670_VAD_CTRL2: 348 case RT5670_VAD_CTRL3: 349 case RT5670_VAD_CTRL4: 350 case RT5670_VAD_CTRL5: 351 case RT5670_ADC_EQ_CTRL1: 352 case RT5670_ADC_EQ_CTRL2: 353 case RT5670_EQ_CTRL1: 354 case RT5670_EQ_CTRL2: 355 case RT5670_ALC_DRC_CTRL1: 356 case RT5670_ALC_DRC_CTRL2: 357 case RT5670_ALC_CTRL_1: 358 case RT5670_ALC_CTRL_2: 359 case RT5670_ALC_CTRL_3: 360 case RT5670_JD_CTRL: 361 case RT5670_IRQ_CTRL1: 362 case RT5670_IRQ_CTRL2: 363 case RT5670_INT_IRQ_ST: 364 case RT5670_GPIO_CTRL1: 365 case RT5670_GPIO_CTRL2: 366 case RT5670_GPIO_CTRL3: 367 case RT5670_SCRABBLE_FUN: 368 case RT5670_SCRABBLE_CTRL: 369 case RT5670_BASE_BACK: 370 case RT5670_MP3_PLUS1: 371 case RT5670_MP3_PLUS2: 372 case RT5670_ADJ_HPF1: 373 case RT5670_ADJ_HPF2: 374 case RT5670_HP_CALIB_AMP_DET: 375 case RT5670_SV_ZCD1: 376 case RT5670_SV_ZCD2: 377 case RT5670_IL_CMD: 378 case RT5670_IL_CMD2: 379 case RT5670_IL_CMD3: 380 case RT5670_DRC_HL_CTRL1: 381 case RT5670_DRC_HL_CTRL2: 382 case RT5670_ADC_MONO_HP_CTRL1: 383 case RT5670_ADC_MONO_HP_CTRL2: 384 case RT5670_ADC_STO2_HP_CTRL1: 385 case RT5670_ADC_STO2_HP_CTRL2: 386 case RT5670_JD_CTRL3: 387 case RT5670_JD_CTRL4: 388 case RT5670_DIG_MISC: 389 case RT5670_DSP_CTRL1: 390 case RT5670_DSP_CTRL2: 391 case RT5670_DSP_CTRL3: 392 case RT5670_DSP_CTRL4: 393 case RT5670_DSP_CTRL5: 394 case RT5670_GEN_CTRL2: 395 case RT5670_GEN_CTRL3: 396 case RT5670_VENDOR_ID: 397 case RT5670_VENDOR_ID1: 398 case RT5670_VENDOR_ID2: 399 return true; 400 default: 401 return false; 402 } 403 } 404 405 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); 406 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); 407 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); 408 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0); 409 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 410 411 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */ 412 static unsigned int bst_tlv[] = { 413 TLV_DB_RANGE_HEAD(7), 414 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), 415 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), 416 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0), 417 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0), 418 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0), 419 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0), 420 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0), 421 }; 422 423 /* Interface data select */ 424 static const char * const rt5670_data_select[] = { 425 "Normal", "Swap", "left copy to right", "right copy to left" 426 }; 427 428 static SOC_ENUM_SINGLE_DECL(rt5670_if2_dac_enum, RT5670_DIG_INF1_DATA, 429 RT5670_IF2_DAC_SEL_SFT, rt5670_data_select); 430 431 static SOC_ENUM_SINGLE_DECL(rt5670_if2_adc_enum, RT5670_DIG_INF1_DATA, 432 RT5670_IF2_ADC_SEL_SFT, rt5670_data_select); 433 434 static const struct snd_kcontrol_new rt5670_snd_controls[] = { 435 /* Headphone Output Volume */ 436 SOC_DOUBLE("HP Playback Switch", RT5670_HP_VOL, 437 RT5670_L_MUTE_SFT, RT5670_R_MUTE_SFT, 1, 1), 438 SOC_DOUBLE_TLV("HP Playback Volume", RT5670_HP_VOL, 439 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 440 39, 0, out_vol_tlv), 441 /* OUTPUT Control */ 442 SOC_DOUBLE("OUT Channel Switch", RT5670_LOUT1, 443 RT5670_VOL_L_SFT, RT5670_VOL_R_SFT, 1, 1), 444 SOC_DOUBLE_TLV("OUT Playback Volume", RT5670_LOUT1, 445 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 39, 1, out_vol_tlv), 446 /* DAC Digital Volume */ 447 SOC_DOUBLE("DAC2 Playback Switch", RT5670_DAC_CTRL, 448 RT5670_M_DAC_L2_VOL_SFT, RT5670_M_DAC_R2_VOL_SFT, 1, 1), 449 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5670_DAC1_DIG_VOL, 450 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 451 175, 0, dac_vol_tlv), 452 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5670_DAC2_DIG_VOL, 453 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 454 175, 0, dac_vol_tlv), 455 /* IN1/IN2 Control */ 456 SOC_SINGLE_TLV("IN1 Boost Volume", RT5670_CJ_CTRL1, 457 RT5670_BST_SFT1, 8, 0, bst_tlv), 458 SOC_SINGLE_TLV("IN2 Boost Volume", RT5670_IN2, 459 RT5670_BST_SFT1, 8, 0, bst_tlv), 460 /* INL/INR Volume Control */ 461 SOC_DOUBLE_TLV("IN Capture Volume", RT5670_INL1_INR1_VOL, 462 RT5670_INL_VOL_SFT, RT5670_INR_VOL_SFT, 463 31, 1, in_vol_tlv), 464 /* ADC Digital Volume Control */ 465 SOC_DOUBLE("ADC Capture Switch", RT5670_STO1_ADC_DIG_VOL, 466 RT5670_L_MUTE_SFT, RT5670_R_MUTE_SFT, 1, 1), 467 SOC_DOUBLE_TLV("ADC Capture Volume", RT5670_STO1_ADC_DIG_VOL, 468 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 469 127, 0, adc_vol_tlv), 470 471 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5670_MONO_ADC_DIG_VOL, 472 RT5670_L_VOL_SFT, RT5670_R_VOL_SFT, 473 127, 0, adc_vol_tlv), 474 475 /* ADC Boost Volume Control */ 476 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5670_ADC_BST_VOL1, 477 RT5670_STO1_ADC_L_BST_SFT, RT5670_STO1_ADC_R_BST_SFT, 478 3, 0, adc_bst_tlv), 479 480 SOC_DOUBLE_TLV("STO2 ADC Boost Gain Volume", RT5670_ADC_BST_VOL1, 481 RT5670_STO2_ADC_L_BST_SFT, RT5670_STO2_ADC_R_BST_SFT, 482 3, 0, adc_bst_tlv), 483 484 SOC_ENUM("ADC IF2 Data Switch", rt5670_if2_adc_enum), 485 SOC_ENUM("DAC IF2 Data Switch", rt5670_if2_dac_enum), 486 }; 487 488 /** 489 * set_dmic_clk - Set parameter of dmic. 490 * 491 * @w: DAPM widget. 492 * @kcontrol: The kcontrol of this widget. 493 * @event: Event id. 494 * 495 * Choose dmic clock between 1MHz and 3MHz. 496 * It is better for clock to approximate 3MHz. 497 */ 498 static int set_dmic_clk(struct snd_soc_dapm_widget *w, 499 struct snd_kcontrol *kcontrol, int event) 500 { 501 struct snd_soc_codec *codec = w->codec; 502 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 503 int idx = -EINVAL; 504 505 idx = rl6231_calc_dmic_clk(rt5670->sysclk); 506 507 if (idx < 0) 508 dev_err(codec->dev, "Failed to set DMIC clock\n"); 509 else 510 snd_soc_update_bits(codec, RT5670_DMIC_CTRL1, 511 RT5670_DMIC_CLK_MASK, idx << RT5670_DMIC_CLK_SFT); 512 return idx; 513 } 514 515 static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 516 struct snd_soc_dapm_widget *sink) 517 { 518 unsigned int val; 519 520 val = snd_soc_read(source->codec, RT5670_GLB_CLK); 521 val &= RT5670_SCLK_SRC_MASK; 522 if (val == RT5670_SCLK_SRC_PLL1) 523 return 1; 524 else 525 return 0; 526 } 527 528 static int is_using_asrc(struct snd_soc_dapm_widget *source, 529 struct snd_soc_dapm_widget *sink) 530 { 531 unsigned int reg, shift, val; 532 533 switch (source->shift) { 534 case 0: 535 reg = RT5670_ASRC_3; 536 shift = 0; 537 break; 538 case 1: 539 reg = RT5670_ASRC_3; 540 shift = 4; 541 break; 542 case 2: 543 reg = RT5670_ASRC_5; 544 shift = 12; 545 break; 546 case 3: 547 reg = RT5670_ASRC_2; 548 shift = 0; 549 break; 550 case 8: 551 reg = RT5670_ASRC_2; 552 shift = 4; 553 break; 554 case 9: 555 reg = RT5670_ASRC_2; 556 shift = 8; 557 break; 558 case 10: 559 reg = RT5670_ASRC_2; 560 shift = 12; 561 break; 562 default: 563 return 0; 564 } 565 566 val = (snd_soc_read(source->codec, reg) >> shift) & 0xf; 567 switch (val) { 568 case 1: 569 case 2: 570 case 3: 571 case 4: 572 return 1; 573 default: 574 return 0; 575 } 576 577 } 578 579 static int can_use_asrc(struct snd_soc_dapm_widget *source, 580 struct snd_soc_dapm_widget *sink) 581 { 582 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm); 583 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 584 585 if (rt5670->sysclk > rt5670->lrck[RT5670_AIF1] * 384) 586 return 1; 587 588 return 0; 589 } 590 591 /* Digital Mixer */ 592 static const struct snd_kcontrol_new rt5670_sto1_adc_l_mix[] = { 593 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER, 594 RT5670_M_ADC_L1_SFT, 1, 1), 595 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_STO1_ADC_MIXER, 596 RT5670_M_ADC_L2_SFT, 1, 1), 597 }; 598 599 static const struct snd_kcontrol_new rt5670_sto1_adc_r_mix[] = { 600 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER, 601 RT5670_M_ADC_R1_SFT, 1, 1), 602 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_STO1_ADC_MIXER, 603 RT5670_M_ADC_R2_SFT, 1, 1), 604 }; 605 606 static const struct snd_kcontrol_new rt5670_sto2_adc_l_mix[] = { 607 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO2_ADC_MIXER, 608 RT5670_M_ADC_L1_SFT, 1, 1), 609 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_STO2_ADC_MIXER, 610 RT5670_M_ADC_L2_SFT, 1, 1), 611 }; 612 613 static const struct snd_kcontrol_new rt5670_sto2_adc_r_mix[] = { 614 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO2_ADC_MIXER, 615 RT5670_M_ADC_R1_SFT, 1, 1), 616 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_STO2_ADC_MIXER, 617 RT5670_M_ADC_R2_SFT, 1, 1), 618 }; 619 620 static const struct snd_kcontrol_new rt5670_mono_adc_l_mix[] = { 621 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_MONO_ADC_MIXER, 622 RT5670_M_MONO_ADC_L1_SFT, 1, 1), 623 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_MONO_ADC_MIXER, 624 RT5670_M_MONO_ADC_L2_SFT, 1, 1), 625 }; 626 627 static const struct snd_kcontrol_new rt5670_mono_adc_r_mix[] = { 628 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_MONO_ADC_MIXER, 629 RT5670_M_MONO_ADC_R1_SFT, 1, 1), 630 SOC_DAPM_SINGLE("ADC2 Switch", RT5670_MONO_ADC_MIXER, 631 RT5670_M_MONO_ADC_R2_SFT, 1, 1), 632 }; 633 634 static const struct snd_kcontrol_new rt5670_dac_l_mix[] = { 635 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5670_AD_DA_MIXER, 636 RT5670_M_ADCMIX_L_SFT, 1, 1), 637 SOC_DAPM_SINGLE("DAC1 Switch", RT5670_AD_DA_MIXER, 638 RT5670_M_DAC1_L_SFT, 1, 1), 639 }; 640 641 static const struct snd_kcontrol_new rt5670_dac_r_mix[] = { 642 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5670_AD_DA_MIXER, 643 RT5670_M_ADCMIX_R_SFT, 1, 1), 644 SOC_DAPM_SINGLE("DAC1 Switch", RT5670_AD_DA_MIXER, 645 RT5670_M_DAC1_R_SFT, 1, 1), 646 }; 647 648 static const struct snd_kcontrol_new rt5670_sto_dac_l_mix[] = { 649 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_STO_DAC_MIXER, 650 RT5670_M_DAC_L1_SFT, 1, 1), 651 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_STO_DAC_MIXER, 652 RT5670_M_DAC_L2_SFT, 1, 1), 653 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_STO_DAC_MIXER, 654 RT5670_M_DAC_R1_STO_L_SFT, 1, 1), 655 }; 656 657 static const struct snd_kcontrol_new rt5670_sto_dac_r_mix[] = { 658 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_STO_DAC_MIXER, 659 RT5670_M_DAC_R1_SFT, 1, 1), 660 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_STO_DAC_MIXER, 661 RT5670_M_DAC_R2_SFT, 1, 1), 662 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_STO_DAC_MIXER, 663 RT5670_M_DAC_L1_STO_R_SFT, 1, 1), 664 }; 665 666 static const struct snd_kcontrol_new rt5670_mono_dac_l_mix[] = { 667 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_DD_MIXER, 668 RT5670_M_DAC_L1_MONO_L_SFT, 1, 1), 669 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_DD_MIXER, 670 RT5670_M_DAC_L2_MONO_L_SFT, 1, 1), 671 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_DD_MIXER, 672 RT5670_M_DAC_R2_MONO_L_SFT, 1, 1), 673 }; 674 675 static const struct snd_kcontrol_new rt5670_mono_dac_r_mix[] = { 676 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_DD_MIXER, 677 RT5670_M_DAC_R1_MONO_R_SFT, 1, 1), 678 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_DD_MIXER, 679 RT5670_M_DAC_R2_MONO_R_SFT, 1, 1), 680 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_DD_MIXER, 681 RT5670_M_DAC_L2_MONO_R_SFT, 1, 1), 682 }; 683 684 static const struct snd_kcontrol_new rt5670_dig_l_mix[] = { 685 SOC_DAPM_SINGLE("Sto DAC Mix L Switch", RT5670_DIG_MIXER, 686 RT5670_M_STO_L_DAC_L_SFT, 1, 1), 687 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_DIG_MIXER, 688 RT5670_M_DAC_L2_DAC_L_SFT, 1, 1), 689 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_DIG_MIXER, 690 RT5670_M_DAC_R2_DAC_L_SFT, 1, 1), 691 }; 692 693 static const struct snd_kcontrol_new rt5670_dig_r_mix[] = { 694 SOC_DAPM_SINGLE("Sto DAC Mix R Switch", RT5670_DIG_MIXER, 695 RT5670_M_STO_R_DAC_R_SFT, 1, 1), 696 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_DIG_MIXER, 697 RT5670_M_DAC_R2_DAC_R_SFT, 1, 1), 698 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_DIG_MIXER, 699 RT5670_M_DAC_L2_DAC_R_SFT, 1, 1), 700 }; 701 702 /* Analog Input Mixer */ 703 static const struct snd_kcontrol_new rt5670_rec_l_mix[] = { 704 SOC_DAPM_SINGLE("INL Switch", RT5670_REC_L2_MIXER, 705 RT5670_M_IN_L_RM_L_SFT, 1, 1), 706 SOC_DAPM_SINGLE("BST2 Switch", RT5670_REC_L2_MIXER, 707 RT5670_M_BST2_RM_L_SFT, 1, 1), 708 SOC_DAPM_SINGLE("BST1 Switch", RT5670_REC_L2_MIXER, 709 RT5670_M_BST1_RM_L_SFT, 1, 1), 710 }; 711 712 static const struct snd_kcontrol_new rt5670_rec_r_mix[] = { 713 SOC_DAPM_SINGLE("INR Switch", RT5670_REC_R2_MIXER, 714 RT5670_M_IN_R_RM_R_SFT, 1, 1), 715 SOC_DAPM_SINGLE("BST2 Switch", RT5670_REC_R2_MIXER, 716 RT5670_M_BST2_RM_R_SFT, 1, 1), 717 SOC_DAPM_SINGLE("BST1 Switch", RT5670_REC_R2_MIXER, 718 RT5670_M_BST1_RM_R_SFT, 1, 1), 719 }; 720 721 static const struct snd_kcontrol_new rt5670_out_l_mix[] = { 722 SOC_DAPM_SINGLE("BST1 Switch", RT5670_OUT_L1_MIXER, 723 RT5670_M_BST1_OM_L_SFT, 1, 1), 724 SOC_DAPM_SINGLE("INL Switch", RT5670_OUT_L1_MIXER, 725 RT5670_M_IN_L_OM_L_SFT, 1, 1), 726 SOC_DAPM_SINGLE("DAC L2 Switch", RT5670_OUT_L1_MIXER, 727 RT5670_M_DAC_L2_OM_L_SFT, 1, 1), 728 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_OUT_L1_MIXER, 729 RT5670_M_DAC_L1_OM_L_SFT, 1, 1), 730 }; 731 732 static const struct snd_kcontrol_new rt5670_out_r_mix[] = { 733 SOC_DAPM_SINGLE("BST2 Switch", RT5670_OUT_R1_MIXER, 734 RT5670_M_BST2_OM_R_SFT, 1, 1), 735 SOC_DAPM_SINGLE("INR Switch", RT5670_OUT_R1_MIXER, 736 RT5670_M_IN_R_OM_R_SFT, 1, 1), 737 SOC_DAPM_SINGLE("DAC R2 Switch", RT5670_OUT_R1_MIXER, 738 RT5670_M_DAC_R2_OM_R_SFT, 1, 1), 739 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_OUT_R1_MIXER, 740 RT5670_M_DAC_R1_OM_R_SFT, 1, 1), 741 }; 742 743 static const struct snd_kcontrol_new rt5670_hpo_mix[] = { 744 SOC_DAPM_SINGLE("DAC1 Switch", RT5670_HPO_MIXER, 745 RT5670_M_DAC1_HM_SFT, 1, 1), 746 SOC_DAPM_SINGLE("HPVOL Switch", RT5670_HPO_MIXER, 747 RT5670_M_HPVOL_HM_SFT, 1, 1), 748 }; 749 750 static const struct snd_kcontrol_new rt5670_hpvoll_mix[] = { 751 SOC_DAPM_SINGLE("DAC1 Switch", RT5670_HPO_MIXER, 752 RT5670_M_DACL1_HML_SFT, 1, 1), 753 SOC_DAPM_SINGLE("INL Switch", RT5670_HPO_MIXER, 754 RT5670_M_INL1_HML_SFT, 1, 1), 755 }; 756 757 static const struct snd_kcontrol_new rt5670_hpvolr_mix[] = { 758 SOC_DAPM_SINGLE("DAC1 Switch", RT5670_HPO_MIXER, 759 RT5670_M_DACR1_HMR_SFT, 1, 1), 760 SOC_DAPM_SINGLE("INR Switch", RT5670_HPO_MIXER, 761 RT5670_M_INR1_HMR_SFT, 1, 1), 762 }; 763 764 static const struct snd_kcontrol_new rt5670_lout_mix[] = { 765 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_LOUT_MIXER, 766 RT5670_M_DAC_L1_LM_SFT, 1, 1), 767 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_LOUT_MIXER, 768 RT5670_M_DAC_R1_LM_SFT, 1, 1), 769 SOC_DAPM_SINGLE("OUTMIX L Switch", RT5670_LOUT_MIXER, 770 RT5670_M_OV_L_LM_SFT, 1, 1), 771 SOC_DAPM_SINGLE("OUTMIX R Switch", RT5670_LOUT_MIXER, 772 RT5670_M_OV_R_LM_SFT, 1, 1), 773 }; 774 775 static const struct snd_kcontrol_new rt5670_hpl_mix[] = { 776 SOC_DAPM_SINGLE("DAC L1 Switch", RT5670_HPO_MIXER, 777 RT5670_M_DACL1_HML_SFT, 1, 1), 778 SOC_DAPM_SINGLE("INL1 Switch", RT5670_HPO_MIXER, 779 RT5670_M_INL1_HML_SFT, 1, 1), 780 }; 781 782 static const struct snd_kcontrol_new rt5670_hpr_mix[] = { 783 SOC_DAPM_SINGLE("DAC R1 Switch", RT5670_HPO_MIXER, 784 RT5670_M_DACR1_HMR_SFT, 1, 1), 785 SOC_DAPM_SINGLE("INR1 Switch", RT5670_HPO_MIXER, 786 RT5670_M_INR1_HMR_SFT, 1, 1), 787 }; 788 789 static const struct snd_kcontrol_new lout_l_enable_control = 790 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5670_LOUT1, 791 RT5670_L_MUTE_SFT, 1, 1); 792 793 static const struct snd_kcontrol_new lout_r_enable_control = 794 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5670_LOUT1, 795 RT5670_R_MUTE_SFT, 1, 1); 796 797 /* DAC1 L/R source */ /* MX-29 [9:8] [11:10] */ 798 static const char * const rt5670_dac1_src[] = { 799 "IF1 DAC", "IF2 DAC" 800 }; 801 802 static SOC_ENUM_SINGLE_DECL(rt5670_dac1l_enum, RT5670_AD_DA_MIXER, 803 RT5670_DAC1_L_SEL_SFT, rt5670_dac1_src); 804 805 static const struct snd_kcontrol_new rt5670_dac1l_mux = 806 SOC_DAPM_ENUM("DAC1 L source", rt5670_dac1l_enum); 807 808 static SOC_ENUM_SINGLE_DECL(rt5670_dac1r_enum, RT5670_AD_DA_MIXER, 809 RT5670_DAC1_R_SEL_SFT, rt5670_dac1_src); 810 811 static const struct snd_kcontrol_new rt5670_dac1r_mux = 812 SOC_DAPM_ENUM("DAC1 R source", rt5670_dac1r_enum); 813 814 /*DAC2 L/R source*/ /* MX-1B [6:4] [2:0] */ 815 /* TODO Use SOC_VALUE_ENUM_SINGLE_DECL */ 816 static const char * const rt5670_dac12_src[] = { 817 "IF1 DAC", "IF2 DAC", "IF3 DAC", "TxDC DAC", 818 "Bass", "VAD_ADC", "IF4 DAC" 819 }; 820 821 static SOC_ENUM_SINGLE_DECL(rt5670_dac2l_enum, RT5670_DAC_CTRL, 822 RT5670_DAC2_L_SEL_SFT, rt5670_dac12_src); 823 824 static const struct snd_kcontrol_new rt5670_dac_l2_mux = 825 SOC_DAPM_ENUM("DAC2 L source", rt5670_dac2l_enum); 826 827 static const char * const rt5670_dacr2_src[] = { 828 "IF1 DAC", "IF2 DAC", "IF3 DAC", "TxDC DAC", "TxDP ADC", "IF4 DAC" 829 }; 830 831 static SOC_ENUM_SINGLE_DECL(rt5670_dac2r_enum, RT5670_DAC_CTRL, 832 RT5670_DAC2_R_SEL_SFT, rt5670_dacr2_src); 833 834 static const struct snd_kcontrol_new rt5670_dac_r2_mux = 835 SOC_DAPM_ENUM("DAC2 R source", rt5670_dac2r_enum); 836 837 /*RxDP source*/ /* MX-2D [15:13] */ 838 static const char * const rt5670_rxdp_src[] = { 839 "IF2 DAC", "IF1 DAC", "STO1 ADC Mixer", "STO2 ADC Mixer", 840 "Mono ADC Mixer L", "Mono ADC Mixer R", "DAC1" 841 }; 842 843 static SOC_ENUM_SINGLE_DECL(rt5670_rxdp_enum, RT5670_DSP_PATH1, 844 RT5670_RXDP_SEL_SFT, rt5670_rxdp_src); 845 846 static const struct snd_kcontrol_new rt5670_rxdp_mux = 847 SOC_DAPM_ENUM("DAC2 L source", rt5670_rxdp_enum); 848 849 /* MX-2D [1] [0] */ 850 static const char * const rt5670_dsp_bypass_src[] = { 851 "DSP", "Bypass" 852 }; 853 854 static SOC_ENUM_SINGLE_DECL(rt5670_dsp_ul_enum, RT5670_DSP_PATH1, 855 RT5670_DSP_UL_SFT, rt5670_dsp_bypass_src); 856 857 static const struct snd_kcontrol_new rt5670_dsp_ul_mux = 858 SOC_DAPM_ENUM("DSP UL source", rt5670_dsp_ul_enum); 859 860 static SOC_ENUM_SINGLE_DECL(rt5670_dsp_dl_enum, RT5670_DSP_PATH1, 861 RT5670_DSP_DL_SFT, rt5670_dsp_bypass_src); 862 863 static const struct snd_kcontrol_new rt5670_dsp_dl_mux = 864 SOC_DAPM_ENUM("DSP DL source", rt5670_dsp_dl_enum); 865 866 /* Stereo2 ADC source */ 867 /* MX-26 [15] */ 868 static const char * const rt5670_stereo2_adc_lr_src[] = { 869 "L", "LR" 870 }; 871 872 static SOC_ENUM_SINGLE_DECL(rt5670_stereo2_adc_lr_enum, RT5670_STO2_ADC_MIXER, 873 RT5670_STO2_ADC_SRC_SFT, rt5670_stereo2_adc_lr_src); 874 875 static const struct snd_kcontrol_new rt5670_sto2_adc_lr_mux = 876 SOC_DAPM_ENUM("Stereo2 ADC LR source", rt5670_stereo2_adc_lr_enum); 877 878 /* Stereo1 ADC source */ 879 /* MX-27 MX-26 [12] */ 880 static const char * const rt5670_stereo_adc1_src[] = { 881 "DAC MIX", "ADC" 882 }; 883 884 static SOC_ENUM_SINGLE_DECL(rt5670_stereo1_adc1_enum, RT5670_STO1_ADC_MIXER, 885 RT5670_ADC_1_SRC_SFT, rt5670_stereo_adc1_src); 886 887 static const struct snd_kcontrol_new rt5670_sto_adc_l1_mux = 888 SOC_DAPM_ENUM("Stereo1 ADC L1 source", rt5670_stereo1_adc1_enum); 889 890 static const struct snd_kcontrol_new rt5670_sto_adc_r1_mux = 891 SOC_DAPM_ENUM("Stereo1 ADC R1 source", rt5670_stereo1_adc1_enum); 892 893 static SOC_ENUM_SINGLE_DECL(rt5670_stereo2_adc1_enum, RT5670_STO2_ADC_MIXER, 894 RT5670_ADC_1_SRC_SFT, rt5670_stereo_adc1_src); 895 896 static const struct snd_kcontrol_new rt5670_sto2_adc_l1_mux = 897 SOC_DAPM_ENUM("Stereo2 ADC L1 source", rt5670_stereo2_adc1_enum); 898 899 static const struct snd_kcontrol_new rt5670_sto2_adc_r1_mux = 900 SOC_DAPM_ENUM("Stereo2 ADC R1 source", rt5670_stereo2_adc1_enum); 901 902 /* MX-27 MX-26 [11] */ 903 static const char * const rt5670_stereo_adc2_src[] = { 904 "DAC MIX", "DMIC" 905 }; 906 907 static SOC_ENUM_SINGLE_DECL(rt5670_stereo1_adc2_enum, RT5670_STO1_ADC_MIXER, 908 RT5670_ADC_2_SRC_SFT, rt5670_stereo_adc2_src); 909 910 static const struct snd_kcontrol_new rt5670_sto_adc_l2_mux = 911 SOC_DAPM_ENUM("Stereo1 ADC L2 source", rt5670_stereo1_adc2_enum); 912 913 static const struct snd_kcontrol_new rt5670_sto_adc_r2_mux = 914 SOC_DAPM_ENUM("Stereo1 ADC R2 source", rt5670_stereo1_adc2_enum); 915 916 static SOC_ENUM_SINGLE_DECL(rt5670_stereo2_adc2_enum, RT5670_STO2_ADC_MIXER, 917 RT5670_ADC_2_SRC_SFT, rt5670_stereo_adc2_src); 918 919 static const struct snd_kcontrol_new rt5670_sto2_adc_l2_mux = 920 SOC_DAPM_ENUM("Stereo2 ADC L2 source", rt5670_stereo2_adc2_enum); 921 922 static const struct snd_kcontrol_new rt5670_sto2_adc_r2_mux = 923 SOC_DAPM_ENUM("Stereo2 ADC R2 source", rt5670_stereo2_adc2_enum); 924 925 /* MX-27 MX26 [10] */ 926 static const char * const rt5670_stereo_adc_src[] = { 927 "ADC1L ADC2R", "ADC3" 928 }; 929 930 static SOC_ENUM_SINGLE_DECL(rt5670_stereo1_adc_enum, RT5670_STO1_ADC_MIXER, 931 RT5670_ADC_SRC_SFT, rt5670_stereo_adc_src); 932 933 static const struct snd_kcontrol_new rt5670_sto_adc_mux = 934 SOC_DAPM_ENUM("Stereo1 ADC source", rt5670_stereo1_adc_enum); 935 936 static SOC_ENUM_SINGLE_DECL(rt5670_stereo2_adc_enum, RT5670_STO2_ADC_MIXER, 937 RT5670_ADC_SRC_SFT, rt5670_stereo_adc_src); 938 939 static const struct snd_kcontrol_new rt5670_sto2_adc_mux = 940 SOC_DAPM_ENUM("Stereo2 ADC source", rt5670_stereo2_adc_enum); 941 942 /* MX-27 MX-26 [9:8] */ 943 static const char * const rt5670_stereo_dmic_src[] = { 944 "DMIC1", "DMIC2", "DMIC3" 945 }; 946 947 static SOC_ENUM_SINGLE_DECL(rt5670_stereo1_dmic_enum, RT5670_STO1_ADC_MIXER, 948 RT5670_DMIC_SRC_SFT, rt5670_stereo_dmic_src); 949 950 static const struct snd_kcontrol_new rt5670_sto1_dmic_mux = 951 SOC_DAPM_ENUM("Stereo1 DMIC source", rt5670_stereo1_dmic_enum); 952 953 static SOC_ENUM_SINGLE_DECL(rt5670_stereo2_dmic_enum, RT5670_STO2_ADC_MIXER, 954 RT5670_DMIC_SRC_SFT, rt5670_stereo_dmic_src); 955 956 static const struct snd_kcontrol_new rt5670_sto2_dmic_mux = 957 SOC_DAPM_ENUM("Stereo2 DMIC source", rt5670_stereo2_dmic_enum); 958 959 /* MX-27 [0] */ 960 static const char * const rt5670_stereo_dmic3_src[] = { 961 "DMIC3", "PDM ADC" 962 }; 963 964 static SOC_ENUM_SINGLE_DECL(rt5670_stereo_dmic3_enum, RT5670_STO1_ADC_MIXER, 965 RT5670_DMIC3_SRC_SFT, rt5670_stereo_dmic3_src); 966 967 static const struct snd_kcontrol_new rt5670_sto_dmic3_mux = 968 SOC_DAPM_ENUM("Stereo DMIC3 source", rt5670_stereo_dmic3_enum); 969 970 /* Mono ADC source */ 971 /* MX-28 [12] */ 972 static const char * const rt5670_mono_adc_l1_src[] = { 973 "Mono DAC MIXL", "ADC1" 974 }; 975 976 static SOC_ENUM_SINGLE_DECL(rt5670_mono_adc_l1_enum, RT5670_MONO_ADC_MIXER, 977 RT5670_MONO_ADC_L1_SRC_SFT, rt5670_mono_adc_l1_src); 978 979 static const struct snd_kcontrol_new rt5670_mono_adc_l1_mux = 980 SOC_DAPM_ENUM("Mono ADC1 left source", rt5670_mono_adc_l1_enum); 981 /* MX-28 [11] */ 982 static const char * const rt5670_mono_adc_l2_src[] = { 983 "Mono DAC MIXL", "DMIC" 984 }; 985 986 static SOC_ENUM_SINGLE_DECL(rt5670_mono_adc_l2_enum, RT5670_MONO_ADC_MIXER, 987 RT5670_MONO_ADC_L2_SRC_SFT, rt5670_mono_adc_l2_src); 988 989 static const struct snd_kcontrol_new rt5670_mono_adc_l2_mux = 990 SOC_DAPM_ENUM("Mono ADC2 left source", rt5670_mono_adc_l2_enum); 991 992 /* MX-28 [9:8] */ 993 static const char * const rt5670_mono_dmic_src[] = { 994 "DMIC1", "DMIC2", "DMIC3" 995 }; 996 997 static SOC_ENUM_SINGLE_DECL(rt5670_mono_dmic_l_enum, RT5670_MONO_ADC_MIXER, 998 RT5670_MONO_DMIC_L_SRC_SFT, rt5670_mono_dmic_src); 999 1000 static const struct snd_kcontrol_new rt5670_mono_dmic_l_mux = 1001 SOC_DAPM_ENUM("Mono DMIC left source", rt5670_mono_dmic_l_enum); 1002 /* MX-28 [1:0] */ 1003 static SOC_ENUM_SINGLE_DECL(rt5670_mono_dmic_r_enum, RT5670_MONO_ADC_MIXER, 1004 RT5670_MONO_DMIC_R_SRC_SFT, rt5670_mono_dmic_src); 1005 1006 static const struct snd_kcontrol_new rt5670_mono_dmic_r_mux = 1007 SOC_DAPM_ENUM("Mono DMIC Right source", rt5670_mono_dmic_r_enum); 1008 /* MX-28 [4] */ 1009 static const char * const rt5670_mono_adc_r1_src[] = { 1010 "Mono DAC MIXR", "ADC2" 1011 }; 1012 1013 static SOC_ENUM_SINGLE_DECL(rt5670_mono_adc_r1_enum, RT5670_MONO_ADC_MIXER, 1014 RT5670_MONO_ADC_R1_SRC_SFT, rt5670_mono_adc_r1_src); 1015 1016 static const struct snd_kcontrol_new rt5670_mono_adc_r1_mux = 1017 SOC_DAPM_ENUM("Mono ADC1 right source", rt5670_mono_adc_r1_enum); 1018 /* MX-28 [3] */ 1019 static const char * const rt5670_mono_adc_r2_src[] = { 1020 "Mono DAC MIXR", "DMIC" 1021 }; 1022 1023 static SOC_ENUM_SINGLE_DECL(rt5670_mono_adc_r2_enum, RT5670_MONO_ADC_MIXER, 1024 RT5670_MONO_ADC_R2_SRC_SFT, rt5670_mono_adc_r2_src); 1025 1026 static const struct snd_kcontrol_new rt5670_mono_adc_r2_mux = 1027 SOC_DAPM_ENUM("Mono ADC2 right source", rt5670_mono_adc_r2_enum); 1028 1029 /* MX-2D [3:2] */ 1030 static const char * const rt5670_txdp_slot_src[] = { 1031 "Slot 0-1", "Slot 2-3", "Slot 4-5", "Slot 6-7" 1032 }; 1033 1034 static SOC_ENUM_SINGLE_DECL(rt5670_txdp_slot_enum, RT5670_DSP_PATH1, 1035 RT5670_TXDP_SLOT_SEL_SFT, rt5670_txdp_slot_src); 1036 1037 static const struct snd_kcontrol_new rt5670_txdp_slot_mux = 1038 SOC_DAPM_ENUM("TxDP Slot source", rt5670_txdp_slot_enum); 1039 1040 /* MX-2F [15] */ 1041 static const char * const rt5670_if1_adc2_in_src[] = { 1042 "IF_ADC2", "VAD_ADC" 1043 }; 1044 1045 static SOC_ENUM_SINGLE_DECL(rt5670_if1_adc2_in_enum, RT5670_DIG_INF1_DATA, 1046 RT5670_IF1_ADC2_IN_SFT, rt5670_if1_adc2_in_src); 1047 1048 static const struct snd_kcontrol_new rt5670_if1_adc2_in_mux = 1049 SOC_DAPM_ENUM("IF1 ADC2 IN source", rt5670_if1_adc2_in_enum); 1050 1051 /* MX-2F [14:12] */ 1052 static const char * const rt5670_if2_adc_in_src[] = { 1053 "IF_ADC1", "IF_ADC2", "IF_ADC3", "TxDC_DAC", "TxDP_ADC", "VAD_ADC" 1054 }; 1055 1056 static SOC_ENUM_SINGLE_DECL(rt5670_if2_adc_in_enum, RT5670_DIG_INF1_DATA, 1057 RT5670_IF2_ADC_IN_SFT, rt5670_if2_adc_in_src); 1058 1059 static const struct snd_kcontrol_new rt5670_if2_adc_in_mux = 1060 SOC_DAPM_ENUM("IF2 ADC IN source", rt5670_if2_adc_in_enum); 1061 1062 /* MX-30 [5:4] */ 1063 static const char * const rt5670_if4_adc_in_src[] = { 1064 "IF_ADC1", "IF_ADC2", "IF_ADC3" 1065 }; 1066 1067 static SOC_ENUM_SINGLE_DECL(rt5670_if4_adc_in_enum, RT5670_DIG_INF2_DATA, 1068 RT5670_IF4_ADC_IN_SFT, rt5670_if4_adc_in_src); 1069 1070 static const struct snd_kcontrol_new rt5670_if4_adc_in_mux = 1071 SOC_DAPM_ENUM("IF4 ADC IN source", rt5670_if4_adc_in_enum); 1072 1073 /* MX-31 [15] [13] [11] [9] */ 1074 static const char * const rt5670_pdm_src[] = { 1075 "Mono DAC", "Stereo DAC" 1076 }; 1077 1078 static SOC_ENUM_SINGLE_DECL(rt5670_pdm1_l_enum, RT5670_PDM_OUT_CTRL, 1079 RT5670_PDM1_L_SFT, rt5670_pdm_src); 1080 1081 static const struct snd_kcontrol_new rt5670_pdm1_l_mux = 1082 SOC_DAPM_ENUM("PDM1 L source", rt5670_pdm1_l_enum); 1083 1084 static SOC_ENUM_SINGLE_DECL(rt5670_pdm1_r_enum, RT5670_PDM_OUT_CTRL, 1085 RT5670_PDM1_R_SFT, rt5670_pdm_src); 1086 1087 static const struct snd_kcontrol_new rt5670_pdm1_r_mux = 1088 SOC_DAPM_ENUM("PDM1 R source", rt5670_pdm1_r_enum); 1089 1090 static SOC_ENUM_SINGLE_DECL(rt5670_pdm2_l_enum, RT5670_PDM_OUT_CTRL, 1091 RT5670_PDM2_L_SFT, rt5670_pdm_src); 1092 1093 static const struct snd_kcontrol_new rt5670_pdm2_l_mux = 1094 SOC_DAPM_ENUM("PDM2 L source", rt5670_pdm2_l_enum); 1095 1096 static SOC_ENUM_SINGLE_DECL(rt5670_pdm2_r_enum, RT5670_PDM_OUT_CTRL, 1097 RT5670_PDM2_R_SFT, rt5670_pdm_src); 1098 1099 static const struct snd_kcontrol_new rt5670_pdm2_r_mux = 1100 SOC_DAPM_ENUM("PDM2 R source", rt5670_pdm2_r_enum); 1101 1102 /* MX-FA [12] */ 1103 static const char * const rt5670_if1_adc1_in1_src[] = { 1104 "IF_ADC1", "IF1_ADC3" 1105 }; 1106 1107 static SOC_ENUM_SINGLE_DECL(rt5670_if1_adc1_in1_enum, RT5670_DIG_MISC, 1108 RT5670_IF1_ADC1_IN1_SFT, rt5670_if1_adc1_in1_src); 1109 1110 static const struct snd_kcontrol_new rt5670_if1_adc1_in1_mux = 1111 SOC_DAPM_ENUM("IF1 ADC1 IN1 source", rt5670_if1_adc1_in1_enum); 1112 1113 /* MX-FA [11] */ 1114 static const char * const rt5670_if1_adc1_in2_src[] = { 1115 "IF1_ADC1_IN1", "IF1_ADC4" 1116 }; 1117 1118 static SOC_ENUM_SINGLE_DECL(rt5670_if1_adc1_in2_enum, RT5670_DIG_MISC, 1119 RT5670_IF1_ADC1_IN2_SFT, rt5670_if1_adc1_in2_src); 1120 1121 static const struct snd_kcontrol_new rt5670_if1_adc1_in2_mux = 1122 SOC_DAPM_ENUM("IF1 ADC1 IN2 source", rt5670_if1_adc1_in2_enum); 1123 1124 /* MX-FA [10] */ 1125 static const char * const rt5670_if1_adc2_in1_src[] = { 1126 "IF1_ADC2_IN", "IF1_ADC4" 1127 }; 1128 1129 static SOC_ENUM_SINGLE_DECL(rt5670_if1_adc2_in1_enum, RT5670_DIG_MISC, 1130 RT5670_IF1_ADC2_IN1_SFT, rt5670_if1_adc2_in1_src); 1131 1132 static const struct snd_kcontrol_new rt5670_if1_adc2_in1_mux = 1133 SOC_DAPM_ENUM("IF1 ADC2 IN1 source", rt5670_if1_adc2_in1_enum); 1134 1135 /* MX-9D [9:8] */ 1136 static const char * const rt5670_vad_adc_src[] = { 1137 "Sto1 ADC L", "Mono ADC L", "Mono ADC R", "Sto2 ADC L" 1138 }; 1139 1140 static SOC_ENUM_SINGLE_DECL(rt5670_vad_adc_enum, RT5670_VAD_CTRL4, 1141 RT5670_VAD_SEL_SFT, rt5670_vad_adc_src); 1142 1143 static const struct snd_kcontrol_new rt5670_vad_adc_mux = 1144 SOC_DAPM_ENUM("VAD ADC source", rt5670_vad_adc_enum); 1145 1146 static int rt5670_hp_power_event(struct snd_soc_dapm_widget *w, 1147 struct snd_kcontrol *kcontrol, int event) 1148 { 1149 struct snd_soc_codec *codec = w->codec; 1150 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 1151 1152 switch (event) { 1153 case SND_SOC_DAPM_POST_PMU: 1154 regmap_update_bits(rt5670->regmap, RT5670_CHARGE_PUMP, 1155 RT5670_PM_HP_MASK, RT5670_PM_HP_HV); 1156 regmap_update_bits(rt5670->regmap, RT5670_GEN_CTRL2, 1157 0x0400, 0x0400); 1158 /* headphone amp power on */ 1159 regmap_update_bits(rt5670->regmap, RT5670_PWR_ANLG1, 1160 RT5670_PWR_HA | RT5670_PWR_FV1 | 1161 RT5670_PWR_FV2, RT5670_PWR_HA | 1162 RT5670_PWR_FV1 | RT5670_PWR_FV2); 1163 /* depop parameters */ 1164 regmap_write(rt5670->regmap, RT5670_DEPOP_M2, 0x3100); 1165 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x8009); 1166 regmap_write(rt5670->regmap, RT5670_PR_BASE + 1167 RT5670_HP_DCC_INT1, 0x9f00); 1168 mdelay(20); 1169 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x8019); 1170 break; 1171 case SND_SOC_DAPM_PRE_PMD: 1172 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x0004); 1173 msleep(30); 1174 break; 1175 default: 1176 return 0; 1177 } 1178 1179 return 0; 1180 } 1181 1182 static int rt5670_hp_event(struct snd_soc_dapm_widget *w, 1183 struct snd_kcontrol *kcontrol, int event) 1184 { 1185 struct snd_soc_codec *codec = w->codec; 1186 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 1187 1188 switch (event) { 1189 case SND_SOC_DAPM_POST_PMU: 1190 /* headphone unmute sequence */ 1191 regmap_write(rt5670->regmap, RT5670_PR_BASE + 1192 RT5670_MAMP_INT_REG2, 0xb400); 1193 regmap_write(rt5670->regmap, RT5670_DEPOP_M3, 0x0772); 1194 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x805d); 1195 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x831d); 1196 regmap_update_bits(rt5670->regmap, RT5670_GEN_CTRL2, 1197 0x0300, 0x0300); 1198 regmap_update_bits(rt5670->regmap, RT5670_HP_VOL, 1199 RT5670_L_MUTE | RT5670_R_MUTE, 0); 1200 msleep(80); 1201 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x8019); 1202 break; 1203 1204 case SND_SOC_DAPM_PRE_PMD: 1205 /* headphone mute sequence */ 1206 regmap_write(rt5670->regmap, RT5670_PR_BASE + 1207 RT5670_MAMP_INT_REG2, 0xb400); 1208 regmap_write(rt5670->regmap, RT5670_DEPOP_M3, 0x0772); 1209 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x803d); 1210 mdelay(10); 1211 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x831d); 1212 mdelay(10); 1213 regmap_update_bits(rt5670->regmap, RT5670_HP_VOL, 1214 RT5670_L_MUTE | RT5670_R_MUTE, 1215 RT5670_L_MUTE | RT5670_R_MUTE); 1216 msleep(20); 1217 regmap_update_bits(rt5670->regmap, 1218 RT5670_GEN_CTRL2, 0x0300, 0x0); 1219 regmap_write(rt5670->regmap, RT5670_DEPOP_M1, 0x8019); 1220 regmap_write(rt5670->regmap, RT5670_DEPOP_M3, 0x0707); 1221 regmap_write(rt5670->regmap, RT5670_PR_BASE + 1222 RT5670_MAMP_INT_REG2, 0xfc00); 1223 break; 1224 1225 default: 1226 return 0; 1227 } 1228 1229 return 0; 1230 } 1231 1232 static int rt5670_bst1_event(struct snd_soc_dapm_widget *w, 1233 struct snd_kcontrol *kcontrol, int event) 1234 { 1235 struct snd_soc_codec *codec = w->codec; 1236 1237 switch (event) { 1238 case SND_SOC_DAPM_POST_PMU: 1239 snd_soc_update_bits(codec, RT5670_PWR_ANLG2, 1240 RT5670_PWR_BST1_P, RT5670_PWR_BST1_P); 1241 break; 1242 1243 case SND_SOC_DAPM_PRE_PMD: 1244 snd_soc_update_bits(codec, RT5670_PWR_ANLG2, 1245 RT5670_PWR_BST1_P, 0); 1246 break; 1247 1248 default: 1249 return 0; 1250 } 1251 1252 return 0; 1253 } 1254 1255 static int rt5670_bst2_event(struct snd_soc_dapm_widget *w, 1256 struct snd_kcontrol *kcontrol, int event) 1257 { 1258 struct snd_soc_codec *codec = w->codec; 1259 1260 switch (event) { 1261 case SND_SOC_DAPM_POST_PMU: 1262 snd_soc_update_bits(codec, RT5670_PWR_ANLG2, 1263 RT5670_PWR_BST2_P, RT5670_PWR_BST2_P); 1264 break; 1265 1266 case SND_SOC_DAPM_PRE_PMD: 1267 snd_soc_update_bits(codec, RT5670_PWR_ANLG2, 1268 RT5670_PWR_BST2_P, 0); 1269 break; 1270 1271 default: 1272 return 0; 1273 } 1274 1275 return 0; 1276 } 1277 1278 static const struct snd_soc_dapm_widget rt5670_dapm_widgets[] = { 1279 SND_SOC_DAPM_SUPPLY("PLL1", RT5670_PWR_ANLG2, 1280 RT5670_PWR_PLL_BIT, 0, NULL, 0), 1281 SND_SOC_DAPM_SUPPLY("I2S DSP", RT5670_PWR_DIG2, 1282 RT5670_PWR_I2S_DSP_BIT, 0, NULL, 0), 1283 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5670_PWR_VOL, 1284 RT5670_PWR_MIC_DET_BIT, 0, NULL, 0), 1285 1286 /* ASRC */ 1287 SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5670_ASRC_1, 1288 11, 0, NULL, 0), 1289 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5670_ASRC_1, 1290 12, 0, NULL, 0), 1291 SND_SOC_DAPM_SUPPLY_S("DAC STO ASRC", 1, RT5670_ASRC_1, 1292 10, 0, NULL, 0), 1293 SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1, RT5670_ASRC_1, 1294 9, 0, NULL, 0), 1295 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5670_ASRC_1, 1296 8, 0, NULL, 0), 1297 SND_SOC_DAPM_SUPPLY_S("DMIC STO1 ASRC", 1, RT5670_ASRC_1, 1298 7, 0, NULL, 0), 1299 SND_SOC_DAPM_SUPPLY_S("DMIC STO2 ASRC", 1, RT5670_ASRC_1, 1300 6, 0, NULL, 0), 1301 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5670_ASRC_1, 1302 5, 0, NULL, 0), 1303 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5670_ASRC_1, 1304 4, 0, NULL, 0), 1305 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5670_ASRC_1, 1306 3, 0, NULL, 0), 1307 SND_SOC_DAPM_SUPPLY_S("ADC STO2 ASRC", 1, RT5670_ASRC_1, 1308 2, 0, NULL, 0), 1309 SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1, RT5670_ASRC_1, 1310 1, 0, NULL, 0), 1311 SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1, RT5670_ASRC_1, 1312 0, 0, NULL, 0), 1313 1314 /* Input Side */ 1315 /* micbias */ 1316 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5670_PWR_ANLG2, 1317 RT5670_PWR_MB1_BIT, 0, NULL, 0), 1318 1319 /* Input Lines */ 1320 SND_SOC_DAPM_INPUT("DMIC L1"), 1321 SND_SOC_DAPM_INPUT("DMIC R1"), 1322 SND_SOC_DAPM_INPUT("DMIC L2"), 1323 SND_SOC_DAPM_INPUT("DMIC R2"), 1324 SND_SOC_DAPM_INPUT("DMIC L3"), 1325 SND_SOC_DAPM_INPUT("DMIC R3"), 1326 1327 SND_SOC_DAPM_INPUT("IN1P"), 1328 SND_SOC_DAPM_INPUT("IN1N"), 1329 SND_SOC_DAPM_INPUT("IN2P"), 1330 SND_SOC_DAPM_INPUT("IN2N"), 1331 1332 SND_SOC_DAPM_PGA("DMIC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1333 SND_SOC_DAPM_PGA("DMIC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1334 SND_SOC_DAPM_PGA("DMIC3", SND_SOC_NOPM, 0, 0, NULL, 0), 1335 1336 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0, 1337 set_dmic_clk, SND_SOC_DAPM_PRE_PMU), 1338 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5670_DMIC_CTRL1, 1339 RT5670_DMIC_1_EN_SFT, 0, NULL, 0), 1340 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5670_DMIC_CTRL1, 1341 RT5670_DMIC_2_EN_SFT, 0, NULL, 0), 1342 SND_SOC_DAPM_SUPPLY("DMIC3 Power", RT5670_DMIC_CTRL1, 1343 RT5670_DMIC_3_EN_SFT, 0, NULL, 0), 1344 /* Boost */ 1345 SND_SOC_DAPM_PGA_E("BST1", RT5670_PWR_ANLG2, RT5670_PWR_BST1_BIT, 1346 0, NULL, 0, rt5670_bst1_event, 1347 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1348 SND_SOC_DAPM_PGA_E("BST2", RT5670_PWR_ANLG2, RT5670_PWR_BST2_BIT, 1349 0, NULL, 0, rt5670_bst2_event, 1350 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1351 /* Input Volume */ 1352 SND_SOC_DAPM_PGA("INL VOL", RT5670_PWR_VOL, 1353 RT5670_PWR_IN_L_BIT, 0, NULL, 0), 1354 SND_SOC_DAPM_PGA("INR VOL", RT5670_PWR_VOL, 1355 RT5670_PWR_IN_R_BIT, 0, NULL, 0), 1356 1357 /* REC Mixer */ 1358 SND_SOC_DAPM_MIXER("RECMIXL", RT5670_PWR_MIXER, RT5670_PWR_RM_L_BIT, 0, 1359 rt5670_rec_l_mix, ARRAY_SIZE(rt5670_rec_l_mix)), 1360 SND_SOC_DAPM_MIXER("RECMIXR", RT5670_PWR_MIXER, RT5670_PWR_RM_R_BIT, 0, 1361 rt5670_rec_r_mix, ARRAY_SIZE(rt5670_rec_r_mix)), 1362 /* ADCs */ 1363 SND_SOC_DAPM_ADC("ADC 1", NULL, SND_SOC_NOPM, 0, 0), 1364 SND_SOC_DAPM_ADC("ADC 2", NULL, SND_SOC_NOPM, 0, 0), 1365 1366 SND_SOC_DAPM_PGA("ADC 1_2", SND_SOC_NOPM, 0, 0, NULL, 0), 1367 1368 SND_SOC_DAPM_SUPPLY("ADC 1 power", RT5670_PWR_DIG1, 1369 RT5670_PWR_ADC_L_BIT, 0, NULL, 0), 1370 SND_SOC_DAPM_SUPPLY("ADC 2 power", RT5670_PWR_DIG1, 1371 RT5670_PWR_ADC_R_BIT, 0, NULL, 0), 1372 SND_SOC_DAPM_SUPPLY("ADC clock", RT5670_PR_BASE + 1373 RT5670_CHOP_DAC_ADC, 12, 0, NULL, 0), 1374 /* ADC Mux */ 1375 SND_SOC_DAPM_MUX("Stereo1 DMIC Mux", SND_SOC_NOPM, 0, 0, 1376 &rt5670_sto1_dmic_mux), 1377 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 1378 &rt5670_sto_adc_l2_mux), 1379 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 1380 &rt5670_sto_adc_r2_mux), 1381 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 1382 &rt5670_sto_adc_l1_mux), 1383 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 1384 &rt5670_sto_adc_r1_mux), 1385 SND_SOC_DAPM_MUX("Stereo2 DMIC Mux", SND_SOC_NOPM, 0, 0, 1386 &rt5670_sto2_dmic_mux), 1387 SND_SOC_DAPM_MUX("Stereo2 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 1388 &rt5670_sto2_adc_l2_mux), 1389 SND_SOC_DAPM_MUX("Stereo2 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 1390 &rt5670_sto2_adc_r2_mux), 1391 SND_SOC_DAPM_MUX("Stereo2 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 1392 &rt5670_sto2_adc_l1_mux), 1393 SND_SOC_DAPM_MUX("Stereo2 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 1394 &rt5670_sto2_adc_r1_mux), 1395 SND_SOC_DAPM_MUX("Stereo2 ADC LR Mux", SND_SOC_NOPM, 0, 0, 1396 &rt5670_sto2_adc_lr_mux), 1397 SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM, 0, 0, 1398 &rt5670_mono_dmic_l_mux), 1399 SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM, 0, 0, 1400 &rt5670_mono_dmic_r_mux), 1401 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM, 0, 0, 1402 &rt5670_mono_adc_l2_mux), 1403 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM, 0, 0, 1404 &rt5670_mono_adc_l1_mux), 1405 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM, 0, 0, 1406 &rt5670_mono_adc_r1_mux), 1407 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM, 0, 0, 1408 &rt5670_mono_adc_r2_mux), 1409 /* ADC Mixer */ 1410 SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5670_PWR_DIG2, 1411 RT5670_PWR_ADC_S1F_BIT, 0, NULL, 0), 1412 SND_SOC_DAPM_SUPPLY("ADC Stereo2 Filter", RT5670_PWR_DIG2, 1413 RT5670_PWR_ADC_S2F_BIT, 0, NULL, 0), 1414 SND_SOC_DAPM_MIXER("Sto1 ADC MIXL", RT5670_STO1_ADC_DIG_VOL, 1415 RT5670_L_MUTE_SFT, 1, rt5670_sto1_adc_l_mix, 1416 ARRAY_SIZE(rt5670_sto1_adc_l_mix)), 1417 SND_SOC_DAPM_MIXER("Sto1 ADC MIXR", RT5670_STO1_ADC_DIG_VOL, 1418 RT5670_R_MUTE_SFT, 1, rt5670_sto1_adc_r_mix, 1419 ARRAY_SIZE(rt5670_sto1_adc_r_mix)), 1420 SND_SOC_DAPM_MIXER("Sto2 ADC MIXL", SND_SOC_NOPM, 0, 0, 1421 rt5670_sto2_adc_l_mix, 1422 ARRAY_SIZE(rt5670_sto2_adc_l_mix)), 1423 SND_SOC_DAPM_MIXER("Sto2 ADC MIXR", SND_SOC_NOPM, 0, 0, 1424 rt5670_sto2_adc_r_mix, 1425 ARRAY_SIZE(rt5670_sto2_adc_r_mix)), 1426 SND_SOC_DAPM_SUPPLY("ADC Mono Left Filter", RT5670_PWR_DIG2, 1427 RT5670_PWR_ADC_MF_L_BIT, 0, NULL, 0), 1428 SND_SOC_DAPM_MIXER("Mono ADC MIXL", RT5670_MONO_ADC_DIG_VOL, 1429 RT5670_L_MUTE_SFT, 1, rt5670_mono_adc_l_mix, 1430 ARRAY_SIZE(rt5670_mono_adc_l_mix)), 1431 SND_SOC_DAPM_SUPPLY("ADC Mono Right Filter", RT5670_PWR_DIG2, 1432 RT5670_PWR_ADC_MF_R_BIT, 0, NULL, 0), 1433 SND_SOC_DAPM_MIXER("Mono ADC MIXR", RT5670_MONO_ADC_DIG_VOL, 1434 RT5670_R_MUTE_SFT, 1, rt5670_mono_adc_r_mix, 1435 ARRAY_SIZE(rt5670_mono_adc_r_mix)), 1436 1437 /* ADC PGA */ 1438 SND_SOC_DAPM_PGA("Stereo1 ADC MIXL", SND_SOC_NOPM, 0, 0, NULL, 0), 1439 SND_SOC_DAPM_PGA("Stereo1 ADC MIXR", SND_SOC_NOPM, 0, 0, NULL, 0), 1440 SND_SOC_DAPM_PGA("Stereo2 ADC MIXL", SND_SOC_NOPM, 0, 0, NULL, 0), 1441 SND_SOC_DAPM_PGA("Stereo2 ADC MIXR", SND_SOC_NOPM, 0, 0, NULL, 0), 1442 SND_SOC_DAPM_PGA("Sto2 ADC LR MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 1443 SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 1444 SND_SOC_DAPM_PGA("Stereo2 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 1445 SND_SOC_DAPM_PGA("Mono ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 1446 SND_SOC_DAPM_PGA("VAD_ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1447 SND_SOC_DAPM_PGA("IF_ADC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1448 SND_SOC_DAPM_PGA("IF_ADC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1449 SND_SOC_DAPM_PGA("IF_ADC3", SND_SOC_NOPM, 0, 0, NULL, 0), 1450 SND_SOC_DAPM_PGA("IF1_ADC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1451 SND_SOC_DAPM_PGA("IF1_ADC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1452 SND_SOC_DAPM_PGA("IF1_ADC3", SND_SOC_NOPM, 0, 0, NULL, 0), 1453 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0), 1454 1455 /* DSP */ 1456 SND_SOC_DAPM_PGA("TxDP_ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1457 SND_SOC_DAPM_PGA("TxDP_ADC_L", SND_SOC_NOPM, 0, 0, NULL, 0), 1458 SND_SOC_DAPM_PGA("TxDP_ADC_R", SND_SOC_NOPM, 0, 0, NULL, 0), 1459 SND_SOC_DAPM_PGA("TxDC_DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 1460 1461 SND_SOC_DAPM_MUX("TDM Data Mux", SND_SOC_NOPM, 0, 0, 1462 &rt5670_txdp_slot_mux), 1463 1464 SND_SOC_DAPM_MUX("DSP UL Mux", SND_SOC_NOPM, 0, 0, 1465 &rt5670_dsp_ul_mux), 1466 SND_SOC_DAPM_MUX("DSP DL Mux", SND_SOC_NOPM, 0, 0, 1467 &rt5670_dsp_dl_mux), 1468 1469 SND_SOC_DAPM_MUX("RxDP Mux", SND_SOC_NOPM, 0, 0, 1470 &rt5670_rxdp_mux), 1471 1472 /* IF2 Mux */ 1473 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM, 0, 0, 1474 &rt5670_if2_adc_in_mux), 1475 1476 /* Digital Interface */ 1477 SND_SOC_DAPM_SUPPLY("I2S1", RT5670_PWR_DIG1, 1478 RT5670_PWR_I2S1_BIT, 0, NULL, 0), 1479 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1480 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1481 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0), 1482 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0), 1483 SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM, 0, 0, NULL, 0), 1484 SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM, 0, 0, NULL, 0), 1485 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1486 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0), 1487 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0), 1488 SND_SOC_DAPM_SUPPLY("I2S2", RT5670_PWR_DIG1, 1489 RT5670_PWR_I2S2_BIT, 0, NULL, 0), 1490 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 1491 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0), 1492 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0), 1493 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1494 SND_SOC_DAPM_PGA("IF2 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0), 1495 SND_SOC_DAPM_PGA("IF2 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0), 1496 1497 /* Digital Interface Select */ 1498 SND_SOC_DAPM_MUX("IF1 ADC1 IN1 Mux", SND_SOC_NOPM, 0, 0, 1499 &rt5670_if1_adc1_in1_mux), 1500 SND_SOC_DAPM_MUX("IF1 ADC1 IN2 Mux", SND_SOC_NOPM, 0, 0, 1501 &rt5670_if1_adc1_in2_mux), 1502 SND_SOC_DAPM_MUX("IF1 ADC2 IN Mux", SND_SOC_NOPM, 0, 0, 1503 &rt5670_if1_adc2_in_mux), 1504 SND_SOC_DAPM_MUX("IF1 ADC2 IN1 Mux", SND_SOC_NOPM, 0, 0, 1505 &rt5670_if1_adc2_in1_mux), 1506 SND_SOC_DAPM_MUX("VAD ADC Mux", SND_SOC_NOPM, 0, 0, 1507 &rt5670_vad_adc_mux), 1508 1509 /* Audio Interface */ 1510 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 1511 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), 1512 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0), 1513 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, 1514 RT5670_GPIO_CTRL1, RT5670_I2S2_PIN_SFT, 1), 1515 1516 /* Audio DSP */ 1517 SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM, 0, 0, NULL, 0), 1518 1519 /* Output Side */ 1520 /* DAC mixer before sound effect */ 1521 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0, 1522 rt5670_dac_l_mix, ARRAY_SIZE(rt5670_dac_l_mix)), 1523 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0, 1524 rt5670_dac_r_mix, ARRAY_SIZE(rt5670_dac_r_mix)), 1525 SND_SOC_DAPM_PGA("DAC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 1526 1527 /* DAC2 channel Mux */ 1528 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM, 0, 0, 1529 &rt5670_dac_l2_mux), 1530 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM, 0, 0, 1531 &rt5670_dac_r2_mux), 1532 SND_SOC_DAPM_PGA("DAC L2 Volume", RT5670_PWR_DIG1, 1533 RT5670_PWR_DAC_L2_BIT, 0, NULL, 0), 1534 SND_SOC_DAPM_PGA("DAC R2 Volume", RT5670_PWR_DIG1, 1535 RT5670_PWR_DAC_R2_BIT, 0, NULL, 0), 1536 1537 SND_SOC_DAPM_MUX("DAC1 L Mux", SND_SOC_NOPM, 0, 0, &rt5670_dac1l_mux), 1538 SND_SOC_DAPM_MUX("DAC1 R Mux", SND_SOC_NOPM, 0, 0, &rt5670_dac1r_mux), 1539 1540 /* DAC Mixer */ 1541 SND_SOC_DAPM_SUPPLY("DAC Stereo1 Filter", RT5670_PWR_DIG2, 1542 RT5670_PWR_DAC_S1F_BIT, 0, NULL, 0), 1543 SND_SOC_DAPM_SUPPLY("DAC Mono Left Filter", RT5670_PWR_DIG2, 1544 RT5670_PWR_DAC_MF_L_BIT, 0, NULL, 0), 1545 SND_SOC_DAPM_SUPPLY("DAC Mono Right Filter", RT5670_PWR_DIG2, 1546 RT5670_PWR_DAC_MF_R_BIT, 0, NULL, 0), 1547 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0, 1548 rt5670_sto_dac_l_mix, 1549 ARRAY_SIZE(rt5670_sto_dac_l_mix)), 1550 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0, 1551 rt5670_sto_dac_r_mix, 1552 ARRAY_SIZE(rt5670_sto_dac_r_mix)), 1553 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM, 0, 0, 1554 rt5670_mono_dac_l_mix, 1555 ARRAY_SIZE(rt5670_mono_dac_l_mix)), 1556 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM, 0, 0, 1557 rt5670_mono_dac_r_mix, 1558 ARRAY_SIZE(rt5670_mono_dac_r_mix)), 1559 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM, 0, 0, 1560 rt5670_dig_l_mix, 1561 ARRAY_SIZE(rt5670_dig_l_mix)), 1562 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM, 0, 0, 1563 rt5670_dig_r_mix, 1564 ARRAY_SIZE(rt5670_dig_r_mix)), 1565 1566 /* DACs */ 1567 SND_SOC_DAPM_SUPPLY("DAC L1 Power", RT5670_PWR_DIG1, 1568 RT5670_PWR_DAC_L1_BIT, 0, NULL, 0), 1569 SND_SOC_DAPM_SUPPLY("DAC R1 Power", RT5670_PWR_DIG1, 1570 RT5670_PWR_DAC_R1_BIT, 0, NULL, 0), 1571 SND_SOC_DAPM_DAC("DAC L1", NULL, SND_SOC_NOPM, 0, 0), 1572 SND_SOC_DAPM_DAC("DAC R1", NULL, SND_SOC_NOPM, 0, 0), 1573 SND_SOC_DAPM_DAC("DAC L2", NULL, RT5670_PWR_DIG1, 1574 RT5670_PWR_DAC_L2_BIT, 0), 1575 1576 SND_SOC_DAPM_DAC("DAC R2", NULL, RT5670_PWR_DIG1, 1577 RT5670_PWR_DAC_R2_BIT, 0), 1578 /* OUT Mixer */ 1579 1580 SND_SOC_DAPM_MIXER("OUT MIXL", RT5670_PWR_MIXER, RT5670_PWR_OM_L_BIT, 1581 0, rt5670_out_l_mix, ARRAY_SIZE(rt5670_out_l_mix)), 1582 SND_SOC_DAPM_MIXER("OUT MIXR", RT5670_PWR_MIXER, RT5670_PWR_OM_R_BIT, 1583 0, rt5670_out_r_mix, ARRAY_SIZE(rt5670_out_r_mix)), 1584 /* Ouput Volume */ 1585 SND_SOC_DAPM_MIXER("HPOVOL MIXL", RT5670_PWR_VOL, 1586 RT5670_PWR_HV_L_BIT, 0, 1587 rt5670_hpvoll_mix, ARRAY_SIZE(rt5670_hpvoll_mix)), 1588 SND_SOC_DAPM_MIXER("HPOVOL MIXR", RT5670_PWR_VOL, 1589 RT5670_PWR_HV_R_BIT, 0, 1590 rt5670_hpvolr_mix, ARRAY_SIZE(rt5670_hpvolr_mix)), 1591 SND_SOC_DAPM_PGA("DAC 1", SND_SOC_NOPM, 0, 0, NULL, 0), 1592 SND_SOC_DAPM_PGA("DAC 2", SND_SOC_NOPM, 0, 0, NULL, 0), 1593 SND_SOC_DAPM_PGA("HPOVOL", SND_SOC_NOPM, 0, 0, NULL, 0), 1594 1595 /* HPO/LOUT/Mono Mixer */ 1596 SND_SOC_DAPM_MIXER("HPO MIX", SND_SOC_NOPM, 0, 0, 1597 rt5670_hpo_mix, ARRAY_SIZE(rt5670_hpo_mix)), 1598 SND_SOC_DAPM_MIXER("LOUT MIX", RT5670_PWR_ANLG1, RT5670_PWR_LM_BIT, 1599 0, rt5670_lout_mix, ARRAY_SIZE(rt5670_lout_mix)), 1600 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM, 0, 0, 1601 rt5670_hp_power_event, SND_SOC_DAPM_POST_PMU | 1602 SND_SOC_DAPM_PRE_PMD), 1603 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5670_PWR_ANLG1, 1604 RT5670_PWR_HP_L_BIT, 0, NULL, 0), 1605 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5670_PWR_ANLG1, 1606 RT5670_PWR_HP_R_BIT, 0, NULL, 0), 1607 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, 1608 rt5670_hp_event, SND_SOC_DAPM_PRE_PMD | 1609 SND_SOC_DAPM_POST_PMU), 1610 SND_SOC_DAPM_SWITCH("LOUT L Playback", SND_SOC_NOPM, 0, 0, 1611 &lout_l_enable_control), 1612 SND_SOC_DAPM_SWITCH("LOUT R Playback", SND_SOC_NOPM, 0, 0, 1613 &lout_r_enable_control), 1614 SND_SOC_DAPM_PGA("LOUT Amp", SND_SOC_NOPM, 0, 0, NULL, 0), 1615 1616 /* PDM */ 1617 SND_SOC_DAPM_SUPPLY("PDM1 Power", RT5670_PWR_DIG2, 1618 RT5670_PWR_PDM1_BIT, 0, NULL, 0), 1619 1620 SND_SOC_DAPM_MUX("PDM1 L Mux", RT5670_PDM_OUT_CTRL, 1621 RT5670_M_PDM1_L_SFT, 1, &rt5670_pdm1_l_mux), 1622 SND_SOC_DAPM_MUX("PDM1 R Mux", RT5670_PDM_OUT_CTRL, 1623 RT5670_M_PDM1_R_SFT, 1, &rt5670_pdm1_r_mux), 1624 1625 /* Output Lines */ 1626 SND_SOC_DAPM_OUTPUT("HPOL"), 1627 SND_SOC_DAPM_OUTPUT("HPOR"), 1628 SND_SOC_DAPM_OUTPUT("LOUTL"), 1629 SND_SOC_DAPM_OUTPUT("LOUTR"), 1630 }; 1631 1632 static const struct snd_soc_dapm_widget rt5670_specific_dapm_widgets[] = { 1633 SND_SOC_DAPM_SUPPLY("PDM2 Power", RT5670_PWR_DIG2, 1634 RT5670_PWR_PDM2_BIT, 0, NULL, 0), 1635 SND_SOC_DAPM_MUX("PDM2 L Mux", RT5670_PDM_OUT_CTRL, 1636 RT5670_M_PDM2_L_SFT, 1, &rt5670_pdm2_l_mux), 1637 SND_SOC_DAPM_MUX("PDM2 R Mux", RT5670_PDM_OUT_CTRL, 1638 RT5670_M_PDM2_R_SFT, 1, &rt5670_pdm2_r_mux), 1639 SND_SOC_DAPM_OUTPUT("PDM1L"), 1640 SND_SOC_DAPM_OUTPUT("PDM1R"), 1641 SND_SOC_DAPM_OUTPUT("PDM2L"), 1642 SND_SOC_DAPM_OUTPUT("PDM2R"), 1643 }; 1644 1645 static const struct snd_soc_dapm_widget rt5672_specific_dapm_widgets[] = { 1646 SND_SOC_DAPM_PGA("SPO Amp", SND_SOC_NOPM, 0, 0, NULL, 0), 1647 SND_SOC_DAPM_OUTPUT("SPOLP"), 1648 SND_SOC_DAPM_OUTPUT("SPOLN"), 1649 SND_SOC_DAPM_OUTPUT("SPORP"), 1650 SND_SOC_DAPM_OUTPUT("SPORN"), 1651 }; 1652 1653 static const struct snd_soc_dapm_route rt5670_dapm_routes[] = { 1654 { "ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc }, 1655 { "ADC Stereo2 Filter", NULL, "ADC STO2 ASRC", is_using_asrc }, 1656 { "ADC Mono Left Filter", NULL, "ADC MONO L ASRC", is_using_asrc }, 1657 { "ADC Mono Right Filter", NULL, "ADC MONO R ASRC", is_using_asrc }, 1658 { "DAC Mono Left Filter", NULL, "DAC MONO L ASRC", is_using_asrc }, 1659 { "DAC Mono Right Filter", NULL, "DAC MONO R ASRC", is_using_asrc }, 1660 { "DAC Stereo1 Filter", NULL, "DAC STO ASRC", is_using_asrc }, 1661 { "Stereo1 DMIC Mux", NULL, "DMIC STO1 ASRC", can_use_asrc }, 1662 { "Stereo2 DMIC Mux", NULL, "DMIC STO2 ASRC", can_use_asrc }, 1663 { "Mono DMIC L Mux", NULL, "DMIC MONO L ASRC", can_use_asrc }, 1664 { "Mono DMIC R Mux", NULL, "DMIC MONO R ASRC", can_use_asrc }, 1665 1666 { "I2S1", NULL, "I2S1 ASRC", can_use_asrc}, 1667 { "I2S2", NULL, "I2S2 ASRC", can_use_asrc}, 1668 1669 { "DMIC1", NULL, "DMIC L1" }, 1670 { "DMIC1", NULL, "DMIC R1" }, 1671 { "DMIC2", NULL, "DMIC L2" }, 1672 { "DMIC2", NULL, "DMIC R2" }, 1673 { "DMIC3", NULL, "DMIC L3" }, 1674 { "DMIC3", NULL, "DMIC R3" }, 1675 1676 { "BST1", NULL, "IN1P" }, 1677 { "BST1", NULL, "IN1N" }, 1678 { "BST1", NULL, "Mic Det Power" }, 1679 { "BST2", NULL, "IN2P" }, 1680 { "BST2", NULL, "IN2N" }, 1681 1682 { "INL VOL", NULL, "IN2P" }, 1683 { "INR VOL", NULL, "IN2N" }, 1684 1685 { "RECMIXL", "INL Switch", "INL VOL" }, 1686 { "RECMIXL", "BST2 Switch", "BST2" }, 1687 { "RECMIXL", "BST1 Switch", "BST1" }, 1688 1689 { "RECMIXR", "INR Switch", "INR VOL" }, 1690 { "RECMIXR", "BST2 Switch", "BST2" }, 1691 { "RECMIXR", "BST1 Switch", "BST1" }, 1692 1693 { "ADC 1", NULL, "RECMIXL" }, 1694 { "ADC 1", NULL, "ADC 1 power" }, 1695 { "ADC 1", NULL, "ADC clock" }, 1696 { "ADC 2", NULL, "RECMIXR" }, 1697 { "ADC 2", NULL, "ADC 2 power" }, 1698 { "ADC 2", NULL, "ADC clock" }, 1699 1700 { "DMIC L1", NULL, "DMIC CLK" }, 1701 { "DMIC L1", NULL, "DMIC1 Power" }, 1702 { "DMIC R1", NULL, "DMIC CLK" }, 1703 { "DMIC R1", NULL, "DMIC1 Power" }, 1704 { "DMIC L2", NULL, "DMIC CLK" }, 1705 { "DMIC L2", NULL, "DMIC2 Power" }, 1706 { "DMIC R2", NULL, "DMIC CLK" }, 1707 { "DMIC R2", NULL, "DMIC2 Power" }, 1708 { "DMIC L3", NULL, "DMIC CLK" }, 1709 { "DMIC L3", NULL, "DMIC3 Power" }, 1710 { "DMIC R3", NULL, "DMIC CLK" }, 1711 { "DMIC R3", NULL, "DMIC3 Power" }, 1712 1713 { "Stereo1 DMIC Mux", "DMIC1", "DMIC1" }, 1714 { "Stereo1 DMIC Mux", "DMIC2", "DMIC2" }, 1715 { "Stereo1 DMIC Mux", "DMIC3", "DMIC3" }, 1716 1717 { "Stereo2 DMIC Mux", "DMIC1", "DMIC1" }, 1718 { "Stereo2 DMIC Mux", "DMIC2", "DMIC2" }, 1719 { "Stereo2 DMIC Mux", "DMIC3", "DMIC3" }, 1720 1721 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" }, 1722 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" }, 1723 { "Mono DMIC L Mux", "DMIC3", "DMIC L3" }, 1724 1725 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" }, 1726 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" }, 1727 { "Mono DMIC R Mux", "DMIC3", "DMIC R3" }, 1728 1729 { "ADC 1_2", NULL, "ADC 1" }, 1730 { "ADC 1_2", NULL, "ADC 2" }, 1731 1732 { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC Mux" }, 1733 { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" }, 1734 { "Stereo1 ADC L1 Mux", "ADC", "ADC 1_2" }, 1735 { "Stereo1 ADC L1 Mux", "DAC MIX", "DAC MIXL" }, 1736 1737 { "Stereo1 ADC R1 Mux", "ADC", "ADC 1_2" }, 1738 { "Stereo1 ADC R1 Mux", "DAC MIX", "DAC MIXR" }, 1739 { "Stereo1 ADC R2 Mux", "DMIC", "Stereo1 DMIC Mux" }, 1740 { "Stereo1 ADC R2 Mux", "DAC MIX", "DAC MIXR" }, 1741 1742 { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" }, 1743 { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" }, 1744 { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" }, 1745 { "Mono ADC L1 Mux", "ADC1", "ADC 1" }, 1746 1747 { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" }, 1748 { "Mono ADC R1 Mux", "ADC2", "ADC 2" }, 1749 { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" }, 1750 { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" }, 1751 1752 { "Sto1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux" }, 1753 { "Sto1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux" }, 1754 { "Sto1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux" }, 1755 { "Sto1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux" }, 1756 1757 { "Stereo1 ADC MIXL", NULL, "Sto1 ADC MIXL" }, 1758 { "Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter" }, 1759 { "ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1760 1761 { "Stereo1 ADC MIXR", NULL, "Sto1 ADC MIXR" }, 1762 { "Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter" }, 1763 { "ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1764 1765 { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" }, 1766 { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" }, 1767 { "Mono ADC MIXL", NULL, "ADC Mono Left Filter" }, 1768 { "ADC Mono Left Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1769 1770 { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" }, 1771 { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" }, 1772 { "Mono ADC MIXR", NULL, "ADC Mono Right Filter" }, 1773 { "ADC Mono Right Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1774 1775 { "Stereo2 ADC L2 Mux", "DMIC", "Stereo2 DMIC Mux" }, 1776 { "Stereo2 ADC L2 Mux", "DAC MIX", "DAC MIXL" }, 1777 { "Stereo2 ADC L1 Mux", "ADC", "ADC 1_2" }, 1778 { "Stereo2 ADC L1 Mux", "DAC MIX", "DAC MIXL" }, 1779 1780 { "Stereo2 ADC R1 Mux", "ADC", "ADC 1_2" }, 1781 { "Stereo2 ADC R1 Mux", "DAC MIX", "DAC MIXR" }, 1782 { "Stereo2 ADC R2 Mux", "DMIC", "Stereo2 DMIC Mux" }, 1783 { "Stereo2 ADC R2 Mux", "DAC MIX", "DAC MIXR" }, 1784 1785 { "Sto2 ADC MIXL", "ADC1 Switch", "Stereo2 ADC L1 Mux" }, 1786 { "Sto2 ADC MIXL", "ADC2 Switch", "Stereo2 ADC L2 Mux" }, 1787 { "Sto2 ADC MIXR", "ADC1 Switch", "Stereo2 ADC R1 Mux" }, 1788 { "Sto2 ADC MIXR", "ADC2 Switch", "Stereo2 ADC R2 Mux" }, 1789 1790 { "Sto2 ADC LR MIX", NULL, "Sto2 ADC MIXL" }, 1791 { "Sto2 ADC LR MIX", NULL, "Sto2 ADC MIXR" }, 1792 1793 { "Stereo2 ADC LR Mux", "L", "Sto2 ADC MIXL" }, 1794 { "Stereo2 ADC LR Mux", "LR", "Sto2 ADC LR MIX" }, 1795 1796 { "Stereo2 ADC MIXL", NULL, "Stereo2 ADC LR Mux" }, 1797 { "Stereo2 ADC MIXL", NULL, "ADC Stereo2 Filter" }, 1798 { "ADC Stereo2 Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1799 1800 { "Stereo2 ADC MIXR", NULL, "Sto2 ADC MIXR" }, 1801 { "Stereo2 ADC MIXR", NULL, "ADC Stereo2 Filter" }, 1802 { "ADC Stereo2 Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1803 1804 { "VAD ADC Mux", "Sto1 ADC L", "Stereo1 ADC MIXL" }, 1805 { "VAD ADC Mux", "Mono ADC L", "Mono ADC MIXL" }, 1806 { "VAD ADC Mux", "Mono ADC R", "Mono ADC MIXR" }, 1807 { "VAD ADC Mux", "Sto2 ADC L", "Sto2 ADC MIXL" }, 1808 1809 { "VAD_ADC", NULL, "VAD ADC Mux" }, 1810 1811 { "IF_ADC1", NULL, "Stereo1 ADC MIXL" }, 1812 { "IF_ADC1", NULL, "Stereo1 ADC MIXR" }, 1813 { "IF_ADC2", NULL, "Mono ADC MIXL" }, 1814 { "IF_ADC2", NULL, "Mono ADC MIXR" }, 1815 { "IF_ADC3", NULL, "Stereo2 ADC MIXL" }, 1816 { "IF_ADC3", NULL, "Stereo2 ADC MIXR" }, 1817 1818 { "IF1 ADC1 IN1 Mux", "IF_ADC1", "IF_ADC1" }, 1819 { "IF1 ADC1 IN1 Mux", "IF1_ADC3", "IF1_ADC3" }, 1820 1821 { "IF1 ADC1 IN2 Mux", "IF1_ADC1_IN1", "IF1 ADC1 IN1 Mux" }, 1822 { "IF1 ADC1 IN2 Mux", "IF1_ADC4", "IF1_ADC4" }, 1823 1824 { "IF1 ADC2 IN Mux", "IF_ADC2", "IF_ADC2" }, 1825 { "IF1 ADC2 IN Mux", "VAD_ADC", "VAD_ADC" }, 1826 1827 { "IF1 ADC2 IN1 Mux", "IF1_ADC2_IN", "IF1 ADC2 IN Mux" }, 1828 { "IF1 ADC2 IN1 Mux", "IF1_ADC4", "IF1_ADC4" }, 1829 1830 { "IF1_ADC1" , NULL, "IF1 ADC1 IN2 Mux" }, 1831 { "IF1_ADC2" , NULL, "IF1 ADC2 IN1 Mux" }, 1832 1833 { "Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXL" }, 1834 { "Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXR" }, 1835 { "Stereo2 ADC MIX", NULL, "Sto2 ADC MIXL" }, 1836 { "Stereo2 ADC MIX", NULL, "Sto2 ADC MIXR" }, 1837 { "Mono ADC MIX", NULL, "Mono ADC MIXL" }, 1838 { "Mono ADC MIX", NULL, "Mono ADC MIXR" }, 1839 1840 { "RxDP Mux", "IF2 DAC", "IF2 DAC" }, 1841 { "RxDP Mux", "IF1 DAC", "IF1 DAC2" }, 1842 { "RxDP Mux", "STO1 ADC Mixer", "Stereo1 ADC MIX" }, 1843 { "RxDP Mux", "STO2 ADC Mixer", "Stereo2 ADC MIX" }, 1844 { "RxDP Mux", "Mono ADC Mixer L", "Mono ADC MIXL" }, 1845 { "RxDP Mux", "Mono ADC Mixer R", "Mono ADC MIXR" }, 1846 { "RxDP Mux", "DAC1", "DAC MIX" }, 1847 1848 { "TDM Data Mux", "Slot 0-1", "Stereo1 ADC MIX" }, 1849 { "TDM Data Mux", "Slot 2-3", "Mono ADC MIX" }, 1850 { "TDM Data Mux", "Slot 4-5", "Stereo2 ADC MIX" }, 1851 { "TDM Data Mux", "Slot 6-7", "IF2 DAC" }, 1852 1853 { "DSP UL Mux", "Bypass", "TDM Data Mux" }, 1854 { "DSP UL Mux", NULL, "I2S DSP" }, 1855 { "DSP DL Mux", "Bypass", "RxDP Mux" }, 1856 { "DSP DL Mux", NULL, "I2S DSP" }, 1857 1858 { "TxDP_ADC_L", NULL, "DSP UL Mux" }, 1859 { "TxDP_ADC_R", NULL, "DSP UL Mux" }, 1860 { "TxDC_DAC", NULL, "DSP DL Mux" }, 1861 1862 { "TxDP_ADC", NULL, "TxDP_ADC_L" }, 1863 { "TxDP_ADC", NULL, "TxDP_ADC_R" }, 1864 1865 { "IF1 ADC", NULL, "I2S1" }, 1866 { "IF1 ADC", NULL, "IF1_ADC1" }, 1867 { "IF1 ADC", NULL, "IF1_ADC2" }, 1868 { "IF1 ADC", NULL, "IF_ADC3" }, 1869 { "IF1 ADC", NULL, "TxDP_ADC" }, 1870 1871 { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" }, 1872 { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" }, 1873 { "IF2 ADC Mux", "IF_ADC3", "IF_ADC3" }, 1874 { "IF2 ADC Mux", "TxDC_DAC", "TxDC_DAC" }, 1875 { "IF2 ADC Mux", "TxDP_ADC", "TxDP_ADC" }, 1876 { "IF2 ADC Mux", "VAD_ADC", "VAD_ADC" }, 1877 1878 { "IF2 ADC L", NULL, "IF2 ADC Mux" }, 1879 { "IF2 ADC R", NULL, "IF2 ADC Mux" }, 1880 1881 { "IF2 ADC", NULL, "I2S2" }, 1882 { "IF2 ADC", NULL, "IF2 ADC L" }, 1883 { "IF2 ADC", NULL, "IF2 ADC R" }, 1884 1885 { "AIF1TX", NULL, "IF1 ADC" }, 1886 { "AIF2TX", NULL, "IF2 ADC" }, 1887 1888 { "IF1 DAC1", NULL, "AIF1RX" }, 1889 { "IF1 DAC2", NULL, "AIF1RX" }, 1890 { "IF2 DAC", NULL, "AIF2RX" }, 1891 1892 { "IF1 DAC1", NULL, "I2S1" }, 1893 { "IF1 DAC2", NULL, "I2S1" }, 1894 { "IF2 DAC", NULL, "I2S2" }, 1895 1896 { "IF1 DAC2 L", NULL, "IF1 DAC2" }, 1897 { "IF1 DAC2 R", NULL, "IF1 DAC2" }, 1898 { "IF1 DAC1 L", NULL, "IF1 DAC1" }, 1899 { "IF1 DAC1 R", NULL, "IF1 DAC1" }, 1900 { "IF2 DAC L", NULL, "IF2 DAC" }, 1901 { "IF2 DAC R", NULL, "IF2 DAC" }, 1902 1903 { "DAC1 L Mux", "IF1 DAC", "IF1 DAC1 L" }, 1904 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" }, 1905 1906 { "DAC1 R Mux", "IF1 DAC", "IF1 DAC1 R" }, 1907 { "DAC1 R Mux", "IF2 DAC", "IF2 DAC R" }, 1908 1909 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" }, 1910 { "DAC1 MIXL", "DAC1 Switch", "DAC1 L Mux" }, 1911 { "DAC1 MIXL", NULL, "DAC Stereo1 Filter" }, 1912 { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR" }, 1913 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" }, 1914 { "DAC1 MIXR", NULL, "DAC Stereo1 Filter" }, 1915 1916 { "DAC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1917 { "DAC Mono Left Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1918 { "DAC Mono Right Filter", NULL, "PLL1", is_sys_clk_from_pll }, 1919 1920 { "DAC MIX", NULL, "DAC1 MIXL" }, 1921 { "DAC MIX", NULL, "DAC1 MIXR" }, 1922 1923 { "Audio DSP", NULL, "DAC1 MIXL" }, 1924 { "Audio DSP", NULL, "DAC1 MIXR" }, 1925 1926 { "DAC L2 Mux", "IF1 DAC", "IF1 DAC2 L" }, 1927 { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" }, 1928 { "DAC L2 Mux", "TxDC DAC", "TxDC_DAC" }, 1929 { "DAC L2 Mux", "VAD_ADC", "VAD_ADC" }, 1930 { "DAC L2 Volume", NULL, "DAC L2 Mux" }, 1931 { "DAC L2 Volume", NULL, "DAC Mono Left Filter" }, 1932 1933 { "DAC R2 Mux", "IF1 DAC", "IF1 DAC2 R" }, 1934 { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" }, 1935 { "DAC R2 Mux", "TxDC DAC", "TxDC_DAC" }, 1936 { "DAC R2 Mux", "TxDP ADC", "TxDP_ADC" }, 1937 { "DAC R2 Volume", NULL, "DAC R2 Mux" }, 1938 { "DAC R2 Volume", NULL, "DAC Mono Right Filter" }, 1939 1940 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" }, 1941 { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" }, 1942 { "Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" }, 1943 { "Stereo DAC MIXL", NULL, "DAC Stereo1 Filter" }, 1944 { "Stereo DAC MIXL", NULL, "DAC L1 Power" }, 1945 { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" }, 1946 { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" }, 1947 { "Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" }, 1948 { "Stereo DAC MIXR", NULL, "DAC Stereo1 Filter" }, 1949 { "Stereo DAC MIXR", NULL, "DAC R1 Power" }, 1950 1951 { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" }, 1952 { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" }, 1953 { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" }, 1954 { "Mono DAC MIXL", NULL, "DAC Mono Left Filter" }, 1955 { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" }, 1956 { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" }, 1957 { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" }, 1958 { "Mono DAC MIXR", NULL, "DAC Mono Right Filter" }, 1959 1960 { "DAC MIXL", "Sto DAC Mix L Switch", "Stereo DAC MIXL" }, 1961 { "DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" }, 1962 { "DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" }, 1963 { "DAC MIXR", "Sto DAC Mix R Switch", "Stereo DAC MIXR" }, 1964 { "DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" }, 1965 { "DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" }, 1966 1967 { "DAC L1", NULL, "DAC L1 Power" }, 1968 { "DAC L1", NULL, "Stereo DAC MIXL" }, 1969 { "DAC R1", NULL, "DAC R1 Power" }, 1970 { "DAC R1", NULL, "Stereo DAC MIXR" }, 1971 { "DAC L2", NULL, "Mono DAC MIXL" }, 1972 { "DAC R2", NULL, "Mono DAC MIXR" }, 1973 1974 { "OUT MIXL", "BST1 Switch", "BST1" }, 1975 { "OUT MIXL", "INL Switch", "INL VOL" }, 1976 { "OUT MIXL", "DAC L2 Switch", "DAC L2" }, 1977 { "OUT MIXL", "DAC L1 Switch", "DAC L1" }, 1978 1979 { "OUT MIXR", "BST2 Switch", "BST2" }, 1980 { "OUT MIXR", "INR Switch", "INR VOL" }, 1981 { "OUT MIXR", "DAC R2 Switch", "DAC R2" }, 1982 { "OUT MIXR", "DAC R1 Switch", "DAC R1" }, 1983 1984 { "HPOVOL MIXL", "DAC1 Switch", "DAC L1" }, 1985 { "HPOVOL MIXL", "INL Switch", "INL VOL" }, 1986 { "HPOVOL MIXR", "DAC1 Switch", "DAC R1" }, 1987 { "HPOVOL MIXR", "INR Switch", "INR VOL" }, 1988 1989 { "DAC 2", NULL, "DAC L2" }, 1990 { "DAC 2", NULL, "DAC R2" }, 1991 { "DAC 1", NULL, "DAC L1" }, 1992 { "DAC 1", NULL, "DAC R1" }, 1993 { "HPOVOL", NULL, "HPOVOL MIXL" }, 1994 { "HPOVOL", NULL, "HPOVOL MIXR" }, 1995 { "HPO MIX", "DAC1 Switch", "DAC 1" }, 1996 { "HPO MIX", "HPVOL Switch", "HPOVOL" }, 1997 1998 { "LOUT MIX", "DAC L1 Switch", "DAC L1" }, 1999 { "LOUT MIX", "DAC R1 Switch", "DAC R1" }, 2000 { "LOUT MIX", "OUTMIX L Switch", "OUT MIXL" }, 2001 { "LOUT MIX", "OUTMIX R Switch", "OUT MIXR" }, 2002 2003 { "PDM1 L Mux", "Stereo DAC", "Stereo DAC MIXL" }, 2004 { "PDM1 L Mux", "Mono DAC", "Mono DAC MIXL" }, 2005 { "PDM1 L Mux", NULL, "PDM1 Power" }, 2006 { "PDM1 R Mux", "Stereo DAC", "Stereo DAC MIXR" }, 2007 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" }, 2008 { "PDM1 R Mux", NULL, "PDM1 Power" }, 2009 2010 { "HP Amp", NULL, "HPO MIX" }, 2011 { "HP Amp", NULL, "Mic Det Power" }, 2012 { "HPOL", NULL, "HP Amp" }, 2013 { "HPOL", NULL, "HP L Amp" }, 2014 { "HPOL", NULL, "Improve HP Amp Drv" }, 2015 { "HPOR", NULL, "HP Amp" }, 2016 { "HPOR", NULL, "HP R Amp" }, 2017 { "HPOR", NULL, "Improve HP Amp Drv" }, 2018 2019 { "LOUT Amp", NULL, "LOUT MIX" }, 2020 { "LOUT L Playback", "Switch", "LOUT Amp" }, 2021 { "LOUT R Playback", "Switch", "LOUT Amp" }, 2022 { "LOUTL", NULL, "LOUT L Playback" }, 2023 { "LOUTR", NULL, "LOUT R Playback" }, 2024 { "LOUTL", NULL, "Improve HP Amp Drv" }, 2025 { "LOUTR", NULL, "Improve HP Amp Drv" }, 2026 }; 2027 2028 static const struct snd_soc_dapm_route rt5670_specific_dapm_routes[] = { 2029 { "PDM2 L Mux", "Stereo DAC", "Stereo DAC MIXL" }, 2030 { "PDM2 L Mux", "Mono DAC", "Mono DAC MIXL" }, 2031 { "PDM2 L Mux", NULL, "PDM2 Power" }, 2032 { "PDM2 R Mux", "Stereo DAC", "Stereo DAC MIXR" }, 2033 { "PDM2 R Mux", "Mono DAC", "Mono DAC MIXR" }, 2034 { "PDM2 R Mux", NULL, "PDM2 Power" }, 2035 { "PDM1L", NULL, "PDM1 L Mux" }, 2036 { "PDM1R", NULL, "PDM1 R Mux" }, 2037 { "PDM2L", NULL, "PDM2 L Mux" }, 2038 { "PDM2R", NULL, "PDM2 R Mux" }, 2039 }; 2040 2041 static const struct snd_soc_dapm_route rt5672_specific_dapm_routes[] = { 2042 { "SPO Amp", NULL, "PDM1 L Mux" }, 2043 { "SPO Amp", NULL, "PDM1 R Mux" }, 2044 { "SPOLP", NULL, "SPO Amp" }, 2045 { "SPOLN", NULL, "SPO Amp" }, 2046 { "SPORP", NULL, "SPO Amp" }, 2047 { "SPORN", NULL, "SPO Amp" }, 2048 }; 2049 2050 static int rt5670_hw_params(struct snd_pcm_substream *substream, 2051 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 2052 { 2053 struct snd_soc_codec *codec = dai->codec; 2054 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2055 unsigned int val_len = 0, val_clk, mask_clk; 2056 int pre_div, bclk_ms, frame_size; 2057 2058 rt5670->lrck[dai->id] = params_rate(params); 2059 pre_div = rl6231_get_clk_info(rt5670->sysclk, rt5670->lrck[dai->id]); 2060 if (pre_div < 0) { 2061 dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n", 2062 rt5670->lrck[dai->id], dai->id); 2063 return -EINVAL; 2064 } 2065 frame_size = snd_soc_params_to_frame_size(params); 2066 if (frame_size < 0) { 2067 dev_err(codec->dev, "Unsupported frame size: %d\n", frame_size); 2068 return -EINVAL; 2069 } 2070 bclk_ms = frame_size > 32; 2071 rt5670->bclk[dai->id] = rt5670->lrck[dai->id] * (32 << bclk_ms); 2072 2073 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", 2074 rt5670->bclk[dai->id], rt5670->lrck[dai->id]); 2075 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 2076 bclk_ms, pre_div, dai->id); 2077 2078 switch (params_width(params)) { 2079 case 16: 2080 break; 2081 case 20: 2082 val_len |= RT5670_I2S_DL_20; 2083 break; 2084 case 24: 2085 val_len |= RT5670_I2S_DL_24; 2086 break; 2087 case 8: 2088 val_len |= RT5670_I2S_DL_8; 2089 break; 2090 default: 2091 return -EINVAL; 2092 } 2093 2094 switch (dai->id) { 2095 case RT5670_AIF1: 2096 mask_clk = RT5670_I2S_BCLK_MS1_MASK | RT5670_I2S_PD1_MASK; 2097 val_clk = bclk_ms << RT5670_I2S_BCLK_MS1_SFT | 2098 pre_div << RT5670_I2S_PD1_SFT; 2099 snd_soc_update_bits(codec, RT5670_I2S1_SDP, 2100 RT5670_I2S_DL_MASK, val_len); 2101 snd_soc_update_bits(codec, RT5670_ADDA_CLK1, mask_clk, val_clk); 2102 break; 2103 case RT5670_AIF2: 2104 mask_clk = RT5670_I2S_BCLK_MS2_MASK | RT5670_I2S_PD2_MASK; 2105 val_clk = bclk_ms << RT5670_I2S_BCLK_MS2_SFT | 2106 pre_div << RT5670_I2S_PD2_SFT; 2107 snd_soc_update_bits(codec, RT5670_I2S2_SDP, 2108 RT5670_I2S_DL_MASK, val_len); 2109 snd_soc_update_bits(codec, RT5670_ADDA_CLK1, mask_clk, val_clk); 2110 break; 2111 default: 2112 dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id); 2113 return -EINVAL; 2114 } 2115 2116 return 0; 2117 } 2118 2119 static int rt5670_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 2120 { 2121 struct snd_soc_codec *codec = dai->codec; 2122 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2123 unsigned int reg_val = 0; 2124 2125 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 2126 case SND_SOC_DAIFMT_CBM_CFM: 2127 rt5670->master[dai->id] = 1; 2128 break; 2129 case SND_SOC_DAIFMT_CBS_CFS: 2130 reg_val |= RT5670_I2S_MS_S; 2131 rt5670->master[dai->id] = 0; 2132 break; 2133 default: 2134 return -EINVAL; 2135 } 2136 2137 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 2138 case SND_SOC_DAIFMT_NB_NF: 2139 break; 2140 case SND_SOC_DAIFMT_IB_NF: 2141 reg_val |= RT5670_I2S_BP_INV; 2142 break; 2143 default: 2144 return -EINVAL; 2145 } 2146 2147 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 2148 case SND_SOC_DAIFMT_I2S: 2149 break; 2150 case SND_SOC_DAIFMT_LEFT_J: 2151 reg_val |= RT5670_I2S_DF_LEFT; 2152 break; 2153 case SND_SOC_DAIFMT_DSP_A: 2154 reg_val |= RT5670_I2S_DF_PCM_A; 2155 break; 2156 case SND_SOC_DAIFMT_DSP_B: 2157 reg_val |= RT5670_I2S_DF_PCM_B; 2158 break; 2159 default: 2160 return -EINVAL; 2161 } 2162 2163 switch (dai->id) { 2164 case RT5670_AIF1: 2165 snd_soc_update_bits(codec, RT5670_I2S1_SDP, 2166 RT5670_I2S_MS_MASK | RT5670_I2S_BP_MASK | 2167 RT5670_I2S_DF_MASK, reg_val); 2168 break; 2169 case RT5670_AIF2: 2170 snd_soc_update_bits(codec, RT5670_I2S2_SDP, 2171 RT5670_I2S_MS_MASK | RT5670_I2S_BP_MASK | 2172 RT5670_I2S_DF_MASK, reg_val); 2173 break; 2174 default: 2175 dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id); 2176 return -EINVAL; 2177 } 2178 return 0; 2179 } 2180 2181 static int rt5670_set_dai_sysclk(struct snd_soc_dai *dai, 2182 int clk_id, unsigned int freq, int dir) 2183 { 2184 struct snd_soc_codec *codec = dai->codec; 2185 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2186 unsigned int reg_val = 0; 2187 2188 if (freq == rt5670->sysclk && clk_id == rt5670->sysclk_src) 2189 return 0; 2190 2191 switch (clk_id) { 2192 case RT5670_SCLK_S_MCLK: 2193 reg_val |= RT5670_SCLK_SRC_MCLK; 2194 break; 2195 case RT5670_SCLK_S_PLL1: 2196 reg_val |= RT5670_SCLK_SRC_PLL1; 2197 break; 2198 case RT5670_SCLK_S_RCCLK: 2199 reg_val |= RT5670_SCLK_SRC_RCCLK; 2200 break; 2201 default: 2202 dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id); 2203 return -EINVAL; 2204 } 2205 snd_soc_update_bits(codec, RT5670_GLB_CLK, 2206 RT5670_SCLK_SRC_MASK, reg_val); 2207 rt5670->sysclk = freq; 2208 rt5670->sysclk_src = clk_id; 2209 2210 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); 2211 2212 return 0; 2213 } 2214 2215 static int rt5670_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, 2216 unsigned int freq_in, unsigned int freq_out) 2217 { 2218 struct snd_soc_codec *codec = dai->codec; 2219 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2220 struct rl6231_pll_code pll_code; 2221 int ret; 2222 2223 if (source == rt5670->pll_src && freq_in == rt5670->pll_in && 2224 freq_out == rt5670->pll_out) 2225 return 0; 2226 2227 if (!freq_in || !freq_out) { 2228 dev_dbg(codec->dev, "PLL disabled\n"); 2229 2230 rt5670->pll_in = 0; 2231 rt5670->pll_out = 0; 2232 snd_soc_update_bits(codec, RT5670_GLB_CLK, 2233 RT5670_SCLK_SRC_MASK, RT5670_SCLK_SRC_MCLK); 2234 return 0; 2235 } 2236 2237 switch (source) { 2238 case RT5670_PLL1_S_MCLK: 2239 snd_soc_update_bits(codec, RT5670_GLB_CLK, 2240 RT5670_PLL1_SRC_MASK, RT5670_PLL1_SRC_MCLK); 2241 break; 2242 case RT5670_PLL1_S_BCLK1: 2243 case RT5670_PLL1_S_BCLK2: 2244 case RT5670_PLL1_S_BCLK3: 2245 case RT5670_PLL1_S_BCLK4: 2246 switch (dai->id) { 2247 case RT5670_AIF1: 2248 snd_soc_update_bits(codec, RT5670_GLB_CLK, 2249 RT5670_PLL1_SRC_MASK, RT5670_PLL1_SRC_BCLK1); 2250 break; 2251 case RT5670_AIF2: 2252 snd_soc_update_bits(codec, RT5670_GLB_CLK, 2253 RT5670_PLL1_SRC_MASK, RT5670_PLL1_SRC_BCLK2); 2254 break; 2255 default: 2256 dev_err(codec->dev, "Invalid dai->id: %d\n", dai->id); 2257 return -EINVAL; 2258 } 2259 break; 2260 default: 2261 dev_err(codec->dev, "Unknown PLL source %d\n", source); 2262 return -EINVAL; 2263 } 2264 2265 ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 2266 if (ret < 0) { 2267 dev_err(codec->dev, "Unsupport input clock %d\n", freq_in); 2268 return ret; 2269 } 2270 2271 dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n", 2272 pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 2273 pll_code.n_code, pll_code.k_code); 2274 2275 snd_soc_write(codec, RT5670_PLL_CTRL1, 2276 pll_code.n_code << RT5670_PLL_N_SFT | pll_code.k_code); 2277 snd_soc_write(codec, RT5670_PLL_CTRL2, 2278 (pll_code.m_bp ? 0 : pll_code.m_code) << RT5670_PLL_M_SFT | 2279 pll_code.m_bp << RT5670_PLL_M_BP_SFT); 2280 2281 rt5670->pll_in = freq_in; 2282 rt5670->pll_out = freq_out; 2283 rt5670->pll_src = source; 2284 2285 return 0; 2286 } 2287 2288 static int rt5670_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, 2289 unsigned int rx_mask, int slots, int slot_width) 2290 { 2291 struct snd_soc_codec *codec = dai->codec; 2292 unsigned int val = 0; 2293 2294 if (rx_mask || tx_mask) 2295 val |= (1 << 14); 2296 2297 switch (slots) { 2298 case 4: 2299 val |= (1 << 12); 2300 break; 2301 case 6: 2302 val |= (2 << 12); 2303 break; 2304 case 8: 2305 val |= (3 << 12); 2306 break; 2307 case 2: 2308 break; 2309 default: 2310 return -EINVAL; 2311 } 2312 2313 switch (slot_width) { 2314 case 20: 2315 val |= (1 << 10); 2316 break; 2317 case 24: 2318 val |= (2 << 10); 2319 break; 2320 case 32: 2321 val |= (3 << 10); 2322 break; 2323 case 16: 2324 break; 2325 default: 2326 return -EINVAL; 2327 } 2328 2329 snd_soc_update_bits(codec, RT5670_TDM_CTRL_1, 0x7c00, val); 2330 2331 return 0; 2332 } 2333 2334 static int rt5670_set_bias_level(struct snd_soc_codec *codec, 2335 enum snd_soc_bias_level level) 2336 { 2337 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2338 2339 switch (level) { 2340 case SND_SOC_BIAS_PREPARE: 2341 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 2342 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2343 RT5670_PWR_VREF1 | RT5670_PWR_MB | 2344 RT5670_PWR_BG | RT5670_PWR_VREF2, 2345 RT5670_PWR_VREF1 | RT5670_PWR_MB | 2346 RT5670_PWR_BG | RT5670_PWR_VREF2); 2347 mdelay(10); 2348 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2349 RT5670_PWR_FV1 | RT5670_PWR_FV2, 2350 RT5670_PWR_FV1 | RT5670_PWR_FV2); 2351 snd_soc_update_bits(codec, RT5670_CHARGE_PUMP, 2352 RT5670_OSW_L_MASK | RT5670_OSW_R_MASK, 2353 RT5670_OSW_L_DIS | RT5670_OSW_R_DIS); 2354 snd_soc_update_bits(codec, RT5670_DIG_MISC, 0x1, 0x1); 2355 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2356 RT5670_LDO_SEL_MASK, 0x3); 2357 } 2358 break; 2359 case SND_SOC_BIAS_STANDBY: 2360 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2361 RT5670_PWR_VREF1 | RT5670_PWR_VREF2 | 2362 RT5670_PWR_FV1 | RT5670_PWR_FV2, 0); 2363 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2364 RT5670_LDO_SEL_MASK, 0x1); 2365 break; 2366 case SND_SOC_BIAS_OFF: 2367 if (rt5670->pdata.jd_mode) 2368 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2369 RT5670_PWR_VREF1 | RT5670_PWR_MB | 2370 RT5670_PWR_BG | RT5670_PWR_VREF2 | 2371 RT5670_PWR_FV1 | RT5670_PWR_FV2, 2372 RT5670_PWR_MB | RT5670_PWR_BG); 2373 else 2374 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2375 RT5670_PWR_VREF1 | RT5670_PWR_MB | 2376 RT5670_PWR_BG | RT5670_PWR_VREF2 | 2377 RT5670_PWR_FV1 | RT5670_PWR_FV2, 0); 2378 2379 snd_soc_update_bits(codec, RT5670_DIG_MISC, 0x1, 0x0); 2380 break; 2381 2382 default: 2383 break; 2384 } 2385 codec->dapm.bias_level = level; 2386 2387 return 0; 2388 } 2389 2390 static int rt5670_probe(struct snd_soc_codec *codec) 2391 { 2392 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2393 2394 switch (snd_soc_read(codec, RT5670_RESET) & RT5670_ID_MASK) { 2395 case RT5670_ID_5670: 2396 case RT5670_ID_5671: 2397 snd_soc_dapm_new_controls(&codec->dapm, 2398 rt5670_specific_dapm_widgets, 2399 ARRAY_SIZE(rt5670_specific_dapm_widgets)); 2400 snd_soc_dapm_add_routes(&codec->dapm, 2401 rt5670_specific_dapm_routes, 2402 ARRAY_SIZE(rt5670_specific_dapm_routes)); 2403 break; 2404 case RT5670_ID_5672: 2405 snd_soc_dapm_new_controls(&codec->dapm, 2406 rt5672_specific_dapm_widgets, 2407 ARRAY_SIZE(rt5672_specific_dapm_widgets)); 2408 snd_soc_dapm_add_routes(&codec->dapm, 2409 rt5672_specific_dapm_routes, 2410 ARRAY_SIZE(rt5672_specific_dapm_routes)); 2411 break; 2412 default: 2413 dev_err(codec->dev, 2414 "The driver is for RT5670 RT5671 or RT5672 only\n"); 2415 return -ENODEV; 2416 } 2417 rt5670->codec = codec; 2418 2419 return 0; 2420 } 2421 2422 static int rt5670_remove(struct snd_soc_codec *codec) 2423 { 2424 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2425 2426 regmap_write(rt5670->regmap, RT5670_RESET, 0); 2427 return 0; 2428 } 2429 2430 #ifdef CONFIG_PM 2431 static int rt5670_suspend(struct snd_soc_codec *codec) 2432 { 2433 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2434 2435 regcache_cache_only(rt5670->regmap, true); 2436 regcache_mark_dirty(rt5670->regmap); 2437 return 0; 2438 } 2439 2440 static int rt5670_resume(struct snd_soc_codec *codec) 2441 { 2442 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2443 2444 regcache_cache_only(rt5670->regmap, false); 2445 regcache_sync(rt5670->regmap); 2446 2447 return 0; 2448 } 2449 #else 2450 #define rt5670_suspend NULL 2451 #define rt5670_resume NULL 2452 #endif 2453 2454 #define RT5670_STEREO_RATES SNDRV_PCM_RATE_8000_96000 2455 #define RT5670_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 2456 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 2457 2458 static struct snd_soc_dai_ops rt5670_aif_dai_ops = { 2459 .hw_params = rt5670_hw_params, 2460 .set_fmt = rt5670_set_dai_fmt, 2461 .set_sysclk = rt5670_set_dai_sysclk, 2462 .set_tdm_slot = rt5670_set_tdm_slot, 2463 .set_pll = rt5670_set_dai_pll, 2464 }; 2465 2466 static struct snd_soc_dai_driver rt5670_dai[] = { 2467 { 2468 .name = "rt5670-aif1", 2469 .id = RT5670_AIF1, 2470 .playback = { 2471 .stream_name = "AIF1 Playback", 2472 .channels_min = 1, 2473 .channels_max = 2, 2474 .rates = RT5670_STEREO_RATES, 2475 .formats = RT5670_FORMATS, 2476 }, 2477 .capture = { 2478 .stream_name = "AIF1 Capture", 2479 .channels_min = 1, 2480 .channels_max = 2, 2481 .rates = RT5670_STEREO_RATES, 2482 .formats = RT5670_FORMATS, 2483 }, 2484 .ops = &rt5670_aif_dai_ops, 2485 }, 2486 { 2487 .name = "rt5670-aif2", 2488 .id = RT5670_AIF2, 2489 .playback = { 2490 .stream_name = "AIF2 Playback", 2491 .channels_min = 1, 2492 .channels_max = 2, 2493 .rates = RT5670_STEREO_RATES, 2494 .formats = RT5670_FORMATS, 2495 }, 2496 .capture = { 2497 .stream_name = "AIF2 Capture", 2498 .channels_min = 1, 2499 .channels_max = 2, 2500 .rates = RT5670_STEREO_RATES, 2501 .formats = RT5670_FORMATS, 2502 }, 2503 .ops = &rt5670_aif_dai_ops, 2504 }, 2505 }; 2506 2507 static struct snd_soc_codec_driver soc_codec_dev_rt5670 = { 2508 .probe = rt5670_probe, 2509 .remove = rt5670_remove, 2510 .suspend = rt5670_suspend, 2511 .resume = rt5670_resume, 2512 .set_bias_level = rt5670_set_bias_level, 2513 .idle_bias_off = true, 2514 .controls = rt5670_snd_controls, 2515 .num_controls = ARRAY_SIZE(rt5670_snd_controls), 2516 .dapm_widgets = rt5670_dapm_widgets, 2517 .num_dapm_widgets = ARRAY_SIZE(rt5670_dapm_widgets), 2518 .dapm_routes = rt5670_dapm_routes, 2519 .num_dapm_routes = ARRAY_SIZE(rt5670_dapm_routes), 2520 }; 2521 2522 static const struct regmap_config rt5670_regmap = { 2523 .reg_bits = 8, 2524 .val_bits = 16, 2525 .max_register = RT5670_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5670_ranges) * 2526 RT5670_PR_SPACING), 2527 .volatile_reg = rt5670_volatile_register, 2528 .readable_reg = rt5670_readable_register, 2529 .cache_type = REGCACHE_RBTREE, 2530 .reg_defaults = rt5670_reg, 2531 .num_reg_defaults = ARRAY_SIZE(rt5670_reg), 2532 .ranges = rt5670_ranges, 2533 .num_ranges = ARRAY_SIZE(rt5670_ranges), 2534 }; 2535 2536 static const struct i2c_device_id rt5670_i2c_id[] = { 2537 { "rt5670", 0 }, 2538 { "rt5671", 0 }, 2539 { "rt5672", 0 }, 2540 { } 2541 }; 2542 MODULE_DEVICE_TABLE(i2c, rt5670_i2c_id); 2543 2544 #ifdef CONFIG_ACPI 2545 static struct acpi_device_id rt5670_acpi_match[] = { 2546 { "10EC5670", 0}, 2547 { }, 2548 }; 2549 MODULE_DEVICE_TABLE(acpi, rt5670_acpi_match); 2550 #endif 2551 2552 static int rt5670_i2c_probe(struct i2c_client *i2c, 2553 const struct i2c_device_id *id) 2554 { 2555 struct rt5670_platform_data *pdata = dev_get_platdata(&i2c->dev); 2556 struct rt5670_priv *rt5670; 2557 int ret; 2558 unsigned int val; 2559 2560 rt5670 = devm_kzalloc(&i2c->dev, 2561 sizeof(struct rt5670_priv), 2562 GFP_KERNEL); 2563 if (NULL == rt5670) 2564 return -ENOMEM; 2565 2566 i2c_set_clientdata(i2c, rt5670); 2567 2568 if (pdata) 2569 rt5670->pdata = *pdata; 2570 2571 rt5670->regmap = devm_regmap_init_i2c(i2c, &rt5670_regmap); 2572 if (IS_ERR(rt5670->regmap)) { 2573 ret = PTR_ERR(rt5670->regmap); 2574 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 2575 ret); 2576 return ret; 2577 } 2578 2579 regmap_read(rt5670->regmap, RT5670_VENDOR_ID2, &val); 2580 if (val != RT5670_DEVICE_ID) { 2581 dev_err(&i2c->dev, 2582 "Device with ID register %x is not rt5670/72\n", val); 2583 return -ENODEV; 2584 } 2585 2586 regmap_write(rt5670->regmap, RT5670_RESET, 0); 2587 regmap_update_bits(rt5670->regmap, RT5670_PWR_ANLG1, 2588 RT5670_PWR_HP_L | RT5670_PWR_HP_R | 2589 RT5670_PWR_VREF2, RT5670_PWR_VREF2); 2590 msleep(100); 2591 2592 regmap_write(rt5670->regmap, RT5670_RESET, 0); 2593 2594 ret = regmap_register_patch(rt5670->regmap, init_list, 2595 ARRAY_SIZE(init_list)); 2596 if (ret != 0) 2597 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); 2598 2599 if (rt5670->pdata.in2_diff) 2600 regmap_update_bits(rt5670->regmap, RT5670_IN2, 2601 RT5670_IN_DF2, RT5670_IN_DF2); 2602 2603 if (i2c->irq) { 2604 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2605 RT5670_GP1_PIN_MASK, RT5670_GP1_PIN_IRQ); 2606 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL2, 2607 RT5670_GP1_PF_MASK, RT5670_GP1_PF_OUT); 2608 2609 } 2610 2611 if (rt5670->pdata.jd_mode) { 2612 regmap_update_bits(rt5670->regmap, RT5670_PWR_ANLG1, 2613 RT5670_PWR_MB, RT5670_PWR_MB); 2614 regmap_update_bits(rt5670->regmap, RT5670_PWR_ANLG2, 2615 RT5670_PWR_JD1, RT5670_PWR_JD1); 2616 regmap_update_bits(rt5670->regmap, RT5670_IRQ_CTRL1, 2617 RT5670_JD1_1_EN_MASK, RT5670_JD1_1_EN); 2618 regmap_update_bits(rt5670->regmap, RT5670_JD_CTRL3, 2619 RT5670_JD_TRI_CBJ_SEL_MASK | 2620 RT5670_JD_TRI_HPO_SEL_MASK, 2621 RT5670_JD_CBJ_JD1_1 | RT5670_JD_HPO_JD1_1); 2622 switch (rt5670->pdata.jd_mode) { 2623 case 1: 2624 regmap_update_bits(rt5670->regmap, RT5670_A_JD_CTRL1, 2625 RT5670_JD1_MODE_MASK, 2626 RT5670_JD1_MODE_0); 2627 break; 2628 case 2: 2629 regmap_update_bits(rt5670->regmap, RT5670_A_JD_CTRL1, 2630 RT5670_JD1_MODE_MASK, 2631 RT5670_JD1_MODE_1); 2632 break; 2633 case 3: 2634 regmap_update_bits(rt5670->regmap, RT5670_A_JD_CTRL1, 2635 RT5670_JD1_MODE_MASK, 2636 RT5670_JD1_MODE_2); 2637 break; 2638 default: 2639 break; 2640 } 2641 } 2642 2643 if (rt5670->pdata.dmic_en) { 2644 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2645 RT5670_GP2_PIN_MASK, 2646 RT5670_GP2_PIN_DMIC1_SCL); 2647 2648 switch (rt5670->pdata.dmic1_data_pin) { 2649 case RT5670_DMIC_DATA_IN2P: 2650 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL1, 2651 RT5670_DMIC_1_DP_MASK, 2652 RT5670_DMIC_1_DP_IN2P); 2653 break; 2654 2655 case RT5670_DMIC_DATA_GPIO6: 2656 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL1, 2657 RT5670_DMIC_1_DP_MASK, 2658 RT5670_DMIC_1_DP_GPIO6); 2659 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2660 RT5670_GP6_PIN_MASK, 2661 RT5670_GP6_PIN_DMIC1_SDA); 2662 break; 2663 2664 case RT5670_DMIC_DATA_GPIO7: 2665 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL1, 2666 RT5670_DMIC_1_DP_MASK, 2667 RT5670_DMIC_1_DP_GPIO7); 2668 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2669 RT5670_GP7_PIN_MASK, 2670 RT5670_GP7_PIN_DMIC1_SDA); 2671 break; 2672 2673 default: 2674 break; 2675 } 2676 2677 switch (rt5670->pdata.dmic2_data_pin) { 2678 case RT5670_DMIC_DATA_IN3N: 2679 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL1, 2680 RT5670_DMIC_2_DP_MASK, 2681 RT5670_DMIC_2_DP_IN3N); 2682 break; 2683 2684 case RT5670_DMIC_DATA_GPIO8: 2685 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL1, 2686 RT5670_DMIC_2_DP_MASK, 2687 RT5670_DMIC_2_DP_GPIO8); 2688 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2689 RT5670_GP8_PIN_MASK, 2690 RT5670_GP8_PIN_DMIC2_SDA); 2691 break; 2692 2693 default: 2694 break; 2695 } 2696 2697 switch (rt5670->pdata.dmic3_data_pin) { 2698 case RT5670_DMIC_DATA_GPIO5: 2699 regmap_update_bits(rt5670->regmap, RT5670_DMIC_CTRL2, 2700 RT5670_DMIC_3_DP_MASK, 2701 RT5670_DMIC_3_DP_GPIO5); 2702 regmap_update_bits(rt5670->regmap, RT5670_GPIO_CTRL1, 2703 RT5670_GP5_PIN_MASK, 2704 RT5670_GP5_PIN_DMIC3_SDA); 2705 break; 2706 2707 case RT5670_DMIC_DATA_GPIO9: 2708 case RT5670_DMIC_DATA_GPIO10: 2709 dev_err(&i2c->dev, 2710 "Always use GPIO5 as DMIC3 data pin\n"); 2711 break; 2712 2713 default: 2714 break; 2715 } 2716 2717 } 2718 2719 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5670, 2720 rt5670_dai, ARRAY_SIZE(rt5670_dai)); 2721 if (ret < 0) 2722 goto err; 2723 2724 return 0; 2725 err: 2726 return ret; 2727 } 2728 2729 static int rt5670_i2c_remove(struct i2c_client *i2c) 2730 { 2731 snd_soc_unregister_codec(&i2c->dev); 2732 2733 return 0; 2734 } 2735 2736 static struct i2c_driver rt5670_i2c_driver = { 2737 .driver = { 2738 .name = "rt5670", 2739 .owner = THIS_MODULE, 2740 .acpi_match_table = ACPI_PTR(rt5670_acpi_match), 2741 }, 2742 .probe = rt5670_i2c_probe, 2743 .remove = rt5670_i2c_remove, 2744 .id_table = rt5670_i2c_id, 2745 }; 2746 2747 module_i2c_driver(rt5670_i2c_driver); 2748 2749 MODULE_DESCRIPTION("ASoC RT5670 driver"); 2750 MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>"); 2751 MODULE_LICENSE("GPL v2"); 2752