sound:wm8960:pdm:Fix some noise with first capture
authorXingyu Wu <xingyu.wu@starfivetech.com>
Tue, 6 Sep 2022 14:04:49 +0000 (22:04 +0800)
committerXingyu Wu <xingyu.wu@starfivetech.com>
Tue, 6 Sep 2022 14:05:51 +0000 (22:05 +0800)
Use delay to fix some noise with first capture.

Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
sound/soc/codecs/wm8960.c
sound/soc/starfive/starfive_pdm.c [changed mode: 0644->0755]

index fbcf9e7..22e0a44 100755 (executable)
@@ -137,6 +137,8 @@ struct wm8960_priv {
        bool is_stream_in_use[2];
        struct wm8960_data pdata;
        struct dentry *debug_file;
+       bool first_capture;
+       bool is_capture;
 };
 
 #define wm8960_reset(c)        regmap_write(c, WM8960_RESET, 0)
@@ -822,6 +824,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
        u16 word_length = 0;
        int ret;
 
+       wm8960->is_capture = substream->stream == SNDRV_PCM_STREAM_CAPTURE;
        wm8960->bclk = snd_soc_params_to_bclk(params);
        if (params_channels(params) == 1)
                wm8960->bclk *= 2;
@@ -1002,6 +1005,10 @@ static int wm8960_set_bias_level_out3(struct snd_soc_component *component,
 
        switch (level) {
        case SND_SOC_BIAS_ON:
+               if (wm8960->first_capture && wm8960->is_capture) {
+                       msleep(800);
+                       wm8960->first_capture = false;
+               }
                break;
 
        case SND_SOC_BIAS_PREPARE:
@@ -1594,6 +1601,8 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
                }
        }
 
+       wm8960->first_capture = true;
+
        /* Latch the update bits */
        regmap_update_bits(wm8960->regmap, WM8960_LINVOL, 0x100, 0x100);
        regmap_update_bits(wm8960->regmap, WM8960_RINVOL, 0x100, 0x100);
old mode 100644 (file)
new mode 100755 (executable)
index 64d98b9..060576b
@@ -29,6 +29,7 @@ struct sf_pdm {
        struct clk *clk_mclk_out;
        struct reset_control *rst_pdm_dmic;
        struct reset_control *rst_pdm_apb;
+       unsigned char flag_first;
 };
 
 static const DECLARE_TLV_DB_SCALE(volume_tlv, -9450, 150, 0);
@@ -69,6 +70,10 @@ static int sf_pdm_trigger(struct snd_pcm_substream *substream, int cmd,
        case SNDRV_PCM_TRIGGER_START:
        case SNDRV_PCM_TRIGGER_RESUME:
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               if (priv->flag_first) {
+                       priv->flag_first = 0;
+                       mdelay(200);
+               }
                sf_pdm_enable(priv->pdm_map);
                return 0;
 
@@ -398,6 +403,7 @@ static int sf_pdm_probe(struct platform_device *pdev)
        }
 
        priv->dev = &pdev->dev;
+       priv->flag_first = 1;
 
        ret = sf_pdm_clock_init(pdev, priv);
        if (ret) {