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