drivers/thermal/hisi_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/hisi_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/hisi_thermal.c- Extension
.c- Size
- 16775 bytes
- Lines
- 652
- Domain
- Driver Families
- Bucket
- drivers/thermal
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/cpufreq.hlinux/delay.hlinux/interrupt.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/io.hlinux/thermal.h
Detected Declarations
struct hisi_thermal_datastruct hisi_thermal_sensorstruct hisi_thermal_opsstruct hisi_thermal_datafunction hi6220_thermal_step_to_tempfunction hi6220_thermal_temp_to_stepfunction hi3660_thermal_step_to_tempfunction hi3660_thermal_temp_to_stepfunction hi6220_thermal_set_lagfunction hi6220_thermal_alarm_clearfunction hi6220_thermal_alarm_enablefunction hi6220_thermal_alarm_setfunction hi6220_thermal_reset_setfunction hi6220_thermal_reset_enablefunction hi6220_thermal_enablefunction hi6220_thermal_get_temperaturefunction hi3660_thermal_set_lagfunction hi3660_thermal_alarm_clearfunction hi3660_thermal_alarm_enablefunction hi3660_thermal_alarm_setfunction hi3660_thermal_get_temperaturefunction hi6220_thermal_sensor_selectfunction hi6220_thermal_hdak_setfunction hi6220_thermal_irq_handlerfunction hi3660_thermal_irq_handlerfunction hi6220_thermal_get_tempfunction hi3660_thermal_get_tempfunction hi6220_thermal_disable_sensorfunction hi3660_thermal_disable_sensorfunction hi6220_thermal_enable_sensorfunction hi3660_thermal_enable_sensorfunction hi6220_thermal_probefunction hi3660_thermal_probefunction hisi_thermal_get_tempfunction hisi_thermal_alarm_irq_threadfunction hisi_trip_walk_cbfunction hisi_thermal_register_sensorfunction hisi_thermal_toggle_sensorfunction hisi_thermal_probefunction hisi_thermal_removefunction hisi_thermal_suspendfunction hisi_thermal_resume
Annotated Snippet
struct hisi_thermal_sensor {
struct hisi_thermal_data *data;
struct thermal_zone_device *tzd;
const char *irq_name;
uint32_t id;
uint32_t thres_temp;
};
struct hisi_thermal_ops {
int (*get_temp)(struct hisi_thermal_sensor *sensor);
int (*enable_sensor)(struct hisi_thermal_sensor *sensor);
int (*disable_sensor)(struct hisi_thermal_sensor *sensor);
int (*irq_handler)(struct hisi_thermal_sensor *sensor);
int (*probe)(struct hisi_thermal_data *data);
};
struct hisi_thermal_data {
const struct hisi_thermal_ops *ops;
struct hisi_thermal_sensor *sensor;
struct platform_device *pdev;
struct clk *clk;
void __iomem *regs;
int nr_sensors;
};
/*
* The temperature computation on the tsensor is as follow:
* Unit: millidegree Celsius
* Step: 200/255 (0.7843)
* Temperature base: -60°C
*
* The register is programmed in temperature steps, every step is 785
* millidegree and begins at -60 000 m°C
*
* The temperature from the steps:
*
* Temp = TempBase + (steps x 785)
*
* and the steps from the temperature:
*
* steps = (Temp - TempBase) / 785
*
*/
static inline int hi6220_thermal_step_to_temp(int step)
{
return HI6220_TEMP_BASE + (step * HI6220_TEMP_STEP);
}
static inline int hi6220_thermal_temp_to_step(int temp)
{
return DIV_ROUND_UP(temp - HI6220_TEMP_BASE, HI6220_TEMP_STEP);
}
/*
* for Hi3660,
* Step: 189/922 (0.205)
* Temperature base: -63.780°C
*
* The register is programmed in temperature steps, every step is 205
* millidegree and begins at -63 780 m°C
*/
static inline int hi3660_thermal_step_to_temp(int step)
{
return HI3660_TEMP_BASE + step * HI3660_TEMP_STEP;
}
static inline int hi3660_thermal_temp_to_step(int temp)
{
return DIV_ROUND_UP(temp - HI3660_TEMP_BASE, HI3660_TEMP_STEP);
}
/*
* The lag register contains 5 bits encoding the temperature in steps.
*
* Each time the temperature crosses the threshold boundary, an
* interrupt is raised. It could be when the temperature is going
* above the threshold or below. However, if the temperature is
* fluctuating around this value due to the load, we can receive
* several interrupts which may not desired.
*
* We can setup a temperature representing the delta between the
* threshold and the current temperature when the temperature is
* decreasing.
*
* For instance: the lag register is 5°C, the threshold is 65°C, when
* the temperature reaches 65°C an interrupt is raised and when the
* temperature decrease to 65°C - 5°C another interrupt is raised.
*
* A very short lag can lead to an interrupt storm, a long lag
* increase the latency to react to the temperature changes. In our
Annotation
- Immediate include surface: `linux/cpufreq.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/io.h`, `linux/thermal.h`.
- Detected declarations: `struct hisi_thermal_data`, `struct hisi_thermal_sensor`, `struct hisi_thermal_ops`, `struct hisi_thermal_data`, `function hi6220_thermal_step_to_temp`, `function hi6220_thermal_temp_to_step`, `function hi3660_thermal_step_to_temp`, `function hi3660_thermal_temp_to_step`, `function hi6220_thermal_set_lag`, `function hi6220_thermal_alarm_clear`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.