[PATCH] spi: omap2-mcspi: Prevent duplicate gpio_request

2015-11-30 Thread Michael Welling
Occasionally the setup function will be called multiple times. Only request
the gpio the first time otherwise -EBUSY will occur on subsequent calls to
setup.

Reported-by: Joseph Bell 

Signed-off-by: Michael Welling 
---
 drivers/spi/spi-omap2-mcspi.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 02aa1d0..7273820 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -1025,6 +1025,16 @@ static int omap2_mcspi_setup(struct spi_device *spi)
spi->controller_state = cs;
/* Link this to context save list */
list_add_tail(>node, >cs);
+
+   if (gpio_is_valid(spi->cs_gpio)) {
+   ret = gpio_request(spi->cs_gpio, dev_name(>dev));
+   if (ret) {
+   dev_err(>dev, "failed to request gpio\n");
+   return ret;
+   }
+   gpio_direction_output(spi->cs_gpio,
+!(spi->mode & SPI_CS_HIGH));
+   }
}
 
if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) {
@@ -1033,15 +1043,6 @@ static int omap2_mcspi_setup(struct spi_device *spi)
return ret;
}
 
-   if (gpio_is_valid(spi->cs_gpio)) {
-   ret = gpio_request(spi->cs_gpio, dev_name(>dev));
-   if (ret) {
-   dev_err(>dev, "failed to request gpio\n");
-   return ret;
-   }
-   gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
-   }
-
ret = pm_runtime_get_sync(mcspi->dev);
if (ret < 0)
return ret;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] spi: omap2-mcspi: Prevent duplicate gpio_request

2015-11-30 Thread Michael Welling
Occasionally the setup function will be called multiple times. Only request
the gpio the first time otherwise -EBUSY will occur on subsequent calls to
setup.

Reported-by: Joseph Bell 

Signed-off-by: Michael Welling 
---
 drivers/spi/spi-omap2-mcspi.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 02aa1d0..7273820 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -1025,6 +1025,16 @@ static int omap2_mcspi_setup(struct spi_device *spi)
spi->controller_state = cs;
/* Link this to context save list */
list_add_tail(>node, >cs);
+
+   if (gpio_is_valid(spi->cs_gpio)) {
+   ret = gpio_request(spi->cs_gpio, dev_name(>dev));
+   if (ret) {
+   dev_err(>dev, "failed to request gpio\n");
+   return ret;
+   }
+   gpio_direction_output(spi->cs_gpio,
+!(spi->mode & SPI_CS_HIGH));
+   }
}
 
if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) {
@@ -1033,15 +1043,6 @@ static int omap2_mcspi_setup(struct spi_device *spi)
return ret;
}
 
-   if (gpio_is_valid(spi->cs_gpio)) {
-   ret = gpio_request(spi->cs_gpio, dev_name(>dev));
-   if (ret) {
-   dev_err(>dev, "failed to request gpio\n");
-   return ret;
-   }
-   gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
-   }
-
ret = pm_runtime_get_sync(mcspi->dev);
if (ret < 0)
return ret;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/