ASoC: amd: renoir: Add a module parameter to influence pdm_gain
authorMario Limonciello <mario.limonciello@amd.com>
Tue, 31 Jan 2023 18:46:50 +0000 (12:46 -0600)
committerMark Brown <broonie@kernel.org>
Thu, 2 Feb 2023 11:42:24 +0000 (11:42 +0000)
In case of regressions for any users that the new pdm_gain value is
too high and for additional debugging, introduce a module parameter
that would let them configure it.

This parameter should be removed in the future:
 * If it's determined that the parameter is not needed, just hardcode
   the correct value as before
 * If users do end up using it to debug and report different values
   we should introduce a config knob that can have policy set by ucm.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20230131184653.10216-5-mario.limonciello@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/amd/renoir/acp3x-pdm-dma.c
sound/soc/amd/renoir/rn_acp3x.h

index 7203c6488df0eb9d5a85a745e6bacb5f4391f2b9..0d8b693aecc9fd8ec39c769366e25daaaba4c138 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/platform_device.h>
 #include <linux/module.h>
+#include <linux/bitfield.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/pm_runtime.h>
 
 #define DRV_NAME "acp_rn_pdm_dma"
 
+static int pdm_gain = 3;
+module_param(pdm_gain, int, 0644);
+MODULE_PARM_DESC(pdm_gain, "Gain control (0-3)");
+
 static const struct snd_pcm_hardware acp_pdm_hardware_capture = {
        .info = SNDRV_PCM_INFO_INTERLEAVED |
                SNDRV_PCM_INFO_BLOCK_TRANSFER |
@@ -80,7 +85,8 @@ static void enable_pdm_clock(void __iomem *acp_base)
 
        rn_writel(pdm_clk_enable, acp_base + ACP_WOV_CLK_CTRL);
        pdm_ctrl = rn_readl(acp_base + ACP_WOV_MISC_CTRL);
-       pdm_ctrl |= ACP_WOV_MISC_CTRL_MASK;
+       pdm_ctrl &= ~ACP_WOV_GAIN_CONTROL;
+       pdm_ctrl |= FIELD_PREP(ACP_WOV_GAIN_CONTROL, clamp(pdm_gain, 0, 3));
        rn_writel(pdm_ctrl, acp_base + ACP_WOV_MISC_CTRL);
 }
 
index c174f84650d2471bb3183c57ee5eef8a5d1720bd..7d0f4e6a2834d7f43b25f99a1c3d4d3db5d11072 100644 (file)
@@ -34,7 +34,7 @@
 #define ACP_ERROR_STAT 29
 #define PDM_DECIMATION_FACTOR 0x2
 #define ACP_PDM_CLK_FREQ_MASK 0x07
-#define ACP_WOV_MISC_CTRL_MASK 0x18
+#define ACP_WOV_GAIN_CONTROL   GENMASK(4, 3)
 #define ACP_PDM_ENABLE 0x01
 #define ACP_PDM_DISABLE 0x00
 #define ACP_PDM_DMA_EN_STATUS 0x02