ASoC: rt1011: Add a flag for the R0 calibration test
authorShuming Fan <shumingf@realtek.com>
Tue, 6 Aug 2019 09:14:59 +0000 (17:14 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 7 Aug 2019 13:19:13 +0000 (14:19 +0100)
The factory test needs to know whether the calibration completed.
This flag helps to confirm the calibration completed or not.

Signed-off-by: Shuming Fan <shumingf@realtek.com>
Link: https://lore.kernel.org/r/20190806091459.14382-1-shumingf@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt1011.c
sound/soc/codecs/rt1011.h

index b25b4c1127ca548808dccf698f5d805e8fccf735..638abcaf52b3ecaa53ead49d5b2a4fdd445d1f28 100644 (file)
@@ -1225,7 +1225,10 @@ static int rt1011_bq_drc_info(struct snd_kcontrol *kcontrol,
 static int rt1011_r0_cali_get(struct snd_kcontrol *kcontrol,
                struct snd_ctl_elem_value *ucontrol)
 {
-       ucontrol->value.integer.value[0] = 0;
+       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+       struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
+
+       ucontrol->value.integer.value[0] = rt1011->cali_done;
 
        return 0;
 }
@@ -1239,6 +1242,7 @@ static int rt1011_r0_cali_put(struct snd_kcontrol *kcontrol,
        if (!component->card->instantiated)
                return 0;
 
+       rt1011->cali_done = 0;
        if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF &&
                ucontrol->value.integer.value[0])
                rt1011_calibrate(rt1011, 1);
@@ -2135,6 +2139,7 @@ static int rt1011_calibrate(struct rt1011_priv *rt1011, unsigned char cali_flag)
                        r0_factor = ((format / r0[0] * 100) / 128)
                                                        - (r0_integer * 100);
                        rt1011->r0_reg = r0[0];
+                       rt1011->cali_done = 1;
                        dev_info(dev,   "r0 resistance about %d.%02d ohm, reg=0x%X\n",
                                r0_integer, r0_factor, r0[0]);
                }
@@ -2185,6 +2190,13 @@ static void rt1011_calibration_work(struct work_struct *work)
 
        rt1011_calibrate(rt1011, 1);
 
+       /*
+        * This flag should reset after booting.
+        * The factory test will do calibration again and use this flag to check
+        * whether the calibration completed
+        */
+       rt1011->cali_done = 0;
+
        /* initial */
        rt1011_reg_init(component);
 }
index 5d431d7f1d16700f2c5401cac6052f18f8a4edf3..2d65983f3d0f73958c26b49c3480e639bf178cb2 100644 (file)
@@ -666,7 +666,7 @@ struct rt1011_priv {
        int pll_out;
 
        int bq_drc_set;
-       unsigned int r0_reg;
+       unsigned int r0_reg, cali_done;
        int recv_spk_mode;
 };