790-46-v6.9-net-dsa-mt7530-fix-improper-frames-on-all-25MHz-and-.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From cfa7c85f92cd3814ad9748eb1ab25658c7f7cc67 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <[email protected]>
  3. Date: Wed, 20 Mar 2024 23:45:30 +0300
  4. Subject: [PATCH 48/48] net: dsa: mt7530: fix improper frames on all 25MHz and
  5. 40MHz XTAL MT7530
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. The MT7530 switch after reset initialises with a core clock frequency that
  10. works with a 25MHz XTAL connected to it. For 40MHz XTAL, the core clock
  11. frequency must be set to 500MHz.
  12. The mt7530_pll_setup() function is responsible of setting the core clock
  13. frequency. Currently, it runs on MT7530 with 25MHz and 40MHz XTAL. This
  14. causes MT7530 switch with 25MHz XTAL to egress and ingress frames
  15. improperly.
  16. Introduce a check to run it only on MT7530 with 40MHz XTAL.
  17. The core clock frequency is set by writing to a switch PHY's register.
  18. Access to the PHY's register is done via the MDIO bus the switch is also
  19. on. Therefore, it works only when the switch makes switch PHYs listen on
  20. the MDIO bus the switch is on. This is controlled either by the state of
  21. the ESW_P1_LED_1 pin after reset deassertion or modifying bit 5 of the
  22. modifiable trap register.
  23. When ESW_P1_LED_1 is pulled high, PHY indirect access is used. That means
  24. accessing PHY registers via the PHY indirect access control register of the
  25. switch.
  26. When ESW_P1_LED_1 is pulled low, PHY direct access is used. That means
  27. accessing PHY registers via the MDIO bus the switch is on.
  28. For MT7530 switch with 40MHz XTAL on a board with ESW_P1_LED_1 pulled high,
  29. the core clock frequency won't be set to 500MHz, causing the switch to
  30. egress and ingress frames improperly.
  31. Run mt7530_pll_setup() after PHY direct access is set on the modifiable
  32. trap register.
  33. With these two changes, all MT7530 switches with 25MHz and 40MHz, and
  34. P1_LED_1 pulled high or low, will egress and ingress frames properly.
  35. Link: https://github.com/BPI-SINOVOIP/BPI-R2-bsp/blob/4a5dd143f2172ec97a2872fa29c7c4cd520f45b5/linux-mt/drivers/net/ethernet/mediatek/gsw_mt7623.c#L1039
  36. Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
  37. Signed-off-by: Arınç ÜNAL <[email protected]>
  38. Link: https://lore.kernel.org/r/20240320-for-net-mt7530-fix-25mhz-xtal-with-direct-phy-access-v1-1-d92f605f1160@arinc9.com
  39. Signed-off-by: Paolo Abeni <[email protected]>
  40. ---
  41. drivers/net/dsa/mt7530.c | 5 +++--
  42. 1 file changed, 3 insertions(+), 2 deletions(-)
  43. --- a/drivers/net/dsa/mt7530.c
  44. +++ b/drivers/net/dsa/mt7530.c
  45. @@ -2259,8 +2259,6 @@ mt7530_setup(struct dsa_switch *ds)
  46. SYS_CTRL_PHY_RST | SYS_CTRL_SW_RST |
  47. SYS_CTRL_REG_RST);
  48. - mt7530_pll_setup(priv);
  49. -
  50. /* Lower Tx driving for TRGMII path */
  51. for (i = 0; i < NUM_TRGMII_CTRL; i++)
  52. mt7530_write(priv, MT7530_TRGMII_TD_ODT(i),
  53. @@ -2276,6 +2274,9 @@ mt7530_setup(struct dsa_switch *ds)
  54. val |= MHWTRAP_MANUAL;
  55. mt7530_write(priv, MT7530_MHWTRAP, val);
  56. + if ((val & HWTRAP_XTAL_MASK) == HWTRAP_XTAL_40MHZ)
  57. + mt7530_pll_setup(priv);
  58. +
  59. mt753x_trap_frames(priv);
  60. /* Enable and reset MIB counters */