Skip to content

Commit 1ffcc8d

Browse files
hkallweitdavem330
authored andcommitted
r8169: add support for the temperature sensor being available from RTL8125B
This adds support for the temperature sensor being available from RTL8125B. Register information was taken from r8125 vendor driver. Signed-off-by: Heiner Kallweit <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2a80d89 commit 1ffcc8d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/clk.h>
1717
#include <linux/delay.h>
1818
#include <linux/ethtool.h>
19+
#include <linux/hwmon.h>
1920
#include <linux/phy.h>
2021
#include <linux/if_vlan.h>
2122
#include <linux/in.h>
@@ -5363,6 +5364,43 @@ static bool rtl_aspm_is_safe(struct rtl8169_private *tp)
53635364
return false;
53645365
}
53655366

5367+
static umode_t r8169_hwmon_is_visible(const void *drvdata,
5368+
enum hwmon_sensor_types type,
5369+
u32 attr, int channel)
5370+
{
5371+
return 0444;
5372+
}
5373+
5374+
static int r8169_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
5375+
u32 attr, int channel, long *val)
5376+
{
5377+
struct rtl8169_private *tp = dev_get_drvdata(dev);
5378+
int val_raw;
5379+
5380+
val_raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
5381+
if (val_raw >= 512)
5382+
val_raw -= 1024;
5383+
5384+
*val = 1000 * val_raw / 2;
5385+
5386+
return 0;
5387+
}
5388+
5389+
static const struct hwmon_ops r8169_hwmon_ops = {
5390+
.is_visible = r8169_hwmon_is_visible,
5391+
.read = r8169_hwmon_read,
5392+
};
5393+
5394+
static const struct hwmon_channel_info * const r8169_hwmon_info[] = {
5395+
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
5396+
NULL
5397+
};
5398+
5399+
static const struct hwmon_chip_info r8169_hwmon_chip_info = {
5400+
.ops = &r8169_hwmon_ops,
5401+
.info = r8169_hwmon_info,
5402+
};
5403+
53665404
static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
53675405
{
53685406
struct rtl8169_private *tp;
@@ -5537,6 +5575,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
55375575
if (rc)
55385576
return rc;
55395577

5578+
/* The temperature sensor is available from RTl8125B */
5579+
if (IS_REACHABLE(CONFIG_HWMON) && tp->mac_version >= RTL_GIGA_MAC_VER_63)
5580+
/* ignore errors */
5581+
devm_hwmon_device_register_with_info(&pdev->dev, "nic_temp", tp,
5582+
&r8169_hwmon_chip_info,
5583+
NULL);
55405584
rc = register_netdev(dev);
55415585
if (rc)
55425586
return rc;

0 commit comments

Comments
 (0)