drivers/hwmon/gigabyte_waterforce.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/gigabyte_waterforce.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/gigabyte_waterforce.c- Extension
.c- Size
- 10815 bytes
- Lines
- 431
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/debugfs.hlinux/hid.hlinux/hwmon.hlinux/jiffies.hlinux/module.hlinux/spinlock.hlinux/unaligned.h
Detected Declarations
struct waterforce_datafunction waterforce_is_visiblefunction waterforce_write_expandedfunction waterforce_get_statusfunction waterforce_readfunction waterforce_read_stringfunction waterforce_get_fw_verfunction waterforce_raw_eventfunction firmware_version_showfunction waterforce_debugfs_initfunction waterforce_probefunction waterforce_removefunction waterforce_initfunction waterforce_exit
Annotated Snippet
struct waterforce_data {
struct hid_device *hdev;
struct device *hwmon_dev;
struct dentry *debugfs;
/* For locking access to buffer */
struct mutex buffer_lock;
/* For queueing multiple readers */
struct mutex status_report_request_mutex;
/* For reinitializing the completion below */
spinlock_t status_report_request_lock;
struct completion status_report_received;
struct completion fw_version_processed;
/* Sensor data */
s32 temp_input[1];
u16 speed_input[2]; /* Fan and pump speed in RPM */
u8 duty_input[2]; /* Fan and pump duty in 0-100% */
u8 *buffer;
int firmware_version;
unsigned long updated; /* jiffies */
};
static umode_t waterforce_is_visible(const void *data,
enum hwmon_sensor_types type, u32 attr, int channel)
{
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_label:
case hwmon_temp_input:
return 0444;
default:
break;
}
break;
case hwmon_fan:
switch (attr) {
case hwmon_fan_label:
case hwmon_fan_input:
return 0444;
default:
break;
}
break;
case hwmon_pwm:
switch (attr) {
case hwmon_pwm_input:
return 0444;
default:
break;
}
break;
default:
break;
}
return 0;
}
/* Writes the command to the device with the rest of the report filled with zeroes */
static int waterforce_write_expanded(struct waterforce_data *priv, const u8 *cmd, int cmd_length)
{
int ret;
mutex_lock(&priv->buffer_lock);
memcpy_and_pad(priv->buffer, MAX_REPORT_LENGTH, cmd, cmd_length, 0x00);
ret = hid_hw_output_report(priv->hdev, priv->buffer, MAX_REPORT_LENGTH);
mutex_unlock(&priv->buffer_lock);
return ret;
}
static int waterforce_get_status(struct waterforce_data *priv)
{
int ret = mutex_lock_interruptible(&priv->status_report_request_mutex);
if (ret < 0)
return ret;
if (!time_after(jiffies, priv->updated + msecs_to_jiffies(STATUS_VALIDITY))) {
/* Data is up to date */
goto unlock_and_return;
}
/*
* Disable raw event parsing for a moment to safely reinitialize the
* completion. Reinit is done because hidraw could have triggered
* the raw event parsing and marked the priv->status_report_received
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/hid.h`, `linux/hwmon.h`, `linux/jiffies.h`, `linux/module.h`, `linux/spinlock.h`, `linux/unaligned.h`.
- Detected declarations: `struct waterforce_data`, `function waterforce_is_visible`, `function waterforce_write_expanded`, `function waterforce_get_status`, `function waterforce_read`, `function waterforce_read_string`, `function waterforce_get_fw_ver`, `function waterforce_raw_event`, `function firmware_version_show`, `function waterforce_debugfs_init`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.