drivers/net/phy/realtek/realtek_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/realtek/realtek_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/realtek/realtek_hwmon.c- Extension
.c- Size
- 1743 bytes
- Lines
- 75
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hwmon.hlinux/phy.hrealtek.h
Detected Declarations
function rtl822x_hwmon_get_tempfunction rtl822x_hwmon_readfunction rtl822x_hwmon_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* HWMON support for Realtek PHY's
*
* Author: Heiner Kallweit <hkallweit1@gmail.com>
*/
#include <linux/hwmon.h>
#include <linux/phy.h>
#include "realtek.h"
#define RTL822X_VND2_TSALRM 0xa662
#define RTL822X_VND2_TSRR 0xbd84
#define RTL822X_VND2_TSSR 0xb54c
static int rtl822x_hwmon_get_temp(int raw)
{
if (raw >= 512)
raw -= 1024;
return 1000 * raw / 2;
}
static int rtl822x_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct phy_device *phydev = dev_get_drvdata(dev);
int raw;
switch (attr) {
case hwmon_temp_input:
raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSRR) & 0x3ff;
*val = rtl822x_hwmon_get_temp(raw);
break;
case hwmon_temp_max:
/* Chip reduces speed to 1G if threshold is exceeded */
raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSSR) >> 6;
*val = rtl822x_hwmon_get_temp(raw);
break;
default:
return -EINVAL;
}
return 0;
}
static const struct hwmon_ops rtl822x_hwmon_ops = {
.visible = 0444,
.read = rtl822x_hwmon_read,
};
static const struct hwmon_channel_info * const rtl822x_hwmon_info[] = {
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MAX),
NULL
};
static const struct hwmon_chip_info rtl822x_hwmon_chip_info = {
.ops = &rtl822x_hwmon_ops,
.info = rtl822x_hwmon_info,
};
int rtl822x_hwmon_init(struct phy_device *phydev)
{
struct device *hwdev, *dev = &phydev->mdio.dev;
/* Ensure over-temp alarm is reset. */
phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSALRM, 3);
hwdev = devm_hwmon_device_register_with_info(dev, NULL, phydev,
&rtl822x_hwmon_chip_info,
NULL);
return PTR_ERR_OR_ZERO(hwdev);
}
Annotation
- Immediate include surface: `linux/hwmon.h`, `linux/phy.h`, `realtek.h`.
- Detected declarations: `function rtl822x_hwmon_get_temp`, `function rtl822x_hwmon_read`, `function rtl822x_hwmon_init`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.