drivers/hwmon/lan966x-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/lan966x-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/lan966x-hwmon.c- Extension
.c- Size
- 9811 bytes
- Lines
- 397
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/clk.hlinux/hwmon.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/polynomial.hlinux/regmap.h
Detected Declarations
struct lan966x_hwmonfunction lan966x_hwmon_read_tempfunction lan966x_hwmon_read_fanfunction lan966x_hwmon_read_pwmfunction lan966x_hwmon_read_pwm_freqfunction lan966x_hwmon_readfunction lan966x_hwmon_write_pwmfunction lan966x_hwmon_write_pwm_freqfunction lan966x_hwmon_writefunction lan966x_hwmon_is_visiblefunction lan966x_hwmon_disablefunction lan966x_hwmon_enablefunction lan966x_hwmon_probe
Annotated Snippet
struct lan966x_hwmon {
struct regmap *regmap_pvt;
struct regmap *regmap_fan;
struct clk *clk;
unsigned long clk_rate;
};
static int lan966x_hwmon_read_temp(struct device *dev, long *val)
{
struct lan966x_hwmon *hwmon = dev_get_drvdata(dev);
unsigned int data;
int ret;
ret = regmap_read(hwmon->regmap_pvt, PVT_SENSOR_STAT, &data);
if (ret < 0)
return ret;
if (!(data & SENSOR_STAT_DATA_VALID))
return -ENODATA;
*val = polynomial_calc(&poly_N_to_temp,
FIELD_GET(SENSOR_STAT_DATA, data));
return 0;
}
static int lan966x_hwmon_read_fan(struct device *dev, long *val)
{
struct lan966x_hwmon *hwmon = dev_get_drvdata(dev);
unsigned int data;
int ret;
ret = regmap_read(hwmon->regmap_fan, FAN_CNT, &data);
if (ret < 0)
return ret;
/*
* Data is given in pulses per second. Assume two pulses
* per revolution.
*/
*val = FIELD_GET(FAN_CNT_DATA, data) * 60 / 2;
return 0;
}
static int lan966x_hwmon_read_pwm(struct device *dev, long *val)
{
struct lan966x_hwmon *hwmon = dev_get_drvdata(dev);
unsigned int data;
int ret;
ret = regmap_read(hwmon->regmap_fan, FAN_CFG, &data);
if (ret < 0)
return ret;
*val = FIELD_GET(FAN_CFG_DUTY_CYCLE, data);
return 0;
}
static int lan966x_hwmon_read_pwm_freq(struct device *dev, long *val)
{
struct lan966x_hwmon *hwmon = dev_get_drvdata(dev);
unsigned long tmp;
unsigned int data;
int ret;
ret = regmap_read(hwmon->regmap_fan, FAN_PWM_FREQ, &data);
if (ret < 0)
return ret;
/*
* Datasheet says it is sys_clk / 256 / pwm_freq. But in reality
* it is sys_clk / 256 / (pwm_freq + 1).
*/
data = FIELD_GET(FAN_PWM_FREQ_FREQ, data) + 1;
tmp = DIV_ROUND_CLOSEST(hwmon->clk_rate, 256);
*val = DIV_ROUND_CLOSEST(tmp, data);
return 0;
}
static int lan966x_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
switch (type) {
case hwmon_temp:
return lan966x_hwmon_read_temp(dev, val);
case hwmon_fan:
return lan966x_hwmon_read_fan(dev, val);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/hwmon.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/polynomial.h`.
- Detected declarations: `struct lan966x_hwmon`, `function lan966x_hwmon_read_temp`, `function lan966x_hwmon_read_fan`, `function lan966x_hwmon_read_pwm`, `function lan966x_hwmon_read_pwm_freq`, `function lan966x_hwmon_read`, `function lan966x_hwmon_write_pwm`, `function lan966x_hwmon_write_pwm_freq`, `function lan966x_hwmon_write`, `function lan966x_hwmon_is_visible`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.