* [PATCH v2 1/7] spi: fix return code when spi device has too many chipselects
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 2/7] spi: keep track of number of chipselects in spi_device Jonas Gorski
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
Don't return a positive value when there are too many chipselects.
Fixes: 4d8ff6b0991d ("spi: Add multi-cs memories support in SPI core")
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* no changes
drivers/spi/spi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index f95c4304df8e..b07d6cdf587c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2445,7 +2445,7 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
if (rc > ctlr->num_chipselect) {
dev_err(&ctlr->dev, "%pOF has number of CS > ctlr->num_chipselect (%d)\n",
nc, rc);
- return rc;
+ return -EINVAL;
}
if ((of_property_present(nc, "parallel-memories")) &&
(!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) {
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 2/7] spi: keep track of number of chipselects in spi_device
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 1/7] spi: fix return code when spi device has too many chipselects Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 3/7] spi: move unused device CS initialization to __spi_add_device() Jonas Gorski
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
There are several places where we need to iterate over a device's
chipselect. To be able to do it efficiently, store the number of
chipselects in spi_device, like we do for controllers.
Since we now use a device supplied value, add a check to make sure it
isn't more than we can support.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
Changes v1 -> v2:
* no changes
drivers/spi/spi.c | 29 +++++++++++++++++++++--------
include/linux/spi/spi.h | 4 +++-
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b07d6cdf587c..6598fb862d80 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -586,6 +586,7 @@ struct spi_device *spi_alloc_device(struct spi_controller *ctlr)
spi->dev.bus = &spi_bus_type;
spi->dev.release = spidev_release;
spi->mode = ctlr->buswidth_override_bits;
+ spi->num_chipselect = 1;
device_initialize(&spi->dev);
return spi;
@@ -635,7 +636,7 @@ static inline int spi_dev_check_cs(struct device *dev,
u8 idx_new;
cs = spi_get_chipselect(spi, idx);
- for (idx_new = new_idx; idx_new < SPI_CS_CNT_MAX; idx_new++) {
+ for (idx_new = new_idx; idx_new < new_spi->num_chipselect; idx_new++) {
cs_new = spi_get_chipselect(new_spi, idx_new);
if (is_valid_cs(cs) && is_valid_cs(cs_new) && cs == cs_new) {
dev_err(dev, "chipselect %u already in use\n", cs_new);
@@ -652,7 +653,7 @@ static int spi_dev_check(struct device *dev, void *data)
int status, idx;
if (spi->controller == new_spi->controller) {
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ for (idx = 0; idx < spi->num_chipselect; idx++) {
status = spi_dev_check_cs(dev, spi, idx, new_spi, 0);
if (status)
return status;
@@ -674,7 +675,13 @@ static int __spi_add_device(struct spi_device *spi)
int status, idx;
u8 cs;
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ if (spi->num_chipselect > SPI_CS_CNT_MAX) {
+ dev_err(dev, "num_cs %d > max %d\n", spi->num_chipselect,
+ SPI_CS_CNT_MAX);
+ return -EOVERFLOW;
+ }
+
+ for (idx = 0; idx < spi->num_chipselect; idx++) {
/* Chipselects are numbered 0..max; validate. */
cs = spi_get_chipselect(spi, idx);
if (is_valid_cs(cs) && cs >= ctlr->num_chipselect) {
@@ -689,7 +696,7 @@ static int __spi_add_device(struct spi_device *spi)
* For example, spi->chip_select[0] != spi->chip_select[1] and so on.
*/
if (!spi_controller_is_target(ctlr)) {
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ for (idx = 0; idx < spi->num_chipselect; idx++) {
status = spi_dev_check_cs(dev, spi, idx, spi, idx + 1);
if (status)
return status;
@@ -717,7 +724,7 @@ static int __spi_add_device(struct spi_device *spi)
if (ctlr->cs_gpiods) {
u8 cs;
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ for (idx = 0; idx < spi->num_chipselect; idx++) {
cs = spi_get_chipselect(spi, idx);
if (is_valid_cs(cs))
spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
@@ -1024,7 +1031,7 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
/*-------------------------------------------------------------------------*/
#define spi_for_each_valid_cs(spi, idx) \
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) \
+ for (idx = 0; idx < spi->num_chipselect; idx++) \
if (!(spi->cs_index_mask & BIT(idx))) {} else
static inline bool spi_is_last_cs(struct spi_device *spi)
@@ -1080,8 +1087,12 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
trace_spi_set_cs(spi, activate);
spi->controller->last_cs_index_mask = spi->cs_index_mask;
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
- spi->controller->last_cs[idx] = enable ? spi_get_chipselect(spi, 0) : SPI_INVALID_CS;
+ for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ if (enable && idx < spi->num_chipselect)
+ spi->controller->last_cs[idx] = spi_get_chipselect(spi, 0);
+ else
+ spi->controller->last_cs[idx] = SPI_INVALID_CS;
+ }
spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;
if (spi->controller->last_cs_mode_high)
@@ -2452,6 +2463,8 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n");
return -EINVAL;
}
+
+ spi->num_chipselect = rc;
for (idx = 0; idx < rc; idx++)
spi_set_chipselect(spi, idx, cs[idx]);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index e9ea43234d9a..49c048277e97 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -170,6 +170,7 @@ extern void spi_transfer_cs_change_delay_exec(struct spi_message *msg,
* two delays will be added up.
* @chip_select: Array of physical chipselect, spi->chipselect[i] gives
* the corresponding physical CS for logical CS i.
+ * @num_chipselect: Number of physical chipselects used.
* @cs_index_mask: Bit mask of the active chipselect(s) in the chipselect array
* @cs_gpiod: Array of GPIO descriptors of the corresponding chipselect lines
* (optional, NULL when not using a GPIO line)
@@ -229,6 +230,7 @@ struct spi_device {
struct spi_delay cs_inactive;
u8 chip_select[SPI_CS_CNT_MAX];
+ u8 num_chipselect;
/*
* Bit mask of the chipselect(s) that the driver need to use from
@@ -315,7 +317,7 @@ static inline bool spi_is_csgpiod(struct spi_device *spi)
{
u8 idx;
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ for (idx = 0; idx < spi->num_chipselect; idx++) {
if (spi_get_csgpiod(spi, idx))
return true;
}
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 3/7] spi: move unused device CS initialization to __spi_add_device()
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 1/7] spi: fix return code when spi device has too many chipselects Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 2/7] spi: keep track of number of chipselects in spi_device Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 4/7] spi: drop check for validity of device chip selects Jonas Gorski
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
Using spi_device::num_chipselect, initialize unused device CS as invalid
at registration time in __spi_add_device(), and drop it from the
different allocation paths.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
Changes v1 -> v2:
* new patch
drivers/spi/spi.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6598fb862d80..ad965eae9c9f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -703,6 +703,10 @@ static int __spi_add_device(struct spi_device *spi)
}
}
+ /* Initialize unused logical CS as invalid */
+ for (idx = spi->num_chipselect; idx < SPI_CS_CNT_MAX; idx++)
+ spi_set_chipselect(spi, idx, SPI_INVALID_CS);
+
/* Set the bus ID string */
spi_dev_set_name(spi);
@@ -780,14 +784,6 @@ int spi_add_device(struct spi_device *spi)
}
EXPORT_SYMBOL_GPL(spi_add_device);
-static void spi_set_all_cs_unused(struct spi_device *spi)
-{
- u8 idx;
-
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
- spi_set_chipselect(spi, idx, SPI_INVALID_CS);
-}
-
/**
* spi_new_device - instantiate one new SPI device
* @ctlr: Controller to which device is connected
@@ -823,7 +819,6 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
/* Use provided chip-select for proxy device */
- spi_set_all_cs_unused(proxy);
spi_set_chipselect(proxy, 0, chip->chip_select);
proxy->max_speed_hz = chip->max_speed_hz;
@@ -2443,8 +2438,6 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
return -EINVAL;
}
- spi_set_all_cs_unused(spi);
-
/* Device address */
rc = of_property_read_variable_u32_array(nc, "reg", &cs[0], 1,
SPI_CS_CNT_MAX);
@@ -2589,7 +2582,6 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
strscpy(ancillary->modalias, "dummy", sizeof(ancillary->modalias));
/* Use provided chip-select for ancillary device */
- spi_set_all_cs_unused(ancillary);
spi_set_chipselect(ancillary, 0, chip_select);
/* Take over SPI mode/speed from SPI main device */
@@ -2837,7 +2829,6 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
return ERR_PTR(-ENOMEM);
}
- spi_set_all_cs_unused(spi);
spi_set_chipselect(spi, 0, lookup.chip_select);
ACPI_COMPANION_SET(&spi->dev, adev);
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 4/7] spi: drop check for validity of device chip selects
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
` (2 preceding siblings ...)
2025-09-15 18:37 ` [PATCH v2 3/7] spi: move unused device CS initialization to __spi_add_device() Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 5/7] spi: don't check spi_controller::num_chipselect when parsing a dt device Jonas Gorski
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
Now that we know the number of chip selects of a device, we can assume
these are valid, and do not need to check them first.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* dropped removal of initialization to SPI_CS_INVALID
drivers/spi/spi.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ad965eae9c9f..91e2f4f504e8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -623,11 +623,6 @@ static void spi_dev_set_name(struct spi_device *spi)
*/
#define SPI_INVALID_CS ((s8)-1)
-static inline bool is_valid_cs(s8 chip_select)
-{
- return chip_select != SPI_INVALID_CS;
-}
-
static inline int spi_dev_check_cs(struct device *dev,
struct spi_device *spi, u8 idx,
struct spi_device *new_spi, u8 new_idx)
@@ -638,7 +633,7 @@ static inline int spi_dev_check_cs(struct device *dev,
cs = spi_get_chipselect(spi, idx);
for (idx_new = new_idx; idx_new < new_spi->num_chipselect; idx_new++) {
cs_new = spi_get_chipselect(new_spi, idx_new);
- if (is_valid_cs(cs) && is_valid_cs(cs_new) && cs == cs_new) {
+ if (cs == cs_new) {
dev_err(dev, "chipselect %u already in use\n", cs_new);
return -EBUSY;
}
@@ -684,7 +679,7 @@ static int __spi_add_device(struct spi_device *spi)
for (idx = 0; idx < spi->num_chipselect; idx++) {
/* Chipselects are numbered 0..max; validate. */
cs = spi_get_chipselect(spi, idx);
- if (is_valid_cs(cs) && cs >= ctlr->num_chipselect) {
+ if (cs >= ctlr->num_chipselect) {
dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx),
ctlr->num_chipselect);
return -EINVAL;
@@ -730,8 +725,7 @@ static int __spi_add_device(struct spi_device *spi)
for (idx = 0; idx < spi->num_chipselect; idx++) {
cs = spi_get_chipselect(spi, idx);
- if (is_valid_cs(cs))
- spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
+ spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 5/7] spi: don't check spi_controller::num_chipselect when parsing a dt device
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
` (3 preceding siblings ...)
2025-09-15 18:37 ` [PATCH v2 4/7] spi: drop check for validity of device chip selects Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 6/7] spi: reduce device chip select limit again Jonas Gorski
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
Do not validate spi_controller::num_chipselect against SPI_CS_CNT_MAX
when parsing an spi device firmware node.
Firstly this is the wrong place, and this should be done while
registering/validating the controller. Secondly, there is no reason for
that check, as SPI_CS_CNT_MAX controls the amount of chipselects a
device may have, not a controller may have.
So drop that check as it needlessly limits controllers to SPI_CS_CNT_MAX
number of chipselects.
Likewise, drop the check for number of device chipselects larger than
controller's number of chipselects, as __spi_add_device() will already
catch that as either one of the chip selects will be out of range, or
there is a duplicate one.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* no changes
drivers/spi/spi.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 91e2f4f504e8..2eb361e9e44d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2427,11 +2427,6 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
return 0;
}
- if (ctlr->num_chipselect > SPI_CS_CNT_MAX) {
- dev_err(&ctlr->dev, "No. of CS is more than max. no. of supported CS\n");
- return -EINVAL;
- }
-
/* Device address */
rc = of_property_read_variable_u32_array(nc, "reg", &cs[0], 1,
SPI_CS_CNT_MAX);
@@ -2440,11 +2435,7 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
nc, rc);
return rc;
}
- if (rc > ctlr->num_chipselect) {
- dev_err(&ctlr->dev, "%pOF has number of CS > ctlr->num_chipselect (%d)\n",
- nc, rc);
- return -EINVAL;
- }
+
if ((of_property_present(nc, "parallel-memories")) &&
(!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) {
dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n");
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 6/7] spi: reduce device chip select limit again
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
` (4 preceding siblings ...)
2025-09-15 18:37 ` [PATCH v2 5/7] spi: don't check spi_controller::num_chipselect when parsing a dt device Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 7/7] spi: rename SPI_CS_CNT_MAX => SPI_DEVICE_CS_CNT_MAX Jonas Gorski
2025-09-23 11:25 ` [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
The spi chipselect limit SPI_CS_CNT_MAX was raised with commit
2f8c7c3715f2 ("spi: Raise limit on number of chip selects") from 4 to 16
to accommodate spi controllers with more than 4 chip selects, and then
later to 24 with commit 96893cdd4760 ("spi: Raise limit on number of
chip selects to 24").
Now that we removed SPI_CS_CNT_MAX limiting the chip selects of
controllers, we can reduce the amount of chip selects per device again
to 4, the original value.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* reworded and rebased onto newest changes
include/linux/spi/spi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 49c048277e97..df4842abbc6f 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -21,7 +21,7 @@
#include <uapi/linux/spi/spi.h>
/* Max no. of CS supported per spi device */
-#define SPI_CS_CNT_MAX 24
+#define SPI_CS_CNT_MAX 4
struct dma_chan;
struct software_node;
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2 7/7] spi: rename SPI_CS_CNT_MAX => SPI_DEVICE_CS_CNT_MAX
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
` (5 preceding siblings ...)
2025-09-15 18:37 ` [PATCH v2 6/7] spi: reduce device chip select limit again Jonas Gorski
@ 2025-09-15 18:37 ` Jonas Gorski
2025-09-23 11:25 ` [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Jonas Gorski @ 2025-09-15 18:37 UTC (permalink / raw)
To: Mark Brown, Amit Kumar Mahapatra
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
Rename SPI_CS_CNT_MAX to SPI_DEVICE_CS_CNT_MAX to make it more obvious
that this is the max number of CS per device supported, not per
controller.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* no changes
drivers/spi/spi-cadence-quadspi.c | 2 +-
drivers/spi/spi.c | 14 +++++++-------
include/linux/spi/spi.h | 12 ++++++------
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 9bf823348cd3..d6b2c1051328 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -33,7 +33,7 @@
#define CQSPI_NAME "cadence-qspi"
#define CQSPI_MAX_CHIPSELECT 4
-static_assert(CQSPI_MAX_CHIPSELECT <= SPI_CS_CNT_MAX);
+static_assert(CQSPI_MAX_CHIPSELECT <= SPI_DEVICE_CS_CNT_MAX);
/* Quirks */
#define CQSPI_NEEDS_WR_DELAY BIT(0)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 2eb361e9e44d..2e0647a06890 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -670,9 +670,9 @@ static int __spi_add_device(struct spi_device *spi)
int status, idx;
u8 cs;
- if (spi->num_chipselect > SPI_CS_CNT_MAX) {
+ if (spi->num_chipselect > SPI_DEVICE_CS_CNT_MAX) {
dev_err(dev, "num_cs %d > max %d\n", spi->num_chipselect,
- SPI_CS_CNT_MAX);
+ SPI_DEVICE_CS_CNT_MAX);
return -EOVERFLOW;
}
@@ -699,7 +699,7 @@ static int __spi_add_device(struct spi_device *spi)
}
/* Initialize unused logical CS as invalid */
- for (idx = spi->num_chipselect; idx < SPI_CS_CNT_MAX; idx++)
+ for (idx = spi->num_chipselect; idx < SPI_DEVICE_CS_CNT_MAX; idx++)
spi_set_chipselect(spi, idx, SPI_INVALID_CS);
/* Set the bus ID string */
@@ -1076,7 +1076,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
trace_spi_set_cs(spi, activate);
spi->controller->last_cs_index_mask = spi->cs_index_mask;
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+ 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);
else
@@ -2354,7 +2354,7 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,
static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
struct device_node *nc)
{
- u32 value, cs[SPI_CS_CNT_MAX];
+ u32 value, cs[SPI_DEVICE_CS_CNT_MAX];
int rc, idx;
/* Mode (clock phase/polarity/etc.) */
@@ -2429,7 +2429,7 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
/* Device address */
rc = of_property_read_variable_u32_array(nc, "reg", &cs[0], 1,
- SPI_CS_CNT_MAX);
+ SPI_DEVICE_CS_CNT_MAX);
if (rc < 0) {
dev_err(&ctlr->dev, "%pOF has no valid 'reg' property (%d)\n",
nc, rc);
@@ -3313,7 +3313,7 @@ int spi_register_controller(struct spi_controller *ctlr)
}
/* Setting last_cs to SPI_INVALID_CS means no chip selected */
- for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+ for (idx = 0; idx < SPI_DEVICE_CS_CNT_MAX; idx++)
ctlr->last_cs[idx] = SPI_INVALID_CS;
status = device_add(&ctlr->dev);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index df4842abbc6f..cb2c2df31089 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -21,7 +21,7 @@
#include <uapi/linux/spi/spi.h>
/* Max no. of CS supported per spi device */
-#define SPI_CS_CNT_MAX 4
+#define SPI_DEVICE_CS_CNT_MAX 4
struct dma_chan;
struct software_node;
@@ -229,7 +229,7 @@ struct spi_device {
struct spi_delay cs_hold;
struct spi_delay cs_inactive;
- u8 chip_select[SPI_CS_CNT_MAX];
+ u8 chip_select[SPI_DEVICE_CS_CNT_MAX];
u8 num_chipselect;
/*
@@ -238,9 +238,9 @@ struct spi_device {
* multiple chip selects & memories are connected in parallel
* then more than one bit need to be set in cs_index_mask.
*/
- u32 cs_index_mask : SPI_CS_CNT_MAX;
+ u32 cs_index_mask : SPI_DEVICE_CS_CNT_MAX;
- struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX]; /* Chip select gpio desc */
+ struct gpio_desc *cs_gpiod[SPI_DEVICE_CS_CNT_MAX]; /* Chip select gpio desc */
/*
* Likely need more hooks for more protocol options affecting how
@@ -721,8 +721,8 @@ struct spi_controller {
bool auto_runtime_pm;
bool fallback;
bool last_cs_mode_high;
- s8 last_cs[SPI_CS_CNT_MAX];
- u32 last_cs_index_mask : SPI_CS_CNT_MAX;
+ s8 last_cs[SPI_DEVICE_CS_CNT_MAX];
+ u32 last_cs_index_mask : SPI_DEVICE_CS_CNT_MAX;
struct completion xfer_completion;
size_t max_dma_len;
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
` (6 preceding siblings ...)
2025-09-15 18:37 ` [PATCH v2 7/7] spi: rename SPI_CS_CNT_MAX => SPI_DEVICE_CS_CNT_MAX Jonas Gorski
@ 2025-09-23 11:25 ` Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2025-09-23 11:25 UTC (permalink / raw)
To: Amit Kumar Mahapatra, Jonas Gorski
Cc: linux-spi, linux-kernel, Marc Kleine-Budde
On Mon, 15 Sep 2025 20:37:18 +0200, Jonas Gorski wrote:
> This series aims at cleaning up the current multi CS parts and removing
> the CS limit per controller that was introduced with the multi CS
> support.
>
> To do this, store the assigned chip selects per device in
> spi_device::num_chipselects, which allows us to use that instead of
> SPI_CS_CNT_MAX for most loops, as well as remove the check for
> SPI_INVALID_CS for any chip select.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/7] spi: fix return code when spi device has too many chipselects
commit: 188f63235bcdd207646773a8739387d85347ed76
[2/7] spi: keep track of number of chipselects in spi_device
commit: 099f942182e3695554cba44e4bafb08a4111b50f
[3/7] spi: move unused device CS initialization to __spi_add_device()
commit: 1c923f624439b26b6740cdd2a9f7a12b1968f3f3
[4/7] spi: drop check for validity of device chip selects
commit: f3982daccf42cefcd80218c76a6b5dd134fe97e3
[5/7] spi: don't check spi_controller::num_chipselect when parsing a dt device
commit: 83c522fb642384aef43697aa5c7686363e9e92dd
[6/7] spi: reduce device chip select limit again
commit: 08fda410bae41cc8dde9697f9104da525be53153
[7/7] spi: rename SPI_CS_CNT_MAX => SPI_DEVICE_CS_CNT_MAX
commit: e336ab509b43ea601801dfa05b4270023c3ed007
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 9+ messages in thread