From: Jonathan Cameron <jic23@kernel.org>
To: Antoniu Miclaus <antoniu.miclaus@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Mark Brown" <broonie@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH v3 1/5] spi: allow ancillary devices to share parent's chip selects
Date: Sun, 15 Feb 2026 18:36:37 +0000 [thread overview]
Message-ID: <20260215183637.315365ce@jic23-huawei> (raw)
In-Reply-To: <20260213144742.16394-2-antoniu.miclaus@analog.com>
On Fri, 13 Feb 2026 16:47:33 +0200
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> When registering an ancillary SPI device, the current code flags a chip
> select conflict with the parent device. This happens because the
> ancillary device intentionally uses one of the parent's chip selects,
> but __spi_add_device() checks against all existing devices including
> the parent.
>
> Allow this by passing the parent device pointer to __spi_add_device()
> and skipping the conflict check when the existing device is the parent.
Smells like a fix. If so why don't we have a fixes tag?
This will need review from Mark. I haven't really understood how this
is intended to work.
Jonathan
>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> Reviewed-by: David Lechner <dlechner@baylibre.com>
> ---
> Changes in v3:
> - Drop redundant NULL check for info->parent in spi_dev_check()
>
> drivers/spi/spi.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index e25df9990f82..693bdcc5a12a 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -641,12 +641,26 @@ static inline int spi_dev_check_cs(struct device *dev,
> return 0;
> }
>
> +struct spi_dev_check_info {
> + struct spi_device *new_spi;
> + struct spi_device *parent; /* set for ancillary devices */
> +};
> +
> static int spi_dev_check(struct device *dev, void *data)
> {
> struct spi_device *spi = to_spi_device(dev);
> - struct spi_device *new_spi = data;
> + struct spi_dev_check_info *info = data;
> + struct spi_device *new_spi = info->new_spi;
> int status, idx;
>
> + /*
> + * When registering an ancillary device, skip checking against the
> + * parent device since the ancillary is intentionally using one of
> + * the parent's chip selects.
> + */
> + if (spi == info->parent)
> + return 0;
> +
> if (spi->controller == new_spi->controller) {
> for (idx = 0; idx < spi->num_chipselect; idx++) {
> status = spi_dev_check_cs(dev, spi, idx, new_spi, 0);
> @@ -663,10 +677,11 @@ static void spi_cleanup(struct spi_device *spi)
> spi->controller->cleanup(spi);
> }
>
> -static int __spi_add_device(struct spi_device *spi)
> +static int __spi_add_device(struct spi_device *spi, struct spi_device *parent)
> {
> struct spi_controller *ctlr = spi->controller;
> struct device *dev = ctlr->dev.parent;
> + struct spi_dev_check_info check_info;
> int status, idx;
> u8 cs;
>
> @@ -710,7 +725,9 @@ static int __spi_add_device(struct spi_device *spi)
> * chipselect **BEFORE** we call setup(), else we'll trash
> * its configuration.
> */
> - status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
> + check_info.new_spi = spi;
> + check_info.parent = parent;
> + status = bus_for_each_dev(&spi_bus_type, NULL, &check_info, spi_dev_check);
> if (status)
> return status;
>
> @@ -772,7 +789,7 @@ int spi_add_device(struct spi_device *spi)
> spi_dev_set_name(spi);
>
> mutex_lock(&ctlr->add_lock);
> - status = __spi_add_device(spi);
> + status = __spi_add_device(spi, NULL);
> mutex_unlock(&ctlr->add_lock);
> return status;
> }
> @@ -2580,8 +2597,8 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
>
> WARN_ON(!mutex_is_locked(&ctlr->add_lock));
>
> - /* Register the new device */
> - rc = __spi_add_device(ancillary);
> + /* Register the new device, passing the parent to skip CS conflict check */
> + rc = __spi_add_device(ancillary, spi);
> if (rc) {
> dev_err(&spi->dev, "failed to register ancillary device\n");
> goto err_out;
next prev parent reply other threads:[~2026-02-15 18:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-13 14:47 [PATCH v3 0/5] iio: adc: ad4080: add support for AD4880 dual-channel ADC Antoniu Miclaus
2026-02-13 14:47 ` [PATCH v3 1/5] spi: allow ancillary devices to share parent's chip selects Antoniu Miclaus
2026-02-13 16:39 ` Nuno Sá
2026-02-15 18:36 ` Jonathan Cameron [this message]
2026-02-13 14:47 ` [PATCH v3 2/5] spi: add devm_spi_new_ancillary_device() Antoniu Miclaus
2026-02-13 16:40 ` Nuno Sá
2026-02-13 14:47 ` [PATCH v3 3/5] iio: backend: add devm_iio_backend_get_by_index() Antoniu Miclaus
2026-02-13 16:33 ` Nuno Sá
2026-02-13 14:47 ` [PATCH v3 4/5] dt-bindings: iio: adc: ad4080: add AD4880 support Antoniu Miclaus
2026-02-13 16:34 ` Rob Herring (Arm)
2026-02-14 8:54 ` Krzysztof Kozlowski
2026-02-13 14:47 ` [PATCH v3 5/5] iio: adc: ad4080: add support for AD4880 dual-channel ADC Antoniu Miclaus
2026-02-13 16:43 ` Nuno Sá
2026-02-15 18:42 ` Jonathan Cameron
2026-02-15 18:34 ` [PATCH v3 0/5] " Jonathan Cameron
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=20260215183637.315365ce@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
/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