Skip to content

spi: add multi-CS and multi-chip aggregation support

Jonathan Santos linux-devicetree linux-iio linux-spi lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest9 patches 17 repliesIn review
  2. v36 patches 16 repliesSuperseded
  3. v25 patches 4 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v16 patches18 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9spi: dt-bindings: Add spi-cs-composite propertyDocumentation/devicetree/bindings/spi/spi-peripheral-props.yaml+8 -04 replies
2/9dt-bindings: iio: adc: ad7768-1: Document multidevice supportDocumentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml+79 -13 replies
3/9spi: support simultaneous assertion of multiple CSdrivers/spi/spi.c+13 -20 replies
4/9spi: restrict CS logical values to a contiguous sequencedrivers/spi/spi.c+10 -03 replies
5/9spi: expand device name to include enabled CS lines for multi-CS devicesdrivers/spi/spi.c+14 -01 reply
6/9spi: introduce SPI ancillary device with lanesdrivers/spi/spi.c include/linux/spi/spi.h+110 -141 reply
7/9spi: add KUnit tests for the multi-CS frameworkdrivers/spi/.kunitconfig drivers/spi/Kconfig drivers/spi/Makefile +4 more+409 -151 reply
8/9spi: spi-engine-ex: Add support for multi-CS devicesdrivers/spi/spi-axi-spi-engine.c+18 -32 replies
9/9iio: adc: ad7768-1: add support for multiple chip aggregationdrivers/iio/adc/ad7768-1.c+90 -102 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/9] spi: add multi-CS and multi-chip aggregation support

This series adds support for multi-CS devices and ancillary devices with lanes, to enable the multi-device setup described in [1], where multiple AD7768-1 ADCs are wired to the same controller in a synchronized sampling configuration, and the limitation noted in [2], where no SPI controller completely handles logical chip selects beyond the first one.

The first part of the set addresses multi-CS support. Some SPI controllers can assert multiple chip selects simultaneously, but the existing code hardcoded CS index 0 in both spi_set_cs() and of_spi_parse_dt(), preventing this from working. The spi device name pattern is modified to include all active CS lines in range format, so multi-CS devices are distinguishable in sysfs.

The second part introduces spi_new_ancillary_device_with_lane() and its devm variant, used here to create subdevices that bind the CS with a corresponding rx and tx lane from the parent device. With that we can handle each device individually when there are separate data lanes.

The last part uses the above infrastructure in the AD7768-1 driver to support aggregating multiple chips as a single IIO device. The number of sub-devices is derived from the number of CS lines. IIO channels are allocated dynamically, buffered capture is restricted to the full-device scan mask, and SPI offload mode enables SPI_MULTI_LANE_MODE_STRIPE to interleave samples from all lanes into the DMA stream.

---
v4 summary:
* Included patch to add new spi-cs-composite property to the bindings,
to allow multi-CS devices.
* Added new patch restricting CS logical values to a contiguous sequence.
* Device name for multi-CS devices is now formatted as range (the
contiguous restriction makes it possible) instead of a list.
* Introduced KUnit tests for SPI core CS management, following the SPI DMA
pattern.
* Addressed other minor suggestions, see individual patches. Please refer
to "OBS For V4" section before proceeding.
* Link to v3: https://lore.kernel.org/linux-spi/[email protected]/T/#t

v3 summary:
* Added new patch to document the properties for multidevice support on
ad7768-1 bindings.
* Refactored "spi: introduce SPI ancillary device with lanes" patch
to reduce duplicated code using helper functions.
* Modified channel mask allocation on ad7768_parse_aaf_gain() to get
a static value, Since we assume the family is single channel. Added a
comment explaining.
* Addressed other minor suggestions, see individual patches. Please refer
to "OBS For V3" section before proceeding.
* Link to v2: https://lore.kernel.org/linux-spi/[email protected]/T/#t

v2 summary:
* Removed the per-transfer CS mask patches, the devices will be
individually handled by the ancillary device feature.
* Removed dynamic multilane selection patches. The lane is bound to the
CS using the new spi_new_ancillary_device_with_lane() feature.
* Included a use case patch modifying the AD7768-1 driver to support
multidevice aggregation.
* Link to v1: https://lore.kernel.org/linux-spi/[email protected]/T/#t

OBS For V4: An alternative to the 'spi-cs-composite' property would be a separate composite device holding all CS in its cs_index_mask (as suggested by David), while the main device and the ancillaries are used for individual access. That approach was dropped because the composite device claims chip selects already taken by its siblings (the main device and the ancillaries), and the CS conflict check only skips the parent device, not siblings. Relaxing that check is not trivial, so the new property instead lets the main device act as the composite while the ancillaries handle individual access.

OBS For V3: The ancillary device approach was chosen over per-transfer CS masks because it has better integration with regmap. Both approaches require multiple regmap instances, but the CS mask approach would additionally require custom read/write functions to route transfers to the correct CS, while ancillary devices handle this more transparently.

David suggested adding an ancillary device field to spi_message, I guess to enable dynamic CS-lane selection. For now, using one ancillary device per chip for individual access and the main SPI device for simultaneous access seems to be sufficient. The dynamic approach can be implemented in the future if needed.

---

[1]: https://lore.kernel.org/linux-iio/af0EGv172ZMl%[email protected]/T/#t
[2]: https://lore.kernel.org/all/[email protected]/

Jonathan Santos (9):
spi: dt-bindings: Add spi-cs-composite property
dt-bindings: iio: adc: ad7768-1: Document multidevice support
spi: support simultaneous assertion of multiple CS
spi: restrict CS logical values to a contiguous sequence
spi: expand device name to include enabled CS lines for multi-CS
devices
spi: introduce SPI ancillary device with lanes
spi: add KUnit tests for the multi-CS framework
spi: spi-engine-ex: Add support for multi-CS devices
iio: adc: ad7768-1: add support for multiple chip aggregation

 .../bindings/iio/adc/adi,ad7768-1.yaml        |  80 +++-
 .../bindings/spi/spi-peripheral-props.yaml    |   8 +
 drivers/iio/adc/ad7768-1.c                    | 100 ++++-
 drivers/spi/.kunitconfig                      |   1 +
 drivers/spi/Kconfig                           |  11 +
 drivers/spi/Makefile                          |   2 +-
 drivers/spi/internals.h                       |  16 +
 drivers/spi/spi-axi-spi-engine.c              |  21 +-
 drivers/spi/spi.c                             | 172 ++++++--
 drivers/spi/tests/Makefile                    |   3 +-
 drivers/spi/tests/spi-multi-cs-kunit.c        | 374 ++++++++++++++++++
 include/linux/spi/spi.h                       |   8 +
 12 files changed, 751 insertions(+), 45 deletions(-)
 create mode 100644 drivers/spi/tests/spi-multi-cs-kunit.c

base-commit: 43ffda3c7f8456bbe641ae8249a077a361b97880

Signature · 1 line
2.34.1