spi: Setup the master controller driver before setting the chipselect
authorFranklin S Cooper Jr <fcooper@ti.com>
Fri, 16 Oct 2015 15:29:03 +0000 (10:29 -0500)
committerMark Brown <broonie@kernel.org>
Wed, 28 Oct 2015 00:34:18 +0000 (09:34 +0900)
SPI controllers may need to be properly setup before chip selects
can be used. Therefore, wait until the spi controller has a chance
to perform their setup procedure before trying to use the chip
select.

This also insures that the chip selects pins are in a good
state before asseting them which otherwise may cause confusion.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
Tested-by: Grygorii Strashko <grygorii.strashko@ti.com>
Tested-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c

index 3abb3903f2ad454ef964299204bd3c2454890062..7b528b0aedb935cb0b8a5983bea5ff0cc683aed3 100644 (file)
@@ -1993,11 +1993,11 @@ int spi_setup(struct spi_device *spi)
        if (!spi->max_speed_hz)
                spi->max_speed_hz = spi->master->max_speed_hz;
 
-       spi_set_cs(spi, false);
-
        if (spi->master->setup)
                status = spi->master->setup(spi);
 
+       spi_set_cs(spi, false);
+
        dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n",
                        (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),
                        (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",