Lines Matching +full:use +full:- +full:jd2
1 // SPDX-License-Identifier: GPL-2.0
3 // rt711.c -- rt711 ALSA SoC audio driver
24 #include <sound/soc-dapm.h>
89 struct regmap *regmap = rt711->regmap; in rt711_calibration()
92 mutex_lock(&rt711->calibrate_mutex); in rt711_calibration()
93 regmap_write(rt711->regmap, in rt711_calibration()
113 pr_err("%s, calibration time-out!\n", in rt711_calibration()
115 ret = -ETIMEDOUT; in rt711_calibration()
129 regmap_write(rt711->regmap, in rt711_calibration()
131 mutex_unlock(&rt711->calibrate_mutex); in rt711_calibration()
142 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_button_detect()
146 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_button_detect()
190 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_headset_detect()
200 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_headset_detect()
206 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_headset_detect()
217 rt711->jack_type = SND_JACK_HEADPHONE; in rt711_headset_detect()
220 rt711->jack_type = SND_JACK_HEADSET; in rt711_headset_detect()
225 ret = -ETIMEDOUT; in rt711_headset_detect()
226 pr_err_ratelimited("Time-out error in %s\n", __func__); in rt711_headset_detect()
233 return -ENODEV; in rt711_headset_detect()
243 if (!rt711->hs_jack) in rt711_jack_detect_handler()
246 if (!snd_soc_card_is_instantiated(rt711->component->card)) in rt711_jack_detect_handler()
249 if (pm_runtime_status_suspended(rt711->slave->dev.parent)) { in rt711_jack_detect_handler()
250 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
257 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_jack_detect_handler()
264 if (rt711->jack_type == 0) { in rt711_jack_detect_handler()
268 if (rt711->jack_type == SND_JACK_HEADSET) in rt711_jack_detect_handler()
270 } else if (rt711->jack_type == SND_JACK_HEADSET) { in rt711_jack_detect_handler()
276 rt711->jack_type = 0; in rt711_jack_detect_handler()
279 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
280 "in %s, jack_type=0x%x\n", __func__, rt711->jack_type); in rt711_jack_detect_handler()
281 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
284 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type | btn_type, in rt711_jack_detect_handler()
291 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type, in rt711_jack_detect_handler()
297 &rt711->jack_btn_check_work, msecs_to_jiffies(200)); in rt711_jack_detect_handler()
314 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_btn_check_handler()
320 if (rt711->jack_type == SND_JACK_HEADSET) { in rt711_btn_check_handler()
325 rt711->jack_type = 0; in rt711_btn_check_handler()
329 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_btn_check_handler()
337 dev_dbg(&rt711->slave->dev, in rt711_btn_check_handler()
339 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type | btn_type, in rt711_btn_check_handler()
346 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type, in rt711_btn_check_handler()
352 &rt711->jack_btn_check_work, msecs_to_jiffies(200)); in rt711_btn_check_handler()
364 snd_soc_component_get_dapm(rt711->component); in rt711_jack_init()
366 mutex_lock(&rt711->calibrate_mutex); in rt711_jack_init()
368 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_jack_init()
369 regmap_write(rt711->regmap, in rt711_jack_init()
372 if (rt711->hs_jack) { in rt711_jack_init()
374 regmap_write(rt711->regmap, in rt711_jack_init()
376 regmap_write(rt711->regmap, in rt711_jack_init()
378 regmap_write(rt711->regmap, in rt711_jack_init()
380 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
382 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
385 switch (rt711->jd_src) { in rt711_jack_init()
390 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
395 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
401 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
406 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
412 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
415 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
420 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
425 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
431 dev_warn(rt711->component->dev, "%s: Wrong JD source\n", __func__); in rt711_jack_init()
435 dev_dbg(&rt711->slave->dev, "in %s enable\n", __func__); in rt711_jack_init()
438 &rt711->jack_detect_work, msecs_to_jiffies(250)); in rt711_jack_init()
440 regmap_write(rt711->regmap, in rt711_jack_init()
442 regmap_write(rt711->regmap, in rt711_jack_init()
444 regmap_write(rt711->regmap, in rt711_jack_init()
447 dev_dbg(&rt711->slave->dev, "in %s disable\n", __func__); in rt711_jack_init()
451 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_jack_init()
452 regmap_write(rt711->regmap, in rt711_jack_init()
454 mutex_unlock(&rt711->calibrate_mutex); in rt711_jack_init()
463 rt711->hs_jack = hs_jack; in rt711_set_jack_detect()
466 if (!rt711->first_hw_init) in rt711_set_jack_detect()
469 ret = pm_runtime_resume_and_get(component->dev); in rt711_set_jack_detect()
471 if (ret != -EACCES) { in rt711_set_jack_detect()
472 dev_err(component->dev, "%s: failed to resume %d\n", __func__, ret); in rt711_set_jack_detect()
477 dev_dbg(component->dev, "%s: skipping jack init for now\n", __func__); in rt711_set_jack_detect()
483 pm_runtime_mark_last_busy(component->dev); in rt711_set_jack_detect()
484 pm_runtime_put_autosuspend(component->dev); in rt711_set_jack_detect()
495 regmap_read(rt711->regmap, addr_l, r_val); in rt711_get_gain()
500 regmap_read(rt711->regmap, addr_h, l_val); in rt711_get_gain()
503 /* For Verb-Set Amplifier Gain (Verb ID = 3h) */
511 (struct soc_mixer_control *)kcontrol->private_value; in rt711_set_amp_gain_put()
517 mutex_lock(&rt711->calibrate_mutex); in rt711_set_amp_gain_put()
519 /* Can't use update bit function, so read the original value first */ in rt711_set_amp_gain_put()
520 addr_h = mc->reg; in rt711_set_amp_gain_put()
521 addr_l = mc->rreg; in rt711_set_amp_gain_put()
522 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_put()
530 if (mc->invert) { in rt711_set_amp_gain_put()
532 val_ll = (mc->max - ucontrol->value.integer.value[0]) in rt711_set_amp_gain_put()
539 val_ll = ((ucontrol->value.integer.value[0]) & 0x7f); in rt711_set_amp_gain_put()
540 if (val_ll > mc->max) in rt711_set_amp_gain_put()
541 val_ll = mc->max; in rt711_set_amp_gain_put()
547 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_set_amp_gain_put()
548 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
552 if (mc->invert) { in rt711_set_amp_gain_put()
554 val_lr = (mc->max - ucontrol->value.integer.value[1]) in rt711_set_amp_gain_put()
561 val_lr = ((ucontrol->value.integer.value[1]) & 0x7f); in rt711_set_amp_gain_put()
562 if (val_lr > mc->max) in rt711_set_amp_gain_put()
563 val_lr = mc->max; in rt711_set_amp_gain_put()
573 val_h = (1 << mc->shift) | (3 << 4); in rt711_set_amp_gain_put()
574 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
576 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
580 val_h = (1 << mc->shift) | (1 << 5); in rt711_set_amp_gain_put()
581 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
585 val_h = (1 << mc->shift) | (1 << 4); in rt711_set_amp_gain_put()
586 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
590 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_put()
601 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_set_amp_gain_put()
602 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
605 mutex_unlock(&rt711->calibrate_mutex); in rt711_set_amp_gain_put()
615 (struct soc_mixer_control *)kcontrol->private_value; in rt711_set_amp_gain_get()
620 addr_h = mc->reg; in rt711_set_amp_gain_get()
621 addr_l = mc->rreg; in rt711_set_amp_gain_get()
622 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_get()
629 if (mc->invert) { in rt711_set_amp_gain_get()
638 ucontrol->value.integer.value[0] = read_ll; in rt711_set_amp_gain_get()
639 ucontrol->value.integer.value[1] = read_rl; in rt711_set_amp_gain_get()
644 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6525, 75, 0);
645 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -1725, 75, 0);
692 if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt711_mux_get()
694 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt711_mux_get()
697 return -EINVAL; in rt711_mux_get()
701 ret = regmap_read(rt711->regmap, reg, &val); in rt711_mux_get()
703 dev_err(component->dev, "%s: sdw read failed: %d\n", in rt711_mux_get()
708 ucontrol->value.enumerated.item[0] = val; in rt711_mux_get()
721 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in rt711_mux_put()
722 unsigned int *item = ucontrol->value.enumerated.item; in rt711_mux_put()
726 if (item[0] >= e->items) in rt711_mux_put()
727 return -EINVAL; in rt711_mux_put()
729 if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt711_mux_put()
731 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt711_mux_put()
734 return -EINVAL; in rt711_mux_put()
737 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in rt711_mux_put()
740 ret = regmap_read(rt711->regmap, reg, &val2); in rt711_mux_put()
742 dev_err(component->dev, "%s: sdw read failed: %d\n", in rt711_mux_put()
754 regmap_write(rt711->regmap, reg, val); in rt711_mux_put()
788 snd_soc_dapm_to_component(w->dapm); in rt711_dac_surround_event()
795 regmap_write(rt711->regmap, in rt711_dac_surround_event()
799 regmap_write(rt711->regmap, in rt711_dac_surround_event()
804 regmap_write(rt711->regmap, in rt711_dac_surround_event()
808 regmap_write(rt711->regmap, in rt711_dac_surround_event()
819 snd_soc_dapm_to_component(w->dapm); in rt711_adc_09_event()
824 regmap_write(rt711->regmap, in rt711_adc_09_event()
828 regmap_write(rt711->regmap, in rt711_adc_09_event()
839 snd_soc_dapm_to_component(w->dapm); in rt711_adc_08_event()
844 regmap_write(rt711->regmap, in rt711_adc_08_event()
848 regmap_write(rt711->regmap, in rt711_adc_08_event()
910 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { in rt711_set_bias_level()
911 regmap_write(rt711->regmap, in rt711_set_bias_level()
918 mutex_lock(&rt711->calibrate_mutex); in rt711_set_bias_level()
919 regmap_write(rt711->regmap, in rt711_set_bias_level()
922 mutex_unlock(&rt711->calibrate_mutex); in rt711_set_bias_level()
934 device_property_read_u32(dev, "realtek,jd-src", in rt711_parse_dt()
935 &rt711->jd_src); in rt711_parse_dt()
945 rt711_parse_dt(rt711, &rt711->slave->dev); in rt711_probe()
946 rt711->component = component; in rt711_probe()
948 if (!rt711->first_hw_init) in rt711_probe()
951 ret = pm_runtime_resume(component->dev); in rt711_probe()
952 if (ret < 0 && ret != -EACCES) in rt711_probe()
989 struct snd_soc_component *component = dai->component; in rt711_pcm_hw_params()
997 dev_dbg(dai->dev, "%s %s", __func__, dai->name); in rt711_pcm_hw_params()
1001 return -EINVAL; in rt711_pcm_hw_params()
1003 if (!rt711->slave) in rt711_pcm_hw_params()
1004 return -EINVAL; in rt711_pcm_hw_params()
1009 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rt711_pcm_hw_params()
1012 if (dai->id == RT711_AIF1) in rt711_pcm_hw_params()
1014 else if (dai->id == RT711_AIF2) in rt711_pcm_hw_params()
1017 return -EINVAL; in rt711_pcm_hw_params()
1020 retval = sdw_stream_add_slave(rt711->slave, &stream_config, in rt711_pcm_hw_params()
1023 dev_err(dai->dev, "%s: Unable to configure port\n", __func__); in rt711_pcm_hw_params()
1029 val |= (params_channels(params) - 1); in rt711_pcm_hw_params()
1031 dev_err(component->dev, "%s: Unsupported channels %d\n", in rt711_pcm_hw_params()
1033 return -EINVAL; in rt711_pcm_hw_params()
1053 return -EINVAL; in rt711_pcm_hw_params()
1057 regmap_write(rt711->regmap, RT711_DAC_FORMAT_H, val); in rt711_pcm_hw_params()
1058 regmap_write(rt711->regmap, RT711_ADC1_FORMAT_H, val); in rt711_pcm_hw_params()
1059 regmap_write(rt711->regmap, RT711_ADC2_FORMAT_H, val); in rt711_pcm_hw_params()
1067 struct snd_soc_component *component = dai->component; in rt711_pcm_hw_free()
1072 if (!rt711->slave) in rt711_pcm_hw_free()
1073 return -EINVAL; in rt711_pcm_hw_free()
1075 sdw_stream_remove_slave(rt711->slave, sdw_stream); in rt711_pcm_hw_free()
1092 .name = "rt711-aif1",
1111 .name = "rt711-aif2",
1137 clk_freq = (rt711->params.curr_dr_freq >> 1); in rt711_clock_config()
1159 return -EINVAL; in rt711_clock_config()
1162 regmap_write(rt711->regmap, 0xe0, value); in rt711_clock_config()
1163 regmap_write(rt711->regmap, 0xf0, value); in rt711_clock_config()
1186 return -ENOMEM; in rt711_init()
1189 rt711->slave = slave; in rt711_init()
1190 rt711->sdw_regmap = sdw_regmap; in rt711_init()
1191 rt711->regmap = regmap; in rt711_init()
1193 regcache_cache_only(rt711->regmap, true); in rt711_init()
1195 mutex_init(&rt711->calibrate_mutex); in rt711_init()
1196 mutex_init(&rt711->disable_irq_lock); in rt711_init()
1198 INIT_DELAYED_WORK(&rt711->jack_detect_work, rt711_jack_detect_handler); in rt711_init()
1199 INIT_DELAYED_WORK(&rt711->jack_btn_check_work, rt711_btn_check_handler); in rt711_init()
1200 INIT_WORK(&rt711->calibration_work, rt711_calibration_work); in rt711_init()
1206 rt711->hw_init = false; in rt711_init()
1207 rt711->first_hw_init = false; in rt711_init()
1209 /* JD source uses JD2 in default */ in rt711_init()
1210 rt711->jd_src = RT711_JD2; in rt711_init()
1230 * to make sure the ASoC framework use of pm_runtime_get_sync() does not silently in rt711_init()
1231 * fail with -EACCESS because of race conditions between card creation and enumeration in rt711_init()
1243 rt711->disable_irq = false; in rt711_io_init()
1245 if (rt711->hw_init) in rt711_io_init()
1248 regcache_cache_only(rt711->regmap, false); in rt711_io_init()
1249 if (rt711->first_hw_init) in rt711_io_init()
1250 regcache_cache_bypass(rt711->regmap, true); in rt711_io_init()
1255 if (!rt711->first_hw_init) in rt711_io_init()
1257 pm_runtime_set_active(&slave->dev); in rt711_io_init()
1259 pm_runtime_get_noresume(&slave->dev); in rt711_io_init()
1261 rt711_reset(rt711->regmap); in rt711_io_init()
1264 regmap_write(rt711->regmap, RT711_SET_AUDIO_POWER_STATE, AC_PWRST_D0); in rt711_io_init()
1267 regmap_write(rt711->regmap, RT711_SET_PIN_MIC2, 0x25); in rt711_io_init()
1268 regmap_write(rt711->regmap, RT711_SET_PIN_HP, 0xc0); in rt711_io_init()
1269 regmap_write(rt711->regmap, RT711_SET_PIN_DMIC1, 0x20); in rt711_io_init()
1270 regmap_write(rt711->regmap, RT711_SET_PIN_DMIC2, 0x20); in rt711_io_init()
1271 regmap_write(rt711->regmap, RT711_SET_PIN_LINE1, 0x20); in rt711_io_init()
1272 regmap_write(rt711->regmap, RT711_SET_PIN_LINE2, 0x20); in rt711_io_init()
1275 regmap_write(rt711->regmap, RT711_SET_GAIN_HP_H, 0xa080); in rt711_io_init()
1276 regmap_write(rt711->regmap, RT711_SET_GAIN_HP_H, 0x9080); in rt711_io_init()
1277 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC2_H, 0x6080); in rt711_io_init()
1278 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC2_H, 0x5080); in rt711_io_init()
1279 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC1_H, 0x6080); in rt711_io_init()
1280 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC1_H, 0x5080); in rt711_io_init()
1283 regmap_write(rt711->regmap, 0x4f12, 0x91); in rt711_io_init()
1284 regmap_write(rt711->regmap, 0x4e12, 0xd6); in rt711_io_init()
1285 regmap_write(rt711->regmap, 0x4d12, 0x11); in rt711_io_init()
1286 regmap_write(rt711->regmap, 0x4c12, 0x20); in rt711_io_init()
1287 regmap_write(rt711->regmap, 0x4f13, 0x91); in rt711_io_init()
1288 regmap_write(rt711->regmap, 0x4e13, 0xd6); in rt711_io_init()
1289 regmap_write(rt711->regmap, 0x4d13, 0x11); in rt711_io_init()
1290 regmap_write(rt711->regmap, 0x4c13, 0x21); in rt711_io_init()
1291 regmap_write(rt711->regmap, 0x4c21, 0xf0); in rt711_io_init()
1292 regmap_write(rt711->regmap, 0x4d21, 0x11); in rt711_io_init()
1293 regmap_write(rt711->regmap, 0x4e21, 0x11); in rt711_io_init()
1294 regmap_write(rt711->regmap, 0x4f21, 0x01); in rt711_io_init()
1297 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1301 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1303 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1305 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1307 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1311 regmap_write(rt711->regmap, RT711_SET_AUDIO_POWER_STATE, AC_PWRST_D3); in rt711_io_init()
1313 if (rt711->first_hw_init) in rt711_io_init()
1316 schedule_work(&rt711->calibration_work); in rt711_io_init()
1322 if (rt711->hs_jack) in rt711_io_init()
1325 if (rt711->first_hw_init) { in rt711_io_init()
1326 regcache_cache_bypass(rt711->regmap, false); in rt711_io_init()
1327 regcache_mark_dirty(rt711->regmap); in rt711_io_init()
1329 rt711->first_hw_init = true; in rt711_io_init()
1332 rt711->hw_init = true; in rt711_io_init()
1334 pm_runtime_mark_last_busy(&slave->dev); in rt711_io_init()
1335 pm_runtime_put_autosuspend(&slave->dev); in rt711_io_init()
1337 dev_dbg(&slave->dev, "%s hw_init complete\n", __func__); in rt711_io_init()