drivers/platform/x86/lenovo/wmi-other.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/lenovo/wmi-other.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/lenovo/wmi-other.c- Extension
.c- Size
- 34719 bytes
- Lines
- 1136
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/acpi.hlinux/bitfield.hlinux/cleanup.hlinux/component.hlinux/container_of.hlinux/device.hlinux/export.hlinux/gfp_types.hlinux/hwmon.hlinux/idr.hlinux/kdev_t.hlinux/kobject.hlinux/limits.hlinux/module.hlinux/platform_profile.hlinux/types.hlinux/wmi.hwmi-capdata.hwmi-events.hwmi-helpers.h../firmware_attributes_class.h
Detected Declarations
struct lwmi_fan_infostruct lwmi_om_privstruct tunable_attr_01struct capdata01_attr_groupenum attribute_propertyfunction lwmi_om_fan_get_setfunction lwmi_om_hwmon_is_visiblefunction lwmi_om_hwmon_readfunction lwmi_om_hwmon_writefunction lwmi_om_hwmon_addfunction lwmi_om_hwmon_removefunction lwmi_om_fan_info_initfunction lwmi_om_fan_info_collect_cd00function lwmi_om_fan_info_collect_cd_fanfunction tunable_attr_01_idfunction int_type_showfunction attr_capdata01_showfunction attr_current_value_storefunction attr_current_value_showfunction lwmi_attr_01_is_supportedfunction lwmi_om_fw_attr_addfunction lwmi_om_fw_attr_removefunction lwmi_om_master_bindfunction lwmi_om_master_unbindfunction lwmi_other_probefunction lwmi_other_remove
Annotated Snippet
struct lwmi_fan_info {
u32 supported;
u32 last_target;
long min_rpm;
long max_rpm;
};
struct lwmi_om_priv {
struct component_master_ops *ops;
/* only valid after capdata bind */
struct cd_list *cd00_list;
struct cd_list *cd01_list;
struct device *hwmon_dev;
struct device *fw_attr_dev;
struct kset *fw_attr_kset;
struct wmi_device *wdev;
int ida_id;
struct lwmi_fan_info fan_info[LWMI_FAN_NR];
struct {
bool capdata00_collected : 1;
bool capdata_fan_collected : 1;
} fan_flags;
};
/*
* Visibility of fan channels:
*
* +-------------------+---------+------------------+-----------------------+------------+
* | | default | +expose_all_fans | +relax_fan_constraint | +both |
* +-------------------+---------+------------------+-----------------------+------------+
* | canonical | RW | RW | RW+relaxed | RW+relaxed |
* +-------------------+---------+------------------+-----------------------+------------+
* | -capdata_fan[idx] | N | RO | N | RW+relaxed |
* +-------------------+---------+------------------+-----------------------+------------+
*
* Note:
* 1. LWMI_ATTR_ID_FAN_RPM[idx].supported is always checked before exposing a channel.
* 2. -capdata_fan implies -capdata_fan[idx].
*/
static bool expose_all_fans;
module_param(expose_all_fans, bool, 0444);
MODULE_PARM_DESC(expose_all_fans,
"This option skips some capability checks and solely relies on per-channel ones "
"to expose fan attributes. Use with caution.");
static bool relax_fan_constraint;
module_param(relax_fan_constraint, bool, 0444);
MODULE_PARM_DESC(relax_fan_constraint,
"Do not enforce fan RPM constraint (div/min/max) "
"and enables fan tuning when such data is missing. "
"Enabling this may results in HWMON attributes being out-of-sync, "
"and setting a too low RPM stops the fan. Use with caution.");
/* ======== HWMON (component: lenovo-wmi-capdata 00 & fan) ======== */
/**
* lwmi_om_fan_get_set() - Get or set fan RPM value of specified fan
* @priv: Driver private data structure
* @channel: Fan channel index (0-based)
* @val: Pointer to value (input for set, output for get)
* @set: True to set value, false to get value
*
* Communicates with WMI interface to either retrieve current fan RPM
* or set target fan RPM.
*
* Return: 0 on success, or an error code.
*/
static int lwmi_om_fan_get_set(struct lwmi_om_priv *priv, int channel, u32 *val, bool set)
{
struct wmi_method_args_32 args = {};
u32 method_id, retval;
int err;
method_id = set ? LWMI_FEATURE_VALUE_SET : LWMI_FEATURE_VALUE_GET;
args.arg0 = LWMI_ATTR_ID_FAN_RPM(channel);
args.arg1 = set ? *val : 0;
err = lwmi_dev_evaluate_int(priv->wdev, 0x0, method_id,
(unsigned char *)&args, sizeof(args), &retval);
if (err)
return err;
if (!set) {
*val = retval;
return 0;
}
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/bitfield.h`, `linux/cleanup.h`, `linux/component.h`, `linux/container_of.h`, `linux/device.h`, `linux/export.h`, `linux/gfp_types.h`.
- Detected declarations: `struct lwmi_fan_info`, `struct lwmi_om_priv`, `struct tunable_attr_01`, `struct capdata01_attr_group`, `enum attribute_property`, `function lwmi_om_fan_get_set`, `function lwmi_om_hwmon_is_visible`, `function lwmi_om_hwmon_read`, `function lwmi_om_hwmon_write`, `function lwmi_om_hwmon_add`.
- Atlas domain: Driver Families / drivers/platform.
- 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.