[PATCH 1/2] net: ethernet: ti: cpsw-phy-sel: add support slave interface using internal clock in dual rmii emac mode

From: Xiangyu Chen
Date: Thu Dec 30 2021 - 21:28:14 EST


The am335x support dual emac in rmii mode, the rmii clock
can be provided by external osc or internal soc by ref_clk pin.
When rmii-clock-ext has been set in device tree, both emac
has been set to external clock mode, otherwise both emac has
been set to internal clock mode.

In some case, one slave can be used external clock, another
slave can be used internal clock.

This commit to support define a method to tell driver which
slave phy use internal clock when the "rmii-clock-ext" has
been set.

Signed-off-by: Xiangyu Chen <xiangyu.chen@xxxxxxx>
---
drivers/net/ethernet/ti/cpsw-phy-sel.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
index e8f38e3f7..332d8e018 100644
--- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
+++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
@@ -30,6 +30,7 @@

struct cpsw_phy_sel_priv {
struct device *dev;
+ u32 ignore_slave;
u32 __iomem *gmii_sel;
bool rmii_clock_external;
void (*cpsw_phy_sel)(struct cpsw_phy_sel_priv *priv,
@@ -78,10 +79,13 @@ static void cpsw_gmii_sel_am3352(struct cpsw_phy_sel_priv *priv,
mode <<= slave * 2;

if (priv->rmii_clock_external) {
- if (slave == 0)
- mode |= AM33XX_GMII_SEL_RMII1_IO_CLK_EN;
- else
- mode |= AM33XX_GMII_SEL_RMII2_IO_CLK_EN;
+ if (slave == 0) {
+ if (priv->ignore_slave != slave)
+ mode |= AM33XX_GMII_SEL_RMII1_IO_CLK_EN;
+ } else {
+ if (priv->ignore_slave != slave)
+ mode |= AM33XX_GMII_SEL_RMII2_IO_CLK_EN;
+ }
}

if (rgmii_id) {
@@ -221,6 +225,7 @@ static int cpsw_phy_sel_probe(struct platform_device *pdev)

priv->dev = &pdev->dev;
priv->cpsw_phy_sel = of_id->data;
+ priv->ignore_slave = 0xff;

priv->gmii_sel = devm_platform_ioremap_resource_byname(pdev, "gmii-sel");
if (IS_ERR(priv->gmii_sel))
@@ -229,6 +234,8 @@ static int cpsw_phy_sel_probe(struct platform_device *pdev)
if (of_find_property(pdev->dev.of_node, "rmii-clock-ext", NULL))
priv->rmii_clock_external = true;

+ of_property_read_u32(pdev->dev.of_node, "ignore-slave", &priv->ignore_slave);
+
dev_set_drvdata(&pdev->dev, priv);

return 0;
--
2.25.1