drivers/hwmon/max31760.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max31760.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max31760.c- Extension
.c- Size
- 13246 bytes
- Lines
- 596
- 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/bits.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/i2c.hlinux/regmap.hlinux/util_macros.h
Detected Declarations
struct max31760_statestruct lut_attributefunction max31760_volatile_regfunction tach_to_rpmfunction max31760_readfunction max31760_writefunction max31760_is_visiblefunction max31760_read_stringfunction lut_showfunction lut_storefunction pwm1_auto_point_temp_hyst_showfunction pwm1_auto_point_temp_hyst_storefunction max31760_create_lut_nodesfunction max31760_probefunction max31760_suspendfunction max31760_resume
Annotated Snippet
struct max31760_state {
struct regmap *regmap;
struct lut_attribute {
char name[24];
struct sensor_device_attribute sda;
} lut[LUT_SIZE];
struct attribute *attrs[LUT_SIZE + 2];
struct attribute_group group;
const struct attribute_group *groups[2];
};
static bool max31760_volatile_reg(struct device *dev, unsigned int reg)
{
return reg > 0x50;
}
static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x5B,
.cache_type = REGCACHE_MAPLE,
.volatile_reg = max31760_volatile_reg,
};
static const int max31760_pwm_freq[] = {33, 150, 1500, 25000};
static int tach_to_rpm(u16 tach)
{
if (tach == 0)
tach = 1;
return 60 * 100000 / tach / 2;
}
static int max31760_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct max31760_state *state = dev_get_drvdata(dev);
unsigned int regval;
unsigned int reg_temp;
s16 temp;
u8 reg[2];
int ret;
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_fault:
ret = regmap_read(state->regmap, REG_STATUS, ®val);
if (ret)
return ret;
*val = FIELD_GET(STATUS_RDFA, regval);
return 0;
case hwmon_temp_max_alarm:
ret = regmap_read(state->regmap, REG_STATUS, ®val);
if (ret)
return ret;
if (channel)
*val = FIELD_GET(STATUS_ALARM_MAX(1), regval);
else
*val = FIELD_GET(STATUS_ALARM_MAX(0), regval);
return 0;
case hwmon_temp_crit_alarm:
ret = regmap_read(state->regmap, REG_STATUS, ®val);
if (ret)
return ret;
if (channel)
*val = FIELD_GET(STATUS_ALARM_CRIT(1), regval);
else
*val = FIELD_GET(STATUS_ALARM_CRIT(0), regval);
return 0;
case hwmon_temp_input:
reg_temp = REG_TEMP_INPUT(channel);
break;
case hwmon_temp_max:
reg_temp = REG_TEMP_MAX(channel);
break;
case hwmon_temp_crit:
reg_temp = REG_TEMP_CRIT(channel);
break;
default:
return -EOPNOTSUPP;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/i2c.h`, `linux/regmap.h`, `linux/util_macros.h`.
- Detected declarations: `struct max31760_state`, `struct lut_attribute`, `function max31760_volatile_reg`, `function tach_to_rpm`, `function max31760_read`, `function max31760_write`, `function max31760_is_visible`, `function max31760_read_string`, `function lut_show`, `function lut_store`.
- 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.