Skip to content

Commit 5c844d5

Browse files
Villemoeskuba-moo
authored andcommitted
net: dsa: microchip: fix writes to phy registers >= 0x10
According to the errata sheets for ksz9477 and ksz9567, writes to the PHY registers 0x10-0x1f (i.e. those located at addresses 0xN120 to 0xN13f) must be done as a 32 bit write to the 4-byte aligned address containing the register, hence requires a RMW in order not to change the adjacent PHY register. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: Simon Horman <simon.horman@corigine.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://lore.kernel.org/r/20230620113855.733526-4-linux@rasmusvillemoes.dk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ece28ec commit 5c844d5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
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)

0 commit comments

Comments
 (0)