Skip to contentSkip to conversation

net: phy: realtek: add hwmon support

PATCH Applied Heiner Kallweit 4 participants 12 messages Jan 11, 2025 – Jan 23, 2025

Subsystems (4)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

v2 cover net: phy: realtek: add hwmon support

This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the internal PHY's of RTL8125B(P)/RTL8125D/RTL8126.

v2:
- patch 2: move Realtek PHY driver to its own subdirectory
- patch 3: remove alarm attribute

Heiner Kallweit (3):
net: phy: realtek: add support for reading MDIO_MMD_VEND2 regs on

    RTL8125/RTL8126

net: phy: move realtek PHY driver to its own subdirectory
net: phy: realtek: add hwmon support for temp sensor on RTL822x

 drivers/net/phy/Kconfig                       |  5 +-
 drivers/net/phy/Makefile                      |  2 +-
 drivers/net/phy/realtek/Kconfig               | 11 +++
 drivers/net/phy/realtek/Makefile              |  4 +
 drivers/net/phy/realtek/realtek.h             | 10 +++
 drivers/net/phy/realtek/realtek_hwmon.c       | 79 +++++++++++++++++++
 .../phy/{realtek.c => realtek/realtek_main.c} | 24 +++++-
 7 files changed, 128 insertions(+), 7 deletions(-)
 create mode 100644 drivers/net/phy/realtek/Kconfig
 create mode 100644 drivers/net/phy/realtek/Makefile
 create mode 100644 drivers/net/phy/realtek/realtek.h
 create mode 100644 drivers/net/phy/realtek/realtek_hwmon.c
 rename drivers/net/phy/{realtek.c => realtek/realtek_main.c} (98%)
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH v2 1/3 net: phy: realtek: add support for reading MDIO_MMD_VEND2 regs on RTL8125/RTL8126

RTL8125/RTL8126 don't support MMD access to the internal PHY, but provide a mechanism to access at least all MDIO_MMD_VEND2 registers. By exposing this mechanism standard MMD access functions can be used to access the MDIO_MMD_VEND2 registers.

---
 drivers/net/phy/realtek.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/phy/realtek.c +10 -2
