drivers/hwmon/as370-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/as370-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/as370-hwmon.c- Extension
.c- Size
- 2950 bytes
- Lines
- 137
- 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/bitops.hlinux/hwmon.hlinux/init.hlinux/io.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.h
Detected Declarations
struct as370_hwmonfunction init_pvtfunction as370_hwmon_readfunction as370_hwmon_is_visiblefunction as370_hwmon_probe
Annotated Snippet
struct as370_hwmon {
void __iomem *base;
};
static void init_pvt(struct as370_hwmon *hwmon)
{
u32 val;
void __iomem *addr = hwmon->base + CTRL;
val = PD;
writel_relaxed(val, addr);
val |= T_SEL;
writel_relaxed(val, addr);
val |= EN;
writel_relaxed(val, addr);
val &= ~PD;
writel_relaxed(val, addr);
}
static int as370_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *temp)
{
int val;
struct as370_hwmon *hwmon = dev_get_drvdata(dev);
switch (attr) {
case hwmon_temp_input:
val = readl_relaxed(hwmon->base + STS) & BN_MASK;
*temp = DIV_ROUND_CLOSEST(val * 251802, 4096) - 85525;
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static umode_t
as370_hwmon_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 as370_hwmon_info[] = {
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
NULL
};
static const struct hwmon_ops as370_hwmon_ops = {
.is_visible = as370_hwmon_is_visible,
.read = as370_hwmon_read,
};
static const struct hwmon_chip_info as370_chip_info = {
.ops = &as370_hwmon_ops,
.info = as370_hwmon_info,
};
static int as370_hwmon_probe(struct platform_device *pdev)
{
struct device *hwmon_dev;
struct as370_hwmon *hwmon;
struct device *dev = &pdev->dev;
hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL);
if (!hwmon)
return -ENOMEM;
hwmon->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(hwmon->base))
return PTR_ERR(hwmon->base);
init_pvt(hwmon);
hwmon_dev = devm_hwmon_device_register_with_info(dev,
"as370",
hwmon,
&as370_chip_info,
NULL);
return PTR_ERR_OR_ZERO(hwmon_dev);
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/hwmon.h`, `linux/init.h`, `linux/io.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`.
- Detected declarations: `struct as370_hwmon`, `function init_pvt`, `function as370_hwmon_read`, `function as370_hwmon_is_visible`, `function as370_hwmon_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.