Thread (14 messages) flat view 14 messages, 5 authors, 2021-06-10

RE: [PATCH V3 net-next 3/4] net: phy: realtek: add dt property to enable ALDPS mode

From: Joakim Zhang <hidden>
Date: 2021-06-09 02:51:17
Also in: linux-devicetree, lkml

Hi Jisheng,
-----Original Message-----
From: Jisheng Zhang <redacted>
Sent: 2021年6月9日 9:57
To: Joakim Zhang <redacted>
Cc: davem@davemloft.net; kuba@kernel.org; robh+dt@kernel.org;
andrew@lunn.ch; hkallweit1@gmail.com; linux@armlinux.org.uk;
f.fainelli@gmail.com; dl-linux-imx [off-list ref];
netdev@vger.kernel.org; devicetree@vger.kernel.org;
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3 net-next 3/4] net: phy: realtek: add dt property to
enable ALDPS mode

On Tue, 8 Jun 2021 10:14:40 +0000
Joakim Zhang [off-list ref] wrote:

quoted

Hi Jisheng,
Hi,
quoted
quoted
-----Original Message-----
From: Jisheng Zhang <redacted>
Sent: 2021年6月8日 17:51
To: Joakim Zhang <redacted>
Cc: davem@davemloft.net; kuba@kernel.org; robh+dt@kernel.org;
andrew@lunn.ch; hkallweit1@gmail.com; linux@armlinux.org.uk;
f.fainelli@gmail.com; dl-linux-imx [off-list ref];
netdev@vger.kernel.org; devicetree@vger.kernel.org;
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3 net-next 3/4] net: phy: realtek: add dt
property to enable ALDPS mode

On Tue,  8 Jun 2021 11:15:34 +0800
Joakim Zhang [off-list ref] wrote:

quoted

If enable Advance Link Down Power Saving (ALDPS) mode, it will
change crystal/clock behavior, which cause RXC clock stop for
dozens to hundreds of miliseconds. This is comfirmed by Realtek
engineer. For some MACs, it needs RXC clock to support RX logic,
after this patch, PHY can generate continuous RXC clock during
auto-negotiation.
quoted
quoted
quoted
ALDPS default is disabled after hardware reset, it's more
reasonable to add a property to enable this feature, since ALDPS
would introduce side
effect.
quoted
This patch adds dt property "realtek,aldps-enable" to enable ALDPS
mode per users' requirement.

Jisheng Zhang enables this feature, changes the default behavior.
Since mine patch breaks the rule that new implementation should
not break existing design, so Cc'ed let him know to see if it can be
accepted.
quoted
quoted
quoted
Cc: Jisheng Zhang <redacted>
Signed-off-by: Joakim Zhang <redacted>
---
 drivers/net/phy/realtek.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index ca258f2a9613..79dc55bb4091 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -76,6 +76,7 @@ MODULE_AUTHOR("Johnson Leung");
MODULE_LICENSE("GPL");

 struct rtl821x_priv {
+       u16 phycr1;
        u16 phycr2;
 };
@@ -98,6 +99,14 @@ static int rtl821x_probe(struct phy_device
*phydev)
quoted
quoted
quoted
        if (!priv)
                return -ENOMEM;

+       priv->phycr1 = phy_read_paged(phydev, 0xa43,
RTL8211F_PHYCR1);
quoted
+       if (priv->phycr1 < 0)
+               return priv->phycr1;
+
+       priv->phycr1 &= (RTL8211F_ALDPS_PLL_OFF |
+ RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF);
I believe your intention is

priv->phycr1 &= ~(RTL8211F_ALDPS_PLL_OFF | RTL8211F_ALDPS_ENABLE |
priv->RTL8211F_ALDPS_XTAL_OFF);
However, this is not necessary. See below.
No, mine intention is to read back this three bits what the register contained.
quoted
quoted
priv->phycr1 is 0 by default, so above 5 LoCs can be removed
The intention of this is to take bootloader into account. Such as uboot
configure the PHY before.

The last param "set" of phy_modify_paged_changed() means *bit mask of bits
to set* If we don't want to enable ALDPS, 0 is enough.

Even if uboot configured the PHY before linux, I believe
phy_modify_paged_changed() can clear ALDPS bits w/o above 5 LoCs.
The logic is:
1) read back these three bits from the register.
2) if linux set "realtek,aldps-enable", assert these three bit; if not, keep these three bits read before.
3) call phy_modify_paged_changed() to configure, "mask" parameter to clear these three bits first, "set" parameter to assert these three bits per the result of step 2.

So, if step 1 read back the value is that these three bits are asserted, then in step 3, it will first clear these three bits and assert these three bits again. The result is ALDPS is enabled even without " realtek,aldps-enable " in DT.

Best Regards,
Joakim Zhang
Thanks
quoted
Best Regards,
Joakim Zhang
quoted
quoted
+       if (of_property_read_bool(dev->of_node,
"realtek,aldps-enable"))
quoted
quoted
quoted
+               priv->phycr1 |= RTL8211F_ALDPS_PLL_OFF |
+ RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF;
+
        priv->phycr2 = phy_read_paged(phydev, 0xa43,
RTL8211F_PHYCR2);
quoted
        if (priv->phycr2 < 0)
                return priv->phycr2; @@ -324,11 +333,16 @@ static
int rtl8211f_config_init(struct phy_device
*phydev)
quoted
        struct rtl821x_priv *priv = phydev->priv;
        struct device *dev = &phydev->mdio.dev;
        u16 val_txdly, val_rxdly;
-       u16 val;
        int ret;

-       val = RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_PLL_OFF |
RTL8211F_ALDPS_XTAL_OFF;
quoted
-       phy_modify_paged_changed(phydev, 0xa43, RTL8211F_PHYCR1,
val,
quoted
quoted
val);
quoted
+       ret = phy_modify_paged_changed(phydev, 0xa43,
RTL8211F_PHYCR1,
quoted
+
RTL8211F_ALDPS_PLL_OFF |
quoted
quoted
RTL8211F_ALDPS_ENABLE | RTL8211F_ALDPS_XTAL_OFF,
quoted
+                                      priv->phycr1);
+       if (ret < 0) {
+               dev_err(dev, "aldps mode  configuration
failed: %pe\n",
quoted
quoted
quoted
+                       ERR_PTR(ret));
+               return ret;
+       }

        switch (phydev->interface) {
        case PHY_INTERFACE_MODE_RGMII:
--
2.17.1
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help