lkml.org 
[lkml]   [2019]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] mfd: mc13xxx-spi: Do not hardcode SPI mode flags
Date
The current use of mode flags to us SPI_MODE_0 and
SPI_CS_HIGH is fragile: it overwrites anything already
assigned by the SPI core. Change it thusly:

- Just |= the SPI_MODE_0 so we keep other flags
- Assign ^= SPI_CS_HIGH since we might be active high
already, and that is usually the case with GPIOs used
for chip select, even if they are in practice active low.

Add a comment clarifying why ^= SPI_CS_HIGH is the right
choice here.

Reported-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/mfd/mc13xxx-spi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index 286ddcf5ddc6..9885e5f8210a 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -134,7 +134,13 @@ static int mc13xxx_spi_probe(struct spi_device *spi)

dev_set_drvdata(&spi->dev, mc13xxx);

- spi->mode = SPI_MODE_0 | SPI_CS_HIGH;
+ spi->mode |= SPI_MODE_0;
+ /*
+ * We want the inverse of what is set in the SPI core, if this
+ * is accomplished with a GPIO line then inversion semantics may
+ * be handled in the GPIO library.
+ */
+ spi->mode ^= SPI_CS_HIGH;

mc13xxx->irq = spi->irq;

--
2.23.0
\
 
 \ /
  Last update: 2019-12-04 16:29    [W:2.991 / U:0.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site