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.

Dependency Surface

Detected Declarations

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

Implementation Notes