drivers/power/supply/bq257xx_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/bq257xx_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/bq257xx_charger.c- Extension
.c- Size
- 23009 bytes
- Lines
- 782
- 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.
- 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/bitfield.hlinux/i2c.hlinux/interrupt.hlinux/mfd/bq257xx.hlinux/platform_device.hlinux/power_supply.hlinux/property.hlinux/regmap.h
Detected Declarations
struct bq257xx_chgstruct bq257xx_chip_infostruct bq257xx_chgfunction bq25703_get_statefunction bq25703_get_min_vsysfunction bq25703_set_min_vsysfunction bq25703_get_curfunction bq25703_get_ichg_curfunction bq25703_set_ichg_curfunction bq25703_get_chrg_voltfunction bq25703_set_chrg_voltfunction bq25703_get_iindpmfunction bq25703_set_iindpmfunction bq25703_get_vbatfunction bq25703_hw_initfunction bq25703_hw_shutdownfunction bq257xx_set_charger_propertyfunction bq257xx_get_charger_propertyfunction bq257xx_property_is_writeablefunction bq257xx_external_power_changedfunction bq257xx_irq_handler_threadfunction bq257xx_parse_dtfunction bq257xx_charger_probefunction bq257xx_charger_shutdown
Annotated Snippet
struct bq257xx_chip_info {
int default_iindpm_uA;
int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
int (*bq257xx_get_ichg)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_ichg)(struct bq257xx_chg *pdata, int ichg);
int (*bq257xx_get_vbatreg)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_vbatreg)(struct bq257xx_chg *pdata, int vbatreg);
int (*bq257xx_get_iindpm)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_iindpm)(struct bq257xx_chg *pdata, int iindpm);
int (*bq257xx_get_cur)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_get_vbat)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_get_min_vsys)(struct bq257xx_chg *pdata, int *intval);
};
/**
* struct bq257xx_chg - driver data for charger
* @chip: hw specific functions
* @bq: parent MFD device
* @charger: power supply device
* @online: charger input is present
* @charging: charger is actively charging the battery
* @fast_charge: charger is in fast charge mode
* @pre_charge: charger is in pre-charge mode
* @overvoltage: overvoltage fault detected
* @ov_fault: charger reports over voltage fault
* @batoc_fault: charger reports battery over current fault
* @oc_fault: charger reports over current fault
* @usb_type: USB type reported from parent power supply
* @supplied: Status of parent power supply
* @iindpm_max: maximum input current limit (uA)
* @vbat_max: maximum charge voltage (uV)
* @ichg_max: maximum charge current (uA)
* @vsys_min: minimum system voltage (uV)
*/
struct bq257xx_chg {
const struct bq257xx_chip_info *chip;
struct bq257xx_device *bq;
struct power_supply *charger;
bool online;
bool charging;
bool fast_charge;
bool pre_charge;
bool overvoltage;
bool ov_fault;
bool batoc_fault;
bool oc_fault;
int usb_type;
int supplied;
u32 iindpm_max;
u32 vbat_max;
u32 ichg_max;
u32 vsys_min;
};
/**
* bq25703_get_state() - Get the current state of the device
* @pdata: driver platform data
*
* Get the current state of the charger. Check if the charger is
* powered, what kind of charge state (if any) the device is in,
* and if there are any active faults.
*
* Return: Returns 0 on success, or error on failure to read device.
*/
static int bq25703_get_state(struct bq257xx_chg *pdata)
{
unsigned int reg;
int ret;
ret = regmap_read(pdata->bq->regmap, BQ25703_CHARGER_STATUS, ®);
if (ret)
return ret;
pdata->online = reg & BQ25703_STS_AC_STAT;
pdata->fast_charge = reg & BQ25703_STS_IN_FCHRG;
pdata->pre_charge = reg & BQ25703_STS_IN_PCHRG;
pdata->charging = pdata->fast_charge || pdata->pre_charge;
pdata->ov_fault = reg & BQ25703_STS_FAULT_ACOV;
pdata->batoc_fault = reg & BQ25703_STS_FAULT_BATOC;
pdata->overvoltage = pdata->ov_fault || pdata->batoc_fault;
pdata->oc_fault = reg & BQ25703_STS_FAULT_ACOC;
return 0;
}
/**
* bq25703_get_min_vsys() - Get the minimum system voltage
* @pdata: driver platform data
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/mfd/bq257xx.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct bq257xx_chg`, `struct bq257xx_chip_info`, `struct bq257xx_chg`, `function bq25703_get_state`, `function bq25703_get_min_vsys`, `function bq25703_set_min_vsys`, `function bq25703_get_cur`, `function bq25703_get_ichg_cur`, `function bq25703_set_ichg_cur`, `function bq25703_get_chrg_volt`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- 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.