Re: [PATCH v4 6/9] spi: introduce SPI ancillary device with lanes

From: Jonathan Cameron

Date: Sun Oct 25 2026 - 22:18:10 EST


On Tue, 20 Oct 2026 22:58:01 -0300
Jonathan Santos <Jonathan.Santos@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
> 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 */