aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-davinci.c
diff options
context:
space:
mode:
authorGrygorii Strashko <grygorii.strashko@ti.com>2014-09-12 10:54:00 -0400
committerMark Brown <broonie@kernel.org>2014-09-13 12:25:46 -0400
commit8936decdd977ee614234153a1aba85d12329fa7a (patch)
treefabcd93df3fb6f3f901e28abd529609f6eb7c4c1 /drivers/spi/spi-davinci.c
parent7d1311b93e58ed55f3a31cc8f94c4b8fe988a2b9 (diff)
spi: davinci: request cs_gpio's from probe
Now CS GPIOs are requested from struct spi_master.setup() callback and that causes failures when Client SPI device is getting accessed through SPIDEV driver. The failure happens, because .setup() callback may be called many times from IOCTL handler and when it's called second time gpio_request() will fail and return -EBUSY. Hence, fix it by moving CS GPIOs requesting code in .probe(). Reported-by: Murali Karicheri <m-karicheri2@ti.com> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-davinci.c')
-rw-r--r--drivers/spi/spi-davinci.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 276a3884fb3c..ff54f73dce4b 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -397,24 +397,21 @@ static int davinci_spi_setup(struct spi_device *spi)
397 struct spi_master *master = spi->master; 397 struct spi_master *master = spi->master;
398 struct device_node *np = spi->dev.of_node; 398 struct device_node *np = spi->dev.of_node;
399 bool internal_cs = true; 399 bool internal_cs = true;
400 unsigned long flags = GPIOF_DIR_OUT;
401 400
402 dspi = spi_master_get_devdata(spi->master); 401 dspi = spi_master_get_devdata(spi->master);
403 pdata = &dspi->pdata; 402 pdata = &dspi->pdata;
404 403
405 flags |= (spi->mode & SPI_CS_HIGH) ? GPIOF_INIT_LOW : GPIOF_INIT_HIGH;
406
407 if (!(spi->mode & SPI_NO_CS)) { 404 if (!(spi->mode & SPI_NO_CS)) {
408 if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) { 405 if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) {
409 retval = gpio_request_one(spi->cs_gpio, 406 retval = gpio_direction_output(
410 flags, dev_name(&spi->dev)); 407 spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
411 internal_cs = false; 408 internal_cs = false;
412 } else if (pdata->chip_sel && 409 } else if (pdata->chip_sel &&
413 spi->chip_select < pdata->num_chipselect && 410 spi->chip_select < pdata->num_chipselect &&
414 pdata->chip_sel[spi->chip_select] != SPI_INTERN_CS) { 411 pdata->chip_sel[spi->chip_select] != SPI_INTERN_CS) {
415 spi->cs_gpio = pdata->chip_sel[spi->chip_select]; 412 spi->cs_gpio = pdata->chip_sel[spi->chip_select];
416 retval = gpio_request_one(spi->cs_gpio, 413 retval = gpio_direction_output(
417 flags, dev_name(&spi->dev)); 414 spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
418 internal_cs = false; 415 internal_cs = false;
419 } 416 }
420 } 417 }
@@ -441,8 +438,6 @@ static int davinci_spi_setup(struct spi_device *spi)
441 438
442static void davinci_spi_cleanup(struct spi_device *spi) 439static void davinci_spi_cleanup(struct spi_device *spi)
443{ 440{
444 if (spi->cs_gpio >= 0)
445 gpio_free(spi->cs_gpio);
446} 441}
447 442
448static int davinci_spi_check_error(struct davinci_spi *dspi, int int_status) 443static int davinci_spi_check_error(struct davinci_spi *dspi, int int_status)
@@ -967,6 +962,27 @@ static int davinci_spi_probe(struct platform_device *pdev)
967 if (dspi->version == SPI_VERSION_2) 962 if (dspi->version == SPI_VERSION_2)
968 dspi->bitbang.flags |= SPI_READY; 963 dspi->bitbang.flags |= SPI_READY;
969 964
965 if (pdev->dev.of_node) {
966 int i;
967
968 for (i = 0; i < pdata->num_chipselect; i++) {
969 int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
970 "cs-gpios", i);
971
972 if (cs_gpio == -EPROBE_DEFER) {
973 ret = cs_gpio;
974 goto free_clk;
975 }
976
977 if (gpio_is_valid(cs_gpio)) {
978 ret = devm_gpio_request(&pdev->dev, cs_gpio,
979 dev_name(&pdev->dev));
980 if (ret)
981 goto free_clk;
982 }
983 }
984 }
985
970 r = platform_get_resource(pdev, IORESOURCE_DMA, 0); 986 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
971 if (r) 987 if (r)
972 dma_rx_chan = r->start; 988 dma_rx_chan = r->start;