drivers/hwmon/nzxt-kraken2.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/nzxt-kraken2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/nzxt-kraken2.c- Extension
.c- Size
- 5390 bytes
- Lines
- 228
- 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/unaligned.hlinux/hid.hlinux/hwmon.hlinux/jiffies.hlinux/module.h
Detected Declarations
struct kraken2_priv_datafunction kraken2_readfunction kraken2_read_stringfunction kraken2_raw_eventfunction kraken2_probefunction kraken2_removefunction kraken2_initfunction kraken2_exit
Annotated Snippet
struct kraken2_priv_data {
struct hid_device *hid_dev;
struct device *hwmon_dev;
s32 temp_input[1];
u16 fan_input[2];
unsigned long updated; /* jiffies */
};
static int kraken2_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct kraken2_priv_data *priv = dev_get_drvdata(dev);
if (time_after(jiffies, priv->updated + STATUS_VALIDITY * HZ))
return -ENODATA;
switch (type) {
case hwmon_temp:
*val = priv->temp_input[channel];
break;
case hwmon_fan:
*val = priv->fan_input[channel];
break;
default:
return -EOPNOTSUPP; /* unreachable */
}
return 0;
}
static int kraken2_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
{
switch (type) {
case hwmon_temp:
*str = kraken2_temp_label[channel];
break;
case hwmon_fan:
*str = kraken2_fan_label[channel];
break;
default:
return -EOPNOTSUPP; /* unreachable */
}
return 0;
}
static const struct hwmon_ops kraken2_hwmon_ops = {
.visible = 0444,
.read = kraken2_read,
.read_string = kraken2_read_string,
};
static const struct hwmon_channel_info * const kraken2_info[] = {
HWMON_CHANNEL_INFO(temp,
HWMON_T_INPUT | HWMON_T_LABEL),
HWMON_CHANNEL_INFO(fan,
HWMON_F_INPUT | HWMON_F_LABEL,
HWMON_F_INPUT | HWMON_F_LABEL),
NULL
};
static const struct hwmon_chip_info kraken2_chip_info = {
.ops = &kraken2_hwmon_ops,
.info = kraken2_info,
};
static int kraken2_raw_event(struct hid_device *hdev,
struct hid_report *report, u8 *data, int size)
{
struct kraken2_priv_data *priv;
if (size < 7 || report->id != STATUS_REPORT_ID)
return 0;
priv = hid_get_drvdata(hdev);
/*
* The fractional byte of the coolant temperature has been observed to
* be in the interval [1,9], but some of these steps are also
* consistently skipped for certain integer parts.
*
* For the lack of a better idea, assume that the resolution is 0.1°C,
* and that the missing steps are artifacts of how the firmware
* processes the raw sensor data.
*/
priv->temp_input[0] = data[1] * 1000 + data[2] * 100;
priv->fan_input[0] = get_unaligned_be16(data + 3);
priv->fan_input[1] = get_unaligned_be16(data + 5);
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/hid.h`, `linux/hwmon.h`, `linux/jiffies.h`, `linux/module.h`.
- Detected declarations: `struct kraken2_priv_data`, `function kraken2_read`, `function kraken2_read_string`, `function kraken2_raw_event`, `function kraken2_probe`, `function kraken2_remove`, `function kraken2_init`, `function kraken2_exit`.
- 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.