drivers/power/supply/rt5033_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rt5033_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rt5033_charger.c- Extension
.c- Size
- 19171 bytes
- Lines
- 754
- 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.
- 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/extcon.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/mfd/rt5033-private.hlinux/property.h
Detected Declarations
struct rt5033_charger_datastruct rt5033_chargerfunction rt5033_get_charger_statefunction rt5033_get_charger_typefunction rt5033_get_charger_current_limitfunction rt5033_get_charger_const_voltagefunction rt5033_init_const_chargefunction rt5033_init_fast_chargefunction rt5033_init_pre_chargefunction rt5033_charger_reg_initfunction rt5033_charger_set_otgfunction rt5033_charger_unset_otgfunction rt5033_charger_set_chargingfunction rt5033_charger_set_mivrfunction rt5033_charger_set_disconnectfunction rt5033_charger_get_propertyfunction rt5033_charger_dt_initfunction rt5033_charger_extcon_workfunction rt5033_charger_extcon_notifierfunction rt5033_charger_probe
Annotated Snippet
struct rt5033_charger_data {
unsigned int pre_uamp;
unsigned int pre_uvolt;
unsigned int const_uvolt;
unsigned int eoc_uamp;
unsigned int fast_uamp;
};
struct rt5033_charger {
struct device *dev;
struct regmap *regmap;
struct power_supply *psy;
struct rt5033_charger_data chg;
struct extcon_dev *edev;
struct notifier_block extcon_nb;
struct work_struct extcon_work;
struct mutex lock;
bool online;
bool otg;
bool mivr_enabled;
u8 cv_regval;
};
static int rt5033_get_charger_state(struct rt5033_charger *charger)
{
struct regmap *regmap = charger->regmap;
unsigned int reg_data;
int state;
if (!regmap)
return POWER_SUPPLY_STATUS_UNKNOWN;
regmap_read(regmap, RT5033_REG_CHG_STAT, ®_data);
switch (reg_data & RT5033_CHG_STAT_MASK) {
case RT5033_CHG_STAT_DISCHARGING:
state = POWER_SUPPLY_STATUS_DISCHARGING;
break;
case RT5033_CHG_STAT_CHARGING:
state = POWER_SUPPLY_STATUS_CHARGING;
break;
case RT5033_CHG_STAT_FULL:
state = POWER_SUPPLY_STATUS_FULL;
break;
case RT5033_CHG_STAT_NOT_CHARGING:
state = POWER_SUPPLY_STATUS_NOT_CHARGING;
break;
default:
state = POWER_SUPPLY_STATUS_UNKNOWN;
}
/* For OTG mode, RT5033 would still report "charging" */
if (charger->otg)
state = POWER_SUPPLY_STATUS_DISCHARGING;
return state;
}
static int rt5033_get_charger_type(struct rt5033_charger *charger)
{
struct regmap *regmap = charger->regmap;
unsigned int reg_data;
int state;
regmap_read(regmap, RT5033_REG_CHG_STAT, ®_data);
switch (reg_data & RT5033_CHG_STAT_TYPE_MASK) {
case RT5033_CHG_STAT_TYPE_FAST:
state = POWER_SUPPLY_CHARGE_TYPE_FAST;
break;
case RT5033_CHG_STAT_TYPE_PRE:
state = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
break;
default:
state = POWER_SUPPLY_CHARGE_TYPE_NONE;
}
return state;
}
static int rt5033_get_charger_current_limit(struct rt5033_charger *charger)
{
struct regmap *regmap = charger->regmap;
unsigned int state, reg_data, data;
regmap_read(regmap, RT5033_REG_CHG_CTRL5, ®_data);
state = (reg_data & RT5033_CHGCTRL5_ICHG_MASK)
>> RT5033_CHGCTRL5_ICHG_SHIFT;
Annotation
- Immediate include surface: `linux/devm-helpers.h`, `linux/extcon.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct rt5033_charger_data`, `struct rt5033_charger`, `function rt5033_get_charger_state`, `function rt5033_get_charger_type`, `function rt5033_get_charger_current_limit`, `function rt5033_get_charger_const_voltage`, `function rt5033_init_const_charge`, `function rt5033_init_fast_charge`, `function rt5033_init_pre_charge`, `function rt5033_charger_reg_init`.
- 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.
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.