drivers/power/supply/test_power.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/test_power.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/test_power.c- Extension
.c- Size
- 21296 bytes
- Lines
- 761
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/power_supply.hlinux/errno.hlinux/delay.hgenerated/utsrelease.h
Detected Declarations
struct battery_property_mapenum test_power_idfunction test_power_get_ac_propertyfunction test_power_get_usb_propertyfunction test_power_get_battery_propertyfunction test_power_battery_property_is_writeablefunction test_power_set_battery_propertyfunction test_power_battery_extget_propertyfunction test_power_battery_extset_propertyfunction test_power_battery_extproperty_is_writeablefunction test_power_configure_battery_extensionfunction test_power_initfunction test_power_exitfunction map_get_valuefunction signal_power_supply_changedfunction param_set_ac_onlinefunction param_get_ac_onlinefunction param_set_usb_onlinefunction param_get_usb_onlinefunction param_set_battery_statusfunction param_get_battery_statusfunction param_set_battery_healthfunction param_get_battery_healthfunction param_set_battery_presentfunction param_get_battery_presentfunction param_set_battery_technologyfunction param_get_battery_technologyfunction param_set_battery_capacityfunction param_set_battery_voltagefunction param_set_battery_charge_counterfunction param_set_battery_currentfunction param_set_battery_extensionmodule init test_power_init
Annotated Snippet
module_init(test_power_init);
static void __exit test_power_exit(void)
{
int i;
/* Let's see how we handle changes... */
ac_online = 0;
usb_online = 0;
battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
power_supply_changed(test_power_supplies[i]);
pr_info("%s: 'changed' event sent, sleeping for 10 seconds...\n",
__func__);
ssleep(10);
for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
power_supply_unregister(test_power_supplies[i]);
module_initialized = false;
}
module_exit(test_power_exit);
#define MAX_KEYLENGTH 256
struct battery_property_map {
int value;
char const *key;
};
static struct battery_property_map map_ac_online[] = {
{ 0, "off" },
{ 1, "on" },
{ -1, NULL },
};
static struct battery_property_map map_status[] = {
{ POWER_SUPPLY_STATUS_CHARGING, "charging" },
{ POWER_SUPPLY_STATUS_DISCHARGING, "discharging" },
{ POWER_SUPPLY_STATUS_NOT_CHARGING, "not-charging" },
{ POWER_SUPPLY_STATUS_FULL, "full" },
{ -1, NULL },
};
static struct battery_property_map map_health[] = {
{ POWER_SUPPLY_HEALTH_GOOD, "good" },
{ POWER_SUPPLY_HEALTH_OVERHEAT, "overheat" },
{ POWER_SUPPLY_HEALTH_DEAD, "dead" },
{ POWER_SUPPLY_HEALTH_OVERVOLTAGE, "overvoltage" },
{ POWER_SUPPLY_HEALTH_UNSPEC_FAILURE, "failure" },
{ -1, NULL },
};
static struct battery_property_map map_present[] = {
{ 0, "false" },
{ 1, "true" },
{ -1, NULL },
};
static struct battery_property_map map_technology[] = {
{ POWER_SUPPLY_TECHNOLOGY_NiMH, "NiMH" },
{ POWER_SUPPLY_TECHNOLOGY_LION, "LION" },
{ POWER_SUPPLY_TECHNOLOGY_LIPO, "LIPO" },
{ POWER_SUPPLY_TECHNOLOGY_LiFe, "LiFe" },
{ POWER_SUPPLY_TECHNOLOGY_NiCd, "NiCd" },
{ POWER_SUPPLY_TECHNOLOGY_LiMn, "LiMn" },
{ -1, NULL },
};
static int map_get_value(struct battery_property_map *map, const char *key,
int def_val)
{
char buf[MAX_KEYLENGTH];
int cr;
strscpy(buf, key, MAX_KEYLENGTH);
cr = strnlen(buf, MAX_KEYLENGTH) - 1;
if (cr < 0)
return def_val;
if (buf[cr] == '\n')
buf[cr] = '\0';
while (map->key) {
if (strncasecmp(map->key, buf, MAX_KEYLENGTH) == 0)
return map->value;
map++;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/power_supply.h`, `linux/errno.h`, `linux/delay.h`, `generated/utsrelease.h`.
- Detected declarations: `struct battery_property_map`, `enum test_power_id`, `function test_power_get_ac_property`, `function test_power_get_usb_property`, `function test_power_get_battery_property`, `function test_power_battery_property_is_writeable`, `function test_power_set_battery_property`, `function test_power_battery_extget_property`, `function test_power_battery_extset_property`, `function test_power_battery_extproperty_is_writeable`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: integration implementation candidate.
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.