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.
- 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/module.hlinux/i2c.hlinux/power_supply.hlinux/regmap.hlinux/types.hlinux/gpio/consumer.hlinux/interrupt.hlinux/delay.hlinux/acpi.hlinux/of.h
Detected Declarations
struct bq2425x_chip_infostruct bq24257_init_datastruct bq24257_statestruct bq24257_deviceenum bq2425x_chipenum bq24257_fieldsenum bq24257_statusenum bq24257_faultenum bq24257_loop_statusenum bq24257_in_ilimitenum bq24257_vovpenum bq24257_vindpmenum bq24257_port_typeenum bq24257_safety_timerfunction bq24257_is_volatile_regfunction bq24257_field_readfunction bq24257_field_writefunction bq24257_find_idxfunction bq24257_get_input_current_limitfunction bq24257_set_input_current_limitfunction bq24257_power_supply_get_propertyfunction bq24257_power_supply_set_propertyfunction bq24257_power_supply_property_is_writeablefunction bq24257_get_chip_statefunction bq24257_state_changedfunction bq24257_iilimit_autosetfunction bq24257_iilimit_setup_workfunction bq24257_handle_state_changefunction bq24257_irq_handler_threadfunction bq24257_hw_initfunction bq24257_show_ovp_voltagefunction bq24257_show_in_dpm_voltagefunction bq24257_sysfs_show_enablefunction bq24257_sysfs_set_enablefunction bq24257_power_supply_initfunction bq24257_pg_gpio_probefunction bq24257_fw_probefunction bq24257_probefunction bq24257_removefunction bq24257_suspendfunction bq24257_resume
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
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/power_supply.h`, `linux/regmap.h`, `linux/types.h`, `linux/gpio/consumer.h`, `linux/interrupt.h`, `linux/delay.h`.
- Detected declarations: `struct bq2425x_chip_info`, `struct bq24257_init_data`, `struct bq24257_state`, `struct bq24257_device`, `enum bq2425x_chip`, `enum bq24257_fields`, `enum bq24257_status`, `enum bq24257_fault`, `enum bq24257_loop_status`, `enum bq24257_in_ilimit`.
- 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.