From: Sven Van Asbroeck <thesve...@gmail.com>

This driver makes sure the underlying SPI bus is set to "mode 0"
by assigning SPI_MODE_0 to spi->mode. Which overwrites all other
SPI mode flags.

In some circumstances, this can break the underlying SPI bus driver.
For example, if SPI_CS_HIGH is set on the SPI bus, the driver
will clear that flag, which results in a chip-select polarity issue.

Fix by changing only the SPI_MODE_N bits, i.e. SPI_CPHA and SPI_CPOL.

Fixes: a8e510f682fe ("phy: Micrel KS8995MA 5-ports 10/100 managed Ethernet 
switch support added")
Fixes: f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
Link: 
https://patchwork.kernel.org/project/spi-devel-general/patch/20201106150706.29089-1-thesve...@gmail.com/#23747737
Signed-off-by: Sven Van Asbroeck <thesve...@gmail.com>
---

Tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git # 
989ef49bdf10

To be followed by a proposed spi helper function. Submit to net-next after net
gets merged into net-next.

# large number of people, from get_maintainer.pl
To: Andrew Lunn <and...@lunn.ch>
To: Heiner Kallweit <hkallwe...@gmail.com>
To: Jakub Kicinski <k...@kernel.org>
Cc: Russell King <li...@armlinux.org.uk>
Cc: "David S. Miller" <da...@davemloft.net>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org

Cc: Mark Brown <broo...@kernel.org>
Cc: Linus Walleij <linus.wall...@linaro.org>
Cc: Andy Shevchenko <andy.shevche...@gmail.com>
Cc: Frederic LAMBERT <frdr...@gmail.com>
Cc: Gabor Juhos <juh...@openwrt.org>
Cc: Jonathan Cameron <jonathan.came...@huawei.com>

# Cc SPI group, suggested by Jakub Kicinski
Cc: linux-...@vger.kernel.org

 drivers/net/phy/spi_ks8995.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/spi_ks8995.c b/drivers/net/phy/spi_ks8995.c
index 4b198399bfa2..3c6c87a09b03 100644
--- a/drivers/net/phy/spi_ks8995.c
+++ b/drivers/net/phy/spi_ks8995.c
@@ -491,7 +491,9 @@ static int ks8995_probe(struct spi_device *spi)
 
        spi_set_drvdata(spi, ks);
 
-       spi->mode = SPI_MODE_0;
+       /* use SPI_MODE_0 without changing any other mode flags */
+       spi->mode &= ~(SPI_CPHA | SPI_CPOL);
+       spi->mode |= SPI_MODE_0;
        spi->bits_per_word = 8;
        err = spi_setup(spi);
        if (err) {
-- 
2.17.1

Reply via email to