|
16 | 16 | #include <linux/clk.h>
|
17 | 17 | #include <linux/delay.h>
|
18 | 18 | #include <linux/ethtool.h>
|
| 19 | +#include <linux/hwmon.h> |
19 | 20 | #include <linux/phy.h>
|
20 | 21 | #include <linux/if_vlan.h>
|
21 | 22 | #include <linux/in.h>
|
@@ -5363,6 +5364,43 @@ static bool rtl_aspm_is_safe(struct rtl8169_private *tp)
|
5363 | 5364 | return false;
|
5364 | 5365 | }
|
5365 | 5366 |
|
| 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 | + |
5366 | 5404 | static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
5367 | 5405 | {
|
5368 | 5406 | struct rtl8169_private *tp;
|
@@ -5537,6 +5575,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
5537 | 5575 | if (rc)
|
5538 | 5576 | return rc;
|
5539 | 5577 |
|
| 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); |
5540 | 5584 | rc = register_netdev(dev);
|
5541 | 5585 | if (rc)
|
5542 | 5586 | return rc;
|
|
0 commit comments