aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-davinci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-davinci.c')
-rw-r--r--drivers/spi/spi-davinci.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 48f1d26e6ad9..134fb6eb7b19 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
@@ -439,12 +436,6 @@ static int davinci_spi_setup(struct spi_device *spi)
439 return retval; 436 return retval;
440} 437}
441 438
442static void davinci_spi_cleanup(struct spi_device *spi)
443{
444 if (spi->cs_gpio >= 0)
445 gpio_free(spi->cs_gpio);
446}
447
448static int davinci_spi_check_error(struct davinci_spi *dspi, int int_status) 439static int davinci_spi_check_error(struct davinci_spi *dspi, int int_status)
449{ 440{
450 struct device *sdev = dspi->bitbang.master->dev.parent; 441 struct device *sdev = dspi->bitbang.master->dev.parent;
@@ -956,7 +947,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
956 master->num_chipselect = pdata->num_chipselect; 947 master->num_chipselect = pdata->num_chipselect;
957 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(2, 16); 948 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(2, 16);
958 master->setup = davinci_spi_setup; 949 master->setup = davinci_spi_setup;
959 master->cleanup = davinci_spi_cleanup;
960 950
961 dspi->bitbang.chipselect = davinci_spi_chipselect; 951 dspi->bitbang.chipselect = davinci_spi_chipselect;
962 dspi->bitbang.setup_transfer = davinci_spi_setup_transfer; 952 dspi->bitbang.setup_transfer = davinci_spi_setup_transfer;
@@ -967,6 +957,27 @@ static int davinci_spi_probe(struct platform_device *pdev)
967 if (dspi->version == SPI_VERSION_2) 957 if (dspi->version == SPI_VERSION_2)
968 dspi->bitbang.flags |= SPI_READY; 958 dspi->bitbang.flags |= SPI_READY;
969 959
960 if (pdev->dev.of_node) {
961 int i;
962
963 for (i = 0; i < pdata->num_chipselect; i++) {
964 int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
965 "cs-gpios", i);
966
967 if (cs_gpio == -EPROBE_DEFER) {
968 ret = cs_gpio;
969 goto free_clk;
970 }
971
972 if (gpio_is_valid(cs_gpio)) {
973 ret = devm_gpio_request(&pdev->dev, cs_gpio,
974 dev_name(&pdev->dev));
975 if (ret)
976 goto free_clk;
977 }
978 }
979 }
980
970 r = platform_get_resource(pdev, IORESOURCE_DMA, 0); 981 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
971 if (r) 982 if (r)
972 dma_rx_chan = r->start; 983 dma_rx_chan = r->start;