drivers/power/supply/axp20x_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/axp20x_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/axp20x_battery.c- Extension
.c- Size
- 30789 bytes
- Lines
- 1158
- 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/err.hlinux/interrupt.hlinux/irq.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/slab.hlinux/time.hlinux/iio/iio.hlinux/iio/consumer.hlinux/mfd/axp20x.h
Detected Declarations
struct axp20x_batt_psstruct axp_datastruct axp20x_batt_psfunction axp20x_battery_get_max_voltagefunction axp22x_battery_get_max_voltagefunction axp717_battery_get_max_voltagefunction axp813_battery_get_max_voltagefunction axp20x_get_constant_charge_currentfunction axp717_get_constant_charge_currentfunction axp20x_battery_get_propfunction axp717_battery_get_propfunction axp22x_battery_set_max_voltagefunction axp20x_battery_set_max_voltagefunction axp717_battery_set_max_voltagefunction axp20x_set_constant_charge_currentfunction axp717_set_constant_charge_currentfunction axp20x_set_max_constant_charge_currentfunction axp20x_set_voltage_min_designfunction axp717_set_voltage_min_designfunction axp20x_battery_set_propfunction axp717_battery_set_propfunction axp20x_battery_prop_writeablefunction axp717_battery_prop_writeablefunction axp209_bat_cfg_iio_channelsfunction axp717_bat_cfg_iio_channelsfunction axp209_set_battery_infofunction axp717_set_battery_infofunction axp20x_power_probe
Annotated Snippet
struct axp_data {
int ccc_scale;
int ccc_offset;
unsigned int ccc_reg;
unsigned int ccc_mask;
bool has_fg_valid;
const struct power_supply_desc *bat_ps_desc;
int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val);
int (*set_max_voltage)(struct axp20x_batt_ps *batt, int val);
int (*cfg_iio_chan)(struct platform_device *pdev,
struct axp20x_batt_ps *axp_batt);
void (*set_bat_info)(struct platform_device *pdev,
struct axp20x_batt_ps *axp_batt,
struct power_supply_battery_info *info);
};
struct axp20x_batt_ps {
struct regmap *regmap;
struct power_supply *batt;
struct device *dev;
struct iio_channel *batt_chrg_i;
struct iio_channel *batt_dischrg_i;
struct iio_channel *batt_v;
/* Maximum constant charge current */
unsigned int max_ccc;
const struct axp_data *data;
bool ts_disable;
};
static int axp20x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
int *val)
{
int ret, reg;
ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, ®);
if (ret)
return ret;
switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
case AXP20X_CHRG_CTRL1_TGT_4_1V:
*val = 4100000;
break;
case AXP20X_CHRG_CTRL1_TGT_4_15V:
*val = 4150000;
break;
case AXP20X_CHRG_CTRL1_TGT_4_2V:
*val = 4200000;
break;
case AXP20X_CHRG_CTRL1_TGT_4_36V:
*val = 4360000;
break;
default:
return -EINVAL;
}
return 0;
}
static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
int *val)
{
int ret, reg;
ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, ®);
if (ret)
return ret;
switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
case AXP20X_CHRG_CTRL1_TGT_4_1V:
*val = 4100000;
break;
case AXP20X_CHRG_CTRL1_TGT_4_2V:
*val = 4200000;
break;
case AXP22X_CHRG_CTRL1_TGT_4_22V:
*val = 4220000;
break;
case AXP22X_CHRG_CTRL1_TGT_4_24V:
*val = 4240000;
break;
default:
return -EINVAL;
}
return 0;
}
static int axp717_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
int *val)
{
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/err.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct axp20x_batt_ps`, `struct axp_data`, `struct axp20x_batt_ps`, `function axp20x_battery_get_max_voltage`, `function axp22x_battery_get_max_voltage`, `function axp717_battery_get_max_voltage`, `function axp813_battery_get_max_voltage`, `function axp20x_get_constant_charge_current`, `function axp717_get_constant_charge_current`, `function axp20x_battery_get_prop`.
- 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.