From patchwork Sun Jan 19 22:05:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13944601 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 42C151E048F; Sun, 19 Jan 2025 22:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737324367; cv=none; b=QZmrNBf6qJMIcE9LFLZBtwM90A/Z+m+8FgtJlq9NvlJ7F30Mc1KisCxASxjY2jJ9Z33GtDMrJnZ8U427pEeonDTkl8lj8qyxISF+prqjlJKMvmJvaZkaYGHvfB/YYBEqysMqalYZW7uZKOdCxMMjjm2Z+73Dysu8JAKQjxmls/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737324367; c=relaxed/simple; bh=2Dkl+z6nmWOjdLpHQU29b41UY3p127bQSzYEhN6JzHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qhm2gF0b4N+EPP4uagz1LCsg4PZdbc1kR7iSYUQDF/4lhu4CN7aN2ZsPyrrXxnrrQtGEDzL2xIzsA07gD93tGNpZ9em1YLtQpFMbtYWQ0A/ZypPVpphBG+t1fUaQBu5argiT2tYYCJFho5t1Wp5OBZU1CTSFMRXDEUW+hDbXE/w= 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=NvQ1AvJ/; arc=none smtp.client-ip=209.85.222.174 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="NvQ1AvJ/" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b6f1be1daeso380398485a.0; Sun, 19 Jan 2025 14:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737324364; x=1737929164; 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=AyvDbG7b41brEYVGfP1u1SKwu5vc8yhuPpSJa7ZhQcc=; b=NvQ1AvJ/wwPJ0irLVtyysyf+kBYR+LAkI/9IqfDb5jURJ4jg0pbKL6SV3KGkjWbR2s uXskHlXdyBOLpwuzvgQUnVkyKcHXkOjDTxdXeD+81qH556rOVGDD88Lt35I5rLL+GnAk F8Fu5Jk1fa6zPhO6M7/fXGrYm0W7Ew68+8IdA4ToSltft7rhPCKmTlyc6mpx0HJ94a8U vvnBSmzaemo+n0flNP8mBVzcs8IXykmASPRyIojqL4rinHymd+DkamCMWIp2AbsaAm59 AgzUULXNKI+grwIng9g7/JqFXhLNpw1R0un7qfVS8EmXMT8AgkVIxT6dXfKftFa2kXGx t3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737324364; x=1737929164; 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=AyvDbG7b41brEYVGfP1u1SKwu5vc8yhuPpSJa7ZhQcc=; b=H0Cvgnjc/lDOuTyk4MUKBr7TcUu2QHXzwdMJgfNkAkU8LFLAff68QnX9YMXXjOLVMg ACBbp68ueTjmiOaklB6E9ta1Y9xdJxNNMK6vzY2H5Uv3XQRCagxhDM9u5Gdn/yfQS8Ho /xZGd/TE/p+oLwfKyu0gFj5v4s8d1AliR1XJV1+2hCDQNdOOxVrvI5o5t/QPz/hYAhu/ 1HZPcSf9bRkIGPX04wDLtGjicWNcK6ii7mU37P3SvDp+/ID97gr79RuayppVlI4MD8/l mPOoDfHfQGaYGsM+tRXVcDDD3IryBs7IrxAEheo4nz074VtsqcezD+FosgVZ7dAcuUir YCkg== X-Forwarded-Encrypted: i=1; AJvYcCUzx9ckTmWYl7NjQ02DuLVqk7NaE8jyW3cdO8J99lpOWSbllnCcNIxOJ0OG8Beck18avR6e/wFxrtloN6w=@vger.kernel.org X-Gm-Message-State: AOJu0YzBVitRlTC1zX676+coyOhlynI44MiEJSiQFZXZkyBFtknWrc/p xKQ1Pq/ojy4T4tnLQ6z1na/JBPuetwCT/A1zOz3dsZArYWh5sGGbYNQGgQ== X-Gm-Gg: ASbGncsInF1dJ2Ly3Pm9xZ94+/uVeL35bUxBY8SMQI7q34/oQy7uA078ocKjqzc02ww /b+LWtwdYKd0cc/QnXEpYdWJEIcA8ONBA+ZYdpv9EnMsIm8Nj6/inZHUIPYjV0PYIyWKMQVMhu6 fJHOc/SCIYLM8FKclSG8CA30ltDdrwY5s0o2nel8wl/cGYWn22CIc0AkDynSe3apvkmNEMLWCh8 C4lSSa49vNDIKFuFeJADrQjwQPm7n8KCEWGPwHC6P6hxG3B1nHuKzcdg8szFn95ivxGKW8CZ6oq Xw== X-Google-Smtp-Source: AGHT+IEAJNCi45JOZs1MgcEl91z1W7VnW00fDmOJmX40sBh/pzafEyt002a0QvFSc1U8dk/DPvTHBQ== X-Received: by 2002:a05:620a:8812:b0:7b6:f17d:f5a7 with SMTP id af79cd13be357-7be631e56b4mr2137495285a.6.1737324363945; Sun, 19 Jan 2025 14:06:03 -0800 (PST) Received: from localhost.localdomain ([2800:bf0:82:1159:c837:3446:190b:188d]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7be614f0096sm369243085a.112.2025.01.19.14.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 14:06:03 -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 v5 04/14] platform/x86: alienware-wmi: Refactor LED control methods Date: Sun, 19 Jan 2025 17:05:32 -0500 Message-ID: <20250119220542.3136-5-kuurtb@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250119220542.3136-1-kuurtb@gmail.com> References: <20250119220542.3136-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 9328bf9b6c81..18f3a619283e 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 @@ -417,12 +418,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 */ @@ -453,46 +485,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) { @@ -509,13 +501,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; } @@ -651,36 +644,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"); } @@ -1223,10 +1197,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); @@ -1267,10 +1280,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;