drivers/thermal/thermal_helpers.c
Source file repositories/reference/linux-study-clean/drivers/thermal/thermal_helpers.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/thermal_helpers.c- Extension
.c- Size
- 6215 bytes
- Lines
- 241
- Domain
- Driver Families
- Bucket
- drivers/thermal
- 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/device.hlinux/err.hlinux/export.hlinux/slab.hlinux/string.hlinux/sysfs.hthermal_core.hthermal_trace.h
Detected Declarations
function Copyrightfunction thermal_instance_presentfunction list_for_each_entryfunction thermal_trip_is_bound_to_cdevfunction __thermal_zone_get_tempfunction thermal_zone_get_tempfunction thermal_cdev_set_cur_statefunction __thermal_cdev_updatefunction thermal_cdev_updatefunction thermal_cdev_update_nocheckfunction thermal_zone_get_slopefunction thermal_zone_get_offsetexport thermal_trip_is_bound_to_cdevexport thermal_zone_get_tempexport thermal_zone_get_slopeexport thermal_zone_get_offset
Annotated Snippet
for_each_trip_desc(tz, td) {
const struct thermal_trip *trip = &td->trip;
if (trip->type == THERMAL_TRIP_CRITICAL) {
crit_temp = trip->temperature;
break;
}
}
/*
* Only allow emulating a temperature when the real temperature
* is below the critical temperature so that the emulation code
* cannot hide critical conditions.
*/
if (!ret && *temp < crit_temp)
*temp = tz->emul_temperature;
}
if (ret)
dev_dbg(&tz->device, "Failed to get temperature: %d\n", ret);
return ret;
}
/**
* thermal_zone_get_temp() - returns the temperature of a thermal zone
* @tz: a valid pointer to a struct thermal_zone_device
* @temp: a valid pointer to where to store the resulting temperature.
*
* When a valid thermal zone reference is passed, it will fetch its
* temperature and fill @temp.
*
* Return: On success returns 0, an error code otherwise
*/
int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
{
int ret;
if (IS_ERR_OR_NULL(tz))
return -EINVAL;
guard(thermal_zone)(tz);
if (!tz->ops.get_temp)
return -EINVAL;
ret = __thermal_zone_get_temp(tz, temp);
if (!ret && *temp <= THERMAL_TEMP_INVALID)
return -ENODATA;
return ret;
}
EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
static int thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev, int state)
{
int ret;
/*
* No check is needed for the ops->set_cur_state as the
* registering function checked the ops are correctly set
*/
ret = cdev->ops->set_cur_state(cdev, state);
if (ret)
return ret;
thermal_notify_cdev_state_update(cdev, state);
thermal_cooling_device_stats_update(cdev, state);
thermal_debug_cdev_state_update(cdev, state);
return 0;
}
void __thermal_cdev_update(struct thermal_cooling_device *cdev)
{
struct thermal_instance *instance;
unsigned long target = 0;
/* Make sure cdev enters the deepest cooling state */
list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
if (instance->target == THERMAL_NO_TARGET)
continue;
if (instance->target > target)
target = instance->target;
}
thermal_cdev_set_cur_state(cdev, target);
trace_cdev_update(cdev, target);
dev_dbg(&cdev->device, "set to state %lu\n", target);
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/export.h`, `linux/slab.h`, `linux/string.h`, `linux/sysfs.h`, `thermal_core.h`, `thermal_trace.h`.
- Detected declarations: `function Copyright`, `function thermal_instance_present`, `function list_for_each_entry`, `function thermal_trip_is_bound_to_cdev`, `function __thermal_zone_get_temp`, `function thermal_zone_get_temp`, `function thermal_cdev_set_cur_state`, `function __thermal_cdev_update`, `function thermal_cdev_update`, `function thermal_cdev_update_nocheck`.
- Atlas domain: Driver Families / drivers/thermal.
- 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.