Skip to content

Commit 98182c7

Browse files
mindachen1987kuba-moo
authored andcommitted
net: stmmac: starfive: Add jhb100 SGMII interface
Add jhb100 compatible and SGMII support. jhb100 soc contains 2 SGMII interfaces and integrated with serdes PHY. SGMII with split TX/RX MAC clock and need to set 2.5M/25M/125M TX/RX clock rate in 10M/100M/1000M speed mode. Signed-off-by: Minda Chen <minda.chen@starfivetech.com> Reviewed-by: Sai Krishna <saikrishnag@marvell.com> Link: https://patch.msgid.link/20260527084108.121416-4-minda.chen@starfivetech.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 64772e4 commit 98182c7

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct starfive_dwmac_data {
2626
struct starfive_dwmac {
2727
struct device *dev;
2828
const struct starfive_dwmac_data *data;
29+
struct clk *sgmii_rx;
2930
};
3031

3132
static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
@@ -68,6 +69,25 @@ static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
6869
return 0;
6970
}
7071

72+
static int stmmac_starfive_sgmii_set_clk_rate(void *bsp_priv, struct clk *clk_tx_i,
73+
phy_interface_t __maybe_unused interface,
74+
int speed)
75+
{
76+
struct starfive_dwmac *dwmac = bsp_priv;
77+
long rate = rgmii_clock(speed);
78+
int ret;
79+
80+
/* MAC clock rate the same as RGMII */
81+
if (rate < 0)
82+
return -EINVAL;
83+
84+
ret = clk_set_rate(clk_tx_i, rate);
85+
if (ret)
86+
return ret;
87+
88+
return clk_set_rate(dwmac->sgmii_rx, rate);
89+
}
90+
7191
static int starfive_dwmac_probe(struct platform_device *pdev)
7292
{
7393
struct plat_stmmacenet_data *plat_dat;
@@ -102,23 +122,34 @@ static int starfive_dwmac_probe(struct platform_device *pdev)
102122
return dev_err_probe(&pdev->dev, PTR_ERR(clk_gtx),
103123
"error getting gtx clock\n");
104124

105-
/* Generally, the rgmii_tx clock is provided by the internal clock,
106-
* which needs to match the corresponding clock frequency according
107-
* to different speeds. If the rgmii_tx clock is provided by the
108-
* external rgmii_rxin, there is no need to configure the clock
109-
* internally, because rgmii_rxin will be adaptively adjusted.
110-
*/
111-
if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk"))
112-
plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
113-
114125
dwmac->dev = &pdev->dev;
115-
plat_dat->flags |= STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP;
116126
plat_dat->bsp_priv = dwmac;
117-
plat_dat->dma_cfg->dche = true;
127+
/* generic sgmii, 1000_BASEX not support yet */
128+
if (plat_dat->phy_interface == PHY_INTERFACE_MODE_SGMII) {
129+
dwmac->sgmii_rx = devm_clk_get_enabled(&pdev->dev, "sgmii_rx");
130+
if (IS_ERR(dwmac->sgmii_rx))
131+
return dev_err_probe(&pdev->dev,
132+
PTR_ERR(dwmac->sgmii_rx),
133+
"error getting sgmii rx clock\n");
134+
plat_dat->set_clk_tx_rate = stmmac_starfive_sgmii_set_clk_rate;
135+
} else {
136+
/*
137+
* Generally, the rgmii_tx clock is provided by the internal clock,
138+
* which needs to match the corresponding clock frequency according
139+
* to different speeds. If the rgmii_tx clock is provided by the
140+
* external rgmii_rxin, there is no need to configure the clock
141+
* internally, because rgmii_rxin will be adaptively adjusted.
142+
*/
143+
if (!device_property_read_bool(&pdev->dev, "starfive,tx-use-rgmii-clk"))
144+
plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
145+
146+
err = starfive_dwmac_set_mode(plat_dat);
147+
if (err)
148+
return err;
149+
}
118150

119-
err = starfive_dwmac_set_mode(plat_dat);
120-
if (err)
121-
return err;
151+
plat_dat->flags |= STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP;
152+
plat_dat->dma_cfg->dche = true;
122153

123154
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
124155
}

0 commit comments

Comments
 (0)