drivers/power/supply/charger-manager.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/charger-manager.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/charger-manager.c- Extension
.c- Size
- 46721 bytes
- Lines
- 1769
- 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/io.hlinux/module.hlinux/irq.hlinux/interrupt.hlinux/rtc.hlinux/slab.hlinux/workqueue.hlinux/platform_device.hlinux/power/charger-manager.hlinux/regulator/consumer.hlinux/string_choices.hlinux/sysfs.hlinux/of.hlinux/thermal.h
Detected Declarations
function is_batt_presentfunction is_ext_pwr_onlinefunction get_batt_uVfunction is_chargingfunction is_full_chargedfunction is_polling_requiredfunction try_charger_enablefunction check_charging_durationfunction cm_get_battery_temperature_by_psyfunction cm_get_battery_temperaturefunction cm_check_thermal_statusfunction cm_get_target_statusfunction _cm_monitorfunction cm_monitorfunction list_for_each_entryfunction _setup_pollingfunction list_for_each_entryfunction cm_monitor_pollerfunction charger_get_propertyfunction cm_setup_timerfunction charger_extcon_workfunction charger_extcon_notifierfunction charger_extcon_initfunction EXTCONfunction charger_name_showfunction charger_state_showfunction charger_externally_control_showfunction charger_externally_control_storefunction chargerfunction cm_init_thermal_datafunction for_each_child_of_nodefunction for_each_child_of_nodefunction cm_timer_funcfunction charger_manager_probefunction charger_manager_removefunction cm_suspend_noirqfunction cm_need_to_awakefunction cm_suspend_preparefunction cm_suspend_completefunction charger_manager_initfunction charger_manager_cleanup
Annotated Snippet
if (!psy) {
dev_err(cm->dev, "Cannot find power supply \"%s\"\n",
cm->desc->psy_charger_stat[i]);
continue;
}
ret = power_supply_get_property(psy,
POWER_SUPPLY_PROP_PRESENT, &val);
power_supply_put(psy);
if (ret == 0 && val.intval) {
present = true;
break;
}
}
break;
}
return present;
}
/**
* is_ext_pwr_online - See if an external power source is attached to charge
* @cm: the Charger Manager representing the battery.
*
* Returns true if at least one of the chargers of the battery has an external
* power source attached to charge the battery regardless of whether it is
* actually charging or not.
*/
static bool is_ext_pwr_online(struct charger_manager *cm)
{
union power_supply_propval val;
struct power_supply *psy;
bool online = false;
int i, ret;
/* If at least one of them has one, it's yes. */
for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
psy = power_supply_get_by_name(cm->desc->psy_charger_stat[i]);
if (!psy) {
dev_err(cm->dev, "Cannot find power supply \"%s\"\n",
cm->desc->psy_charger_stat[i]);
continue;
}
ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE,
&val);
power_supply_put(psy);
if (ret == 0 && val.intval) {
online = true;
break;
}
}
return online;
}
/**
* get_batt_uV - Get the voltage level of the battery
* @cm: the Charger Manager representing the battery.
* @uV: the voltage level returned.
*
* Returns 0 if there is no error.
* Returns a negative value on error.
*/
static int get_batt_uV(struct charger_manager *cm, int *uV)
{
union power_supply_propval val;
struct power_supply *fuel_gauge;
int ret;
fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
if (!fuel_gauge)
return -ENODEV;
ret = power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_VOLTAGE_NOW, &val);
power_supply_put(fuel_gauge);
if (ret)
return ret;
*uV = val.intval;
return 0;
}
/**
* is_charging - Returns true if the battery is being charged.
* @cm: the Charger Manager representing the battery.
*/
static bool is_charging(struct charger_manager *cm)
{
Annotation
- Immediate include surface: `linux/io.h`, `linux/module.h`, `linux/irq.h`, `linux/interrupt.h`, `linux/rtc.h`, `linux/slab.h`, `linux/workqueue.h`, `linux/platform_device.h`.
- Detected declarations: `function is_batt_present`, `function is_ext_pwr_online`, `function get_batt_uV`, `function is_charging`, `function is_full_charged`, `function is_polling_required`, `function try_charger_enable`, `function check_charging_duration`, `function cm_get_battery_temperature_by_psy`, `function cm_get_battery_temperature`.
- 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.