drivers/power/supply/power_supply_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/power_supply_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/power_supply_hwmon.c- Extension
.c- Size
- 10017 bytes
- Lines
- 437
- 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.
- 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/err.hlinux/hwmon.hlinux/power_supply.hlinux/slab.hpower_supply.h
Detected Declarations
struct power_supply_hwmonstruct hwmon_type_attr_listfunction power_supply_hwmon_in_to_propertyfunction power_supply_hwmon_curr_to_propertyfunction power_supply_hwmon_power_to_propertyfunction power_supply_hwmon_temp_to_propertyfunction power_supply_hwmon_to_propertyfunction power_supply_hwmon_is_a_labelfunction power_supply_hwmon_has_inputfunction power_supply_hwmon_is_writablefunction power_supply_hwmon_is_visiblefunction power_supply_hwmon_read_stringfunction power_supply_hwmon_readfunction power_supply_hwmon_writefunction power_supply_add_hwmon_sysfsfunction power_supply_remove_hwmon_sysfs
Annotated Snippet
struct power_supply_hwmon {
struct power_supply *psy;
unsigned long *props;
};
static const char *const ps_temp_label[] = {
"temp",
"ambient temp",
};
static int power_supply_hwmon_in_to_property(u32 attr)
{
switch (attr) {
case hwmon_in_average:
return POWER_SUPPLY_PROP_VOLTAGE_AVG;
case hwmon_in_min:
return POWER_SUPPLY_PROP_VOLTAGE_MIN;
case hwmon_in_max:
return POWER_SUPPLY_PROP_VOLTAGE_MAX;
case hwmon_in_input:
return POWER_SUPPLY_PROP_VOLTAGE_NOW;
default:
return -EINVAL;
}
}
static int power_supply_hwmon_curr_to_property(u32 attr)
{
switch (attr) {
case hwmon_curr_average:
return POWER_SUPPLY_PROP_CURRENT_AVG;
case hwmon_curr_max:
return POWER_SUPPLY_PROP_CURRENT_MAX;
case hwmon_curr_input:
return POWER_SUPPLY_PROP_CURRENT_NOW;
default:
return -EINVAL;
}
}
static int power_supply_hwmon_power_to_property(u32 attr)
{
switch (attr) {
case hwmon_power_input:
return POWER_SUPPLY_PROP_POWER_NOW;
case hwmon_power_average:
return POWER_SUPPLY_PROP_POWER_AVG;
default:
return -EINVAL;
}
}
static int power_supply_hwmon_temp_to_property(u32 attr, int channel)
{
if (channel) {
switch (attr) {
case hwmon_temp_input:
return POWER_SUPPLY_PROP_TEMP_AMBIENT;
case hwmon_temp_min_alarm:
return POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN;
case hwmon_temp_max_alarm:
return POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX;
default:
break;
}
} else {
switch (attr) {
case hwmon_temp_input:
return POWER_SUPPLY_PROP_TEMP;
case hwmon_temp_max:
return POWER_SUPPLY_PROP_TEMP_MAX;
case hwmon_temp_min:
return POWER_SUPPLY_PROP_TEMP_MIN;
case hwmon_temp_min_alarm:
return POWER_SUPPLY_PROP_TEMP_ALERT_MIN;
case hwmon_temp_max_alarm:
return POWER_SUPPLY_PROP_TEMP_ALERT_MAX;
default:
break;
}
}
return -EINVAL;
}
static int
power_supply_hwmon_to_property(enum hwmon_sensor_types type,
u32 attr, int channel)
{
switch (type) {
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/power_supply.h`, `linux/slab.h`, `power_supply.h`.
- Detected declarations: `struct power_supply_hwmon`, `struct hwmon_type_attr_list`, `function power_supply_hwmon_in_to_property`, `function power_supply_hwmon_curr_to_property`, `function power_supply_hwmon_power_to_property`, `function power_supply_hwmon_temp_to_property`, `function power_supply_hwmon_to_property`, `function power_supply_hwmon_is_a_label`, `function power_supply_hwmon_has_input`, `function power_supply_hwmon_is_writable`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source 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.