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.

Dependency Surface

Detected Declarations

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, &reg);
	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

Implementation Notes