summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-cadence.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2019-01-07 10:51:53 -0500
committerMark Brown <broonie@kernel.org>2019-01-09 07:41:45 -0500
commitcfeefa79dc37d378216e2ced1600e297dd04e591 (patch)
treefe0e541905e9ee3e081d6c90d5a2e19c3ce3766c /drivers/spi/spi-cadence.c
parentefc92fbb876014c8efa4d90f4ac4b49569f0a84e (diff)
spi: cadence: Convert to use CS GPIO descriptors
This converts the Cadence SPI master driver to use GPIO descriptors for chip select handling. The Cadence driver was allocating a state container just to hold the requested GPIO line and contained lots of polarity inversion code. As this is all handled by gpiolib and a simple devm_* request in the core, and as the driver is fully device tree only, most of this code chunk goes away in favour of central handling. The setup/cleanup callbacks goes away. This driver does NOT drive the CS line by setting the value of the GPIO so it relies on the SPI core to do this, which should work just fine with the descriptors. Cc: Wei Yongjun <weiyongjun1@huawei.com> Cc: Janek Kotas <jank@cadence.com> Cc: Linuxarm <linuxarm@huawei.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-cadence.c')
-rw-r--r--drivers/spi/spi-cadence.c67
1 files changed, 2 insertions, 65 deletions
diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index 7c88f74f7f47..e332d173dbf9 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -13,7 +13,7 @@
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gpio.h> 16#include <linux/gpio/consumer.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/module.h> 19#include <linux/module.h>
@@ -128,10 +128,6 @@ struct cdns_spi {
128 u32 is_decoded_cs; 128 u32 is_decoded_cs;
129}; 129};
130 130
131struct cdns_spi_device_data {
132 bool gpio_requested;
133};
134
135/* Macros for the SPI controller read/write */ 131/* Macros for the SPI controller read/write */
136static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) 132static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset)
137{ 133{
@@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master)
469 return 0; 465 return 0;
470} 466}
471 467
472static int cdns_spi_setup(struct spi_device *spi)
473{
474
475 int ret = -EINVAL;
476 struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
477
478 /* this is a pin managed by the controller, leave it alone */
479 if (spi->cs_gpio == -ENOENT)
480 return 0;
481
482 /* this seems to be the first time we're here */
483 if (!cdns_spi_data) {
484 cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL);
485 if (!cdns_spi_data)
486 return -ENOMEM;
487 cdns_spi_data->gpio_requested = false;
488 spi_set_ctldata(spi, cdns_spi_data);
489 }
490
491 /* if we haven't done so, grab the gpio */
492 if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) {
493 ret = gpio_request_one(spi->cs_gpio,
494 (spi->mode & SPI_CS_HIGH) ?
495 GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
496 dev_name(&spi->dev));
497 if (ret)
498 dev_err(&spi->dev, "can't request chipselect gpio %d\n",
499 spi->cs_gpio);
500 else
501 cdns_spi_data->gpio_requested = true;
502 } else {
503 if (gpio_is_valid(spi->cs_gpio)) {
504 int mode = ((spi->mode & SPI_CS_HIGH) ?
505 GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
506
507 ret = gpio_direction_output(spi->cs_gpio, mode);
508 if (ret)
509 dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
510 spi->cs_gpio, ret);
511 }
512 }
513
514 return ret;
515}
516
517static void cdns_spi_cleanup(struct spi_device *spi)
518{
519 struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
520
521 if (cdns_spi_data) {
522 if (cdns_spi_data->gpio_requested)
523 gpio_free(spi->cs_gpio);
524 kfree(cdns_spi_data);
525 spi_set_ctldata(spi, NULL);
526 }
527
528}
529
530/** 468/**
531 * cdns_spi_probe - Probe method for the SPI driver 469 * cdns_spi_probe - Probe method for the SPI driver
532 * @pdev: Pointer to the platform_device structure 470 * @pdev: Pointer to the platform_device structure
@@ -621,13 +559,12 @@ static int cdns_spi_probe(struct platform_device *pdev)
621 goto clk_dis_all; 559 goto clk_dis_all;
622 } 560 }
623 561
562 master->use_gpio_descriptors = true;
624 master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; 563 master->prepare_transfer_hardware = cdns_prepare_transfer_hardware;
625 master->prepare_message = cdns_prepare_message; 564 master->prepare_message = cdns_prepare_message;
626 master->transfer_one = cdns_transfer_one; 565 master->transfer_one = cdns_transfer_one;
627 master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; 566 master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware;
628 master->set_cs = cdns_spi_chipselect; 567 master->set_cs = cdns_spi_chipselect;
629 master->setup = cdns_spi_setup;
630 master->cleanup = cdns_spi_cleanup;
631 master->auto_runtime_pm = true; 568 master->auto_runtime_pm = true;
632 master->mode_bits = SPI_CPOL | SPI_CPHA; 569 master->mode_bits = SPI_CPOL | SPI_CPHA;
633 570