drivers/power/supply/mp2629_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/mp2629_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/mp2629_charger.c- Extension
.c- Size
- 17235 bytes
- Lines
- 663
- 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/bits.hlinux/iio/consumer.hlinux/iio/types.hlinux/interrupt.hlinux/mfd/mp2629.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.h
Detected Declarations
struct mp2629_chargerstruct mp2629_propenum mp2629_source_typeenum mp2629_fieldfunction mp2629_read_adcfunction mp2629_get_propfunction mp2629_set_propfunction mp2629_get_battery_capacityfunction mp2629_charger_battery_get_propfunction mp2629_charger_battery_set_propfunction mp2629_charger_usb_get_propfunction mp2629_charger_usb_set_propfunction mp2629_charger_battery_prop_writeablefunction mp2629_charger_usb_prop_writeablefunction mp2629_irq_handlerfunction batt_impedance_compensation_showfunction batt_impedance_compensation_storefunction mp2629_charger_disablefunction mp2629_charger_probe
Annotated Snippet
struct mp2629_charger {
struct device *dev;
int status;
int fault;
struct regmap *regmap;
struct regmap_field *regmap_fields[MP2629_MAX_FIELD];
struct mutex lock;
struct power_supply *usb;
struct power_supply *battery;
struct iio_channel *iiochan[MP2629_ADC_CHAN_END];
};
struct mp2629_prop {
int reg;
int mask;
int min;
int max;
int step;
int shift;
};
static enum power_supply_property mp2629_charger_usb_props[] = {
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_USB_TYPE,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
};
static enum power_supply_property mp2629_charger_bat_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_CHARGE_TYPE,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
};
static struct mp2629_prop props[] = {
MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000),
MP2629_PROPS(INPUT_VLIM, 3800000, 5300000, 100000),
MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000),
MP2629_PROPS(CHARGE_VLIM, 3400000, 4670000, 10000),
MP2629_PROPS(PRECHARGE, 120000, 720000, 40000),
MP2629_PROPS(TERM_CURRENT, 80000, 680000, 40000),
};
static const struct reg_field mp2629_reg_fields[] = {
[INPUT_ILIM] = REG_FIELD(MP2629_REG_INPUT_ILIM, 0, 5),
[INPUT_VLIM] = REG_FIELD(MP2629_REG_INPUT_VLIM, 0, 3),
[CHARGE_ILIM] = REG_FIELD(MP2629_REG_CHARGE_ILIM, 0, 6),
[CHARGE_VLIM] = REG_FIELD(MP2629_REG_CHARGE_VLIM, 1, 7),
[PRECHARGE] = REG_FIELD(MP2629_REG_PRECHARGE, 4, 7),
[TERM_CURRENT] = REG_FIELD(MP2629_REG_TERM_CURRENT, 0, 3),
};
static char *adc_chan_name[] = {
"mp2629-batt-volt",
"mp2629-system-volt",
"mp2629-input-volt",
"mp2629-batt-current",
"mp2629-input-current",
};
static int mp2629_read_adc(struct mp2629_charger *charger,
enum mp2629_adc_chan ch,
union power_supply_propval *val)
{
int ret;
int chval;
ret = iio_read_channel_processed(charger->iiochan[ch], &chval);
if (ret)
return ret;
val->intval = chval * 1000;
return 0;
}
static int mp2629_get_prop(struct mp2629_charger *charger,
enum mp2629_field fld,
Annotation
- Immediate include surface: `linux/bits.h`, `linux/iio/consumer.h`, `linux/iio/types.h`, `linux/interrupt.h`, `linux/mfd/mp2629.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`.
- Detected declarations: `struct mp2629_charger`, `struct mp2629_prop`, `enum mp2629_source_type`, `enum mp2629_field`, `function mp2629_read_adc`, `function mp2629_get_prop`, `function mp2629_set_prop`, `function mp2629_get_battery_capacity`, `function mp2629_charger_battery_get_prop`, `function mp2629_charger_battery_set_prop`.
- 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.