Lines Matching full:rk3308
2 * rk3308_codec.c -- RK3308 ALSA Soc Audio Driver
54 #define CODEC_DRV_NAME "rk3308-acodec"
248 static bool handle_loopback(struct rk3308_codec_priv *rk3308);
252 static void rk3308_codec_dac_mclk_enable(struct rk3308_codec_priv *rk3308);
254 static int rk3308_codec_micbias_enable(struct rk3308_codec_priv *rk3308,
256 static int rk3308_codec_micbias_disable(struct rk3308_codec_priv *rk3308);
626 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_mic_mute_get() local
632 dev_err(rk3308->plat_dev, in rk3308_codec_mic_mute_get()
639 regmap_read(rk3308->regmap, RK3308_ADC_DIG_CON03(grp), &value); in rk3308_codec_mic_mute_get()
640 rk3308->mic_mute_r[e->reg] = (value & RK3308_ADC_R_CH_BIST_SINE) >> in rk3308_codec_mic_mute_get()
642 ucontrol->value.integer.value[0] = rk3308->mic_mute_r[e->reg]; in rk3308_codec_mic_mute_get()
645 regmap_read(rk3308->regmap, RK3308_ADC_DIG_CON03(grp), &value); in rk3308_codec_mic_mute_get()
646 rk3308->mic_mute_l[e->reg] = (value & RK3308_ADC_L_CH_BIST_SINE) >> in rk3308_codec_mic_mute_get()
648 ucontrol->value.integer.value[0] = rk3308->mic_mute_l[e->reg]; in rk3308_codec_mic_mute_get()
658 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_mic_mute_put() local
664 dev_err(rk3308->plat_dev, in rk3308_codec_mic_mute_put()
672 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON03(grp), in rk3308_codec_mic_mute_put()
675 rk3308->mic_mute_r[e->reg] = ucontrol->value.integer.value[0]; in rk3308_codec_mic_mute_put()
679 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON03(grp), in rk3308_codec_mic_mute_put()
682 rk3308->mic_mute_l[e->reg] = ucontrol->value.integer.value[0]; in rk3308_codec_mic_mute_put()
692 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_micbias_volts_get() local
694 ucontrol->value.integer.value[0] = rk3308->micbias_volt; in rk3308_codec_micbias_volts_get()
703 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_micbias_volts_put() local
709 dev_err(rk3308->plat_dev, "The invalid micbias volt: %d\n", in rk3308_codec_micbias_volts_put()
714 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(0), in rk3308_codec_micbias_volts_put()
718 rk3308->micbias_volt = volt; in rk3308_codec_micbias_volts_put()
727 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_main_micbias_get() local
729 ucontrol->value.integer.value[0] = rk3308->enable_micbias; in rk3308_codec_main_micbias_get()
738 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_main_micbias_put() local
742 if (!rk3308->enable_micbias) in rk3308_codec_main_micbias_put()
743 rk3308_codec_micbias_enable(rk3308, rk3308->micbias_volt); in rk3308_codec_main_micbias_put()
745 if (rk3308->enable_micbias) in rk3308_codec_main_micbias_put()
746 rk3308_codec_micbias_disable(rk3308); in rk3308_codec_main_micbias_put()
762 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_mic_gain_put() local
766 dev_err(rk3308->plat_dev, "%s: invalid mic gain: %d\n", in rk3308_codec_mic_gain_put()
771 if (rk3308->codec_ver == ACODEC_VERSION_A) { in rk3308_codec_mic_gain_put()
777 dev_err(rk3308->plat_dev, in rk3308_codec_mic_gain_put()
791 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_hpf_get() local
796 dev_err(rk3308->plat_dev, in rk3308_codec_hpf_get()
801 regmap_read(rk3308->regmap, RK3308_ADC_DIG_CON04(e->reg), &value); in rk3308_codec_hpf_get()
803 rk3308->hpf_cutoff[e->reg] = 0; in rk3308_codec_hpf_get()
805 rk3308->hpf_cutoff[e->reg] = 1; in rk3308_codec_hpf_get()
807 ucontrol->value.integer.value[0] = rk3308->hpf_cutoff[e->reg]; in rk3308_codec_hpf_get()
816 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_hpf_put() local
821 dev_err(rk3308->plat_dev, in rk3308_codec_hpf_put()
828 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON04(e->reg), in rk3308_codec_hpf_put()
833 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON04(e->reg), in rk3308_codec_hpf_put()
838 rk3308->hpf_cutoff[e->reg] = value; in rk3308_codec_hpf_put()
853 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_hpout_l_put_tlv() local
857 dev_err(rk3308->plat_dev, "%s: invalid l_dgain: %d\n", in rk3308_codec_hpout_l_put_tlv()
862 rk3308->hpout_l_dgain = dgain; in rk3308_codec_hpout_l_put_tlv()
877 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_hpout_r_put_tlv() local
881 dev_err(rk3308->plat_dev, "%s: invalid r_dgain: %d\n", in rk3308_codec_hpout_r_put_tlv()
886 rk3308->hpout_r_dgain = dgain; in rk3308_codec_hpout_r_put_tlv()
891 static u32 to_mapped_grp(struct rk3308_codec_priv *rk3308, int idx) in to_mapped_grp() argument
893 return rk3308->i2s_sdis[idx]; in to_mapped_grp()
896 static bool adc_for_each_grp(struct rk3308_codec_priv *rk3308, in adc_for_each_grp() argument
900 u32 mapped_grp = to_mapped_grp(rk3308, idx); in adc_for_each_grp()
903 if (rk3308->enable_all_adcs) in adc_for_each_grp()
906 max_grps = rk3308->used_adc_grps; in adc_for_each_grp()
911 if ((!rk3308->loopback_dacs_enabled) && in adc_for_each_grp()
912 handle_loopback(rk3308) && in adc_for_each_grp()
913 rk3308->loopback_grp == mapped_grp) { in adc_for_each_grp()
919 } else if (rk3308->en_always_grps_num && in adc_for_each_grp()
920 rk3308->skip_grps[mapped_grp]) { in adc_for_each_grp()
927 dev_dbg(rk3308->plat_dev, in adc_for_each_grp()
935 dev_dbg(rk3308->plat_dev, in adc_for_each_grp()
942 if (idx == (int)rk3308->cur_dbg_grp) in adc_for_each_grp()
947 dev_dbg(rk3308->plat_dev, in adc_for_each_grp()
954 *grp = rk3308->loopback_grp; in adc_for_each_grp()
955 dev_dbg(rk3308->plat_dev, in adc_for_each_grp()
963 static int rk3308_codec_get_dac_path_state(struct rk3308_codec_priv *rk3308) in rk3308_codec_get_dac_path_state() argument
965 return rk3308->dac_path_state; in rk3308_codec_get_dac_path_state()
968 static void rk3308_codec_set_dac_path_state(struct rk3308_codec_priv *rk3308, in rk3308_codec_set_dac_path_state() argument
971 rk3308->dac_path_state = state; in rk3308_codec_set_dac_path_state()
974 static void rk3308_headphone_ctl(struct rk3308_codec_priv *rk3308, int on) in rk3308_headphone_ctl() argument
976 if (rk3308->hp_ctl_gpio) in rk3308_headphone_ctl()
977 gpiod_direction_output(rk3308->hp_ctl_gpio, on); in rk3308_headphone_ctl()
980 static void rk3308_speaker_ctl(struct rk3308_codec_priv *rk3308, int on) in rk3308_speaker_ctl() argument
983 if (rk3308->pa_drv_gpio) { in rk3308_speaker_ctl()
984 gpiod_direction_output(rk3308->pa_drv_gpio, on); in rk3308_speaker_ctl()
985 msleep(rk3308->delay_pa_drv_ms); in rk3308_speaker_ctl()
988 if (rk3308->spk_ctl_gpio) in rk3308_speaker_ctl()
989 gpiod_direction_output(rk3308->spk_ctl_gpio, on); in rk3308_speaker_ctl()
991 if (rk3308->spk_ctl_gpio) in rk3308_speaker_ctl()
992 gpiod_direction_output(rk3308->spk_ctl_gpio, on); in rk3308_speaker_ctl()
994 if (rk3308->pa_drv_gpio) { in rk3308_speaker_ctl()
995 msleep(rk3308->delay_pa_drv_ms); in rk3308_speaker_ctl()
996 gpiod_direction_output(rk3308->pa_drv_gpio, on); in rk3308_speaker_ctl()
1003 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_reset() local
1005 reset_control_assert(rk3308->reset); in rk3308_codec_reset()
1007 reset_control_deassert(rk3308->reset); in rk3308_codec_reset()
1009 regmap_write(rk3308->regmap, RK3308_GLB_CON, 0x00); in rk3308_codec_reset()
1011 regmap_write(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_reset()
1019 static int rk3308_codec_adc_dig_reset(struct rk3308_codec_priv *rk3308) in rk3308_codec_adc_dig_reset() argument
1021 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_adc_dig_reset()
1025 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_adc_dig_reset()
1032 static int rk3308_codec_dac_dig_reset(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_dig_reset() argument
1034 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_dac_dig_reset()
1038 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_dac_dig_reset()
1048 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_set_bias_level() local
1056 regcache_cache_only(rk3308->regmap, false); in rk3308_set_bias_level()
1057 regcache_sync(rk3308->regmap); in rk3308_set_bias_level()
1070 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_set_dai_fmt() local
1079 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_set_dai_fmt()
1091 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_set_dai_fmt()
1162 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_set_dai_fmt()
1166 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_set_dai_fmt()
1170 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON01(grp), in rk3308_set_dai_fmt()
1174 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON02(grp), in rk3308_set_dai_fmt()
1183 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_set_dai_fmt()
1187 regmap_update_bits(rk3308->regmap, RK3308_DAC_DIG_CON01, in rk3308_set_dai_fmt()
1191 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_set_dai_fmt()
1192 regmap_update_bits(rk3308->regmap, RK3308_DAC_DIG_CON02, in rk3308_set_dai_fmt()
1198 regmap_update_bits(rk3308->regmap, RK3308_DAC_DIG_CON02, in rk3308_set_dai_fmt()
1208 static int rk3308_codec_dac_dig_config(struct rk3308_codec_priv *rk3308, in rk3308_codec_dac_dig_config() argument
1214 rk3308_codec_dac_dig_reset(rk3308); in rk3308_codec_dac_dig_config()
1236 regmap_update_bits(rk3308->regmap, RK3308_DAC_DIG_CON01, in rk3308_codec_dac_dig_config()
1240 regmap_update_bits(rk3308->regmap, RK3308_DAC_DIG_CON02, in rk3308_codec_dac_dig_config()
1247 static int rk3308_codec_adc_dig_config(struct rk3308_codec_priv *rk3308, in rk3308_codec_adc_dig_config() argument
1255 rk3308_codec_adc_dig_reset(rk3308); in rk3308_codec_adc_dig_config()
1291 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_dig_config()
1295 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON01(grp), in rk3308_codec_adc_dig_config()
1300 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON02(grp), in rk3308_codec_adc_dig_config()
1308 static int rk3308_codec_update_adc_grps(struct rk3308_codec_priv *rk3308, in rk3308_codec_update_adc_grps() argument
1313 rk3308->used_adc_grps = 1; in rk3308_codec_update_adc_grps()
1319 rk3308->used_adc_grps = params_channels(params) / 2; in rk3308_codec_update_adc_grps()
1322 dev_err(rk3308->plat_dev, "Invalid channels: %d\n", in rk3308_codec_update_adc_grps()
1333 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_mute_stream() local
1339 if (rk3308->codec_ver <= ACODEC_VERSION_B) { in rk3308_mute_stream()
1347 regmap_update_bits(rk3308->regmap, in rk3308_mute_stream()
1356 rk3308_headphone_ctl(rk3308, 0); in rk3308_mute_stream()
1357 rk3308_speaker_ctl(rk3308, 0); in rk3308_mute_stream()
1361 if (rk3308->dac_output == DAC_LINEOUT) in rk3308_mute_stream()
1362 rk3308_speaker_ctl(rk3308, 1); in rk3308_mute_stream()
1363 else if (rk3308->dac_output == DAC_HPOUT) in rk3308_mute_stream()
1364 rk3308_headphone_ctl(rk3308, 1); in rk3308_mute_stream()
1366 if (rk3308->delay_start_play_ms) in rk3308_mute_stream()
1367 msleep(rk3308->delay_start_play_ms); in rk3308_mute_stream()
1369 if (rk3308->codec_ver <= ACODEC_VERSION_B) { in rk3308_mute_stream()
1377 regmap_update_bits(rk3308->regmap, in rk3308_mute_stream()
1390 static int rk3308_codec_digital_fadein(struct rk3308_codec_priv *rk3308) in rk3308_codec_digital_fadein() argument
1394 if (rk3308->hpout_l_dgain != rk3308->hpout_r_dgain) { in rk3308_codec_digital_fadein()
1396 rk3308->hpout_l_dgain, rk3308->hpout_r_dgain); in rk3308_codec_digital_fadein()
1397 dgain_ref = min(rk3308->hpout_l_dgain, rk3308->hpout_r_dgain); in rk3308_codec_digital_fadein()
1399 dgain_ref = rk3308->hpout_l_dgain; in rk3308_codec_digital_fadein()
1409 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON05, in rk3308_codec_digital_fadein()
1414 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON06, in rk3308_codec_digital_fadein()
1422 static int rk3308_codec_digital_fadeout(struct rk3308_codec_priv *rk3308) in rk3308_codec_digital_fadeout() argument
1430 regmap_read(rk3308->regmap, RK3308_DAC_ANA_CON05, &l_dgain); in rk3308_codec_digital_fadeout()
1433 regmap_read(rk3308->regmap, RK3308_DAC_ANA_CON06, &r_dgain); in rk3308_codec_digital_fadeout()
1448 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON05, in rk3308_codec_digital_fadeout()
1453 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON06, in rk3308_codec_digital_fadeout()
1468 static int rk3308_codec_dac_lineout_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_lineout_enable() argument
1470 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_lineout_enable()
1479 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_lineout_enable()
1488 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_lineout_enable()
1498 static int rk3308_codec_dac_lineout_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_lineout_disable() argument
1501 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_lineout_disable()
1508 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_lineout_disable()
1514 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_lineout_disable()
1523 static int rk3308_codec_dac_hpout_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_hpout_enable() argument
1525 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_hpout_enable()
1533 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_enable()
1542 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_enable()
1551 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_enable()
1562 static int rk3308_codec_dac_hpout_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_hpout_disable() argument
1565 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_disable()
1572 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_disable()
1579 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_hpout_disable()
1586 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_hpout_disable()
1594 static int rk3308_codec_dac_switch(struct rk3308_codec_priv *rk3308, in rk3308_codec_dac_switch() argument
1598 if (rk3308->dac_output == dac_output) { in rk3308_codec_dac_switch()
1599 dev_info(rk3308->plat_dev, in rk3308_codec_dac_switch()
1610 dev_err(rk3308->plat_dev, "Unknown value: %d\n", dac_output); in rk3308_codec_dac_switch()
1615 if (rk3308_codec_get_dac_path_state(rk3308) == PATH_BUSY) { in rk3308_codec_dac_switch()
1623 rk3308_headphone_ctl(rk3308, 0); in rk3308_codec_dac_switch()
1624 rk3308_speaker_ctl(rk3308, 1); in rk3308_codec_dac_switch()
1625 rk3308_codec_dac_hpout_disable(rk3308); in rk3308_codec_dac_switch()
1626 rk3308_codec_dac_lineout_enable(rk3308); in rk3308_codec_dac_switch()
1629 rk3308_speaker_ctl(rk3308, 0); in rk3308_codec_dac_switch()
1630 rk3308_headphone_ctl(rk3308, 1); in rk3308_codec_dac_switch()
1631 rk3308_codec_dac_lineout_disable(rk3308); in rk3308_codec_dac_switch()
1632 rk3308_codec_dac_hpout_enable(rk3308); in rk3308_codec_dac_switch()
1635 rk3308_speaker_ctl(rk3308, 1); in rk3308_codec_dac_switch()
1636 rk3308_headphone_ctl(rk3308, 1); in rk3308_codec_dac_switch()
1637 rk3308_codec_dac_lineout_enable(rk3308); in rk3308_codec_dac_switch()
1638 rk3308_codec_dac_hpout_enable(rk3308); in rk3308_codec_dac_switch()
1645 rk3308->dac_output = dac_output; in rk3308_codec_dac_switch()
1647 dev_dbg(rk3308->plat_dev, "switch dac_output to: %d\n", in rk3308_codec_dac_switch()
1648 rk3308->dac_output); in rk3308_codec_dac_switch()
1653 static int rk3308_codec_dac_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_enable() argument
1686 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON00, in rk3308_codec_dac_enable()
1696 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_enable()
1706 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_enable()
1714 if (rk3308->codec_ver >= ACODEC_VERSION_B && in rk3308_codec_dac_enable()
1715 (rk3308->dac_output == DAC_LINEOUT || in rk3308_codec_dac_enable()
1716 rk3308->dac_output == DAC_LINEOUT_HPOUT)) { in rk3308_codec_dac_enable()
1718 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_enable()
1728 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_enable()
1738 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_enable()
1744 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_enable()
1752 if (rk3308->dac_output == DAC_LINEOUT || in rk3308_codec_dac_enable()
1753 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_enable()
1755 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_enable()
1764 if (rk3308->dac_output == DAC_HPOUT || in rk3308_codec_dac_enable()
1765 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_enable()
1767 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_enable()
1776 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_enable()
1785 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_dac_enable()
1787 if (rk3308->dac_output == DAC_HPOUT) { in rk3308_codec_dac_enable()
1788 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_enable()
1795 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_enable()
1806 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_enable()
1815 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_enable()
1824 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_enable()
1833 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_enable()
1842 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON12, in rk3308_codec_dac_enable()
1851 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_enable()
1861 if (rk3308->dac_output == DAC_HPOUT || in rk3308_codec_dac_enable()
1862 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_enable()
1864 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_enable()
1873 if (rk3308->dac_output == DAC_LINEOUT || in rk3308_codec_dac_enable()
1874 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_enable()
1876 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_enable()
1887 if (rk3308->dac_output == DAC_HPOUT || in rk3308_codec_dac_enable()
1888 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_enable()
1890 rk3308_codec_digital_fadein(rk3308); in rk3308_codec_dac_enable()
1893 rk3308->dac_endisable = true; in rk3308_codec_dac_enable()
1900 static int rk3308_codec_dac_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_disable() argument
1910 if (rk3308->dac_output == DAC_HPOUT || in rk3308_codec_dac_disable()
1911 rk3308->dac_output == DAC_LINEOUT_HPOUT) { in rk3308_codec_dac_disable()
1913 rk3308_codec_digital_fadeout(rk3308); in rk3308_codec_dac_disable()
1917 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_disable()
1924 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON12, in rk3308_codec_dac_disable()
1930 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_disable()
1937 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_disable()
1944 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_disable()
1951 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_disable()
1958 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_dac_disable()
1965 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_disable()
1972 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_disable()
1979 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_disable()
1986 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON02, in rk3308_codec_dac_disable()
1993 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_disable()
2000 if (rk3308->codec_ver >= ACODEC_VERSION_B && in rk3308_codec_dac_disable()
2001 (rk3308->dac_output == DAC_LINEOUT || in rk3308_codec_dac_disable()
2002 rk3308->dac_output == DAC_LINEOUT_HPOUT)) { in rk3308_codec_dac_disable()
2003 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_dac_disable()
2011 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_dac_disable()
2018 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON00, in rk3308_codec_dac_disable()
2023 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON03, in rk3308_codec_dac_disable()
2030 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON13, in rk3308_codec_dac_disable()
2044 * rk3308_codec_adc_ana_disable(rk3308, type); in rk3308_codec_dac_disable()
2047 rk3308->dac_endisable = false; in rk3308_codec_dac_disable()
2052 static int rk3308_codec_power_on(struct rk3308_codec_priv *rk3308) in rk3308_codec_power_on() argument
2063 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_power_on()
2066 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON01, in rk3308_codec_power_on()
2070 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_on()
2076 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_power_on()
2079 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, in rk3308_codec_power_on()
2087 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_on()
2091 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_on()
2096 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_on()
2107 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_on()
2110 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_on()
2115 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_on()
2126 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_on()
2132 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_on()
2140 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_on()
2154 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_on()
2157 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_on()
2162 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_on()
2166 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_codec_power_on()
2168 regmap_write(rk3308->regmap, RK3308_DAC_ANA_CON07, 0x11); in rk3308_codec_power_on()
2169 regmap_write(rk3308->regmap, RK3308_DAC_ANA_CON08, 0x11); in rk3308_codec_power_on()
2175 static int rk3308_codec_power_off(struct rk3308_codec_priv *rk3308) in rk3308_codec_power_off() argument
2187 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_off()
2191 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_off()
2196 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_off()
2202 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_off()
2206 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_off()
2208 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14, in rk3308_codec_power_off()
2219 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON10(0), in rk3308_codec_power_off()
2225 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_power_off()
2233 regmap_update_bits(rk3308->regmap, in rk3308_codec_power_off()
2252 static int rk3308_codec_headset_detect_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_headset_detect_enable() argument
2254 if (rk3308->codec_ver == ACODEC_VERSION_C) in rk3308_codec_headset_detect_enable()
2255 rk3308_codec_dac_mclk_enable(rk3308); in rk3308_codec_headset_detect_enable()
2264 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON00, in rk3308_codec_headset_detect_enable()
2271 static int rk3308_codec_headset_detect_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_headset_detect_disable() argument
2277 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON00, in rk3308_codec_headset_detect_disable()
2284 static int rk3308_codec_check_i2s_sdis(struct rk3308_codec_priv *rk3308, in rk3308_codec_check_i2s_sdis() argument
2291 rk3308->which_i2s = ACODEC_TO_I2S1_2CH; in rk3308_codec_check_i2s_sdis()
2294 rk3308->which_i2s = ACODEC_TO_I2S3_4CH; in rk3308_codec_check_i2s_sdis()
2297 rk3308->which_i2s = ACODEC_TO_I2S2_8CH; in rk3308_codec_check_i2s_sdis()
2300 dev_err(rk3308->plat_dev, "Invalid i2s sdis num: %d\n", num); in rk3308_codec_check_i2s_sdis()
2306 if (rk3308->i2s_sdis[i] > ADC_LR_GROUP_MAX - 1) { in rk3308_codec_check_i2s_sdis()
2307 dev_err(rk3308->plat_dev, in rk3308_codec_check_i2s_sdis()
2309 i, rk3308->i2s_sdis[i]); in rk3308_codec_check_i2s_sdis()
2318 if (rk3308->i2s_sdis[i] == rk3308->i2s_sdis[j]) { in rk3308_codec_check_i2s_sdis()
2319 dev_err(rk3308->plat_dev, in rk3308_codec_check_i2s_sdis()
2321 i, rk3308->i2s_sdis[i], in rk3308_codec_check_i2s_sdis()
2322 j, rk3308->i2s_sdis[j]); in rk3308_codec_check_i2s_sdis()
2333 static int rk3308_codec_adc_grps_route_config(struct rk3308_codec_priv *rk3308) in rk3308_codec_adc_grps_route_config() argument
2337 if (rk3308->which_i2s == ACODEC_TO_I2S2_8CH) { in rk3308_codec_adc_grps_route_config()
2338 for (idx = 0; idx < rk3308->to_i2s_grps; idx++) { in rk3308_codec_adc_grps_route_config()
2339 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_config()
2340 GRF_I2S2_8CH_SDI(idx, rk3308->i2s_sdis[idx])); in rk3308_codec_adc_grps_route_config()
2342 } else if (rk3308->which_i2s == ACODEC_TO_I2S3_4CH) { in rk3308_codec_adc_grps_route_config()
2343 for (idx = 0; idx < rk3308->to_i2s_grps; idx++) { in rk3308_codec_adc_grps_route_config()
2344 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_config()
2345 GRF_I2S3_4CH_SDI(idx, rk3308->i2s_sdis[idx])); in rk3308_codec_adc_grps_route_config()
2347 } else if (rk3308->which_i2s == ACODEC_TO_I2S1_2CH) { in rk3308_codec_adc_grps_route_config()
2348 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_config()
2349 GRF_I2S1_2CH_SDI(rk3308->i2s_sdis[idx])); in rk3308_codec_adc_grps_route_config()
2356 static int rk3308_codec_adc_grps_route_default(struct rk3308_codec_priv *rk3308) in rk3308_codec_adc_grps_route_default() argument
2365 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_default()
2369 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_default()
2374 rk3308->which_i2s = ACODEC_TO_I2S2_8CH; in rk3308_codec_adc_grps_route_default()
2375 rk3308->to_i2s_grps = ADC_LR_GROUP_MAX; in rk3308_codec_adc_grps_route_default()
2378 rk3308->i2s_sdis[idx] = idx; in rk3308_codec_adc_grps_route_default()
2379 regmap_write(rk3308->grf, GRF_SOC_CON1, in rk3308_codec_adc_grps_route_default()
2386 static int rk3308_codec_adc_grps_route(struct rk3308_codec_priv *rk3308, in rk3308_codec_adc_grps_route() argument
2395 rk3308_codec_adc_grps_route_default(rk3308); in rk3308_codec_adc_grps_route()
2398 dev_err(rk3308->plat_dev, in rk3308_codec_adc_grps_route()
2407 rk3308->i2s_sdis, num); in rk3308_codec_adc_grps_route()
2409 dev_err(rk3308->plat_dev, in rk3308_codec_adc_grps_route()
2415 ret = rk3308_codec_check_i2s_sdis(rk3308, num); in rk3308_codec_adc_grps_route()
2417 dev_err(rk3308->plat_dev, in rk3308_codec_adc_grps_route()
2422 rk3308->to_i2s_grps = num; in rk3308_codec_adc_grps_route()
2424 rk3308_codec_adc_grps_route_config(rk3308); in rk3308_codec_adc_grps_route()
2446 static bool handle_loopback(struct rk3308_codec_priv *rk3308) in handle_loopback() argument
2449 if (rk3308->codec_ver >= ACODEC_VERSION_B) in handle_loopback()
2452 switch (rk3308->loopback_grp) { in handle_loopback()
2463 static bool has_en_always_grps(struct rk3308_codec_priv *rk3308) in has_en_always_grps() argument
2467 if (rk3308->en_always_grps_num) { in has_en_always_grps()
2469 if (rk3308->en_always_grps[idx] >= 0 && in has_en_always_grps()
2470 rk3308->en_always_grps[idx] <= ADC_LR_GROUP_MAX - 1) in has_en_always_grps()
2478 static int rk3308_codec_micbias_enable(struct rk3308_codec_priv *rk3308, in rk3308_codec_micbias_enable() argument
2483 if (rk3308->ext_micbias != EXT_MICBIAS_NONE) in rk3308_codec_micbias_enable()
2491 dev_err(rk3308->plat_dev, "This is an invalid micbias: %d\n", in rk3308_codec_micbias_enable()
2500 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(0), in rk3308_codec_micbias_enable()
2513 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON08(0), in rk3308_codec_micbias_enable()
2524 if (rk3308->micbias1) in rk3308_codec_micbias_enable()
2525 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(1), in rk3308_codec_micbias_enable()
2529 if (rk3308->micbias2) in rk3308_codec_micbias_enable()
2530 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(2), in rk3308_codec_micbias_enable()
2537 rk3308->enable_micbias = true; in rk3308_codec_micbias_enable()
2542 static int rk3308_codec_micbias_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_micbias_disable() argument
2544 if (rk3308->ext_micbias != EXT_MICBIAS_NONE) in rk3308_codec_micbias_disable()
2554 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(1), in rk3308_codec_micbias_disable()
2557 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(2), in rk3308_codec_micbias_disable()
2567 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON08(0), in rk3308_codec_micbias_disable()
2571 rk3308->enable_micbias = false; in rk3308_codec_micbias_disable()
2576 static int rk3308_codec_adc_reinit_mics(struct rk3308_codec_priv *rk3308, in rk3308_codec_adc_reinit_mics() argument
2581 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2586 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_reinit_mics()
2593 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2598 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_reinit_mics()
2605 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2610 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_reinit_mics()
2619 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2624 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_reinit_mics()
2631 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2636 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_reinit_mics()
2643 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_reinit_mics()
2648 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_reinit_mics()
2658 static int rk3308_codec_adc_ana_enable(struct rk3308_codec_priv *rk3308, in rk3308_codec_adc_ana_enable() argument
2671 if (rk3308->adc_grp0_using_linein) { in rk3308_codec_adc_ana_enable()
2672 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON07(0), in rk3308_codec_adc_ana_enable()
2679 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2684 regmap_update_bits(rk3308->regmap, in rk3308_codec_adc_ana_enable()
2692 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2696 regmap_update_bits(rk3308->regmap, in rk3308_codec_adc_ana_enable()
2710 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2714 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_enable()
2725 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2729 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON06(grp), in rk3308_codec_adc_ana_enable()
2743 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2747 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_enable()
2755 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2759 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_enable()
2767 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2771 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_ana_enable()
2779 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2783 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_enable()
2791 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2795 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_enable()
2803 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2807 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_enable()
2815 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2819 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_ana_enable()
2827 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2831 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_enable()
2843 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2847 regmap_read(rk3308->regmap, RK3308_ALC_L_DIG_CON09(grp), in rk3308_codec_adc_ana_enable()
2849 if (rk3308->adc_zerocross || in rk3308_codec_adc_ana_enable()
2851 regmap_update_bits(rk3308->regmap, in rk3308_codec_adc_ana_enable()
2856 regmap_read(rk3308->regmap, RK3308_ALC_R_DIG_CON09(grp), in rk3308_codec_adc_ana_enable()
2858 if (rk3308->adc_zerocross || in rk3308_codec_adc_ana_enable()
2860 regmap_update_bits(rk3308->regmap, in rk3308_codec_adc_ana_enable()
2867 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_enable()
2871 rk3308->adc_grps_endisable[grp] = true; in rk3308_codec_adc_ana_enable()
2877 static int rk3308_codec_adc_ana_disable(struct rk3308_codec_priv *rk3308, in rk3308_codec_adc_ana_disable() argument
2882 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2887 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_ana_disable()
2894 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2899 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_disable()
2906 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2911 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_disable()
2918 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2923 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_ana_disable()
2930 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2935 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_disable()
2942 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2947 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_disable()
2954 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2959 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON06(grp), in rk3308_codec_adc_ana_disable()
2964 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2969 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON05(grp), in rk3308_codec_adc_ana_disable()
2976 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2981 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON02(grp), in rk3308_codec_adc_ana_disable()
2988 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
2993 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON00(grp), in rk3308_codec_adc_ana_disable()
3000 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_adc_ana_disable()
3004 rk3308->adc_grps_endisable[grp] = false; in rk3308_codec_adc_ana_disable()
3010 static int rk3308_codec_open_capture(struct rk3308_codec_priv *rk3308) in rk3308_codec_open_capture() argument
3015 rk3308_codec_adc_ana_enable(rk3308, type); in rk3308_codec_open_capture()
3016 rk3308_codec_adc_reinit_mics(rk3308, type); in rk3308_codec_open_capture()
3018 if (rk3308->adc_grp0_using_linein) { in rk3308_codec_open_capture()
3019 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON03(0), in rk3308_codec_open_capture()
3022 regmap_update_bits(rk3308->regmap, RK3308_ADC_DIG_CON03(0), in rk3308_codec_open_capture()
3026 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_open_capture()
3027 if (handle_loopback(rk3308) && in rk3308_codec_open_capture()
3028 idx == rk3308->loopback_grp && in rk3308_codec_open_capture()
3039 regmap_update_bits(rk3308->regmap, in rk3308_codec_open_capture()
3040 RK3308_ADC_DIG_CON03(rk3308->loopback_grp), in rk3308_codec_open_capture()
3043 regmap_update_bits(rk3308->regmap, in rk3308_codec_open_capture()
3044 RK3308_ADC_DIG_CON03(rk3308->loopback_grp), in rk3308_codec_open_capture()
3051 regmap_update_bits(rk3308->regmap, in rk3308_codec_open_capture()
3055 regmap_update_bits(rk3308->regmap, in rk3308_codec_open_capture()
3066 static void rk3308_codec_adc_mclk_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_adc_mclk_disable() argument
3068 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_adc_mclk_disable()
3073 static void rk3308_codec_adc_mclk_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_adc_mclk_enable() argument
3075 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_adc_mclk_enable()
3081 static void rk3308_codec_dac_mclk_disable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_mclk_disable() argument
3083 if (!rk3308->no_hp_det && rk3308->codec_ver == ACODEC_VERSION_C) in rk3308_codec_dac_mclk_disable()
3086 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_dac_mclk_disable()
3091 static void rk3308_codec_dac_mclk_enable(struct rk3308_codec_priv *rk3308) in rk3308_codec_dac_mclk_enable() argument
3093 regmap_update_bits(rk3308->regmap, RK3308_GLB_CON, in rk3308_codec_dac_mclk_enable()
3099 static int rk3308_codec_open_dbg_capture(struct rk3308_codec_priv *rk3308) in rk3308_codec_open_dbg_capture() argument
3101 rk3308_codec_adc_ana_enable(rk3308, ADC_TYPE_DBG); in rk3308_codec_open_dbg_capture()
3106 static int rk3308_codec_close_dbg_capture(struct rk3308_codec_priv *rk3308) in rk3308_codec_close_dbg_capture() argument
3108 rk3308_codec_adc_ana_disable(rk3308, ADC_TYPE_DBG); in rk3308_codec_close_dbg_capture()
3113 static int rk3308_codec_close_all_capture(struct rk3308_codec_priv *rk3308) in rk3308_codec_close_all_capture() argument
3115 rk3308_codec_adc_ana_disable(rk3308, ADC_TYPE_ALL); in rk3308_codec_close_all_capture()
3120 static int rk3308_codec_close_capture(struct rk3308_codec_priv *rk3308) in rk3308_codec_close_capture() argument
3122 rk3308_codec_adc_ana_disable(rk3308, ADC_TYPE_NORMAL); in rk3308_codec_close_capture()
3127 static int rk3308_codec_open_playback(struct rk3308_codec_priv *rk3308) in rk3308_codec_open_playback() argument
3129 rk3308_codec_dac_enable(rk3308); in rk3308_codec_open_playback()
3134 static int rk3308_codec_close_playback(struct rk3308_codec_priv *rk3308) in rk3308_codec_close_playback() argument
3136 rk3308_codec_dac_disable(rk3308); in rk3308_codec_close_playback()
3141 static int rk3308_codec_llp_down(struct rk3308_codec_priv *rk3308) in rk3308_codec_llp_down() argument
3143 rk3308_codec_adc_mclk_disable(rk3308); in rk3308_codec_llp_down()
3144 rk3308_codec_dac_mclk_disable(rk3308); in rk3308_codec_llp_down()
3149 static int rk3308_codec_llp_up(struct rk3308_codec_priv *rk3308) in rk3308_codec_llp_up() argument
3151 rk3308_codec_adc_mclk_enable(rk3308); in rk3308_codec_llp_up()
3152 rk3308_codec_dac_mclk_enable(rk3308); in rk3308_codec_llp_up()
3157 static int rk3308_codec_dlp_down(struct rk3308_codec_priv *rk3308) in rk3308_codec_dlp_down() argument
3159 rk3308_codec_micbias_disable(rk3308); in rk3308_codec_dlp_down()
3160 rk3308_codec_power_off(rk3308); in rk3308_codec_dlp_down()
3165 static int rk3308_codec_dlp_up(struct rk3308_codec_priv *rk3308) in rk3308_codec_dlp_up() argument
3167 rk3308_codec_power_on(rk3308); in rk3308_codec_dlp_up()
3168 rk3308_codec_micbias_enable(rk3308, rk3308->micbias_volt); in rk3308_codec_dlp_up()
3174 static void rk3308_codec_set_pm_state(struct rk3308_codec_priv *rk3308, in rk3308_codec_set_pm_state() argument
3181 rk3308_codec_llp_down(rk3308); in rk3308_codec_set_pm_state()
3184 rk3308_codec_llp_up(rk3308); in rk3308_codec_set_pm_state()
3187 rk3308_codec_dlp_down(rk3308); in rk3308_codec_set_pm_state()
3190 rk3308_codec_dlp_up(rk3308); in rk3308_codec_set_pm_state()
3193 clk_disable_unprepare(rk3308->mclk_rx); in rk3308_codec_set_pm_state()
3194 clk_disable_unprepare(rk3308->mclk_tx); in rk3308_codec_set_pm_state()
3195 clk_disable_unprepare(rk3308->pclk); in rk3308_codec_set_pm_state()
3198 ret = clk_prepare_enable(rk3308->pclk); in rk3308_codec_set_pm_state()
3200 dev_err(rk3308->plat_dev, in rk3308_codec_set_pm_state()
3205 ret = clk_prepare_enable(rk3308->mclk_rx); in rk3308_codec_set_pm_state()
3207 dev_err(rk3308->plat_dev, in rk3308_codec_set_pm_state()
3212 ret = clk_prepare_enable(rk3308->mclk_tx); in rk3308_codec_set_pm_state()
3214 dev_err(rk3308->plat_dev, in rk3308_codec_set_pm_state()
3220 dev_err(rk3308->plat_dev, "Invalid pm_state: %d\n", pm_state); in rk3308_codec_set_pm_state()
3224 rk3308->pm_state = pm_state; in rk3308_codec_set_pm_state()
3230 static void rk3308_codec_update_adcs_status(struct rk3308_codec_priv *rk3308, in rk3308_codec_update_adcs_status() argument
3237 for (idx = 0; idx < rk3308->used_adc_grps; idx++) { in rk3308_codec_update_adcs_status()
3238 u32 mapped_grp = to_mapped_grp(rk3308, idx); in rk3308_codec_update_adcs_status()
3240 for (grp = 0; grp < rk3308->en_always_grps_num; grp++) { in rk3308_codec_update_adcs_status()
3241 u32 en_always_grp = rk3308->en_always_grps[grp]; in rk3308_codec_update_adcs_status()
3244 rk3308->skip_grps[en_always_grp] = 1; in rk3308_codec_update_adcs_status()
3255 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_hw_params() local
3264 rk3308_codec_dac_mclk_enable(rk3308); in rk3308_hw_params()
3265 rk3308_codec_open_playback(rk3308); in rk3308_hw_params()
3266 rk3308_codec_dac_dig_config(rk3308, params); in rk3308_hw_params()
3267 rk3308_codec_set_dac_path_state(rk3308, PATH_BUSY); in rk3308_hw_params()
3269 if (rk3308->micbias_num && in rk3308_hw_params()
3270 !rk3308->enable_micbias) in rk3308_hw_params()
3271 rk3308_codec_micbias_enable(rk3308, rk3308->micbias_volt); in rk3308_hw_params()
3273 rk3308_codec_adc_mclk_enable(rk3308); in rk3308_hw_params()
3274 ret = rk3308_codec_update_adc_grps(rk3308, params); in rk3308_hw_params()
3278 if (handle_loopback(rk3308)) { in rk3308_hw_params()
3279 if (rk3308->micbias_num && in rk3308_hw_params()
3281 to_mapped_grp(rk3308, 0) == rk3308->loopback_grp) in rk3308_hw_params()
3282 rk3308_codec_micbias_disable(rk3308); in rk3308_hw_params()
3286 rk3308->loopback_dacs_enabled = true; in rk3308_hw_params()
3287 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_hw_params()
3291 regmap_update_bits(rk3308->regmap, in rk3308_hw_params()
3295 regmap_update_bits(rk3308->regmap, in rk3308_hw_params()
3301 rk3308->loopback_dacs_enabled = false; in rk3308_hw_params()
3302 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_hw_params()
3306 regmap_update_bits(rk3308->regmap, in rk3308_hw_params()
3310 regmap_update_bits(rk3308->regmap, in rk3308_hw_params()
3318 rk3308_codec_open_capture(rk3308); in rk3308_hw_params()
3319 rk3308_codec_adc_dig_config(rk3308, params); in rk3308_hw_params()
3320 rk3308_codec_update_adcs_status(rk3308, PATH_BUSY); in rk3308_hw_params()
3330 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_pcm_trigger() local
3334 if (handle_loopback(rk3308) && in rk3308_pcm_trigger()
3335 rk3308->dac_output == DAC_LINEOUT && in rk3308_pcm_trigger()
3343 &rk3308->loopback_work, in rk3308_pcm_trigger()
3344 msecs_to_jiffies(rk3308->delay_loopback_handle_ms)); in rk3308_pcm_trigger()
3350 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_pcm_trigger()
3354 regmap_update_bits(rk3308->regmap, in rk3308_pcm_trigger()
3358 regmap_update_bits(rk3308->regmap, in rk3308_pcm_trigger()
3363 rk3308_codec_adc_ana_disable(rk3308, ADC_TYPE_LOOPBACK); in rk3308_pcm_trigger()
3374 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_pcm_shutdown() local
3377 rk3308_codec_close_playback(rk3308); in rk3308_pcm_shutdown()
3378 rk3308_codec_dac_mclk_disable(rk3308); in rk3308_pcm_shutdown()
3379 regcache_cache_only(rk3308->regmap, false); in rk3308_pcm_shutdown()
3380 regcache_sync(rk3308->regmap); in rk3308_pcm_shutdown()
3381 rk3308_codec_set_dac_path_state(rk3308, PATH_IDLE); in rk3308_pcm_shutdown()
3383 rk3308_codec_close_capture(rk3308); in rk3308_pcm_shutdown()
3384 if (!has_en_always_grps(rk3308)) { in rk3308_pcm_shutdown()
3385 rk3308_codec_adc_mclk_disable(rk3308); in rk3308_pcm_shutdown()
3386 rk3308_codec_update_adcs_status(rk3308, PATH_IDLE); in rk3308_pcm_shutdown()
3387 if (rk3308->micbias_num && in rk3308_pcm_shutdown()
3388 rk3308->enable_micbias) in rk3308_pcm_shutdown()
3389 rk3308_codec_micbias_disable(rk3308); in rk3308_pcm_shutdown()
3392 regcache_cache_only(rk3308->regmap, false); in rk3308_pcm_shutdown()
3393 regcache_sync(rk3308->regmap); in rk3308_pcm_shutdown()
3407 .name = "rk3308-hifi",
3435 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_suspend() local
3437 if (rk3308->no_deep_low_power) in rk3308_suspend()
3440 rk3308_codec_dlp_down(rk3308); in rk3308_suspend()
3441 clk_disable_unprepare(rk3308->mclk_rx); in rk3308_suspend()
3442 clk_disable_unprepare(rk3308->mclk_tx); in rk3308_suspend()
3443 clk_disable_unprepare(rk3308->pclk); in rk3308_suspend()
3452 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_resume() local
3455 if (rk3308->no_deep_low_power) in rk3308_resume()
3458 ret = clk_prepare_enable(rk3308->pclk); in rk3308_resume()
3460 dev_err(rk3308->plat_dev, in rk3308_resume()
3465 ret = clk_prepare_enable(rk3308->mclk_rx); in rk3308_resume()
3467 dev_err(rk3308->plat_dev, in rk3308_resume()
3472 ret = clk_prepare_enable(rk3308->mclk_tx); in rk3308_resume()
3474 dev_err(rk3308->plat_dev, in rk3308_resume()
3479 rk3308_codec_dlp_up(rk3308); in rk3308_resume()
3485 static int rk3308_codec_default_gains(struct rk3308_codec_priv *rk3308) in rk3308_codec_default_gains() argument
3492 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON01(grp), in rk3308_codec_default_gains()
3501 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON03(grp), in rk3308_codec_default_gains()
3504 regmap_update_bits(rk3308->regmap, RK3308_ADC_ANA_CON04(grp), in rk3308_codec_default_gains()
3509 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_codec_default_gains()
3513 regmap_write(rk3308->regmap, RK3308BS_ADC_DIG_CON05(grp), in rk3308_codec_default_gains()
3515 regmap_write(rk3308->regmap, RK3308BS_ADC_DIG_CON06(grp), in rk3308_codec_default_gains()
3522 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON12, in rk3308_codec_default_gains()
3529 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON05, in rk3308_codec_default_gains()
3532 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON06, in rk3308_codec_default_gains()
3537 rk3308->hpout_l_dgain = RK3308_DAC_L_HPOUT_GAIN_0DB; in rk3308_codec_default_gains()
3538 rk3308->hpout_r_dgain = RK3308_DAC_R_HPOUT_GAIN_0DB; in rk3308_codec_default_gains()
3541 regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON04, in rk3308_codec_default_gains()
3547 if (rk3308->codec_ver == ACODEC_VERSION_C) { in rk3308_codec_default_gains()
3549 regmap_write(rk3308->regmap, RK3308BS_DAC_DIG_CON04, in rk3308_codec_default_gains()
3556 static int rk3308_codec_setup_en_always_adcs(struct rk3308_codec_priv *rk3308, in rk3308_codec_setup_en_always_adcs() argument
3570 dev_err(rk3308->plat_dev, in rk3308_codec_setup_en_always_adcs()
3576 rk3308->en_always_grps_num = 0; in rk3308_codec_setup_en_always_adcs()
3580 rk3308->en_always_grps_num = num; in rk3308_codec_setup_en_always_adcs()
3583 rk3308->en_always_grps, num); in rk3308_codec_setup_en_always_adcs()
3585 dev_err(rk3308->plat_dev, in rk3308_codec_setup_en_always_adcs()
3593 rk3308->skip_grps[num] = 0; in rk3308_codec_setup_en_always_adcs()
3596 for (num = 0; num < rk3308->en_always_grps_num; num++) { in rk3308_codec_setup_en_always_adcs()
3597 if (rk3308->en_always_grps[num] == rk3308->loopback_grp) { in rk3308_codec_setup_en_always_adcs()
3598 dev_err(rk3308->plat_dev, in rk3308_codec_setup_en_always_adcs()
3600 rk3308->loopback_grp); in rk3308_codec_setup_en_always_adcs()
3609 static int rk3308_codec_dapm_mic_gains(struct rk3308_codec_priv *rk3308) in rk3308_codec_dapm_mic_gains() argument
3613 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_dapm_mic_gains()
3614 ret = snd_soc_add_component_controls(rk3308->component, in rk3308_codec_dapm_mic_gains()
3618 dev_err(rk3308->plat_dev, in rk3308_codec_dapm_mic_gains()
3624 ret = snd_soc_add_component_controls(rk3308->component, in rk3308_codec_dapm_mic_gains()
3628 dev_err(rk3308->plat_dev, in rk3308_codec_dapm_mic_gains()
3638 static int rk3308_codec_check_micbias(struct rk3308_codec_priv *rk3308, in rk3308_codec_check_micbias() argument
3641 struct device *dev = (struct device *)rk3308->plat_dev; in rk3308_codec_check_micbias()
3645 rk3308->micbias1 = in rk3308_codec_check_micbias()
3647 if (rk3308->micbias1) in rk3308_codec_check_micbias()
3650 rk3308->micbias2 = in rk3308_codec_check_micbias()
3652 if (rk3308->micbias2) in rk3308_codec_check_micbias()
3655 rk3308->micbias_volt = RK3308_ADC_MICBIAS_VOLT_0_85; /* by default */ in rk3308_codec_check_micbias()
3656 rk3308->micbias_num = num; in rk3308_codec_check_micbias()
3659 rk3308->ext_micbias = EXT_MICBIAS_NONE; in rk3308_codec_check_micbias()
3661 rk3308->micbias_en_gpio = devm_gpiod_get_optional(dev, in rk3308_codec_check_micbias()
3664 if (!rk3308->micbias_en_gpio) { in rk3308_codec_check_micbias()
3666 } else if (IS_ERR(rk3308->micbias_en_gpio)) { in rk3308_codec_check_micbias()
3667 ret = PTR_ERR(rk3308->micbias_en_gpio); in rk3308_codec_check_micbias()
3670 } else if (gpiod_get_value(rk3308->micbias_en_gpio)) { in rk3308_codec_check_micbias()
3671 rk3308->ext_micbias = EXT_MICBIAS_FUNC1; in rk3308_codec_check_micbias()
3674 rk3308->vcc_micbias = devm_regulator_get_optional(dev, in rk3308_codec_check_micbias()
3676 if (IS_ERR(rk3308->vcc_micbias)) { in rk3308_codec_check_micbias()
3677 if (PTR_ERR(rk3308->vcc_micbias) == -EPROBE_DEFER) in rk3308_codec_check_micbias()
3681 ret = regulator_enable(rk3308->vcc_micbias); in rk3308_codec_check_micbias()
3686 rk3308->ext_micbias = EXT_MICBIAS_FUNC2; in rk3308_codec_check_micbias()
3689 dev_info(dev, "Check ext_micbias: %d\n", rk3308->ext_micbias); in rk3308_codec_check_micbias()
3694 static int rk3308_codec_dapm_controls_prepare(struct rk3308_codec_priv *rk3308) in rk3308_codec_dapm_controls_prepare() argument
3699 rk3308->hpf_cutoff[grp] = 0; in rk3308_codec_dapm_controls_prepare()
3701 rk3308_codec_dapm_mic_gains(rk3308); in rk3308_codec_dapm_controls_prepare()
3706 static int rk3308_codec_prepare(struct rk3308_codec_priv *rk3308) in rk3308_codec_prepare() argument
3709 rk3308_codec_close_playback(rk3308); in rk3308_codec_prepare()
3710 rk3308_codec_close_all_capture(rk3308); in rk3308_codec_prepare()
3711 rk3308_codec_default_gains(rk3308); in rk3308_codec_prepare()
3712 rk3308_codec_llp_down(rk3308); in rk3308_codec_prepare()
3713 rk3308_codec_dapm_controls_prepare(rk3308); in rk3308_codec_prepare()
3720 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_probe() local
3723 rk3308->component = component; in rk3308_probe()
3724 rk3308_codec_set_dac_path_state(rk3308, PATH_IDLE); in rk3308_probe()
3727 rk3308_codec_power_on(rk3308); in rk3308_probe()
3730 ext_micbias = rk3308->ext_micbias; in rk3308_probe()
3731 rk3308->ext_micbias = EXT_MICBIAS_NONE; in rk3308_probe()
3732 rk3308_codec_micbias_disable(rk3308); in rk3308_probe()
3733 rk3308->ext_micbias = ext_micbias; in rk3308_probe()
3735 rk3308_codec_prepare(rk3308); in rk3308_probe()
3736 if (!rk3308->no_hp_det) in rk3308_probe()
3737 rk3308_codec_headset_detect_enable(rk3308); in rk3308_probe()
3739 regcache_cache_only(rk3308->regmap, false); in rk3308_probe()
3740 regcache_sync(rk3308->regmap); in rk3308_probe()
3747 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_remove() local
3749 rk3308_headphone_ctl(rk3308, 0); in rk3308_remove()
3750 rk3308_speaker_ctl(rk3308, 0); in rk3308_remove()
3751 if (!rk3308->no_hp_det) in rk3308_remove()
3752 rk3308_codec_headset_detect_disable(rk3308); in rk3308_remove()
3753 rk3308_codec_micbias_disable(rk3308); in rk3308_remove()
3754 rk3308_codec_power_off(rk3308); in rk3308_remove()
3756 rk3308_codec_set_dac_path_state(rk3308, PATH_IDLE); in rk3308_remove()
3758 regcache_cache_only(rk3308->regmap, false); in rk3308_remove()
3759 regcache_sync(rk3308->regmap); in rk3308_remove()
3765 struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component); in rk3308_codec_set_jack() local
3768 if (rk3308->no_hp_det) in rk3308_codec_set_jack()
3771 rk3308->hpdet_jack = jack; in rk3308_codec_set_jack()
3774 disable_irq_nosync(rk3308->irq); in rk3308_codec_set_jack()
3776 &rk3308->hpdet_work, msecs_to_jiffies(10)); in rk3308_codec_set_jack()
3778 dev_info(rk3308->plat_dev, "%s: Request detect hp jack once\n", in rk3308_codec_set_jack()
3812 struct rk3308_codec_priv *rk3308 = in rk3308_codec_hpdetect_work() local
3819 if (rk3308->codec_ver == ACODEC_VERSION_C) in rk3308_codec_hpdetect_work()
3822 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_codec_hpdetect_work()
3824 regmap_read(rk3308->detect_grf, in rk3308_codec_hpdetect_work()
3826 regmap_write(rk3308->detect_grf, in rk3308_codec_hpdetect_work()
3829 if (rk3308->hp_jack_reversed) { in rk3308_codec_hpdetect_work()
3851 rk3308_codec_dac_switch(rk3308, dac_output); in rk3308_codec_hpdetect_work()
3852 if (rk3308->hpdet_jack) in rk3308_codec_hpdetect_work()
3853 snd_soc_jack_report(rk3308->hpdet_jack, in rk3308_codec_hpdetect_work()
3857 enable_irq(rk3308->irq); in rk3308_codec_hpdetect_work()
3863 regmap_read(rk3308->regmap, headphone_con, &val); in rk3308_codec_hpdetect_work()
3865 if (rk3308->hp_jack_reversed) { in rk3308_codec_hpdetect_work()
3867 rk3308->hp_plugged = true; in rk3308_codec_hpdetect_work()
3873 if (rk3308->hp_plugged) { in rk3308_codec_hpdetect_work()
3874 rk3308->hp_plugged = false; in rk3308_codec_hpdetect_work()
3881 rk3308->hp_plugged = false; in rk3308_codec_hpdetect_work()
3886 if (!rk3308->hp_plugged) { in rk3308_codec_hpdetect_work()
3887 rk3308->hp_plugged = true; in rk3308_codec_hpdetect_work()
3897 &rk3308->hpdet_work, in rk3308_codec_hpdetect_work()
3904 rk3308_codec_dac_switch(rk3308, dac_output); in rk3308_codec_hpdetect_work()
3906 if (rk3308->hpdet_jack) in rk3308_codec_hpdetect_work()
3907 snd_soc_jack_report(rk3308->hpdet_jack, in rk3308_codec_hpdetect_work()
3913 enable_irq(rk3308->irq); in rk3308_codec_hpdetect_work()
3918 struct rk3308_codec_priv *rk3308 = in rk3308_codec_loopback_work() local
3924 rk3308_codec_adc_ana_enable(rk3308, type); in rk3308_codec_loopback_work()
3930 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) { in rk3308_codec_loopback_work()
3934 regmap_update_bits(rk3308->regmap, in rk3308_codec_loopback_work()
3938 regmap_update_bits(rk3308->regmap, in rk3308_codec_loopback_work()
3947 struct rk3308_codec_priv *rk3308 = data; in rk3308_codec_hpdet_isr() local
3953 disable_irq_nosync(rk3308->irq); in rk3308_codec_hpdet_isr()
3955 &rk3308->hpdet_work, msecs_to_jiffies(10)); in rk3308_codec_hpdet_isr()
3977 struct rk3308_codec_priv *rk3308 = in pm_state_show() local
3980 return sprintf(buf, "pm_state: %d\n", rk3308->pm_state); in pm_state_show()
3987 struct rk3308_codec_priv *rk3308 = in pm_state_store() local
3998 rk3308_codec_set_pm_state(rk3308, pm_state); in pm_state_store()
4000 dev_info(dev, "Store pm_state: %d\n", rk3308->pm_state); in pm_state_store()
4009 struct rk3308_codec_priv *rk3308 = in adc_grps_show() local
4017 for (idx = 0; adc_for_each_grp(rk3308, type, idx, &grp); idx++) in adc_grps_show()
4021 rk3308->loopback_grp); in adc_grps_show()
4030 struct rk3308_codec_priv *rk3308 = in adc_grps_store() local
4037 dev_err(rk3308->plat_dev, "%s sscanf failed: %d\n", in adc_grps_store()
4043 rk3308->used_adc_grps = grps; in adc_grps_store()
4045 rk3308->loopback_grp = grps; in adc_grps_store()
4054 struct rk3308_codec_priv *rk3308 = in adc_grps_route_show() local
4060 switch (rk3308->which_i2s) { in adc_grps_route_show()
4074 for (grp = 0; grp < rk3308->to_i2s_grps; grp++) { in adc_grps_route_show()
4076 grp, rk3308->i2s_sdis[grp]); in adc_grps_route_show()
4086 struct rk3308_codec_priv *rk3308 = in adc_grps_route_store() local
4094 dev_err(rk3308->plat_dev, "%s sscanf failed: %d\n", in adc_grps_route_store()
4101 dev_err(rk3308->plat_dev, "Invalid i2s type: %d\n", which_i2s); in adc_grps_route_store()
4105 rk3308->which_i2s = which_i2s; in adc_grps_route_store()
4107 switch (rk3308->which_i2s) { in adc_grps_route_store()
4109 rk3308->to_i2s_grps = 1; in adc_grps_route_store()
4112 rk3308->to_i2s_grps = 2; in adc_grps_route_store()
4115 rk3308->to_i2s_grps = 4; in adc_grps_route_store()
4119 for (idx = 0; idx < rk3308->to_i2s_grps; idx++) in adc_grps_route_store()
4120 rk3308->i2s_sdis[idx] = i2s_sdis[idx]; in adc_grps_route_store()
4122 rk3308_codec_adc_grps_route_config(rk3308); in adc_grps_route_store()
4132 struct rk3308_codec_priv *rk3308 = in adc_grp0_in_show() local
4136 rk3308->adc_grp0_using_linein ? "line in" : "mic in"); in adc_grp0_in_show()
4143 struct rk3308_codec_priv *rk3308 = in adc_grp0_in_store() local
4154 rk3308->adc_grp0_using_linein = using_linein; in adc_grp0_in_store()
4157 rk3308->adc_grp0_using_linein); in adc_grp0_in_store()
4166 struct rk3308_codec_priv *rk3308 = in adc_zerocross_show() local
4170 rk3308->adc_zerocross ? "enabled" : "disabled"); in adc_zerocross_show()
4177 struct rk3308_codec_priv *rk3308 = in adc_zerocross_store() local
4188 rk3308->adc_zerocross = zerocross; in adc_zerocross_store()
4190 dev_info(dev, "store adc zerocross: %d\n", rk3308->adc_zerocross); in adc_zerocross_store()
4199 struct rk3308_codec_priv *rk3308 = in adc_grps_endisable_show() local
4206 rk3308->adc_grps_endisable[i]); in adc_grps_endisable_show()
4216 struct rk3308_codec_priv *rk3308 = in adc_grps_endisable_store() local
4222 dev_err(rk3308->plat_dev, "%s sscanf failed: %d\n", in adc_grps_endisable_store()
4227 rk3308->cur_dbg_grp = grp; in adc_grps_endisable_store()
4230 rk3308_codec_open_dbg_capture(rk3308); in adc_grps_endisable_store()
4232 rk3308_codec_close_dbg_capture(rk3308); in adc_grps_endisable_store()
4243 struct rk3308_codec_priv *rk3308 = in dac_endisable_show() local
4246 return sprintf(buf, "%d\n", rk3308->dac_endisable); in dac_endisable_show()
4253 struct rk3308_codec_priv *rk3308 = in dac_endisable_store() local
4265 rk3308_codec_open_playback(rk3308); in dac_endisable_store()
4267 rk3308_codec_close_playback(rk3308); in dac_endisable_store()
4278 struct rk3308_codec_priv *rk3308 = in dac_output_show() local
4282 switch (rk3308->dac_output) { in dac_output_show()
4294 pr_err("Invalid dac path: %d ?\n", rk3308->dac_output); in dac_output_show()
4305 struct rk3308_codec_priv *rk3308 = in dac_output_store() local
4316 rk3308_codec_dac_switch(rk3308, dac_output); in dac_output_store()
4318 dev_info(dev, "Store dac_output: %d\n", rk3308->dac_output); in dac_output_store()
4327 struct rk3308_codec_priv *rk3308 = in enable_all_adcs_show() local
4330 return sprintf(buf, "%d\n", rk3308->enable_all_adcs); in enable_all_adcs_show()
4337 struct rk3308_codec_priv *rk3308 = in enable_all_adcs_store() local
4348 rk3308->enable_all_adcs = enable; in enable_all_adcs_store()
4371 struct rk3308_codec_priv *rk3308) in rk3308_codec_sysfs_init() argument
4373 struct device *dev = &rk3308->dev; in rk3308_codec_sysfs_init()
4379 dev_set_name(dev, "rk3308-acodec-dev"); in rk3308_codec_sysfs_init()
4383 "Register 'rk3308-acodec-dev' failed\n"); in rk3308_codec_sysfs_init()
4391 "Create 'rk3308-acodec-dev' attr failed\n"); in rk3308_codec_sysfs_init()
4400 static void rk3308_codec_sysfs_exit(struct rk3308_codec_priv *rk3308) in rk3308_codec_sysfs_exit() argument
4402 struct device *dev = &rk3308->dev; in rk3308_codec_sysfs_exit()
4413 struct rk3308_codec_priv *rk3308 = s->private; in rk3308_codec_debugfs_reg_show() local
4418 regmap_read(rk3308->regmap, i, &val); in rk3308_codec_debugfs_reg_show()
4433 struct rk3308_codec_priv *rk3308 = in rk3308_codec_debugfs_reg_operate() local
4455 regmap_write(rk3308->regmap, reg, val); in rk3308_codec_debugfs_reg_operate()
4456 regcache_cache_only(rk3308->regmap, false); in rk3308_codec_debugfs_reg_operate()
4457 regcache_sync(rk3308->regmap); in rk3308_codec_debugfs_reg_operate()
4460 regmap_read(rk3308->regmap, reg, &val); in rk3308_codec_debugfs_reg_operate()
4485 static int rk3308_codec_get_version(struct rk3308_codec_priv *rk3308) in rk3308_codec_get_version() argument
4489 regmap_read(rk3308->grf, GRF_CHIP_ID, &chip_id); in rk3308_codec_get_version()
4492 rk3308->codec_ver = ACODEC_VERSION_A; in rk3308_codec_get_version()
4495 rk3308->codec_ver = ACODEC_VERSION_B; in rk3308_codec_get_version()
4498 rk3308->codec_ver = ACODEC_VERSION_C; in rk3308_codec_get_version()
4505 pr_info("The acodec version is: %x\n", rk3308->codec_ver); in rk3308_codec_get_version()
4512 struct rk3308_codec_priv *rk3308; in rk3308_platform_probe() local
4517 rk3308 = devm_kzalloc(&pdev->dev, sizeof(*rk3308), GFP_KERNEL); in rk3308_platform_probe()
4518 if (!rk3308) in rk3308_platform_probe()
4521 rk3308->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf"); in rk3308_platform_probe()
4522 if (IS_ERR(rk3308->grf)) { in rk3308_platform_probe()
4525 return PTR_ERR(rk3308->grf); in rk3308_platform_probe()
4528 ret = rk3308_codec_get_version(rk3308); in rk3308_platform_probe()
4532 ret = rk3308_codec_sysfs_init(pdev, rk3308); in rk3308_platform_probe()
4539 rk3308->dbg_codec = debugfs_create_dir(CODEC_DRV_NAME, NULL); in rk3308_platform_probe()
4540 if (IS_ERR(rk3308->dbg_codec)) in rk3308_platform_probe()
4542 "Failed to create debugfs dir for rk3308!\n"); in rk3308_platform_probe()
4544 debugfs_create_file("reg", 0644, rk3308->dbg_codec, in rk3308_platform_probe()
4545 rk3308, &rk3308_codec_reg_debugfs_fops); in rk3308_platform_probe()
4547 rk3308->plat_dev = &pdev->dev; in rk3308_platform_probe()
4549 rk3308->reset = devm_reset_control_get(&pdev->dev, "acodec-reset"); in rk3308_platform_probe()
4550 if (IS_ERR(rk3308->reset)) { in rk3308_platform_probe()
4551 ret = PTR_ERR(rk3308->reset); in rk3308_platform_probe()
4556 rk3308->reset = NULL; in rk3308_platform_probe()
4559 rk3308->hp_ctl_gpio = devm_gpiod_get_optional(&pdev->dev, "hp-ctl", in rk3308_platform_probe()
4561 if (!rk3308->hp_ctl_gpio) { in rk3308_platform_probe()
4563 } else if (IS_ERR(rk3308->hp_ctl_gpio)) { in rk3308_platform_probe()
4564 ret = PTR_ERR(rk3308->hp_ctl_gpio); in rk3308_platform_probe()
4569 rk3308->spk_ctl_gpio = devm_gpiod_get_optional(&pdev->dev, "spk-ctl", in rk3308_platform_probe()
4572 if (!rk3308->spk_ctl_gpio) { in rk3308_platform_probe()
4574 } else if (IS_ERR(rk3308->spk_ctl_gpio)) { in rk3308_platform_probe()
4575 ret = PTR_ERR(rk3308->spk_ctl_gpio); in rk3308_platform_probe()
4580 rk3308->pa_drv_gpio = devm_gpiod_get_optional(&pdev->dev, "pa-drv", in rk3308_platform_probe()
4583 if (!rk3308->pa_drv_gpio) { in rk3308_platform_probe()
4585 } else if (IS_ERR(rk3308->pa_drv_gpio)) { in rk3308_platform_probe()
4586 ret = PTR_ERR(rk3308->pa_drv_gpio); in rk3308_platform_probe()
4591 if (rk3308->pa_drv_gpio) { in rk3308_platform_probe()
4592 rk3308->delay_pa_drv_ms = PA_DRV_MS; in rk3308_platform_probe()
4594 &rk3308->delay_pa_drv_ms); in rk3308_platform_probe()
4599 rk3308_headphone_ctl(rk3308, 1); in rk3308_platform_probe()
4600 rk3308_speaker_ctl(rk3308, 1); in rk3308_platform_probe()
4603 rk3308_headphone_ctl(rk3308, 0); in rk3308_platform_probe()
4604 rk3308_speaker_ctl(rk3308, 0); in rk3308_platform_probe()
4607 rk3308->pclk = devm_clk_get(&pdev->dev, "acodec"); in rk3308_platform_probe()
4608 if (IS_ERR(rk3308->pclk)) { in rk3308_platform_probe()
4610 ret = PTR_ERR(rk3308->pclk); in rk3308_platform_probe()
4614 rk3308->mclk_rx = devm_clk_get(&pdev->dev, "mclk_rx"); in rk3308_platform_probe()
4615 if (IS_ERR(rk3308->mclk_rx)) { in rk3308_platform_probe()
4617 ret = PTR_ERR(rk3308->mclk_rx); in rk3308_platform_probe()
4621 rk3308->mclk_tx = devm_clk_get(&pdev->dev, "mclk_tx"); in rk3308_platform_probe()
4622 if (IS_ERR(rk3308->mclk_tx)) { in rk3308_platform_probe()
4624 ret = PTR_ERR(rk3308->mclk_tx); in rk3308_platform_probe()
4628 ret = clk_prepare_enable(rk3308->pclk); in rk3308_platform_probe()
4634 ret = clk_prepare_enable(rk3308->mclk_rx); in rk3308_platform_probe()
4640 ret = clk_prepare_enable(rk3308->mclk_tx); in rk3308_platform_probe()
4646 rk3308_codec_check_micbias(rk3308, np); in rk3308_platform_probe()
4648 rk3308->enable_all_adcs = in rk3308_platform_probe()
4651 rk3308->hp_jack_reversed = in rk3308_platform_probe()
4654 rk3308->no_deep_low_power = in rk3308_platform_probe()
4657 rk3308->no_hp_det = in rk3308_platform_probe()
4660 rk3308->delay_loopback_handle_ms = LOOPBACK_HANDLE_MS; in rk3308_platform_probe()
4662 &rk3308->delay_loopback_handle_ms); in rk3308_platform_probe()
4664 rk3308->delay_start_play_ms = 0; in rk3308_platform_probe()
4666 &rk3308->delay_start_play_ms); in rk3308_platform_probe()
4668 rk3308->loopback_grp = NOT_USED; in rk3308_platform_probe()
4670 &rk3308->loopback_grp); in rk3308_platform_probe()
4681 ret = rk3308_codec_adc_grps_route(rk3308, np); in rk3308_platform_probe()
4688 ret = rk3308_codec_setup_en_always_adcs(rk3308, np); in rk3308_platform_probe()
4703 rk3308->regmap = devm_regmap_init_mmio(&pdev->dev, base, in rk3308_platform_probe()
4705 if (IS_ERR(rk3308->regmap)) { in rk3308_platform_probe()
4706 ret = PTR_ERR(rk3308->regmap); in rk3308_platform_probe()
4711 if (!rk3308->no_hp_det) { in rk3308_platform_probe()
4714 if (rk3308->codec_ver >= ACODEC_VERSION_B) in rk3308_platform_probe()
4717 rk3308->irq = platform_get_irq(pdev, index); in rk3308_platform_probe()
4718 if (rk3308->irq < 0) { in rk3308_platform_probe()
4723 INIT_DELAYED_WORK(&rk3308->hpdet_work, rk3308_codec_hpdetect_work); in rk3308_platform_probe()
4725 ret = devm_request_irq(&pdev->dev, rk3308->irq, in rk3308_platform_probe()
4729 rk3308); in rk3308_platform_probe()
4735 if (rk3308->codec_ver >= ACODEC_VERSION_B) { in rk3308_platform_probe()
4736 rk3308->detect_grf = in rk3308_platform_probe()
4738 if (IS_ERR(rk3308->detect_grf)) { in rk3308_platform_probe()
4741 ret = PTR_ERR(rk3308->detect_grf); in rk3308_platform_probe()
4746 regmap_write(rk3308->detect_grf, in rk3308_platform_probe()
4749 regmap_write(rk3308->detect_grf, in rk3308_platform_probe()
4756 if (rk3308->codec_ver == ACODEC_VERSION_A) in rk3308_platform_probe()
4757 INIT_DELAYED_WORK(&rk3308->loopback_work, in rk3308_platform_probe()
4760 rk3308->adc_grp0_using_linein = ADC_GRP0_MICIN; in rk3308_platform_probe()
4761 rk3308->dac_output = DAC_LINEOUT; in rk3308_platform_probe()
4762 rk3308->adc_zerocross = 0; in rk3308_platform_probe()
4763 rk3308->pm_state = PM_NORMAL; in rk3308_platform_probe()
4765 platform_set_drvdata(pdev, rk3308); in rk3308_platform_probe()
4777 clk_disable_unprepare(rk3308->mclk_tx); in rk3308_platform_probe()
4779 clk_disable_unprepare(rk3308->mclk_rx); in rk3308_platform_probe()
4781 clk_disable_unprepare(rk3308->pclk); in rk3308_platform_probe()
4783 rk3308_codec_sysfs_exit(rk3308); in rk3308_platform_probe()
4790 struct rk3308_codec_priv *rk3308 = in rk3308_platform_remove() local
4793 clk_disable_unprepare(rk3308->mclk_rx); in rk3308_platform_remove()
4794 clk_disable_unprepare(rk3308->mclk_tx); in rk3308_platform_remove()
4795 clk_disable_unprepare(rk3308->pclk); in rk3308_platform_remove()
4796 device_unregister(&rk3308->dev); in rk3308_platform_remove()
4802 { .compatible = "rockchip,rk3308-codec", },
4818 MODULE_DESCRIPTION("ASoC RK3308 Codec Driver");