drivers/hwmon/qnap-mcu-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/qnap-mcu-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/qnap-mcu-hwmon.c- Extension
.c- Size
- 8402 bytes
- Lines
- 364
- 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/hwmon.hlinux/mfd/qnap-mcu.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/thermal.h
Detected Declarations
struct qnap_mcu_hwmonfunction qnap_mcu_hwmon_get_rpmfunction qnap_mcu_hwmon_get_pwmfunction qnap_mcu_hwmon_set_pwmfunction qnap_mcu_hwmon_get_tempfunction qnap_mcu_hwmon_writefunction qnap_mcu_hwmon_readfunction qnap_mcu_hwmon_is_visiblefunction qnap_mcu_hwmon_get_max_statefunction qnap_mcu_hwmon_get_cur_statefunction qnap_mcu_hwmon_set_cur_statefunction devm_fan_node_releasefunction qnap_mcu_hwmon_get_cooling_datafunction qnap_mcu_hwmon_probefunction qnap_mcu_hwmon_get_cooling_data
Annotated Snippet
struct qnap_mcu_hwmon {
struct qnap_mcu *mcu;
struct device *dev;
unsigned int pwm_min;
unsigned int pwm_max;
struct fwnode_handle *fan_node;
unsigned int fan_state;
unsigned int fan_max_state;
unsigned int *fan_cooling_levels;
struct thermal_cooling_device *cdev;
struct hwmon_chip_info info;
};
static int qnap_mcu_hwmon_get_rpm(struct qnap_mcu_hwmon *hwm)
{
static const u8 cmd[] = { '@', 'F', 'A' };
u8 reply[6];
int ret;
/* poll the fan rpm */
ret = qnap_mcu_exec(hwm->mcu, cmd, sizeof(cmd), reply, sizeof(reply));
if (ret)
return ret;
/* First 2 bytes must mirror the sent command */
if (memcmp(cmd, reply, 2))
return -EIO;
return reply[4] * 30;
}
static int qnap_mcu_hwmon_get_pwm(struct qnap_mcu_hwmon *hwm)
{
static const u8 cmd[] = { '@', 'F', 'Z', '0' }; /* 0 = fan-id? */
u8 reply[4];
int ret;
/* poll the fan pwm */
ret = qnap_mcu_exec(hwm->mcu, cmd, sizeof(cmd), reply, sizeof(reply));
if (ret)
return ret;
/* First 3 bytes must mirror the sent command */
if (memcmp(cmd, reply, 3))
return -EIO;
return reply[3];
}
static int qnap_mcu_hwmon_set_pwm(struct qnap_mcu_hwmon *hwm, u8 pwm)
{
const u8 cmd[] = { '@', 'F', 'W', '0', pwm }; /* 0 = fan-id?, pwm 0-255 */
/* set the fan pwm */
return qnap_mcu_exec_with_ack(hwm->mcu, cmd, sizeof(cmd));
}
static int qnap_mcu_hwmon_get_temp(struct qnap_mcu_hwmon *hwm)
{
static const u8 cmd[] = { '@', 'T', '3' };
u8 reply[4];
int ret;
/* poll the fan rpm */
ret = qnap_mcu_exec(hwm->mcu, cmd, sizeof(cmd), reply, sizeof(reply));
if (ret)
return ret;
/* First bytes must mirror the sent command */
if (memcmp(cmd, reply, sizeof(cmd)))
return -EIO;
/*
* There is an unknown bit set in bit7.
* Bits [6:0] report the actual temperature as returned by the
* original qnap firmware-tools, so just drop bit7 for now.
*/
return (reply[3] & 0x7f) * 1000;
}
static int qnap_mcu_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
struct qnap_mcu_hwmon *hwm = dev_get_drvdata(dev);
switch (attr) {
case hwmon_pwm_input:
Annotation
- Immediate include surface: `linux/hwmon.h`, `linux/mfd/qnap-mcu.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`, `linux/thermal.h`.
- Detected declarations: `struct qnap_mcu_hwmon`, `function qnap_mcu_hwmon_get_rpm`, `function qnap_mcu_hwmon_get_pwm`, `function qnap_mcu_hwmon_set_pwm`, `function qnap_mcu_hwmon_get_temp`, `function qnap_mcu_hwmon_write`, `function qnap_mcu_hwmon_read`, `function qnap_mcu_hwmon_is_visible`, `function qnap_mcu_hwmon_get_max_state`, `function qnap_mcu_hwmon_get_cur_state`.
- 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.