drivers/thermal/dove_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/dove_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/dove_thermal.c- Extension
.c- Size
- 4649 bytes
- Lines
- 185
- 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/device.hlinux/err.hlinux/io.hlinux/kernel.hlinux/of.hlinux/module.hlinux/platform_device.hlinux/thermal.h
Detected Declarations
struct dove_thermal_privfunction dove_init_sensorfunction dove_get_tempfunction dove_thermal_probefunction dove_thermal_exit
Annotated Snippet
struct dove_thermal_priv {
void __iomem *sensor;
void __iomem *control;
};
static int dove_init_sensor(const struct dove_thermal_priv *priv)
{
u32 reg;
u32 i;
/* Configure the Diode Control Register #0 */
reg = readl_relaxed(priv->control);
/* Use average of 2 */
reg &= ~PMU_TDC0_AVG_NUM_MASK;
reg |= (0x1 << PMU_TDC0_AVG_NUM_OFFS);
/* Reference calibration value */
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
reg |= (0x0F1 << PMU_TDC0_REF_CAL_CNT_OFFS);
/* Set the high level reference for calibration */
reg &= ~PMU_TDC0_SEL_VCAL_MASK;
reg |= (0x2 << PMU_TDC0_SEL_VCAL_OFFS);
writel(reg, priv->control);
/* Reset the sensor */
reg = readl_relaxed(priv->control);
writel((reg | PMU_TDC0_SW_RST_MASK), priv->control);
writel(reg, priv->control);
/* Enable the sensor */
reg = readl_relaxed(priv->sensor);
reg &= ~PMU_TM_DISABLE_MASK;
writel(reg, priv->sensor);
/* Poll the sensor for the first reading */
for (i = 0; i < 1000000; i++) {
reg = readl_relaxed(priv->sensor);
if (reg & DOVE_THERMAL_TEMP_MASK)
break;
}
if (i == 1000000)
return -EIO;
return 0;
}
static int dove_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
unsigned long reg;
struct dove_thermal_priv *priv = thermal_zone_device_priv(thermal);
/* Valid check */
reg = readl_relaxed(priv->control + PMU_TEMP_DIOD_CTRL1_REG);
if ((reg & PMU_TDC1_TEMP_VALID_MASK) == 0x0)
return -EIO;
/*
* Calculate temperature. According to Marvell internal
* documentation the formula for this is:
* Celsius = (322-reg)/1.3625
*/
reg = readl_relaxed(priv->sensor);
reg = (reg >> DOVE_THERMAL_TEMP_OFFSET) & DOVE_THERMAL_TEMP_MASK;
*temp = ((3220000000UL - (10000000UL * reg)) / 13625);
return 0;
}
static const struct thermal_zone_device_ops ops = {
.get_temp = dove_get_temp,
};
static const struct of_device_id dove_thermal_id_table[] = {
{ .compatible = "marvell,dove-thermal" },
{}
};
static int dove_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *thermal = NULL;
struct dove_thermal_priv *priv;
int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/io.h`, `linux/kernel.h`, `linux/of.h`, `linux/module.h`, `linux/platform_device.h`, `linux/thermal.h`.
- Detected declarations: `struct dove_thermal_priv`, `function dove_init_sensor`, `function dove_get_temp`, `function dove_thermal_probe`, `function dove_thermal_exit`.
- 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.