drivers/power/supply/axp288_fuel_gauge.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/axp288_fuel_gauge.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/axp288_fuel_gauge.c- Extension
.c- Size
- 21024 bytes
- Lines
- 820
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/acpi.hlinux/dmi.hlinux/module.hlinux/kernel.hlinux/device.hlinux/regmap.hlinux/jiffies.hlinux/interrupt.hlinux/mfd/axp20x.hlinux/platform_device.hlinux/power_supply.hlinux/iio/consumer.hlinux/unaligned.hasm/iosf_mbi.h
Detected Declarations
struct axp288_fg_infofunction fuel_gauge_reg_readbfunction fuel_gauge_reg_writebfunction fuel_gauge_read_15bit_wordfunction fuel_gauge_read_12bit_wordfunction fuel_gauge_update_registersfunction fuel_gauge_get_statusfunction fuel_gauge_battery_healthfunction fuel_gauge_get_propertyfunction fuel_gauge_set_propertyfunction fuel_gauge_property_is_writeablefunction fuel_gauge_thread_handlerfunction fuel_gauge_external_power_changedfunction axp288_fuel_gauge_read_initial_regsfunction axp288_fuel_gauge_release_iio_chansfunction axp288_fuel_gauge_probe
Annotated Snippet
struct axp288_fg_info {
struct device *dev;
struct regmap *regmap;
int irq[AXP288_FG_INTR_NUM];
struct iio_channel *iio_channel[IIO_CHANNEL_NUM];
struct power_supply *bat;
struct mutex lock;
int status;
int max_volt;
int pwr_op;
int low_cap;
struct dentry *debug_file;
char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
int pwr_stat;
int fg_res;
int bat_volt;
int d_curr;
int c_curr;
int ocv;
int fg_cc_mtr1;
int fg_des_cap1;
};
static enum power_supply_property fuel_gauge_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_OCV,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN,
POWER_SUPPLY_PROP_TECHNOLOGY,
/* The 3 props below are not used when no_current_sense_res is set */
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
};
static int fuel_gauge_reg_readb(struct axp288_fg_info *info, int reg)
{
unsigned int val;
int ret;
ret = regmap_read(info->regmap, reg, &val);
if (ret < 0) {
dev_err(info->dev, "Error reading reg 0x%02x err: %d\n", reg, ret);
return ret;
}
return val;
}
static int fuel_gauge_reg_writeb(struct axp288_fg_info *info, int reg, u8 val)
{
int ret;
ret = regmap_write(info->regmap, reg, (unsigned int)val);
if (ret < 0)
dev_err(info->dev, "Error writing reg 0x%02x err: %d\n", reg, ret);
return ret;
}
static int fuel_gauge_read_15bit_word(struct axp288_fg_info *info, int reg)
{
unsigned char buf[2];
int ret;
ret = regmap_bulk_read(info->regmap, reg, buf, 2);
if (ret < 0) {
dev_err(info->dev, "Error reading reg 0x%02x err: %d\n", reg, ret);
return ret;
}
ret = get_unaligned_be16(buf);
if (!(ret & FG_15BIT_WORD_VALID)) {
dev_err(info->dev, "Error reg 0x%02x contents not valid\n", reg);
return -ENXIO;
}
return ret & FG_15BIT_VAL_MASK;
}
static int fuel_gauge_read_12bit_word(struct axp288_fg_info *info, int reg)
{
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/dmi.h`, `linux/module.h`, `linux/kernel.h`, `linux/device.h`, `linux/regmap.h`, `linux/jiffies.h`, `linux/interrupt.h`.
- Detected declarations: `struct axp288_fg_info`, `function fuel_gauge_reg_readb`, `function fuel_gauge_reg_writeb`, `function fuel_gauge_read_15bit_word`, `function fuel_gauge_read_12bit_word`, `function fuel_gauge_update_registers`, `function fuel_gauge_get_status`, `function fuel_gauge_battery_health`, `function fuel_gauge_get_property`, `function fuel_gauge_set_property`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.