netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B
@ 2024-10-07 18:34 Heiner Kallweit
  2024-10-09  8:41 ` Simon Horman
  2024-10-09 12:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Heiner Kallweit @ 2024-10-07 18:34 UTC (permalink / raw)
  To: Realtek linux nic maintainers, Paolo Abeni, Jakub Kicinski,
	David Miller, Eric Dumazet, Jean Delvare, Guenter Roeck
  Cc: netdev@vger.kernel.org, linux-hwmon@vger.kernel.org

This adds support for the temperature sensor being available from
RTL8125B. Register information was taken from r8125 vendor driver.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v2:
- don't omit identifiers in definition of r8169_hwmon_is_visible()
---
 drivers/net/ethernet/realtek/r8169_main.c | 44 +++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 305ec19cc..6a9259d85 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -16,6 +16,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/ethtool.h>
+#include <linux/hwmon.h>
 #include <linux/phy.h>
 #include <linux/if_vlan.h>
 #include <linux/in.h>
@@ -5363,6 +5364,43 @@ static bool rtl_aspm_is_safe(struct rtl8169_private *tp)
 	return false;
 }
 
+static umode_t r8169_hwmon_is_visible(const void *drvdata,
+				      enum hwmon_sensor_types type,
+				      u32 attr, int channel)
+{
+	return 0444;
+}
+
+static int r8169_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
+			    u32 attr, int channel, long *val)
+{
+	struct rtl8169_private *tp = dev_get_drvdata(dev);
+	int val_raw;
+
+	val_raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
+	if (val_raw >= 512)
+		val_raw -= 1024;
+
+	*val = 1000 * val_raw / 2;
+
+	return 0;
+}
+
+static const struct hwmon_ops r8169_hwmon_ops = {
+	.is_visible =  r8169_hwmon_is_visible,
+	.read = r8169_hwmon_read,
+};
+
+static const struct hwmon_channel_info * const r8169_hwmon_info[] = {
+	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
+	NULL
+};
+
+static const struct hwmon_chip_info r8169_hwmon_chip_info = {
+	.ops = &r8169_hwmon_ops,
+	.info = r8169_hwmon_info,
+};
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5537,6 +5575,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		return rc;
 
+	/* The temperature sensor is available from RTl8125B */
+	if (IS_REACHABLE(CONFIG_HWMON) && tp->mac_version >= RTL_GIGA_MAC_VER_63)
+		/* ignore errors */
+		devm_hwmon_device_register_with_info(&pdev->dev, "nic_temp", tp,
+						     &r8169_hwmon_chip_info,
+						     NULL);
 	rc = register_netdev(dev);
 	if (rc)
 		return rc;
-- 
2.46.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B
  2024-10-07 18:34 [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B Heiner Kallweit
@ 2024-10-09  8:41 ` Simon Horman
  2024-10-09 12:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-10-09  8:41 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Realtek linux nic maintainers, Paolo Abeni, Jakub Kicinski,
	David Miller, Eric Dumazet, Jean Delvare, Guenter Roeck,
	netdev@vger.kernel.org, linux-hwmon@vger.kernel.org

On Mon, Oct 07, 2024 at 08:34:12PM +0200, Heiner Kallweit wrote:
> This adds support for the temperature sensor being available from
> RTL8125B. Register information was taken from r8125 vendor driver.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - don't omit identifiers in definition of r8169_hwmon_is_visible()

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B
  2024-10-07 18:34 [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B Heiner Kallweit
  2024-10-09  8:41 ` Simon Horman
@ 2024-10-09 12:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-09 12:40 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: nic_swsd, pabeni, kuba, davem, edumazet, jdelvare, linux, netdev,
	linux-hwmon

Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Mon, 7 Oct 2024 20:34:12 +0200 you wrote:
> This adds support for the temperature sensor being available from
> RTL8125B. Register information was taken from r8125 vendor driver.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - don't omit identifiers in definition of r8169_hwmon_is_visible()
> 
> [...]

Here is the summary with links:
  - [net-next,v2] r8169: add support for the temperature sensor being available from RTL8125B
    https://git.kernel.org/netdev/net-next/c/1ffcc8d41306

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-09 12:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07 18:34 [PATCH net-next v2] r8169: add support for the temperature sensor being available from RTL8125B Heiner Kallweit
2024-10-09  8:41 ` Simon Horman
2024-10-09 12:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).