From patchwork Mon Jan 27 04:03:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13950966 Received: from mail-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3262C1FC7E4; Mon, 27 Jan 2025 04:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737950669; cv=none; b=gSWx24/d60RGGVZMkt2eNs72HLGtc/eDm8PuOmLmt3dqE1IOHFkHBkILFEABszBl7ca+FeZYpDx+Mw1iizplKBf6CWrUMt23TNRYIEoBbaCX9L+lwR3WW04icNzAVwHryaQX72BHxO8PbrMsBke07WsedMAQWH+ui4v5KC1yQvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737950669; c=relaxed/simple; bh=ZIzW+htGWGosViRTAiyRFL5GGFpNgaomx5pjZPEFkg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AK9+T7OxntWwZjTNo/f3h4/g6DA7XJ8FNc4EABh89r93WCBebSh0T3R0+T33eGfJVwB1DhMDBHyqv85XB00iZIkE05WExvSYliW1j1TjSm/GWu5FJjGwr4k76wfUNb42gkPiEPcZ1TIS6PprHS4b+W11k6bKLL01T/4GOElr3p4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jEWddxsY; arc=none smtp.client-ip=209.85.217.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jEWddxsY" Received: by mail-vs1-f54.google.com with SMTP id ada2fe7eead31-4b24bc0cc65so2497022137.2; Sun, 26 Jan 2025 20:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737950665; x=1738555465; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9H0HNusswph+vw18OEfCZzKqgd39+ujZYdZ5oQgL4ls=; b=jEWddxsYwS+Kz7N0EPyZd7oGdzzv2AXiE3HEPfZ3YbzI/o6e7RBhr3D39rAFv4Q/VX /7x6jGLQ8v3WrVqBqoIfNtHENsYZsyKi+2A1R3W0Q0D2DeKnST9zzUTvo07F3F9Enhsj EVC4yPIms2Y5wOK3ROfXoKN4AnsiZDf1mmYOeahPmJqfdKqTAh9qJBmftAmvPIUCJXlJ 35JwhAqGGHr/MQvW0fIzvBoBI7KdNw7ohY2LpVJqZ6ZUXN2ORJTGjWIpb93ChgGEh5OC Y2AtROST5sJnHY06rTWXhXxxhkPp/9kbIES/94BYGcLA9Ivv9nEqreHccsscvAMxuBkS FXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737950665; x=1738555465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9H0HNusswph+vw18OEfCZzKqgd39+ujZYdZ5oQgL4ls=; b=e4TWnM75l+v1xCD6A2ns0bbMNS0Xf0bgIFeUCv6B8ykABcjA1pMzPaoWDQnM1A3GgS kyFnH71xAGWwMq9ozc3gt3khaagcVaYzkR8cRXdnvC18pJVMGDFu3wxYMfrkZ+L/6bX7 SYToMlCJCjEApn4Oyax3QV74jpLK5AYeWcrrbln6LKhe2egz1b2vw8/d95qLAGFTFY78 G3mlh/FPcSBuxpI4cKzb2n5eT0LHuYY+KIdercGQowNKIKAzWT+T1tP8y/6tFE9nmagE ahLRWQa8O0PZacyb7UOK6dO3L4Hy9cMBPBb61LXYKkPKt4kTcCnnYAnW7kNwJ0HvZI3m xUoA== X-Forwarded-Encrypted: i=1; AJvYcCUTsyxH0tnUA6BJP+g6jcRl75j5uXZ40mI5hv9pXwOe/2dMJhKUssdOx18q+Ku8VnYoBloXHVaThIW5q/w=@vger.kernel.org X-Gm-Message-State: AOJu0YzreqbB+kl/yCGPLv4XLW7PmyFb2RS+bGkjvToT+boOtkwLiEtN a7nox3LZU1c6XSAVnHVBehrfQ8x0L8Cnj4Zq6dp9FmK+zDdB4Kd9d2iM/g== X-Gm-Gg: ASbGnct16gY6vaPVF5ESHJzhZBv/JYxCqJeCihUWG8/dhx3CQruKXZO0j9sZmslyrUB HJ/57KToLEpZwLBRkWG3GVHxLEN8ic2kiIOyTfcy7WI87q5eqAd/d2qU0YLQO6jM46lFwz+xPZ1 yGVcXa9IvFXMu8S47i5aJMljrp1or8kKdA3iV+34JRBMJJMPzB8otpf8HWvOa/bQGpT0yzx52vJ zp2vl+amnGkZhrSJ2Gf5mjZj8w+kSLL0va/ivJqc4Ed448CK17OnLbyHfitVdmKErtwRf0YmiWZ NyAc2tD8guKldf0qOSmwjlM= X-Google-Smtp-Source: AGHT+IGvT6vgPRy+XQ0ulw9Q4RY4jLRoADNqlLxIpS+D3EqAGowd6d7MBUxjpHLCJHXbuDSn0gXaLQ== X-Received: by 2002:a05:6102:c04:b0:4b6:d108:cac0 with SMTP id ada2fe7eead31-4b6d108ce5dmr26549009137.3.1737950665529; Sun, 26 Jan 2025 20:04:25 -0800 (PST) Received: from localhost.localdomain ([2800:bf0:82:1159:c837:3446:190b:188d]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-864a9c176f0sm1733758241.23.2025.01.26.20.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2025 20:04:24 -0800 (PST) From: Kurt Borja To: platform-driver-x86@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "Armin Wolf" , "Mario Limonciello" , "Hans de Goede" , Dell.Client.Kernel@dell.com, linux-kernel@vger.kernel.org, "Kurt Borja" Subject: [PATCH v6 04/14] platform/x86: alienware-wmi: Refactor LED control methods Date: Sun, 26 Jan 2025 23:03:56 -0500 Message-ID: <20250127040406.17112-5-kuurtb@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127040406.17112-1-kuurtb@gmail.com> References: <20250127040406.17112-1-kuurtb@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both WMI devices handled by this module specify a distinct interface for LED control. Previously this module handled this by dynamically adapting arguments passed to wmi_evaluate_method() based on the `interface` global variable. To avoid the use of global variables, and enable the migration to non-deprecated WMI methods, let the WMI drivers define upd_led and upd_brightness operations, which completely replace alienware_update_led() and wmax_brightness(). Also define alienware_wmi_command(), which serves as a wrapper for wmidev_evaluate_method(). This new method is very similar to alienware_wmax_command() but is WMI device agnostic. Reviewed-by: Armin Wolf Signed-off-by: Kurt Borja --- drivers/platform/x86/dell/alienware-wmi.c | 166 ++++++++++++++-------- 1 file changed, 104 insertions(+), 62 deletions(-) diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index b681b86e3894..a5f590da139e 100644 --- a/drivers/platform/x86/dell/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -426,12 +427,43 @@ struct alienfx_priv { u8 lighting_control_state; }; +struct alienfx_ops { + int (*upd_led)(struct alienfx_priv *priv, struct wmi_device *wdev, + u8 location); + int (*upd_brightness)(struct alienfx_priv *priv, struct wmi_device *wdev, + u8 brightness); +}; + struct alienfx_platdata { struct wmi_device *wdev; + struct alienfx_ops ops; }; static u8 interface; +static int alienware_wmi_command(struct wmi_device *wdev, u32 method_id, + void *in_args, size_t in_size, u32 *out_data) +{ + struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; + struct acpi_buffer in = {in_size, in_args}; + acpi_status ret; + + ret = wmidev_evaluate_method(wdev, 0, method_id, &in, out_data ? &out : NULL); + if (ACPI_FAILURE(ret)) + return -EIO; + + union acpi_object *obj __free(kfree) = out.pointer; + + if (out_data) { + if (obj && obj->type == ACPI_TYPE_INTEGER) + *out_data = (u32)obj->integer.value; + else + return -ENOMSG; + } + + return 0; +} + /* * Helpers used for zone control */ @@ -462,46 +494,6 @@ static int parse_rgb(const char *buf, struct color_platform *colors) /* * Individual RGB zone control */ -static int alienware_update_led(struct alienfx_priv *priv, u8 location) -{ - int method_id; - acpi_status status; - char *guid; - struct acpi_buffer input; - struct legacy_led_args legacy_args; - struct wmax_led_args wmax_basic_args; - if (interface == WMAX) { - wmax_basic_args.led_mask = 1 << location; - wmax_basic_args.colors = priv->colors[location]; - wmax_basic_args.state = priv->lighting_control_state; - guid = WMAX_CONTROL_GUID; - method_id = WMAX_METHOD_ZONE_CONTROL; - - input.length = sizeof(wmax_basic_args); - input.pointer = &wmax_basic_args; - } else { - legacy_args.colors = priv->colors[location]; - legacy_args.brightness = priv->global_brightness; - legacy_args.state = 0; - if (priv->lighting_control_state == LEGACY_BOOTING || - priv->lighting_control_state == LEGACY_SUSPEND) { - guid = LEGACY_POWER_CONTROL_GUID; - legacy_args.state = priv->lighting_control_state; - } else - guid = LEGACY_CONTROL_GUID; - method_id = location + 1; - - input.length = sizeof(legacy_args); - input.pointer = &legacy_args; - } - pr_debug("alienware-wmi: guid %s method %d\n", guid, method_id); - - status = wmi_evaluate_method(guid, 0, method_id, &input, NULL); - if (ACPI_FAILURE(status)) - pr_err("alienware-wmi: zone set failure: %u\n", status); - return ACPI_FAILURE(status); -} - static ssize_t zone_show(struct device *dev, struct device_attribute *attr, char *buf, u8 location) { @@ -518,13 +510,14 @@ static ssize_t zone_store(struct device *dev, struct device_attribute *attr, { struct alienfx_priv *priv = dev_get_drvdata(dev); struct color_platform *colors = &priv->colors[location]; + struct alienfx_platdata *pdata = dev_get_platdata(dev); int ret; ret = parse_rgb(buf, colors); if (ret) return ret; - ret = alienware_update_led(priv, location); + ret = pdata->ops.upd_led(priv, pdata->wdev, location); return ret ? ret : count; } @@ -660,36 +653,17 @@ static struct attribute_group zone_attribute_group = { /* * LED Brightness (Global) */ -static int wmax_brightness(int brightness) -{ - acpi_status status; - struct acpi_buffer input; - struct wmax_brightness_args args = { - .led_mask = 0xFF, - .percentage = brightness, - }; - input.length = sizeof(args); - input.pointer = &args; - status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, - WMAX_METHOD_BRIGHTNESS, &input, NULL); - if (ACPI_FAILURE(status)) - pr_err("alienware-wmi: brightness set failure: %u\n", status); - return ACPI_FAILURE(status); -} - static void global_led_set(struct led_classdev *led_cdev, enum led_brightness brightness) { struct alienfx_priv *priv = container_of(led_cdev, struct alienfx_priv, global_led); + struct alienfx_platdata *pdata = dev_get_platdata(&priv->pdev->dev); int ret; priv->global_brightness = brightness; - if (interface == WMAX) - ret = wmax_brightness(brightness); - else - ret = alienware_update_led(priv, 0); + ret = pdata->ops.upd_brightness(priv, pdata->wdev, brightness); if (ret) pr_err("LED brightness update failed\n"); } @@ -1232,10 +1206,49 @@ static void alienware_alienfx_exit(struct wmi_device *wdev) /* * Legacy WMI driver */ +static int legacy_wmi_update_led(struct alienfx_priv *priv, + struct wmi_device *wdev, u8 location) +{ + struct legacy_led_args legacy_args = { + .colors = priv->colors[location], + .brightness = priv->global_brightness, + .state = 0, + }; + struct acpi_buffer input; + acpi_status status; + + if (legacy_args.state != LEGACY_RUNNING) { + legacy_args.state = priv->lighting_control_state; + + input.length = sizeof(legacy_args); + input.pointer = &legacy_args; + + status = wmi_evaluate_method(LEGACY_POWER_CONTROL_GUID, 0, + location + 1, &input, NULL); + if (ACPI_FAILURE(status)) + return -EIO; + + return 0; + } + + return alienware_wmi_command(wdev, location + 1, &legacy_args, + sizeof(legacy_args), NULL); +} + +static int legacy_wmi_update_brightness(struct alienfx_priv *priv, + struct wmi_device *wdev, u8 brightness) +{ + return legacy_wmi_update_led(priv, wdev, 0); +} + static int legacy_wmi_probe(struct wmi_device *wdev, const void *context) { struct alienfx_platdata pdata = { .wdev = wdev, + .ops = { + .upd_led = legacy_wmi_update_led, + .upd_brightness = legacy_wmi_update_brightness, + }, }; return alienware_alienfx_setup(&pdata); @@ -1276,10 +1289,39 @@ static void __exit alienware_legacy_wmi_exit(void) /* * WMAX WMI driver */ +static int wmax_wmi_update_led(struct alienfx_priv *priv, + struct wmi_device *wdev, u8 location) +{ + struct wmax_led_args in_args = { + .led_mask = 1 << location, + .colors = priv->colors[location], + .state = priv->lighting_control_state, + }; + + return alienware_wmi_command(wdev, WMAX_METHOD_ZONE_CONTROL, &in_args, + sizeof(in_args), NULL); +} + +static int wmax_wmi_update_brightness(struct alienfx_priv *priv, + struct wmi_device *wdev, u8 brightness) +{ + struct wmax_brightness_args in_args = { + .led_mask = 0xFF, + .percentage = brightness, + }; + + return alienware_wmi_command(wdev, WMAX_METHOD_BRIGHTNESS, &in_args, + sizeof(in_args), NULL); +} + static int wmax_wmi_probe(struct wmi_device *wdev, const void *context) { struct alienfx_platdata pdata = { .wdev = wdev, + .ops = { + .upd_led = wmax_wmi_update_led, + .upd_brightness = wmax_wmi_update_brightness, + }, }; struct platform_device *pdev; int ret;