drivers/thermal/broadcom/bcm2835_thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/broadcom/bcm2835_thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/broadcom/bcm2835_thermal.c- Extension
.c- Size
- 7443 bytes
- Lines
- 278
- 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/debugfs.hlinux/device.hlinux/err.hlinux/io.hlinux/kernel.hlinux/minmax.hlinux/module.hlinux/of.hlinux/of_address.hlinux/of_device.hlinux/platform_device.hlinux/thermal.h../thermal_hwmon.h
Detected Declarations
struct bcm2835_thermal_datafunction bcm2835_thermal_adc2tempfunction bcm2835_thermal_temp2adcfunction bcm2835_thermal_get_tempfunction bcm2835_thermal_debugfsfunction bcm2835_thermal_probefunction bcm2835_thermal_remove
Annotated Snippet
struct bcm2835_thermal_data {
struct thermal_zone_device *tz;
void __iomem *regs;
struct clk *clk;
struct dentry *debugfsdir;
};
static int bcm2835_thermal_adc2temp(u32 adc, int offset, int slope)
{
return offset + slope * adc;
}
static int bcm2835_thermal_temp2adc(int temp, int offset, int slope)
{
temp -= offset;
temp /= slope;
return clamp(temp, 0, (int)BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1);
}
static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct bcm2835_thermal_data *data = thermal_zone_device_priv(tz);
u32 val = readl(data->regs + BCM2835_TS_TSENSSTAT);
if (!(val & BCM2835_TS_TSENSSTAT_VALID))
return -EIO;
val &= BCM2835_TS_TSENSSTAT_DATA_MASK;
*temp = bcm2835_thermal_adc2temp(
val,
thermal_zone_get_offset(data->tz),
thermal_zone_get_slope(data->tz));
return 0;
}
static const struct debugfs_reg32 bcm2835_thermal_regs[] = {
{
.name = "ctl",
.offset = 0
},
{
.name = "stat",
.offset = 4
}
};
static void bcm2835_thermal_debugfs(struct platform_device *pdev)
{
struct bcm2835_thermal_data *data = platform_get_drvdata(pdev);
struct debugfs_regset32 *regset;
data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL);
regset = devm_kzalloc(&pdev->dev, sizeof(*regset), GFP_KERNEL);
if (!regset)
return;
regset->regs = bcm2835_thermal_regs;
regset->nregs = ARRAY_SIZE(bcm2835_thermal_regs);
regset->base = data->regs;
debugfs_create_regset32("regset", 0444, data->debugfsdir, regset);
}
static const struct thermal_zone_device_ops bcm2835_thermal_ops = {
.get_temp = bcm2835_thermal_get_temp,
};
/*
* Note: as per Raspberry Foundation FAQ
* (https://www.raspberrypi.org/help/faqs/#performanceOperatingTemperature)
* the recommended temperature range for the SoC -40C to +85C
* so the trip limit is set to 80C.
* this applies to all the BCM283X SoC
*/
static const struct of_device_id bcm2835_thermal_of_match_table[] = {
{
.compatible = "brcm,bcm2835-thermal",
},
{
.compatible = "brcm,bcm2836-thermal",
},
{
.compatible = "brcm,bcm2837-thermal",
},
{},
Annotation
- Immediate include surface: `linux/clk.h`, `linux/debugfs.h`, `linux/device.h`, `linux/err.h`, `linux/io.h`, `linux/kernel.h`, `linux/minmax.h`, `linux/module.h`.
- Detected declarations: `struct bcm2835_thermal_data`, `function bcm2835_thermal_adc2temp`, `function bcm2835_thermal_temp2adc`, `function bcm2835_thermal_get_temp`, `function bcm2835_thermal_debugfs`, `function bcm2835_thermal_probe`, `function bcm2835_thermal_remove`.
- 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.