[PATCH RFT] clk: qcom: gcc-ipq5018: pick the GMAC1 125 MHz config by the UNIPHY rate

From: Julius Bairaktaris

Date: Sun Nov 29 2026 - 17:29:59 EST


The GMAC1 RX and TX frequency tables list 125 MHz twice: UNIPHY / 2.5
for a UNIPHY at 312.5 MHz (2500BASE-X) and UNIPHY / 1 for a UNIPHY at
125 MHz (SGMII). With a plain freq_tbl and clk_rcg2_ops,
qcom_find_freq() returns the first entry whose rate is not below the
request, so the second entry is never used: at 1000 Mbps in SGMII the
RCG divides the 125 MHz UNIPHY clock by 2.5 and gives the MAC 50 MHz.

Describe both configs under one 125 MHz entry of a freq_multi_tbl and
switch the two RCGs to clk_rcg2_fm_ops, as gcc-ipq8074 does for its
port 5 and port 6 clocks. __clk_rcg2_select_conf() then takes the
config whose output from the parent's current rate equals the request,
which is UNIPHY / 1 in SGMII and UNIPHY / 2.5 in 2500BASE-X.

Fixes: e3fdbef1bab8 ("clk: qcom: Add Global Clock controller (GCC) driver for IPQ5018")
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---

Notes:
RFT: a run on an IPQ5018 board with GMAC1 in SGMII or 2500BASE-X is
welcome. George and Ziyang are in Cc for the OpenWrt patch that
comments out the UNIPHY / 2.5 entries of both tables for the same
reason; with this change that patch is no longer needed and 1 Gbps on
a 2500BASE-X link keeps its config.

The selection was run in a userspace harness that compiles
qcom_find_freq(), qcom_find_freq_multi(), calc_rate() and
__clk_rcg2_select_conf() with the GMAC1 RX table of this driver:

before (freq_tbl, clk_rcg2_ops)
SGMII 1G uniphy 125 MHz, request 125 MHz -> / 2.5 = 50 MHz
2500BASE-X 2.5G uniphy 312.5 MHz, request 312.5 MHz -> / 1 = 312.5 MHz
2500BASE-X 1G uniphy 312.5 MHz, request 125 MHz -> / 2.5 = 125 MHz
after (freq_multi_tbl, clk_rcg2_fm_ops)
SGMII 1G uniphy 125 MHz, request 125 MHz -> / 1 = 125 MHz
2500BASE-X 2.5G uniphy 312.5 MHz, request 312.5 MHz -> / 1 = 312.5 MHz
2500BASE-X 1G uniphy 312.5 MHz, request 125 MHz -> / 2.5 = 125 MHz

I used Claude (Anthropic) to help write these patches.

drivers/clk/qcom/gcc-ipq5018.c | 44 ++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/clk/qcom/gcc-ipq5018.c b/drivers/clk/qcom/gcc-ipq5018.c
index 37ccdc44a8..d749d940bf 100644
--- a/drivers/clk/qcom/gcc-ipq5018.c
+++ b/drivers/clk/qcom/gcc-ipq5018.c
@@ -682,13 +682,17 @@ static struct clk_regmap_div gmac0_tx_div_clk_src = {
},
};

