drivers/hwmon/max31827.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max31827.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max31827.c- Extension
.c- Size
- 15650 bytes
- Lines
- 646
- 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/bitops.hlinux/delay.hlinux/hwmon.hlinux/i2c.hlinux/of_device.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct max31827_stateenum chipsenum max31827_cnvenum max31827_resolutionfunction shutdown_writefunction write_alarm_valfunction max31827_is_visiblefunction max31827_readfunction max31827_writefunction temp1_resolution_showfunction temp1_resolution_storefunction max31827_init_clientfunction max31827_probe
Annotated Snippet
struct max31827_state {
/*
* Prevent simultaneous access to the i2c client.
*/
struct regmap *regmap;
bool enable;
unsigned int resolution;
unsigned int update_interval;
};
static const struct regmap_config max31827_regmap = {
.reg_bits = 8,
.val_bits = 16,
.max_register = 0xA,
};
static int shutdown_write(struct max31827_state *st, unsigned int reg,
unsigned int mask, unsigned int val)
{
unsigned int cfg;
unsigned int cnv_rate;
int ret;
/*
* Before the Temperature Threshold Alarm, Alarm Hysteresis Threshold
* and Resolution bits from Configuration register are changed over I2C,
* the part must be in shutdown mode.
*/
if (!st->enable) {
if (!mask)
return regmap_write(st->regmap, reg, val);
return regmap_update_bits(st->regmap, reg, mask, val);
}
ret = regmap_read(st->regmap, MAX31827_CONFIGURATION_REG, &cfg);
if (ret)
return ret;
cnv_rate = MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg;
cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |
MAX31827_CONFIGURATION_CNV_RATE_MASK);
ret = regmap_write(st->regmap, MAX31827_CONFIGURATION_REG, cfg);
if (ret)
return ret;
if (!mask)
ret = regmap_write(st->regmap, reg, val);
else
ret = regmap_update_bits(st->regmap, reg, mask, val);
if (ret)
return ret;
return regmap_update_bits(st->regmap, MAX31827_CONFIGURATION_REG,
MAX31827_CONFIGURATION_CNV_RATE_MASK,
cnv_rate);
}
static int write_alarm_val(struct max31827_state *st, unsigned int reg,
long val)
{
val = MAX31827_M_DGR_TO_16_BIT(val);
return shutdown_write(st, reg, 0, val);
}
static umode_t max31827_is_visible(const void *state,
enum hwmon_sensor_types type, u32 attr,
int channel)
{
if (type == hwmon_temp) {
switch (attr) {
case hwmon_temp_enable:
case hwmon_temp_max:
case hwmon_temp_min:
case hwmon_temp_max_hyst:
case hwmon_temp_min_hyst:
return 0644;
case hwmon_temp_input:
case hwmon_temp_min_alarm:
case hwmon_temp_max_alarm:
return 0444;
default:
return 0;
}
} else if (type == hwmon_chip) {
if (attr == hwmon_chip_update_interval)
return 0644;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/delay.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/of_device.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct max31827_state`, `enum chips`, `enum max31827_cnv`, `enum max31827_resolution`, `function shutdown_write`, `function write_alarm_val`, `function max31827_is_visible`, `function max31827_read`, `function max31827_write`, `function temp1_resolution_show`.
- 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.