iio: adc: stm32-dfsdm: add check on spi-max-frequency
authorFabrice Gasnier <fabrice.gasnier@st.com>
Fri, 23 Feb 2018 12:51:01 +0000 (13:51 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 28 Apr 2018 15:17:59 +0000 (16:17 +0100)
spi-max-frequency is requested for SPI master mode (only), to tune output
clock. It may happen requested frequency isn't reachable.
Add explicit check, so probe fails with error in this case. Otherwise,
output clock may simply be silently turned off (conversions fail).

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/stm32-dfsdm-core.c

index 6290332cfd3f8a7654d6f68cc13024540031a5c7..540d42cf6f4cefbe737d01da9db0eba7b0c7439b 100644 (file)
@@ -219,6 +219,11 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
        }
 
        priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem) - 1;
+       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;
 
        if (rem) {