drivers/hwmon/surface_fan.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/surface_fan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/surface_fan.c- Extension
.c- Size
- 1969 bytes
- Lines
- 84
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hwmon.hlinux/kernel.hlinux/module.hlinux/surface_aggregator/device.hlinux/types.h
Detected Declarations
function surface_fan_hwmon_readfunction surface_fan_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Surface Fan driver for Surface System Aggregator Module. It provides access
* to the fan's rpm through the hwmon system.
*
* Copyright (C) 2023 Ivor Wanders <ivor@iwanders.net>
*/
#include <linux/hwmon.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/surface_aggregator/device.h>
#include <linux/types.h>
// SSAM
SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, {
.target_category = SSAM_SSH_TC_FAN,
.command_id = 0x01,
});
static int surface_fan_hwmon_read(struct device *dev,
enum hwmon_sensor_types type, u32 attr,
int channel, long *val)
{
struct ssam_device *sdev = dev_get_drvdata(dev);
int ret;
__le16 value;
ret = __ssam_fan_rpm_get(sdev, &value);
if (ret)
return ret;
*val = le16_to_cpu(value);
return 0;
}
static const struct hwmon_channel_info *const surface_fan_info[] = {
HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
NULL
};
static const struct hwmon_ops surface_fan_hwmon_ops = {
.visible = 0444,
.read = surface_fan_hwmon_read,
};
static const struct hwmon_chip_info surface_fan_chip_info = {
.ops = &surface_fan_hwmon_ops,
.info = surface_fan_info,
};
static int surface_fan_probe(struct ssam_device *sdev)
{
struct device *hdev;
hdev = devm_hwmon_device_register_with_info(&sdev->dev,
"surface_fan", sdev,
&surface_fan_chip_info,
NULL);
return PTR_ERR_OR_ZERO(hdev);
}
static const struct ssam_device_id ssam_fan_match[] = {
{ SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
{},
};
MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
static struct ssam_device_driver surface_fan = {
.probe = surface_fan_probe,
.match_table = ssam_fan_match,
.driver = {
.name = "surface_fan",
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
},
};
module_ssam_device_driver(surface_fan);
MODULE_AUTHOR("Ivor Wanders <ivor@iwanders.net>");
MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/hwmon.h`, `linux/kernel.h`, `linux/module.h`, `linux/surface_aggregator/device.h`, `linux/types.h`.
- Detected declarations: `function surface_fan_hwmon_read`, `function surface_fan_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.