-static const struct freq_tbl ftbl_gmac1_rx_clk_src[] = {
- F(2500000, P_UNIPHY_RX, 12.5, 0, 0),
- F(24000000, P_XO, 1, 0, 0),
- F(25000000, P_UNIPHY_RX, 2.5, 0, 0),
- F(125000000, P_UNIPHY_RX, 2.5, 0, 0),
- F(125000000, P_UNIPHY_RX, 1, 0, 0),
- F(312500000, P_UNIPHY_RX, 1, 0, 0),
+static const struct freq_conf ftbl_gmac1_rx_clk_src_125[] = {
+ C(P_UNIPHY_RX, 2.5, 0, 0),
+ C(P_UNIPHY_RX, 1, 0, 0),
+};
+
+static const struct freq_multi_tbl ftbl_gmac1_rx_clk_src[] = {
+ FMS(2500000, P_UNIPHY_RX, 12.5, 0, 0),
+ FMS(24000000, P_XO, 1, 0, 0),
+ FMS(25000000, P_UNIPHY_RX, 2.5, 0, 0),
+ FM(125000000, ftbl_gmac1_rx_clk_src_125),
+ FMS(312500000, P_UNIPHY_RX, 1, 0, 0),
{ }
};

@@ -696,12 +700,12 @@ static struct clk_rcg2 gmac1_rx_clk_src = {
.cmd_rcgr = 0x68030,
.parent_map = gcc_xo_uniphy_gcc_rx_uniphy_gcc_tx_ubi32_pll_gpll0_map,
.hid_width = 5,
- .freq_tbl = ftbl_gmac1_rx_clk_src,
+ .freq_multi_tbl = ftbl_gmac1_rx_clk_src,
.clkr.hw.init = &(struct clk_init_data) {
.name = "gmac1_rx_clk_src",
.parent_data = gcc_xo_uniphy_gcc_rx_uniphy_gcc_tx_ubi32_pll_gpll0,
.num_parents = ARRAY_SIZE(gcc_xo_uniphy_gcc_rx_uniphy_gcc_tx_ubi32_pll_gpll0),
- .ops = &clk_rcg2_ops,
+ .ops = &clk_rcg2_fm_ops,
},
};

@@ -722,13 +726,17 @@ static struct clk_regmap_div gmac1_rx_div_clk_src = {
},
};

-static const struct freq_tbl ftbl_gmac1_tx_clk_src[] = {
- F(2500000, P_UNIPHY_TX, 12.5, 0, 0),
- F(24000000, P_XO, 1, 0, 0),
- F(25000000, P_UNIPHY_TX, 2.5, 0, 0),
- F(125000000, P_UNIPHY_TX, 2.5, 0, 0),
- F(125000000, P_UNIPHY_TX, 1, 0, 0),
- F(312500000, P_UNIPHY_TX, 1, 0, 0),
+static const struct freq_conf ftbl_gmac1_tx_clk_src_125[] = {
+ C(P_UNIPHY_TX, 2.5, 0, 0),
+ C(P_UNIPHY_TX, 1, 0, 0),
+};
+
+static const struct freq_multi_tbl ftbl_gmac1_tx_clk_src[] = {
+ FMS(2500000, P_UNIPHY_TX, 12.5, 0, 0),
+ FMS(24000000, P_XO, 1, 0, 0),
+ FMS(25000000, P_UNIPHY_TX, 2.5, 0, 0),
+ FM(125000000, ftbl_gmac1_tx_clk_src_125),
+ FMS(312500000, P_UNIPHY_TX, 1, 0, 0),
{ }
};

@@ -736,12 +744,12 @@ static struct clk_rcg2 gmac1_tx_clk_src = {
.cmd_rcgr = 0x68038,
.parent_map = gcc_xo_uniphy_gcc_tx_uniphy_gcc_rx_ubi32_pll_gpll0_map,
.hid_width = 5,
- .freq_tbl = ftbl_gmac1_tx_clk_src,
+ .freq_multi_tbl = ftbl_gmac1_tx_clk_src,
.clkr.hw.init = &(struct clk_init_data) {
.name = "gmac1_tx_clk_src",
.parent_data = gcc_xo_uniphy_gcc_tx_uniphy_gcc_rx_ubi32_pll_gpll0,
.num_parents = ARRAY_SIZE(gcc_xo_uniphy_gcc_tx_uniphy_gcc_rx_ubi32_pll_gpll0),
- .ops = &clk_rcg2_ops,
+ .ops = &clk_rcg2_fm_ops,
},
};


base-commit: ef922b721a5e99348fc1f5801fdeb427ee14ee9f
--
2.53.0