mbox series

[0/7,v1] SPI CS using GPIO descriptors

Message ID 20181215233823.1042-1-linus.walleij@linaro.org
Headers show
Series SPI CS using GPIO descriptors | expand

Message

Linus Walleij Dec. 15, 2018, 11:38 p.m. UTC
This is a first version of trying to pull GPIO descriptor
handling of SPI chip selects into the SPI core.

The core grows a bit, bit handles descriptors in addition
to the already handled DT and static GPIO lines, and then
I start converting over some drivers to show the utility
of pulling this into the core.

There are *many* drivers to convert.

This should also cover the ACPI usecase by way of the
completely generic GPIO descriptor handling code that
simply picks the GPIO "cs" descriptors associated with
the device.

Linus Walleij (7):
  spi: Optionally use GPIO descriptors for CS GPIOs
  spi: ath79: Convert to use CS GPIO descriptors
  spi: atmel: Convert to use CS GPIO descriptors
  spi: cadence: Convert to use CS GPIO descriptors
  spi: clps711x: Convert to use CS GPIO descriptors
  spi: davinci: Convert to use CS GPIO descriptors
  spi: dw: Convert to use CS GPIO descriptors

 drivers/spi/spi-ath79.c    |  42 +++++----------
 drivers/spi/spi-atmel.c    |  93 ++++++++++----------------------
 drivers/spi/spi-cadence.c  |  67 +----------------------
 drivers/spi/spi-clps711x.c |  23 +-------
 drivers/spi/spi-davinci.c  |  53 +++++--------------
 drivers/spi/spi-dw-mmio.c  |  22 --------
 drivers/spi/spi-dw.c       |   9 +---
 drivers/spi/spi.c          | 105 +++++++++++++++++++++++++++++++++----
 include/linux/spi/spi.h    |  23 ++++++--
 9 files changed, 173 insertions(+), 264 deletions(-)

-- 
2.19.2

Comments

Jay Fang Dec. 18, 2018, 6:23 a.m. UTC | #1
On 2018/12/16 7:38, Linus Walleij wrote:
> This converts the DesignWare (dw) SPI master driver to

> use GPIO descriptors for chip select handling.

> 

> This driver has a duplicate DT parser in addition to the

> one in the core, sets up the line as non-asserted and

> relies on the core to drive the GPIOs.

> 

> It is a pretty straight-forward conversion.

> 

> Cc: Talel Shenhar <talel@amazon.com>

> Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>

> Cc: Linuxarm <linuxarm@huawei.com>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

> ---

>  drivers/spi/spi-dw-mmio.c | 22 ----------------------

>  drivers/spi/spi-dw.c      |  9 +--------

>  2 files changed, 1 insertion(+), 30 deletions(-)

> 

> diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c

> index 3ffb6a40fe0c..00a43c19f2a4 100644

> --- a/drivers/spi/spi-dw-mmio.c

> +++ b/drivers/spi/spi-dw-mmio.c

> @@ -18,7 +18,6 @@

>  #include <linux/mfd/syscon.h>

>  #include <linux/module.h>

>  #include <linux/of.h>

> -#include <linux/of_gpio.h>

>  #include <linux/of_platform.h>

>  #include <linux/property.h>

>  #include <linux/regmap.h>

> @@ -184,27 +183,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)

>  

>  	dws->num_cs = num_cs;

>  

> -	if (pdev->dev.of_node) {

> -		int i;

> -

> -		for (i = 0; i < dws->num_cs; i++) {

> -			int cs_gpio = of_get_named_gpio(pdev->dev.of_node,

> -					"cs-gpios", i);

> -

> -			if (cs_gpio == -EPROBE_DEFER) {

> -				ret = cs_gpio;

> -				goto out;

> -			}

> -

> -			if (gpio_is_valid(cs_gpio)) {

> -				ret = devm_gpio_request(&pdev->dev, cs_gpio,

> -						dev_name(&pdev->dev));

> -				if (ret)

> -					goto out;

> -			}

> -		}

> -	}

> -

>  	init_func = device_get_match_data(&pdev->dev);

