1 |
From a223a36225da82a734ccd156c622e76507b4831e Mon Sep 17 00:00:00 2001 |
2 |
From: Linus Walleij <linus.walleij@linaro.org> |
3 |
Date: Mon, 10 Sep 2018 00:28:05 +0200 |
4 |
Subject: [PATCH 060/145] spi: gpio: No MISO does not imply no RX |
5 |
|
6 |
[ Upstream commit abf5feef3ff0cefade0c76be53b59e55fdd46093 ] |
7 |
|
8 |
There is a logical problem in spi-gpio with host just |
9 |
assigning a MOSI line and no MISO: this is interpreted |
10 |
as the host cannot do RX and the host is flagged with |
11 |
SPI_MASTER_NO_RX. |
12 |
|
13 |
This is wrong: since GPIO lines can switch direction, |
14 |
in 3WIRE operation the host will simply reverse the |
15 |
direction of the GPIO line and start reading from it, |
16 |
there is even code for doing this in the driver, but |
17 |
it went unnoticed because it was tested by using a |
18 |
master with 4 wires but a device using just 3 wires. |
19 |
|
20 |
Remove the offending flag. |
21 |
|
22 |
Cc: Andrzej Hajda <a.hajda@samsung.com> |
23 |
Cc: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> |
24 |
Signed-off-by: Linus Walleij <linus.walleij@linaro.org> |
25 |
Signed-off-by: Mark Brown <broonie@kernel.org> |
26 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
27 |
--- |
28 |
drivers/spi/spi-gpio.c | 10 ++++++---- |
29 |
1 file changed, 6 insertions(+), 4 deletions(-) |
30 |
|
31 |
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c |
32 |
index 421bfc7dda67..088772ebef9b 100644 |
33 |
--- a/drivers/spi/spi-gpio.c |
34 |
+++ b/drivers/spi/spi-gpio.c |
35 |
@@ -295,9 +295,11 @@ static int spi_gpio_request(struct device *dev, |
36 |
spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); |
37 |
if (IS_ERR(spi_gpio->miso)) |
38 |
return PTR_ERR(spi_gpio->miso); |
39 |
- if (!spi_gpio->miso) |
40 |
- /* HW configuration without MISO pin */ |
41 |
- *mflags |= SPI_MASTER_NO_RX; |
42 |
+ /* |
43 |
+ * No setting SPI_MASTER_NO_RX here - if there is only a MOSI |
44 |
+ * pin connected the host can still do RX by changing the |
45 |
+ * direction of the line. |
46 |
+ */ |
47 |
|
48 |
spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); |
49 |
if (IS_ERR(spi_gpio->sck)) |
50 |
@@ -423,7 +425,7 @@ static int spi_gpio_probe(struct platform_device *pdev) |
51 |
spi_gpio->bitbang.chipselect = spi_gpio_chipselect; |
52 |
spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction; |
53 |
|
54 |
- if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { |
55 |
+ if ((master_flags & SPI_MASTER_NO_TX) == 0) { |
56 |
spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; |
57 |
spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; |
58 |
spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; |
59 |
-- |
60 |
2.19.1 |
61 |
|