From: Jonathan Santos <Jonathan.Santos@analog.com>
To: <linux-spi@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
<linux@analog.com>
Cc: Jonathan Santos <Jonathan.Santos@analog.com>,
<broonie@kernel.org>, <robh@kernel.org>, <krzk+dt@kernel.org>,
<conor+dt@kernel.org>, <Michael.Hennerich@analog.com>,
<nuno.sa@analog.com>, <jic23@kernel.org>, <dlechner@baylibre.com>,
<andriy.shevchenko@intel.com>
Subject: [PATCH v4 3/9] spi: support simultaneous assertion of multiple CS
Date: Tue, 20 Oct 2026 22:57:12 -0300 [thread overview]
Message-ID: <372aad8ff5acef8412edef77ab1b7fcce7a902fd.1792435248.git.Jonathan.Santos@analog.com> (raw)
In-Reply-To: <cover.1792435248.git.Jonathan.Santos@analog.com>
Some SPI controllers allow multiple CS lines to be toggled at the same
time. The existing code always used CS index 0 when tracking the last
active CS in spi_set_cs(), and unconditionally set cs_index_mask to
BIT(0) when parsing DT, both forcing the single CS usage.
Modify spi_set_cs() to iterate last_cs[] using each logical CS index
instead of always reading index 0. Modify of_spi_parse_dt() to build
cs_index_mask from all parsed CS entries when 'spi-cs-composite' is set,
so the controller identifies which CS lines belong to a device when
asserting them simultaneously as a composite device.
Board info, ACPI, and ancillary device paths are not updated here.
Board info would require an API change to accept an array of CS values
and is left for a follow-up when we have a use case for this. Ancillary
devices are by design single-CS, so multi-CS is not a current use case for
them. ACPI represents the CS as a 64-bit integer with no established
convention for encoding multiple CS indices yet, so any extension there
would require a separate specification effort.
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
Changes in v4:
* use spi-cs-composite to determine whether to assert all CS lines
together, rather than always asserting them together.
* Replaced the for-loop to assign the spi->cs_index_mask with
"GENMASK(spi->num_chipselect - 1, 0)".
Changes in v3:
* None.
Changes in v2:
* Include Summary describing why the other SPI paths were not addressed
here.
---
drivers/spi/spi.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5b5b3bc5f0d8..7a0406ec200e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1278,7 +1278,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
spi->controller->last_cs_index_mask = spi->cs_index_mask;
for (idx = 0; idx < SPI_DEVICE_CS_CNT_MAX; idx++) {
if (enable && idx < spi->num_chipselect)
- spi->controller->last_cs[idx] = spi_get_chipselect(spi, 0);
+ spi->controller->last_cs[idx] = spi_get_chipselect(spi, idx);
else
spi->controller->last_cs[idx] = SPI_INVALID_CS;
}
@@ -2794,8 +2794,19 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
/*
* By default spi->chip_select[0] will hold the physical CS number,
* so set bit 0 in spi->cs_index_mask.
+ *
+ * If "spi-cs-composite" is present, assert all CS lines at once
+ * so the device acts as a single composite target.
*/
- spi->cs_index_mask = BIT(0);
+ if (of_property_read_bool(nc, "spi-cs-composite")) {
+ if (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS)) {
+ dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n");
+ return -EINVAL;
+ }
+ spi->cs_index_mask = GENMASK(spi->num_chipselect - 1, 0);
+ } else {
+ spi->cs_index_mask = BIT(0);
+ }
/* Device speed */
if (!of_property_read_u32(nc, "spi-max-frequency", &value))
--
2.34.1
next prev parent reply other threads:[~2026-10-21 1:57 UTC|newest]
Thread overview: 10+ 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-21 1:56 ` [PATCH v4 2/9] dt-bindings: iio: adc: ad7768-1: Document multidevice support Jonathan Santos
2026-10-21 1:57 ` Jonathan Santos [this message]
2026-10-21 1:57 ` [PATCH v4 4/9] spi: restrict CS logical values to a contiguous sequence Jonathan Santos
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-21 1:58 ` [PATCH v4 6/9] spi: introduce SPI ancillary device with lanes Jonathan Santos
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 1:58 ` [PATCH v4 9/9] iio: adc: ad7768-1: add support for multiple chip aggregation Jonathan Santos
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=372aad8ff5acef8412edef77ab1b7fcce7a902fd.1792435248.git.Jonathan.Santos@analog.com \
--to=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=jic23@kernel.org \
--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®