spi: dw: Correct handling of native chipselect
PATCH 1/1 spi: dw: Correct handling of native chipselect
This patch reverts commit 6e0a32d6f376 ("spi: dw: Fix default polarity of native chipselect").
The SPI framework always called the set_cs callback with the logic level it desired on the chip select line, which is what the drivers original handling supported. commit f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs") changed these symantics, but only in the case of drivers that also support GPIO chip selects, to true meaning apply slave select rather than logic high. This left things in an odd state where a driver that only supports hardware chip selects, the core would handle polarity but if the driver supported GPIOs as well the driver should handle polarity. At this point the reverted change was applied to change the logic in the driver to match new system.
This was then broken by commit 3e5ec1db8bfe ("spi: Fix SPI_CS_HIGH setting when using native and GPIO CS") which reverted the core back to consistently calling set_cs with a logic level.
This fix reverts the driver code back to its original state to match the current core code. This is probably a better fix as a) the set_cs callback is always called with consistent symantics and b) the inversion for SPI_CS_HIGH can be handled in the core and doesn't need to be coded in each driver supporting it.
---
This is only build tested on my end, and I really think it would benefit for someone actually testing it incase I have missed something.
Also I have updated the commit message a little over the Cadence fix, to include some of the additional information from chatting to Linus. So let me know if you would rather I did a respin of the Cadence fix with an updated commit message as well.
Thanks,
Charles
drivers/spi/spi-dw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +3 -2
@@ -129,10 +129,11 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable)struct dw_spi *dws =spi_controller_get_devdata (spi->controller);struct chip_data *chip =spi_get_ctldata (spi); +/* Chip select logic is inverted from spi_set_cs() */ if (chip && chip->cs_control) - chip->cs_control (enable); + chip->cs_control (!enable); -if (enable) +if (!enable)dw_writel (dws,DW_SPI_SER ,BIT (spi->chip_select));else if (dws->cs_override)dw_writel (dws,DW_SPI_SER ,0 );
Signature · 1 line
2.11.0
Quoted 19 lines · Charles Keepax
This patch reverts commit
6e0a32d6f376("spi: dw: Fix default polarity of native chipselect").The SPI framework always called the
set_cscallback with the logic level it desired on the chip select line, which is what the drivers original handling supported. commitf3186dd87669("spi: Optionally use GPIO descriptors for CS GPIOs") changed these symantics, but only in the case of drivers that also support GPIO chip selects, to true meaning apply slave select rather than logic high. This left things in an odd state where a driver that only supports hardware chip selects, the core would handle polarity but if the driver supported GPIOs as well the driver should handle polarity. At this point the reverted change was applied to change the logic in the driver to match new system.This was then broken by commit
3e5ec1db8bfe("spi: FixSPI_CS_HIGHsetting when using native and GPIO CS") which reverted the core back to consistently callingset_cswith a logic level.
Quoted 8 lines
This fix reverts the driver code back to its original state to match the current core code. This is probably a better fix as a) the
set_cscallback is always called with consistent symantics and b) the inversion forSPI_CS_HIGHcan be handled in the core and doesn't need to be coded in each driver supporting it.Fixes 3e5ec1db8bfe ("spi: Fix SPI_CS_HIGH setting when using native and GPIO CS")Signed-off-by Charles Keepax <[email protected]>
Thanks for looking into this Charles!!
I think we should have all regressions covered with these two patches.
Yours,
Linus Walleij
Mark Brown
maintainerApplied "spi: dw: Correct handling of native chipselect" to the spi tree
In reply to Charles KeepaxThe patch
spi: dw: Correct handling of native chipselect
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.5
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
Quoted 1 line
From
ada9e3fcc175db4538f5b5e05abf5dedf626e550Mon Sep 17 00:00:00 2001
From: Charles Keepax <[email protected]>
Date: Wed, 27 Nov 2019 15:39:36 +0000
Subject: [PATCH] spi: dw: Correct handling of native chipselect
This patch reverts commit 6e0a32d6f376 ("spi: dw: Fix default polarity of native chipselect").
The SPI framework always called the set_cs callback with the logic level it desired on the chip select line, which is what the drivers original handling supported. commit f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs") changed these symantics, but only in the case of drivers that also support GPIO chip selects, to true meaning apply slave select rather than logic high. This left things in an odd state where a driver that only supports hardware chip selects, the core would handle polarity but if the driver supported GPIOs as well the driver should handle polarity. At this point the reverted change was applied to change the logic in the driver to match new system.
This was then broken by commit 3e5ec1db8bfe ("spi: Fix SPI_CS_HIGH setting when using native and GPIO CS") which reverted the core back to consistently calling set_cs with a logic level.
This fix reverts the driver code back to its original state to match the current core code. This is probably a better fix as a) the set_cs callback is always called with consistent symantics and b) the inversion for SPI_CS_HIGH can be handled in the core and doesn't need to be coded in each driver supporting it.
--- drivers/spi/spi-dw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +3 -2
@@ -129,10 +129,11 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable)struct dw_spi *dws =spi_controller_get_devdata (spi->controller);struct chip_data *chip =spi_get_ctldata (spi); +/* Chip select logic is inverted from spi_set_cs() */ if (chip && chip->cs_control) - chip->cs_control (enable); + chip->cs_control (!enable); -if (enable) +if (!enable)dw_writel (dws,DW_SPI_SER ,BIT (spi->chip_select));else if (dws->cs_override)dw_writel (dws,DW_SPI_SER ,0 );
Signature · 1 line
2.20.1