drivers/thermal/st/st_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/st/st_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/st/st_thermal.c- Extension
.c- Size
- 5999 bytes
- Lines
- 268
- 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.
- 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/clk.hlinux/module.hlinux/of.hlinux/of_device.hst_thermal.h../thermal_hwmon.h
Detected Declarations
function Copyrightfunction st_thermal_sensor_onfunction st_thermal_sensor_offfunction st_thermal_calibrationfunction st_thermal_get_tempfunction st_thermal_registerfunction st_thermal_unregisterfunction st_thermal_suspendfunction st_thermal_resumeexport st_thermal_registerexport st_thermal_unregisterexport st_thermal_pm_ops
Annotated Snippet
IS_ERR(sensor->temp_data)) {
dev_err(dev, "failed to allocate common regfields\n");
return -EINVAL;
}
return sensor->ops->alloc_regfields(sensor);
}
static int st_thermal_sensor_on(struct st_thermal_sensor *sensor)
{
int ret;
struct device *dev = sensor->dev;
ret = clk_prepare_enable(sensor->clk);
if (ret) {
dev_err(dev, "failed to enable clk\n");
return ret;
}
ret = sensor->ops->power_ctrl(sensor, POWER_ON);
if (ret) {
dev_err(dev, "failed to power on sensor\n");
clk_disable_unprepare(sensor->clk);
}
return ret;
}
static int st_thermal_sensor_off(struct st_thermal_sensor *sensor)
{
int ret;
ret = sensor->ops->power_ctrl(sensor, POWER_OFF);
if (ret)
return ret;
clk_disable_unprepare(sensor->clk);
return 0;
}
static int st_thermal_calibration(struct st_thermal_sensor *sensor)
{
int ret;
unsigned int val;
struct device *dev = sensor->dev;
/* Check if sensor calibration data is already written */
ret = regmap_field_read(sensor->dcorrect, &val);
if (ret) {
dev_err(dev, "failed to read calibration data\n");
return ret;
}
if (!val) {
/*
* Sensor calibration value not set by bootloader,
* default calibration data to be used
*/
ret = regmap_field_write(sensor->dcorrect,
sensor->cdata->calibration_val);
if (ret)
dev_err(dev, "failed to set calibration data\n");
}
return ret;
}
/* Callback to get temperature from HW*/
static int st_thermal_get_temp(struct thermal_zone_device *th, int *temperature)
{
struct st_thermal_sensor *sensor = thermal_zone_device_priv(th);
unsigned int temp;
unsigned int overflow;
int ret;
ret = regmap_field_read(sensor->overflow, &overflow);
if (ret)
return ret;
if (overflow)
return -EIO;
ret = regmap_field_read(sensor->temp_data, &temp);
if (ret)
return ret;
temp += sensor->cdata->temp_adjust_val;
temp = mcelsius(temp);
*temperature = temp;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/module.h`, `linux/of.h`, `linux/of_device.h`, `st_thermal.h`, `../thermal_hwmon.h`.
- Detected declarations: `function Copyright`, `function st_thermal_sensor_on`, `function st_thermal_sensor_off`, `function st_thermal_calibration`, `function st_thermal_get_temp`, `function st_thermal_register`, `function st_thermal_unregister`, `function st_thermal_suspend`, `function st_thermal_resume`, `export st_thermal_register`.
- 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.