Skip to contentSkip to conversation

net: phy: realtek: Support external PHY clock

PATCH Applied Detlev Casanova 4 participants 8 messages Jun 5, 2023 – Jun 12, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover net: phy: realtek: Support external PHY clock

Some PHYs can use an external clock that must be enabled before communicating with them.

Changes since v3:
* Do not call genphy_suspend if WoL is enabled.
Changes since v2:
* Reword documentation commit message
Changes since v1:
* Remove the clock name as it is not guaranteed to be identical across different PHYs
* Disable/Enable the clock when suspending/resuming

#1 lore raw

PATCH v4 1/3 net: phy: realtek: Add optional external PHY clock

In some cases, the PHY can use an external clock source instead of a crystal.

Add an optional clock in the phy node to make sure that the clock source is enabled, if specified, before probing.

---
 drivers/net/phy/realtek.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/phy/realtek.c +7 -0
index 3d99fd6664d7..b13dd0b3c99e 100644
@@ -12,6 +12,7 @@
 #include <linux/phy.h>
 #include <linux/module.h>
 #include <linux/delay.h>
+#include <linux/clk.h>
 
 #define RTL821x_PHYSR				0x11
 #define RTL821x_PHYSR_DUPLEX			BIT(13)
@@ -80,6 +81,7 @@ struct rtl821x_priv {
 	u16 phycr1;
 	u16 phycr2;
 	bool has_phycr2;
+	struct clk *clk;
 };
 
 static int rtl821x_read_page(struct phy_device *phydev)
@@ -103,6 +105,11 @@ static int rtl821x_probe(struct phy_device *phydev)
 	if (!priv)
 		return -ENOMEM;
 
+	priv->clk = devm_clk_get_optional_enabled(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(dev, PTR_ERR(priv->clk),
+				     "failed to get phy clock\n");
+
 	ret = phy_read_paged(phydev, 0xa43, RTL8211F_PHYCR1);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.39.3
#2 lore raw

PATCH v4 2/3 dt-bindings: net: phy: Document support for external PHY clk

In reply to Detlev Casanova

Ethern PHYs can have external an clock that needs to be activated before communicating with the PHY.

---
 Documentation/devicetree/bindings/net/ethernet-phy.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +6 -0
index 4f574532ee13..c1241c8a3b77 100644
@@ -93,6 +93,12 @@ properties:
       the turn around line low at end of the control phase of the
       MDIO transaction.
 
+  clocks:
+    maxItems: 1
+    description:
+      External clock connected to the PHY. If not specified it is assumed
+      that the PHY uses a fixed crystal or an internal oscillator.
+
   enet-phy-lane-swap:
     $ref: /schemas/types.yaml#/definitions/flag
     description:
Signature · 1 line
2.39.3
#3 lore raw

PATCH v4 3/3 net: phy: realtek: Disable clock on suspend

In reply to Detlev Casanova

For PHYs that call rtl821x_probe() where an external clock can be configured, make sure that the clock is disabled
when ->suspend() is called and enabled on resume.

The PHY_ALWAYS_CALL_SUSPEND is added to ensure that the suspend function is actually always called.

---
 drivers/net/phy/realtek.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/net/phy/realtek.c +25 -2
index b13dd0b3c99e..894172a3e15f 100644
@@ -426,10 +426,31 @@ static int rtl8211f_config_init(struct phy_device *phydev)
 	return genphy_soft_reset(phydev);
 }
 
