ath79: fix sorting in generic 02_network
[openwrt/staging/ansuel.git] / target / linux / ath79 / patches-5.10 / 0054-spi-sync-up-initial-chipselect-state.patch
1 From 4b7d7f85abac1e7ad9e8b745694e470f0729f527 Mon Sep 17 00:00:00 2001
2 From: David Bauer <mail@david-bauer.net>
3 Date: Wed, 3 Mar 2021 17:11:34 +0100
4 Subject: [PATCH] spi: sync up initial chipselect state
5
6 When initially probing the SPI slave device, the call for disabling an
7 SPI device without the SPI_CS_HIGH flag is not applied, as the
8 condition for checking whether or not the state to be applied equals the
9 one currently set evaluates to true.
10
11 This however might not necessarily be the case, as the chipselect might
12 be active.
13
14 Add a force flag to spi_set_cs which allows to override this
15 early access condition. Set it to false everywhere except when called
16 from spi_setup to sync up the initial CS state.
17
18 Fixes commit d40f0b6f2e21 ("spi: Avoid setting the chip select if we don't
19 need to")
20
21 Signed-off-by: David Bauer <mail@david-bauer.net>
22 ---
23 drivers/spi/spi.c | 16 ++++++++--------
24 1 file changed, 8 insertions(+), 8 deletions(-)
25
26 --- a/drivers/spi/spi.c
27 +++ b/drivers/spi/spi.c
28 @@ -787,7 +787,7 @@ int spi_register_board_info(struct spi_b
29
30 /*-------------------------------------------------------------------------*/
31
32 -static void spi_set_cs(struct spi_device *spi, bool enable)
33 +static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
34 {
35 bool enable1 = enable;
36
37 @@ -795,7 +795,7 @@ static void spi_set_cs(struct spi_device
38 * Avoid calling into the driver (or doing delays) if the chip select
39 * isn't actually changing from the last time this was called.
40 */
41 - if ((spi->controller->last_cs_enable == enable) &&
42 + if (!force && (spi->controller->last_cs_enable == enable) &&
43 (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH)))
44 return;
45
46 @@ -1243,7 +1243,7 @@ static int spi_transfer_one_message(stru
47 struct spi_statistics *statm = &ctlr->statistics;
48 struct spi_statistics *stats = &msg->spi->statistics;
49
50 - spi_set_cs(msg->spi, true);
51 + spi_set_cs(msg->spi, true, false);
52
53 SPI_STATISTICS_INCREMENT_FIELD(statm, messages);
54 SPI_STATISTICS_INCREMENT_FIELD(stats, messages);
55 @@ -1311,9 +1311,9 @@ fallback_pio:
56 &msg->transfers)) {
57 keep_cs = true;
58 } else {
59 - spi_set_cs(msg->spi, false);
60 + spi_set_cs(msg->spi, false, false);
61 _spi_transfer_cs_change_delay(msg, xfer);
62 - spi_set_cs(msg->spi, true);
63 + spi_set_cs(msg->spi, true, false);
64 }
65 }
66
67 @@ -1322,7 +1322,7 @@ fallback_pio:
68
69 out:
70 if (ret != 0 || !keep_cs)
71 - spi_set_cs(msg->spi, false);
72 + spi_set_cs(msg->spi, false, false);
73
74 if (msg->status == -EINPROGRESS)
75 msg->status = ret;
76 @@ -3400,11 +3400,11 @@ int spi_setup(struct spi_device *spi)
77 */
78 status = 0;
79
80 - spi_set_cs(spi, false);
81 + spi_set_cs(spi, false, true);
82 pm_runtime_mark_last_busy(spi->controller->dev.parent);
83 pm_runtime_put_autosuspend(spi->controller->dev.parent);
84 } else {
85 - spi_set_cs(spi, false);
86 + spi_set_cs(spi, false, true);
87 }
88
89 mutex_unlock(&spi->controller->io_mutex);