drivers/hwmon/lm95245.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/lm95245.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/lm95245.c- Extension
.c- Size
- 14549 bytes
- Lines
- 579
- 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/init.hlinux/hwmon.hlinux/i2c.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct lm95245_datafunction temp_from_reg_unsignedfunction temp_from_reg_signedfunction lm95245_read_conversion_ratefunction lm95245_set_conversion_ratefunction lm95245_read_tempfunction lm95245_write_tempfunction lm95245_read_chipfunction lm95245_write_chipfunction lm95245_readfunction lm95245_writefunction lm95245_temp_is_visiblefunction lm95245_is_visiblefunction lm95245_detectfunction lm95245_init_clientfunction lm95245_is_writeable_regfunction lm95245_is_volatile_regfunction lm95245_probe
Annotated Snippet
struct lm95245_data {
struct regmap *regmap;
int interval; /* in msecs */
};
/* Conversions */
static int temp_from_reg_unsigned(u8 val_h, u8 val_l)
{
return val_h * 1000 + val_l * 1000 / 256;
}
static int temp_from_reg_signed(u8 val_h, u8 val_l)
{
if (val_h & 0x80)
return (val_h - 0x100) * 1000;
return temp_from_reg_unsigned(val_h, val_l);
}
static int lm95245_read_conversion_rate(struct lm95245_data *data)
{
unsigned int rate;
int ret;
ret = regmap_read(data->regmap, LM95245_REG_RW_CONVERS_RATE, &rate);
if (ret < 0)
return ret;
switch (rate) {
case RATE_CR0063:
data->interval = 63;
break;
case RATE_CR0364:
data->interval = 364;
break;
case RATE_CR1000:
data->interval = 1000;
break;
case RATE_CR2500:
default:
data->interval = 2500;
break;
}
return 0;
}
static int lm95245_set_conversion_rate(struct lm95245_data *data, long interval)
{
int ret, rate;
if (interval <= 63) {
interval = 63;
rate = RATE_CR0063;
} else if (interval <= 364) {
interval = 364;
rate = RATE_CR0364;
} else if (interval <= 1000) {
interval = 1000;
rate = RATE_CR1000;
} else {
interval = 2500;
rate = RATE_CR2500;
}
ret = regmap_write(data->regmap, LM95245_REG_RW_CONVERS_RATE, rate);
if (ret < 0)
return ret;
data->interval = interval;
return 0;
}
static int lm95245_read_temp(struct device *dev, u32 attr, int channel,
long *val)
{
struct lm95245_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap;
unsigned int regs[2];
unsigned int regval;
u8 regvals[2];
int ret;
switch (attr) {
case hwmon_temp_input:
regs[0] = channel ? LM95245_REG_R_REMOTE_TEMPL_S :
LM95245_REG_R_LOCAL_TEMPL_S;
regs[1] = channel ? LM95245_REG_R_REMOTE_TEMPH_S :
LM95245_REG_R_LOCAL_TEMPH_S;
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret < 0)
return ret;
Annotation
- Immediate include surface: `linux/err.h`, `linux/init.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct lm95245_data`, `function temp_from_reg_unsigned`, `function temp_from_reg_signed`, `function lm95245_read_conversion_rate`, `function lm95245_set_conversion_rate`, `function lm95245_read_temp`, `function lm95245_write_temp`, `function lm95245_read_chip`, `function lm95245_write_chip`, `function lm95245_read`.
- 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.