From b85f3f3e1ff5b0327c5b79a500166bb89b2d31c8 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Tue, 16 Jun 2020 10:23:03 +0100 Subject: [PATCH 1/3] Revert "SQUASH: Fix spi driver compiler warnings" This reverts commit fe3f696b7e5229678ae45d1293e97b5ecc00c245. See: https://github.com/raspberrypi/linux/pull/3687 --- drivers/spi/spi-bcm2835.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index dc759de7124b7c..c2e7a2dbbcc7aa 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1230,6 +1230,8 @@ static int bcm2835_spi_setup(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller; struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); + struct gpio_chip *chip; + enum gpio_lookup_flags lflags; u32 cs; /* From ec82bb5428a15289f63569c45652ae76fa048975 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Tue, 16 Jun 2020 10:23:29 +0100 Subject: [PATCH 2/3] Revert "spi: spi-bcm2835: Disable forced software CS" This reverts commit 2697f0186db346176832b8eb79adaf5c874681e8. See: https://github.com/raspberrypi/linux/pull/3687 --- drivers/spi/spi-bcm2835.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index c2e7a2dbbcc7aa..9dccfbaa2e1d27 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1283,6 +1283,43 @@ static int bcm2835_spi_setup(struct spi_device *spi) return -EINVAL; } + /* + * Translate native CS to GPIO + * + * FIXME: poking around in the gpiolib internals like this is + * not very good practice. Find a way to locate the real problem + * and fix it. Why is the GPIO descriptor in spi->cs_gpiod + * sometimes not assigned correctly? Erroneous device trees? + */ + + /* get the gpio chip for the base */ + chip = gpiochip_find("pinctrl-bcm2835", chip_match_name); + if (!chip) + return 0; + + /* + * Retrieve the corresponding GPIO line used for CS. + * The inversion semantics will be handled by the GPIO core + * code, so we pass GPIOS_OUT_LOW for "unasserted" and + * the correct flag for inversion semantics. The SPI_CS_HIGH + * on spi->mode cannot be checked for polarity in this case + * as the flag use_gpio_descriptors enforces SPI_CS_HIGH. + */ + if (of_property_read_bool(spi->dev.of_node, "spi-cs-high")) + lflags = GPIO_ACTIVE_HIGH; + else + lflags = GPIO_ACTIVE_LOW; + spi->cs_gpiod = gpiochip_request_own_desc(chip, 8 - spi->chip_select, + DRV_NAME, + lflags, + GPIOD_OUT_LOW); + if (IS_ERR(spi->cs_gpiod)) + return PTR_ERR(spi->cs_gpiod); + + /* and set up the "mode" and level */ + dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n", + spi->chip_select); + return 0; } From 66bc874381c4208446dd4c1f2c4ec9aec8d0f92d Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Tue, 16 Jun 2020 10:23:42 +0100 Subject: [PATCH 3/3] Revert "spi: spi-bcm2835: Re-enable HW CS" This reverts commit 49b9bd89784e3fa29f143ebf1ac8f125be47b708. See: https://github.com/raspberrypi/linux/pull/3687 --- drivers/spi/spi-bcm2835.c | 53 ++------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 9dccfbaa2e1d27..6899558fcba209 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1173,57 +1173,9 @@ static void bcm2835_spi_handle_err(struct spi_controller *ctlr, bcm2835_spi_reset_hw(ctlr); } -static void bcm2835_spi_set_cs(struct spi_device *spi, bool gpio_level) +static int chip_match_name(struct gpio_chip *chip, void *data) { - /* - * we can assume that we are "native" as per spi_set_cs - * calling us ONLY when cs_gpio is not set - * we can also assume that we are CS < 3 as per bcm2835_spi_setup - * we would not get called because of error handling there. - * the level passed is the electrical level not enabled/disabled - * so it has to get translated back to enable/disable - * see spi_set_cs in spi.c for the implementation - */ - - struct spi_master *master = spi->master; - struct bcm2835_spi *bs = spi_master_get_devdata(master); - u32 cs = bcm2835_rd(bs, BCM2835_SPI_CS); - bool enable; - - /* calculate the enable flag from the passed gpio_level */ - enable = (spi->mode & SPI_CS_HIGH) ? gpio_level : !gpio_level; - - /* set flags for "reverse" polarity in the registers */ - if (spi->mode & SPI_CS_HIGH) { - /* set the correct CS-bits */ - cs |= BCM2835_SPI_CS_CSPOL; - cs |= BCM2835_SPI_CS_CSPOL0 << spi->chip_select; - } else { - /* clean the CS-bits */ - cs &= ~BCM2835_SPI_CS_CSPOL; - cs &= ~(BCM2835_SPI_CS_CSPOL0 << spi->chip_select); - } - - /* select the correct chip_select depending on disabled/enabled */ - if (enable) { - /* set cs correctly */ - if (spi->mode & SPI_NO_CS) { - /* use the "undefined" chip-select */ - cs |= BCM2835_SPI_CS_CS_10 | BCM2835_SPI_CS_CS_01; - } else { - /* set the chip select */ - cs &= ~(BCM2835_SPI_CS_CS_10 | BCM2835_SPI_CS_CS_01); - cs |= spi->chip_select; - } - } else { - /* disable CSPOL which puts HW-CS into deselected state */ - cs &= ~BCM2835_SPI_CS_CSPOL; - /* use the "undefined" chip-select as precaution */ - cs |= BCM2835_SPI_CS_CS_10 | BCM2835_SPI_CS_CS_01; - } - - /* finally set the calculated flags in SPI_CS */ - bcm2835_wr(bs, BCM2835_SPI_CS, cs); + return !strcmp(chip->label, data); } static int bcm2835_spi_setup(struct spi_device *spi) @@ -1341,7 +1293,6 @@ static int bcm2835_spi_probe(struct platform_device *pdev) ctlr->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->num_chipselect = BCM2835_SPI_NUM_CS; ctlr->setup = bcm2835_spi_setup; - ctlr->set_cs = bcm2835_spi_set_cs; ctlr->transfer_one = bcm2835_spi_transfer_one; ctlr->handle_err = bcm2835_spi_handle_err; ctlr->prepare_message = bcm2835_spi_prepare_message;