Merge branch 'asoc-4.19' into asoc-4.20 for rt5682 deps.
[platform/kernel/linux-starfive.git] / sound / soc / codecs / rt5682.c
index 731c6a8..7213b1c 100644 (file)
@@ -749,7 +749,6 @@ static bool rt5682_readable_register(struct device *dev, unsigned int reg)
        }
 }
 
-static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -2250, 150, 0);
 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
@@ -1108,10 +1107,6 @@ static void rt5682_jack_detect_handler(struct work_struct *work)
 }
 
 static const struct snd_kcontrol_new rt5682_snd_controls[] = {
-       /* Headphone Output Volume */
-       SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5682_HPL_GAIN,
-               RT5682_HPR_GAIN, RT5682_G_HP_SFT, 15, 1, hp_vol_tlv),
-
        /* DAC Digital Volume */
        SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5682_DAC1_DIG_VOL,
                RT5682_L_VOL_SFT + 1, RT5682_R_VOL_SFT + 1, 86, 0, dac_vol_tlv),
@@ -1437,6 +1432,28 @@ static const struct snd_kcontrol_new hpor_switch =
        SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5682_HP_CTRL_1,
                                        RT5682_R_MUTE_SFT, 1, 1);
 
+static int rt5682_charge_pump_event(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_component *component =
+               snd_soc_dapm_to_component(w->dapm);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               snd_soc_component_update_bits(component,
+                       RT5682_HP_CHARGE_PUMP_1, RT5682_PM_HP_MASK, RT5682_PM_HP_HV);
+               break;
+       case SND_SOC_DAPM_POST_PMD:
+               snd_soc_component_update_bits(component,
+                       RT5682_HP_CHARGE_PUMP_1, RT5682_PM_HP_MASK, RT5682_PM_HP_LV);
+               break;
+       default:
+               return 0;
+       }
+
+       return 0;
+}
+
 static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
        struct snd_kcontrol *kcontrol, int event)
 {
@@ -1449,8 +1466,6 @@ static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
                        RT5682_HP_LOGIC_CTRL_2, 0x0012);
                snd_soc_component_write(component,
                        RT5682_HP_CTRL_2, 0x6000);
-               snd_soc_component_update_bits(component, RT5682_STO_NG2_CTRL_1,
-                       RT5682_NG2_EN_MASK, RT5682_NG2_EN);
                snd_soc_component_update_bits(component,
                        RT5682_DEPOP_1, 0x60, 0x60);
                break;
@@ -1723,7 +1738,8 @@ static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] = {
        SND_SOC_DAPM_SUPPLY("HP Amp R", RT5682_PWR_ANLG_1,
                RT5682_PWR_HA_R_BIT, 0, NULL, 0),
        SND_SOC_DAPM_SUPPLY_S("Charge Pump", 1, RT5682_DEPOP_1,
-               RT5682_PUMP_EN_SFT, 0, NULL, 0),
+               RT5682_PUMP_EN_SFT, 0, rt5682_charge_pump_event,
+               SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
        SND_SOC_DAPM_SUPPLY_S("Capless", 2, RT5682_DEPOP_1,
                RT5682_CAPLESS_EN_SFT, 0, NULL, 0),
 
@@ -1884,6 +1900,7 @@ static const struct snd_soc_dapm_route rt5682_dapm_routes[] = {
        {"HP Amp", NULL, "Charge Pump"},
        {"HP Amp", NULL, "CLKDET SYS"},
        {"HP Amp", NULL, "CBJ Power"},
+       {"HP Amp", NULL, "Vref1"},
        {"HP Amp", NULL, "Vref2"},
        {"HPOL Playback", "Switch", "HP Amp"},
        {"HPOR Playback", "Switch", "HP Amp"},
@@ -2607,6 +2624,10 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
                        RT5682_GP4_PIN_MASK | RT5682_GP5_PIN_MASK,
                        RT5682_GP4_PIN_ADCDAT1 | RT5682_GP5_PIN_DACDAT1);
        regmap_write(rt5682->regmap, RT5682_TEST_MODE_CTRL_1, 0x0000);
+       regmap_update_bits(rt5682->regmap, RT5682_BIAS_CUR_CTRL_8,
+                       RT5682_HPA_CP_BIAS_CTRL_MASK, RT5682_HPA_CP_BIAS_3UA);
+       regmap_update_bits(rt5682->regmap, RT5682_CHARGE_PUMP_1,
+                       RT5682_CP_CLK_HP_MASK, RT5682_CP_CLK_HP_300KHZ);
 
        INIT_DELAYED_WORK(&rt5682->jack_detect_work,
                                rt5682_jack_detect_handler);