drivers/hwmon/tmp464.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/tmp464.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/tmp464.c- Extension
.c- Size
- 18517 bytes
- Lines
- 693
- 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/of.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct tmp464_channelstruct tmp464_datafunction temp_from_regfunction temp_to_limit_regfunction temp_to_offset_regfunction tmp464_enable_channelsfunction tmp464_chip_readfunction tmp464_temp_readfunction tmp464_readfunction tmp464_read_stringfunction tmp464_set_convratefunction tmp464_chip_writefunction tmp464_temp_writefunction tmp464_writefunction tmp464_is_visiblefunction tmp464_restore_lockfunction tmp464_restore_configfunction tmp464_init_clientfunction tmp464_detectfunction tmp464_probe_child_from_dtfunction tmp464_probe_from_dtfunction for_each_child_of_node_scopedfunction tmp464_is_volatile_regfunction tmp464_probe
Annotated Snippet
struct tmp464_channel {
const char *label;
bool enabled;
};
struct tmp464_data {
struct regmap *regmap;
int channels;
s16 config_orig;
u16 open_reg;
unsigned long last_updated;
bool valid;
int update_interval;
struct tmp464_channel channel[MAX_CHANNELS];
};
static int temp_from_reg(s16 reg)
{
return DIV_ROUND_CLOSEST((reg >> 3) * 625, 10);
}
static s16 temp_to_limit_reg(long temp)
{
return DIV_ROUND_CLOSEST(temp, 500) << 6;
}
static s16 temp_to_offset_reg(long temp)
{
return DIV_ROUND_CLOSEST(temp * 10, 625) << 3;
}
static int tmp464_enable_channels(struct tmp464_data *data)
{
struct regmap *regmap = data->regmap;
u16 enable = 0;
int i;
for (i = 0; i < data->channels; i++)
if (data->channel[i].enabled)
enable |= TMP464_CONFIG_REG_REN(i);
return regmap_update_bits(regmap, TMP464_CONFIG_REG, TMP464_CONFIG_REG_REN_MASK, enable);
}
static int tmp464_chip_read(struct device *dev, u32 attr, int channel, long *val)
{
struct tmp464_data *data = dev_get_drvdata(dev);
switch (attr) {
case hwmon_chip_update_interval:
*val = data->update_interval;
return 0;
default:
return -EOPNOTSUPP;
}
}
static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val)
{
struct tmp464_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap;
unsigned int regs[2];
unsigned int regval;
u16 regvals[2];
int err = 0;
switch (attr) {
case hwmon_temp_max_alarm:
err = regmap_read(regmap, TMP464_THERM_STATUS_REG, ®val);
if (err < 0)
break;
*val = !!(regval & BIT(channel + 7));
break;
case hwmon_temp_crit_alarm:
err = regmap_read(regmap, TMP464_THERM2_STATUS_REG, ®val);
if (err < 0)
break;
*val = !!(regval & BIT(channel + 7));
break;
case hwmon_temp_fault:
/*
* The chip clears TMP464_REMOTE_OPEN_REG after it is read
* and only updates it after the next measurement cycle is
* complete. That means we have to cache the value internally
* for one measurement cycle and report the cached value.
*/
if (!data->valid || time_after(jiffies, data->last_updated +
msecs_to_jiffies(data->update_interval))) {
err = regmap_read(regmap, TMP464_REMOTE_OPEN_REG, ®val);
if (err < 0)
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/init.h`, `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct tmp464_channel`, `struct tmp464_data`, `function temp_from_reg`, `function temp_to_limit_reg`, `function temp_to_offset_reg`, `function tmp464_enable_channels`, `function tmp464_chip_read`, `function tmp464_temp_read`, `function tmp464_read`, `function tmp464_read_string`.
- 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.