From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129420; b=Y08mCHXkuuIqI5HHF3nt/jBP1GdxAGACv/ncp8pbXjV2/FyXwu7syhhd/5ZrjfgdDlIN CvOCnsNnaw/k5E1md8a+3LhWYkMRyHYFiGYCG2IWuEKWJt8xguyKqLpW09rGDE+sZCN31 rtCtlOOoH6EP0/OwwcukK1PUPW/dqbsxuXJDERY6FLDhkutcFWGZ3RCLFUg76G0Ze9m6o cEgIn4VPhTA9qyQnb/eYkh17b2pf+KuixvDHZnQhWEp7I7++jUSMADcZ/h/YVqx8KXjTf K6LVORQRleQJk70N+3WYGcHblhs3lniSAiVDKHanCtyHTQ1FjbVsYGh/QvPiOXq+8pw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129420; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=wg9CBEN64IQDXhWyhVaMrG37xS3eY+wT2jL62iutVSg=; b=bPAI1UKtOyTkYr6wfi9/8q81nlMdN++wSy9y02cc9+BL/pDNHla1Kzov6d9zfb8pq1po LdQYVtU2GhC8vTnyiZXE9Ztdr//j9bSBf3/mBEUg839p9flDFiPBPdyPu4yUOzoR4adpr QJQRHdBdwKoVU/t/cy2QcE+IWU6xhb2D00O3wsqcCufySENoy4rzQFoq/Cw3Zf/5EdjNv CqDwkeZLdXjnK2LEuifAj7AzfmXtS/JJOdsm4Y30S9CQ+DzAAiE03RZV+kegdrvU5NKti V+Lm+8+BmU6b7MIUgpQBTqkwHHFA/qGmH3p+HaYB02DV/mxWcBioITvnPUxfiXfrKWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="HxExxA/z"; arc=none smtp.remote-ip=192.198.163.7 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F521606A680 for ; Tue, 1 Dec 2026 12:50:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0F521606A680 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HxExxA/z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796129419; x=1827665419; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=wg9CBEN64IQDXhWyhVaMrG37xS3eY+wT2jL62iutVSg=; b=HxExxA/zSw99SZ/5BWlKTm7hodJQjb3zybNoYfghzk/XrW3swuqVHRGO uv+pAcPqHzms2EqtSV5YMn2Yn/vmOIwmCjuAYL2RnHOcDNCd2oBn0FULP F32s/IPMsZIKLKE/3u97e3NGLP3Ol7erfZHt06gjmpsSoPUS+oEXlvy4q Tm/ZwoT3fNCzNi8PcWO1wr/jBTZAuYXVzB3Qz17tlWZh1Kwtkv+fmkphc Y1uPsQyaFmHsTCTUY61vBkpiEb+pi4LzLyrh5TibAecc2LyiiGBbQ/vJX 21zSoMOphiwQ9oSb2ptz4/NQAiDDbtAikdU9kwIbZvWDUWbqNDWtZRQOb g==; X-CSE-ConnectionGUID: +8vMyJPwQEm70QCV4uGDgA== X-CSE-MsgGUID: R88K5Y8cQamK6Fp6WB0qWA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4849097" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4849097" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 04:50:18 -0800 X-CSE-ConnectionGUID: NzqegFSpSEibtIIipC/4SQ== X-CSE-MsgGUID: 1GrbovNYQH6iUSgJqOb9iA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13718216" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 04:50:17 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 1 Dec 2026 14:50:12 +0200 (EET) To: Batuhan cc: Hans de Goede , "Lee, Chun-Yi" , platform-driver-x86@vger.kernel.org Subject: Re: [PATCH v4] platform/x86: acer-wmi: Add 4-zone RGB keyboard support for Nitro AN515-58 In-Reply-To: <20261126094703.6690-1-tuugspeedman@gmail.com> Message-ID: References: <20261126094703.6690-1-tuugspeedman@gmail.com> X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-334791351-1796129412=:1168" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-334791351-1796129412=:1168 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Thu, 26 Nov 2026, Batuhan wrote: > From: Batuhan G=C3=BCvener >=20 > Add support for the 4-zone RGB keyboard backlights found on Acer Nitro > AN515-58 laptops. >=20 > The hardware operates via a dual-control mechanism: global hardware > brightness is managed by the EC via RAM offset 0x31 with a range of 0 to = 4 > (where 0x04 is maximum intensity), while per-zone RGB color control is > handled via WMI Method 6. >=20 > Exposing max_brightness =3D 4 to match the EC hardware level causes the > led-class-multicolor subsystem to scale color components down, restrictin= g > the palette to 5x5x5 (125) total color combinations. Keeping max_brightne= ss > at 255 allows fine-grained 8-bit per-channel control from userspace, thou= gh > it creates a dual-control scenario where hardware EC brightness and > userspace multicolor brightness operate concurrently (e.g. EC brightness = at > 4 while userspace intensity is 0). >=20 > Additionally, when the system resumes from a shutdown or power cycle > while brightness is set to 0, the hardware initializes with 0 > brightness but cannot derive valid multi-intensity values. To ensure > consistent state evaluation, it defaults to max intensity > (255, 255, 255 - white). >=20 > Since the Nitro AN515-58 SKU ships with both 4-zone RGB > and single-color red backlight options, add SMBIOS Type 0xAC checks > to ensure non-functional LED devices are not registered > on single-color models. >=20 > This implementation builds upon initial findings and reverse-engineering > efforts by Dirga Yuza and open-source community driver implementations. >=20 > Link: https://lore.kernel.org/r/20260503062131.158944-1-dirgayuza123@gmai= l.com/ > Link: https://github.com/0x7375646F/Linuwu-Sense > Link: https://github.com/JafarAkhondali/acer-predator-turbo-and-rgb-keybo= ard-linux-module > Link: https://github.com/archivesteak/opensense >=20 > Signed-off-by: Batuhan G=C3=BCvener >=20 > --- > The SMBIOS Type 0xAC parsing logic (type_ac_dmi_decode()) was written > with assistance from LLM, and was reviewed and verified against raw > DMI dumps from target hardware to ensure accurate capability detection. >=20 > Changes since v3: > - Instead of masking wmi_evaluate_method() with a helper, migrated to new= er wmidev approach > - Added RGB capability checking on top of DMI checks based on archivestea= k's findings > - Fix spacing on newly added #define lines > - Rename led_information struct to be more informative acer_kbd_zone_led > - Switch kbl_four_zone quirk into a boolean and rename it into kbd_bl_fou= r_zone > - Separate AN16-41's quirks to set target hardware cleanly > - Initial zone colors are now read through WMI method 7 and not directly = from EC > - Rebased onto next-20261125 >=20 > Changes since v2: > - Remove redundant comments > - Place new #include headers near alphabetical neighbors > - Replace deprecated wmi_evaluate_method() with WMI_gaming_execute_buf() = using __free(kfree) > - Use __packed structs for WMI command payloads > - Switch to guard(mutex), devm_mutex_init(), and FIELD_MAX() > - Use dev_warn() instead of pr_warn() > - Fix indentation and reverse xmas-tree variable ordering >=20 > Changes since v1: > - Clear non-English comments > - Rebase onto linux-next > --- > drivers/platform/x86/Kconfig | 1 + > drivers/platform/x86/acer-wmi.c | 410 +++++++++++++++++++++++++++++++- > 2 files changed, 410 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig > index 7daef6ad5dbe..a200fd3d5308 100644 > --- a/drivers/platform/x86/Kconfig > +++ b/drivers/platform/x86/Kconfig > @@ -178,6 +178,7 @@ config ACER_WMI > =09select LEDS_CLASS > =09select NEW_LEDS > =09select PLATFORM_PROFILE > +=09select LEDS_CLASS_MULTICOLOR > =09help > =09 This is a driver for newer Acer (and Wistron) laptops. It adds > =09 wireless radio and bluetooth control, and on some laptops, > diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-= wmi.c > index 60028fe9f3e6..11c33e9b1346 100644 > --- a/drivers/platform/x86/acer-wmi.c > +++ b/drivers/platform/x86/acer-wmi.c > @@ -14,11 +14,13 @@ > #include > #include > #include > +#include > #include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -26,6 +28,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -36,6 +39,10 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > =20 > MODULE_AUTHOR("Carlos Corbacho"); > MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); > @@ -77,6 +84,29 @@ MODULE_LICENSE("GPL"); > #define ACER_WMID_SET_GAMING_MISC_SETTING_METHODID 22 > #define ACER_WMID_GET_GAMING_MISC_SETTING_METHODID 23 > =20 > +#define ACER_WMID_SET_GAMING_STATIC_LED_METHODID 6 > +#define ACER_WMID_SET_GAMING_KBD_BL_METHODID 20 > + > +#define ACER_GAMING_LED_KBD_BL_ENABLE=09BIT_ULL(3) > +#define ACER_GAMING_LED_KBD_BL_INTERFACE_MASK=09GENMASK_ULL(43, 40) > + > +#define ACER_KBD_STATIC_PREAMBLE_BRIGHTNESS=09100 > +#define ACER_KBD_RGB_MAX_INTENSITY=09=09255 > +#define ACER_KBD_NUM_ZONES=09=09=094 > +#define ACER_KBD_NUM_COLOR_CHANNELS=09=093 > + > +#define ACER_KBD_MODE_STATIC=09=09=090 > +#define ACER_SMBIOS_TYPE_KBD_INFO=09=090xAC > +#define ACER_SMBIOS_KBD_TYPE_FOUR_ZONE=09=094 > +#define ACER_SMBIOS_KBD_COLOR_RGB=09=092 > +#define ACER_SMBIOS_KBD_RECORD_TYPE=09=090x08 > +#define ACER_SMBIOS_KBD_RECORD_COLOR=09=090x0A > + > +#define ACER_WMID_GET_GAMING_STATIC_LED_METHODID 7 > +#define ACER_KBD_COLOR_R_MASK GENMASK_ULL(15, 8) > +#define ACER_KBD_COLOR_G_MASK GENMASK_ULL(23, 16) > +#define ACER_KBD_COLOR_B_MASK GENMASK_ULL(31, 24) > + > #define ACER_GAMING_FAN_BEHAVIOR_CPU BIT(0) > #define ACER_GAMING_FAN_BEHAVIOR_GPU BIT(3) > =20 > @@ -389,6 +419,170 @@ struct wmi_interface { > /* The static interface pointer, points to the currently detected interf= ace */ > static struct wmi_interface *interface; > =20 > +struct acer_kbd_zone_led { > +=09struct led_classdev_mc led_general; > +=09struct mc_subled led_colors[3]; > +=09struct rgb_wmi *parent; > +=09u8 zone_id; > +=09u8 current_brightness; > +}; > + > +struct rgb_wmi { > +=09struct wmi_device *wdev; > +=09struct mutex led_lock; /* making sure EC receives single command at a= time */ > +=09struct acer_kbd_zone_led zones[ACER_KBD_NUM_ZONES]; > +}; > + > +static int acer_gaming_wmi_eval_buf(struct wmi_device *wdev, u32 method_= id, > +=09=09=09=09 const void *in, size_t in_size, u64 *out) > +{ > +=09struct acpi_buffer result =3D { ACPI_ALLOCATE_BUFFER, NULL }; > +=09struct acpi_buffer input =3D { > +=09=09.length =3D in_size, > +=09=09.pointer =3D (void *)in, > +=09}; > +=09acpi_status status; > + > +=09status =3D wmidev_evaluate_method(wdev, 0, method_id, &input, &result= ); This interface is deprecated. ** * wmidev_evaluate_method - Evaluate a WMI method (deprecated) > +=09if (ACPI_FAILURE(status)) > +=09=09return -EIO; > + > +=09union acpi_object *obj __free(kfree) =3D result.pointer; > + > +=09if (!out) No blank line between assignment and its "error handling". > +=09=09return 0; > + > +=09if (!obj) > +=09=09return -ENOMSG; > + > +=09switch (obj->type) { > +=09case ACPI_TYPE_INTEGER: > +=09=09*out =3D obj->integer.value; > +=09=09return 0; > +=09case ACPI_TYPE_BUFFER: > +=09=09if (obj->buffer.length >=3D 8) > +=09=09=09*out =3D get_unaligned_le64(obj->buffer.pointer); > +=09=09else if (obj->buffer.length >=3D 4) > +=09=09=09*out =3D get_unaligned_le32(obj->buffer.pointer); > +=09=09else if (obj->buffer.length >=3D 1) > +=09=09=09*out =3D ((u8 *)obj->buffer.pointer)[0]; > +=09=09else > +=09=09=09return -ENOMSG; > +=09=09return 0; > +=09default: > +=09=09return -ENOMSG; > +=09} > +} > + > +static int acer_gaming_wmi_eval_u64(struct wmi_device *wdev, u32 method_= id, > +=09=09=09=09 u64 in, u64 *out) > +{ > +=09return acer_gaming_wmi_eval_buf(wdev, method_id, &in, sizeof(in), out= ); > +} > + > +struct acer_gaming_kbd_bl_input { > +=09u8 mode; > +=09u8 speed; > +=09u8 brightness; > +=09u8 reserved; > +=09u8 direction; > +=09u8 r; > +=09u8 g; > +=09u8 b; > +=09u8 cmd_flags[2]; > +=09u8 padding[6]; > +} __packed; > + > +static int acer_kbd_set_static_preamble(struct wmi_device *wdev, u8 ec_b= rightness) > +{ > +=09struct acer_gaming_kbd_bl_input gm_input =3D { > +=09=09.mode =3D ACER_KBD_MODE_STATIC, > +=09=09.brightness =3D ec_brightness, > +=09=09.cmd_flags =3D { 3, 1 }, > +=09}; > +=09u64 resp =3D 0; > +=09int ret; > + > +=09ret =3D acer_gaming_wmi_eval_buf(wdev, ACER_WMID_SET_GAMING_KBD_BL_ME= THODID, > +=09=09=09=09 &gm_input, sizeof(gm_input), &resp); > +=09if (ret < 0 || resp) > +=09=09return -EIO; > + > +=09return 0; > +} > + > +struct acer_gaming_static_led_input { > +=09u8 zone_bit; > +=09u8 r; > +=09u8 g; > +=09u8 b; > +=09u32 padding; > +} __packed; > + > +static int send_zone_color(struct wmi_device *wdev, u8 zone_bit, u8 r, u= 8 g, u8 b) > +{ > +=09struct acer_gaming_static_led_input input =3D { > +=09=09.zone_bit =3D zone_bit, > +=09=09.r =3D r, > +=09=09.g =3D g, > +=09=09.b =3D b, > +=09}; > +=09u64 resp =3D 0; > +=09u64 payload; > +=09int ret; > + > +=09memcpy(&payload, &input, sizeof(payload)); > + > +=09ret =3D acer_gaming_wmi_eval_u64(wdev, ACER_WMID_SET_GAMING_STATIC_LE= D_METHODID, > +=09=09=09=09 payload, &resp); > +=09if (ret < 0 || resp) > +=09=09return -EIO; > + > +=09return 0; > +} > + > +static enum led_brightness rgb_get(struct led_classdev *led_cdev) > +{ > +=09struct led_classdev_mc *general_mcolor =3D lcdev_to_mccdev(led_cdev); > +=09struct acer_kbd_zone_led *led_info =3D container_of(general_mcolor, > +=09=09=09=09=09=09=09struct acer_kbd_zone_led, > +=09=09=09=09=09=09=09led_general); > +=09return led_info->current_brightness; > +} > + > +static int rgb_set(struct led_classdev *led_cdev, enum led_brightness br= ightness) > +{ > +=09struct led_classdev_mc *general_mcolor =3D lcdev_to_mccdev(led_cdev); > +=09struct acer_kbd_zone_led *led_info =3D container_of(general_mcolor, > +=09=09=09=09=09=09=09struct acer_kbd_zone_led, > +=09=09=09=09=09=09=09led_general); > +=09struct rgb_wmi *data =3D led_info->parent; > +=09u8 r, g, b; > +=09int ret; > + > +=09guard(mutex)(&data->led_lock); > + > +=09if (brightness =3D=3D 0) { > +=09=09r =3D 0; > +=09=09g =3D 0; > +=09=09b =3D 0; > +=09} else { > +=09=09led_mc_calc_color_components(general_mcolor, brightness); > +=09=09r =3D led_info->led_colors[0].brightness; > +=09=09g =3D led_info->led_colors[1].brightness; > +=09=09b =3D led_info->led_colors[2].brightness; > +=09} > + > +=09ret =3D send_zone_color(data->wdev, led_info->zone_id, r, g, b); > +=09if (ret) > +=09=09return ret; > + > +=09led_info->current_brightness =3D brightness; > +=09led_cdev->brightness =3D brightness; > + > +=09return 0; > +} > + > /* > * Embedded Controller quirks > * Some laptops require us to directly access the EC to either enable or= query > @@ -407,10 +601,154 @@ struct quirk_entry { > =09bool platform_profile; > =09bool pwm; > =09bool commun_bluetooth; > +=09bool kbd_bl_four_zone; > }; > =20 > static struct quirk_entry *quirks; > =20 > +struct acer_smbios_type_ac { > +=09struct dmi_header header; > +=09u16 version; > +} __packed; > + > +struct acer_smbios_type_ac_entry { > +=09u8 id; > +=09u16 value; > +} __packed; > + > +static void type_ac_dmi_decode(const struct dmi_header *header, void *da= ta) > +{ > +=09const u8 *ptr, *end; > +=09bool has_four_zone =3D false; > +=09bool has_rgb =3D false; > +=09bool *supported =3D data; > + > +=09if (header->type !=3D ACER_SMBIOS_TYPE_KBD_INFO) > +=09=09return; > + > +=09if (header->length < sizeof(struct acer_smbios_type_ac)) > +=09=09return; > + > +=09ptr =3D (const u8 *)header + sizeof(struct acer_smbios_type_ac); > +=09end =3D (const u8 *)header + header->length; > + > +=09while (ptr + sizeof(struct acer_smbios_type_ac_entry) <=3D end) { > +=09=09const struct acer_smbios_type_ac_entry *entry =3D > +=09=09=09(const struct acer_smbios_type_ac_entry *)ptr; > + > +=09=09if (entry->id =3D=3D ACER_SMBIOS_KBD_RECORD_TYPE && > +=09=09 le16_to_cpu(entry->value) =3D=3D ACER_SMBIOS_KBD_TYPE_FOUR_ZON= E) > +=09=09=09has_four_zone =3D true; > +=09=09else if (entry->id =3D=3D ACER_SMBIOS_KBD_RECORD_COLOR && > +=09=09=09 le16_to_cpu(entry->value) =3D=3D ACER_SMBIOS_KBD_COLOR_RGB) > +=09=09=09has_rgb =3D true; > + > +=09=09ptr +=3D sizeof(*entry); > +=09} > + > +=09if (has_four_zone && has_rgb) > +=09=09*supported =3D true; > +} > + > +static bool acer_kbd_four_zone_supported(void) > +{ > +=09bool supported =3D false; > + > +=09dmi_walk(type_ac_dmi_decode, &supported); > +=09return supported; > +} > + > +static int acer_kbd_rgb_init(struct wmi_device *wdev, struct rgb_wmi *rg= b_data) > +{ > +=09static const char * const zone_names[] =3D { > +=09=09"acer-wmi:rgb:kbd_backlight-left", > +=09=09"acer-wmi:rgb:kbd_backlight-center-left", > +=09=09"acer-wmi:rgb:kbd_backlight-center-right", > +=09=09"acer-wmi:rgb:kbd_backlight-right", For correct naming, please see: Documentation/leds/leds-class.rst > +=09}; > +=09u64 led_mode; > +=09int ret; > +=09int i; > + > +=09led_mode =3D ACER_GAMING_LED_KBD_BL_ENABLE | > +=09=09 FIELD_PREP(ACER_GAMING_LED_KBD_BL_INTERFACE_MASK, > +=09=09=09 FIELD_MAX(ACER_GAMING_LED_KBD_BL_INTERFACE_MASK)); > + > +=09ret =3D acer_gaming_wmi_eval_u64(wdev, ACER_WMID_SET_GAMING_LED_METHO= DID, > +=09=09=09=09 led_mode, NULL); > +=09if (ret < 0) > +=09=09return ret; > + > +=09ret =3D acer_kbd_set_static_preamble(wdev, ACER_KBD_STATIC_PREAMBLE_B= RIGHTNESS); > +=09if (ret) > +=09=09dev_warn(&wdev->dev, "Failed to set static preamble on init: %d\n"= , ret); > + > +=09ret =3D devm_mutex_init(&wdev->dev, &rgb_data->led_lock); > +=09if (ret) > +=09=09return ret; > + > +=09for (i =3D 0; i < ACER_KBD_NUM_ZONES; i++) { > +=09=09struct acer_kbd_zone_led *zone =3D &rgb_data->zones[i]; > +=09=09u64 color_out =3D 0; > +=09=09u8 r, g, b; > +=09=09u8 max_val; > + > +=09=09zone->zone_id =3D BIT(i); > +=09=09zone->parent =3D rgb_data; > + > +=09=09ret =3D acer_gaming_wmi_eval_u64(wdev, > +=09=09=09=09=09 ACER_WMID_GET_GAMING_STATIC_LED_METHODID, > +=09=09=09=09=09 zone->zone_id, &color_out); > +=09=09if (ret) { > +=09=09=09dev_warn(&wdev->dev, > +=09=09=09=09 "Failed to read initial color for zone %d, defaulting to wh= ite\n", > +=09=09=09=09 i); > +=09=09=09r =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09=09g =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09=09b =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09} else { > +=09=09=09r =3D FIELD_GET(ACER_KBD_COLOR_R_MASK, color_out); > +=09=09=09g =3D FIELD_GET(ACER_KBD_COLOR_G_MASK, color_out); > +=09=09=09b =3D FIELD_GET(ACER_KBD_COLOR_B_MASK, color_out); > +=09=09} > + > +=09=09max_val =3D max3(r, g, b); > + > +=09=09if (max_val =3D=3D 0) { > +=09=09=09zone->led_colors[0].intensity =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09=09zone->led_colors[1].intensity =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09=09zone->led_colors[2].intensity =3D ACER_KBD_RGB_MAX_INTENSITY; > +=09=09=09zone->current_brightness =3D 0; > +=09=09} else { > +=09=09=09zone->led_colors[0].intensity =3D (r * ACER_KBD_RGB_MAX_INTENSI= TY) / max_val; > +=09=09=09zone->led_colors[1].intensity =3D (g * ACER_KBD_RGB_MAX_INTENSI= TY) / max_val; > +=09=09=09zone->led_colors[2].intensity =3D (b * ACER_KBD_RGB_MAX_INTENSI= TY) / max_val; > +=09=09=09zone->current_brightness =3D max_val; > +=09=09} > + > +=09=09zone->led_colors[0].color_index =3D LED_COLOR_ID_RED; > +=09=09zone->led_colors[1].color_index =3D LED_COLOR_ID_GREEN; > +=09=09zone->led_colors[2].color_index =3D LED_COLOR_ID_BLUE; > + > +=09=09zone->led_general.subled_info =3D zone->led_colors; > +=09=09zone->led_general.num_colors =3D ACER_KBD_NUM_COLOR_CHANNELS; > + > +=09=09zone->led_general.led_cdev.name =3D zone_names[i]; > +=09=09zone->led_general.led_cdev.max_brightness =3D ACER_KBD_RGB_MAX_INT= ENSITY; > +=09=09zone->led_general.led_cdev.brightness =3D zone->current_brightness= ; > +=09=09zone->led_general.led_cdev.brightness_set_blocking =3D rgb_set; > +=09=09zone->led_general.led_cdev.brightness_get =3D rgb_get; > +=09=09zone->led_general.led_cdev.flags =3D LED_RETAIN_AT_SHUTDOWN; > + > +=09=09ret =3D devm_led_classdev_multicolor_register(&wdev->dev, > +=09=09=09=09=09=09=09 &zone->led_general); > +=09=09if (ret) > +=09=09=09return ret; > +=09} > + > +=09return 0; > +} > + > static void __init set_quirks(void) > { > =09if (quirks->mailled) > @@ -473,10 +811,17 @@ static struct quirk_entry quirk_acer_travelmate_249= 0 =3D { > =09.mailled =3D 1, > }; > =20 > +static struct quirk_entry quirk_acer_nitro_an16_41 =3D { > +=09.hwmon =3D true, > +=09.platform_profile =3D true, > +=09.pwm =3D true, > +}; > + > static struct quirk_entry quirk_acer_nitro_an515_58 =3D { > =09.hwmon =3D true, > =09.platform_profile =3D true, > =09.pwm =3D true, > +=09.kbd_bl_four_zone =3D true, > }; > =20 > static struct quirk_entry quirk_acer_predator_ph315_53 =3D { > @@ -708,7 +1053,7 @@ static const struct dmi_system_id acer_quirks[] __in= itconst =3D { > =09=09=09DMI_MATCH(DMI_SYS_VENDOR, "Acer"), > =09=09=09DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN16-41"), > =09=09}, > -=09=09.driver_data =3D &quirk_acer_nitro_an515_58, > +=09=09.driver_data =3D &quirk_acer_nitro_an16_41, > =09}, > =09{ > =09=09.callback =3D dmi_matched, > @@ -2835,6 +3180,7 @@ static int acer_wmi_hwmon_init(void); > /* > * Platform device > */ > + > static int acer_platform_probe(struct platform_device *device) > { > =09int err; > @@ -2933,11 +3279,64 @@ static int acer_resume(struct device *dev) > =20 > =09return 0; > } > + > #else > #define acer_suspend=09NULL > #define acer_resume=09NULL > #endif > =20 > +static int acer_gaming_wmi_probe(struct wmi_device *wdev, const void *co= ntext) > +{ > +=09struct rgb_wmi *rgb_data; > + > +=09if (!quirks || !quirks->kbd_bl_four_zone) > +=09=09return -ENODEV; > + > +=09if (!acer_kbd_four_zone_supported()) > +=09=09return -ENODEV; > + > +=09rgb_data =3D devm_kzalloc(&wdev->dev, sizeof(*rgb_data), GFP_KERNEL); > +=09if (!rgb_data) > +=09=09return -ENOMEM; > + > +=09rgb_data->wdev =3D wdev; > +=09dev_set_drvdata(&wdev->dev, rgb_data); > + > +=09return acer_kbd_rgb_init(wdev, rgb_data); > +} > + > +static int acer_gaming_wmi_resume(struct device *dev) > +{ > +=09struct rgb_wmi *rgb_data =3D dev_get_drvdata(dev); > +=09int ret; > + > +=09ret =3D acer_kbd_set_static_preamble(rgb_data->wdev, > +=09=09=09=09=09 ACER_KBD_STATIC_PREAMBLE_BRIGHTNESS); > +=09if (ret) > +=09=09dev_warn(dev, "Failed to restore keyboard static mode on resume: %= d\n", > +=09=09=09 ret); > + > +=09return 0; > +} > + > +static DEFINE_SIMPLE_DEV_PM_OPS(acer_gaming_wmi_pm_ops, NULL, > +=09=09=09=09acer_gaming_wmi_resume); > + > +static const struct wmi_device_id acer_gaming_wmi_id_table[] =3D { > +=09{ WMID_GUID4, NULL }, > +=09{ } > +}; > +MODULE_DEVICE_TABLE(wmi, acer_gaming_wmi_id_table); > + > +static struct wmi_driver acer_gaming_wmi_driver =3D { > +=09.driver =3D { > +=09=09.name =3D "acer-gaming-wmi", > +=09=09.pm =3D pm_sleep_ptr(&acer_gaming_wmi_pm_ops), > +=09}, > +=09.id_table =3D acer_gaming_wmi_id_table, > +=09.probe =3D acer_gaming_wmi_probe, > +}; > + > static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume); > =20 > static void acer_platform_shutdown(struct platform_device *device) > @@ -3327,6 +3726,12 @@ static int __init acer_wmi_init(void) > =09if (err) > =09=09goto error_device_add; > =20 > +=09err =3D wmi_driver_register(&acer_gaming_wmi_driver); > +=09if (err) { > +=09=09pr_err("Unable to register gaming WMI driver\n"); > +=09=09goto error_wmi_register; > +=09} > + > =09if (wmi_has_guid(WMID_GUID2)) { > =09=09interface->debug.wmid_devices =3D get_wmid_devices(); > =09=09create_debugfs(); > @@ -3337,6 +3742,8 @@ static int __init acer_wmi_init(void) > =20 > =09return 0; > =20 > +error_wmi_register: > +=09platform_device_del(acer_platform_device); > error_device_add: > =09platform_device_put(acer_platform_device); > error_device_alloc: > @@ -3361,6 +3768,7 @@ static void __exit acer_wmi_exit(void) > =09remove_debugfs(); > =09platform_device_unregister(acer_platform_device); > =09platform_driver_unregister(&acer_platform_driver); > +=09wmi_driver_unregister(&acer_gaming_wmi_driver); > =20 > =09pr_info("Acer Laptop WMI Extras unloaded\n"); > } >=20 --=20 i. --8323328-334791351-1796129412=:1168--