drivers/hwmon/lm92.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/lm92.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/lm92.c- Extension
.c- Size
- 10554 bytes
- Lines
- 432
- 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/err.hlinux/hwmon.hlinux/i2c.hlinux/init.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct lm92_datafunction limitsfunction TEMP_TO_REGfunction ALARMS_FROM_REGfunction lm92_temp_readfunction lm92_chip_readfunction lm92_readfunction lm92_temp_writefunction lm92_writefunction lm92_is_visiblefunction lm92_init_clientfunction lm92_detectfunction lm92_reg_readfunction lm92_reg_writefunction lm92_regmap_is_volatilefunction lm92_regmap_is_writeablefunction lm92_probe
Annotated Snippet
struct lm92_data {
struct regmap *regmap;
int resolution;
};
static int lm92_temp_read(struct lm92_data *data, u32 attr, int channel, long *val)
{
int reg = -1, hyst_reg = -1, alarm_bit = 0;
struct regmap *regmap = data->regmap;
u32 temp;
int ret;
switch (attr) {
case hwmon_temp_input:
reg = LM92_REG_TEMP;
break;
case hwmon_temp_min:
reg = LM92_REG_TEMP_LOW;
break;
case hwmon_temp_max:
reg = LM92_REG_TEMP_HIGH;
break;
case hwmon_temp_crit:
reg = LM92_REG_TEMP_CRIT;
break;
case hwmon_temp_min_hyst:
hyst_reg = LM92_REG_TEMP_LOW;
break;
case hwmon_temp_max_hyst:
hyst_reg = LM92_REG_TEMP_HIGH;
break;
case hwmon_temp_crit_hyst:
hyst_reg = LM92_REG_TEMP_CRIT;
break;
case hwmon_temp_min_alarm:
alarm_bit = 0;
break;
case hwmon_temp_max_alarm:
alarm_bit = 1;
break;
case hwmon_temp_crit_alarm:
alarm_bit = 2;
break;
default:
return -EOPNOTSUPP;
}
if (reg >= 0) {
ret = regmap_read(regmap, reg, &temp);
if (ret < 0)
return ret;
*val = TEMP_FROM_REG(temp);
} else if (hyst_reg >= 0) {
u32 regs[2] = { hyst_reg, LM92_REG_TEMP_HYST };
u16 regvals[2];
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
if (attr == hwmon_temp_min_hyst)
*val = TEMP_FROM_REG(regvals[0]) + TEMP_FROM_REG(regvals[1]);
else
*val = TEMP_FROM_REG(regvals[0]) - TEMP_FROM_REG(regvals[1]);
} else {
ret = regmap_read(regmap, LM92_REG_TEMP, &temp);
if (ret)
return ret;
*val = !!(temp & BIT(alarm_bit));
}
return 0;
}
static int lm92_chip_read(struct lm92_data *data, u32 attr, long *val)
{
u32 temp;
int ret;
switch (attr) {
case hwmon_chip_alarms:
ret = regmap_read(data->regmap, LM92_REG_TEMP, &temp);
if (ret)
return ret;
*val = ALARMS_FROM_REG(temp);
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static int lm92_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/init.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct lm92_data`, `function limits`, `function TEMP_TO_REG`, `function ALARMS_FROM_REG`, `function lm92_temp_read`, `function lm92_chip_read`, `function lm92_read`, `function lm92_temp_write`, `function lm92_write`, `function lm92_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.