From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 129621D88D7; Wed, 2 Jul 2025 03:38:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427517; cv=none; b=P6Za6+NQFxj6Qy1RgxHZ+aw2SHSj4Ra6C6IVlkLzmSvvHnVBAyxMZaSVQKx+kBvIF7kTlhdGzwQdaPrEaXPIRQUmqb41alXCaabiNvws19m/Ea7mDs4xw0Qu3oaNLJ/RDXO5M+wdvTSy/0IU6fY+sf3K9AMxD5lCXosSWfhnreM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427517; c=relaxed/simple; bh=rJl3aFWtlqRs+dqcSti/loEsT2WNTFhQNPWTd8K6laY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i/R6tfE54s/B1VZO0C20R6wIITSu/7LvAPpF2EkDsIsR9i4GWtOJaJWQgqrbV1eY+7B2SxULnfEzhcoroJp9Kg8HVLdE87ZXILPEmNkcRcjaLoD7hbCYTm6PgXUAsQ6kRepZnZKYEM/AE46w1apEdp9NeFer2k4rES5hczgkGtI= 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=Pgscq20p; arc=none smtp.client-ip=209.85.210.172 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="Pgscq20p" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7481600130eso5128751b3a.3; Tue, 01 Jul 2025 20:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427514; x=1752032314; 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=8Yi+NoAQErcTbWl94DF71VoeBJYcbpe09ipCKXKmsis=; b=Pgscq20pbGoHRjMZu9WtaJ+z8nTQVn1ey2B1Qp4X9nt11ntSUiVcFshdtQMi9DdF5W jKov/uKrm5CsEJBgpB28R0YkJvUev8hXHVzHV+CORBMq9JQCXjw1yOP6qAv/pcHwpRA/ Q7quMJKXLSPLTw9Bsh4VKMhVYv1Wby5IKPEOR8meTQy2hqSCIrllBTBf6dn+7FgWCltr 5Yuo0ZVYaAl6EDMZ+7KeYHANdpxWkbTsGMIXOwEZzzZ9hOUJgidnvzr0t2foFI4UGPFP TsOq/1AHV8vR9laGDZFmZ2N8p5BzwXNmPBDni6U8Ic5lguzIV9G+LLOQFRMCx1/xFfMK 7KjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427514; x=1752032314; 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=8Yi+NoAQErcTbWl94DF71VoeBJYcbpe09ipCKXKmsis=; b=bAXcqLCzOSjBKg/6mCv3VaY36ZIdxgR5NKMK/SPTtJKm8KxC0fCPwUmqI+uVxdFgxP 8YgM1f4WAuKPfxI+MYI4M7xm1Kmg4Xpp9HVsH9gVbcBsvcBkrXZ7kLuNcS1rNE+NjKbN 4MotWAKYmdJTAXQQ+gtkiU/uCfDG64muvoplPYFTZ8gzend9G29gZjZgzoHg5hyjkH9n cpkwdyQcfCq6s0DeajauVN2fEj9HAAyG7uH0CL9J+m16L4IwvgvCVv5Wkn5FfO+mdqS4 t3Oe2iEEXT7PU3XZ1mkM+iHiU/Wp9bPWV+SEETS8pbPXudxOQxKbDJjIK55oxWykSFx7 PaVw== X-Forwarded-Encrypted: i=1; AJvYcCWlYLKaXl8u2kkfE1PbNBF1KMO/PmqYu3CWpXVIFyFoGI6KBMqEe68t4Kl3x5LlHsbEMR8K81+JszbWYx/Q@vger.kernel.org, AJvYcCWtB5+hcQLQJmvNxrPTmNvwbRedbJDk1eA3m0gjleFyF7dE3LX0tj6cB0pwGQT+ZXn6DSpb+20LR8XIuPZR21PHIvzg4g==@vger.kernel.org, AJvYcCXsc9nex+fZjHniYglmnhh75ls5iDBzjib/uLpUBN40RF9oK1U2DRZ+muko+s2j4P2SL75BKIJHIpU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxi1bVe8ubs7kHScpxHPWOR6fUAMCkNFaPekaPi5/+hqQXetPeG IVhKc2l7QlSubjjBl77sDqz7aUEwD5oj9KqCxEehMZA3xPfgwDdYDBweOz02cuwe X-Gm-Gg: ASbGncvEERyH0kCDs1+y2dno6Qr5jc4m91skWy1rvMtOkibOpdI9Juzj9BPY3siIBTc 1M1aKi1E/IUcahAwF3oBB2Q96jVxGVwf16oo22m7Hhikuf8Jkphq7V8JyoOfsbXMoCuor+lgPKE O8YmovWqAB3gvA45HKU+KE1vwDzyfH8epE16bjky37ptP8twNGq2XppROrFo9rsEdhI+O/gjOOz YmK5DDDFBO9nXMP9QxCi9Ik1sgw/jagdNrlhYkOzzG958ANKN5JnpPkhWqBc6zrhzYZ62USP0iL 2VbCzRUeRPxaba9L6tMGzhi8kCaXwSklnlIrH4f5L4ZFD6YIW0C2wEcc5WAYpVh+qCM40oUv4fD 4u/o6T/FQDCPm77Wa0Mkry2I1maugKAwzAiYdzHOGhw== X-Google-Smtp-Source: AGHT+IGosLydtrG301xy3oYUSuaFi1PomDNwgDqEzYXX2BhNkFhix5vpZkIynsZZGYUXT/VGSi2Usg== X-Received: by 2002:a05:6a21:498:b0:21f:83ae:3290 with SMTP id adf61e73a8af0-222d7ef812dmr2026155637.33.1751427514175; Tue, 01 Jul 2025 20:38:34 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:33 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alok Tiwari , Mario Limonciello Subject: [PATCH v13 1/6] platform/x86: Add lenovo-wmi-* driver Documentation Date: Tue, 1 Jul 2025 20:38:21 -0700 Message-ID: <20250702033826.1057762-2-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds documentation for new lenovo-wmi drivers. Reviewed-by: Alok Tiwari Reviewed-by: Armin Wolf Reviewed-by: Mario Limonciello Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move drivers into new lenovo folder. - Use LENOVO DRIVERS entry in MAKEFILE instead of new entry. v12: No change v11: No change v10: No change v9: No change v8: No change v7: No change v6: - Fix typos and requested rewordings from v5 review. - Rename lenovo-wmi-other-method.rst to lenovo-wmi-other.rst, fixes warining and aligns documentation with driver name. v5: - Fix extra spaces in lenovo-wmi-gamezone.rst. - Fix monospace for GUID's. v4: - Fixed MOF formatting issues. - Fixed spelling mistakes. - Updated description of balanced-performance profile for Gamezone. - Updated description of thermal mode event GUID for Gamezone. v3: - Split documentation into multiple files, one for each parent driver for the Gamezone and Other Mode WMI interfaces. - Add MOF data for all parent and child interfaces. - Remove lenovo-wmi-camera.c driver from v2 documentation. v2: - Update description of Custom Profile to include the need to manually set it. - Remove all references to Legion hardware. - Add section for lenovo-wmi-camera.c driver as it follows the same naming convention. --- --- .../wmi/devices/lenovo-wmi-gamezone.rst | 203 ++++++++++++++++++ .../wmi/devices/lenovo-wmi-other.rst | 108 ++++++++++ MAINTAINERS | 3 + 3 files changed, 314 insertions(+) create mode 100644 Documentation/wmi/devices/lenovo-wmi-gamezone.rst create mode 100644 Documentation/wmi/devices/lenovo-wmi-other.rst diff --git a/Documentation/wmi/devices/lenovo-wmi-gamezone.rst b/Documentat= ion/wmi/devices/lenovo-wmi-gamezone.rst new file mode 100644 index 000000000000..997263e51a7d --- /dev/null +++ b/Documentation/wmi/devices/lenovo-wmi-gamezone.rst @@ -0,0 +1,203 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D +Lenovo WMI Interface Gamezone Driver (lenovo-wmi-gamezone) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +The Lenovo WMI gamezone interface is broken up into multiple GUIDs, +The primary "Gamezone" GUID provides advanced features such as fan +profiles and overclocking. It is paired with multiple event GUIDs +and data block GUIDs that provide context for the various methods. + +Gamezone Data +------------- + +WMI GUID ``887B54E3-DDDC-4B2C-8B88-68A26A8835D0`` + +The Gamezone Data WMI interface provides platform-profile and fan curve +settings for devices that fall under the "Gaming Series" of Lenovo devices. +It uses a notifier chain to inform other Lenovo WMI interface drivers of t= he +current platform profile when it changes. + +The following platform profiles are supported: + - low-power + - balanced + - balanced-performance + - performance + - custom + +Balanced-Performance +~~~~~~~~~~~~~~~~~~~~ +Some newer Lenovo "Gaming Series" laptops have an "Extreme Mode" profile +enabled in their BIOS. For these devices, the performance platform profile +corresponds to the BIOS Extreme Mode, while the balanced-performance +platform profile corresponds to the BIOS Performance mode. For legacy +devices, the performance platform profile will correspond with the BIOS +Performance mode. + +For some newer devices the "Extreme Mode" profile is incomplete in the BIOS +and setting it will cause undefined behavior. A BIOS bug quirk table is +provided to ensure these devices cannot set "Extreme Mode" from the driver. + +Custom Profile +~~~~~~~~~~~~~~ +The custom profile represents a hardware mode on Lenovo devices that enabl= es +user modifications to Package Power Tracking (PPT) and fan curve settings. +When an attribute exposed by the Other Mode WMI interface is to be modifie= d, +the Gamezone driver must first be switched to the "custom" profile manuall= y, +or the setting will have no effect. If another profile is set from the list +of supported profiles, the BIOS will override any user PPT settings when +switching to that profile. + +Gamezone Thermal Mode Event +--------------------------- + +WMI GUID ``D320289E-8FEA-41E0-86F9-911D83151B5F`` + +The Gamezone Thermal Mode Event interface notifies the system when the pla= tform +profile has changed, either through the hardware event (Fn+Q for laptops or +Legion + Y for Go Series), or through the Gamezone WMI interface. This eve= nt is +implemented in the Lenovo WMI Events driver (lenovo-wmi-events). + + +WMI interface description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +The WMI interface description can be decoded from the embedded binary MOF = (bmof) +data using the `bmfdec `_ utility: + +:: + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("LE= NOVO_GAMEZONE_DATA class"), guid("{887B54E3-DDDC-4B2C-8B88-68A26A8835D0}")] + class LENOVO_GAMEZONE_DATA { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiMethodId(4), Implemented, Description("Is SupportGpu OverClock")] = void IsSupportGpuOC([out, Description("Is SupportGpu OverClock")] uint32 Da= ta); + [WmiMethodId(11), Implemented, Description("Get AslCode Version")] voi= d GetVersion ([out, Description("AslCode version")] UINT32 Data); + [WmiMethodId(12), Implemented, Description("Fan cooling capability")] = void IsSupportFanCooling([out, Description("Fan cooling capability")] UINT3= 2 Data); + [WmiMethodId(13), Implemented, Description("Set Fan cooling on/off")] = void SetFanCooling ([in, Description("Set Fan cooling on/off")] UINT32 Data= ); + [WmiMethodId(14), Implemented, Description("cpu oc capability")] void = IsSupportCpuOC ([out, Description("cpu oc capability")] UINT32 Data); + [WmiMethodId(15), Implemented, Description("bios has overclock capabil= ity")] void IsBIOSSupportOC ([out, Description("bios has overclock capabili= ty")] UINT32 Data); + [WmiMethodId(16), Implemented, Description("enable or disable overcloc= k in bios")] void SetBIOSOC ([in, Description("enable or disable overclock = in bios")] UINT32 Data); + [WmiMethodId(18), Implemented, Description("Get CPU temperature")] voi= d GetCPUTemp ([out, Description("Get CPU temperature")] UINT32 Data); + [WmiMethodId(19), Implemented, Description("Get GPU temperature")] voi= d GetGPUTemp ([out, Description("Get GPU temperature")] UINT32 Data); + [WmiMethodId(20), Implemented, Description("Get Fan cooling on/off sta= tus")] void GetFanCoolingStatus ([out, Description("Get Fan cooling on/off = status")] UINT32 Data); + [WmiMethodId(21), Implemented, Description("EC support disable windows= key capability")] void IsSupportDisableWinKey ([out, Description("EC suppo= rt disable windows key capability")] UINT32 Data); + [WmiMethodId(22), Implemented, Description("Set windows key disable/en= able")] void SetWinKeyStatus ([in, Description("Set windows key disable/ena= ble")] UINT32 Data); + [WmiMethodId(23), Implemented, Description("Get windows key disable/en= able status")] void GetWinKeyStatus ([out, Description("Get windows key dis= able/enable status")] UINT32 Data); + [WmiMethodId(24), Implemented, Description("EC support disable touchpa= d capability")] void IsSupportDisableTP ([out, Description("EC support disa= ble touchpad capability")] UINT32 Data); + [WmiMethodId(25), Implemented, Description("Set touchpad disable/enabl= e")] void SetTPStatus ([in, Description("Set touchpad disable/enable")] UIN= T32 Data); + [WmiMethodId(26), Implemented, Description("Get touchpad disable/enabl= e status")] void GetTPStatus ([out, Description("Get touchpad disable/enabl= e status")] UINT32 Data); + [WmiMethodId(30), Implemented, Description("Get Keyboard feature list"= )] void GetKeyboardfeaturelist ([out, Description("Get Keyboard feature lis= t")] UINT32 Data); + [WmiMethodId(31), Implemented, Description("Get Memory OC Information"= )] void GetMemoryOCInfo ([out, Description("Get Memory OC Information")] UI= NT32 Data); + [WmiMethodId(32), Implemented, Description("Water Cooling feature capa= bility")] void IsSupportWaterCooling ([out, Description("Water Cooling feat= ure capability")] UINT32 Data); + [WmiMethodId(33), Implemented, Description("Set Water Cooling status")= ] void SetWaterCoolingStatus ([in, Description("Set Water Cooling status")]= UINT32 Data); + [WmiMethodId(34), Implemented, Description("Get Water Cooling status")= ] void GetWaterCoolingStatus ([out, Description("Get Water Cooling status")= ] UINT32 Data); + [WmiMethodId(35), Implemented, Description("Lighting feature capabilit= y")] void IsSupportLightingFeature ([out, Description("Lighting feature cap= ability")] UINT32 Data); + [WmiMethodId(36), Implemented, Description("Set keyboard light off or = on to max")] void SetKeyboardLight ([in, Description("keyboard light off or= on switch")] UINT32 Data); + [WmiMethodId(37), Implemented, Description("Get keyboard light on/off = status")] void GetKeyboardLight ([out, Description("Get keyboard light on/o= ff status")] UINT32 Data); + [WmiMethodId(38), Implemented, Description("Get Macrokey scan code")] = void GetMacrokeyScancode ([in, Description("Macrokey index")] UINT32 idx, [= out, Description("Scan code")] UINT32 scancode); + [WmiMethodId(39), Implemented, Description("Get Macrokey count")] void= GetMacrokeyCount ([out, Description("Macrokey count")] UINT32 Data); + [WmiMethodId(40), Implemented, Description("Support G-Sync feature")] = void IsSupportGSync ([out, Description("Support G-Sync feature")] UINT32 Da= ta); + [WmiMethodId(41), Implemented, Description("Get G-Sync Status")] void = GetGSyncStatus ([out, Description("Get G-Sync Status")] UINT32 Data); + [WmiMethodId(42), Implemented, Description("Set G-Sync Status")] void = SetGSyncStatus ([in, Description("Set G-Sync Status")] UINT32 Data); + [WmiMethodId(43), Implemented, Description("Support Smart Fan feature"= )] void IsSupportSmartFan ([out, Description("Support Smart Fan feature")] = UINT32 Data); + [WmiMethodId(44), Implemented, Description("Set Smart Fan Mode")] void= SetSmartFanMode ([in, Description("Set Smart Fan Mode")] UINT32 Data); + [WmiMethodId(45), Implemented, Description("Get Smart Fan Mode")] void= GetSmartFanMode ([out, Description("Get Smart Fan Mode")] UINT32 Data); + [WmiMethodId(46), Implemented, Description("Get Smart Fan Setting Mode= ")] void GetSmartFanSetting ([out, Description("Get Smart Setting Mode")] U= INT32 Data); + [WmiMethodId(47), Implemented, Description("Get Power Charge Mode")] v= oid GetPowerChargeMode ([out, Description("Get Power Charge Mode")] UINT32 = Data); + [WmiMethodId(48), Implemented, Description("Get Gaming Product Info")]= void GetProductInfo ([out, Description("Get Gaming Product Info")] UINT32 = Data); + [WmiMethodId(49), Implemented, Description("Over Drive feature capabil= ity")] void IsSupportOD ([out, Description("Over Drive feature capability")= ] UINT32 Data); + [WmiMethodId(50), Implemented, Description("Get Over Drive status")] v= oid GetODStatus ([out, Description("Get Over Drive status")] UINT32 Data); + [WmiMethodId(51), Implemented, Description("Set Over Drive status")] v= oid SetODStatus ([in, Description("Set Over Drive status")] UINT32 Data); + [WmiMethodId(52), Implemented, Description("Set Light Control Owner")]= void SetLightControlOwner ([in, Description("Set Light Control Owner")] UI= NT32 Data); + [WmiMethodId(53), Implemented, Description("Set DDS Control Owner")] v= oid SetDDSControlOwner ([in, Description("Set DDS Control Owner")] UINT32 D= ata); + [WmiMethodId(54), Implemented, Description("Get the flag of restore OC= value")] void IsRestoreOCValue ([in, Description("Clean this flag")] UINT3= 2 idx, [out, Description("Restore oc value flag")] UINT32 Data); + [WmiMethodId(55), Implemented, Description("Get Real Thremal Mode")] v= oid GetThermalMode ([out, Description("Real Thremal Mode")] UINT32 Data); + [WmiMethodId(56), Implemented, Description("Get the OC switch status i= n BIOS")] void GetBIOSOCMode ([out, Description("OC Mode")] UINT32 Data); + [WmiMethodId(59), Implemented, Description("Get hardware info support = version")] void GetHardwareInfoSupportVersion ([out, Description("version")= ] UINT32 Data); + [WmiMethodId(60), Implemented, Description("Get Cpu core 0 max frequen= cy")] void GetCpuFrequency ([out, Description("frequency")] UINT32 Data); + [WmiMethodId(62), Implemented, Description("Check the Adapter type fit= for OC")] void IsACFitForOC ([out, Description("AC check result")] UINT32 = Data); + [WmiMethodId(63), Implemented, Description("Is support IGPU mode")] vo= id IsSupportIGPUMode ([out, Description("IGPU modes")] UINT32 Data); + [WmiMethodId(64), Implemented, Description("Get IGPU Mode Status")] vo= id GetIGPUModeStatus([out, Description("IGPU Mode Status")] UINT32 Data); + [WmiMethodId(65), Implemented, Description("Set IGPU Mode")] void SetI= GPUModeStatus([in, Description("IGPU Mode")] UINT32 mode, [out, Description= ("return code")] UINT32 Data); + [WmiMethodId(66), Implemented, Description("Notify DGPU Status")] void= NotifyDGPUStatus([in, Description("DGPU status")] UINT32 status, [out, Des= cription("return code")] UINT32 Data); + [WmiMethodId(67), Implemented, Description("Is changed Y log")] void I= sChangedYLog([out, Description("Is changed Y Log")] UINT32 Data); + [WmiMethodId(68), Implemented, Description("Get DGPU Hardwawre ID")] v= oid GetDGPUHWId([out, Description("Get DGPU Hardware ID")] string Data); + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("De= finition of CPU OC parameter list"), guid("{B7F3CA0A-ACDC-42D2-9217-77C6C62= 8FBD2}")] + class LENOVO_GAMEZONE_CPU_OC_DATA { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("OC tune id.")] uint32 Tuneid; + [WmiDataId(2), read, Description("Default value.")] uint32 DefaultValu= e; + [WmiDataId(3), read, Description("OC Value.")] uint32 OCValue; + [WmiDataId(4), read, Description("Min Value.")] uint32 MinValue; + [WmiDataId(5), read, Description("Max Value.")] uint32 MaxValue; + [WmiDataId(6), read, Description("Scale Value.")] uint32 ScaleValue; + [WmiDataId(7), read, Description("OC Order id.")] uint32 OCOrderid; + [WmiDataId(8), read, Description("NON-OC Order id.")] uint32 NOCOrderi= d; + [WmiDataId(9), read, Description("Delay time in ms.")] uint32 Interval; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("De= finition of GPU OC parameter list"), guid("{887B54E2-DDDC-4B2C-8B88-68A26A8= 835D0}")] + class LENOVO_GAMEZONE_GPU_OC_DATA { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("P-State ID.")] uint32 PStateID; + [WmiDataId(2), read, Description("CLOCK ID.")] uint32 ClockID; + [WmiDataId(3), read, Description("Default value.")] uint32 defaultvalu= e; + [WmiDataId(4), read, Description("OC Offset freqency.")] uint32 OCOffs= etFreq; + [WmiDataId(5), read, Description("OC Min offset value.")] uint32 OCMin= Offset; + [WmiDataId(6), read, Description("OC Max offset value.")] uint32 OCMax= Offset; + [WmiDataId(7), read, Description("OC Offset Scale.")] uint32 OCOffsetS= cale; + [WmiDataId(8), read, Description("OC Order id.")] uint32 OCOrderid; + [WmiDataId(9), read, Description("NON-OC Order id.")] uint32 NOCOrderi= d; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("Fa= ncooling finish event"), guid("{BC72A435-E8C1-4275-B3E2-D8B8074ABA59}")] + class LENOVO_GAMEZONE_FAN_COOLING_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("Fancooling clean finish event")] uin= t32 EventId; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("Sm= art Fan mode change event"), guid("{D320289E-8FEA-41E0-86F9-611D83151B5F}")] + class LENOVO_GAMEZONE_SMART_FAN_MODE_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("Smart Fan Mode change event")] uint3= 2 mode; + [WmiDataId(2), read, Description("version of FN+Q")] uint32 version; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("Sm= art Fan setting mode change event"), guid("{D320289E-8FEA-41E1-86F9-611D831= 51B5F}")] + class LENOVO_GAMEZONE_SMART_FAN_SETTING_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("Smart Fan Setting mode change event"= )] uint32 mode; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("PO= WER CHARGE MODE Change EVENT"), guid("{D320289E-8FEA-41E0-86F9-711D83151B5F= }")] + class LENOVO_GAMEZONE_POWER_CHARGE_MODE_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("POWER CHARGE MODE Change EVENT")] ui= nt32 mode; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("Th= ermal Mode Real Mode change event"), guid("{D320289E-8FEA-41E0-86F9-911D831= 51B5F}")] + class LENOVO_GAMEZONE_THERMAL_MODE_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("Thermal Mode Real Mode")] uint32 mod= e; + }; diff --git a/Documentation/wmi/devices/lenovo-wmi-other.rst b/Documentation= /wmi/devices/lenovo-wmi-other.rst new file mode 100644 index 000000000000..d7928b8dfb4b --- /dev/null +++ b/Documentation/wmi/devices/lenovo-wmi-other.rst @@ -0,0 +1,108 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Lenovo WMI Interface Other Mode Driver (lenovo-wmi-other) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Lenovo WMI Other Mode interface is broken up into multiple GUIDs, +The primary Other Mode interface provides advanced power tuning features +such as Package Power Tracking (PPT). It is paired with multiple data block +GUIDs that provide context for the various methods. + + +Other Mode +---------- + +WMI GUID ``DC2A8805-3A8C-41BA-A6F7-092E0089CD3B`` + +The Other Mode WMI interface uses the firmware_attributes class to expose +various WMI attributes provided by the interface in the sysfs. This enables +CPU and GPU power limit tuning as well as various other attributes for +devices that fall under the "Gaming Series" of Lenovo devices. Each +attribute exposed by the Other Mode interface has corresponding +capability data blocks which allow the driver to probe details about the +attribute. Each attribute has multiple pages, one for each of the platform +profiles managed by the Gamezone interface. Attributes are exposed in sysfs +under the following path: + +:: + + /sys/class/firmware-attributes/lenovo-wmi-other/attributes// + +LENOVO_CAPABILITY_DATA_01 +------------------------- + +WMI GUID ``7A8F5407-CB67-4D6E-B547-39B3BE018154`` + +The LENOVO_CAPABILITY_DATA_01 interface provides information on various +power limits of integrated CPU and GPU components. + +Each attribute has the following properties: + - current_value + - default_value + - display_name + - max_value + - min_value + - scalar_increment + - type + +The following attributes are implemented: + - ppt_pl1_spl: Platform Profile Tracking Sustained Power Limit + - ppt_pl2_sppt: Platform Profile Tracking Slow Package Power Tracking + - ppt_pl3_fppt: Platform Profile Tracking Fast Package Power Tracking + + +WMI interface description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +The WMI interface description can be decoded from the embedded binary MOF = (bmof) +data using the `bmfdec `_ utility: + +:: + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("LE= NOVO_OTHER_METHOD class"), guid("{dc2a8805-3a8c-41ba-a6f7-092e0089cd3b}")] + class LENOVO_OTHER_METHOD { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiMethodId(17), Implemented, Description("Get Feature Value ")] void= GetFeatureValue([in] uint32 IDs, [out] uint32 value); + [WmiMethodId(18), Implemented, Description("Set Feature Value ")] void= SetFeatureValue([in] uint32 IDs, [in] uint32 value); + [WmiMethodId(19), Implemented, Description("Get Data By Command ")] vo= id GetDataByCommand([in] uint32 IDs, [in] uint32 Command, [out] uint32 Data= Size, [out, WmiSizeIs("DataSize")] uint32 Data[]); + [WmiMethodId(99), Implemented, Description("Get Data By Package for TA= C")] void GetDataByPackage([in, Max(40)] uint8 Input[], [out] uint32 DataSi= ze, [out, WmiSizeIs("DataSize")] uint8 Data[]); + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("LE= NOVO CAPABILITY DATA 00"), guid("{362a3afe-3d96-4665-8530-96dad5bb300e}")] + class LENOVO_CAPABILITY_DATA_00 { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description(" IDs.")] uint32 IDs; + [WmiDataId(2), read, Description("Capability.")] uint32 Capability; + [WmiDataId(3), read, Description("Capability Default Value.")] uint32 = DefaultValue; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("LE= NOVO CAPABILITY DATA 01"), guid("{7a8f5407-cb67-4d6e-b547-39b3be018154}")] + class LENOVO_CAPABILITY_DATA_01 { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description(" IDs.")] uint32 IDs; + [WmiDataId(2), read, Description("Capability.")] uint32 Capability; + [WmiDataId(3), read, Description("Default Value.")] uint32 DefaultValu= e; + [WmiDataId(4), read, Description("Step.")] uint32 Step; + [WmiDataId(5), read, Description("Minimum Value.")] uint32 MinValue; + [WmiDataId(6), read, Description("Maximum Value.")] uint32 MaxValue; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("LE= NOVO CAPABILITY DATA 02"), guid("{bbf1f790-6c2f-422b-bc8c-4e7369c7f6ab}")] + class LENOVO_CAPABILITY_DATA_02 { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description(" IDs.")] uint32 IDs; + [WmiDataId(2), read, Description("Capability.")] uint32 Capability; + [WmiDataId(3), read, Description("Data Size.")] uint32 DataSize; + [WmiDataId(4), read, Description("Default Value"), WmiSizeIs("DataSize= ")] uint8 DefaultValue[]; + }; diff --git a/MAINTAINERS b/MAINTAINERS index c14614613377..c202c67efa3c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13673,8 +13673,11 @@ F: drivers/usb/misc/legousbtower.c =20 LENOVO drivers M: Mark Pearson +M: Derek J. Clark L: platform-driver-x86@vger.kernel.org S: Maintained +F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst +F: Documentation/wmi/devices/lenovo-wmi-other.rst F: drivers/platform/x86/lenovo/* =20 LENOVO WMI HOTKEY UTILITIES DRIVER --=20 2.50.0 From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 9F0D61DEFC5; Wed, 2 Jul 2025 03:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427518; cv=none; b=C4OVoPc8p5SNWVlmBGkT3X/jHPo//lXkdaaG4NG/KCGWx9BwZxSsOVAki38+WDkcux3sPSovcQiT42c7JkX7ONm1DnfoQq7rXHmyCsPmb4rmMpALRMr1DDhdSvj9c7dqqwNsnCv43qPo0hUapgX1jTIkYmV42Qm696wNBsA2EBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427518; c=relaxed/simple; bh=X6dhvs+dX1KYOy99PeAYM3TOgvkDxZ4d9AZJQ0QPVSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nLf47HwrfOfJ40qLum7CNYH7S/omRjmYTzlFCL078JbvV+zD2LSv+BC9HFkZK78dJJtY61mXP4v41l1l+103laRad4ypv/QqhMqcDXT0SXGDREGiuANhASOLaGoSrcAvcAWjAl1Vj40JJlp57d1BdM3cJ2TvsMA2WQPL/xLO2lk= 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=ISji5JSu; arc=none smtp.client-ip=209.85.210.178 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="ISji5JSu" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-742c7a52e97so6337517b3a.3; Tue, 01 Jul 2025 20:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427516; x=1752032316; 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=iRC31Hg8+GiKl4jaSDHbF9Mujqfkmw958SdLk6uIIoU=; b=ISji5JSuC6hppTh14x7Ph1o8Qts1Ufp6XV/XrMYtB90Y8ArK4YeoyI2yq2ZiIU6f0S W0Azo4aUiHX30XTfwgRnSctTCSD6lXbLVLEx32iFqA+O07vGFWV6BHcKFrrv3jZOd8hL V4tguUReGEYbUPkhguHdEgn1tYQ/1jL1OVBO2//5Ga7SkJYrOgjHn6ehgVsGSCMD6A0Q M6Uk/NYl29LeHtyUqxPdp9WXEidI8ZmeQJ67IYCyxmvtRK3suiAwWO+nVqGRbEzeBXbS a60jxXDOodhFrmKmcP3MI+WfPHv0whWBXBSxZnNyrUFRSNQShB/ueoHRKIL2MvWVTAjK DauA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427516; x=1752032316; 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=iRC31Hg8+GiKl4jaSDHbF9Mujqfkmw958SdLk6uIIoU=; b=EhxxuFC+agE3+hlHQ9Ky+41B8JanDONg2OncSFCN0ld4bbvj0rY9tEk479n+SaxAyH qcZvOq0S3nmzwd8ohUt3sCDdG21SCfFG7fg8vixz7Y+69WUQzUxBybXNto22AG6UpIaq /xt6eCI2/VBWAFyHLBcPiAu0QG0J34820ZzaCjUxnV4ZDIZAzBgk6mxTugvHzO28gXy6 NeIJasLOqj2NhbmzowiEZ5b5uRnBe50KdvckQp+hLc3x6JXUHChe76tPCImaq0yx85Z/ WGJbR/rjxYf/oCVIDfll/KV3fpMgb7JkUd60h0Blh05rpDPbE32VkXblGyqIdJCS3wYd Wxyw== X-Forwarded-Encrypted: i=1; AJvYcCVUn2ln+Be0Dy88I7nso0jH66kqNUhFtVWJ7wTyLtDD65Wq8uRON83olWBsbwiEMSw9xeY0zSMgW2Dluc4G@vger.kernel.org, AJvYcCXGUXliYhrxpHJ1qR3XYVL37RfxQOgrZbvOhsJ4RfThC0FemFkElRVlx4gMvDqPjyyu3j0zUvQOQM3ZF2L1qythyc/QfQ==@vger.kernel.org, AJvYcCXqUhEsZZxqrnXgKjKHL/0hczXmIvK/QtFrR17Thv/GItOsz9Th87RVcK9SRsi/JRrtO+a0KxAEBlY=@vger.kernel.org X-Gm-Message-State: AOJu0YyeYYWlgnPD6Sp9Fk4uboJg0fPE+lWoRJLpOlk4bvQ1hHRhbvTr OD49pTLuADeNZFyQD4ZzmxqMC9wKxN6Qvxmu0yra/tXSl788oiD6fnP8 X-Gm-Gg: ASbGncv3slxJNFOpGp9rzBNPD/ajkXi18fq/nzp4FdaiUrjEkOWJRFm/3q2QftZdF7V FXEx+ZpESnfy+8gbADF2Xu5IadyNx1iABS/RhcQXZs7JBWJ+xb3BnPT0zRV3SOyEkdnMc509b1m umXgv5oW3nvNWIdJJNbOrtq9cB62vp6Ml8eWPrIdjmMwxObC9puHHMDbz7J8XCqC13CDyt3Xb7s 2dKHSQS3t750TsY7BTDirAF1ZMIZgn07BUoARBFpSqqRoI1L9ymW2b7Kr+RGNRZUKgpMACPoepH WuIOaAOPYNGi+OvsuSee9scT/9FAO2rbJJmg4M4Q+GT+LMpFUX5VZhJA4qV9HvNnRjHJbO3B0IM aEeCWWlEaR0hhDMX+NT6/6f1khSj/MACEQ0/vDD9xaTUKORi4PPiN X-Google-Smtp-Source: AGHT+IGB07kSHarDlzJTOMH9bv1YcCX6mrwnW0FiOczboaS0I3PUoLx0QX5N3Wn5FPgz/IfSWc9B2A== X-Received: by 2002:a05:6a21:7a82:b0:222:d62f:761a with SMTP id adf61e73a8af0-222d7f309bamr2225853637.42.1751427515731; Tue, 01 Jul 2025 20:38:35 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:35 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alok Tiwari , Mario Limonciello Subject: [PATCH v13 2/6] platform/x86: Add lenovo-wmi-helpers Date: Tue, 1 Jul 2025 20:38:22 -0700 Message-ID: <20250702033826.1057762-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-helpers, which provides a common wrapper function for wmidev_evaluate_method that does data validation and error handling. Reviewed-by: Alok Tiwari Reviewed-by: Armin Wolf Reviewed-by: Mario Limonciello Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move into new lenovo folder. v12: No change v11: - Formatting v10: No change v9: Fix missing newline before return in lwmi_dev_evaluate_int v8: No change v7: - Fix typos v6: - Fix typos and rewordings from v5 review. v5: - Fixes from v4 review. - Combine all previous methods into a single function that takes a buffer for the wmi method arguments. v4: - Changed namespace to LENOVO_WMI_HELPERS from LENOVO_WMI. - Changed filenames to lenovo-wmi-helpers from lenovo-wmi. - Removed structs and functions implemented by other drivers. --- --- drivers/platform/x86/lenovo/Kconfig | 4 ++ drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/wmi-helpers.c | 74 +++++++++++++++++++++++ drivers/platform/x86/lenovo/wmi-helpers.h | 20 ++++++ 4 files changed, 99 insertions(+) create mode 100644 drivers/platform/x86/lenovo/wmi-helpers.c create mode 100644 drivers/platform/x86/lenovo/wmi-helpers.h diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/len= ovo/Kconfig index 05dab29a22f7..abb488889834 100644 --- a/drivers/platform/x86/lenovo/Kconfig +++ b/drivers/platform/x86/lenovo/Kconfig @@ -232,3 +232,7 @@ config YT2_1380 =20 To compile this driver as a module, choose M here: the module will be called lenovo-yogabook. + +config LENOVO_WMI_HELPERS + tristate + depends on ACPI_WMI diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/le= novo/Makefile index f1aa2449293b..a347d657d235 100644 --- a/drivers/platform/x86/lenovo/Makefile +++ b/drivers/platform/x86/lenovo/Makefile @@ -12,6 +12,7 @@ lenovo-target-$(CONFIG_LENOVO_YMC) +=3D ymc.o lenovo-target-$(CONFIG_YOGABOOK) +=3D yogabook.o lenovo-target-$(CONFIG_YT2_1380) +=3D yoga-tab2-pro-1380-fastcharger.o lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) +=3D wmi-camera.o +lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) +=3D wmi-helpers.o =20 # Add 'lenovo' prefix to each module listed in lenovo-target-* define LENOVO_OBJ_TARGET diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x= 86/lenovo/wmi-helpers.c new file mode 100644 index 000000000000..f6fef6296251 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-helpers.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo Legion WMI helpers driver. + * + * The Lenovo Legion WMI interface is broken up into multiple GUID interfa= ces + * that require cross-references between GUID's for some functionality. The + * "Custom Mode" interface is a legacy interface for managing and displayi= ng + * CPU & GPU power and hwmon settings and readings. The "Other Mode" inter= face + * is a modern interface that replaces or extends the "Custom Mode" interf= ace + * methods. The "Gamezone" interface adds advanced features such as fan + * profiles and overclocking. The "Lighting" interface adds control of var= ious + * status lights related to different hardware components. Each of these + * drivers uses a common procedure to get data from the WMI interface, + * enumerated here. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include + +#include "wmi-helpers.h" + +/** + * lwmi_dev_evaluate_int() - Helper function for calling WMI methods that + * return an integer. + * @wdev: Pointer to the WMI device to be called. + * @instance: Instance of the called method. + * @method_id: WMI Method ID for the method to be called. + * @buf: Buffer of all arguments for the given method_id. + * @size: Length of the buffer. + * @retval: Pointer for the return value to be assigned. + * + * Calls wmidev_evaluate_method for Lenovo WMI devices that return an ACPI + * integer. Validates the return value type and assigns the value to the + * retval pointer. + * + * Return: 0 on success, or an error code. + */ +int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method= _id, + unsigned char *buf, size_t size, u32 *retval) +{ + struct acpi_buffer output =3D { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *ret_obj __free(kfree) =3D NULL; + struct acpi_buffer input =3D { size, buf }; + acpi_status status; + + status =3D wmidev_evaluate_method(wdev, instance, method_id, &input, + &output); + if (ACPI_FAILURE(status)) + return -EIO; + + if (retval) { + ret_obj =3D output.pointer; + if (!ret_obj) + return -ENODATA; + + if (ret_obj->type !=3D ACPI_TYPE_INTEGER) + return -ENXIO; + + *retval =3D (u32)ret_obj->integer.value; + } + + return 0; +}; +EXPORT_SYMBOL_NS_GPL(lwmi_dev_evaluate_int, "LENOVO_WMI_HELPERS"); + +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo WMI Helpers Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x= 86/lenovo/wmi-helpers.h new file mode 100644 index 000000000000..20fd21749803 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-helpers.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright (C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_HELPERS_H_ +#define _LENOVO_WMI_HELPERS_H_ + +#include + +struct wmi_device; + +struct wmi_method_args_32 { + u32 arg0; + u32 arg1; +}; + +int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method= _id, + unsigned char *buf, size_t size, u32 *retval); + +#endif /* !_LENOVO_WMI_HELPERS_H_ */ --=20 2.50.0 From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 15F681E1A3F; Wed, 2 Jul 2025 03:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427519; cv=none; b=DpDalSSP/b37+7C+jPw9SJDwTgRS50LNlFzlRSMnmUbDwJkwSM2PJZh+ICxCsR6JsiPGaCThScB3+6iQvi9tXtNnwtt+o6AChkGRX2ViNKU/fJ8Hi/yufNU8maxKrN2OXU4/1Y1bBlGg/dTULiH4ADjSOqEjo/XAUsz4SJm3FWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427519; c=relaxed/simple; bh=63UON5GugYnD9F7uv9G3HzmUPI0ms53w9qGWfOkbheg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLmqBpmFPJ0Z+F4BPWRJvnqWDLhOGTvqX8I0kFrUDcPZTJvn7cF/WRPpYtYEod2IMc7Aa54svn88SGPGyCnZPwkkbMY1LIy6l16jHxu3U41mV1yFzDlmD47F9QnDGRFwb2CneSNTTnD3DGLkjGdRkKuF+ukk3a7yC/uG3DFOBHo= 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=VLuxGrzv; arc=none smtp.client-ip=209.85.215.182 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="VLuxGrzv" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b34c068faf8so6793486a12.2; Tue, 01 Jul 2025 20:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427517; x=1752032317; 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=2oGoFKImDQInj564O85YMs7uWiNJR0eE35Kph48sqUI=; b=VLuxGrzvA0RSP1GXh0r/QwpeFMLTcyPUnWBNMXg9EfGLhm2HEQ78DGV19qeN7Hm6I/ CChnR99sGTDEej691v6+NZP3uM3u3JRf3OEw1YW9SqgKfabhM9/aCf95Y9WuX8NzxIsl 2e86lPuPIgHDGQvoI6hAs9NW/liODkjXyiswnuygesMii+VH12HfDF6+T94bsiBVoq4U 7q3rFtb84gorHbjy9inffnE59cpJUZYOarnghI1ykOnssZBVbJGT0FznaBA5UqQmmmXo La8UG4LyTa321Rr+cg0/7llgFh+jGFopDZ2yxFvhr1//74eP5yDssTrnUNEnSo4sTksW mr0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427517; x=1752032317; 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=2oGoFKImDQInj564O85YMs7uWiNJR0eE35Kph48sqUI=; b=uH59Ye1PnfL8C8eIfoufaCDfe7i1O7IEO5JGJFsP6SLkK4nEovIxICUpX+pQsGXxks VrclkyGssxK2sDTlwZuQl9t7Bmf4sFzJ2bel+62nwVEoZ+1N1+hdug8ecI0ZWRcneQX6 6b1z0f2VhJnZB/32bG4nwHs/Bdw17KPyiLWN1N7V45fk3a6Y4VgroVwshcECsSDfbHO6 ONTp65cA7iuBRsLvvrnGK06oea/MlEaHZPPhhcHDHEsnWqOSMPl4PlB+Hsa05hRlCsm1 QajugbUqOitRWx1O4bYoqfFz2t5r7CDEPZY/bM0vgVXNTL6InNPIr63q7c9tFmCkhly6 Eq3A== X-Forwarded-Encrypted: i=1; AJvYcCUTbmNH4Rk3YXIJEL5FQT9cATklqhlGpA98RE7pPg1IY2pEYXeiQ791kHQ3DuCZUueQdQknvfJeTduPCI1I2kNi0FXceA==@vger.kernel.org, AJvYcCVP/ZA49kIarAj2L8UkEMPs2/DPDUz9i0lH/k8zm4L32kCSfG8kZCXwv+0zGltnv0fXKbukqPppTtS7hCjl@vger.kernel.org, AJvYcCWuvSPhCJ2+Diw6zp7uM4d/VYEP/kFQNRq7ffCYVB5gy0xKDcam1XZtHUpiLNJpQ9qHVO+/99I5NVc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxfivs/fVyKb1eumGLT6+Wf2K7LLT/N6AmrLXJhWLBN+PvDXcqz cphQcM6XWqvUGuObO2Qr/G+cE+cK6RNOyX8bBG9SuEv5qa4Q4WraqHHO X-Gm-Gg: ASbGncu87fMLdlSLF1mROBJ5jTKeCp2+Tq/k4F82kynMGG/W1aUZydByyjyzdqqwv3n xIy2cu06gMgNIYq4yWrbGsM3z6IwuYX5Ffx1rvWp0f7l3uwaSyuTLg5ihmYdpzNsXJq0x44ZlPd uKsfsM8deXscGlrjqQu/hh/nFQVn0qOVBc3E6L2SO6p36pNkmAx0aIx0hje8PfocHAUPoRsNbzX rt26L/WFHeKMFVZmbFHcy5eWUBIHMz2S910Y6mJ52q7plfEl/CY8A8Nyc+gwySNtnxDVzYoqqdn l1NVwUvQG/WjRxLdmKIyUFZL9iS9AoxyLIfsomp4NEFV4wwN70UKZp0JxWR9s5fwcyk7sFWNqeb 4oJ6qLdEOGdluwCqT9j/UCDchJHZrKnaXuExHRlmxvnkPODLsFXpX X-Google-Smtp-Source: AGHT+IG1yzpagLY74dilDv7Hf7tH64Cu9QFNDcbolbKAf/QwzdnPMC6IcRvUG/5L1j0Ga7Zq5kd/kw== X-Received: by 2002:a05:6a21:2d8a:b0:222:d71e:d35f with SMTP id adf61e73a8af0-222d7e856damr2735564637.21.1751427517347; Tue, 01 Jul 2025 20:38:37 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:37 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alok Tiwari , Mario Limonciello Subject: [PATCH v13 3/6] platform/x86: Add Lenovo WMI Events Driver Date: Tue, 1 Jul 2025 20:38:23 -0700 Message-ID: <20250702033826.1057762-4-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-events driver. The events driver is designed as a general entrypoint for all Lenovo WMI Events. It acts as a notification chain head that will process event data and pass it on to registered drivers so they can react to the events. Currently only the Gamezone interface Thermal Mode Event GUID is implemented in this driver. It is documented in the Gamezone documentation. Suggested-by: Armin Wolf Reviewed-by: Alok Tiwari Reviewed-by: Armin Wolf Reviewed-by: Mario Limonciello Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move to new lenovo folder v12: No change v11: - Formatting v10: No change v9: No change v8: No change v7: - Fix typos v6: - Fix typos and rewordings to ensure consistancy in function description text. v5: - Fixes from v4 review. v4: - Remove the Thermal Mode Event GUID from Gamezone and add this driver. --- --- drivers/platform/x86/lenovo/Kconfig | 4 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/wmi-events.c | 196 +++++++++++++++++++++++ drivers/platform/x86/lenovo/wmi-events.h | 20 +++ 4 files changed, 221 insertions(+) create mode 100644 drivers/platform/x86/lenovo/wmi-events.c create mode 100644 drivers/platform/x86/lenovo/wmi-events.h diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/len= ovo/Kconfig index abb488889834..95dce00f257e 100644 --- a/drivers/platform/x86/lenovo/Kconfig +++ b/drivers/platform/x86/lenovo/Kconfig @@ -233,6 +233,10 @@ config YT2_1380 To compile this driver as a module, choose M here: the module will be called lenovo-yogabook. =20 +config LENOVO_WMI_EVENTS + tristate + depends on ACPI_WMI + config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/le= novo/Makefile index a347d657d235..814c4ba9bdbe 100644 --- a/drivers/platform/x86/lenovo/Makefile +++ b/drivers/platform/x86/lenovo/Makefile @@ -12,6 +12,7 @@ lenovo-target-$(CONFIG_LENOVO_YMC) +=3D ymc.o lenovo-target-$(CONFIG_YOGABOOK) +=3D yogabook.o lenovo-target-$(CONFIG_YT2_1380) +=3D yoga-tab2-pro-1380-fastcharger.o lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) +=3D wmi-camera.o +lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS) +=3D wmi-events.o lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) +=3D wmi-helpers.o =20 # Add 'lenovo' prefix to each module listed in lenovo-target-* diff --git a/drivers/platform/x86/lenovo/wmi-events.c b/drivers/platform/x8= 6/lenovo/wmi-events.c new file mode 100644 index 000000000000..0994cd7dd504 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-events.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo WMI Events driver. Lenovo WMI interfaces provide various + * hardware triggered events that many drivers need to have propagated. + * This driver provides a uniform entrypoint for these events so that + * any driver that needs to respond to these events can subscribe to a + * notifier chain. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include + +#include "wmi-events.h" +#include "wmi-gamezone.h" + +#define THERMAL_MODE_EVENT_GUID "D320289E-8FEA-41E0-86F9-911D83151B5F" + +#define LWMI_EVENT_DEVICE(guid, type) \ + .guid_string =3D (guid), .context =3D &(enum lwmi_events_type) \ + { \ + type \ + } + +static BLOCKING_NOTIFIER_HEAD(events_chain_head); + +struct lwmi_events_priv { + struct wmi_device *wdev; + enum lwmi_events_type type; +}; + +/** + * lwmi_events_register_notifier() - Add a notifier to the notifier chain. + * @nb: The notifier_block struct to register + * + * Call blocking_notifier_chain_register to register the notifier block to= the + * lenovo-wmi-events driver blocking notifier chain. + * + * Return: 0 on success, %-EEXIST on error. + */ +int lwmi_events_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&events_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_events_register_notifier, "LENOVO_WMI_EVENTS"); + +/** + * lwmi_events_unregister_notifier() - Remove a notifier from the notifier + * chain. + * @nb: The notifier_block struct to unregister + * + * Call blocking_notifier_chain_unregister to unregister the notifier block + * from the lenovo-wmi-events driver blocking notifier chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +int lwmi_events_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&events_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_events_unregister_notifier, "LENOVO_WMI_EVENTS"); + +/** + * devm_lwmi_events_unregister_notifier() - Remove a notifier from the not= ifier + * chain. + * @data: Void pointer to the notifier_block struct to unregister. + * + * Call lwmi_events_unregister_notifier to unregister the notifier block f= rom + * the lenovo-wmi-events driver blocking notifier chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +static void devm_lwmi_events_unregister_notifier(void *data) +{ + struct notifier_block *nb =3D data; + + lwmi_events_unregister_notifier(nb); +} + +/** + * devm_lwmi_events_register_notifier() - Add a notifier to the notifier c= hain. + * @dev: The parent device of the notifier_block struct. + * @nb: The notifier_block struct to register + * + * Call lwmi_events_register_notifier to register the notifier block to the + * lenovo-wmi-events driver blocking notifier chain. Then add, as a device + * managed action, unregister_notifier to automatically unregister the + * notifier block upon its parent device removal. + * + * Return: 0 on success, or an error code. + */ +int devm_lwmi_events_register_notifier(struct device *dev, + struct notifier_block *nb) +{ + int ret; + + ret =3D lwmi_events_register_notifier(nb); + if (ret < 0) + return ret; + + return devm_add_action_or_reset(dev, devm_lwmi_events_unregister_notifier= , nb); +} +EXPORT_SYMBOL_NS_GPL(devm_lwmi_events_register_notifier, "LENOVO_WMI_EVENT= S"); + +/** + * lwmi_events_notify() - Call functions for the notifier call chain. + * @wdev: The parent WMI device of the driver. + * @obj: ACPI object passed by the registered WMI Event. + * + * Validate WMI event data and notify all registered drivers of the event = and + * its output. + * + * Return: 0 on success, or an error code. + */ +static void lwmi_events_notify(struct wmi_device *wdev, union acpi_object = *obj) +{ + struct lwmi_events_priv *priv =3D dev_get_drvdata(&wdev->dev); + int sel_prof; + int ret; + + switch (priv->type) { + case LWMI_EVENT_THERMAL_MODE: + if (obj->type !=3D ACPI_TYPE_INTEGER) + return; + + sel_prof =3D obj->integer.value; + + switch (sel_prof) { + case LWMI_GZ_THERMAL_MODE_QUIET: + case LWMI_GZ_THERMAL_MODE_BALANCED: + case LWMI_GZ_THERMAL_MODE_PERFORMANCE: + case LWMI_GZ_THERMAL_MODE_EXTREME: + case LWMI_GZ_THERMAL_MODE_CUSTOM: + ret =3D blocking_notifier_call_chain(&events_chain_head, + LWMI_EVENT_THERMAL_MODE, + &sel_prof); + if (ret =3D=3D NOTIFY_BAD) + dev_err(&wdev->dev, + "Failed to send notification to call chain for WMI Events\n"); + return; + default: + dev_err(&wdev->dev, "Got invalid thermal mode: %x", + sel_prof); + return; + } + break; + default: + return; + } +} + +static int lwmi_events_probe(struct wmi_device *wdev, const void *context) +{ + struct lwmi_events_priv *priv; + + if (!context) + return -EINVAL; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->wdev =3D wdev; + priv->type =3D *(enum lwmi_events_type *)context; + dev_set_drvdata(&wdev->dev, priv); + + return 0; +} + +static const struct wmi_device_id lwmi_events_id_table[] =3D { + { LWMI_EVENT_DEVICE(THERMAL_MODE_EVENT_GUID, LWMI_EVENT_THERMAL_MODE) }, + {} +}; + +static struct wmi_driver lwmi_events_driver =3D { + .driver =3D { + .name =3D "lenovo_wmi_events", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lwmi_events_id_table, + .probe =3D lwmi_events_probe, + .notify =3D lwmi_events_notify, + .no_singleton =3D true, +}; + +module_wmi_driver(lwmi_events_driver); + +MODULE_DEVICE_TABLE(wmi, lwmi_events_id_table); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo WMI Events Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo/wmi-events.h b/drivers/platform/x8= 6/lenovo/wmi-events.h new file mode 100644 index 000000000000..cd34e886912c --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-events.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright (C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_EVENTS_H_ +#define _LENOVO_WMI_EVENTS_H_ + +struct device; +struct notifier_block; + +enum lwmi_events_type { + LWMI_EVENT_THERMAL_MODE =3D 1, +}; + +int lwmi_events_register_notifier(struct notifier_block *nb); +int lwmi_events_unregister_notifier(struct notifier_block *nb); +int devm_lwmi_events_register_notifier(struct device *dev, + struct notifier_block *nb); + +#endif /* !_LENOVO_WMI_EVENTS_H_ */ --=20 2.50.0 From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 A67F31E521E; Wed, 2 Jul 2025 03:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427521; cv=none; b=CjHVa8EONJ/EeNBia8nl1i4fzM1gZzxENAb8xICGrNITFCkKQ6B0QptUSDQF7UwBvjVwfBPGTjKsZkzeqvEzP9yFYxFsQyNjX5/LY4ZJ+VyONRjtf1Hu6j3eUrmmOyzXZYn3DATKWXB/S/IExmbbbBis30aP9ZaeVRWdDWPvW1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427521; c=relaxed/simple; bh=UXyFGMczY2vnUK1fHDakNnTifLrkOwkeZqOUHwQKick=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOywsKl+6aE6GqF50yYxgQ22Er2V5bk2FflUT1nzszbKEzBrAMI+6kbafs25tA5R1fi+5MdhEXXQHJjae2Ifj3PoR6ccQNQaMlhWVyKqRKIppLQE/SSR7eLDcVVQoCO5+/xzieKKXlA9uEDTuW8Ba5a1KuCbrdQJTFUSXpySnYw= 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=I3mLJayc; arc=none smtp.client-ip=209.85.210.173 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="I3mLJayc" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7490acf57b9so3064779b3a.2; Tue, 01 Jul 2025 20:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427519; x=1752032319; 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=7HAs6coMNCNUbXXVPUcvfTbpVoqKAThZUcEDvY+zXVY=; b=I3mLJaycjJ/JU/PYXzdWE02wia4qbuQXA/Drf0Q50rfWzhdWhr+tE/JEZnFtJhGVpt kG9NDnxlBIKI9YZt5Gs2O/gwH6W+EUx1cb9KCJMS5o+VuAvzy1sSLFAe+ZkNfEUVTJMo lTPLOaN6bEKFrIbcTMk0VA2nJGAxEGHW3l8ShxWTxqfx8SOz/vAf9vISTFL046qFE/KL jM41O6aN5nD5Ghkjn6/oGElX38uAIlFo5H4BSeVGtVz3GOCH1gEa5bCRMrcUBTJbXZpG x1abUiruataH/05W89FmLrt9M0ejIkDcgwkLZHZ0eiXO7H3a5ZRDr6NLzsIsvGPgPaWm nQnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427519; x=1752032319; 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=7HAs6coMNCNUbXXVPUcvfTbpVoqKAThZUcEDvY+zXVY=; b=bH73Y+TqcRqwiFiLadgThjqf8C+6IM6JH/i3uZ+4fiLF/u6GYODrZQvApEDaSxLL6m uCn+H+ptNDYjCHxwcx3ykILrcfr9/2mFYddlovQPjvp8A+E0ocKI2mgEXxbv90+wxeIC YbqQQ5uO7ePrePS6xB/ogq1TQX6XFrjqQ8ifMdDXbbNPwhfRD/GRG/xGItEhurMT5Vvr tgfusMa+sHYMtukOaU7ddc6l8t7LLA4BHiaYGvby61Ch60+RfQfreO+4E+5CV6YsYm0d p7hIKcFN3uS/kRBqe+2AeJ/hxuX3z7+CwZzGYfIVQ5jyPTHUzcMYPk76y7Qw0MHo4rA2 NRPQ== X-Forwarded-Encrypted: i=1; AJvYcCUWwULYsu4HBc5QU5qRNsK9VQEMsYWkVF+Kt9Q83CoXjyyEKhXQTS2atZlmdA5j5vVIjUxYINNqDZ9OzfWfcBUjTsDzbw==@vger.kernel.org, AJvYcCVVIGbYtYgPFVOSYd/xwEtx8ggSRuToiBtIOnqFVIzMgjZ33bdaOFJFcWt6eujYfwgepCmQ73Y5xIRAoKv2@vger.kernel.org, AJvYcCWux6/qU2Cg8K8A6COKs96iojh4Rqs7PLez4vMXN97sydbRUgK70f/V+oODDqkhFCiGPqeC6VVvEmE=@vger.kernel.org X-Gm-Message-State: AOJu0YyJWOLl389ZUkO87iyzvgAH6vd3dCsV/4LAwglYA5Dc0ePc4xFS VM8muIoqMT8KlUYPvXh4EodxrbnwR7NMD0L7+/aOFHD6hjcwDpEvxyHR X-Gm-Gg: ASbGnct2fvbRKqXnZ0H4d5WycqheJpu7PW2WOiwtnT9M/wwPZCCTDe2qNQ/ycJN7Yb9 X0EU1zL2/4PyUYnTZhQgdkFAYZGVd/wOX9k2r1BX6+Mkkmtd1FP+vQC02eR3dteEaGTADu67Aco DuJ8Hu5MDUBiJaEKcv/mbu2/K3mskNyPTSOlPF9EgQfAwFwE7JHOyiB4JdBUsiQEgVogDBYxo2W 5/7t0qeyBGTVepDjXb/75TtBQ5hb0ecdxCRP4CNCw2L1XfHlQRv+n3pZcSQayWK8h7OWJdkwCRZ 6Az2/Ewsl0gvlQek/QFsstFFbv9biKPIGEjQdSGxD7+3C6u3DhubL2P7pt2lJsOSoscqDmHyBpG Kry2bdrd8oVzt459VKxmTgFj6t3+TzUE9SlzIqq8H5Q== X-Google-Smtp-Source: AGHT+IGGe4M4U7OBfA9psOAzVGhGgbU5Kj/0jTjp0mRTd8Eqj7keOjO1bfoBIMFURw++Qz+CsfCWVg== X-Received: by 2002:a05:6a21:7a47:b0:21a:eabb:ab93 with SMTP id adf61e73a8af0-222d7dc4670mr2816095637.6.1751427518963; Tue, 01 Jul 2025 20:38:38 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:38 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alok Tiwari Subject: [PATCH v13 4/6] platform/x86: Add Lenovo Capability Data 01 WMI Driver Date: Tue, 1 Jul 2025 20:38:24 -0700 Message-ID: <20250702033826.1057762-5-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-capdata01 driver which provides the LENOVO_CAPABILITY_DATA_01 WMI data block that comes on "Other Mode" enabled hardware. Provides an interface for querying if a given attribute is supported by the hardware, as well as its default_value, max_value, min_value, and step increment. Reviewed-by: Alok Tiwari Reviewed-by: Armin Wolf Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move to new lenovo folder v12: - Fix warnings from make W=3D1 v11: - Formatting v10: No change v9: - Check result of devm_mutex_init. v8: - Use devm_mutex_init() instead of mutex_init(). - Check return of devm_add_action_or_reset during probe. - Don't check if cd01 list exists in bind as the driver will bail if there is a malloc/populating issue prior to bind. - Fix typos. v7: - Do memcpy instead of returning pointer in lwmi_cd01_get_data. - Put list mutex inside lwmi_cd01_priv struct. - Unregister from acpi events on dev remove. - Fix typos. v6: - Recache capabiltiy data on ACPI AC events to ensure accutare max_value. - Fix typos and rewordings from v5 review. v5: - Return to cache at device initialization. On component bind, pass a pointer to lenovo-wmi-other. - Fixes from v4 review. v4: - Make driver data a private struct, remove references from Other Mode driver. - Don't cache data at device initialization. Instead, on component bind, cache the data on a member variable of the Other Mode driver data passed as a void pointer. - Add header file for capdata01 structs. - Add new struct to pass capdata01 array data and array length to Other Mode. v3: - Add as component to lenovo-wmi-other driver. v2: - Use devm_kmalloc to ensure driver can be instanced, remove global reference. - Ensure reverse Christmas tree for all variable declarations. - Remove extra whitespace. - Use guard(mutex) in all mutex instances, global mutex. - Use pr_fmt instead of adding the driver name to each pr_err. - Remove noisy pr_info usage. - Rename capdata_wmi to lenovo_wmi_cd01_priv and cd01_wmi to priv. - Use list to get the lenovo_wmi_cd01_priv instance in lenovo_wmi_capdata01_get as none of the data provided by the macros that will use it can pass a member of the struct for use in container_of. --- --- drivers/platform/x86/lenovo/Kconfig | 4 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/wmi-capdata01.c | 302 ++++++++++++++++++++ drivers/platform/x86/lenovo/wmi-capdata01.h | 25 ++ 4 files changed, 332 insertions(+) create mode 100644 drivers/platform/x86/lenovo/wmi-capdata01.c create mode 100644 drivers/platform/x86/lenovo/wmi-capdata01.h diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/len= ovo/Kconfig index 95dce00f257e..1943e3a24f43 100644 --- a/drivers/platform/x86/lenovo/Kconfig +++ b/drivers/platform/x86/lenovo/Kconfig @@ -233,6 +233,10 @@ config YT2_1380 To compile this driver as a module, choose M here: the module will be called lenovo-yogabook. =20 +config LENOVO_WMI_DATA01 + tristate + depends on ACPI_WMI + config LENOVO_WMI_EVENTS tristate depends on ACPI_WMI diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/le= novo/Makefile index 814c4ba9bdbe..1ce970e4ddb8 100644 --- a/drivers/platform/x86/lenovo/Makefile +++ b/drivers/platform/x86/lenovo/Makefile @@ -12,6 +12,7 @@ lenovo-target-$(CONFIG_LENOVO_YMC) +=3D ymc.o lenovo-target-$(CONFIG_YOGABOOK) +=3D yogabook.o lenovo-target-$(CONFIG_YT2_1380) +=3D yoga-tab2-pro-1380-fastcharger.o lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) +=3D wmi-camera.o +lenovo-target-$(CONFIG_LENOVO_WMI_DATA01) +=3D wmi-capdata01.o lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS) +=3D wmi-events.o lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) +=3D wmi-helpers.o =20 diff --git a/drivers/platform/x86/lenovo/wmi-capdata01.c b/drivers/platform= /x86/lenovo/wmi-capdata01.c new file mode 100644 index 000000000000..c922680b3cba --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-capdata01.c @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo Capability Data 01 WMI Data Block driver. + * + * Lenovo Capability Data 01 provides information on tunable attributes us= ed by + * the "Other Mode" WMI interface. The data includes if the attribute is + * supported by the hardware, the default_value, max_value, min_value, and= step + * increment. Each attribute has multiple pages, one for each of the therm= al + * modes managed by the Gamezone interface. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wmi-capdata01.h" + +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE0181= 54" + +#define ACPI_AC_CLASS "ac_adapter" +#define ACPI_AC_NOTIFY_STATUS 0x80 + +struct lwmi_cd01_priv { + struct notifier_block acpi_nb; /* ACPI events */ + struct wmi_device *wdev; + struct cd01_list *list; +}; + +struct cd01_list { + struct mutex list_mutex; /* list R/W mutex */ + u8 count; + struct capdata01 data[]; +}; + +/** + * lwmi_cd01_component_bind() - Bind component to master device. + * @cd01_dev: Pointer to the lenovo-wmi-capdata01 driver parent device. + * @om_dev: Pointer to the lenovo-wmi-other driver parent device. + * @data: capdata01_list object pointer used to return the capability data. + * + * On lenovo-wmi-other's master bind, provide a pointer to the local capda= ta01 + * list. This is used to call lwmi_cd01_get_data to look up attribute data + * from the lenovo-wmi-other driver. + * + * Return: 0 + */ +static int lwmi_cd01_component_bind(struct device *cd01_dev, + struct device *om_dev, void *data) +{ + struct lwmi_cd01_priv *priv =3D dev_get_drvdata(cd01_dev); + struct cd01_list **cd01_list =3D data; + + *cd01_list =3D priv->list; + + return 0; +} + +static const struct component_ops lwmi_cd01_component_ops =3D { + .bind =3D lwmi_cd01_component_bind, +}; + +/** + * lwmi_cd01_get_data - Get the data of the specified attribute + * @list: The lenovo-wmi-capdata01 pointer to its cd01_list struct. + * @attribute_id: The capdata attribute ID to be found. + * @output: Pointer to a capdata01 struct to return the data. + * + * Retrieves the capability data 01 struct pointer for the given + * attribute for its specified thermal mode. + * + * Return: 0 on success, or -EINVAL. + */ +int lwmi_cd01_get_data(struct cd01_list *list, u32 attribute_id, struct ca= pdata01 *output) +{ + u8 idx; + + guard(mutex)(&list->list_mutex); + for (idx =3D 0; idx < list->count; idx++) { + if (list->data[idx].id !=3D attribute_id) + continue; + memcpy(output, &list->data[idx], sizeof(list->data[idx])); + return 0; + }; + + return -EINVAL; +} +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_get_data, "LENOVO_WMI_CD01"); + +/** + * lwmi_cd01_cache() - Cache all WMI data block information + * @priv: lenovo-wmi-capdata01 driver data. + * + * Loop through each WMI data block and cache the data. + * + * Return: 0 on success, or an error. + */ +static int lwmi_cd01_cache(struct lwmi_cd01_priv *priv) +{ + int idx; + + guard(mutex)(&priv->list->list_mutex); + for (idx =3D 0; idx < priv->list->count; idx++) { + union acpi_object *ret_obj __free(kfree) =3D NULL; + + ret_obj =3D wmidev_block_query(priv->wdev, idx); + if (!ret_obj) + return -ENODEV; + + if (ret_obj->type !=3D ACPI_TYPE_BUFFER || + ret_obj->buffer.length < sizeof(priv->list->data[idx])) + continue; + + memcpy(&priv->list->data[idx], ret_obj->buffer.pointer, + ret_obj->buffer.length); + } + + return 0; +} + +/** + * lwmi_cd01_alloc() - Allocate a cd01_list struct in drvdata + * @priv: lenovo-wmi-capdata01 driver data. + * + * Allocate a cd01_list struct large enough to contain data from all WMI d= ata + * blocks provided by the interface. + * + * Return: 0 on success, or an error. + */ +static int lwmi_cd01_alloc(struct lwmi_cd01_priv *priv) +{ + struct cd01_list *list; + size_t list_size; + int count, ret; + + count =3D wmidev_instance_count(priv->wdev); + list_size =3D struct_size(list, data, count); + + list =3D devm_kzalloc(&priv->wdev->dev, list_size, GFP_KERNEL); + if (!list) + return -ENOMEM; + + ret =3D devm_mutex_init(&priv->wdev->dev, &list->list_mutex); + if (ret) + return ret; + + list->count =3D count; + priv->list =3D list; + + return 0; +} + +/** + * lwmi_cd01_setup() - Cache all WMI data block information + * @priv: lenovo-wmi-capdata01 driver data. + * + * Allocate a cd01_list struct large enough to contain data from all WMI d= ata + * blocks provided by the interface. Then loop through each data block and + * cache the data. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_cd01_setup(struct lwmi_cd01_priv *priv) +{ + int ret; + + ret =3D lwmi_cd01_alloc(priv); + if (ret) + return ret; + + return lwmi_cd01_cache(priv); +} + +/** + * lwmi_cd01_notifier_call() - Call method for lenovo-wmi-capdata01 driver= notifier. + * block call chain. + * @nb: The notifier_block registered to lenovo-wmi-events driver. + * @action: Unused. + * @data: The ACPI event. + * + * For LWMI_EVENT_THERMAL_MODE, set current_mode and notify platform_profi= le + * of a change. + * + * Return: notifier_block status. + */ +static int lwmi_cd01_notifier_call(struct notifier_block *nb, unsigned lon= g action, + void *data) +{ + struct acpi_bus_event *event =3D data; + struct lwmi_cd01_priv *priv; + int ret; + + if (strcmp(event->device_class, ACPI_AC_CLASS) !=3D 0) + return NOTIFY_DONE; + + priv =3D container_of(nb, struct lwmi_cd01_priv, acpi_nb); + + switch (event->type) { + case ACPI_AC_NOTIFY_STATUS: + ret =3D lwmi_cd01_cache(priv); + if (ret) + return NOTIFY_BAD; + + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +/** + * lwmi_cd01_unregister() - Unregister the cd01 ACPI notifier_block. + * @data: The ACPI event notifier_block to unregister. + */ +static void lwmi_cd01_unregister(void *data) +{ + struct notifier_block *acpi_nb =3D data; + + unregister_acpi_notifier(acpi_nb); +} + +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context) + +{ + struct lwmi_cd01_priv *priv; + int ret; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->wdev =3D wdev; + dev_set_drvdata(&wdev->dev, priv); + + ret =3D lwmi_cd01_setup(priv); + if (ret) + return ret; + + priv->acpi_nb.notifier_call =3D lwmi_cd01_notifier_call; + + ret =3D register_acpi_notifier(&priv->acpi_nb); + if (ret) + return ret; + + ret =3D devm_add_action_or_reset(&wdev->dev, lwmi_cd01_unregister, &priv-= >acpi_nb); + if (ret) + return ret; + + return component_add(&wdev->dev, &lwmi_cd01_component_ops); +} + +static void lwmi_cd01_remove(struct wmi_device *wdev) +{ + component_del(&wdev->dev, &lwmi_cd01_component_ops); +} + +static const struct wmi_device_id lwmi_cd01_id_table[] =3D { + { LENOVO_CAPABILITY_DATA_01_GUID, NULL }, + {} +}; + +static struct wmi_driver lwmi_cd01_driver =3D { + .driver =3D { + .name =3D "lenovo_wmi_cd01", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lwmi_cd01_id_table, + .probe =3D lwmi_cd01_probe, + .remove =3D lwmi_cd01_remove, + .no_singleton =3D true, +}; + +/** + * lwmi_cd01_match() - Match rule for the master driver. + * @dev: Pointer to the capability data 01 parent device. + * @data: Unused void pointer for passing match criteria. + * + * Return: int. + */ +int lwmi_cd01_match(struct device *dev, void *data) +{ + return dev->driver =3D=3D &lwmi_cd01_driver.driver; +} +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01"); + +module_wmi_driver(lwmi_cd01_driver); + +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo/wmi-capdata01.h b/drivers/platform= /x86/lenovo/wmi-capdata01.h new file mode 100644 index 000000000000..bd06c5751f68 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-capdata01.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright (C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_CAPDATA01_H_ +#define _LENOVO_WMI_CAPDATA01_H_ + +#include + +struct device; +struct cd01_list; + +struct capdata01 { + u32 id; + u32 supported; + u32 default_value; + u32 step; + u32 min_value; + u32 max_value; +}; + +int lwmi_cd01_get_data(struct cd01_list *list, u32 attribute_id, struct ca= pdata01 *output); +int lwmi_cd01_match(struct device *dev, void *data); + +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */ --=20 2.50.0 From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 5DBB81EBFE0; Wed, 2 Jul 2025 03:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427523; cv=none; b=Kz8Q6dBNL1kph9BW1rA+VMIKu/EHNyDDZu0LbebPhl37bj83wM5JT/O4AbuUdTl4P4ClHrz5/aAUzQHjkdsu73ArXGDPsP+Tv/vPp6eqOhHtrvhyuvHfK3MXyqMKH1fa33PE8Xn/VEOJkFzUiGs1bsnK8fqghw4H02VxsSzpsKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427523; c=relaxed/simple; bh=5GoDPUdw29pbZ7LBYeQiifgEoC7Tlczs/g+IrrkiPtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G70kGG+cg/pZCZ9s/3pYgsL3EsZuV5wH/Jmg5WRs+4S+g+Mi8qHXIzGg5SBvnZ0oAOgVcIkRJJEo8CYUoZ0WsewDk/P6auO4tFNhIQS61ON4tsi2CTlK/9OMTFhB/+a6G6ds/nv2yNXmTOoYL/mjDLLM7oR569x5DFw0iSf01dg= 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=jGsHW1zK; arc=none smtp.client-ip=209.85.215.177 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="jGsHW1zK" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-b271f3ae786so5700225a12.3; Tue, 01 Jul 2025 20:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427521; x=1752032321; 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=ByOtmmYpXi02hzRaouZsVbd6MxblsMhCiMQatTvEuC0=; b=jGsHW1zKjN3qknHbYAqVQcPno1KnO1yxH0JxxKk5L0sx47We5DVLjJ/pr6H0OotN1y QZ9tveFyGJm3gmpjdbEAAaaaarmWqFM1Z3Y4V22/2zhoqrpfK7ld5wNkshe9WVfBZKOT NUZGqGM15pYoF4T+KM5C7Rh/J3FgKaQlxN5YlUhlc3+2AOW9qekG4jcbuJVBwkZCRkvh +0l3yE3Kk1EuZHhSqJshegSl/C7uzyCcrIgfpYD2hmDKTCP610TL3cI8XZMICUQDnCUX DF1AJ3x+V6NNNRUWvjr3w3VONGhKYIQ6HfscmbGVMiYV36UubOiUMEmpRcaLyj1aI4X/ yI1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427521; x=1752032321; 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=ByOtmmYpXi02hzRaouZsVbd6MxblsMhCiMQatTvEuC0=; b=OTKy02BAx0piQvp+SEHkiDxDbyGRvo83x5ILGiDUe0AzamWxRMuwA/dKAFASNhzJlP 9/5GObjsfhozKFyqb0xPIuQMtjs5IgXVQhh/9m7cWpPRpSy3MEL5Mo+NqQdW2s7VwVC6 sc2QiKlMEZcQI5IKHQEwGN45dz33Z3B5GjtQcb+PJoYizpn3YG53LQ3yC97wy9iW5nJw CNJP6VsDLCXQAbPRCdFXn4/QdOt4O983cJwhBPWnjE3Ded5d1GbWijtlyf+sW/otXOZv a2ZHhYQpYPbkKrrgHD565UxQ0Pm1w+pdNCDJIP9hCSLRmEokOpyK6T4xx+5+QhHSpy7o Mxxw== X-Forwarded-Encrypted: i=1; AJvYcCUHJz6JdzUNsUygLB/qMDy8QEVG8h1WVtYoXxSG6PJhd61H1qCDNa/xuSmhL097Vv78kMmEEF/XAzlgnSR5@vger.kernel.org, AJvYcCUmOsiXVr5V44J50LtrZAwYb2oAgpScuAYLW3zyIg0+zUt8mfZrJx4UOELfOEPW0y0Uhqq0yIELH+VE5iPIbU+W1nVwCg==@vger.kernel.org, AJvYcCWeF4uKVUGNQ4IKaYnxInFbj9agCuFsQ9XVoUGSMyvBExlESojmKwS5GqmSEGj22GDx+rFfO3Q6Npc=@vger.kernel.org X-Gm-Message-State: AOJu0YwQbj0gNkYvEunQ7AFw+RpLZuRLUyH8eoR+ERx+ZBsA1mAJccGT nyF/MY2G49CNQW4mnM9pYcrgL6TZ58w83hefzVPbuoDBCvV411Bty8AK X-Gm-Gg: ASbGncscspYZNL4GDfyMA5whChOrZUV+i5oheByfGpiaHvS/pvV/C11GIFvPbdH1r1R 0QGT8qyvcxgn4CBEU1JNgtmNS2NSbwcR8g8jmEtJ1Fj1F0dZ3g4ZSwxnHpthrMvcpn7s6CN+fN4 PGyig8LqvFaZCgyJNmoPmjemZeHSe6Y7/ZvSZq4gOrdxlq6lTtHKdI4lJJaV/M8yi2tq0xSnvf6 25N+ptzP7I7TSJGpWfkhvRTEecCHAd3L8PM5XW2iq4s1DLTS/s20HFJ7/G+F7NbO6VcJn7n+0dB iYhdaJktVeCXMlw4MPbD0xWVCYaX3Q6Mb9Eacp1c6pxFpgDostcevSIMJ7970a+nP+tZTUpRM4L EFZi7gGDkCgHObdbp/pufXpx418vWxnhJNz/s6ahLCg== X-Google-Smtp-Source: AGHT+IHyRUaonQsKoPIYQ+LU0uAFKhu9iq5e/MskHmSa46/DlxoTauIwSUetwHJI6u+YpxhTE3t3cA== X-Received: by 2002:a05:6a21:7a47:b0:220:9d82:a290 with SMTP id adf61e73a8af0-222d7db2c71mr3029093637.8.1751427520550; Tue, 01 Jul 2025 20:38:40 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:40 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v13 5/6] platform/x86: Add Lenovo Gamezone WMI Driver Date: Tue, 1 Jul 2025 20:38:25 -0700 Message-ID: <20250702033826.1057762-6-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI. Reviewed-by: Armin Wolf Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move to new lenovo folder v12: No change v11: - Formatting. v10: No change v9: - Pass NULL instead of 0 in lwmi_dev_evaluate_int where no args buffer was used. v8: - Remove RW from lock comment. v7: - Move spinlock into lwmi_gz_priv. - Add scoped_guard at missing location. - Move adding lwmi_gz_mode_call up in the series. While its only used by lenovo-wmi-other, it doesn't depend on it. - Return instead of assigning ret at end of probe. - Fix typos. v6: - Recache capabiltiy data on ACPI AC events to ensure accutare max_value. - Fix typos and rewordings from v5 review. v5: - Return to cache at device initialization. On component bind, pass a pointer to lenovo-wmi-other. - Fixes from v4 review. v4: - Make driver data a private struct, remove references from Other Mode driver. - Don't cache data at device initialization. Instead, on component bind, cache the data on a member variable of the Other Mode driver data passed as a void pointer. - Add header file for capdata01 structs. - Add new struct to pass capdata01 array data and array length to Other Mode. v3: - Add as component to lenovo-wmi-other driver. v2: - Use devm_kmalloc to ensure driver can be instanced, remove global reference. - Ensure reverse Christmas tree for all variable declarations. - Remove extra whitespace. - Use guard(mutex) in all mutex instances, global mutex. - Use pr_fmt instead of adding the driver name to each pr_err. - Remove noisy pr_info usage. - Rename capdata_wmi to lenovo_wmi_cd01_priv and cd01_wmi to priv. - Use list to get the lenovo_wmi_cd01_priv instance in lenovo_wmi_capdata01_get as none of the data provided by the macros that will use it can pass a member of the struct for use in container_of. --- --- drivers/platform/x86/lenovo/Kconfig | 14 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/wmi-gamezone.c | 407 +++++++++++++++++++++ drivers/platform/x86/lenovo/wmi-gamezone.h | 20 + 4 files changed, 442 insertions(+) create mode 100644 drivers/platform/x86/lenovo/wmi-gamezone.c create mode 100644 drivers/platform/x86/lenovo/wmi-gamezone.h diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/len= ovo/Kconfig index 1943e3a24f43..9de050c637b7 100644 --- a/drivers/platform/x86/lenovo/Kconfig +++ b/drivers/platform/x86/lenovo/Kconfig @@ -244,3 +244,17 @@ config LENOVO_WMI_EVENTS config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI + +config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMI + depends on DMI + select ACPI_PLATFORM_PROFILE + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like = to use the + platform-profile firmware interface to manage power usage. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-gamezone. diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/le= novo/Makefile index 1ce970e4ddb8..0722fd7ad486 100644 --- a/drivers/platform/x86/lenovo/Makefile +++ b/drivers/platform/x86/lenovo/Makefile @@ -15,6 +15,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) +=3D wmi-camera= .o lenovo-target-$(CONFIG_LENOVO_WMI_DATA01) +=3D wmi-capdata01.o lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS) +=3D wmi-events.o lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) +=3D wmi-helpers.o +lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE) +=3D wmi-gamezone.o =20 # Add 'lenovo' prefix to each module listed in lenovo-target-* define LENOVO_OBJ_TARGET diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/= x86/lenovo/wmi-gamezone.c new file mode 100644 index 000000000000..0eb7fe8222f4 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-gamezone.c @@ -0,0 +1,407 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo GameZone WMI interface driver. + * + * The GameZone WMI interface provides platform profile and fan curve sett= ings + * for devices that fall under the "Gaming Series" of Lenovo Legion device= s. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wmi-events.h" +#include "wmi-gamezone.h" +#include "wmi-helpers.h" +#include "wmi-other.h" + +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" + +#define LWMI_GZ_METHOD_ID_SMARTFAN_SUP 43 +#define LWMI_GZ_METHOD_ID_SMARTFAN_SET 44 +#define LWMI_GZ_METHOD_ID_SMARTFAN_GET 45 + +static BLOCKING_NOTIFIER_HEAD(gz_chain_head); + +struct lwmi_gz_priv { + enum thermal_mode current_mode; + struct notifier_block event_nb; + struct notifier_block mode_nb; + spinlock_t gz_mode_lock; /* current_mode lock */ + struct wmi_device *wdev; + int extreme_supported; + struct device *ppdev; +}; + +struct quirk_entry { + bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug =3D { + .extreme_supported =3D false, +}; + +/** + * lwmi_gz_mode_call() - Call method for lenovo-wmi-other driver notifier. + * + * @nb: The notifier_block registered to lenovo-wmi-other driver. + * @cmd: The event type. + * @data: Thermal mode enum pointer pointer for returning the thermal mode. + * + * For LWMI_GZ_GET_THERMAL_MODE, retrieve the current thermal mode. + * + * Return: Notifier_block status. + */ +static int lwmi_gz_mode_call(struct notifier_block *nb, unsigned long cmd, + void *data) +{ + enum thermal_mode **mode =3D data; + struct lwmi_gz_priv *priv; + + priv =3D container_of(nb, struct lwmi_gz_priv, mode_nb); + + switch (cmd) { + case LWMI_GZ_GET_THERMAL_MODE: + scoped_guard(spinlock, &priv->gz_mode_lock) { + **mode =3D priv->current_mode; + } + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +/** + * lwmi_gz_event_call() - Call method for lenovo-wmi-events driver notifie= r. + * block call chain. + * @nb: The notifier_block registered to lenovo-wmi-events driver. + * @cmd: The event type. + * @data: The data to be updated by the event. + * + * For LWMI_EVENT_THERMAL_MODE, set current_mode and notify platform_profi= le + * of a change. + * + * Return: notifier_block status. + */ +static int lwmi_gz_event_call(struct notifier_block *nb, unsigned long cmd, + void *data) +{ + enum thermal_mode *mode =3D data; + struct lwmi_gz_priv *priv; + + priv =3D container_of(nb, struct lwmi_gz_priv, event_nb); + + switch (cmd) { + case LWMI_EVENT_THERMAL_MODE: + scoped_guard(spinlock, &priv->gz_mode_lock) { + priv->current_mode =3D *mode; + } + platform_profile_notify(priv->ppdev); + return NOTIFY_STOP; + default: + return NOTIFY_DONE; + } +} + +/** + * lwmi_gz_thermal_mode_supported() - Get the version of the WMI + * interface to determine the support level. + * @wdev: The Gamezone WMI device. + * @supported: Pointer to return the support level with. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_gz_thermal_mode_supported(struct wmi_device *wdev, + int *supported) +{ + return lwmi_dev_evaluate_int(wdev, 0x0, LWMI_GZ_METHOD_ID_SMARTFAN_SUP, + NULL, 0, supported); +} + +/** + * lwmi_gz_thermal_mode_get() - Get the current thermal mode. + * @wdev: The Gamezone interface WMI device. + * @mode: Pointer to return the thermal mode with. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_gz_thermal_mode_get(struct wmi_device *wdev, + enum thermal_mode *mode) +{ + return lwmi_dev_evaluate_int(wdev, 0x0, LWMI_GZ_METHOD_ID_SMARTFAN_GET, + NULL, 0, mode); +} + +/** + * lwmi_gz_profile_get() - Get the current platform profile. + * @dev: the Gamezone interface parent device. + * @profile: Pointer to provide the current platform profile with. + * + * Call lwmi_gz_thermal_mode_get and convert the thermal mode into a platf= orm + * profile based on the support level of the interface. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_gz_profile_get(struct device *dev, + enum platform_profile_option *profile) +{ + struct lwmi_gz_priv *priv =3D dev_get_drvdata(dev); + enum thermal_mode mode; + int ret; + + ret =3D lwmi_gz_thermal_mode_get(priv->wdev, &mode); + if (ret) + return ret; + + switch (mode) { + case LWMI_GZ_THERMAL_MODE_QUIET: + *profile =3D PLATFORM_PROFILE_LOW_POWER; + break; + case LWMI_GZ_THERMAL_MODE_BALANCED: + *profile =3D PLATFORM_PROFILE_BALANCED; + break; + case LWMI_GZ_THERMAL_MODE_PERFORMANCE: + if (priv->extreme_supported) { + *profile =3D PLATFORM_PROFILE_BALANCED_PERFORMANCE; + break; + } + *profile =3D PLATFORM_PROFILE_PERFORMANCE; + break; + case LWMI_GZ_THERMAL_MODE_EXTREME: + *profile =3D PLATFORM_PROFILE_PERFORMANCE; + break; + case LWMI_GZ_THERMAL_MODE_CUSTOM: + *profile =3D PLATFORM_PROFILE_CUSTOM; + break; + default: + return -EINVAL; + } + + guard(spinlock)(&priv->gz_mode_lock); + priv->current_mode =3D mode; + + return 0; +} + +/** + * lwmi_gz_profile_set() - Set the current platform profile. + * @dev: The Gamezone interface parent device. + * @profile: Pointer to the desired platform profile. + * + * Convert the given platform profile into a thermal mode based on the sup= port + * level of the interface, then call the WMI method to set the thermal mod= e. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_gz_profile_set(struct device *dev, + enum platform_profile_option profile) +{ + struct lwmi_gz_priv *priv =3D dev_get_drvdata(dev); + struct wmi_method_args_32 args; + enum thermal_mode mode; + int ret; + + switch (profile) { + case PLATFORM_PROFILE_LOW_POWER: + mode =3D LWMI_GZ_THERMAL_MODE_QUIET; + break; + case PLATFORM_PROFILE_BALANCED: + mode =3D LWMI_GZ_THERMAL_MODE_BALANCED; + break; + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: + mode =3D LWMI_GZ_THERMAL_MODE_PERFORMANCE; + break; + case PLATFORM_PROFILE_PERFORMANCE: + if (priv->extreme_supported) { + mode =3D LWMI_GZ_THERMAL_MODE_EXTREME; + break; + } + mode =3D LWMI_GZ_THERMAL_MODE_PERFORMANCE; + break; + case PLATFORM_PROFILE_CUSTOM: + mode =3D LWMI_GZ_THERMAL_MODE_CUSTOM; + break; + default: + return -EOPNOTSUPP; + } + + args.arg0 =3D mode; + + ret =3D lwmi_dev_evaluate_int(priv->wdev, 0x0, + LWMI_GZ_METHOD_ID_SMARTFAN_SET, + (u8 *)&args, sizeof(args), NULL); + if (ret) + return ret; + + guard(spinlock)(&priv->gz_mode_lock); + priv->current_mode =3D mode; + + return 0; +} + +static const struct dmi_system_id fwbug_list[] =3D { + { + .ident =3D "Legion Go 8APU1", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go 8APU1"), + }, + .driver_data =3D &quirk_no_extreme_bug, + }, + { + .ident =3D "Legion Go S 8APU1", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go S 8APU1"), + }, + .driver_data =3D &quirk_no_extreme_bug, + }, + { + .ident =3D "Legion Go S 8ARP1", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go S 8ARP1"), + }, + .driver_data =3D &quirk_no_extreme_bug, + }, + {}, + +}; + +/** + * lwmi_gz_extreme_supported() - Evaluate if a device supports extreme the= rmal mode. + * @profile_support_ver: Version of the WMI interface. + * + * Determine if the extreme thermal mode is supported by the hardware. + * Anything version 5 or lower does not. For devices with a version 6 or + * greater do a DMI check, as some devices report a version that supports + * extreme mode but have an incomplete entry in the BIOS. To ensure this + * cannot be set, quirk them to prevent assignment. + * + * Return: bool. + */ +static bool lwmi_gz_extreme_supported(int profile_support_ver) +{ + const struct dmi_system_id *dmi_id; + struct quirk_entry *quirks; + + if (profile_support_ver < 6) + return false; + + dmi_id =3D dmi_first_match(fwbug_list); + if (!dmi_id) + return true; + + quirks =3D dmi_id->driver_data; + + return quirks->extreme_supported; +} + +/** + * lwmi_gz_platform_profile_probe - Enable and set up the platform profile + * device. + * @drvdata: Driver data for the interface. + * @choices: Container for enabled platform profiles. + * + * Determine if thermal mode is supported, and if so to what feature level. + * Then enable all supported platform profiles. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_gz_platform_profile_probe(void *drvdata, unsigned long *ch= oices) +{ + struct lwmi_gz_priv *priv =3D drvdata; + int profile_support_ver; + int ret; + + ret =3D lwmi_gz_thermal_mode_supported(priv->wdev, &profile_support_ver); + if (ret) + return ret; + + if (profile_support_ver < 1) + return -ENODEV; + + set_bit(PLATFORM_PROFILE_LOW_POWER, choices); + set_bit(PLATFORM_PROFILE_BALANCED, choices); + set_bit(PLATFORM_PROFILE_PERFORMANCE, choices); + set_bit(PLATFORM_PROFILE_CUSTOM, choices); + + priv->extreme_supported =3D lwmi_gz_extreme_supported(profile_support_ver= ); + if (priv->extreme_supported) + set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices); + + return 0; +} + +static const struct platform_profile_ops lwmi_gz_platform_profile_ops =3D { + .probe =3D lwmi_gz_platform_profile_probe, + .profile_get =3D lwmi_gz_profile_get, + .profile_set =3D lwmi_gz_profile_set, +}; + +static int lwmi_gz_probe(struct wmi_device *wdev, const void *context) +{ + struct lwmi_gz_priv *priv; + int ret; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->wdev =3D wdev; + dev_set_drvdata(&wdev->dev, priv); + + priv->ppdev =3D devm_platform_profile_register(&wdev->dev, "lenovo-wmi-ga= mezone", + priv, &lwmi_gz_platform_profile_ops); + if (IS_ERR(priv->ppdev)) + return -ENODEV; + + spin_lock_init(&priv->gz_mode_lock); + + ret =3D lwmi_gz_thermal_mode_get(wdev, &priv->current_mode); + if (ret) + return ret; + + priv->event_nb.notifier_call =3D lwmi_gz_event_call; + ret =3D devm_lwmi_events_register_notifier(&wdev->dev, &priv->event_nb); + if (ret) + return ret; + + priv->mode_nb.notifier_call =3D lwmi_gz_mode_call; + return devm_lwmi_om_register_notifier(&wdev->dev, &priv->mode_nb); +} + +static const struct wmi_device_id lwmi_gz_id_table[] =3D { + { LENOVO_GAMEZONE_GUID, NULL }, + {} +}; + +static struct wmi_driver lwmi_gz_driver =3D { + .driver =3D { + .name =3D "lenovo_wmi_gamezone", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lwmi_gz_id_table, + .probe =3D lwmi_gz_probe, + .no_singleton =3D true, +}; + +module_wmi_driver(lwmi_gz_driver); + +MODULE_IMPORT_NS("LENOVO_WMI_EVENTS"); +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS"); +MODULE_IMPORT_NS("LENOVO_WMI_OTHER"); +MODULE_DEVICE_TABLE(wmi, lwmi_gz_id_table); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo GameZone WMI Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.h b/drivers/platform/= x86/lenovo/wmi-gamezone.h new file mode 100644 index 000000000000..6b163a5eeb95 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-gamezone.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright (C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_ + +enum gamezone_events_type { + LWMI_GZ_GET_THERMAL_MODE =3D 1, +}; + +enum thermal_mode { + LWMI_GZ_THERMAL_MODE_QUIET =3D 0x01, + LWMI_GZ_THERMAL_MODE_BALANCED =3D 0x02, + LWMI_GZ_THERMAL_MODE_PERFORMANCE =3D 0x03, + LWMI_GZ_THERMAL_MODE_EXTREME =3D 0xE0, /* Ver 6+ */ + LWMI_GZ_THERMAL_MODE_CUSTOM =3D 0xFF, +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */ --=20 2.50.0 From nobody Wed Oct 8 05:22:10 2025 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 21F341EFF8B; Wed, 2 Jul 2025 03:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427528; cv=none; b=nha7lZ1CvsMTxF0mALwTwI5zK1sIdtdd3bye/AyZxhGH5T+kteURwtcoPJPjZjEtdLrfYcTHXKFv5IYin6Oskk26S7PkMeE6NSLyfW0XusbDM9gVbyCBq72tq4tTFdfEdPkhcSijumnRv99KyRadaV8ggilF6OKlFLZt+rs3Ctk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751427528; c=relaxed/simple; bh=tyrL5RXLscACrkcRCJJIla6jHVVlSy5+r+2T+87iYOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A/hM0kbM3MuxRnbFD4TaWv3+nJqLSvhk4TS+Y/PXS/FzgzGhl0g81buYzi08CY9zaDviqfl7OD5VtI7CdDiQJ5IHXm8RMqcoPVrgBh0d05ObshNq7TQE5W/ORYq5MGAKXWDKRfsflOCT2b+RCoCl3t2YCh07AfAyVyYK7Aln320= 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=O/i+IT1A; arc=none smtp.client-ip=209.85.210.173 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="O/i+IT1A" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-74b27c1481bso1955209b3a.2; Tue, 01 Jul 2025 20:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751427522; x=1752032322; 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=De4DBr9bwzW72J7fPNdVknNZwr8/BR5YOGDhv9h/PGU=; b=O/i+IT1ACY24nioDPfvG56qYBfROoemIhMNeNqySEjvY6TctRqLIkXXd9Ni6FDAD0A Hlb7uFkceCQESIq3AOYXdFxD6xv+TIOnHvgyDhSisZEg6+i0rAjaumUa8gPQjktO78xN xMv95m+gntytZlUJo6Qifq/U96x/ETy/pqrxxI5MSSHpyx7M3Ykz4EOlcnfYLQU72a9N NBMamYWuKXKYcozGMiQmCwmVQftLqSdteaMYO8d411EF94cEZURs5IaKa9uTpqBAKPlU bmE72KMlW25cVHMasUAlKiZtomEz4fyoDIz1/GD/SdZNtF2vzTiGZsgCfLOs4P2VWw9p ZYsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751427522; x=1752032322; 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=De4DBr9bwzW72J7fPNdVknNZwr8/BR5YOGDhv9h/PGU=; b=itsUCROMO9NKORF+6h3c/Un9KulG82n1hBpWzm8NnWUTtk+QisD7seJFrIGCVk2p7e DqKgZvZMwA/mFXrx9mk8yIPoY8xMqlX/f5+1CLXvm43qU4cRVWhe27kEo09Rq4tiB0WK 0LD26rIgpohv+JPKfybL0cZ7ywQXYxMMIfwdhzUOJSSd2JslrFdo00tehMtx3ITQCSq0 NqEnknbHvY9Dmoe7pj2JGwNavHMCN2KkJZnFhRWlzQSil4Ctd4bslSvtHQ6v8W9O/1Mr 5mNRE0KiR1r7UD6r8XaFBOiw50TsSIZjLw6NT1Nlb47g1Zvi3LJh6uxoWl0XQBNBJrVD 5vNQ== X-Forwarded-Encrypted: i=1; AJvYcCU196ftWK6lAEYNW8lBjOAWL8rF7xwks0MnR5bSVMGRbJb5cuqrOQkUzBXo+nUb1Cq/i806vM7KBlr9bL+aXsU2lB31bw==@vger.kernel.org, AJvYcCUeEoyFYUOiPJmJsAcYWDe1YycEtJHjStJwy5ydUHsDCkBFszGOmsVoOEMcF/ViX2VGh/sq8NtBTE6aLAz8@vger.kernel.org, AJvYcCWaiQT2tq61LrxDR3PtmMDyu7npLq5aK8GYb6oCd8JGuTzzYyXIQC1Tz2vbcUkaKaI1XJUP7DPdQ3s=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg+7M/bZPqDUep6Ik7SlMH1z9uI6o6Q1PVBs9J+Wf8egEzhdj1 qOxsbev82zga1jqNgC4jGkqmq1gk/vjHaYCnNUYJmJMbIxN8x7s88lKn X-Gm-Gg: ASbGncsJ7SIXo05OloUmNZSHdG1cWf3iBqZ/gLJYUHOLhyhEUVCbnfiby5xwBkbAHLT iXjbToDTClj0ALmGoK6ZKLY9kapeFWpjAcVfieLAiewVfcV9NsF6hMynbT3PfU2ZgCXClAChvDL 7O7gyKyyEjK2EO8XvWkGBbSDVxlXpv1Sz54oP++hJdKhY342rBL7A+tEAdsf69X5/gjULH+Tydg pzJkM6w4Kg3AqDNtRtUf1F1DkSAQ2irJ24BUFYMlQaeVFXSm48BISLwc6AjuvoO169bUEZMTHy1 d83ynrXcM1mlmIrKT8cEHoJbj5fCLyrM3SytMSNcPlLf5sHUsqPNr/gTtf1f4nEsSyfcbv55QLh S94kwsj6FQTB1H44BjgrQAWUPIQQlLAjFteH9feNeiQ== X-Google-Smtp-Source: AGHT+IGhtUNybDFsaziHf8YWQyS7lIqJbP073Lhq6VHi5cTAiglnslCF0gfbdHm3cd6NLLcNuQr74A== X-Received: by 2002:a05:6a21:4598:b0:215:e43a:29b9 with SMTP id adf61e73a8af0-222d7ef7667mr2125388637.33.1751427522105; Tue, 01 Jul 2025 20:38:42 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b34e301d64fsm11783008a12.19.2025.07.01.20.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 20:38:41 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . H . Chiu" , John Martens , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alok Tiwari Subject: [PATCH v13 6/6] platform/x86: Add Lenovo Other Mode WMI Driver Date: Tue, 1 Jul 2025 20:38:26 -0700 Message-ID: <20250702033826.1057762-7-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702033826.1057762-1-derekjohn.clark@gmail.com> References: <20250702033826.1057762-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-other driver which provides the Lenovo "Other Mode" WMI interface that comes on some Lenovo "Gaming Series" hardware. Provides a firmware-attributes class which enables the use of tunable knobs for SPL, SPPT, and FPPT. Reviewed-by: Alok Tiwari Reviewed-by: Armin Wolf Signed-off-by: Derek J. Clark Suggested-by: Mario Limonciello --- v13: - Move to new lenovo folder v12: - Fix warnings from make W=3D1 v11: - Formatting v10: - include kdev_t to fix build error. v9: - Make tunable_attr_01 declarations static & adjust formatting. v8: - Remove dead code. - use struct cd01_list pointer instead of void pointer in lwmi_cd01_priv. v7: - Use stach allocated capdata01 stuct instead of getting a pointer from lenovo-wmi-capdata01. - Fix typos. v6: - Pass locally stored pointer to cd01_list back to lenovo-wmi-capdata01 instead of itterating over the list locally. Due to ACPI event handing the list is now mutexed. - Fix typos and rewordings from v5 review. v5: - Switch from locally storing capability data list to storing a pointer from the capability data interface. - Add portion of Gamezone driver that relies on the exported functions of this driver. - Properly initialize IDA and use it for naming the firmware-attributes path. - Rename most defines to clearly indicate they are from this driver. - Misc fixes from v4 review. v4: - Treat Other Mode as a notifier chain head, use the notifier chain to get the current mode from Gamezone. - Add header file for Other Mode specific structs and finctions. - Use component master bind to cache the capdata01 array locally. - Drop all reference to external driver private data structs. - Various fixes from review. v3: - Add notifier block and store result for getting the Gamezone interface profile changes. - Add driver as master component of capdata01 driver. - Use FIELD_PREP where appropriate. - Move macros and associated functions out of lemovo-wmi.h that are only used by this driver. v2: - Use devm_kmalloc to ensure driver can be instanced, remove global reference. - Ensure reverse Christmas tree for all variable declarations. - Remove extra whitespace. - Use guard(mutex) in all mutex instances, global mutex. - Use pr_fmt instead of adding the driver name to each pr_err. - Remove noisy pr_info usage. - Rename other_method_wmi to lenovo_wmi_om_priv and om_wmi to priv. - Use list to get the lenovo_wmi_om_priv instance in some macro called functions as the data provided by the macros that use it doesn't pass a member of the struct for use in container_of. - Do not rely on GameZone interface to grab the current fan mode. --- --- drivers/platform/x86/lenovo/Kconfig | 15 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/wmi-other.c | 665 ++++++++++++++++++++++++ drivers/platform/x86/lenovo/wmi-other.h | 16 + 4 files changed, 697 insertions(+) create mode 100644 drivers/platform/x86/lenovo/wmi-other.c create mode 100644 drivers/platform/x86/lenovo/wmi-other.h diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/len= ovo/Kconfig index 9de050c637b7..b76157b35296 100644 --- a/drivers/platform/x86/lenovo/Kconfig +++ b/drivers/platform/x86/lenovo/Kconfig @@ -258,3 +258,18 @@ config LENOVO_WMI_GAMEZONE =20 To compile this driver as a module, choose M here: the module will be called lenovo-wmi-gamezone. + +config LENOVO_WMI_TUNING + tristate "Lenovo Other Mode WMI Driver" + depends on ACPI_WMI + select FW_ATTR_CLASS + select LENOVO_WMI_DATA01 + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like = to use the + firmware_attributes API to control various tunable settings typically e= xposed by + Lenovo software in Windows. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-other. diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/le= novo/Makefile index 0722fd7ad486..7b2128e3a214 100644 --- a/drivers/platform/x86/lenovo/Makefile +++ b/drivers/platform/x86/lenovo/Makefile @@ -16,6 +16,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_DATA01) +=3D wmi-capdat= a01.o lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS) +=3D wmi-events.o lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) +=3D wmi-helpers.o lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE) +=3D wmi-gamezone.o +lenovo-target-$(CONFIG_LENOVO_WMI_TUNING) +=3D wmi-other.o =20 # Add 'lenovo' prefix to each module listed in lenovo-target-* define LENOVO_OBJ_TARGET diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86= /lenovo/wmi-other.c new file mode 100644 index 000000000000..2a960b278f11 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-other.c @@ -0,0 +1,665 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo Other Mode WMI interface driver. + * + * This driver uses the fw_attributes class to expose the various WMI func= tions + * provided by the "Other Mode" WMI interface. This enables CPU and GPU po= wer + * limit as well as various other attributes for devices that fall under t= he + * "Gaming Series" of Lenovo laptop devices. Each attribute exposed by the + * "Other Mode" interface has a corresponding Capability Data struct that + * allows the driver to probe details about the attribute such as if it is + * supported by the hardware, the default_value, max_value, min_value, and= step + * increment. + * + * These attributes typically don't fit anywhere else in the sysfs and are= set + * in Windows using one of Lenovo's multiple user applications. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wmi-capdata01.h" +#include "wmi-events.h" +#include "wmi-gamezone.h" +#include "wmi-helpers.h" +#include "wmi-other.h" +#include "../firmware_attributes_class.h" + +#define LENOVO_OTHER_MODE_GUID "DC2A8805-3A8C-41BA-A6F7-092E0089CD3B" + +#define LWMI_DEVICE_ID_CPU 0x01 + +#define LWMI_FEATURE_ID_CPU_SPPT 0x01 +#define LWMI_FEATURE_ID_CPU_SPL 0x02 +#define LWMI_FEATURE_ID_CPU_FPPT 0x03 + +#define LWMI_TYPE_ID_NONE 0x00 + +#define LWMI_FEATURE_VALUE_GET 17 +#define LWMI_FEATURE_VALUE_SET 18 + +#define LWMI_ATTR_DEV_ID_MASK GENMASK(31, 24) +#define LWMI_ATTR_FEAT_ID_MASK GENMASK(23, 16) +#define LWMI_ATTR_MODE_ID_MASK GENMASK(15, 8) +#define LWMI_ATTR_TYPE_ID_MASK GENMASK(7, 0) + +#define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other" + +static BLOCKING_NOTIFIER_HEAD(om_chain_head); +static DEFINE_IDA(lwmi_om_ida); + +enum attribute_property { + DEFAULT_VAL, + MAX_VAL, + MIN_VAL, + STEP_VAL, + SUPPORTED, +}; + +struct lwmi_om_priv { + struct component_master_ops *ops; + struct cd01_list *cd01_list; /* only valid after capdata01 bind */ + struct device *fw_attr_dev; + struct kset *fw_attr_kset; + struct notifier_block nb; + struct wmi_device *wdev; + int ida_id; +}; + +struct tunable_attr_01 { + struct capdata01 *capdata; + struct device *dev; + u32 feature_id; + u32 device_id; + u32 type_id; +}; + +static struct tunable_attr_01 ppt_pl1_spl =3D { + .device_id =3D LWMI_DEVICE_ID_CPU, + .feature_id =3D LWMI_FEATURE_ID_CPU_SPL, + .type_id =3D LWMI_TYPE_ID_NONE, +}; + +static struct tunable_attr_01 ppt_pl2_sppt =3D { + .device_id =3D LWMI_DEVICE_ID_CPU, + .feature_id =3D LWMI_FEATURE_ID_CPU_SPPT, + .type_id =3D LWMI_TYPE_ID_NONE, +}; + +static struct tunable_attr_01 ppt_pl3_fppt =3D { + .device_id =3D LWMI_DEVICE_ID_CPU, + .feature_id =3D LWMI_FEATURE_ID_CPU_FPPT, + .type_id =3D LWMI_TYPE_ID_NONE, +}; + +struct capdata01_attr_group { + const struct attribute_group *attr_group; + struct tunable_attr_01 *tunable_attr; +}; + +/** + * lwmi_om_register_notifier() - Add a notifier to the blocking notifier c= hain + * @nb: The notifier_block struct to register + * + * Call blocking_notifier_chain_register to register the notifier block to= the + * lenovo-wmi-other driver notifier chain. + * + * Return: 0 on success, %-EEXIST on error. + */ +int lwmi_om_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&om_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_om_register_notifier, "LENOVO_WMI_OTHER"); + +/** + * lwmi_om_unregister_notifier() - Remove a notifier from the blocking not= ifier + * chain. + * @nb: The notifier_block struct to register + * + * Call blocking_notifier_chain_unregister to unregister the notifier bloc= k from the + * lenovo-wmi-other driver notifier chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +int lwmi_om_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&om_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_om_unregister_notifier, "LENOVO_WMI_OTHER"); + +/** + * devm_lwmi_om_unregister_notifier() - Remove a notifier from the blocking + * notifier chain. + * @data: Void pointer to the notifier_block struct to register. + * + * Call lwmi_om_unregister_notifier to unregister the notifier block from = the + * lenovo-wmi-other driver notifier chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +static void devm_lwmi_om_unregister_notifier(void *data) +{ + struct notifier_block *nb =3D data; + + lwmi_om_unregister_notifier(nb); +} + +/** + * devm_lwmi_om_register_notifier() - Add a notifier to the blocking notif= ier + * chain. + * @dev: The parent device of the notifier_block struct. + * @nb: The notifier_block struct to register + * + * Call lwmi_om_register_notifier to register the notifier block to the + * lenovo-wmi-other driver notifier chain. Then add devm_lwmi_om_unregiste= r_notifier + * as a device managed action to automatically unregister the notifier blo= ck + * upon parent device removal. + * + * Return: 0 on success, or an error code. + */ +int devm_lwmi_om_register_notifier(struct device *dev, + struct notifier_block *nb) +{ + int ret; + + ret =3D lwmi_om_register_notifier(nb); + if (ret < 0) + return ret; + + return devm_add_action_or_reset(dev, devm_lwmi_om_unregister_notifier, + nb); +} +EXPORT_SYMBOL_NS_GPL(devm_lwmi_om_register_notifier, "LENOVO_WMI_OTHER"); + +/** + * lwmi_om_notifier_call() - Call functions for the notifier call chain. + * @mode: Pointer to a thermal mode enum to retrieve the data from. + * + * Call blocking_notifier_call_chain to retrieve the thermal mode from the + * lenovo-wmi-gamezone driver. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_om_notifier_call(enum thermal_mode *mode) +{ + int ret; + + ret =3D blocking_notifier_call_chain(&om_chain_head, + LWMI_GZ_GET_THERMAL_MODE, &mode); + if ((ret & ~NOTIFY_STOP_MASK) !=3D NOTIFY_OK) + return -EINVAL; + + return 0; +} + +/* Attribute Methods */ + +/** + * int_type_show() - Emit the data type for an integer attribute + * @kobj: Pointer to the driver object. + * @kattr: Pointer to the attribute calling this function. + * @buf: The buffer to write to. + * + * Return: Number of characters written to buf. + */ +static ssize_t int_type_show(struct kobject *kobj, struct kobj_attribute *= kattr, + char *buf) +{ + return sysfs_emit(buf, "integer\n"); +} + +/** + * attr_capdata01_show() - Get the value of the specified attribute proper= ty + * + * @kobj: Pointer to the driver object. + * @kattr: Pointer to the attribute calling this function. + * @buf: The buffer to write to. + * @tunable_attr: The attribute to be read. + * @prop: The property of this attribute to be read. + * + * Retrieves the given property from the capability data 01 struct for the + * specified attribute's "custom" thermal mode. This function is intended + * to be generic so it can be called from any integer attributes "_show" + * function. + * + * If the WMI is success the sysfs attribute is notified. + * + * Return: Either number of characters written to buf, or an error code. + */ +static ssize_t attr_capdata01_show(struct kobject *kobj, + struct kobj_attribute *kattr, char *buf, + struct tunable_attr_01 *tunable_attr, + enum attribute_property prop) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(tunable_attr->dev); + struct capdata01 capdata; + u32 attribute_id; + int value, ret; + + attribute_id =3D + FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, + LWMI_GZ_THERMAL_MODE_CUSTOM) | + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); + + ret =3D lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata); + if (ret) + return ret; + + switch (prop) { + case DEFAULT_VAL: + value =3D capdata.default_value; + break; + case MAX_VAL: + value =3D capdata.max_value; + break; + case MIN_VAL: + value =3D capdata.min_value; + break; + case STEP_VAL: + value =3D capdata.step; + break; + default: + return -EINVAL; + } + + return sysfs_emit(buf, "%d\n", value); +} + +/** + * attr_current_value_store() - Set the current value of the given attribu= te + * @kobj: Pointer to the driver object. + * @kattr: Pointer to the attribute calling this function. + * @buf: The buffer to read from, this is parsed to `int` type. + * @count: Required by sysfs attribute macros, pass in from the callee att= r. + * @tunable_attr: The attribute to be stored. + * + * Sets the value of the given attribute when operating under the "custom" + * smartfan profile. The current smartfan profile is retrieved from the + * lenovo-wmi-gamezone driver and error is returned if the result is not + * "custom". This function is intended to be generic so it can be called f= rom + * any integer attribute's "_store" function. The integer to be sent to th= e WMI + * method is range checked and an error code is returned if out of range. + * + * If the value is valid and WMI is success, then the sysfs attribute is + * notified. + * + * Return: Either count, or an error code. + */ +static ssize_t attr_current_value_store(struct kobject *kobj, + struct kobj_attribute *kattr, + const char *buf, size_t count, + struct tunable_attr_01 *tunable_attr) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(tunable_attr->dev); + struct wmi_method_args_32 args; + struct capdata01 capdata; + enum thermal_mode mode; + u32 attribute_id; + u32 value; + int ret; + + ret =3D lwmi_om_notifier_call(&mode); + if (ret) + return ret; + + if (mode !=3D LWMI_GZ_THERMAL_MODE_CUSTOM) + return -EBUSY; + + attribute_id =3D + FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) | + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); + + ret =3D lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata); + if (ret) + return ret; + + ret =3D kstrtouint(buf, 10, &value); + if (ret) + return ret; + + if (value < capdata.min_value || value > capdata.max_value) + return -EINVAL; + + args.arg0 =3D attribute_id; + args.arg1 =3D value; + + ret =3D lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET, + (unsigned char *)&args, sizeof(args), NULL); + if (ret) + return ret; + + return count; +}; + +/** + * attr_current_value_show() - Get the current value of the given attribute + * @kobj: Pointer to the driver object. + * @kattr: Pointer to the attribute calling this function. + * @buf: The buffer to write to. + * @tunable_attr: The attribute to be read. + * + * Retrieves the value of the given attribute for the current smartfan pro= file. + * The current smartfan profile is retrieved from the lenovo-wmi-gamezone = driver. + * This function is intended to be generic so it can be called from any in= teger + * attribute's "_show" function. + * + * If the WMI is success the sysfs attribute is notified. + * + * Return: Either number of characters written to buf, or an error code. + */ +static ssize_t attr_current_value_show(struct kobject *kobj, + struct kobj_attribute *kattr, char *buf, + struct tunable_attr_01 *tunable_attr) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(tunable_attr->dev); + struct wmi_method_args_32 args; + enum thermal_mode mode; + u32 attribute_id; + int retval; + int ret; + + ret =3D lwmi_om_notifier_call(&mode); + if (ret) + return ret; + + attribute_id =3D + FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) | + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); + + args.arg0 =3D attribute_id; + + ret =3D lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET, + (unsigned char *)&args, sizeof(args), + &retval); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", retval); +} + +/* Lenovo WMI Other Mode Attribute macros */ +#define __LWMI_ATTR_RO(_func, _name) \ + { \ + .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ + .show =3D _func##_##_name##_show, \ + } + +#define __LWMI_ATTR_RO_AS(_name, _show) \ + { \ + .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ + .show =3D _show, \ + } + +#define __LWMI_ATTR_RW(_func, _name) \ + __ATTR(_name, 0644, _func##_##_name##_show, _func##_##_name##_store) + +/* Shows a formatted static variable */ +#define __LWMI_ATTR_SHOW_FMT(_prop, _attrname, _fmt, _val) = \ + static ssize_t _attrname##_##_prop##_show( \ + struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ + { \ + return sysfs_emit(buf, _fmt, _val); \ + } \ + static struct kobj_attribute attr_##_attrname##_##_prop =3D \ + __LWMI_ATTR_RO(_attrname, _prop) + +/* Attribute current value read/write */ +#define __LWMI_TUNABLE_CURRENT_VALUE_CAP01(_attrname) = \ + static ssize_t _attrname##_current_value_store( \ + struct kobject *kobj, struct kobj_attribute *kattr, \ + const char *buf, size_t count) \ + { \ + return attr_current_value_store(kobj, kattr, buf, count, \ + &_attrname); \ + } \ + static ssize_t _attrname##_current_value_show( \ + struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ + { \ + return attr_current_value_show(kobj, kattr, buf, &_attrname); \ + } \ + static struct kobj_attribute attr_##_attrname##_current_value =3D \ + __LWMI_ATTR_RW(_attrname, current_value) + +/* Attribute property read only */ +#define __LWMI_TUNABLE_RO_CAP01(_prop, _attrname, _prop_type) = \ + static ssize_t _attrname##_##_prop##_show( \ + struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ + { \ + return attr_capdata01_show(kobj, kattr, buf, &_attrname, \ + _prop_type); \ + } \ + static struct kobj_attribute attr_##_attrname##_##_prop =3D \ + __LWMI_ATTR_RO(_attrname, _prop) + +#define LWMI_ATTR_GROUP_TUNABLE_CAP01(_attrname, _fsname, _dispname) \ + __LWMI_TUNABLE_CURRENT_VALUE_CAP01(_attrname); \ + __LWMI_TUNABLE_RO_CAP01(default_value, _attrname, DEFAULT_VAL); \ + __LWMI_ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + __LWMI_TUNABLE_RO_CAP01(max_value, _attrname, MAX_VAL); \ + __LWMI_TUNABLE_RO_CAP01(min_value, _attrname, MIN_VAL); \ + __LWMI_TUNABLE_RO_CAP01(scalar_increment, _attrname, STEP_VAL); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __LWMI_ATTR_RO_AS(type, int_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_default_value.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_max_value.attr, \ + &attr_##_attrname##_min_value.attr, \ + &attr_##_attrname##_scalar_increment.attr, \ + &attr_##_attrname##_type.attr, \ + NULL, \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + +LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl1_spl, "ppt_pl1_spl", + "Set the CPU sustained power limit"); +LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl2_sppt, "ppt_pl2_sppt", + "Set the CPU slow package power tracking limit"); +LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl3_fppt, "ppt_pl3_fppt", + "Set the CPU fast package power tracking limit"); + +static struct capdata01_attr_group cd01_attr_groups[] =3D { + { &ppt_pl1_spl_attr_group, &ppt_pl1_spl }, + { &ppt_pl2_sppt_attr_group, &ppt_pl2_sppt }, + { &ppt_pl3_fppt_attr_group, &ppt_pl3_fppt }, + {}, +}; + +/** + * lwmi_om_fw_attr_add() - Register all firmware_attributes_class members + * @priv: The Other Mode driver data. + * + * Return: Either 0, or an error code. + */ +static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv) +{ + unsigned int i; + int err; + + priv->ida_id =3D ida_alloc(&lwmi_om_ida, GFP_KERNEL); + if (priv->ida_id < 0) + return priv->ida_id; + + priv->fw_attr_dev =3D device_create(&firmware_attributes_class, NULL, + MKDEV(0, 0), NULL, "%s-%u", + LWMI_OM_FW_ATTR_BASE_PATH, + priv->ida_id); + if (IS_ERR(priv->fw_attr_dev)) { + err =3D PTR_ERR(priv->fw_attr_dev); + goto err_free_ida; + } + + priv->fw_attr_kset =3D kset_create_and_add("attributes", NULL, + &priv->fw_attr_dev->kobj); + if (!priv->fw_attr_kset) { + err =3D -ENOMEM; + goto err_destroy_classdev; + } + + for (i =3D 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) { + err =3D sysfs_create_group(&priv->fw_attr_kset->kobj, + cd01_attr_groups[i].attr_group); + if (err) + goto err_remove_groups; + + cd01_attr_groups[i].tunable_attr->dev =3D &priv->wdev->dev; + } + return 0; + +err_remove_groups: + while (i--) + sysfs_remove_group(&priv->fw_attr_kset->kobj, + cd01_attr_groups[i].attr_group); + + kset_unregister(priv->fw_attr_kset); + +err_destroy_classdev: + device_unregister(priv->fw_attr_dev); + +err_free_ida: + ida_free(&lwmi_om_ida, priv->ida_id); + return err; +} + +/** + * lwmi_om_fw_attr_remove() - Unregister all capability data attribute gro= ups + * @priv: the lenovo-wmi-other driver data. + */ +static void lwmi_om_fw_attr_remove(struct lwmi_om_priv *priv) +{ + for (unsigned int i =3D 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) + sysfs_remove_group(&priv->fw_attr_kset->kobj, + cd01_attr_groups[i].attr_group); + + kset_unregister(priv->fw_attr_kset); + device_unregister(priv->fw_attr_dev); +} + +/** + * lwmi_om_master_bind() - Bind all components of the other mode driver + * @dev: The lenovo-wmi-other driver basic device. + * + * Call component_bind_all to bind the lenovo-wmi-capdata01 driver to the + * lenovo-wmi-other master driver. On success, assign the capability data = 01 + * list pointer to the driver data struct for later access. This pointer + * is only valid while the capdata01 interface exists. Finally, register a= ll + * firmware attribute groups. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_om_master_bind(struct device *dev) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(dev); + struct cd01_list *tmp_list; + int ret; + + ret =3D component_bind_all(dev, &tmp_list); + if (ret) + return ret; + + priv->cd01_list =3D tmp_list; + if (!priv->cd01_list) + return -ENODEV; + + return lwmi_om_fw_attr_add(priv); +} + +/** + * lwmi_om_master_unbind() - Unbind all components of the other mode driver + * @dev: The lenovo-wmi-other driver basic device + * + * Unregister all capability data attribute groups. Then call + * component_unbind_all to unbind the lenovo-wmi-capdata01 driver from the + * lenovo-wmi-other master driver. Finally, free the IDA for this device. + */ +static void lwmi_om_master_unbind(struct device *dev) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(dev); + + lwmi_om_fw_attr_remove(priv); + component_unbind_all(dev, NULL); +} + +static const struct component_master_ops lwmi_om_master_ops =3D { + .bind =3D lwmi_om_master_bind, + .unbind =3D lwmi_om_master_unbind, +}; + +static int lwmi_other_probe(struct wmi_device *wdev, const void *context) +{ + struct component_match *master_match =3D NULL; + struct lwmi_om_priv *priv; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->wdev =3D wdev; + dev_set_drvdata(&wdev->dev, priv); + + component_match_add(&wdev->dev, &master_match, lwmi_cd01_match, NULL); + if (IS_ERR(master_match)) + return PTR_ERR(master_match); + + return component_master_add_with_match(&wdev->dev, &lwmi_om_master_ops, + master_match); +} + +static void lwmi_other_remove(struct wmi_device *wdev) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(&wdev->dev); + + component_master_del(&wdev->dev, &lwmi_om_master_ops); + ida_free(&lwmi_om_ida, priv->ida_id); +} + +static const struct wmi_device_id lwmi_other_id_table[] =3D { + { LENOVO_OTHER_MODE_GUID, NULL }, + {} +}; + +static struct wmi_driver lwmi_other_driver =3D { + .driver =3D { + .name =3D "lenovo_wmi_other", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lwmi_other_id_table, + .probe =3D lwmi_other_probe, + .remove =3D lwmi_other_remove, + .no_singleton =3D true, +}; + +module_wmi_driver(lwmi_other_driver); + +MODULE_IMPORT_NS("LENOVO_WMI_CD01"); +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS"); +MODULE_DEVICE_TABLE(wmi, lwmi_other_id_table); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo Other Mode WMI Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo/wmi-other.h b/drivers/platform/x86= /lenovo/wmi-other.h new file mode 100644 index 000000000000..8ebf5602bb99 --- /dev/null +++ b/drivers/platform/x86/lenovo/wmi-other.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright (C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_OTHER_H_ +#define _LENOVO_WMI_OTHER_H_ + +struct device; +struct notifier_block; + +int lwmi_om_register_notifier(struct notifier_block *nb); +int lwmi_om_unregister_notifier(struct notifier_block *nb); +int devm_lwmi_om_register_notifier(struct device *dev, + struct notifier_block *nb); + +#endif /* !_LENOVO_WMI_OTHER_H_ */ --=20 2.50.0