drivers/thermal/imx91_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/imx91_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/imx91_thermal.c- Extension
.c- Size
- 10349 bytes
- Lines
- 389
- 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/bitfield.hlinux/clk.hlinux/err.hlinux/interrupt.hlinux/iopoll.hlinux/nvmem-consumer.hlinux/module.hlinux/of.hlinux/of_device.hlinux/platform_device.hlinux/pm_runtime.hlinux/thermal.hlinux/units.hthermal_hwmon.h
Detected Declarations
struct imx91_tmufunction imx91_tmu_startfunction imx91_tmu_enablefunction imx91_tmu_to_mcelsiusfunction imx91_tmu_from_mcelsiusfunction imx91_tmu_get_tempfunction imx91_tmu_set_tripsfunction imx91_init_from_nvmem_cellsfunction imx91_tmu_action_removefunction imx91_tmu_alarm_irqfunction imx91_tmu_alarm_irq_threadfunction imx91_tmu_change_modefunction imx91_tmu_probefunction imx91_tmu_runtime_suspendfunction imx91_tmu_runtime_resume
Annotated Snippet
struct imx91_tmu {
void __iomem *base;
struct clk *clk;
struct device *dev;
struct thermal_zone_device *tzd;
};
static void imx91_tmu_start(struct imx91_tmu *tmu, bool start)
{
u32 val = start ? IMX91_TMU_CTRL1_START : IMX91_TMU_CTRL1_STOP;
writel_relaxed(val, tmu->base + IMX91_TMU_CTRL1 + REG_SET);
}
static void imx91_tmu_enable(struct imx91_tmu *tmu, bool enable)
{
u32 reg = IMX91_TMU_CTRL1;
reg += enable ? REG_SET : REG_CLR;
writel_relaxed(IMX91_TMU_CTRL1_EN, tmu->base + reg);
}
static int imx91_tmu_to_mcelsius(int x)
{
return x * MILLIDEGREE_PER_DEGREE / IMX91_TMP_FRAC;
}
static int imx91_tmu_from_mcelsius(int x)
{
return x * IMX91_TMP_FRAC / MILLIDEGREE_PER_DEGREE;
}
static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
s16 data;
/* DATA0 is 16bit signed number */
data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
*temp = imx91_tmu_to_mcelsius(data);
return 0;
}
static int imx91_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
{
struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
int val;
if (high >= IMX91_TMU_TEMP_HIGH_LIMIT)
return -EINVAL;
writel_relaxed(IMX91_TMU_CTRL0_THR1_IE, tmu->base + IMX91_TMU_CTRL0 + REG_CLR);
/* Comparator1 for temperature threshold */
writel_relaxed(IMX91_TMU_THR_CTRL01_THR1_MASK, tmu->base + IMX91_TMU_THR_CTRL01 + REG_CLR);
val = FIELD_PREP(IMX91_TMU_THR_CTRL01_THR1_MASK, imx91_tmu_from_mcelsius(high));
writel_relaxed(val, tmu->base + IMX91_TMU_THR_CTRL01 + REG_SET);
writel_relaxed(IMX91_TMU_STAT0_THR1_IF, tmu->base + IMX91_TMU_STAT0 + REG_CLR);
writel_relaxed(IMX91_TMU_CTRL0_THR1_IE, tmu->base + IMX91_TMU_CTRL0 + REG_SET);
return 0;
}
static int imx91_init_from_nvmem_cells(struct imx91_tmu *tmu)
{
struct device *dev = tmu->dev;
u32 trim1, trim2;
int ret;
ret = nvmem_cell_read_u32(dev, "trim1", &trim1);
if (ret)
return ret;
ret = nvmem_cell_read_u32(dev, "trim2", &trim2);
if (ret)
return ret;
if (trim1 == 0 || trim2 == 0)
return -EINVAL;
writel_relaxed(trim1, tmu->base + IMX91_TMU_TRIM1);
writel_relaxed(trim2, tmu->base + IMX91_TMU_TRIM2);
return 0;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/err.h`, `linux/interrupt.h`, `linux/iopoll.h`, `linux/nvmem-consumer.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct imx91_tmu`, `function imx91_tmu_start`, `function imx91_tmu_enable`, `function imx91_tmu_to_mcelsius`, `function imx91_tmu_from_mcelsius`, `function imx91_tmu_get_temp`, `function imx91_tmu_set_trips`, `function imx91_init_from_nvmem_cells`, `function imx91_tmu_action_remove`, `function imx91_tmu_alarm_irq`.
- 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.