spi: Assume GPIO CS active high in ACPI case
PATCH v2 1/1 spi: Assume GPIO CS active high in ACPI case
Currently GPIO CS handling, when descriptors are in use, doesn't take into consideration that in ACPI case the default polarity is Active High and can't be altered. Instead we have to use the per-chip definition provided by SPISerialBus() resource.
---
v2: refactor to avoid ternary (Mark, Sven), dropped comment changes (Mark)
drivers/spi/spi.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/spi/spi.c +18 -4
@@ -820,15 +820,29 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)if (spi->cs_gpiod ||gpio_is_valid (spi->cs_gpio)) {if (!(spi->mode &SPI_NO_CS )) { -if (spi->cs_gpiod) -/* polarity handled by gpiolib */ -gpiod_set_value_cansleep (spi->cs_gpiod, activate); -else +if (spi->cs_gpiod) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep (spi->cs_gpiod, !enable); +else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi->cs_gpiod, activate); + }else {/* * invert the enable line, as active low is * default for SPI. */ gpio_set_value_cansleep (spi->cs_gpio, !enable); + } }/* Some SPI masters need both GPIO CS & slave_select */ if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
Signature · 1 line
2.30.2
Quoted 5 lines · Andy Shevchenko
Currently GPIO CS handling, when descriptors are in use, doesn't take into consideration that in ACPI case the default polarity is Active High and can't be altered. Instead we have to use the per-chip definition provided by
SPISerialBus()resource.
I don't have access to the hardware to test this right now, but the patch is small enough to determine that the OF case will stay the same.
LGTM.
Quoted 31 lines · Andy Shevchenko
Currently GPIO CS handling, when descriptors are in use, doesn't take into consideration that in ACPI case the default polarity is Active High and can't be altered. Instead we have to use the per-chip definition provided by
SPISerialBus()resource.Fixes 766c6b63aa04 ("spi: fix client driver breakages when using GPIO descriptors")Cc Liguang Zhang <[email protected]>Cc Jay Fang <[email protected]>Cc Sven Van Asbroeck <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Tested-by Xin Hao <[email protected]>---
v2: refactor to avoid ternary (Mark, Sven), dropped comment changes (Mark)drivers/spi/spi.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)drivers/spi/spi.c +3
-4@@ -820,15 +820,29 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)if (spi->cs_gpiod ||gpio_is_valid (spi->cs_gpio)) {if (!(spi->mode &SPI_NO_CS )) { -if (spi->cs_gpiod) -/* polarity handled by gpiolib */ -gpiod_set_value_cansleep (spi->cs_gpiod, activate); -else +if (spi->cs_gpiod) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_set_cs(struct spi_device *spi, bool enable, bool force) · line 835
Quoted 10 lines
drivers/spi/spi.c +10
-0+* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep (spi->cs_gpiod, !enable);
it worked and code changed minimally, before ACPI & OF keeps no same rules, this patch is ok!
Quoted 13 lines
drivers/spi/spi.c +5
-0+else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi->cs_gpiod, activate); + }else {/* * invert the enable line, as active low is * default for SPI. */ gpio_set_value_cansleep (spi->cs_gpio, !enable); + } }/* Some SPI masters need both GPIO CS & slave_select */ if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
Signature · 2 lines
Best Regards! Xin Hao
Mark Brown
maintainerQuoted 4 lines · Andy Shevchenko
Currently GPIO CS handling, when descriptors are in use, doesn't take into consideration that in ACPI case the default polarity is Active High and can't be altered. Instead we have to use the per-chip definition provided by
SPISerialBus()resource.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: Assume GPIO CS active high in ACPI case
commit: 6b69546912a57ff8c31061f98e56383cc0beffd3
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