drivers/hwmon/tps23861.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/tps23861.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/tps23861.c- Extension
.c- Size
- 14192 bytes
- Lines
- 569
- 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/debugfs.hlinux/delay.hlinux/hwmon-sysfs.hlinux/hwmon.hlinux/i2c.hlinux/module.hlinux/of.hlinux/regmap.h
Detected Declarations
struct tps23861_datafunction tps23861_read_tempfunction tps23861_read_voltagefunction tps23861_read_currentfunction tps23861_port_disablefunction tps23861_port_enablefunction tps23861_is_visiblefunction tps23861_writefunction tps23861_readfunction tps23861_read_stringfunction tps23861_port_resistancefunction tps23861_port_status_showfunction tps23861_probe
Annotated Snippet
struct tps23861_data {
struct regmap *regmap;
u32 shunt_resistor;
struct i2c_client *client;
};
static const struct regmap_config tps23861_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x6f,
};
static int tps23861_read_temp(struct tps23861_data *data, long *val)
{
unsigned int regval;
int err;
err = regmap_read(data->regmap, TEMPERATURE, ®val);
if (err < 0)
return err;
*val = ((long)regval * TEMPERATURE_LSB) - 20000;
return 0;
}
static int tps23861_read_voltage(struct tps23861_data *data, int channel,
long *val)
{
__le16 regval;
long raw_val;
int err;
if (channel < TPS23861_NUM_PORTS) {
err = regmap_bulk_read(data->regmap,
PORT_1_VOLTAGE_LSB + channel * PORT_N_VOLTAGE_LSB_OFFSET,
®val, 2);
} else {
err = regmap_bulk_read(data->regmap,
INPUT_VOLTAGE_LSB,
®val, 2);
}
if (err < 0)
return err;
raw_val = le16_to_cpu(regval);
*val = (FIELD_GET(VOLTAGE_CURRENT_MASK, raw_val) * VOLTAGE_LSB) / 1000;
return 0;
}
static int tps23861_read_current(struct tps23861_data *data, int channel,
long *val)
{
long raw_val, current_lsb;
__le16 regval;
int err;
if (data->shunt_resistor == SHUNT_RESISTOR_DEFAULT)
current_lsb = CURRENT_LSB_255;
else
current_lsb = CURRENT_LSB_250;
err = regmap_bulk_read(data->regmap,
PORT_1_CURRENT_LSB + channel * PORT_N_CURRENT_LSB_OFFSET,
®val, 2);
if (err < 0)
return err;
raw_val = le16_to_cpu(regval);
*val = (FIELD_GET(VOLTAGE_CURRENT_MASK, raw_val) * current_lsb) / 1000000;
return 0;
}
static int tps23861_port_disable(struct tps23861_data *data, int channel)
{
unsigned int regval = 0;
int err;
regval |= BIT(channel + 4);
err = regmap_write(data->regmap, POWER_ENABLE, regval);
return err;
}
static int tps23861_port_enable(struct tps23861_data *data, int channel)
{
unsigned int regval = 0;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/hwmon-sysfs.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct tps23861_data`, `function tps23861_read_temp`, `function tps23861_read_voltage`, `function tps23861_read_current`, `function tps23861_port_disable`, `function tps23861_port_enable`, `function tps23861_is_visible`, `function tps23861_write`, `function tps23861_read`, `function tps23861_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.