spi: bcm2835: Increase the CS limit to 24
authorPhil Elwell <phil@raspberrypi.com>
Fri, 30 Apr 2021 07:34:36 +0000 (08:34 +0100)
committerPhil Elwell <phil@raspberrypi.com>
Fri, 30 Apr 2021 07:42:16 +0000 (08:42 +0100)
Increase the maximum number of CS lines to 24, and ensure this limit is
not exceeded.

See: https://github.com/raspberrypi/linux/pull/4281

Suggested-by: Joe Burmeister <joe.burmeister@devtank.co.uk>
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
drivers/spi/spi-bcm2835.c

index aab6c7e..ae74d86 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h> /* FIXME: using chip internals */
 #include <linux/gpio/driver.h> /* FIXME: using chip internals */
+#include <linux/of_gpio.h>
 #include <linux/of_irq.h>
 #include <linux/spi/spi.h>
 
@@ -68,7 +69,7 @@
 #define BCM2835_SPI_FIFO_SIZE          64
 #define BCM2835_SPI_FIFO_SIZE_3_4      48
 #define BCM2835_SPI_DMA_MIN_LENGTH     96
-#define BCM2835_SPI_NUM_CS             4   /* raise as necessary */
+#define BCM2835_SPI_NUM_CS             24  /* more than enough */
 #define BCM2835_SPI_MODE_BITS  (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
                                | SPI_NO_CS | SPI_3WIRE)
 
@@ -1292,6 +1293,11 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
        struct bcm2835_spi *bs;
        int err;
 
+       if (of_gpio_named_count(pdev->dev.of_node, "cs-gpios") >
+           BCM2835_SPI_NUM_CS)
+               return dev_err_probe(&pdev->dev, -EINVAL,
+                                    "too many chip selects\n");
+
        ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs),
                                                  dma_get_cache_alignment()));
        if (!ctlr)