net: stmmac: dwmac-imx: add platform level clocks management for i.MX
Split clocks settings from init callback into clks_config callback, which could support platform level clocks management. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b4d45aee66
commit
8f2f83765e
@ -90,6 +90,32 @@ imx8dxl_set_intf_mode(struct plat_stmmacenet_data *plat_dat)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int imx_dwmac_clks_config(void *priv, bool enabled)
|
||||
{
|
||||
struct imx_priv_data *dwmac = priv;
|
||||
int ret = 0;
|
||||
|
||||
if (enabled) {
|
||||
ret = clk_prepare_enable(dwmac->clk_mem);
|
||||
if (ret) {
|
||||
dev_err(dwmac->dev, "mem clock enable failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(dwmac->clk_tx);
|
||||
if (ret) {
|
||||
dev_err(dwmac->dev, "tx clock enable failed\n");
|
||||
clk_disable_unprepare(dwmac->clk_mem);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
clk_disable_unprepare(dwmac->clk_tx);
|
||||
clk_disable_unprepare(dwmac->clk_mem);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int imx_dwmac_init(struct platform_device *pdev, void *priv)
|
||||
{
|
||||
struct plat_stmmacenet_data *plat_dat;
|
||||
@ -98,39 +124,18 @@ static int imx_dwmac_init(struct platform_device *pdev, void *priv)
|
||||
|
||||
plat_dat = dwmac->plat_dat;
|
||||
|
||||
ret = clk_prepare_enable(dwmac->clk_mem);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "mem clock enable failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(dwmac->clk_tx);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "tx clock enable failed\n");
|
||||
goto clk_tx_en_failed;
|
||||
}
|
||||
|
||||
if (dwmac->ops->set_intf_mode) {
|
||||
ret = dwmac->ops->set_intf_mode(plat_dat);
|
||||
if (ret)
|
||||
goto intf_mode_failed;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
intf_mode_failed:
|
||||
clk_disable_unprepare(dwmac->clk_tx);
|
||||
clk_tx_en_failed:
|
||||
clk_disable_unprepare(dwmac->clk_mem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void imx_dwmac_exit(struct platform_device *pdev, void *priv)
|
||||
{
|
||||
struct imx_priv_data *dwmac = priv;
|
||||
|
||||
clk_disable_unprepare(dwmac->clk_tx);
|
||||
clk_disable_unprepare(dwmac->clk_mem);
|
||||
/* nothing to do now */
|
||||
}
|
||||
|
||||
static void imx_dwmac_fix_speed(void *priv, unsigned int speed)
|
||||
@ -249,10 +254,15 @@ static int imx_dwmac_probe(struct platform_device *pdev)
|
||||
plat_dat->addr64 = dwmac->ops->addr_width;
|
||||
plat_dat->init = imx_dwmac_init;
|
||||
plat_dat->exit = imx_dwmac_exit;
|
||||
plat_dat->clks_config = imx_dwmac_clks_config;
|
||||
plat_dat->fix_mac_speed = imx_dwmac_fix_speed;
|
||||
plat_dat->bsp_priv = dwmac;
|
||||
dwmac->plat_dat = plat_dat;
|
||||
|
||||
ret = imx_dwmac_clks_config(dwmac, true);
|
||||
if (ret)
|
||||
goto err_clks_config;
|
||||
|
||||
ret = imx_dwmac_init(pdev, dwmac);
|
||||
if (ret)
|
||||
goto err_dwmac_init;
|
||||
@ -263,9 +273,11 @@ static int imx_dwmac_probe(struct platform_device *pdev)
|
||||
|
||||
return 0;
|
||||
|
||||
err_dwmac_init:
|
||||
err_drv_probe:
|
||||
imx_dwmac_exit(pdev, plat_dat->bsp_priv);
|
||||
err_dwmac_init:
|
||||
imx_dwmac_clks_config(dwmac, false);
|
||||
err_clks_config:
|
||||
err_parse_dt:
|
||||
err_match_data:
|
||||
stmmac_remove_config_dt(pdev, plat_dat);
|
||||
|
Loading…
Reference in New Issue
Block a user