linux-stable/drivers
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
..
accel
accessibility
acpi
amba
android
ata
atm atm: fore200e: Convert to platform remove callback returning void 2024-03-07 20:36:32 -08:00
auxdisplay
base * Mitigate RFDS vulnerability 2024-03-12 09:31:39 -07:00
bcma
block for-6.9/block-20240310 2024-03-11 11:43:44 -07:00
bluetooth Bluetooth: Add new quirk for broken read key length on ATS2851 2024-03-06 17:27:14 -05:00
bus ARM: SoC drivers for 6.9 2024-03-12 10:35:24 -07:00
cache
cdrom cdrom: gdrom: Convert to platform remove callback returning void 2024-03-07 11:53:30 -07:00
cdx
char
clk
clocksource
comedi comedi: comedi_test: Prevent timers rescheduling during deletion 2024-03-05 14:21:45 +00:00
connector
counter
cpufreq
cpuidle
crypto - Add the x86 part of the SEV-SNP host support. This will allow the 2024-03-11 17:44:11 -07:00
cxl
dax
dca
devfreq
dio
dma Updates for the MSI interrupt subsystem and RISC-V initial MSI support: 2024-03-11 14:03:03 -07:00
dma-buf
dpll Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-03-11 20:38:36 -07:00
edac - Add a FRU (Field Replaceable Unit) memory poison manager which 2024-03-11 18:14:06 -07:00
eisa
extcon
firewire firewire: ohci: prevent leak of left-over IRQ on unbind 2024-03-06 22:35:22 +09:00
firmware pstore updates for v6.9-rc1 2024-03-12 14:36:18 -07:00
fpga
fsi
gnss
gpio
gpu A moderatly busy cycle for development this time around. 2024-03-12 15:18:34 -07:00
greybus
hid
hsi
hte
hv
hwmon Rework of APIC enumeration and topology evaluation: 2024-03-11 15:45:55 -07:00
hwspinlock
hwtracing
i2c i2c: aspeed: Fix the dummy irq expected print 2024-03-08 10:10:27 +01:00
i3c
idle
iio
infiniband
input Input updates for v6.8-rc7 2024-03-08 13:06:35 -08:00
interconnect
iommu SoC: device tree updates for 6.9 2024-03-12 10:29:57 -07:00
ipack
irqchip Updates for the MSI interrupt subsystem and RISC-V initial MSI support: 2024-03-11 14:03:03 -07:00
isdn isdn: capi: make capi_class constant 2024-03-07 20:26:24 -08:00
leds
macintosh
mailbox
mcb
md Revert "dm: use queue_limits_set" 2024-03-11 17:11:28 -07:00
media
memory
memstick
message
mfd
misc hardening updates for v6.9-rc1 2024-03-12 14:49:30 -07:00
mmc for-6.9/block-20240310 2024-03-11 11:43:44 -07:00
most
mtd for-6.9/block-20240310 2024-03-11 11:43:44 -07:00
mux
net net: dsa: mt7530: prevent possible incorrect XTAL frequency selection 2024-03-18 12:28:20 +00:00
nfc
ntb
nubus
nvdimm
nvme Networking changes for 6.9. 2024-03-12 17:44:08 -07:00
nvmem
of
opp
parisc
parport
pci Networking changes for 6.9. 2024-03-12 17:44:08 -07:00
pcmcia
peci
perf Updates for the MSI interrupt subsystem and RISC-V initial MSI support: 2024-03-11 14:03:03 -07:00
phy phy: qcom-qmp-combo: fix type-c switch registration 2024-03-06 20:37:37 +05:30
pinctrl
platform Rework of APIC enumeration and topology evaluation: 2024-03-11 15:45:55 -07:00
pmdomain ARM: SoC drivers for 6.9 2024-03-12 10:35:24 -07:00
pnp
power
powercap
pps
ps3
ptp Networking changes for 6.9. 2024-03-12 17:44:08 -07:00
pwm
rapidio
ras - Add a FRU (Field Replaceable Unit) memory poison manager which 2024-03-11 18:14:06 -07:00
regulator regulator: rk808: fix LDO range on RK806 2024-03-04 14:54:32 +00:00
remoteproc
reset
rpmsg
rtc
s390 s390 updates for 6.9 merge window 2024-03-12 10:14:22 -07:00
sbus
scsi for-6.9/block-20240310 2024-03-11 11:43:44 -07:00
sh
siox
slimbus
soc soc: fsl: qbman: Use raw spinlock for cgr_lock 2024-03-13 08:12:02 +00:00
soundwire
spi spi: cs42l43: Don't limit native CS to the first chip select 2024-03-06 17:44:28 +00:00
spmi
ssb
staging Networking changes for 6.9. 2024-03-12 17:44:08 -07:00
target vfs-6.9.super 2024-03-11 10:52:34 -07:00
tc
tee ARM: SoC drivers for 6.9 2024-03-12 10:35:24 -07:00
thermal
thunderbolt
tty Revert "tty: serial: simplify qcom_geni_serial_send_chunk_fifo()" 2024-03-05 13:40:34 +00:00
ufs Updates for the MSI interrupt subsystem and RISC-V initial MSI support: 2024-03-11 14:03:03 -07:00
uio
usb workqueue: BH workqueue conversions for v6.9 2024-03-11 13:05:19 -07:00
vdpa
vfio
vhost vhost/net: remove vhost_net_page_frag_refill() 2024-03-05 11:38:14 +01:00
video hyperv-fixes for v6.8 2024-03-05 12:38:50 -08:00
virt
virtio
w1
watchdog
xen Support for x86 Fast Return and Event Delivery (FRED): 2024-03-11 16:00:17 -07:00
zorro
Kconfig
Makefile