index f65d7f1f3..af9874143 100644
@@ -736,7 +736,11 @@ static int rtlgen_read_mmd(struct phy_device *phydev, int devnum, u16 regnum)
 {
 	int ret;
 
-	if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE) {
+	if (devnum == MDIO_MMD_VEND2) {
+		rtl821x_write_page(phydev, regnum >> 4);
+		ret = __phy_read(phydev, 0x10 + ((regnum & 0xf) >> 1));
+		rtl821x_write_page(phydev, 0);
+	} else if (devnum == MDIO_MMD_PCS && regnum == MDIO_PCS_EEE_ABLE) {
 		rtl821x_write_page(phydev, 0xa5c);
 		ret = __phy_read(phydev, 0x12);
 		rtl821x_write_page(phydev, 0);
@@ -760,7 +764,11 @@ static int rtlgen_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
 {
 	int ret;
 
-	if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
+	if (devnum == MDIO_MMD_VEND2) {
+		rtl821x_write_page(phydev, regnum >> 4);
+		ret = __phy_write(phydev, 0x10 + ((regnum & 0xf) >> 1), val);
+		rtl821x_write_page(phydev, 0);
+	} else if (devnum == MDIO_MMD_AN && regnum == MDIO_AN_EEE_ADV) {
 		rtl821x_write_page(phydev, 0xa5d);
 		ret = __phy_write(phydev, 0x10, val);
 		rtl821x_write_page(phydev, 0);
Signature · 1 line
2.47.1
maintainer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH net-next v2 1/3] net: phy: realtek: add support for reading MDIO_MMD_VEND2 regs on RTL8125/RTL8126

Quoted 6 lines · Heiner Kallweit

RTL8125/RTL8126 don't support MMD access to the internal PHY, but provide a mechanism to access at least all MDIO_MMD_VEND2 registers. By exposing this mechanism standard MMD access functions can be used to access the MDIO_MMD_VEND2 registers.

Andrew

author maintainer
#3 lore raw

PATCH v2 2/3 net: phy: move realtek PHY driver to its own subdirectory

In reply to Heiner Kallweit

In preparation of adding a source file with hwmon support, move the Realtek PHY driver to its own subdirectory and rename realtek.c to realtek_main.c.

---
 drivers/net/phy/Kconfig                               | 5 +----
 drivers/net/phy/Makefile                              | 2 +-
 drivers/net/phy/realtek/Kconfig                       | 5 +++++
 drivers/net/phy/realtek/Makefile                      | 3 +++
 drivers/net/phy/{realtek.c => realtek/realtek_main.c} | 0
 5 files changed, 10 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/phy/realtek/Kconfig
 create mode 100644 drivers/net/phy/realtek/Makefile
 rename drivers/net/phy/{realtek.c => realtek/realtek_main.c} (100%)
drivers/net/phy/Kconfig +1 -4
index dc625f2b3..e043d3ef1 100644
@@ -350,10 +350,7 @@ config QSEMI_PHY
 	help
 	  Currently supports the qs6612
 
-config REALTEK_PHY
-	tristate "Realtek PHYs"
-	help
-	  Supports the Realtek 821x PHY.
+source "drivers/net/phy/realtek/Kconfig"
 
 config RENESAS_PHY
 	tristate "Renesas PHYs"
drivers/net/phy/Makefile +1 -1
index 39b72b464..c8dac6e92 100644
@@ -95,7 +95,7 @@ obj-$(CONFIG_NXP_CBTX_PHY)	+= nxp-cbtx.o
 obj-$(CONFIG_NXP_TJA11XX_PHY)	+= nxp-tja11xx.o
 obj-y				+= qcom/
 obj-$(CONFIG_QSEMI_PHY)		+= qsemi.o
-obj-$(CONFIG_REALTEK_PHY)	+= realtek.o
+obj-$(CONFIG_REALTEK_PHY)	+= realtek/
 obj-$(CONFIG_RENESAS_PHY)	+= uPD60620.o
 obj-$(CONFIG_ROCKCHIP_PHY)	+= rockchip.o
 obj-$(CONFIG_SMSC_PHY)		+= smsc.o
drivers/net/phy/realtek/Kconfig new file +5 -0
new file mode 100644
index 000000000..5b9e6e6db
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config REALTEK_PHY
+	tristate "Realtek PHYs"
+	help
+	  Currently supports RTL821x/RTL822x and fast ethernet PHYs
drivers/net/phy/realtek/Makefile new file +3 -0
new file mode 100644
index 000000000..996a80642
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+realtek-y			+= realtek_main.o
+obj-$(CONFIG_REALTEK_PHY)	+= realtek.o
drivers/net/phy/realtek/realtek_main.c renamed from drivers/net/phy/realtek.c +0 -0
similarity index 100%
rename from drivers/net/phy/realtek.c
rename to drivers/net/phy/realtek/realtek_main.c
Signature · 1 line
2.47.1
maintainer Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH net-next v2 2/3] net: phy: move realtek PHY driver to its own subdirectory

Quoted 5 lines · Heiner Kallweit

In preparation of adding a source file with hwmon support, move the Realtek PHY driver to its own subdirectory and rename realtek.c to realtek_main.c.

Andrew

author maintainer
#5 lore raw

PATCH v2 3/3 net: phy: realtek: add hwmon support for temp sensor on RTL822x

In reply to Heiner Kallweit

This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the integrated PHY's in RTL8125B/RTL8125D/RTL8126.

---
 drivers/net/phy/realtek/Kconfig         |  6 ++
 drivers/net/phy/realtek/Makefile        |  1 +
 drivers/net/phy/realtek/realtek.h       | 10 ++++
 drivers/net/phy/realtek/realtek_hwmon.c | 79 +++++++++++++++++++++++++
 drivers/net/phy/realtek/realtek_main.c  | 12 ++++
 5 files changed, 108 insertions(+)
 create mode 100644 drivers/net/phy/realtek/realtek.h
 create mode 100644 drivers/net/phy/realtek/realtek_hwmon.c
drivers/net/phy/realtek/Kconfig +6 -0
index 5b9e6e6db..31935f147 100644
@@ -3,3 +3,9 @@ config REALTEK_PHY
 	tristate "Realtek PHYs"
 	help
 	  Currently supports RTL821x/RTL822x and fast ethernet PHYs
+
+config REALTEK_PHY_HWMON
+	def_bool REALTEK_PHY && HWMON
+	depends on !(REALTEK_PHY=y && HWMON=m)
+	help
+	  Optional hwmon support for the temperature sensor
drivers/net/phy/realtek/Makefile +1 -0
index 996a80642..dd21cf87f 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 realtek-y			+= realtek_main.o
+realtek-$(CONFIG_REALTEK_PHY_HWMON) += realtek_hwmon.o
 obj-$(CONFIG_REALTEK_PHY)	+= realtek.o
drivers/net/phy/realtek/realtek.h new file +10 -0
new file mode 100644
index 000000000..a39b44fa1
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef REALTEK_H
+#define REALTEK_H
+
+#include <linux/phy.h>
+
+int rtl822x_hwmon_init(struct phy_device *phydev);
+
+#endif /* REALTEK_H */
drivers/net/phy/realtek/realtek_hwmon.c new file +79 -0

79 lines not on this page · raw message

drivers/net/phy/realtek/realtek_main.c +12 -0
index af9874143..38149958d 100644
@@ -14,6 +14,8 @@
 #include <linux/delay.h>
 #include <linux/clk.h>
 
+#include "realtek.h"
+
 #define RTL821x_PHYSR				0x11
 #define RTL821x_PHYSR_DUPLEX			BIT(13)
 #define RTL821x_PHYSR_SPEED			GENMASK(15, 14)
@@ -820,6 +822,15 @@ static int rtl822x_write_mmd(struct phy_device *phydev, int devnum, u16 regnum,
 	return ret;
 }
 
+static int rtl822x_probe(struct phy_device *phydev)
+{
+	if (IS_ENABLED(CONFIG_REALTEK_PHY_HWMON) &&
+	    phydev->phy_id != RTL_GENERIC_PHYID)
+		return rtl822x_hwmon_init(phydev);
+
+	return 0;
+}
+
 static int rtl822xb_config_init(struct phy_device *phydev)
 {
 	bool has_2500, has_sgmii;
@@ -1519,6 +1530,7 @@ static struct phy_driver realtek_drvs[] = {
 		.match_phy_device = rtl_internal_nbaset_match_phy_device,
 		.name           = "Realtek Internal NBASE-T PHY",
 		.flags		= PHY_IS_INTERNAL,
+		.probe		= rtl822x_probe,
 		.get_features   = rtl822x_get_features,
 		.config_aneg    = rtl822x_config_aneg,
 		.read_status    = rtl822x_read_status,
Signature · 1 line
2.47.1
maintainer
#6 lore raw

Re: [PATCH net-next v2 3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x

drivers/net/phy/realtek/Kconfig config REALTEK_PHY · line 11

Quoted 5 lines
drivers/net/phy/realtek/Kconfig +5 -0
+config REALTEK_PHY_HWMON
+	def_bool REALTEK_PHY && HWMON
+	depends on !(REALTEK_PHY=y && HWMON=m)
+	help
+	  Optional hwmon support for the temperature sensor

We frequently end up with build problems with HWMON. All the other PHYs use:

        depends on HWMON || HWMON=n

We have not yet seen 0-day report issues with your earlier patchsets versions, but maybe we should keep it the same as all other PHYs? But maybe it is actually the same, if you apply De Morgan's Law?

Andrew

author maintainer
#7 lore raw

Re: [PATCH net-next v2 3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x

Quoted 11 lines · Andrew Lunn

drivers/net/phy/realtek/Kconfig config REALTEK_PHY · line 11

Quoted 5 lines
drivers/net/phy/realtek/Kconfig +5 -0
+config REALTEK_PHY_HWMON
+	def_bool REALTEK_PHY && HWMON
+	depends on !(REALTEK_PHY=y && HWMON=m)
+	help
+	  Optional hwmon support for the temperature sensor

We frequently end up with build problems with HWMON. All the other PHYs use:

        depends on HWMON || HWMON=n

The situation is different here. In the other cases HWMON is used from the main source file. If HWMON=n, then the main source file can be built as module or be built-in, and the stubs of the HWMON functions are used.

In my case, if HWMON=n, I want REALTEK_PHY_HWMON to be n, because then I omit building realtek_hwmon.c (see Makefile).

Quoted 5 lines

We have not yet seen 0-day report issues with your earlier patchsets versions, but maybe we should keep it the same as all other PHYs? But maybe it is actually the same, if you apply De Morgan's Law?

Andrew

Heiner

maintainer Reviewed-by
#8 lore raw

Re: [PATCH net-next v2 3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x

Quoted 2 lines

In my case, if HWMON=n, I want REALTEK_PHY_HWMON to be n, because then I omit building realtek_hwmon.c (see Makefile).

Thanks for the explanation.

Andrew

#9 lore raw

Re: [PATCH net-next v2 3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x

In reply to Heiner Kallweit

Hi Heiner,

CC hwmon

Quoted 5 lines · Heiner Kallweit

This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the integrated PHY's in RTL8125B/RTL8125D/RTL8126.

Thanks for your patch, which is now commit 33700ca45b7d2e16 ("net: phy: realtek: add hwmon support for temp sensor on RTL822x") in net-next.

drivers/net/phy/realtek/Kconfig config REALTEK_PHY · line 11

Quoted 12 lines
drivers/net/phy/realtek/Kconfig +6 -0
@@ -3,3 +3,9 @@ config REALTEK_PHY
 	tristate "Realtek PHYs"
 	help
 	  Currently supports RTL821x/RTL822x and fast ethernet PHYs
+
+config REALTEK_PHY_HWMON
+	def_bool REALTEK_PHY && HWMON
+	depends on !(REALTEK_PHY=y && HWMON=m)
+	help
+	  Optional hwmon support for the temperature sensor

So this is optional, but as the symbol is invisible, it cannot be disabled by the user. Is that intentional?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#10 lore raw

Re: [PATCH net-next v2 3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x

Quoted 15 lines · Geert Uytterhoeven

    Hi Heiner,

CC hwmon

Quoted 5 lines · Heiner Kallweit

This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the integrated PHY's in RTL8125B/RTL8125D/RTL8126.

Thanks for your patch, which is now commit 33700ca45b7d2e16 ("net: phy: realtek: add hwmon support for temp sensor on RTL822x") in net-next.

Quoted 16 lines

drivers/net/phy/realtek/Kconfig config REALTEK_PHY · line 11

Quoted 12 lines
drivers/net/phy/realtek/Kconfig +0 -0
@@ -3,3 +3,9 @@ config REALTEK_PHY

    tristate "Realtek PHYs"
    help
      Currently supports RTL821x/RTL822x and fast ethernet PHYs

drivers/net/phy/realtek/Kconfig +6 -0
+
+config REALTEK_PHY_HWMON
+    def_bool REALTEK_PHY && HWMON
+    depends on !(REALTEK_PHY=y && HWMON=m)
+    help
+      Optional hwmon support for the temperature sensor

So this is optional, but as the symbol is invisible, it cannot be disabled by the user. Is that intentional?

Well, it isn't intentional in either direction. Thanks for the hint, I should make it user-visible.

Quoted 11 lines

Gr{oetje,eeting}s,

                        Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#11 lore raw
In reply to Heiner Kallweit
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 9 lines · On Sat, 11 Jan 2025 21:48:29 +0100 you wrote:

This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the internal PHY's of RTL8125B(P)/RTL8125D/RTL8126.

v2:
- patch 2: move Realtek PHY driver to its own subdirectory
- patch 3: remove alarm attribute

[...]

Here is the summary with links:
- [net-next,v2,1/3] net: phy: realtek: add support for reading MDIO_MMD_VEND2 regs on RTL8125/RTL8126

    https://git.kernel.org/netdev/net-next/c/3d483a10327f
  - [net-next,v2,2/3] net: phy: move realtek PHY driver to its own subdirectory
    https://git.kernel.org/netdev/net-next/c/1416a9b2ba71
  - [net-next,v2,3/3] net: phy: realtek: add hwmon support for temp sensor on RTL822x
    https://git.kernel.org/netdev/net-next/c/33700ca45b7d

You are awesome, thank you!

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