drivers/thermal/kirkwood_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/kirkwood_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/kirkwood_thermal.c- Extension
.c- Size
- 2940 bytes
- Lines
- 117
- 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 kirkwood_thermal_privfunction kirkwood_get_tempfunction kirkwood_thermal_probefunction kirkwood_thermal_exit
Annotated Snippet
struct kirkwood_thermal_priv {
void __iomem *sensor;
};
static int kirkwood_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
unsigned long reg;
struct kirkwood_thermal_priv *priv = thermal_zone_device_priv(thermal);
reg = readl_relaxed(priv->sensor);
/* Valid check */
if (!((reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
KIRKWOOD_THERMAL_VALID_MASK))
return -EIO;
/*
* Calculate temperature. According to Marvell internal
* documentation the formula for this is:
* Celsius = (322-reg)/1.3625
*/
reg = (reg >> KIRKWOOD_THERMAL_TEMP_OFFSET) &
KIRKWOOD_THERMAL_TEMP_MASK;
*temp = ((3220000000UL - (10000000UL * reg)) / 13625);
return 0;
}
static const struct thermal_zone_device_ops ops = {
.get_temp = kirkwood_get_temp,
};
static const struct of_device_id kirkwood_thermal_id_table[] = {
{ .compatible = "marvell,kirkwood-thermal" },
{}
};
static int kirkwood_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *thermal = NULL;
struct kirkwood_thermal_priv *priv;
int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->sensor = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
if (IS_ERR(priv->sensor))
return PTR_ERR(priv->sensor);
thermal = thermal_tripless_zone_device_register("kirkwood_thermal",
priv, &ops, NULL);
if (IS_ERR(thermal)) {
dev_err(&pdev->dev,
"Failed to register thermal zone device\n");
return PTR_ERR(thermal);
}
ret = thermal_zone_device_enable(thermal);
if (ret) {
thermal_zone_device_unregister(thermal);
dev_err(&pdev->dev, "Failed to enable thermal zone device\n");
return ret;
}
platform_set_drvdata(pdev, thermal);
return 0;
}
static void kirkwood_thermal_exit(struct platform_device *pdev)
{
struct thermal_zone_device *kirkwood_thermal =
platform_get_drvdata(pdev);
thermal_zone_device_unregister(kirkwood_thermal);
}
MODULE_DEVICE_TABLE(of, kirkwood_thermal_id_table);
static struct platform_driver kirkwood_thermal_driver = {
.probe = kirkwood_thermal_probe,
.remove = kirkwood_thermal_exit,
.driver = {
.name = "kirkwood_thermal",
.of_match_table = kirkwood_thermal_id_table,
},
};
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 kirkwood_thermal_priv`, `function kirkwood_get_temp`, `function kirkwood_thermal_probe`, `function kirkwood_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.