linux-stable/drivers/net/dsa
Arınç ÜNAL f490c492e9 net: dsa: mt7530: prevent possible incorrect XTAL frequency selection
On MT7530, the HT_XTAL_FSEL field of the HWTRAP register stores a 2-bit
value that represents the frequency of the crystal oscillator connected to
the switch IC. The field is populated by the state of the ESW_P4_LED_0 and
ESW_P4_LED_0 pins, which is done right after reset is deasserted.

  ESW_P4_LED_0    ESW_P3_LED_0    Frequency
  -----------------------------------------
  0               0               Reserved
  0               1               20MHz
  1               0               40MHz
  1               1               25MHz

On MT7531, the XTAL25 bit of the STRAP register stores this. The LAN0LED0
pin is used to populate the bit. 25MHz when the pin is high, 40MHz when
it's low.

These pins are also used with LEDs, therefore, their state can be set to
something other than the bootstrapping configuration. For example, a link
may be established on port 3 before the DSA subdriver takes control of the
switch which would set ESW_P3_LED_0 to high.

Currently on mt7530_setup() and mt7531_setup(), 1000 - 1100 usec delay is
described between reset assertion and deassertion. Some switch ICs in real
life conditions cannot always have these pins set back to the bootstrapping
configuration before reset deassertion in this amount of delay. This causes
wrong crystal frequency to be selected which puts the switch in a
nonfunctional state after reset deassertion.

The tests below are conducted on an MT7530 with a 40MHz crystal oscillator
by Justin Swartz.

With a cable from an active peer connected to port 3 before reset, an
incorrect crystal frequency (0b11 = 25MHz) is selected:

                      [1]                  [3]     [5]
                      :                    :       :
              _____________________________         __________________
ESW_P4_LED_0                               |_______|
              _____________________________
ESW_P3_LED_0                               |__________________________

                       :                  : :     :
                       :                  : [4]...:
                       :                  :
                       [2]................:

[1] Reset is asserted.
[2] Period of 1000 - 1100 usec.
[3] Reset is deasserted.
[4] Period of 315 usec. HWTRAP register is populated with incorrect
    XTAL frequency.
[5] Signals reflect the bootstrapped configuration.

Increase the delay between reset_control_assert() and
reset_control_deassert(), and gpiod_set_value_cansleep(priv->reset, 0) and
gpiod_set_value_cansleep(priv->reset, 1) to 5000 - 5100 usec. This amount
ensures a higher possibility that the switch IC will have these pins back
to the bootstrapping configuration before reset deassertion.

With a cable from an active peer connected to port 3 before reset, the
correct crystal frequency (0b10 = 40MHz) is selected:

                      [1]        [2-1]     [3]     [5]
                      :          :         :       :
              _____________________________         __________________
ESW_P4_LED_0                               |_______|
              ___________________           _______
ESW_P3_LED_0                     |_________|       |__________________

                       :          :       : :     :
                       :          [2-2]...: [4]...:
                       [2]................:

[1] Reset is asserted.
[2] Period of 5000 - 5100 usec.
[2-1] ESW_P3_LED_0 goes low.
[2-2] Remaining period of 5000 - 5100 usec.
[3] Reset is deasserted.
[4] Period of 310 usec. HWTRAP register is populated with bootstrapped
    XTAL frequency.
[5] Signals reflect the bootstrapped configuration.

ESW_P3_LED_0 low period before reset deassertion:

              5000 usec
            - 5100 usec
    TEST     RESET HOLD
       #         (usec)
  ---------------------
       1           5410
       2           5440
       3           4375
       4           5490
       5           5475
       6           4335
       7           4370
       8           5435
       9           4205
      10           4335
      11           3750
      12           3170
      13           4395
      14           4375
      15           3515
      16           4335
      17           4220
      18           4175
      19           4175
      20           4350

     Min           3170
     Max           5490

  Median       4342.500
     Avg       4466.500

Revert commit 2920dd92b9 ("net: dsa: mt7530: disable LEDs before reset").
Changing the state of pins via reset assertion is simpler and more
efficient than doing so by setting the LED controller off.

