[PATCH 2/2] spi: img-spfi: fix spfi_setup by removing gpio_request_one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



spfi_setup may be called many times bye the spi framework, but
gpio_request_one can only be called once without freeing, repeatedly
calling gpio_request_one will cause an error to be thrown, which causes
the request to spi_setup to be marked as failed.

We can simply use gpio_direction_output to set the direction of the
gpio instead of gpio_request_one to put the gpio in to initial state,
after which the spi framework can control the chipselect line via gpio
using gpio_set_value.

Fixes: 8c2c8c0 ("spi: img-spfi: Control CS lines with GPIO")
Signed-off-by: Sifan Naeem <sifan.naeem@xxxxxxxxxx>
Cc: Stable kernel (v4.1) <stable@xxxxxxxxxxxxxxx>
---
 drivers/spi/spi-img-spfi.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c
index f27d9d5..a7f3d6a 100644
--- a/drivers/spi/spi-img-spfi.c
+++ b/drivers/spi/spi-img-spfi.c
@@ -442,13 +442,15 @@ static int img_spfi_setup(struct spi_device *spi)
 {
 	int ret;
 
-	ret = gpio_request_one(spi->cs_gpio, (spi->mode & SPI_CS_HIGH) ?
-			       GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
-			       dev_name(&spi->dev));
-	if (ret)
-		dev_err(&spi->dev, "can't request chipselect gpio %d\n",
-				spi->cs_gpio);
-
+	if (gpio_is_valid(spi->cs_gpio)) {
+		int mode = ((spi->mode & SPI_CS_HIGH) ?
+			     GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
+
+		ret = gpio_direction_output(spi->cs_gpio, mode);
+		if (ret)
+			dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
+				spi->cs_gpio, ret);
+	}
 	return ret;
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]