From 10b63561fcd8a9eccc93fc8a6d66f11ba8bef8ee Mon Sep 17 00:00:00 2001 From: Sugar Zhang Date: Wed, 12 Oct 2022 11:42:17 +0800 Subject: [PATCH] ASoC: rockchip: pdm: Allow mclk shift around 1 ppm This patch allow mclk shift around +/- 1ppm compared to requested freq. we could not always achieve the precise freq as required, e.g. request: 98304000, but got: 98303999 there is no big deal and any side effect on the above case, so, we allow a tiny shift for mclk. Signed-off-by: Sugar Zhang Change-Id: I8da91e467cfc0306fa9069ab30079d5ddf1c0336 --- sound/soc/rockchip/rockchip_pdm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound/soc/rockchip/rockchip_pdm.c b/sound/soc/rockchip/rockchip_pdm.c index f4719f271793..83a05fdb5976 100644 --- a/sound/soc/rockchip/rockchip_pdm.c +++ b/sound/soc/rockchip/rockchip_pdm.c @@ -28,6 +28,7 @@ #define PDM_START_DELAY_MS_MAX (1000) #define PDM_FILTER_DELAY_MS_MIN (20) #define PDM_FILTER_DELAY_MS_MAX (1000) +#define PDM_CLK_SHIFT_PPM_MAX (1000000) /* 1 ppm */ enum rk_pdm_version { RK_PDM_RK3229, @@ -89,7 +90,7 @@ static unsigned int get_pdm_clk(struct rk_pdm_dev *pdm, unsigned int sr, unsigned int *clk_src, unsigned int *clk_out, unsigned int signoff) { - unsigned int i, count, clk, div, rate; + unsigned int i, count, clk, div, rate, delta; clk = 0; if (!sr) @@ -103,7 +104,9 @@ static unsigned int get_pdm_clk(struct rk_pdm_dev *pdm, unsigned int sr, if ((div & (div - 1)) == 0) { *clk_out = clkref[i].clk_out; rate = clk_round_rate(pdm->clk, clkref[i].clk); - if (rate != clkref[i].clk) + delta = clkref[i].clk / PDM_CLK_SHIFT_PPM_MAX; + if (rate < clkref[i].clk - delta || + rate > clkref[i].clk + delta) continue; clk = clkref[i].clk; *clk_src = clkref[i].clk;