Fixes: b8f126a8d5 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Fixes: c288575f78 ("net: dsa: mt7530: Add the support of MT7531 switch")
Co-developed-by: Justin Swartz <justin.swartz@risingedge.co.za>
Signed-off-by: Justin Swartz <justin.swartz@risingedge.co.za>
Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-18 12:28:20 +00:00
..
b53 net: dsa: b53: unexport and move b53_eee_enable_set() 2024-02-08 19:03:46 -08:00
hirschmann net: dsa: hirschmann: Convert to platform remove callback returning void 2023-09-20 10:25:57 +01:00
microchip Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-03-11 20:38:36 -07:00
mv88e6xxx net: dsa: mv88e6xxx: update 88e6185 PCS driver to use neg_mode 2024-03-07 20:50:17 -08:00
ocelot net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
qca net: dsa: qca8k: consistently use "ret" rather than "err" for error codes 2024-02-05 12:39:27 +00:00
realtek net: dsa: realtek: support reset controller 2024-02-28 08:21:41 +00:00
sja1105 net: dsa: sja1105: Use units.h instead of the copy of a definition 2023-11-29 20:12:17 -08:00
xrs700x net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
bcm_sf2.c ethtool: replace struct ethtool_eee with a new struct ethtool_keee on kernel side 2024-01-31 12:30:47 +00:00
bcm_sf2.h net: dsa: bcm_sf2: drop priv->master_mii_dn 2024-01-05 11:56:36 +00:00
bcm_sf2_cfp.c net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
bcm_sf2_regs.h
dsa_loop.c net: dsa: dsa_loop: add phylink capabilities 2023-10-11 10:06:05 +01:00
dsa_loop.h
dsa_loop_bdinfo.c net: fill in MODULE_DESCRIPTION()s for dsa_loop_bdinfo 2024-02-09 14:12:02 -08:00
Kconfig net: dsa: mt7530: select MEDIATEK_GE_PHY for NET_DSA_MT7530_MDIO 2024-01-26 20:31:52 -08:00
lan9303-core.c net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
lan9303.h
lan9303_i2c.c net: dsa: Switch i2c drivers back to use .probe() 2023-05-31 09:52:55 +01:00
lan9303_mdio.c net: dsa: lan9303: consequently nested-lock physical MDIO 2023-11-02 10:48:09 +01:00
lantiq_gswip.c net: dsa: lantiq_gswip: ignore MDIO buses disabled in OF 2024-01-05 11:56:35 +00:00
lantiq_pce.h
Makefile net: dsa: mt7530: introduce driver for MT7988 built-in switch 2023-04-03 10:13:01 +01:00
mt7530-mdio.c net: dsa: mt7530: store port 5 SGMII capability of MT7531 2024-01-29 18:04:11 -08:00
mt7530-mmio.c net: dsa: mt7530: Convert to platform remove callback returning void 2023-09-20 10:25:57 +01:00
mt7530.c net: dsa: mt7530: prevent possible incorrect XTAL frequency selection 2024-03-18 12:28:20 +00:00
mt7530.h net: dsa: mt7530: simplify link operations 2024-03-05 12:23:43 +01:00
mv88e6060.c net: dsa: mv88e6060: add phylink_get_caps implementation 2023-08-14 18:57:17 -07:00
mv88e6060.h
rzn1_a5psw.c net: dsa: rzn1_a5psw: Convert to platform remove callback returning void 2023-09-20 10:25:58 +01:00
rzn1_a5psw.h net: dsa: rzn1-a5psw: add vlan support 2023-08-11 11:58:36 +01:00
vitesse-vsc73xx-core.c net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe 2024-01-16 17:48:27 -08:00
vitesse-vsc73xx-platform.c net: dsa: vitesse-vsc73xx: Convert to platform remove callback returning void 2023-09-20 10:25:58 +01:00
vitesse-vsc73xx-spi.c net: dsa: vitesse-vsc73xx: remove unnecessary set_drvdata() 2022-09-22 19:30:39 -07:00
vitesse-vsc73xx.h