spi: atmel: Fix scheduling while atomic
authorBen Whitten <ben.whitten@gmail.com>
Mon, 14 Nov 2016 15:13:20 +0000 (15:13 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 15 Nov 2016 18:51:35 +0000 (18:51 +0000)
A call to clk_get_rate appears to be called in the context of an interrupt,
cache the bus clock for the frequency calculations in transmission.

This fixes a 'BUG: scheduling while atomic' and
'WARNING: CPU: 0 PID: 777 at kernel/sched/core.c:2960 atmel_spi_unlock'

Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
Signed-off-by: Steve deRosier <steve.derosier@lairdtech.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-atmel.c

index d3affa6afe7ec13e3fed4a7df5ac00a0bb6083e3..9fb00ac3ac2ef023820df542bb4c1d70376dd547 100644 (file)
@@ -296,6 +296,7 @@ struct atmel_spi {
        int                     irq;
        struct clk              *clk;
        struct platform_device  *pdev;
+       unsigned long           spi_clk;
 
        struct spi_transfer     *current_transfer;
        int                     current_remaining_bytes;
@@ -865,7 +866,7 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
        unsigned long           bus_hz;
 
        /* v1 chips start out at half the peripheral bus speed. */
-       bus_hz = clk_get_rate(as->clk);
+       bus_hz = as->spi_clk;
        if (!atmel_spi_is_v2(as))
                bus_hz /= 2;
 
@@ -1634,6 +1635,9 @@ static int atmel_spi_probe(struct platform_device *pdev)
        ret = clk_prepare_enable(clk);
        if (ret)
                goto out_free_irq;
+
+       as->spi_clk = clk_get_rate(clk);
+
        spi_writel(as, CR, SPI_BIT(SWRST));
        spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
        if (as->caps.has_wdrbt) {