drivers/hwmon/ltc2991.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ltc2991.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ltc2991.c- Extension
.c- Size
- 9655 bytes
- Lines
- 431
- 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/bitops.hlinux/err.hlinux/hwmon.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/property.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct ltc2991_statefunction ltc2991_read_regfunction ltc2991_get_voltagefunction ltc2991_read_infunction ltc2991_get_currfunction ltc2991_read_currfunction ltc2991_get_tempfunction ltc2991_read_tempfunction ltc2991_readfunction ltc2991_is_visiblefunction ltc2991_initfunction device_for_each_child_node_scopedfunction ltc2991_i2c_probe
Annotated Snippet
struct ltc2991_state {
struct regmap *regmap;
u32 r_sense_uohm[LTC2991_MAX_CHANNEL];
bool temp_en[LTC2991_MAX_CHANNEL];
};
static int ltc2991_read_reg(struct ltc2991_state *st, u8 addr, u8 reg_len,
int *val)
{
__be16 regvals;
int ret;
if (reg_len < 2)
return regmap_read(st->regmap, addr, val);
ret = regmap_bulk_read(st->regmap, addr, ®vals, reg_len);
if (ret)
return ret;
*val = be16_to_cpu(regvals);
return 0;
}
static int ltc2991_get_voltage(struct ltc2991_state *st, u32 reg, long *val)
{
int reg_val, ret, offset = 0;
ret = ltc2991_read_reg(st, reg, 2, ®_val);
if (ret)
return ret;
if (reg == LTC2991_VCC_MSB)
/* Vcc 2.5V offset */
offset = 2500;
/* Vx, 305.18uV/LSB */
*val = DIV_ROUND_CLOSEST(sign_extend32(reg_val, 14) * 30518,
1000 * 100) + offset;
return 0;
}
static int ltc2991_read_in(struct device *dev, u32 attr, int channel, long *val)
{
struct ltc2991_state *st = dev_get_drvdata(dev);
u32 reg;
switch (attr) {
case hwmon_in_input:
if (channel == LTC2991_VCC_CH_NR)
reg = LTC2991_VCC_MSB;
else
reg = LTC2991_CHANNEL_V_MSB(channel - 1);
return ltc2991_get_voltage(st, reg, val);
default:
return -EOPNOTSUPP;
}
}
static int ltc2991_get_curr(struct ltc2991_state *st, u32 reg, int channel,
long *val)
{
int reg_val, ret;
ret = ltc2991_read_reg(st, reg, 2, ®_val);
if (ret)
return ret;
/* Vx-Vy, 19.075uV/LSB */
*val = DIV_ROUND_CLOSEST(sign_extend32(reg_val, 14) * 19075,
(s32)st->r_sense_uohm[channel]);
return 0;
}
static int ltc2991_read_curr(struct device *dev, u32 attr, int channel,
long *val)
{
struct ltc2991_state *st = dev_get_drvdata(dev);
u32 reg;
switch (attr) {
case hwmon_curr_input:
reg = LTC2991_CHANNEL_C_MSB(channel);
return ltc2991_get_curr(st, reg, channel, val);
default:
return -EOPNOTSUPP;
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct ltc2991_state`, `function ltc2991_read_reg`, `function ltc2991_get_voltage`, `function ltc2991_read_in`, `function ltc2991_get_curr`, `function ltc2991_read_curr`, `function ltc2991_get_temp`, `function ltc2991_read_temp`, `function ltc2991_read`, `function ltc2991_is_visible`.
- 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.