]> Git Repo - linux.git/blobdiff - drivers/spi/spi-gpio.c
regmap: mmio: Allow passing an empty config->reg_stride
[linux.git] / drivers / spi / spi-gpio.c
index 4b12c4964a6643bfef95fa02b815162b0811bcd0..092afc7679d4071edced902bbde9c32545820d4a 100644 (file)
@@ -230,7 +230,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
 
        /* Drive chip select line, if we have one */
        if (spi_gpio->cs_gpios) {
-               struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select];
+               struct gpio_desc *cs = spi_gpio->cs_gpios[spi_get_chipselect(spi, 0)];
 
                /* SPI chip selects are normally active-low */
                gpiod_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
@@ -248,7 +248,7 @@ static int spi_gpio_setup(struct spi_device *spi)
         * initialized from the descriptor lookup.
         */
        if (spi_gpio->cs_gpios) {
-               cs = spi_gpio->cs_gpios[spi->chip_select];
+               cs = spi_gpio->cs_gpios[spi_get_chipselect(spi, 0)];
                if (!spi->controller_state && cs)
                        status = gpiod_direction_output(cs,
                                                  !(spi->mode & SPI_CS_HIGH));
@@ -268,9 +268,19 @@ static int spi_gpio_set_direction(struct spi_device *spi, bool output)
        if (output)
                return gpiod_direction_output(spi_gpio->mosi, 1);
 
-       ret = gpiod_direction_input(spi_gpio->mosi);
-       if (ret)
-               return ret;
+       /*
+        * Only change MOSI to an input if using 3WIRE mode.
+        * Otherwise, MOSI could be left floating if there is
+        * no pull resistor connected to the I/O pin, or could
+        * be left logic high if there is a pull-up. Transmitting
+        * logic high when only clocking MISO data in can put some
+        * SPI devices in to a bad state.
+        */
+       if (spi->mode & SPI_3WIRE) {
+               ret = gpiod_direction_input(spi_gpio->mosi);
+               if (ret)
+                       return ret;
+       }
        /*
         * Send a turnaround high impedance cycle when switching
         * from output to input. Theoretically there should be
This page took 0.044502 seconds and 4 git commands to generate.