Skip to content

Commit 4cc339c

Browse files
ziyao233Paolo Abeni
authored andcommitted
net: stmmac: thead: Get and enable APB clock on initialization
It's necessary to adjust the MAC TX clock when the linkspeed changes, but it's noted such adjustment always fails on TH1520 SoC, and reading back from APB glue registers that control clock generation results in garbage, causing broken link. With some testing, it's found a clock must be ungated for access to APB glue registers. Without any consumer, the clock is automatically disabled during late kernel startup. Let's get and enable it if it's described in devicetree. For backward compatibility with older devicetrees, probing won't fail if the APB clock isn't found. In this case, we emit a warning since the link will break if the speed changes. Fixes: 33a1a01 ("net: stmmac: Add glue layer for T-HEAD TH1520 SoC") Signed-off-by: Yao Zi <[email protected]> Tested-by: Drew Fustini <[email protected]> Reviewed-by: Drew Fustini <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent c8a9a61 commit 4cc339c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static int thead_dwmac_probe(struct platform_device *pdev)
211211
struct stmmac_resources stmmac_res;
212212
struct plat_stmmacenet_data *plat;
213213
struct thead_dwmac *dwmac;
214+
struct clk *apb_clk;
214215
void __iomem *apb;
215216
int ret;
216217

@@ -224,6 +225,19 @@ static int thead_dwmac_probe(struct platform_device *pdev)
224225
return dev_err_probe(&pdev->dev, PTR_ERR(plat),
225226
"dt configuration failed\n");
226227

228+
/*
229+
* The APB clock is essential for accessing glue registers. However,
230+
* old devicetrees don't describe it correctly. We continue to probe
231+
* and emit a warning if it isn't present.
232+
*/
233+
apb_clk = devm_clk_get_enabled(&pdev->dev, "apb");
234+
if (PTR_ERR(apb_clk) == -ENOENT)
235+
dev_warn(&pdev->dev,
236+
"cannot get apb clock, link may break after speed changes\n");
237+
else if (IS_ERR(apb_clk))
238+
return dev_err_probe(&pdev->dev, PTR_ERR(apb_clk),
239+
"failed to get apb clock\n");
240+
227241
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
228242
if (!dwmac)
229243
return -ENOMEM;

0 commit comments

Comments
 (0)