drivers/hwmon/max31730.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max31730.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max31730.c- Extension
.c- Size
- 10993 bytes
- Lines
- 440
- 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/bits.hlinux/err.hlinux/i2c.hlinux/init.hlinux/hwmon.hlinux/module.hlinux/of.hlinux/slab.h
Detected Declarations
struct max31730_datafunction max31730_reg_to_mcfunction max31730_write_configfunction max31730_set_enablefunction max31730_set_offset_enablefunction max31730_set_channel_enablefunction max31730_readfunction max31730_writefunction max31730_is_visiblefunction max31730_removefunction max31730_probefunction max31730_check_reg_tempfunction max31730_detectfunction max31730_suspendfunction max31730_resume
Annotated Snippet
struct max31730_data {
struct i2c_client *client;
u8 orig_conf;
u8 current_conf;
u8 offset_enable;
u8 channel_enable;
};
/*-----------------------------------------------------------------------*/
static inline long max31730_reg_to_mc(s16 temp)
{
return DIV_ROUND_CLOSEST((temp >> 4) * 1000, 16);
}
static int max31730_write_config(struct max31730_data *data, u8 set_mask,
u8 clr_mask)
{
u8 value;
clr_mask |= MAX31730_EXTRANGE;
value = data->current_conf & ~clr_mask;
value |= set_mask;
if (data->current_conf != value) {
s32 err;
err = i2c_smbus_write_byte_data(data->client, MAX31730_REG_CONF,
value);
if (err)
return err;
data->current_conf = value;
}
return 0;
}
static int max31730_set_enable(struct i2c_client *client, int reg,
u8 *confdata, int channel, bool enable)
{
u8 regval = *confdata;
int err;
if (enable)
regval |= BIT(channel);
else
regval &= ~BIT(channel);
if (regval != *confdata) {
err = i2c_smbus_write_byte_data(client, reg, regval);
if (err)
return err;
*confdata = regval;
}
return 0;
}
static int max31730_set_offset_enable(struct max31730_data *data, int channel,
bool enable)
{
return max31730_set_enable(data->client, MAX31730_REG_OFFSET_ENABLE,
&data->offset_enable, channel, enable);
}
static int max31730_set_channel_enable(struct max31730_data *data, int channel,
bool enable)
{
return max31730_set_enable(data->client, MAX31730_REG_CHANNEL_ENABLE,
&data->channel_enable, channel, enable);
}
static int max31730_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct max31730_data *data = dev_get_drvdata(dev);
int regval, reg, offset;
if (type != hwmon_temp)
return -EINVAL;
switch (attr) {
case hwmon_temp_input:
if (!(data->channel_enable & BIT(channel)))
return -ENODATA;
reg = MAX31730_REG_TEMP + (channel * 2);
break;
case hwmon_temp_max:
reg = MAX31730_REG_TEMP_MAX + (channel * 2);
break;
case hwmon_temp_min:
reg = MAX31730_REG_TEMP_MIN;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/hwmon.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`.
- Detected declarations: `struct max31730_data`, `function max31730_reg_to_mc`, `function max31730_write_config`, `function max31730_set_enable`, `function max31730_set_offset_enable`, `function max31730_set_channel_enable`, `function max31730_read`, `function max31730_write`, `function max31730_is_visible`, `function max31730_remove`.
- 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.