drivers/power/supply/max14577_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/max14577_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/max14577_charger.c- Extension
.c- Size
- 16480 bytes
- Lines
- 643
- 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.
- 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/platform_device.hlinux/power_supply.hlinux/mfd/max14577-private.hlinux/mfd/max14577.h
Detected Declarations
struct max14577_chargerfunction maxim_get_charger_typefunction max14577_get_charger_statefunction max14577_get_charge_typefunction max14577_get_onlinefunction max14577_get_battery_healthfunction max14577_get_presentfunction max14577_set_fast_charge_timerfunction max14577_init_constant_voltagefunction max14577_init_eocfunction max14577_init_fast_chargefunction max14577_charger_reg_initfunction max14577_charger_get_propertyfunction show_fast_charge_timerfunction store_fast_charge_timerfunction max14577_charger_probefunction max14577_charger_remove
Annotated Snippet
struct max14577_charger {
struct device *dev;
struct max14577 *max14577;
struct power_supply *charger;
struct max14577_charger_platform_data *pdata;
};
/*
* Helper function for mapping values of STATUS2/CHGTYP register on max14577
* and max77836 chipsets to enum maxim_muic_charger_type.
*/
static enum max14577_muic_charger_type maxim_get_charger_type(
enum maxim_device_type dev_type, u8 val) {
switch (val) {
case MAX14577_CHARGER_TYPE_NONE:
case MAX14577_CHARGER_TYPE_USB:
case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
case MAX14577_CHARGER_TYPE_SPECIAL_1A:
return val;
case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
case MAX14577_CHARGER_TYPE_RESERVED:
if (dev_type == MAXIM_DEVICE_TYPE_MAX77836)
val |= 0x8;
return val;
default:
WARN_ONCE(1, "max14577: Unsupported chgtyp register value 0x%02x", val);
return val;
}
}
static int max14577_get_charger_state(struct max14577_charger *chg, int *val)
{
struct regmap *rmap = chg->max14577->regmap;
int ret;
u8 reg_data;
/*
* Charging occurs only if:
* - CHGCTRL2/MBCHOSTEN == 1
* - STATUS2/CGMBC == 1
*
* TODO:
* - handle FULL after Top-off timer (EOC register may be off
* and the charger won't be charging although MBCHOSTEN is on)
* - handle properly dead-battery charging (respect timer)
* - handle timers (fast-charge and prequal) /MBCCHGERR/
*/
ret = max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
if (ret < 0)
goto out;
if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0) {
*val = POWER_SUPPLY_STATUS_DISCHARGING;
goto out;
}
ret = max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
if (ret < 0)
goto out;
if (reg_data & STATUS3_CGMBC_MASK) {
/* Charger or USB-cable is connected */
if (reg_data & STATUS3_EOC_MASK)
*val = POWER_SUPPLY_STATUS_FULL;
else
*val = POWER_SUPPLY_STATUS_CHARGING;
goto out;
}
*val = POWER_SUPPLY_STATUS_DISCHARGING;
out:
return ret;
}
/*
* Supported charge types:
* - POWER_SUPPLY_CHARGE_TYPE_NONE
* - POWER_SUPPLY_CHARGE_TYPE_FAST
*/
static int max14577_get_charge_type(struct max14577_charger *chg, int *val)
{
int ret, charging;
/*
* TODO: CHARGE_TYPE_TRICKLE (VCHGR_RC or EOC)?
* As spec says:
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/mfd/max14577-private.h`, `linux/mfd/max14577.h`.
- Detected declarations: `struct max14577_charger`, `function maxim_get_charger_type`, `function max14577_get_charger_state`, `function max14577_get_charge_type`, `function max14577_get_online`, `function max14577_get_battery_health`, `function max14577_get_present`, `function max14577_set_fast_charge_timer`, `function max14577_init_constant_voltage`, `function max14577_init_eoc`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
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.