mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Jonathan Santos <Jonathan.Santos@analog.com>
Cc: <linux-spi@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
	<linux@analog.com>, <broonie@kernel.org>, <robh@kernel.org>,
	<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<Michael.Hennerich@analog.com>, <nuno.sa@analog.com>,
	<dlechner@baylibre.com>, <andriy.shevchenko@intel.com>
Subject: Re: [PATCH v4 6/9] spi: introduce SPI ancillary device with lanes
Date: Mon, 26 Oct 2026 02:17:32 +0000	[thread overview]
Message-ID: <20261026021732.31e510da@jic23-hlaptop> (raw)
In-Reply-To: <21fb26ff0337f493643167f8c9dfae92d1b3b9a7.1792435248.git.Jonathan.Santos@analog.com>

On Tue, 20 Oct 2026 22:58:01 -0300
Jonathan Santos <Jonathan.Santos@analog.com> wrote:

> The existing spi_new_ancillary_device() creates an ancillary SPI device
> but does not consider the parent's lane map. In multi-device setups where
> each sub-device's chip-select is bound to a dedicated data lane, there is
> no way to bind an ancillary device to an arbitrary lane index.
> 
> Introduce spi_new_ancillary_device_with_lane() and
> devm_spi_new_ancillary_device_with_lane(), which accept rx_lane_idx and
> tx_lane_idx parameters to select a specific lane from the parent's
> rx_lane_map and tx_lane_map respectively. The resulting ancillary device
> is registered with a single RX and TX lane, keeping it independent from
> the other sub-devices sharing the same controller.

The multiple-data-lanes.rst doc doesn't me make it clear if for the 
lanes are all one wide, or if it is fine to have 2 lanes each
of width 4.  Either way I'd expect more parameters to be needed.
The AD7786 has diagrams of two devices, bus width 2 for each.

> 
> While at it, fix the spi_new_ancillary_device() documentation, which
> claimed it returns 0 on success instead of a pointer.
> 
> Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
> ---
> Changes in v4:
> * Don't use extern for the new declarations of the ancillary functions from
>   spi.h.
> 
> Changes in v3:
> * Refactored code using helper function to reduce duplicated code.
> 
> Changes in v2:
> * New patch.
> ---
>  drivers/spi/spi.c       | 116 +++++++++++++++++++++++++++++++++++-----
>  include/linux/spi/spi.h |   8 +++
>  2 files changed, 110 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 53d6ab4ce8a3..30103bffad33 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -2918,20 +2918,12 @@ static void of_register_spi_devices(struct spi_controller *ctlr)
>  static void of_register_spi_devices(struct spi_controller *ctlr) { }
>  #endif
>  
> -/**
> - * spi_new_ancillary_device() - Register ancillary SPI device
> - * @spi:         Pointer to the main SPI device registering the ancillary device
> - * @chip_select: Chip Select of the ancillary device
> - *
> - * Register an ancillary SPI device; for example some chips have a chip-select
> - * for normal device usage and another one for setup/firmware upload.
> - *
> - * This may only be called from main SPI device's probe routine.
> - *
> - * Return: 0 on success; negative errno on failure
> - */
> -struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
> -					     u8 chip_select)
> +#define SPI_UNDEFINED_LANE	-1
> +
> +static struct spi_device *__spi_new_ancillary_device(struct spi_device *spi,
> +						     u8 chip_select,
> +						     int rx_lane_idx,
> +						     int tx_lane_idx)
>  {
>  	struct spi_controller *ctlr = spi->controller;
>  	struct spi_device *ancillary;
> @@ -2958,6 +2950,21 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
>  	 */
>  	ancillary->cs_index_mask = BIT(0);
>  
> +	if (rx_lane_idx >= spi->num_rx_lanes || tx_lane_idx >= spi->num_tx_lanes) {
> +		rc = -EINVAL;
> +		goto err_out;
> +	}
> +
> +	if (rx_lane_idx != SPI_UNDEFINED_LANE) {
> +		ancillary->rx_lane_map[0] = spi->rx_lane_map[rx_lane_idx];
> +		ancillary->num_rx_lanes = 1;
> +	}
> +
> +	if (tx_lane_idx != SPI_UNDEFINED_LANE) {
> +		ancillary->tx_lane_map[0] = spi->tx_lane_map[tx_lane_idx];
> +		ancillary->num_tx_lanes = 1;
> +	}
> +
>  	WARN_ON(!mutex_is_locked(&ctlr->add_lock));
>  
>  	/* Register the new device, passing the parent to skip CS conflict check */


  reply	other threads:[~2026-10-26  2:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  1:56 [PATCH v4 0/9] spi: add multi-CS and multi-chip aggregation support Jonathan Santos
2026-10-21  1:56 ` [PATCH v4 1/9] spi: dt-bindings: Add spi-cs-composite property Jonathan Santos
2026-10-26  2:00   ` Jonathan Cameron
2026-10-21  1:56 ` [PATCH v4 2/9] dt-bindings: iio: adc: ad7768-1: Document multidevice support Jonathan Santos
2026-10-26  2:05   ` Jonathan Cameron
2026-10-21  1:57 ` [PATCH v4 3/9] spi: support simultaneous assertion of multiple CS Jonathan Santos
2026-10-21  1:57 ` [PATCH v4 4/9] spi: restrict CS logical values to a contiguous sequence Jonathan Santos
2026-10-21 15:06   ` Andy Shevchenko
2026-10-21  1:57 ` [PATCH v4 5/9] spi: expand device name to include enabled CS lines for multi-CS devices Jonathan Santos
2026-10-26  2:07   ` Jonathan Cameron
2026-10-21  1:58 ` [PATCH v4 6/9] spi: introduce SPI ancillary device with lanes Jonathan Santos
2026-10-26  2:17   ` Jonathan Cameron [this message]
2026-10-21  1:58 ` [PATCH v4 7/9] spi: add KUnit tests for the multi-CS framework Jonathan Santos
2026-10-21  1:58 ` [PATCH v4 8/9] spi: spi-engine-ex: Add support for multi-CS devices Jonathan Santos
2026-10-21 15:13   ` Andy Shevchenko
2026-10-21  1:58 ` [PATCH v4 9/9] iio: adc: ad7768-1: add support for multiple chip aggregation Jonathan Santos
2026-10-26  2:26   ` 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=20261026021732.31e510da@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=Jonathan.Santos@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andriy.shevchenko@intel.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=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®