[PATCH/RFC 6/6] spi: bcm2835: set gpio-cs to high state prior to any

Martin Sperl kernel at martin.sperl.org
Sun Mar 29 07:03:28 PDT 2015


 device initialization

The situation has been observed that on the RPI after a reboot the
GPIOs used for chip-selects are set to low when pinctl finishes setting
up the direction of the pins.

This can negatively impact the spi-bus and inhibit propper device
detection.

This (incomplete) code pulls the CS high to avoid the situation in the
common case of "normal" CS-priority - it still needs a revisit to get
the reverse polarity cases right as well.

A variation of this probably should get moved into spi_register_master
to fix this for other spi-controller as well.

Signed-off-by: Martin Sperl <kernel at martin.sperl.org>
Tested-by: Martin Sperl <kernel at martin.sperl.org>

---
 drivers/spi/spi-bcm2835.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Applies against spi - topic/bcm2835.

diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index 1d731b8..b6825a4 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -349,6 +349,26 @@ static int bcm2835_spi_setup(struct spi_device *spi)
 	return -EINVAL;
 }
 
+static void bcm2835_spi_initialsetup_gpio(struct spi_master *master)
+{
+	int i;
+	bool level;
+
+	if (!master->cs_gpios)
+		return;
+
+	for (i = 0; i < master->num_chipselect; i++) {
+		if (gpio_is_valid(master->cs_gpios[i])) {
+			/* actually we need to figure out the
+			 * configured CSPOL of that device here,
+			 * not sure how to do that...
+			 */
+			level = true;
+			gpio_set_value(master->cs_gpios[i], level);
+		}
+	}
+}
+
 static int bcm2835_spi_probe(struct platform_device *pdev)
 {
 	struct spi_master *master;
@@ -414,6 +434,9 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 		goto out_clk_disable;
 	}
 
+	/* set GPIO-CS to disabled */
+	bcm2835_spi_initialsetup_gpio(master);
+
 	return 0;
 
 out_clk_disable:
-- 
1.7.10.4





More information about the linux-rpi-kernel mailing list