+static int rtl821x_suspend(struct phy_device *phydev)
+{
+	struct rtl821x_priv *priv = phydev->priv;
+	int ret = 0;
+
+	if (!phydev->wol_enabled) {
+		ret = genphy_suspend(phydev);
+
+		if (ret)
+			return ret;
+
+		clk_disable_unprepare(priv->clk);
+	}
+
+	return ret;
+}
+
 static int rtl821x_resume(struct phy_device *phydev)
 {
+	struct rtl821x_priv *priv = phydev->priv;
 	int ret;
 
+	if (!phydev->wol_enabled)
+		clk_prepare_enable(priv->clk);
+
 	ret = genphy_resume(phydev);
 	if (ret < 0)
 		return ret;
@@ -934,10 +955,11 @@ static struct phy_driver realtek_drvs[] = {
 		.read_status	= rtlgen_read_status,
 		.config_intr	= &rtl8211f_config_intr,
 		.handle_interrupt = rtl8211f_handle_interrupt,
-		.suspend	= genphy_suspend,
+		.suspend	= rtl821x_suspend,
 		.resume		= rtl821x_resume,
 		.read_page	= rtl821x_read_page,
 		.write_page	= rtl821x_write_page,
+		.flags		= PHY_ALWAYS_CALL_SUSPEND,
 	}, {
 		PHY_ID_MATCH_EXACT(RTL_8211FVD_PHYID),
 		.name		= "RTL8211F-VD Gigabit Ethernet",
@@ -946,10 +968,11 @@ static struct phy_driver realtek_drvs[] = {
 		.read_status	= rtlgen_read_status,
 		.config_intr	= &rtl8211f_config_intr,
 		.handle_interrupt = rtl8211f_handle_interrupt,
-		.suspend	= genphy_suspend,
+		.suspend	= rtl821x_suspend,
 		.resume		= rtl821x_resume,
 		.read_page	= rtl821x_read_page,
 		.write_page	= rtl821x_write_page,
+		.flags		= PHY_ALWAYS_CALL_SUSPEND,
 	}, {
 		.name		= "Generic FE-GE Realtek PHY",
 		.match_phy_device = rtlgen_match_phy_device,
Signature · 1 line
2.39.3
#4 lore raw

Re: [PATCH v4 3/3] net: phy: realtek: Disable clock on suspend

kernel test robot noticed the following build errors:

Hi Detlev,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on net/main linus/master v6.4-rc5] [cannot apply to net-next/main next-20230609]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Detlev-Casanova/net-phy-realtek-Add-optional-external-PHY-clock/20230605-234223
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230605154010.49611-4-detlev.casanova%40collabora.com
patch subject: [PATCH v4 3/3] net: phy: realtek: Disable clock on suspend
config: i386-debian-10.3 (https://download.01.org/0day-ci/archive/20230610/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

reproduce (this is a W=1 build):
git remote add robh https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
git fetch robh for-next
git checkout robh/for-next
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/net/phy/realtek.c: In function 'rtl821x_suspend':

>> drivers/net/phy/realtek.c:434:22: error: 'struct phy_device' has no member named 'wol_enabled'; did you mean 'eee_enabled'?
     434 |         if (!phydev->wol_enabled) {
         |                      ^~~~~~~~~~~
         |                      eee_enabled
   drivers/net/phy/realtek.c: In function 'rtl821x_resume':
   drivers/net/phy/realtek.c:451:22: error: 'struct phy_device' has no member named 'wol_enabled'; did you mean 'eee_enabled'?
     451 |         if (!phydev->wol_enabled)
         |                      ^~~~~~~~~~~
         |                      eee_enabled
   drivers/net/phy/realtek.c: At top level:
>> drivers/net/phy/realtek.c:962:35: error: 'PHY_ALWAYS_CALL_SUSPEND' undeclared here (not in a function)

962 | .flags = PHY_ALWAYS_CALL_SUSPEND,
| ^~~~~~~~~~~~~~~~~~~~~~~

vim +434 drivers/net/phy/realtek.c

428
429 static int rtl821x_suspend(struct phy_device *phydev)
430 {
431 struct rtl821x_priv *priv = phydev->priv;
432 int ret = 0;
433

 > 434		if (!phydev->wol_enabled) {

435 ret = genphy_suspend(phydev);
436
437 if (ret)
438 return ret;
439
440 clk_disable_unprepare(priv->clk);
441 }
442
443 return ret;
444 }
445

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH v4 3/3] net: phy: realtek: Disable clock on suspend

Quoted 10 lines · On Friday, June 9, 2023 1:41:58 P.M. EDT kernel test robot wrote:

Hi Detlev,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on net/main linus/master v6.4-rc5] [cannot apply to net-next/main next-20230609]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

Hi,

Yes, it is applied on the wrong tree, the correct tree should be net-next
(git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git). I didn't know about the --base argument, I will use that in the future., thanks !

Detlev.

Quoted 76 lines

url:
https://github.com/intel-lab-lkp/linux/commits/Detlev-Casanova/net-phy-real
tek-Add-optional-external-PHY-clock/20230605-234223 base:
https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link:
https://lore.kernel.org/r/20230605154010.49611-4-detlev.casanova%40collabor
a.com patch subject: [PATCH v4 3/3] net: phy: realtek: Disable clock on suspend config: i386-debian-10.3
(https://download.01.org/0day-ci/archive/20230610/202306100152.2hG4J7Ds-lkp
@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build):
git remote add robh
https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git git fetch robh for-next
git checkout robh/for-next
b4 shazam
https://lore.kernel.org/r/20230605154010.49611-4-detlev.casanova@collabora.
com # save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/[email protected]
| /

All errors (new ones prefixed by >>):

drivers/net/phy/realtek.c: In function 'rtl821x_suspend':

Quoted 2 lines
Quoted 2 lines

drivers/net/phy/realtek.c:434:22: error: 'struct phy_device' has no member named 'wol_enabled'; did you mean 'eee_enabled'?

     434 |         if (!phydev->wol_enabled) {

         |                      ^~~~~~~~~~~
         |                      eee_enabled

drivers/net/phy/realtek.c: In function 'rtl821x_resume':
drivers/net/phy/realtek.c:451:22: error: 'struct phy_device' has no
member named 'wol_enabled'; did you mean 'eee_enabled'? 451 | if
(!phydev->wol_enabled)

         |                      ^~~~~~~~~~~
         |                      eee_enabled

drivers/net/phy/realtek.c: At top level:

Quoted 2 lines
Quoted 2 lines

drivers/net/phy/realtek.c:962:35: error: 'PHY_ALWAYS_CALL_SUSPEND' undeclared here (not in a function)

962 | .flags = PHY_ALWAYS_CALL_SUSPEND,

| ^~~~~~~~~~~~~~~~~~~~~~~

vim +434 drivers/net/phy/realtek.c

   428
   429	static int rtl821x_suspend(struct phy_device *phydev)
   430	{
   431		struct rtl821x_priv *priv = phydev->priv;
   432		int ret = 0;
   433
Quoted 1 line

434 if (!phydev->wol_enabled) {

   435			ret = genphy_suspend(phydev);
   436
   437			if (ret)
   438				return ret;
   439
   440			clk_disable_unprepare(priv->clk);
   441		}
   442
   443		return ret;
   444	}
   445
maintainer
#6 lore raw
In reply to Detlev Casanova
Quoted 13 lines · Detlev Casanova

Some PHYs can use an external clock that must be enabled before communicating with them.

Changes since v3:
* Do not call genphy_suspend if WoL is enabled.
Changes since v2:
* Reword documentation commit message
Changes since v1:
* Remove the clock name as it is not guaranteed to be identical across different PHYs
* Disable/Enable the clock when suspending/resuming

Not a big thing, but if a v5 should be needed:
Please annotate the series properly as net-next (see netdev FAQ).

#7 lore raw
In reply to Detlev Casanova
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 11 lines · On Mon, 5 Jun 2023 11:40:07 -0400 you wrote:

Some PHYs can use an external clock that must be enabled before communicating with them.

Changes since v3:
* Do not call genphy_suspend if WoL is enabled.
Changes since v2:
* Reword documentation commit message
Changes since v1:
* Remove the clock name as it is not guaranteed to be identical across different PHYs
* Disable/Enable the clock when suspending/resuming

Here is the summary with links:
- [v4,1/3] net: phy: realtek: Add optional external PHY clock

    https://git.kernel.org/netdev/net-next/c/7300c9b574cc
  - [v4,2/3] dt-bindings: net: phy: Document support for external PHY clk
    https://git.kernel.org/netdev/net-next/c/350b7a258f20
  - [v4,3/3] net: phy: realtek: Disable clock on suspend
    https://git.kernel.org/netdev/net-next/c/59e227e2894b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html