drivers/power/supply/max77759_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/max77759_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/max77759_charger.c- Extension
.c- Size
- 19800 bytes
- Lines
- 775
- 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/bitfield.hlinux/cleanup.hlinux/device.hlinux/devm-helpers.hlinux/interrupt.hlinux/irq.hlinux/linear_range.hlinux/mfd/max77759.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/regulator/driver.hlinux/string_choices.hlinux/workqueue.h
Detected Declarations
struct max77759_chargerfunction unlock_prot_regsfunction charger_input_validfunction get_onlinefunction get_statusfunction get_charge_typefunction get_chg_healthfunction get_batt_healthfunction get_healthfunction get_fast_charge_currentfunction set_fast_charge_current_limitfunction get_float_voltagefunction set_float_voltage_limitfunction get_input_current_limitfunction set_input_current_limitfunction max77759_charger_get_propertyfunction charger_set_modefunction enable_chgin_otgfunction disable_chgin_otgfunction chgin_otg_statusfunction irq_handlerfunction bat_oilo_irq_handlerfunction max77759_init_irqhandlerfunction max77759_charger_initfunction psy_work_itemfunction scoped_guardfunction psy_changedfunction max_tcpci_unregister_psy_notifierfunction max77759_charger_probe
Annotated Snippet
struct max77759_charger {
struct device *dev;
struct regmap *regmap;
struct power_supply *psy;
struct regulator_dev *chgin_otg_rdev;
struct notifier_block nb;
struct power_supply *tcpm_psy;
struct delayed_work psy_work;
struct mutex retry_lock; /* Protects psy_work_retry_cnt */
u32 psy_work_retry_cnt;
int irqs[NUM_IRQS];
struct mutex lock; /* protects the state below */
enum max77759_chgr_mode mode;
};
static inline int unlock_prot_regs(struct max77759_charger *chg, bool unlock)
{
return regmap_update_bits(chg->regmap, MAX77759_CHGR_REG_CHG_CNFG_06,
MAX77759_CHGR_REG_CHG_CNFG_06_CHGPROT, unlock
? MAX77759_CHGR_REG_CHG_CNFG_06_CHGPROT : 0);
}
static int charger_input_valid(struct max77759_charger *chg)
{
u32 val;
int ret;
ret = regmap_read(chg->regmap, MAX77759_CHGR_REG_CHG_INT_OK, &val);
if (ret)
return ret;
return (val & MAX77759_CHGR_REG_CHG_INT_CHG) &&
(val & MAX77759_CHGR_REG_CHG_INT_CHGIN);
}
static int get_online(struct max77759_charger *chg)
{
u32 val;
int ret;
ret = charger_input_valid(chg);
if (ret <= 0)
return ret;
ret = regmap_read(chg->regmap, MAX77759_CHGR_REG_CHG_DETAILS_02, &val);
if (ret)
return ret;
guard(mutex)(&chg->lock);
return (val & MAX77759_CHGR_REG_CHG_DETAILS_02_CHGIN_STS) &&
(chg->mode == MAX77759_CHGR_MODE_CHG_BUCK_ON);
}
static int get_status(struct max77759_charger *chg)
{
u32 val;
int ret;
ret = regmap_read(chg->regmap, MAX77759_CHGR_REG_CHG_DETAILS_01, &val);
if (ret)
return ret;
switch (FIELD_GET(MAX77759_CHGR_REG_CHG_DETAILS_01_CHG_DTLS, val)) {
case MAX77759_CHGR_CHG_DTLS_PREQUAL:
case MAX77759_CHGR_CHG_DTLS_CC:
case MAX77759_CHGR_CHG_DTLS_CV:
case MAX77759_CHGR_CHG_DTLS_TO:
return POWER_SUPPLY_STATUS_CHARGING;
case MAX77759_CHGR_CHG_DTLS_DONE:
return POWER_SUPPLY_STATUS_FULL;
case MAX77759_CHGR_CHG_DTLS_TIMER_FAULT:
case MAX77759_CHGR_CHG_DTLS_SUSP_BATT_THM:
case MAX77759_CHGR_CHG_DTLS_OFF_WDOG_TIMER:
case MAX77759_CHGR_CHG_DTLS_SUSP_JEITA:
return POWER_SUPPLY_STATUS_NOT_CHARGING;
case MAX77759_CHGR_CHG_DTLS_OFF:
return POWER_SUPPLY_STATUS_DISCHARGING;
default:
break;
}
return POWER_SUPPLY_STATUS_UNKNOWN;
}
static int get_charge_type(struct max77759_charger *chg)
{
u32 val;
int ret;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/cleanup.h`, `linux/device.h`, `linux/devm-helpers.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/linear_range.h`, `linux/mfd/max77759.h`.
- Detected declarations: `struct max77759_charger`, `function unlock_prot_regs`, `function charger_input_valid`, `function get_online`, `function get_status`, `function get_charge_type`, `function get_chg_health`, `function get_batt_health`, `function get_health`, `function get_fast_charge_current`.
- 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.