Lines Matching +full:mic2 +full:- +full:src
1 // SPDX-License-Identifier: GPL-2.0
3 // rt711.c -- rt711 ALSA SoC audio driver
23 #include <sound/soc-dapm.h>
88 struct regmap *regmap = rt711->regmap; in rt711_calibration()
91 mutex_lock(&rt711->calibrate_mutex); in rt711_calibration()
92 regmap_write(rt711->regmap, in rt711_calibration()
112 pr_err("%s, calibration time-out!\n", in rt711_calibration()
114 ret = -ETIMEDOUT; in rt711_calibration()
128 regmap_write(rt711->regmap, in rt711_calibration()
130 mutex_unlock(&rt711->calibrate_mutex); in rt711_calibration()
141 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_button_detect()
145 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_button_detect()
189 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_headset_detect()
199 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_headset_detect()
205 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_headset_detect()
216 rt711->jack_type = SND_JACK_HEADPHONE; in rt711_headset_detect()
219 rt711->jack_type = SND_JACK_HEADSET; in rt711_headset_detect()
224 ret = -ETIMEDOUT; in rt711_headset_detect()
225 pr_err_ratelimited("Time-out error in %s\n", __func__); in rt711_headset_detect()
232 return -ENODEV; in rt711_headset_detect()
242 if (!rt711->hs_jack) in rt711_jack_detect_handler()
245 if (!rt711->component->card || !rt711->component->card->instantiated) in rt711_jack_detect_handler()
248 if (pm_runtime_status_suspended(rt711->slave->dev.parent)) { in rt711_jack_detect_handler()
249 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
256 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_jack_detect_handler()
263 if (rt711->jack_type == 0) { in rt711_jack_detect_handler()
267 if (rt711->jack_type == SND_JACK_HEADSET) in rt711_jack_detect_handler()
269 } else if (rt711->jack_type == SND_JACK_HEADSET) { in rt711_jack_detect_handler()
275 rt711->jack_type = 0; in rt711_jack_detect_handler()
278 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
279 "in %s, jack_type=0x%x\n", __func__, rt711->jack_type); in rt711_jack_detect_handler()
280 dev_dbg(&rt711->slave->dev, in rt711_jack_detect_handler()
283 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type | btn_type, in rt711_jack_detect_handler()
290 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type, in rt711_jack_detect_handler()
296 &rt711->jack_btn_check_work, msecs_to_jiffies(200)); in rt711_jack_detect_handler()
313 ret = regmap_read(rt711->regmap, reg, &jack_status); in rt711_btn_check_handler()
319 if (rt711->jack_type == SND_JACK_HEADSET) { in rt711_btn_check_handler()
324 rt711->jack_type = 0; in rt711_btn_check_handler()
328 ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, in rt711_btn_check_handler()
336 dev_dbg(&rt711->slave->dev, in rt711_btn_check_handler()
338 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type | btn_type, in rt711_btn_check_handler()
345 snd_soc_jack_report(rt711->hs_jack, rt711->jack_type, in rt711_btn_check_handler()
351 &rt711->jack_btn_check_work, msecs_to_jiffies(200)); in rt711_btn_check_handler()
363 snd_soc_component_get_dapm(rt711->component); in rt711_jack_init()
365 mutex_lock(&rt711->calibrate_mutex); in rt711_jack_init()
367 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_jack_init()
368 regmap_write(rt711->regmap, in rt711_jack_init()
371 if (rt711->hs_jack) { in rt711_jack_init()
373 regmap_write(rt711->regmap, in rt711_jack_init()
375 regmap_write(rt711->regmap, in rt711_jack_init()
377 regmap_write(rt711->regmap, in rt711_jack_init()
379 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
381 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
384 switch (rt711->jd_src) { in rt711_jack_init()
389 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
394 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
400 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
405 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
411 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
414 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
419 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
424 rt711_index_update_bits(rt711->regmap, RT711_VENDOR_REG, in rt711_jack_init()
430 dev_warn(rt711->component->dev, "Wrong JD source\n"); in rt711_jack_init()
434 dev_dbg(&rt711->slave->dev, "in %s enable\n", __func__); in rt711_jack_init()
437 &rt711->jack_detect_work, msecs_to_jiffies(250)); in rt711_jack_init()
439 regmap_write(rt711->regmap, in rt711_jack_init()
441 regmap_write(rt711->regmap, in rt711_jack_init()
443 regmap_write(rt711->regmap, in rt711_jack_init()
446 dev_dbg(&rt711->slave->dev, "in %s disable\n", __func__); in rt711_jack_init()
450 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_jack_init()
451 regmap_write(rt711->regmap, in rt711_jack_init()
453 mutex_unlock(&rt711->calibrate_mutex); in rt711_jack_init()
462 rt711->hs_jack = hs_jack; in rt711_set_jack_detect()
464 ret = pm_runtime_resume_and_get(component->dev); in rt711_set_jack_detect()
466 if (ret != -EACCES) { in rt711_set_jack_detect()
467 dev_err(component->dev, "%s: failed to resume %d\n", __func__, ret); in rt711_set_jack_detect()
472 dev_dbg(component->dev, "%s: skipping jack init for now\n", __func__); in rt711_set_jack_detect()
478 pm_runtime_mark_last_busy(component->dev); in rt711_set_jack_detect()
479 pm_runtime_put_autosuspend(component->dev); in rt711_set_jack_detect()
490 regmap_read(rt711->regmap, addr_l, r_val); in rt711_get_gain()
495 regmap_read(rt711->regmap, addr_h, l_val); in rt711_get_gain()
498 /* For Verb-Set Amplifier Gain (Verb ID = 3h) */
506 (struct soc_mixer_control *)kcontrol->private_value; in rt711_set_amp_gain_put()
512 mutex_lock(&rt711->calibrate_mutex); in rt711_set_amp_gain_put()
515 addr_h = mc->reg; in rt711_set_amp_gain_put()
516 addr_l = mc->rreg; in rt711_set_amp_gain_put()
517 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_put()
525 if (mc->invert) { in rt711_set_amp_gain_put()
527 val_ll = (mc->max - ucontrol->value.integer.value[0]) in rt711_set_amp_gain_put()
534 val_ll = ((ucontrol->value.integer.value[0]) & 0x7f); in rt711_set_amp_gain_put()
535 if (val_ll > mc->max) in rt711_set_amp_gain_put()
536 val_ll = mc->max; in rt711_set_amp_gain_put()
542 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_set_amp_gain_put()
543 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
547 if (mc->invert) { in rt711_set_amp_gain_put()
549 val_lr = (mc->max - ucontrol->value.integer.value[1]) in rt711_set_amp_gain_put()
556 val_lr = ((ucontrol->value.integer.value[1]) & 0x7f); in rt711_set_amp_gain_put()
557 if (val_lr > mc->max) in rt711_set_amp_gain_put()
558 val_lr = mc->max; in rt711_set_amp_gain_put()
568 val_h = (1 << mc->shift) | (3 << 4); in rt711_set_amp_gain_put()
569 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
571 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
575 val_h = (1 << mc->shift) | (1 << 5); in rt711_set_amp_gain_put()
576 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
580 val_h = (1 << mc->shift) | (1 << 4); in rt711_set_amp_gain_put()
581 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
585 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_put()
596 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt711_set_amp_gain_put()
597 regmap_write(rt711->regmap, in rt711_set_amp_gain_put()
600 mutex_unlock(&rt711->calibrate_mutex); in rt711_set_amp_gain_put()
610 (struct soc_mixer_control *)kcontrol->private_value; in rt711_set_amp_gain_get()
615 addr_h = mc->reg; in rt711_set_amp_gain_get()
616 addr_l = mc->rreg; in rt711_set_amp_gain_get()
617 if (mc->shift == RT711_DIR_OUT_SFT) /* output */ in rt711_set_amp_gain_get()
624 if (mc->invert) { in rt711_set_amp_gain_get()
633 ucontrol->value.integer.value[0] = read_ll; in rt711_set_amp_gain_get()
634 ucontrol->value.integer.value[1] = read_rl; in rt711_set_amp_gain_get()
639 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6525, 75, 0);
640 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -1725, 75, 0);
687 if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt711_mux_get()
689 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt711_mux_get()
692 return -EINVAL; in rt711_mux_get()
696 ret = regmap_read(rt711->regmap, reg, &val); in rt711_mux_get()
698 dev_err(component->dev, "%s: sdw read failed: %d\n", in rt711_mux_get()
703 ucontrol->value.enumerated.item[0] = val; in rt711_mux_get()
716 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in rt711_mux_put()
717 unsigned int *item = ucontrol->value.enumerated.item; in rt711_mux_put()
721 if (item[0] >= e->items) in rt711_mux_put()
722 return -EINVAL; in rt711_mux_put()
724 if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt711_mux_put()
726 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt711_mux_put()
729 return -EINVAL; in rt711_mux_put()
732 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in rt711_mux_put()
735 ret = regmap_read(rt711->regmap, reg, &val2); in rt711_mux_put()
737 dev_err(component->dev, "%s: sdw read failed: %d\n", in rt711_mux_put()
749 regmap_write(rt711->regmap, reg, val); in rt711_mux_put()
759 "MIC2",
783 snd_soc_dapm_to_component(w->dapm); in rt711_dac_surround_event()
790 regmap_write(rt711->regmap, in rt711_dac_surround_event()
794 regmap_write(rt711->regmap, in rt711_dac_surround_event()
799 regmap_write(rt711->regmap, in rt711_dac_surround_event()
803 regmap_write(rt711->regmap, in rt711_dac_surround_event()
814 snd_soc_dapm_to_component(w->dapm); in rt711_adc_09_event()
819 regmap_write(rt711->regmap, in rt711_adc_09_event()
823 regmap_write(rt711->regmap, in rt711_adc_09_event()
834 snd_soc_dapm_to_component(w->dapm); in rt711_adc_08_event()
839 regmap_write(rt711->regmap, in rt711_adc_08_event()
843 regmap_write(rt711->regmap, in rt711_adc_08_event()
852 SND_SOC_DAPM_INPUT("MIC2"),
887 {"ADC 22 Mux", "MIC2", "MIC2"},
891 {"ADC 23 Mux", "MIC2", "MIC2"},
905 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { in rt711_set_bias_level()
906 regmap_write(rt711->regmap, in rt711_set_bias_level()
913 mutex_lock(&rt711->calibrate_mutex); in rt711_set_bias_level()
914 regmap_write(rt711->regmap, in rt711_set_bias_level()
917 mutex_unlock(&rt711->calibrate_mutex); in rt711_set_bias_level()
929 device_property_read_u32(dev, "realtek,jd-src", in rt711_parse_dt()
930 &rt711->jd_src); in rt711_parse_dt()
940 rt711_parse_dt(rt711, &rt711->slave->dev); in rt711_probe()
941 rt711->component = component; in rt711_probe()
943 ret = pm_runtime_resume(component->dev); in rt711_probe()
944 if (ret < 0 && ret != -EACCES) in rt711_probe()
973 return -ENOMEM; in rt711_set_sdw_stream()
975 stream->sdw_stream = sdw_stream; in rt711_set_sdw_stream()
979 dai->playback_dma_data = stream; in rt711_set_sdw_stream()
981 dai->capture_dma_data = stream; in rt711_set_sdw_stream()
1000 struct snd_soc_component *component = dai->component; in rt711_pcm_hw_params()
1009 dev_dbg(dai->dev, "%s %s", __func__, dai->name); in rt711_pcm_hw_params()
1013 return -EINVAL; in rt711_pcm_hw_params()
1015 if (!rt711->slave) in rt711_pcm_hw_params()
1016 return -EINVAL; in rt711_pcm_hw_params()
1019 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rt711_pcm_hw_params()
1024 if (dai->id == RT711_AIF1) in rt711_pcm_hw_params()
1026 else if (dai->id == RT711_AIF2) in rt711_pcm_hw_params()
1029 return -EINVAL; in rt711_pcm_hw_params()
1038 port_config.ch_mask = (1 << (num_channels)) - 1; in rt711_pcm_hw_params()
1041 retval = sdw_stream_add_slave(rt711->slave, &stream_config, in rt711_pcm_hw_params()
1042 &port_config, 1, stream->sdw_stream); in rt711_pcm_hw_params()
1044 dev_err(dai->dev, "Unable to configure port\n"); in rt711_pcm_hw_params()
1050 val |= (params_channels(params) - 1); in rt711_pcm_hw_params()
1052 dev_err(component->dev, "Unsupported channels %d\n", in rt711_pcm_hw_params()
1054 return -EINVAL; in rt711_pcm_hw_params()
1074 return -EINVAL; in rt711_pcm_hw_params()
1078 regmap_write(rt711->regmap, RT711_DAC_FORMAT_H, val); in rt711_pcm_hw_params()
1079 regmap_write(rt711->regmap, RT711_ADC1_FORMAT_H, val); in rt711_pcm_hw_params()
1080 regmap_write(rt711->regmap, RT711_ADC2_FORMAT_H, val); in rt711_pcm_hw_params()
1088 struct snd_soc_component *component = dai->component; in rt711_pcm_hw_free()
1093 if (!rt711->slave) in rt711_pcm_hw_free()
1094 return -EINVAL; in rt711_pcm_hw_free()
1096 sdw_stream_remove_slave(rt711->slave, stream->sdw_stream); in rt711_pcm_hw_free()
1113 .name = "rt711-aif1",
1132 .name = "rt711-aif2",
1158 clk_freq = (rt711->params.curr_dr_freq >> 1); in rt711_clock_config()
1180 return -EINVAL; in rt711_clock_config()
1183 regmap_write(rt711->regmap, 0xe0, value); in rt711_clock_config()
1184 regmap_write(rt711->regmap, 0xf0, value); in rt711_clock_config()
1207 return -ENOMEM; in rt711_init()
1210 rt711->slave = slave; in rt711_init()
1211 rt711->sdw_regmap = sdw_regmap; in rt711_init()
1212 rt711->regmap = regmap; in rt711_init()
1214 mutex_init(&rt711->calibrate_mutex); in rt711_init()
1215 mutex_init(&rt711->disable_irq_lock); in rt711_init()
1217 INIT_DELAYED_WORK(&rt711->jack_detect_work, rt711_jack_detect_handler); in rt711_init()
1218 INIT_DELAYED_WORK(&rt711->jack_btn_check_work, rt711_btn_check_handler); in rt711_init()
1219 INIT_WORK(&rt711->calibration_work, rt711_calibration_work); in rt711_init()
1225 rt711->hw_init = false; in rt711_init()
1226 rt711->first_hw_init = false; in rt711_init()
1229 rt711->jd_src = RT711_JD2; in rt711_init()
1236 dev_dbg(&slave->dev, "%s\n", __func__); in rt711_init()
1245 rt711->disable_irq = false; in rt711_io_init()
1247 if (rt711->hw_init) in rt711_io_init()
1250 if (rt711->first_hw_init) { in rt711_io_init()
1251 regcache_cache_only(rt711->regmap, false); in rt711_io_init()
1252 regcache_cache_bypass(rt711->regmap, true); in rt711_io_init()
1258 if (!rt711->first_hw_init) { in rt711_io_init()
1260 pm_runtime_set_autosuspend_delay(&slave->dev, 3000); in rt711_io_init()
1261 pm_runtime_use_autosuspend(&slave->dev); in rt711_io_init()
1264 pm_runtime_set_active(&slave->dev); in rt711_io_init()
1267 pm_runtime_mark_last_busy(&slave->dev); in rt711_io_init()
1269 pm_runtime_enable(&slave->dev); in rt711_io_init()
1272 pm_runtime_get_noresume(&slave->dev); in rt711_io_init()
1274 rt711_reset(rt711->regmap); in rt711_io_init()
1277 regmap_write(rt711->regmap, RT711_SET_AUDIO_POWER_STATE, AC_PWRST_D0); in rt711_io_init()
1280 regmap_write(rt711->regmap, RT711_SET_PIN_MIC2, 0x25); in rt711_io_init()
1281 regmap_write(rt711->regmap, RT711_SET_PIN_HP, 0xc0); in rt711_io_init()
1282 regmap_write(rt711->regmap, RT711_SET_PIN_DMIC1, 0x20); in rt711_io_init()
1283 regmap_write(rt711->regmap, RT711_SET_PIN_DMIC2, 0x20); in rt711_io_init()
1284 regmap_write(rt711->regmap, RT711_SET_PIN_LINE1, 0x20); in rt711_io_init()
1285 regmap_write(rt711->regmap, RT711_SET_PIN_LINE2, 0x20); in rt711_io_init()
1288 regmap_write(rt711->regmap, RT711_SET_GAIN_HP_H, 0xa080); in rt711_io_init()
1289 regmap_write(rt711->regmap, RT711_SET_GAIN_HP_H, 0x9080); in rt711_io_init()
1290 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC2_H, 0x6080); in rt711_io_init()
1291 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC2_H, 0x5080); in rt711_io_init()
1292 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC1_H, 0x6080); in rt711_io_init()
1293 regmap_write(rt711->regmap, RT711_SET_GAIN_ADC1_H, 0x5080); in rt711_io_init()
1296 regmap_write(rt711->regmap, 0x4f12, 0x91); in rt711_io_init()
1297 regmap_write(rt711->regmap, 0x4e12, 0xd6); in rt711_io_init()
1298 regmap_write(rt711->regmap, 0x4d12, 0x11); in rt711_io_init()
1299 regmap_write(rt711->regmap, 0x4c12, 0x20); in rt711_io_init()
1300 regmap_write(rt711->regmap, 0x4f13, 0x91); in rt711_io_init()
1301 regmap_write(rt711->regmap, 0x4e13, 0xd6); in rt711_io_init()
1302 regmap_write(rt711->regmap, 0x4d13, 0x11); in rt711_io_init()
1303 regmap_write(rt711->regmap, 0x4c13, 0x21); in rt711_io_init()
1304 regmap_write(rt711->regmap, 0x4c21, 0xf0); in rt711_io_init()
1305 regmap_write(rt711->regmap, 0x4d21, 0x11); in rt711_io_init()
1306 regmap_write(rt711->regmap, 0x4e21, 0x11); in rt711_io_init()
1307 regmap_write(rt711->regmap, 0x4f21, 0x01); in rt711_io_init()
1310 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1314 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1316 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1318 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1320 rt711_index_write(rt711->regmap, RT711_VENDOR_REG, in rt711_io_init()
1324 regmap_write(rt711->regmap, RT711_SET_AUDIO_POWER_STATE, AC_PWRST_D3); in rt711_io_init()
1326 if (rt711->first_hw_init) in rt711_io_init()
1329 schedule_work(&rt711->calibration_work); in rt711_io_init()
1335 if (rt711->hs_jack) in rt711_io_init()
1338 if (rt711->first_hw_init) { in rt711_io_init()
1339 regcache_cache_bypass(rt711->regmap, false); in rt711_io_init()
1340 regcache_mark_dirty(rt711->regmap); in rt711_io_init()
1342 rt711->first_hw_init = true; in rt711_io_init()
1345 rt711->hw_init = true; in rt711_io_init()
1347 pm_runtime_mark_last_busy(&slave->dev); in rt711_io_init()
1348 pm_runtime_put_autosuspend(&slave->dev); in rt711_io_init()
1350 dev_dbg(&slave->dev, "%s hw_init complete\n", __func__); in rt711_io_init()