git: d67880fca7ff - main - dwc: rockchip: Do not enable the same clock twice

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 13:55:54 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=d67880fca7ff67c7c592375e12988373a015b590

commit d67880fca7ff67c7c592375e12988373a015b590
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-21 07:26:27 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-20 13:55:31 +0000

    dwc: rockchip: Do not enable the same clock twice
    
    Some Rockchip SoCs reference the same clock from several clock-names
    properties.  On the RK3568 both mac_clk_tx and clk_mac_speed reference
    the same clock: SCLK_GMAC0_RX_TX on GMAC0 and SCLK_GMAC1_RX_TX on
    GMAC1.  So if_dwc_rk_init_clocks() enables that clock twice through two
    different handles.
    
    The clk framework then considers that the clock has more than one
    consumer and refuses the rate change done by rk3568_set_speed() with
    EBUSY, as the clock is not glitch-free.
    
    Only enable clk_mac_speed if it is not the same clock as mac_clk_tx.
    
    Reviewed by:    oh
    Differential Revision:  https://reviews.freebsd.org/D61016
---
 sys/dev/dwc/if_dwc_rk.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/dev/dwc/if_dwc_rk.c b/sys/dev/dwc/if_dwc_rk.c
index 769b339678fd..00056c33fba4 100644
--- a/sys/dev/dwc/if_dwc_rk.c
+++ b/sys/dev/dwc/if_dwc_rk.c
@@ -613,7 +613,16 @@ if_dwc_rk_init_clocks(device_t dev)
 		clk_enable(sc->pclk_mac);
 	if (sc->mac_clk_tx)
 		clk_enable(sc->mac_clk_tx);
-	if (sc->clk_mac_speed)
+	/*
+	 * Some SoCs reference the same clock from several clock-names.  On
+	 * the RK3568 both mac_clk_tx and clk_mac_speed are SCLK_GMAC0_RX_TX
+	 * (resp. SCLK_GMAC1_RX_TX), do not enable it twice or the clk
+	 * framework will refuse to change its rate.
+	 */
+	if (sc->clk_mac_speed != NULL &&
+	    (sc->mac_clk_tx == NULL ||
+	     strcmp(clk_get_name(sc->mac_clk_tx),
+	        clk_get_name(sc->clk_mac_speed)) != 0))
 		clk_enable(sc->clk_mac_speed);
 
 	DELAY(50);