drivers/power/supply/max8971_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/max8971_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/max8971_charger.c- Extension
.c- Size
- 19964 bytes
- Lines
- 753
- 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/devm-helpers.hlinux/delay.hlinux/device.hlinux/err.hlinux/extcon.hlinux/i2c.hlinux/mod_devicetable.hlinux/of_graph.hlinux/property.hlinux/interrupt.hlinux/module.hlinux/pm.hlinux/power_supply.hlinux/regmap.hlinux/sysfs.hlinux/types.h
Detected Declarations
struct max8971_dataenum max8971_charging_stateenum max8971_health_stateenum max8971_field_idxfunction max8971_get_statusfunction max8971_get_charge_typefunction max8971_get_healthfunction max8971_get_onlinefunction max8971_get_integerfunction max8971_set_integerfunction max8971_get_propertyfunction max8971_set_propertyfunction max8971_property_is_writeablefunction max8971_update_configfunction fast_charge_timer_showfunction fast_charge_timer_storefunction top_off_threshold_current_showfunction top_off_threshold_current_storefunction top_off_timer_showfunction top_off_timer_storefunction max8971_extcon_evt_workerfunction extcon_get_charger_typefunction max8971_interruptfunction max8971_probefunction max8971_resume
Annotated Snippet
struct max8971_data {
struct device *dev;
struct power_supply *psy_mains;
struct extcon_dev *edev;
struct notifier_block extcon_nb;
struct delayed_work extcon_work;
struct regmap *regmap;
struct regmap_field *rfield[MAX8971_N_REGMAP_FIELDS];
enum power_supply_usb_type usb_type;
u32 fchgt;
u32 tofft;
u32 toffs;
bool present;
};
static int max8971_get_status(struct max8971_data *priv, int *val)
{
u32 regval;
int err;
err = regmap_field_read(priv->rfield[CHG_DTLS], ®val);
if (err)
return err;
switch (regval) {
case MAX8971_CHARGING_DEAD_BATTERY:
case MAX8971_CHARGING_PREQUALIFICATION:
case MAX8971_CHARGING_FAST_CONST_CURRENT:
case MAX8971_CHARGING_FAST_CONST_VOLTAGE:
case MAX8971_CHARGING_TOP_OFF:
case MAX8971_CHARGING_THERMAL_LOOP:
*val = POWER_SUPPLY_STATUS_CHARGING;
break;
case MAX8971_CHARGING_DONE:
*val = POWER_SUPPLY_STATUS_FULL;
break;
case MAX8971_CHARGING_TIMER_FAULT:
*val = POWER_SUPPLY_STATUS_NOT_CHARGING;
break;
case MAX8971_CHARGING_OFF:
case MAX8971_CHARGING_SUSPENDED_THERMAL:
*val = POWER_SUPPLY_STATUS_DISCHARGING;
break;
default:
*val = POWER_SUPPLY_STATUS_UNKNOWN;
}
return 0;
}
static int max8971_get_charge_type(struct max8971_data *priv, int *val)
{
u32 regval;
int err;
err = regmap_field_read(priv->rfield[CHG_DTLS], ®val);
if (err)
return err;
switch (regval) {
case MAX8971_CHARGING_DEAD_BATTERY:
case MAX8971_CHARGING_PREQUALIFICATION:
*val = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
break;
case MAX8971_CHARGING_FAST_CONST_CURRENT:
case MAX8971_CHARGING_FAST_CONST_VOLTAGE:
*val = POWER_SUPPLY_CHARGE_TYPE_FAST;
break;
case MAX8971_CHARGING_TOP_OFF:
case MAX8971_CHARGING_THERMAL_LOOP:
*val = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
break;
case MAX8971_CHARGING_DONE:
case MAX8971_CHARGING_TIMER_FAULT:
case MAX8971_CHARGING_SUSPENDED_THERMAL:
case MAX8971_CHARGING_OFF:
*val = POWER_SUPPLY_CHARGE_TYPE_NONE;
break;
default:
*val = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
}
return 0;
}
Annotation
- Immediate include surface: `linux/devm-helpers.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/extcon.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/of_graph.h`.
- Detected declarations: `struct max8971_data`, `enum max8971_charging_state`, `enum max8971_health_state`, `enum max8971_field_idx`, `function max8971_get_status`, `function max8971_get_charge_type`, `function max8971_get_health`, `function max8971_get_online`, `function max8971_get_integer`, `function max8971_set_integer`.
- 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.