aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;