1 From 1ffcc8d41306fd2e5f140b276820714a26a11cc4 Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Mon, 7 Oct 2024 20:34:12 +0200
4 Subject: [PATCH] r8169: add support for the temperature sensor being available
7 This adds support for the temperature sensor being available from
8 RTL8125B. Register information was taken from r8125 vendor driver.
10 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
11 Reviewed-by: Simon Horman <horms@kernel.org>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
14 drivers/net/ethernet/realtek/r8169_main.c | 44 +++++++++++++++++++++++
15 1 file changed, 44 insertions(+)
17 --- a/drivers/net/ethernet/realtek/r8169_main.c
18 +++ b/drivers/net/ethernet/realtek/r8169_main.c
20 #include <linux/clk.h>
21 #include <linux/delay.h>
22 #include <linux/ethtool.h>
23 +#include <linux/hwmon.h>
24 #include <linux/phy.h>
25 #include <linux/if_vlan.h>
27 @@ -5373,6 +5374,43 @@ static bool rtl_aspm_is_safe(struct rtl8
31 +static umode_t r8169_hwmon_is_visible(const void *drvdata,
32 + enum hwmon_sensor_types type,
33 + u32 attr, int channel)
38 +static int r8169_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
39 + u32 attr, int channel, long *val)
41 + struct rtl8169_private *tp = dev_get_drvdata(dev);
44 + val_raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
48 + *val = 1000 * val_raw / 2;
53 +static const struct hwmon_ops r8169_hwmon_ops = {
54 + .is_visible = r8169_hwmon_is_visible,
55 + .read = r8169_hwmon_read,
58 +static const struct hwmon_channel_info * const r8169_hwmon_info[] = {
59 + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
63 +static const struct hwmon_chip_info r8169_hwmon_chip_info = {
64 + .ops = &r8169_hwmon_ops,
65 + .info = r8169_hwmon_info,
68 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
70 struct rtl8169_private *tp;
71 @@ -5547,6 +5585,12 @@ static int rtl_init_one(struct pci_dev *
75 + /* The temperature sensor is available from RTl8125B */
76 + if (IS_REACHABLE(CONFIG_HWMON) && tp->mac_version >= RTL_GIGA_MAC_VER_63)
78 + devm_hwmon_device_register_with_info(&pdev->dev, "nic_temp", tp,
79 + &r8169_hwmon_chip_info,
81 rc = register_netdev(dev);