From: Sascha Hauer <s.hauer@pengutronix.de>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 06/12] spi: add support to handle cs-gpios
Date: Fri, 20 Dec 2024 10:51:21 +0100 [thread overview]
Message-ID: <Z2U-GS_4Yc_CxuwK@pengutronix.de> (raw)
In-Reply-To: <20241216130324.1592755-6-m.felsch@pengutronix.de>
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@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 |
next prev parent reply other threads:[~2024-12-20 11:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 13:03 [PATCH v2 01/12] spi: cosmetic style fixes Marco Felsch
2024-12-16 13:03 ` [PATCH v2 02/12] spi: fix spi_message init during __spi_validate Marco Felsch
2024-12-16 13:03 ` [PATCH v2 03/12] spi: add spi_{set,get}_ctldata accessors Marco Felsch
2024-12-16 13:03 ` [PATCH v2 04/12] gpiolib: add support for gpiod_get_index and gpiod_get_index_optional Marco Felsch
2024-12-16 13:03 ` [PATCH v2 05/12] gpiolib: add support for gpiod_set_consumer_name Marco Felsch
2024-12-16 13:03 ` [PATCH v2 06/12] spi: add support to handle cs-gpios Marco Felsch
2024-12-20 9:51 ` Sascha Hauer [this message]
2024-12-16 13:03 ` [PATCH v2 07/12] spi: add support to setup spi-cs-{setup,hold,inactive}-delay-ns Marco Felsch
2024-12-16 13:03 ` [PATCH v2 08/12] spi: allow reporting the effectivly used speed_hz for a transfer Marco Felsch
2024-12-16 13:03 ` [PATCH v2 09/12] spi: import spi_controller::flags Marco Felsch
2024-12-16 13:03 ` [PATCH v2 10/12] spi: add support for spi_controller::set_cs_timing Marco Felsch
2024-12-16 13:03 ` [PATCH v2 11/12] spi: Provide common spi_message processing loop Marco Felsch
2024-12-16 13:03 ` [PATCH v2 12/12] spi: add support for BCM2835 SPI controller Marco Felsch
2024-12-20 9:16 ` [PATCH v2 01/12] spi: cosmetic style fixes Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z2U-GS_4Yc_CxuwK@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox