drivers/thermal/broadcom/sr-thermal.c
Source file repositories/reference/linux-study-clean/drivers/thermal/broadcom/sr-thermal.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/broadcom/sr-thermal.c- Extension
.c- Size
- 2740 bytes
- Lines
- 116
- 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/module.hlinux/of_address.hlinux/platform_device.hlinux/thermal.h
Detected Declarations
struct sr_tmonstruct sr_thermalfunction sr_get_tempfunction sr_thermal_probe
Annotated Snippet
struct sr_tmon {
unsigned int crit_temp;
unsigned int tmon_id;
struct sr_thermal *priv;
};
struct sr_thermal {
void __iomem *regs;
unsigned int max_crit_temp;
struct sr_tmon tmon[SR_TMON_MAX_LIST];
};
static int sr_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct sr_tmon *tmon = thermal_zone_device_priv(tz);
struct sr_thermal *sr_thermal = tmon->priv;
*temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
return 0;
}
static const struct thermal_zone_device_ops sr_tz_ops = {
.get_temp = sr_get_temp,
};
static int sr_thermal_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct thermal_zone_device *tz;
struct sr_thermal *sr_thermal;
struct sr_tmon *tmon;
struct resource *res;
u32 sr_tmon_list = 0;
unsigned int i;
int ret;
sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL);
if (!sr_thermal)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENOENT;
sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start,
resource_size(res),
MEMREMAP_WB);
if (IS_ERR(sr_thermal->regs)) {
dev_err(dev, "failed to get io address\n");
return PTR_ERR(sr_thermal->regs);
}
ret = device_property_read_u32(dev, "brcm,tmon-mask", &sr_tmon_list);
if (ret)
return ret;
tmon = sr_thermal->tmon;
for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) {
if (!(sr_tmon_list & BIT(i)))
continue;
/* Flush temperature registers */
writel(0, sr_thermal->regs + SR_TMON_TEMP_BASE(i));
tmon->tmon_id = i;
tmon->priv = sr_thermal;
tz = devm_thermal_of_zone_register(dev, i, tmon,
&sr_tz_ops);
if (IS_ERR(tz))
return PTR_ERR(tz);
dev_dbg(dev, "thermal sensor %d registered\n", i);
}
return 0;
}
static const struct of_device_id sr_thermal_of_match[] = {
{ .compatible = "brcm,sr-thermal", },
{},
};
MODULE_DEVICE_TABLE(of, sr_thermal_of_match);
static struct platform_driver sr_thermal_driver = {
.probe = sr_thermal_probe,
.driver = {
.name = "sr-thermal",
.of_match_table = sr_thermal_of_match,
},
};
Annotation
- Immediate include surface: `linux/module.h`, `linux/of_address.h`, `linux/platform_device.h`, `linux/thermal.h`.
- Detected declarations: `struct sr_tmon`, `struct sr_thermal`, `function sr_get_temp`, `function sr_thermal_probe`.
- 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.