Lines Matching +full:io +full:- +full:channel +full:- +full:mux
1 // SPDX-License-Identifier: GPL-2.0
3 // rt700.c -- rt700 ALSA SoC audio driver
24 #include <sound/soc-dapm.h>
66 ret = rt700_index_read(rt700->regmap, RT700_IRQ_FLAG_TABLE1, &val80); in rt700_button_detect()
69 ret = rt700_index_read(rt700->regmap, RT700_IRQ_FLAG_TABLE2, &val81); in rt700_button_detect()
112 ret = rt700_index_read(rt700->regmap, in rt700_headset_detect()
122 ret = rt700_index_read(rt700->regmap, in rt700_headset_detect()
128 ret = regmap_read(rt700->regmap, reg, &jack_status); in rt700_headset_detect()
137 rt700->jack_type = SND_JACK_HEADPHONE; in rt700_headset_detect()
140 rt700->jack_type = SND_JACK_HEADSET; in rt700_headset_detect()
145 ret = -ETIMEDOUT; in rt700_headset_detect()
146 pr_err_ratelimited("Time-out error in %s\n", __func__); in rt700_headset_detect()
149 pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret); in rt700_headset_detect()
153 return -ENODEV; in rt700_headset_detect()
163 if (!rt700->hs_jack) in rt700_jack_detect_handler()
166 if (!snd_soc_card_is_instantiated(rt700->component->card)) in rt700_jack_detect_handler()
170 ret = regmap_read(rt700->regmap, reg, &jack_status); in rt700_jack_detect_handler()
177 if (rt700->jack_type == 0) { in rt700_jack_detect_handler()
181 if (rt700->jack_type == SND_JACK_HEADSET) in rt700_jack_detect_handler()
183 } else if (rt700->jack_type == SND_JACK_HEADSET) { in rt700_jack_detect_handler()
189 rt700->jack_type = 0; in rt700_jack_detect_handler()
192 dev_dbg(&rt700->slave->dev, in rt700_jack_detect_handler()
193 "in %s, jack_type=0x%x\n", __func__, rt700->jack_type); in rt700_jack_detect_handler()
194 dev_dbg(&rt700->slave->dev, in rt700_jack_detect_handler()
197 snd_soc_jack_report(rt700->hs_jack, rt700->jack_type | btn_type, in rt700_jack_detect_handler()
204 snd_soc_jack_report(rt700->hs_jack, rt700->jack_type, in rt700_jack_detect_handler()
210 &rt700->jack_btn_check_work, msecs_to_jiffies(200)); in rt700_jack_detect_handler()
216 pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret); in rt700_jack_detect_handler()
227 ret = regmap_read(rt700->regmap, reg, &jack_status); in rt700_btn_check_handler()
233 if (rt700->jack_type == SND_JACK_HEADSET) { in rt700_btn_check_handler()
238 rt700->jack_type = 0; in rt700_btn_check_handler()
242 ret = rt700_index_read(rt700->regmap, RT700_COMBO_JACK_AUTO_CTL2, ®); in rt700_btn_check_handler()
249 dev_dbg(&rt700->slave->dev, in rt700_btn_check_handler()
251 snd_soc_jack_report(rt700->hs_jack, rt700->jack_type | btn_type, in rt700_btn_check_handler()
258 snd_soc_jack_report(rt700->hs_jack, rt700->jack_type, in rt700_btn_check_handler()
264 &rt700->jack_btn_check_work, msecs_to_jiffies(200)); in rt700_btn_check_handler()
270 pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret); in rt700_btn_check_handler()
276 snd_soc_component_get_dapm(rt700->component); in rt700_jack_init()
279 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt700_jack_init()
280 regmap_write(rt700->regmap, in rt700_jack_init()
283 if (rt700->hs_jack) { in rt700_jack_init()
285 regmap_write(rt700->regmap, in rt700_jack_init()
287 regmap_write(rt700->regmap, in rt700_jack_init()
289 regmap_write(rt700->regmap, in rt700_jack_init()
291 rt700_index_write(rt700->regmap, 0x10, 0x2420); in rt700_jack_init()
292 rt700_index_write(rt700->regmap, 0x19, 0x2e11); in rt700_jack_init()
294 dev_dbg(&rt700->slave->dev, "in %s enable\n", __func__); in rt700_jack_init()
297 &rt700->jack_detect_work, msecs_to_jiffies(250)); in rt700_jack_init()
299 regmap_write(rt700->regmap, in rt700_jack_init()
301 regmap_write(rt700->regmap, in rt700_jack_init()
303 regmap_write(rt700->regmap, in rt700_jack_init()
306 dev_dbg(&rt700->slave->dev, "in %s disable\n", __func__); in rt700_jack_init()
310 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt700_jack_init()
311 regmap_write(rt700->regmap, in rt700_jack_init()
321 rt700->hs_jack = hs_jack; in rt700_set_jack_detect()
324 if (!rt700->first_hw_init) in rt700_set_jack_detect()
327 ret = pm_runtime_resume_and_get(component->dev); in rt700_set_jack_detect()
329 if (ret != -EACCES) { in rt700_set_jack_detect()
330 dev_err(component->dev, "%s: failed to resume %d\n", __func__, ret); in rt700_set_jack_detect()
335 dev_dbg(component->dev, "%s: skipping jack init for now\n", __func__); in rt700_set_jack_detect()
341 pm_runtime_mark_last_busy(component->dev); in rt700_set_jack_detect()
342 pm_runtime_put_autosuspend(component->dev); in rt700_set_jack_detect()
351 /* R Channel */ in rt700_get_gain()
353 regmap_read(rt700->regmap, addr_l, r_val); in rt700_get_gain()
355 /* L Channel */ in rt700_get_gain()
358 regmap_read(rt700->regmap, addr_h, l_val); in rt700_get_gain()
361 /* For Verb-Set Amplifier Gain (Verb ID = 3h) */
369 (struct soc_mixer_control *)kcontrol->private_value; in rt700_set_amp_gain_put()
376 addr_h = mc->reg; in rt700_set_amp_gain_put()
377 addr_l = mc->rreg; in rt700_set_amp_gain_put()
378 if (mc->shift == RT700_DIR_OUT_SFT) /* output */ in rt700_set_amp_gain_put()
385 /* L Channel */ in rt700_set_amp_gain_put()
386 if (mc->invert) { in rt700_set_amp_gain_put()
388 val_ll = (mc->max - ucontrol->value.integer.value[0]) << 7; in rt700_set_amp_gain_put()
394 val_ll = ((ucontrol->value.integer.value[0]) & 0x7f); in rt700_set_amp_gain_put()
395 if (val_ll > mc->max) in rt700_set_amp_gain_put()
396 val_ll = mc->max; in rt700_set_amp_gain_put()
402 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt700_set_amp_gain_put()
403 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
406 /* R Channel */ in rt700_set_amp_gain_put()
407 if (mc->invert) { in rt700_set_amp_gain_put()
409 val_lr = (mc->max - ucontrol->value.integer.value[1]) << 7; in rt700_set_amp_gain_put()
415 val_lr = ((ucontrol->value.integer.value[1]) & 0x7f); in rt700_set_amp_gain_put()
416 if (val_lr > mc->max) in rt700_set_amp_gain_put()
417 val_lr = mc->max; in rt700_set_amp_gain_put()
426 val_h = (1 << mc->shift) | (3 << 4); in rt700_set_amp_gain_put()
427 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
429 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
433 val_h = (1 << mc->shift) | (1 << 5); in rt700_set_amp_gain_put()
434 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
438 val_h = (1 << mc->shift) | (1 << 4); in rt700_set_amp_gain_put()
439 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
443 if (mc->shift == RT700_DIR_OUT_SFT) /* output */ in rt700_set_amp_gain_put()
454 if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) in rt700_set_amp_gain_put()
455 regmap_write(rt700->regmap, in rt700_set_amp_gain_put()
466 (struct soc_mixer_control *)kcontrol->private_value; in rt700_set_amp_gain_get()
470 addr_h = mc->reg; in rt700_set_amp_gain_get()
471 addr_l = mc->rreg; in rt700_set_amp_gain_get()
472 if (mc->shift == RT700_DIR_OUT_SFT) /* output */ in rt700_set_amp_gain_get()
479 if (mc->invert) { in rt700_set_amp_gain_get()
488 ucontrol->value.integer.value[0] = read_ll; in rt700_set_amp_gain_get()
489 ucontrol->value.integer.value[1] = read_rl; in rt700_set_amp_gain_get()
494 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6525, 75, 0);
495 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -1725, 75, 0);
534 if (strstr(ucontrol->id.name, "HPO Mux")) in rt700_mux_get()
536 else if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt700_mux_get()
538 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt700_mux_get()
541 return -EINVAL; in rt700_mux_get()
545 ret = regmap_read(rt700->regmap, reg, &val); in rt700_mux_get()
549 ucontrol->value.enumerated.item[0] = val; in rt700_mux_get()
562 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in rt700_mux_put()
563 unsigned int *item = ucontrol->value.enumerated.item; in rt700_mux_put()
567 if (item[0] >= e->items) in rt700_mux_put()
568 return -EINVAL; in rt700_mux_put()
570 if (strstr(ucontrol->id.name, "HPO Mux")) in rt700_mux_put()
572 else if (strstr(ucontrol->id.name, "ADC 22 Mux")) in rt700_mux_put()
574 else if (strstr(ucontrol->id.name, "ADC 23 Mux")) in rt700_mux_put()
577 return -EINVAL; in rt700_mux_put()
580 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in rt700_mux_put()
583 ret = regmap_read(rt700->regmap, reg, &val2); in rt700_mux_put()
594 regmap_write(rt700->regmap, reg, val); in rt700_mux_put()
617 SOC_DAPM_ENUM_EXT("ADC 22 Mux", rt700_adc22_enum,
621 SOC_DAPM_ENUM_EXT("ADC 23 Mux", rt700_adc23_enum,
633 SOC_DAPM_ENUM_EXT("HP Mux", rt700_hp_enum,
640 snd_soc_dapm_to_component(w->dapm); in rt700_dac_front_event()
645 regmap_write(rt700->regmap, in rt700_dac_front_event()
649 regmap_write(rt700->regmap, in rt700_dac_front_event()
660 snd_soc_dapm_to_component(w->dapm); in rt700_dac_surround_event()
665 regmap_write(rt700->regmap, in rt700_dac_surround_event()
669 regmap_write(rt700->regmap, in rt700_dac_surround_event()
680 snd_soc_dapm_to_component(w->dapm); in rt700_adc_09_event()
685 regmap_write(rt700->regmap, in rt700_adc_09_event()
689 regmap_write(rt700->regmap, in rt700_adc_09_event()
700 snd_soc_dapm_to_component(w->dapm); in rt700_adc_08_event()
705 regmap_write(rt700->regmap, in rt700_adc_08_event()
709 regmap_write(rt700->regmap, in rt700_adc_08_event()
720 snd_soc_dapm_to_component(w->dapm); in rt700_hpo_mux_event()
728 regmap_write(rt700->regmap, in rt700_hpo_mux_event()
733 regmap_write(rt700->regmap, in rt700_hpo_mux_event()
745 snd_soc_dapm_to_component(w->dapm); in rt700_spk_pga_event()
753 regmap_write(rt700->regmap, in rt700_spk_pga_event()
758 regmap_write(rt700->regmap, in rt700_spk_pga_event()
779 SND_SOC_DAPM_MUX_E("HPO Mux", SND_SOC_NOPM, 0, 0, &rt700_hp_mux,
791 SND_SOC_DAPM_MUX("ADC 22 Mux", SND_SOC_NOPM, 0, 0,
793 SND_SOC_DAPM_MUX("ADC 23 Mux", SND_SOC_NOPM, 0, 0,
806 {"ADC 09", NULL, "ADC 22 Mux"},
807 {"ADC 08", NULL, "ADC 23 Mux"},
808 {"ADC 22 Mux", "DMIC", "DMIC1"},
809 {"ADC 22 Mux", "LINE1", "LINE1"},
810 {"ADC 22 Mux", "LINE2", "LINE2"},
811 {"ADC 22 Mux", "MIC2", "MIC2"},
812 {"ADC 23 Mux", "DMIC", "DMIC2"},
813 {"ADC 23 Mux", "LINE1", "LINE1"},
814 {"ADC 23 Mux", "LINE2", "LINE2"},
815 {"ADC 23 Mux", "MIC2", "MIC2"},
816 {"HPO Mux", "Front", "DAC Front"},
817 {"HPO Mux", "Surround", "DAC Surround"},
818 {"HP", NULL, "HPO Mux"},
828 rt700->component = component; in rt700_probe()
830 if (!rt700->first_hw_init) in rt700_probe()
833 ret = pm_runtime_resume(component->dev); in rt700_probe()
834 if (ret < 0 && ret != -EACCES) in rt700_probe()
849 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { in rt700_set_bias_level()
850 regmap_write(rt700->regmap, in rt700_set_bias_level()
857 regmap_write(rt700->regmap, in rt700_set_bias_level()
865 dapm->bias_level = level; in rt700_set_bias_level()
900 struct snd_soc_component *component = dai->component; in rt700_pcm_hw_params()
908 dev_dbg(dai->dev, "%s %s", __func__, dai->name); in rt700_pcm_hw_params()
912 return -EINVAL; in rt700_pcm_hw_params()
914 if (!rt700->slave) in rt700_pcm_hw_params()
915 return -EINVAL; in rt700_pcm_hw_params()
921 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rt700_pcm_hw_params()
926 switch (dai->id) { in rt700_pcm_hw_params()
933 dev_err(component->dev, "Invalid DAI id %d\n", dai->id); in rt700_pcm_hw_params()
934 return -EINVAL; in rt700_pcm_hw_params()
937 retval = sdw_stream_add_slave(rt700->slave, &stream_config, in rt700_pcm_hw_params()
940 dev_err(dai->dev, "Unable to configure port\n"); in rt700_pcm_hw_params()
945 /* bit 3:0 Number of Channel */ in rt700_pcm_hw_params()
946 val |= (params_channels(params) - 1); in rt700_pcm_hw_params()
948 dev_err(component->dev, "Unsupported channels %d\n", in rt700_pcm_hw_params()
950 return -EINVAL; in rt700_pcm_hw_params()
970 return -EINVAL; in rt700_pcm_hw_params()
974 regmap_write(rt700->regmap, RT700_DAC_FORMAT_H, val); in rt700_pcm_hw_params()
975 regmap_write(rt700->regmap, RT700_ADC_FORMAT_H, val); in rt700_pcm_hw_params()
983 struct snd_soc_component *component = dai->component; in rt700_pcm_hw_free()
988 if (!rt700->slave) in rt700_pcm_hw_free()
989 return -EINVAL; in rt700_pcm_hw_free()
991 sdw_stream_remove_slave(rt700->slave, sdw_stream); in rt700_pcm_hw_free()
1008 .name = "rt700-aif1",
1027 .name = "rt700-aif2",
1060 clk_freq = (rt700->params.curr_dr_freq >> 1); in rt700_clock_config()
1082 return -EINVAL; in rt700_clock_config()
1085 regmap_write(rt700->regmap, 0xe0, value); in rt700_clock_config()
1086 regmap_write(rt700->regmap, 0xf0, value); in rt700_clock_config()
1102 return -ENOMEM; in rt700_init()
1105 rt700->slave = slave; in rt700_init()
1106 rt700->sdw_regmap = sdw_regmap; in rt700_init()
1107 rt700->regmap = regmap; in rt700_init()
1109 regcache_cache_only(rt700->regmap, true); in rt700_init()
1111 mutex_init(&rt700->disable_irq_lock); in rt700_init()
1113 INIT_DELAYED_WORK(&rt700->jack_detect_work, in rt700_init()
1115 INIT_DELAYED_WORK(&rt700->jack_btn_check_work, in rt700_init()
1122 rt700->hw_init = false; in rt700_init()
1123 rt700->first_hw_init = false; in rt700_init()
1144 * fail with -EACCESS because of race conditions between card creation and enumeration in rt700_init()
1146 dev_dbg(&slave->dev, "%s\n", __func__); in rt700_init()
1155 rt700->disable_irq = false; in rt700_io_init()
1157 if (rt700->hw_init) in rt700_io_init()
1160 regcache_cache_only(rt700->regmap, false); in rt700_io_init()
1161 if (rt700->first_hw_init) in rt700_io_init()
1162 regcache_cache_bypass(rt700->regmap, true); in rt700_io_init()
1167 if (!rt700->first_hw_init) in rt700_io_init()
1169 pm_runtime_set_active(&slave->dev); in rt700_io_init()
1171 pm_runtime_get_noresume(&slave->dev); in rt700_io_init()
1174 regmap_write(rt700->regmap, 0xff01, 0x0000); in rt700_io_init()
1175 regmap_write(rt700->regmap, 0x7520, 0x001a); in rt700_io_init()
1176 regmap_write(rt700->regmap, 0x7420, 0xc003); in rt700_io_init()
1179 regmap_write(rt700->regmap, RT700_SET_AUDIO_POWER_STATE, AC_PWRST_D0); in rt700_io_init()
1181 regmap_write(rt700->regmap, RT700_SET_PIN_HP, 0x40); in rt700_io_init()
1182 regmap_write(rt700->regmap, RT700_SET_PIN_SPK, 0x40); in rt700_io_init()
1183 regmap_write(rt700->regmap, RT700_SET_EAPD_SPK, RT700_EAPD_HIGH); in rt700_io_init()
1184 regmap_write(rt700->regmap, RT700_SET_PIN_DMIC1, 0x20); in rt700_io_init()
1185 regmap_write(rt700->regmap, RT700_SET_PIN_DMIC2, 0x20); in rt700_io_init()
1186 regmap_write(rt700->regmap, RT700_SET_PIN_MIC2, 0x20); in rt700_io_init()
1189 regmap_write(rt700->regmap, 0x4f12, 0x91); in rt700_io_init()
1190 regmap_write(rt700->regmap, 0x4e12, 0xd6); in rt700_io_init()
1191 regmap_write(rt700->regmap, 0x4d12, 0x11); in rt700_io_init()
1192 regmap_write(rt700->regmap, 0x4c12, 0x20); in rt700_io_init()
1193 regmap_write(rt700->regmap, 0x4f13, 0x91); in rt700_io_init()
1194 regmap_write(rt700->regmap, 0x4e13, 0xd6); in rt700_io_init()
1195 regmap_write(rt700->regmap, 0x4d13, 0x11); in rt700_io_init()
1196 regmap_write(rt700->regmap, 0x4c13, 0x21); in rt700_io_init()
1198 regmap_write(rt700->regmap, 0x4f19, 0x02); in rt700_io_init()
1199 regmap_write(rt700->regmap, 0x4e19, 0xa1); in rt700_io_init()
1200 regmap_write(rt700->regmap, 0x4d19, 0x90); in rt700_io_init()
1201 regmap_write(rt700->regmap, 0x4c19, 0x80); in rt700_io_init()
1204 regmap_write(rt700->regmap, 0x371b, 0x40); in rt700_io_init()
1205 regmap_write(rt700->regmap, 0x731b, 0xb0); in rt700_io_init()
1206 regmap_write(rt700->regmap, 0x839b, 0x00); in rt700_io_init()
1209 rt700_index_write(rt700->regmap, 0x4a, 0x201b); in rt700_io_init()
1210 rt700_index_write(rt700->regmap, 0x45, 0x5089); in rt700_io_init()
1211 rt700_index_write(rt700->regmap, 0x6b, 0x5064); in rt700_io_init()
1212 rt700_index_write(rt700->regmap, 0x48, 0xd249); in rt700_io_init()
1215 regmap_write(rt700->regmap, RT700_SET_AUDIO_POWER_STATE, AC_PWRST_D3); in rt700_io_init()
1221 if (rt700->hs_jack) in rt700_io_init()
1224 if (rt700->first_hw_init) { in rt700_io_init()
1225 regcache_cache_bypass(rt700->regmap, false); in rt700_io_init()
1226 regcache_mark_dirty(rt700->regmap); in rt700_io_init()
1228 rt700->first_hw_init = true; in rt700_io_init()
1231 rt700->hw_init = true; in rt700_io_init()
1233 pm_runtime_mark_last_busy(&slave->dev); in rt700_io_init()
1234 pm_runtime_put_autosuspend(&slave->dev); in rt700_io_init()
1236 dev_dbg(&slave->dev, "%s hw_init complete\n", __func__); in rt700_io_init()