[PATCH v2 06/12] spi: add support to handle cs-gpios

Sascha Hauer s.hauer at pengutronix.de
Fri Dec 20 01:51:21 PST 2024


On Mon, Dec 16, 2024 at 02:03:18PM +0100, Marco Felsch wrote:
> At the moment all drivers have to parse the cs-gpios on their own and
> have to implement the mapping. By this commit we add the support to
> handle this within the core and if there is valid CS GPIO for a device
> we assign it accordingly.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---
> Changelog:
> v2:
>  - add missing 'use_gpio_descriptor' member documentation
> 
>  drivers/spi/spi.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/spi/spi.h | 12 +++++++++
>  2 files changed, 78 insertions(+)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 36d0653a191c..c239de9d8549 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -8,6 +8,8 @@
>   */
>  
>  #include <common.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/spi/spi-mem.h>
>  #include <spi/spi.h>
>  #include <xfuncs.h>
> @@ -64,6 +66,8 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
>  	proxy = xzalloc(sizeof *proxy);
>  	proxy->master = ctrl;
>  	proxy->chip_select = chip->chip_select;
> +	if (ctrl->cs_gpiods)
> +		proxy->cs_gpiod = ctrl->cs_gpiods[chip->chip_select];
>  	proxy->max_speed_hz = chip->max_speed_hz;
>  	proxy->mode = chip->mode;
>  	proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
> @@ -215,6 +219,62 @@ static void scan_boardinfo(struct spi_controller *ctrl)
>  	}
>  }
>  
> +/**
> + * spi_get_gpio_descs() - grab chip select GPIOs for the master
> + * @ctlr: The SPI master to grab GPIO descriptors for
> + */
> +static int spi_get_gpio_descs(struct spi_controller *ctlr)
> +{
> +	int nb, i;
> +	struct gpio_desc **cs;
> +	struct device *dev = ctlr->dev;
> +
> +	nb = gpiod_count(dev, "cs");
> +	if (nb < 0) {
> +		/* No GPIOs at all is fine, else return the error */
> +		if (nb == -ENOENT)
> +			return 0;
> +		return nb;
> +	}

This breaks a number of non device tree defconfigs:

drivers/spi/spi.o: in function `spi_get_gpio_descs':
/__w/barebox/barebox/drivers/spi/spi.c:277:(.text.spi_register_controller+0x15c): undefined reference to `gpiod_count'

I haven't looked into it yet what we can best do about it.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list