drivers/power/supply/mt6360_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/mt6360_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/mt6360_charger.c- Extension
.c- Size
- 23787 bytes
- Lines
- 862
- 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/devm-helpers.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/linear_range.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/property.hlinux/regmap.hlinux/regulator/driver.h
Detected Declarations
struct mt6360_chg_infoenum mt6360_iinlmtselenum mt6360_pmu_chg_typefunction mt6360_get_chrdet_ext_statfunction mt6360_charger_get_onlinefunction mt6360_charger_get_statusfunction mt6360_charger_get_charge_typefunction mt6360_charger_get_ichgfunction mt6360_charger_get_max_ichgfunction mt6360_charger_get_cvfunction mt6360_charger_get_max_cvfunction mt6360_charger_get_aicrfunction mt6360_charger_get_mivrfunction mt6360_charger_get_iprechgfunction mt6360_charger_get_ieocfunction mt6360_charger_set_onlinefunction mt6360_charger_set_ichgfunction mt6360_charger_set_cvfunction mt6360_charger_set_aicrfunction mt6360_charger_set_mivrfunction mt6360_charger_set_iprechgfunction mt6360_charger_set_ieocfunction mt6360_charger_get_propertyfunction mt6360_charger_set_propertyfunction mt6360_charger_property_is_writeablefunction mt6360_pmu_attach_i_handlerfunction mt6360_handle_chrdet_ext_evtfunction mt6360_chrdet_workfunction mt6360_pmu_chrdet_ext_evt_handlerfunction mt6360_chg_irq_registerfunction mt6360_vinovp_trans_to_selfunction mt6360_chg_init_settingfunction mt6360_charger_probe
Annotated Snippet
struct mt6360_chg_info {
struct device *dev;
struct regmap *regmap;
struct power_supply_desc psy_desc;
struct power_supply *psy;
struct regulator_dev *otg_rdev;
struct mutex chgdet_lock;
u32 vinovp;
bool pwr_rdy;
bool bc12_en;
int psy_usb_type;
struct work_struct chrdet_work;
};
enum mt6360_iinlmtsel {
MT6360_IINLMTSEL_AICR_3250 = 0,
MT6360_IINLMTSEL_CHG_TYPE,
MT6360_IINLMTSEL_AICR,
MT6360_IINLMTSEL_LOWER_LEVEL,
};
enum mt6360_pmu_chg_type {
MT6360_CHG_TYPE_NOVBUS = 0,
MT6360_CHG_TYPE_UNDER_GOING,
MT6360_CHG_TYPE_SDP,
MT6360_CHG_TYPE_SDPNSTD,
MT6360_CHG_TYPE_DCP,
MT6360_CHG_TYPE_CDP,
MT6360_CHG_TYPE_DISABLE_BC12,
MT6360_CHG_TYPE_MAX,
};
static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci,
bool *pwr_rdy)
{
int ret;
unsigned int regval;
ret = regmap_read(mci->regmap, MT6360_PMU_FOD_STAT, ®val);
if (ret < 0)
return ret;
*pwr_rdy = (regval & MT6360_CHRDET_EXT_MASK) ? true : false;
return 0;
}
static int mt6360_charger_get_online(struct mt6360_chg_info *mci,
union power_supply_propval *val)
{
int ret;
bool pwr_rdy;
ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy);
if (ret < 0)
return ret;
val->intval = pwr_rdy ? true : false;
return 0;
}
static int mt6360_charger_get_status(struct mt6360_chg_info *mci,
union power_supply_propval *val)
{
int status, ret;
unsigned int regval;
bool pwr_rdy;
ret = mt6360_get_chrdet_ext_stat(mci, &pwr_rdy);
if (ret < 0)
return ret;
if (!pwr_rdy) {
status = POWER_SUPPLY_STATUS_DISCHARGING;
goto out;
}
ret = regmap_read(mci->regmap, MT6360_PMU_CHG_STAT, ®val);
if (ret < 0)
return ret;
regval &= MT6360_CHG_STAT_MASK;
regval >>= MT6360_CHG_STAT_SHFT;
switch (regval) {
case 0x0:
status = POWER_SUPPLY_STATUS_NOT_CHARGING;
break;
case 0x1:
status = POWER_SUPPLY_STATUS_CHARGING;
break;
case 0x2:
status = POWER_SUPPLY_STATUS_FULL;
break;
default:
ret = -EIO;
Annotation
- Immediate include surface: `linux/devm-helpers.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/linear_range.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct mt6360_chg_info`, `enum mt6360_iinlmtsel`, `enum mt6360_pmu_chg_type`, `function mt6360_get_chrdet_ext_stat`, `function mt6360_charger_get_online`, `function mt6360_charger_get_status`, `function mt6360_charger_get_charge_type`, `function mt6360_charger_get_ichg`, `function mt6360_charger_get_max_ichg`, `function mt6360_charger_get_cv`.
- 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.