drivers/power/supply/power_supply_core.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/power_supply_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/power_supply_core.c- Extension
.c- Size
- 50997 bytes
- Lines
- 1792
- Domain
- Driver Families
- Bucket
- drivers/power
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/cleanup.hlinux/module.hlinux/types.hlinux/init.hlinux/slab.hlinux/delay.hlinux/device.hlinux/notifier.hlinux/err.hlinux/power_supply.hlinux/property.hlinux/thermal.hlinux/fixp-arith.hpower_supply.hsamsung-sdi-battery.h
Detected Declarations
struct psy_for_each_psy_cb_datastruct psy_am_i_supplied_datastruct psy_get_supplier_prop_datafunction __power_supply_is_supplied_byfunction __power_supply_changed_workfunction power_supply_changed_workfunction power_supply_changedfunction psy_for_each_psy_cbfunction power_supply_for_each_psyfunction power_supply_changedfunction power_supply_changedfunction __power_supply_populate_supplied_fromfunction power_supply_populate_supplied_fromfunction __power_supply_find_supply_from_nodefunction power_supply_find_supply_from_fwnodefunction power_supply_check_suppliesfunction power_supply_check_suppliesfunction __power_supply_am_i_suppliedfunction power_supply_am_i_suppliedfunction __power_supply_is_system_suppliedfunction power_supply_is_system_suppliedfunction __power_supply_get_supplier_propertyfunction power_supply_get_property_from_supplierfunction power_supply_match_device_by_namefunction power_supply_get_by_namefunction power_supply_putfunction power_supply_match_device_fwnodefunction power_supply_get_by_referencefunction devm_power_supply_putfunction devm_power_supply_get_by_referencefunction power_supply_get_battery_infofunction power_supply_put_battery_infofunction power_supply_battery_info_has_propfunction power_supply_battery_info_get_propfunction power_supply_temp2resist_simplefunction power_supply_vbat2rifunction power_supply_get_maintenance_charging_settingfunction power_supply_ocv2cap_simplefunction power_supply_find_ocv2cap_tablefunction power_supply_batinfo_ocv2capfunction power_supply_battery_bti_in_rangefunction psy_desc_has_propertyfunction power_supply_ext_has_propertyfunction power_supply_has_propertyfunction power_supply_for_each_extensionfunction __power_supply_get_propertyfunction power_supply_get_propertyfunction power_supply_get_property
Annotated Snippet
rc = device_add(dev);
if (rc)
goto device_add_failed;
rc = device_init_wakeup(dev, cfg ? !cfg->no_wakeup_source : true);
if (rc)
goto wakeup_init_failed;
rc = psy_register_thermal(psy);
if (rc)
goto register_thermal_failed;
rc = power_supply_create_triggers(psy);
if (rc)
goto create_triggers_failed;
scoped_guard(rwsem_read, &psy->extensions_sem) {
rc = power_supply_add_hwmon_sysfs(psy);
if (rc)
goto add_hwmon_sysfs_failed;
}
/*
* Update use_cnt after any uevents (most notably from device_add()).
* We are here still during driver's probe but
* the power_supply_uevent() calls back driver's get_property
* method so:
* 1. Driver did not assigned the returned struct power_supply,
* 2. Driver could not finish initialization (anything in its probe
* after calling power_supply_register()).
*/
atomic_inc(&psy->use_cnt);
psy->initialized = true;
queue_delayed_work(system_power_efficient_wq,
&psy->deferred_register_work,
POWER_SUPPLY_DEFERRED_REGISTER_TIME);
return psy;
add_hwmon_sysfs_failed:
power_supply_remove_triggers(psy);
create_triggers_failed:
psy_unregister_thermal(psy);
register_thermal_failed:
wakeup_init_failed:
device_del(dev);
device_add_failed:
check_supplies_failed:
dev_set_name_failed:
put_device(dev);
return ERR_PTR(rc);
}
/**
* power_supply_register() - Register new power supply
* @parent: Device to be a parent of power supply's device, usually
* the device which probe function calls this
* @desc: Description of power supply, must be valid through whole
* lifetime of this power supply
* @cfg: Run-time specific configuration accessed during registering,
* may be NULL
*
* Return: A pointer to newly allocated power_supply on success
* or ERR_PTR otherwise.
* Use power_supply_unregister() on returned power_supply pointer to release
* resources.
*/
struct power_supply *__must_check power_supply_register(struct device *parent,
const struct power_supply_desc *desc,
const struct power_supply_config *cfg)
{
return __power_supply_register(parent, desc, cfg);
}
EXPORT_SYMBOL_GPL(power_supply_register);
static void devm_power_supply_release(struct device *dev, void *res)
{
struct power_supply **psy = res;
power_supply_unregister(*psy);
}
/**
* devm_power_supply_register() - Register managed power supply
* @parent: Device to be a parent of power supply's device, usually
* the device which probe function calls this
* @desc: Description of power supply, must be valid through whole
* lifetime of this power supply
* @cfg: Run-time specific configuration accessed during registering,
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/module.h`, `linux/types.h`, `linux/init.h`, `linux/slab.h`, `linux/delay.h`, `linux/device.h`, `linux/notifier.h`.
- Detected declarations: `struct psy_for_each_psy_cb_data`, `struct psy_am_i_supplied_data`, `struct psy_get_supplier_prop_data`, `function __power_supply_is_supplied_by`, `function __power_supply_changed_work`, `function power_supply_changed_work`, `function power_supply_changed`, `function psy_for_each_psy_cb`, `function power_supply_for_each_psy`, `function power_supply_changed`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: integration 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.