The MDIO address of the MT7530 and MT7531 switch ICs can be configured
using bootstrap pins. However, there are only 4 possible options for the
switch itself: 7, 15, 23 and 31. As in MediaTek's SDK the address of the
switch is wrongly stated in the device tree as 0 (while in reality it is
31), warn the user about such broken device tree and make a good guess
what was actually intended.
This is imporant also to not break compatibility with older Device Trees
as with commit 868ff5f4944a ("net: dsa: mt7530-mdio: read PHY address of
switch from device tree") the address in device tree will be taken into
account, while before it was hard-coded to 0x1f.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Daniel Golle <daniel@xxxxxxxxxxxxxx>
---
Only tested on BPi-R3 (with various deliberately broken DT) for now!
Changes since v2 [2]:
- use macros instead of magic numbers
- introduce helper functions
- register new device on MDIO bus instead of messing with the address
and schedule delayed_work to unregister the "wrong" device.
This is a slightly different approach than suggested by Russell, but
imho makes things much easier than keeping the "wrong" device and
having to deal with keeping the removal of both devices linked.
- improve comments
Changes since v1 [1]:
- use FW_WARN as suggested.
- fix build on net tree which doesn't have 'mdiodev' as member of the
priv struct. Imho including this patch as fix makes sense to warn
users about broken firmware, even if the change introducing the
actual breakage is only present in net-next for now.
[1]: https://patchwork.kernel.org/project/netdevbpf/patch/e615351aefba25e990215845e4812e6cb8153b28.1714433716.git.daniel@xxxxxxxxxxxxxx/
[2]: https://patchwork.kernel.org/project/netdevbpf/patch/11f5f127d0350e72569c36f9060b6e642dfaddbb.1714514208.git.daniel@xxxxxxxxxxxxxx/