net: phy: spi_ks8995: Do not overwrite SPI mode flags
Subsystems (4)
PATCH v2 1/1 net: phy: spi_ks8995: Do not overwrite SPI mode flags
From: Sven Van Asbroeck <[email protected]>
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.
---
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 <[email protected]> To: Heiner Kallweit <[email protected]> To: Jakub Kicinski <[email protected]> Cc: Russell King <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: [email protected] Cc: [email protected]
# Cc SPI group, suggested by Jakub Kicinski
Cc: [email protected]
drivers/net/phy/spi_ks8995.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/spi_ks8995.c +3 -1
@@ -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) {
Signature · 1 line
2.17.1
Quoted 7 lines · Sven Van Asbroeck
From: Sven Van Asbroeck <[email protected]>
This driver makes sure the underlying SPI bus is set to "mode 0" by assigning
SPI_MODE_0tospi->mode. Which overwrites all other SPI mode flags.
Quoted 5 lines
In some circumstances, this can break the underlying SPI bus driver. For example, if
SPI_CS_HIGHis 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_Nbits, i.e.SPI_CPHAandSPI_CPOL.
I see that this is a fix for backporing, but maybe you can send a patches on top of this to:
1) introduce
#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL)
drivers/net/phy/spi_ks8995.c static int ks8995_probe(struct spi_device *spi) · line 495
Quoted 2 lines
drivers/net/phy/spi_ks8995.c +2
-0+/* use SPI_MODE_0 without changing any other mode flags */ + spi->mode &= ~(SPI_CPHA |SPI_CPOL );
2)
spi->mode &= ~SPI_MODE_MASK;
Quoted 1 line
+
spi->mode|=SPI_MODE_0;
?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy, thank you for the feedback.
Quoted 7 lines · Andy Shevchenko
I see that this is a fix for backporing, but maybe you can send a patches on top of this to:
1) introduce#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL) spi->mode &= ~SPI_MODE_MASK;
Andrew Lunn suggested that a spi helper function would probably fit the bill. I am planning to submit that to net-next after this patch is accepted in next (and next is merged into net-next).
I am learning that net is only for the most minimal of fixes.
See the previous discussion here:
https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
PING Jakub
Quoted 8 lines · Andy Shevchenko
I see that this is a fix for backporing, but maybe you can send a patches on top of this to:
1) introduce#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL) spi->mode &= ~SPI_MODE_MASK;Quoted 1 line
+
spi->mode|=SPI_MODE_0;
Jakub,
Is it possible to merge Andy's suggestion into net? Or should this go into net-next?
Thank you,
Sven
Andrew Lunn
maintainerQuoted 10 lines · Sven Van Asbroeck
PING Jakub
Quoted 6 lines · Andy Shevchenko
I see that this is a fix for backporing, but maybe you can send a patches on top of this to:
1) introduce#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL) spi->mode &= ~SPI_MODE_MASK;
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
+
spi->mode|=SPI_MODE_0;Jakub,
Is it possible to merge Andy's suggestion into net? Or should this go into net-next?
I would keep with the minimal fix for the moment, it keeps the dependencies simple.
When you add a helper, it should really be somewhere in the SPI code, not the net code. So we need both the SPI and the net maintainers to cooperate to get the helper merged, and then this driver using the helper.
Andrew
A spi core fix has been accepted which makes this patch unnecessary.
Quoted 17 lines · Sven Van Asbroeck
This driver makes sure the underlying SPI bus is set to "mode 0" by assigning
SPI_MODE_0tospi->mode. Which overwrites all other SPI mode flags.In some circumstances, this can break the underlying SPI bus driver. For example, if
SPI_CS_HIGHis 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_Nbits, i.e.SPI_CPHAandSPI_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")Signed-off-by Sven Van Asbroeck <[email protected]>---