drivers/power/supply/bq24257_charger.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/bq24257_charger.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/bq24257_charger.c
Extension
.c
Size
29799 bytes
Lines
1177
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 bq2425x_chip_info {
	const char *const name;
	enum bq2425x_chip chip;
};

enum bq24257_fields {
	F_WD_FAULT, F_WD_EN, F_STAT, F_FAULT,			    /* REG 1 */
	F_RESET, F_IILIMIT, F_EN_STAT, F_EN_TERM, F_CE, F_HZ_MODE,  /* REG 2 */
	F_VBAT, F_USB_DET,					    /* REG 3 */
	F_ICHG, F_ITERM,					    /* REG 4 */
	F_LOOP_STATUS, F_LOW_CHG, F_DPDM_EN, F_CE_STATUS, F_VINDPM, /* REG 5 */
	F_X2_TMR_EN, F_TMR, F_SYSOFF, F_TS_EN, F_TS_STAT,	    /* REG 6 */
	F_VOVP, F_CLR_VDP, F_FORCE_BATDET, F_FORCE_PTM,		    /* REG 7 */

	F_MAX_FIELDS
};

/* initial field values, converted from uV/uA */
struct bq24257_init_data {
	u8 ichg;	/* charge current      */
	u8 vbat;	/* regulation voltage  */
	u8 iterm;	/* termination current */
	u8 iilimit;	/* input current limit */
	u8 vovp;	/* over voltage protection voltage */
	u8 vindpm;	/* VDMP input threshold voltage */
};

struct bq24257_state {
	u8 status;
	u8 fault;
	bool power_good;
};

struct bq24257_device {
	struct i2c_client *client;
	struct device *dev;
	struct power_supply *charger;

	const struct bq2425x_chip_info *info;

	struct regmap *rmap;
	struct regmap_field *rmap_fields[F_MAX_FIELDS];

	struct gpio_desc *pg;

	struct delayed_work iilimit_setup_work;

	struct bq24257_init_data init_data;
	struct bq24257_state state;

	struct mutex lock; /* protect state data */

	bool iilimit_autoset_enable;
};

static bool bq24257_is_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BQ24257_REG_2:
	case BQ24257_REG_4:
		return false;

	default:
		return true;
	}
}

static const struct regmap_config bq24257_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = BQ24257_REG_7,
	.cache_type = REGCACHE_MAPLE,

	.volatile_reg = bq24257_is_volatile_reg,
};

static const struct reg_field bq24257_reg_fields[] = {
	/* REG 1 */
	[F_WD_FAULT]		= REG_FIELD(BQ24257_REG_1, 7, 7),
	[F_WD_EN]		= REG_FIELD(BQ24257_REG_1, 6, 6),
	[F_STAT]		= REG_FIELD(BQ24257_REG_1, 4, 5),
	[F_FAULT]		= REG_FIELD(BQ24257_REG_1, 0, 3),
	/* REG 2 */
	[F_RESET]		= REG_FIELD(BQ24257_REG_2, 7, 7),
	[F_IILIMIT]		= REG_FIELD(BQ24257_REG_2, 4, 6),
	[F_EN_STAT]		= REG_FIELD(BQ24257_REG_2, 3, 3),
	[F_EN_TERM]		= REG_FIELD(BQ24257_REG_2, 2, 2),
	[F_CE]			= REG_FIELD(BQ24257_REG_2, 1, 1),
	[F_HZ_MODE]		= REG_FIELD(BQ24257_REG_2, 0, 0),

Annotation

Implementation Notes