drivers/power/supply/ltc4162-l-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/ltc4162-l-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/ltc4162-l-charger.c- Extension
.c- Size
- 33024 bytes
- Lines
- 1263
- Domain
- Driver Families
- Bucket
- drivers/power
- 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/module.hlinux/delay.hlinux/of.hlinux/pm_runtime.hlinux/power_supply.hlinux/i2c.hlinux/regmap.h
Detected Declarations
struct ltc4162l_infostruct ltc4162l_chip_infostruct ltc4162l_infoenum ltc4162_chemenum ltc4162l_stateenum ltc4162l_charge_statusfunction ltc4162l_get_cell_countfunction ltc4162l_get_chem_typefunction ltc4162l_state_decodefunction ltc4162l_get_statusfunction ltc4162l_charge_status_decodefunction ltc4162l_get_charge_typefunction ltc4162l_state_to_healthfunction ltc4162l_get_healthfunction ltc4162l_get_onlinefunction ltc4162l_get_vbatfunction ltc4015_get_vbatfunction ltc4162l_get_ibatfunction ltc4162l_get_input_voltagefunction ltc4162l_get_input_currentfunction ltc4162l_get_ichargefunction ltc4162l_set_ichargefunction ltc4162l_get_vchargefunction ltc4015_get_vchargefunction ltc4162l_vchargefunction ltc4162l_set_vchargefunction ltc4015_set_vchargefunction ltc4162l_get_iin_limit_dacfunction ltc4162l_set_iin_limitfunction ltc4162l_get_die_tempfunction ltc4015_get_die_tempfunction ltc4162l_get_term_currentfunction ltc4162l_set_term_currentfunction charge_status_showfunction vbat_showfunction vbat_avg_showfunction ibat_showfunction force_telemetry_showfunction force_telemetry_storefunction arm_ship_mode_showfunction arm_ship_mode_storefunction ltc4162l_get_propertyfunction ltc4162l_set_propertyfunction ltc4162l_property_is_writeablefunction ltc4162l_is_writeable_regfunction ltc4162l_is_volatile_regfunction ltc4162l_clear_interruptsfunction ltc4162l_probe
Annotated Snippet
struct ltc4162l_chip_info {
const char *name;
int (*get_vbat)(struct ltc4162l_info *info, unsigned int reg,
union power_supply_propval *val);
int (*get_vcharge)(struct ltc4162l_info *info, unsigned int reg,
union power_supply_propval *val);
int (*set_vcharge)(struct ltc4162l_info *info, unsigned int reg,
unsigned int value);
int (*get_die_temp)(struct ltc4162l_info *info,
union power_supply_propval *val);
unsigned int ibat_resolution_pv;
unsigned int vin_resolution_uv;
u8 telemetry_mask;
};
struct ltc4162l_info {
struct i2c_client *client;
struct regmap *regmap;
struct power_supply *charger;
const struct ltc4162l_chip_info *chip_info;
u32 rsnsb; /* Series resistor that sets charge current, microOhm */
u32 rsnsi; /* Series resistor to measure input current, microOhm */
u8 cell_count; /* Number of connected cells, 0 while unknown */
};
static u8 ltc4162l_get_cell_count(struct ltc4162l_info *info)
{
int ret;
unsigned int val;
/* Once read successfully */
if (info->cell_count)
return info->cell_count;
ret = regmap_read(info->regmap, LTC4162L_CHEM_CELLS_REG, &val);
if (ret)
return 0;
/* Lower 4 bits is the cell count, or 0 if the chip doesn't know yet */
val &= 0x0f;
if (!val)
return 0;
/* Once determined, keep the value */
info->cell_count = val;
return val;
};
static u8 ltc4162l_get_chem_type(struct ltc4162l_info *info)
{
int ret;
unsigned int val;
ret = regmap_read(info->regmap, LTC4162L_CHEM_CELLS_REG, &val);
if (ret)
return ret;
return FIELD_GET(LTC4162L_CHEM_MASK, val);
};
/* Convert enum value to POWER_SUPPLY_STATUS value */
static int ltc4162l_state_decode(enum ltc4162l_state value)
{
switch (value) {
case precharge:
case cc_cv_charge:
return POWER_SUPPLY_STATUS_CHARGING;
case c_over_x_term:
return POWER_SUPPLY_STATUS_FULL;
case bat_missing_fault:
case bat_short_fault:
return POWER_SUPPLY_STATUS_UNKNOWN;
default:
return POWER_SUPPLY_STATUS_NOT_CHARGING;
}
};
static int ltc4162l_get_status(struct ltc4162l_info *info,
union power_supply_propval *val)
{
unsigned int regval;
int ret;
ret = regmap_read(info->regmap, LTC4162L_CHARGER_STATE, ®val);
if (ret) {
dev_err(&info->client->dev, "Failed to read CHARGER_STATE\n");
return ret;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/module.h`, `linux/delay.h`, `linux/of.h`, `linux/pm_runtime.h`, `linux/power_supply.h`, `linux/i2c.h`, `linux/regmap.h`.
- Detected declarations: `struct ltc4162l_info`, `struct ltc4162l_chip_info`, `struct ltc4162l_info`, `enum ltc4162_chem`, `enum ltc4162l_state`, `enum ltc4162l_charge_status`, `function ltc4162l_get_cell_count`, `function ltc4162l_get_chem_type`, `function ltc4162l_state_decode`, `function ltc4162l_get_status`.
- Atlas domain: Driver Families / drivers/power.
- 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.