>  	if (init_func) {

>  		ret = init_func(pdev, dwsmmio);

> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c

> index b705f2bdb8b9..22a7998dbc08 100644

> --- a/drivers/spi/spi-dw.c

> +++ b/drivers/spi/spi-dw.c

> @@ -20,7 +20,6 @@

>  #include <linux/delay.h>

>  #include <linux/slab.h>

>  #include <linux/spi/spi.h>

> -#include <linux/gpio.h>

>  

>  #include "spi-dw.h"

>  

> @@ -425,13 +424,6 @@ static int dw_spi_setup(struct spi_device *spi)

>  

>  	chip->tmode = SPI_TMOD_TR;

>  

> -	if (gpio_is_valid(spi->cs_gpio)) {

> -		ret = gpio_direction_output(spi->cs_gpio,

> -				!(spi->mode & SPI_CS_HIGH));

> -		if (ret)

> -			return ret;

> -	}

> -

>  	return 0;

>  }

>  

> @@ -496,6 +488,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)

>  		goto err_free_master;

>  	}

>  

> +	master->use_gpio_descriptors = true;

>  	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;

>  	master->bits_per_word_mask =  SPI_BPW_RANGE_MASK(4, 16);

>  	master->bus_num = dws->bus_num;

> 


Hi, Linus
for spi-dw-mmio(ACPI):

Tested-by: Jay Fang <f.fangjian@huawei.com>




Thank you,
Jay
Alexandre Belloni Dec. 18, 2018, 10:55 a.m. UTC | #2
On 16/12/2018 00:38:23+0100, Linus Walleij wrote:
> This converts the DesignWare (dw) SPI master driver to

> use GPIO descriptors for chip select handling.

> 

> This driver has a duplicate DT parser in addition to the

> one in the core, sets up the line as non-asserted and

> relies on the core to drive the GPIOs.

> 

> It is a pretty straight-forward conversion.

> 

> Cc: Talel Shenhar <talel@amazon.com>

> Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>

> Cc: Linuxarm <linuxarm@huawei.com>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


The core part was on my todo list since early 2014, thank you to take
care of that :)

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>


> ---

>  drivers/spi/spi-dw-mmio.c | 22 ----------------------

>  drivers/spi/spi-dw.c      |  9 +--------

>  2 files changed, 1 insertion(+), 30 deletions(-)

> 

> diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c

> index 3ffb6a40fe0c..00a43c19f2a4 100644

> --- a/drivers/spi/spi-dw-mmio.c

> +++ b/drivers/spi/spi-dw-mmio.c

> @@ -18,7 +18,6 @@

>  #include <linux/mfd/syscon.h>

>  #include <linux/module.h>

>  #include <linux/of.h>

> -#include <linux/of_gpio.h>

>  #include <linux/of_platform.h>

>  #include <linux/property.h>

>  #include <linux/regmap.h>

> @@ -184,27 +183,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)

>  

>  	dws->num_cs = num_cs;

>  

> -	if (pdev->dev.of_node) {

> -		int i;

> -

> -		for (i = 0; i < dws->num_cs; i++) {

> -			int cs_gpio = of_get_named_gpio(pdev->dev.of_node,

> -					"cs-gpios", i);

> -

> -			if (cs_gpio == -EPROBE_DEFER) {

> -				ret = cs_gpio;

> -				goto out;

> -			}

> -

> -			if (gpio_is_valid(cs_gpio)) {

> -				ret = devm_gpio_request(&pdev->dev, cs_gpio,

> -						dev_name(&pdev->dev));

> -				if (ret)

> -					goto out;

> -			}

> -		}

> -	}

> -

>  	init_func = device_get_match_data(&pdev->dev);

>  	if (init_func) {

>  		ret = init_func(pdev, dwsmmio);

> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c

> index b705f2bdb8b9..22a7998dbc08 100644

> --- a/drivers/spi/spi-dw.c

> +++ b/drivers/spi/spi-dw.c

> @@ -20,7 +20,6 @@

>  #include <linux/delay.h>

>  #include <linux/slab.h>

>  #include <linux/spi/spi.h>

> -#include <linux/gpio.h>

>  

>  #include "spi-dw.h"

>  

> @@ -425,13 +424,6 @@ static int dw_spi_setup(struct spi_device *spi)

>  

>  	chip->tmode = SPI_TMOD_TR;

>  

> -	if (gpio_is_valid(spi->cs_gpio)) {

> -		ret = gpio_direction_output(spi->cs_gpio,

> -				!(spi->mode & SPI_CS_HIGH));

> -		if (ret)

> -			return ret;

> -	}

> -

>  	return 0;

>  }

>  

> @@ -496,6 +488,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)

>  		goto err_free_master;

>  	}

>  

> +	master->use_gpio_descriptors = true;

>  	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;

>  	master->bits_per_word_mask =  SPI_BPW_RANGE_MASK(4, 16);

>  	master->bus_num = dws->bus_num;

> -- 

> 2.19.2

> 


-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com