drivers/hwmon/sparx5-temp.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/sparx5-temp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/sparx5-temp.c- Extension
.c- Size
- 3394 bytes
- Lines
- 152
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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/bitfield.hlinux/clk.hlinux/hwmon.hlinux/init.hlinux/io.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct s5_hwmonfunction s5_temp_enablefunction s5_readfunction s5_is_visiblefunction s5_temp_probe
Annotated Snippet
struct s5_hwmon {
void __iomem *base;
struct clk *clk;
};
static void s5_temp_enable(struct s5_hwmon *hwmon)
{
u32 val = readl(hwmon->base + TEMP_CFG);
u32 clk = clk_get_rate(hwmon->clk) / USEC_PER_SEC;
val &= ~TEMP_CFG_CYCLES;
val |= FIELD_PREP(TEMP_CFG_CYCLES, clk);
val |= TEMP_CFG_ENA;
writel(val, hwmon->base + TEMP_CFG);
}
static int s5_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *temp)
{
struct s5_hwmon *hwmon = dev_get_drvdata(dev);
int rc = 0, value;
u32 stat;
switch (attr) {
case hwmon_temp_input:
stat = readl_relaxed(hwmon->base + TEMP_STAT);
if (!(stat & TEMP_STAT_VALID))
return -EAGAIN;
value = stat & TEMP_STAT_TEMP;
/*
* From register documentation:
* Temp(C) = TEMP_SENSOR_STAT.TEMP / 4096 * 352.2 - 109.4
*/
value = DIV_ROUND_CLOSEST(value * 3522, 4096) - 1094;
/*
* Scale down by 10 from above and multiply by 1000 to
* have millidegrees as specified by the hwmon sysfs
* interface.
*/
value *= 100;
*temp = value;
break;
default:
rc = -EOPNOTSUPP;
break;
}
return rc;
}
static umode_t s5_is_visible(const void *_data, enum hwmon_sensor_types type,
u32 attr, int channel)
{
if (type != hwmon_temp)
return 0;
switch (attr) {
case hwmon_temp_input:
return 0444;
default:
return 0;
}
}
static const struct hwmon_channel_info * const s5_info[] = {
HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
NULL
};
static const struct hwmon_ops s5_hwmon_ops = {
.is_visible = s5_is_visible,
.read = s5_read,
};
static const struct hwmon_chip_info s5_chip_info = {
.ops = &s5_hwmon_ops,
.info = s5_info,
};
static int s5_temp_probe(struct platform_device *pdev)
{
struct device *hwmon_dev;
struct s5_hwmon *hwmon;
hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
if (!hwmon)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/hwmon.h`, `linux/init.h`, `linux/io.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct s5_hwmon`, `function s5_temp_enable`, `function s5_read`, `function s5_is_visible`, `function s5_temp_probe`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.