Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b2fef87

Browse files
committed
Merge branch 'net-dsa-microchip-fix-writes-to-phy-registers-0x10'
Rasmus Villemoes says: ==================== net: dsa: microchip: fix writes to phy registers >= 0x10 Patch 1 is just a simplification, technically unrelated to the other two patches. But it would be a bit inconsistent to have the new ksz_prmw32() introduced in patch 2 use ksz_rmw32() while leaving ksz_prmw8() as-is. The actual fix is of course patch 3. I can definitely see some weird behaviour on our ksz9567 when writing to phy registers 0x1e and 0x1f (with phytool from userspace), though it does not seem that the effect is always to write zeroes to the buddy register as the errata sheet says would be the case. In our case, the switch is connected via i2c; I hope somebody with other switches and/or the SPI variants can test this. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 0c3d6fd + 5c844d5 commit b2fef87

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

drivers/net/dsa/microchip/ksz9477.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,27 @@ int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
329329

330330
int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
331331
{
332+
u32 mask, val32;
333+
332334
/* No real PHY after this. */
333335
if (!dev->info->internal_phy[addr])
334336
return 0;
335337

336-
return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
338+
if (reg < 0x10)
339+
return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
340+
341+
/* Errata: When using SPI, I2C, or in-band register access,
342+
* writes to certain PHY registers should be performed as
343+
* 32-bit writes instead of 16-bit writes.
344+
*/
345+
val32 = val;
346+
mask = 0xffff;
347+
if ((reg & 1) == 0) {
348+
val32 <<= 16;
349+
mask <<= 16;
350+
}
351+
reg &= ~1;
352+
return ksz_prmw32(dev, addr, 0x100 + (reg << 1), mask, val32);
337353
}
338354

339355
void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,17 +578,15 @@ static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
578578
static inline int ksz_prmw8(struct ksz_device *dev, int port, int offset,
579579
u8 mask, u8 val)
580580
{
581-
int ret;
582-
583-
ret = regmap_update_bits(ksz_regmap_8(dev),
584-
dev->dev_ops->get_port_addr(port, offset),
585-
mask, val);
586-
if (ret)
587-
dev_err(dev->dev, "can't rmw 8bit reg 0x%x: %pe\n",
588-
dev->dev_ops->get_port_addr(port, offset),
589-
ERR_PTR(ret));
581+
return ksz_rmw8(dev, dev->dev_ops->get_port_addr(port, offset),
582+
mask, val);
583+
}
590584

591-
return ret;
585+
static inline int ksz_prmw32(struct ksz_device *dev, int port, int offset,
586+
u32 mask, u32 val)
587+
{
588+
return ksz_rmw32(dev, dev->dev_ops->get_port_addr(port, offset),
589+
mask, val);
592590
}
593591

594592
static inline void ksz_regmap_lock(void *__mtx)

0 commit comments

Comments
 (0)