Skip to content

Commit b06bbbc

Browse files
Sasha Levingregkh
authored andcommitted
spi: dw: Fix native CS being unset
[ Upstream commit 9aea644 ] Commit 6e0a32d ("spi: dw: Fix default polarity of native chipselect") attempted to fix the problem when GPIO active-high chip-select is utilized to communicate with some SPI slave. It fixed the problem, but broke the normal native CS support. At the same time the reversion commit ada9e3f ("spi: dw: Correct handling of native chipselect") didn't solve the problem either, since it just inverted the set_cs() polarity perception without taking into account that CS-high might be applicable. Here is what is done to finally fix the problem. DW SPI controller demands any native CS being set in order to proceed with data transfer. So in order to activate the SPI communications we must set any bit in the Slave Select DW SPI controller register no matter whether the platform requests the GPIO- or native CS. Preferably it should be the bit corresponding to the SPI slave CS number. But currently the dw_spi_set_cs() method activates the chip-select only if the second argument is false. Since the second argument of the set_cs callback is expected to be a boolean with "is-high" semantics (actual chip-select pin state value), the bit in the DW SPI Slave Select register will be set only if SPI core requests the driver to set the CS in the low state. So this will work for active-low GPIO-based CS case, and won't work for active-high CS setting the bit when SPI core actually needs to deactivate the CS. This commit fixes the problem for all described cases. So no matter whether an SPI slave needs GPIO- or native-based CS with active-high or low signal the corresponding bit will be set in SER. Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> Fixes: ada9e3f ("spi: dw: Correct handling of native chipselect") Fixes: 6e0a32d ("spi: dw: Fix default polarity of native chipselect") Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20200515104758.6934-5-Sergey.Semin@baikalelectronics.ru Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eb63150 commit b06bbbc

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎drivers/spi/spi-dw.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,20 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable)
128128
{
129129
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
130130
struct chip_data *chip = spi_get_ctldata(spi);
131+
bool cs_high = !!(spi->mode & SPI_CS_HIGH);
131132

132133
/* Chip select logic is inverted from spi_set_cs() */
133134
if (chip && chip->cs_control)
134135
chip->cs_control(!enable);
135136

136-
if (!enable)
137+
/*
138+
* DW SPI controller demands any native CS being set in order to
139+
* proceed with data transfer. So in order to activate the SPI
140+
* communications we must set a corresponding bit in the Slave
141+
* Enable register no matter whether the SPI core is configured to
142+
* support active-high or active-low CS level.
143+
*/
144+
if (cs_high == enable)
137145
dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select));
138146
else if (dws->cs_override)
139147
dw_writel(dws, DW_SPI_SER, 0);

0 commit comments

Comments
 (0)