drivers/hwmon/sl28cpld-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/sl28cpld-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/sl28cpld-hwmon.c- Extension
.c- Size
- 2976 bytes
- Lines
- 126
- 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/hwmon.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regmap.h
Detected Declarations
struct sl28cpld_hwmonfunction sl28cpld_hwmon_readfunction sl28cpld_hwmon_probe
Annotated Snippet
struct sl28cpld_hwmon {
struct regmap *regmap;
u32 offset;
};
static int sl28cpld_hwmon_read(struct device *dev,
enum hwmon_sensor_types type, u32 attr,
int channel, long *input)
{
struct sl28cpld_hwmon *hwmon = dev_get_drvdata(dev);
unsigned int value;
int ret;
switch (attr) {
case hwmon_fan_input:
ret = regmap_read(hwmon->regmap, hwmon->offset + FAN_INPUT,
&value);
if (ret)
return ret;
/*
* The register has a 7 bit value and 1 bit which indicates the
* scale. If the MSB is set, then the lower 7 bit has to be
* multiplied by 8, to get the correct reading.
*/
if (value & FAN_SCALE_X8)
value = FIELD_GET(FAN_VALUE_MASK, value) << 3;
/*
* The counter period is 1000ms and the sysfs specification
* says we should assume 2 pulses per revolution.
*/
value *= 60 / 2;
break;
default:
return -EOPNOTSUPP;
}
*input = value;
return 0;
}
static const struct hwmon_channel_info * const sl28cpld_hwmon_info[] = {
HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
NULL
};
static const struct hwmon_ops sl28cpld_hwmon_ops = {
.visible = 0444,
.read = sl28cpld_hwmon_read,
};
static const struct hwmon_chip_info sl28cpld_hwmon_chip_info = {
.ops = &sl28cpld_hwmon_ops,
.info = sl28cpld_hwmon_info,
};
static int sl28cpld_hwmon_probe(struct platform_device *pdev)
{
struct sl28cpld_hwmon *hwmon;
struct device *hwmon_dev;
int ret;
if (!pdev->dev.parent)
return -ENODEV;
hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
if (!hwmon)
return -ENOMEM;
hwmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!hwmon->regmap)
return -ENODEV;
ret = device_property_read_u32(&pdev->dev, "reg", &hwmon->offset);
if (ret)
return -EINVAL;
hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
"sl28cpld_hwmon", hwmon,
&sl28cpld_hwmon_chip_info, NULL);
if (IS_ERR(hwmon_dev))
dev_err(&pdev->dev, "failed to register as hwmon device");
return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct of_device_id sl28cpld_hwmon_of_match[] = {
{ .compatible = "kontron,sl28cpld-fan" },
{}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/hwmon.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct sl28cpld_hwmon`, `function sl28cpld_hwmon_read`, `function sl28cpld_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.