[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1551862524-25098-2-git-send-email-fabrice.gasnier@st.com>
Date: Wed, 6 Mar 2019 09:55:17 +0100
From: Fabrice Gasnier <fabrice.gasnier@...com>
To: <jic23@...nel.org>
CC: <linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>, <mcoquelin.stm32@...il.com>,
<alexandre.torgue@...com>, <fabrice.gasnier@...com>,
<linux-iio@...r.kernel.org>, <lars@...afoo.de>, <knaack.h@....de>,
<pmeerw@...erw.net>, <linux-stm32@...md-mailman.stormreply.com>,
<arnaud.pouliquen@...com>, <olivier.moysan@...com>
Subject: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate
When SPI clock isn't accurate, 'spi_master_freq' is filled in with
expected frequency. Use computed value instead:
- e.g. source clock / (CKOUTDIV + 1)
Also, current divider may be set to value that makes CKOUT to exceed
spi-max-frequency. Rather use lower value (e.g. round up divider when
ckout isn't accurate).
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@...com>
---
drivers/iio/adc/stm32-dfsdm-core.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c
index bf089f5..65b7556 100644
--- a/drivers/iio/adc/stm32-dfsdm-core.c
+++ b/drivers/iio/adc/stm32-dfsdm-core.c
@@ -243,13 +243,18 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
return 0;
}
- priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem) - 1;
+ priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem);
+
+ /* round up divider when clkout isn't accurate (e.g. !rem) */
+ if (priv->spi_clk_out_div && !rem)
+ priv->spi_clk_out_div--;
+
if (!priv->spi_clk_out_div) {
/* spi_clk_out_div == 0 means ckout is OFF */
dev_err(&pdev->dev, "spi-max-frequency not achievable\n");
return -EINVAL;
}
- priv->dfsdm.spi_master_freq = spi_freq;
+ priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1);
if (rem) {
dev_warn(&pdev->dev, "SPI clock not accurate\n");
--
2.7.4
Powered by blists - more mailing lists