[PATCH 20/25] net: stmmac: Add Tx/Rx platform clocks support

From: Serge Semin
Date: Mon Dec 14 2020 - 04:19:15 EST


Depending on the DW *MAC configuration it can be at least connected to an
external Transmit clock, but in some cases to an external Receive clock
generator. In order to simplify/unify the sub-drivers code and to prevent
having the same clocks named differently add the Tx/Rx clocks support to
the generic STMMAC DT-based platform data initialization method under the
names "tx" and "rx" respectively. The bindings schema has already been
altered in accordance with that.

Signed-off-by: Serge Semin <Sergey.Semin@xxxxxxxxxxxxxxxxxxxx>
---
.../ethernet/stmicro/stmmac/stmmac_platform.c | 24 +++++++++++++++++++
include/linux/stmmac.h | 2 ++
2 files changed, 26 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 38e8836861c4..943498d57e3a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -588,6 +588,24 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)

clk_prepare_enable(plat->pclk);

+ plat->tx_clk = devm_clk_get_optional(&pdev->dev, "tx");
+ if (IS_ERR(plat->tx_clk)) {
+ rc = PTR_ERR(plat->tx_clk);
+ dev_err_probe(&pdev->dev, rc, "Cannot get Tx clock\n");
+ goto error_tx_clk_get;
+ }
+
+ clk_prepare_enable(plat->tx_clk);
+
+ plat->rx_clk = devm_clk_get_optional(&pdev->dev, "rx");
+ if (IS_ERR(plat->rx_clk)) {
+ rc = PTR_ERR(plat->rx_clk);
+ dev_err_probe(&pdev->dev, rc, "Cannot get Rx clock\n");
+ goto error_rx_clk_get;
+ }
+
+ clk_prepare_enable(plat->rx_clk);
+
/* Fall-back to main clock in case of no PTP ref is passed */
plat->clk_ptp_ref = devm_clk_get_optional(&pdev->dev, "ptp_ref");
if (IS_ERR(plat->clk_ptp_ref)) {
@@ -613,6 +631,10 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
return plat;

error_hw_init:
+ clk_disable_unprepare(plat->rx_clk);
+error_rx_clk_get:
+ clk_disable_unprepare(plat->tx_clk);
+error_tx_clk_get:
clk_disable_unprepare(plat->pclk);
error_pclk_get:
clk_disable_unprepare(plat->stmmac_clk);
@@ -634,6 +656,8 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
void stmmac_remove_config_dt(struct platform_device *pdev,
struct plat_stmmacenet_data *plat)
{
+ clk_disable_unprepare(plat->rx_clk);
+ clk_disable_unprepare(plat->tx_clk);
clk_disable_unprepare(plat->pclk);
clk_disable_unprepare(plat->stmmac_clk);
of_node_put(plat->phy_node);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 628e28903b8b..b75cf13d088c 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -185,6 +185,8 @@ struct plat_stmmacenet_data {
void *bsp_priv;
struct clk *stmmac_clk;
struct clk *pclk;
+ struct clk *tx_clk;
+ struct clk *rx_clk;
struct clk *clk_ptp_ref;
unsigned int clk_ptp_rate;
unsigned int clk_ref_rate;
--
2.29.2