drivers/thermal/sprd_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/sprd_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/sprd_thermal.c- Extension
.c- Size
- 14064 bytes
- Lines
- 550
- 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.
- 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/io.hlinux/iopoll.hlinux/module.hlinux/nvmem-consumer.hlinux/of.hlinux/platform_device.hlinux/slab.hlinux/thermal.h
Detected Declarations
struct sprd_thermal_sensorstruct sprd_thermal_datastruct sprd_thm_variant_datafunction sprd_thm_update_bitsfunction sprd_thm_cal_readfunction sprd_thm_sensor_calibrationfunction sprd_thm_rawdata_to_tempfunction sprd_thm_temp_to_rawdatafunction sprd_thm_read_tempfunction sprd_thm_poll_ready_statusfunction sprd_thm_wait_temp_readyfunction sprd_thm_set_readyfunction sprd_thm_sensor_initfunction sprd_thm_para_configfunction sprd_thm_toggle_sensorfunction sprd_thm_probefunction for_each_child_of_nodefunction sprd_thm_hw_suspendfunction sprd_thm_suspendfunction sprd_thm_hw_resumefunction sprd_thm_resumefunction sprd_thm_remove
Annotated Snippet
struct sprd_thermal_sensor {
struct thermal_zone_device *tzd;
struct sprd_thermal_data *data;
struct device *dev;
int cal_slope;
int cal_offset;
int id;
};
struct sprd_thermal_data {
const struct sprd_thm_variant_data *var_data;
struct sprd_thermal_sensor *sensor[SPRD_THM_MAX_SENSOR];
struct clk *clk;
void __iomem *base;
u32 ratio_off;
int ratio_sign;
int nr_sensors;
};
/*
* The conversion between ADC and temperature is based on linear relationship,
* and use idea_k to specify the slope and ideal_b to specify the offset.
*
* Since different Spreadtrum SoCs have different ideal_k and ideal_b,
* we should save ideal_k and ideal_b in the device data structure.
*/
struct sprd_thm_variant_data {
u32 ideal_k;
u32 ideal_b;
};
static const struct sprd_thm_variant_data ums512_data = {
.ideal_k = 262,
.ideal_b = 66400,
};
static inline void sprd_thm_update_bits(void __iomem *reg, u32 mask, u32 val)
{
u32 tmp, orig;
orig = readl(reg);
tmp = orig & ~mask;
tmp |= val & mask;
writel(tmp, reg);
}
static int sprd_thm_cal_read(struct device_node *np, const char *cell_id,
u32 *val)
{
struct nvmem_cell *cell;
void *buf;
size_t len;
cell = of_nvmem_cell_get(np, cell_id);
if (IS_ERR(cell))
return PTR_ERR(cell);
buf = nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);
if (IS_ERR(buf))
return PTR_ERR(buf);
if (len > sizeof(u32)) {
kfree(buf);
return -EINVAL;
}
memcpy(val, buf, len);
kfree(buf);
return 0;
}
static int sprd_thm_sensor_calibration(struct device_node *np,
struct sprd_thermal_data *thm,
struct sprd_thermal_sensor *sen)
{
int ret;
/*
* According to thermal datasheet, the default calibration offset is 64,
* and the default ratio is 1000.
*/
int dt_offset = 64, ratio = 1000;
ret = sprd_thm_cal_read(np, "sen_delta_cal", &dt_offset);
if (ret)
return ret;
ratio += thm->ratio_sign * thm->ratio_off;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/nvmem-consumer.h`, `linux/of.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct sprd_thermal_sensor`, `struct sprd_thermal_data`, `struct sprd_thm_variant_data`, `function sprd_thm_update_bits`, `function sprd_thm_cal_read`, `function sprd_thm_sensor_calibration`, `function sprd_thm_rawdata_to_temp`, `function sprd_thm_temp_to_rawdata`, `function sprd_thm_read_temp`, `function sprd_thm_poll_ready_status`.
- Atlas domain: Driver Families / drivers/thermal.
- 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.