From patchwork Tue Feb 25 21:59:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Derek J. Clark" X-Patchwork-Id: 13991033 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 DA4BB2135CA; Tue, 25 Feb 2025 22:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520855; cv=none; b=iXdG7AXZpzG/6QDrApk1kxVNu2jMFneQrVacQ3ewLcMpHb3CHaNrTTBCQg+41vSsR84ZFBbtyLK29GpU8bYvJBET/NIGrOk+AJCW5cuJnBwBz5QP7R+KRWB+SzxUkMonz2n8T2rxc/7A6vSMbAn8sJtCPLV2ngd59xLevnSGqoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520855; c=relaxed/simple; bh=a1wl6xvlJGrSBqnEUDmnq2FinJq6EPpb+9kn5Pjf41s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NjbbGh35JQlDEJQi9asixvGL6cP0Dr3OuAtBqH3MxHboK1z8m351QaNj8p+b+1VHa1vlqBfK+NC9tNqqFsq+Zqtf31XmLRFBhC0+vXD45KyEe6yvN7plZNgfs+q+Yd+unu6SdY3iHluFIH76OslOOGVM75LxlJiiwsSo/bxB9Ds= 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=UXrmen5q; arc=none smtp.client-ip=209.85.214.181 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="UXrmen5q" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2211acda7f6so138594995ad.3; Tue, 25 Feb 2025 14:00:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740520852; x=1741125652; 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=tGaY8+FkMOehwNUk/1jBCOEEknd3jFUarR0Ou8VobtE=; b=UXrmen5qxtPW09Ud+cSNa0VZLjdtcJDsh7prby9C90WUAYDWzt6d7bVK16lbcfIxNC c1EIxAIUV8gDf0pV30dLFkdwBN2H4dyJYJ4SJjwNOuJxlOYPxIEv6ru3tu/NnUgqD12o Cn/ZtS3DSGs6CNd9bwY54MLP1xg2gS+MKmMGCzAxO2/gpF5g2G8ofebsrzpE2cAZVCY3 Gt1Zu+ZUiW1KBd7G1GZQsuhhH19ADjRHI60ubx9eLGxJdyWkfVxISQ4wj4gVR4Ryc7w2 YOXybboyeDVggd2X1u9U901rkKA8WfC58bM2noK7iF0MRvjNhmCDIAadIKrK6D4yYT7B 94pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740520852; x=1741125652; 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=tGaY8+FkMOehwNUk/1jBCOEEknd3jFUarR0Ou8VobtE=; b=wqfhydSVk5EP66uW+LlRYtJrfq4G1qmKlXuYeClZZub6hVC/+1jpWLEY24TFcK4itO 1DRrfjF5M7RvDzkLpDQIA2NHdYpt5kFTw0ZiJVEqCqzc53tdHJ8oe9uFiIviVLiFawrh C0rmCbtE+yvVyRN+m7rGZjnzsuUl5MPVQIkcI7e9qKZuGTTw658gHhhbq4tnzEsYddeb OZWjd1yzqvBLcl8oPB/20wWeLuDLe3jxgAMCO3SQ20YD0msqJv/g6WKP1udsCOhK6SuE u7H3aCYzBUcES5dSRkLFsSPsZKoXuIEJt+xHYfsybbPdrqQuBXGunSGj3c1Rq0AmUpED C8mg== X-Forwarded-Encrypted: i=1; AJvYcCVXscCr3dH3piKhG+Dpr1UFsJ0iw0xK5m3/+WgXyh+kj51Mr8PvaSqTrELlBpyZlUglS2SyTn968eMfMmjJ@vger.kernel.org, AJvYcCXni8zWAeVTLoyQQZBYxgSHxRsRQuj69+6iMzfspfsn0enWSAI72I+VYp/cmpZBQIFfSmJeq5vNkcw=@vger.kernel.org, AJvYcCXvdrTqQOV2JnWBkoWoJV8slKUugs12yZKFeCCT6t2504HMuIzHv5eKw8+gkGpsKMvsTJ2lVJ+rpnmNXck4+aq+tufPOQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yx6u1A5f0Iw5sZOQWcmoTG44DFH/hDQD61CxLLbgxughXkcDb1S QpSrgyS1AAz2z2rqNT+qBlK63N34krUy3/kHL6vghik6xDEQsGjm X-Gm-Gg: ASbGnctspG1OOy54phdvXwtzNb+vMLPs3CTh25793dlVBl8BMgBn40C7t+uL/Ssgni4 bkDdue1LWHj1k/HU1dljZunjZqGbBm2977I/PZ6AuDl1gUmyOpsw7WGMgu2ur68FC5twpMRuG/P oYspRvnjPx+89k9fNu5L4atCwzF3wemsiNF5J64+Pa+BmVwKYOEf7187PxWdJRwyx21ABlVgXKu 12cgo0yUPHtj7u77T4fvOtqqMoXMvJr6xlZjo4w7p1F/9K75hRrLo3PjpWVclS3bUPuhKPN4nqU 3xsEuJaPASwCIXcWoM67U5JzQq9qqu5+/JMLPaQLkLaYkfhfrDPC5P3plLYM2cG7gpVTlUVCaT1 TgqC8VbqvaZ0m7MleJfgUGykS X-Google-Smtp-Source: AGHT+IGCg++5iL3eTTUOHsJzzPBW9PKiUIqcKtwqrqp2Etkf2PJRf0XgcvcTqOcUhIdjsNLOsHaaMQ== X-Received: by 2002:a17:902:e5d0:b0:218:a43c:571e with SMTP id d9443c01a7336-223200b51ffmr18482145ad.28.1740520851767; Tue, 25 Feb 2025 14:00:51 -0800 (PST) Received: from localhost.localdomain (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a6f912fsm2114122b3a.61.2025.02.25.14.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 14:00:50 -0800 (PST) From: "Derek J. Clark" To: Hans de Goede , =?utf-8?q?Ilpo_J=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 , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] platform/x86: Add lenovo-wmi drivers Documentation Date: Tue, 25 Feb 2025 13:59:52 -0800 Message-ID: <20250225220037.16073-2-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250225220037.16073-1-derekjohn.clark@gmail.com> References: <20250225220037.16073-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds documentation for all new lenovo-wmi drivers. 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. Signed-off-by: Derek J. Clark Signed-off-by: Foo bar --- .../wmi/devices/lenovo-wmi-gamezone.rst | 355 ++++++++++++++++++ .../wmi/devices/lenovo-wmi-other-method.rst | 142 +++++++ MAINTAINERS | 7 + 3 files changed, 504 insertions(+) create mode 100644 Documentation/wmi/devices/lenovo-wmi-gamezone.rst create mode 100644 Documentation/wmi/devices/lenovo-wmi-other-method.rst diff --git a/Documentation/wmi/devices/lenovo-wmi-gamezone.rst b/Documentation/wmi/devices/lenovo-wmi-gamezone.rst new file mode 100644 index 000000000000..1dc281fdd99d --- /dev/null +++ b/Documentation/wmi/devices/lenovo-wmi-gamezone.rst @@ -0,0 +1,355 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later +========================================================== +Lenovo WMI Interface Gamezone Driver (lenovo-wmi-gamezone) +========================================================== + +Introduction +============ +The Lenovo WMI gamezone interface is broken up into multiple GUIDs, +The priamry "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 the +current platform profile when it changes. + +The following platform profiles are supported: + - low-power + - balanced + - balanced-performance + - performance + - custom + +Balanced-Perfornance and Performance Profiles +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Some newer Lenovo "Gaming Series" laptops have an "Extreme Mode" profile +enabled in their BIOS. For these devices, the performance platform profile +will correspond to the BIOS Extreme Mode, while the balanced-performance +platform profile will correspond to the BIOS Performance mode. For legacy +devices, the performance platform prfile will correspond with the BIOS +Performance mode. + +Custom Profile +~~~~~~~~~~~~~~ +The custom profile represents a hardware mode on Lenovo devices that enables +user modifications to Package Power Tracking (PPT) and fan curve settings. +When an attribute exposed by the Other Mode WMI interface is to be modified, +the Gamezone driver must first be switched to the "custom" profile manually, +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 platform +profile has changed, either through the hardware event (Fn+Q for laptops or +Legion + Y for Go Series), or through the Gamezone WMI interface. + + +WMI interface description +========================= + +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("LENOVO_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 Data); + + [WmiMethodId(11), Implemented, Description("Get AslCode Version")] + void GetVersion ([out, Description("AslCode version")] UINT32 Data); + + [WmiMethodId(12), Implemented, Description("Fan cooling capability")] + void IsSupportFanCooling([out, Description("Fan cooling capability")] UINT32 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 capability")] + void IsBIOSSupportOC ([out, Description("bios has overclock capability")] UINT32 Data); + + [WmiMethodId(16), Implemented, Description("enable or disable overclock in bios")] + void SetBIOSOC ([in, Description("enable or disable overclock in bios")] UINT32 Data); + + [WmiMethodId(18), Implemented, Description("Get CPU temperature")] + void GetCPUTemp ([out, Description("Get CPU temperature")] UINT32 Data); + + [WmiMethodId(19), Implemented, Description("Get GPU temperature")] + void GetGPUTemp ([out, Description("Get GPU temperature")] UINT32 Data); + + [WmiMethodId(20), Implemented, Description("Get Fan cooling on/off status")] + 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 support disable windows key capability")] UINT32 Data); + + [WmiMethodId(22), Implemented, Description("Set windows key disable/enable")] + void SetWinKeyStatus ([in, Description("Set windows key disable/enable")] UINT32 Data); + + [WmiMethodId(23), Implemented, Description("Get windows key disable/enable status")] + void GetWinKeyStatus ([out, Description("Get windows key disable/enable status")] UINT32 Data); + + [WmiMethodId(24), Implemented, Description("EC support disable touchpad capability")] + void IsSupportDisableTP ([out, Description("EC support disable touchpad capability")] UINT32 Data); + + [WmiMethodId(25), Implemented, Description("Set touchpad disable/enable")] + void SetTPStatus ([in, Description("Set touchpad disable/enable")] UINT32 Data); + + [WmiMethodId(26), Implemented, Description("Get touchpad disable/enable status")] + void GetTPStatus ([out, Description("Get touchpad disable/enable status")] UINT32 Data); + + [WmiMethodId(30), emented, Description("Get Keyboard feature list")] + void GetKeyboardfeaturelist ([out, Description("Get Keyboard feature list")] UINT32 Data); + + [WmiMethodId(31), emented, Description("Get Memory OC Information")] + void GetMemoryOCInfo ([out, Description("Get Memory OC Information")] UINT32 Data); + + [WmiMethodId(32), emented, Description("Water Cooling feature capability")] + void IsSupportWaterCooling ([out, Description("Water Cooling feature capability")] UINT32 Data); + + [WmiMethodId(33), emented, Description("Set Water Cooling status")] + void SetWaterCoolingStatus ([in, Description("Set Water Cooling status")] UINT32 Data); + + [WmiMethodId(34), emented, Description("Get Water Cooling status")] + void GetWaterCoolingStatus ([out, Description("Get Water Cooling status")] UINT32 Data); + + [WmiMethodId(35), emented, Description("Lighting feature capability")] + void IsSupportLightingFeature ([out, Description("Lighting feature capability")] UINT32 Data); + + [WmiMethodId(36), emented, Description("Set keyboard light off or on to max")] + void SetKeyboardLight ([in, Description("keyboard light off or on switch")] UINT32 Data); + + [WmiMethodId(37), emented, Description("Get keyboard light on/off status")] + void GetKeyboardLight ([out, Description("Get keyboard light on/off status")] UINT32 Data); + + [WmiMethodId(38), emented, Description("Get Macrokey scan code")] + void GetMacrokeyScancode ([in, Description("Macrokey index")] UINT32 idx, [out, Description("Scan code")] UINT32 scancode); + + [WmiMethodId(39), emented, Description("Get Macrokey count")] + void GetMacrokeyCount ([out, Description("Macrokey count")] UINT32 Data); + + [WmiMethodId(40), emented, Description("Support G-Sync feature")] + void IsSupportGSync ([out, Description("Support G-Sync feature")] UINT32 Data); + + [WmiMethodId(41), emented, Description("Get G-Sync Statust")] + void GetGSyncStatus ([out, Description("Get G-Sync Statust")] UINT32 Data); + + [WmiMethodId(42), emented, Description("Set G-Sync Statust")] + void SetGSyncStatus ([in, Description("Set G-Sync Statust")] UINT32 Data); + + [WmiMethodId(43), emented, Description("Support Smart Fan feature")] + void IsSupportSmartFan ([out, Description("Support Smart Fan feature")] UINT32 Data); + + [WmiMethodId(44), emented, Description("Set Smart Fan Mode")] + void SetSmartFanMode ([in, Description("Set Smart Fan Mode")] UINT32 Data); + + [WmiMethodId(45), emented, Description("Get Smart Fan Mode")] + void GetSmartFanMode ([out, Description("Get Smart Fan Mode")] UINT32 Data); + + [WmiMethodId(46), emented, Description("Get Smart Fan Setting Mode")] + void GetSmartFanSetting ([out, Description("Get Smart Setting Mode")] UINT32 Data); + + [WmiMethodId(47), emented, Description("Get Power Charge Mode")] + void GetPowerChargeMode ([out, Description("Get Power Charge Mode")] UINT32 Data); + + [WmiMethodId(48), emented, Description("Get Gaming Product Info")] + void GetProductInfo ([out, Description("Get Gaming Product Info")] UINT32 Data); + + [WmiMethodId(49), emented, Description("Over Drive feature capability")] + void IsSupportOD ([out, Description("Over Drive feature capability")] UINT32 Data); + + [WmiMethodId(50), emented, Description("Get Over Drive status")] + void GetODStatus ([out, Description("Get Over Drive status")] UINT32 Data); + + [WmiMethodId(51), emented, Description("Set Over Drive status")] + void SetODStatus ([in, Description("Set Over Drive status")] UINT32 Data); + + [WmiMethodId(52), emented, Description("Set Light Control Owner")] + void SetLightControlOwner ([in, Description("Set Light Control Owner")] UINT32 Data); + + [WmiMethodId(53), emented, Description("Set DDS Control Owner")] + void SetDDSControlOwner ([in, Description("Set DDS Control Owner")] UINT32 Data); + + [WmiMethodId(54), emented, Description("Get the flag of restore OC value")] + void IsRestoreOCValue ([in, Description("Clean this flag")] UINT32 idx, [out, Description("Restore oc value flag")] UINT32 Data); + + [WmiMethodId(55), emented, Description("Get Real Thremal Mode")] + void GetThermalMode ([out, Description("Real Thremal Mode")] UINT32 Data); + + [WmiMethodId(56), emented, Description("Get the OC switch status in BIOS")] + void GetBIOSOCMode ([out, Description("OC Mode")] UINT32 Data); + + [WmiMethodId(59), emented, Description("Get hardware info support version")] + void GetHardwareInfoSupportVersion ([out, Description("version")] UINT32 Data); + + [WmiMethodId(60), emented, Description("Get Cpu core 0 max frequency")] + void GetCpuFrequency ([out, Description("frequency")] UINT32 Data); + + [WmiMethodId(62), emented, Description("Check the Adapter type fit for OC")] + void IsACFitForOC ([out, Description("AC check result")] UINT32 Data); + + [WmiMethodId(63), emented, Description("Is support IGPU mode")] + void IsSupportIGPUMode ([out, Description("IGPU modes")] UINT32 Data); + + [WmiMethodId(64), emented, Description("Get IGPU Mode Status")] + void GetIGPUModeStatus([out, Description("IGPU Mode Status")] UINT32 Data); + + [WmiMethodId(65), emented, Description("Set IGPU Mode")] + void SetIGPUModeStatus([in, Description("IGPU Mode")] UINT32 mode, [out, Description("return code")] UINT32 Data); + + [WmiMethodId(66), emented, Description("Notify DGPU Status")] + void NotifyDGPUStatus([in, Description("DGPU status")] UINT32 status, [out, Description("return code")] UINT32 Data); + + [WmiMethodId(67), emented, Description("Is changed Y log")] + void IsChangedYLog([out, Description("Is changed Y Log")] UINT32 Data); + + [WmiMethodId(68), emented, Description("Get DGPU Hardwawre ID")] + void GetDGPUHWId([out, Description("Get DGPU Hardware ID")] string Data); + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Definition of CPU OC parameter list"), + guid("{B7F3CA0A-ACDC-42D2-9217-77C6C628FBD2}")] + 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 DefaultValue; + + [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 NOCOrderid; + + [WmiDataId(9), read, Description("Delay time in ms.")] + uint32 Interval; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Definition of GPU OC parameter list"), + guid("{887B54E2-DDDC-4B2C-8B88-68A26A8835D0}")] + 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 defaultvalue; + + [WmiDataId(4), read, Description("OC Offset freqency.")] + uint32 OCOffsetFreq; + + [WmiDataId(5), read, Description("OC Min offset value.")] + uint32 OCMinOffset; + + [WmiDataId(6), read, Description("OC Max offset value.")] + uint32 OCMaxOffset; + + [WmiDataId(7), read, Description("OC Offset Scale.")] + uint32 OCOffsetScale; + + [WmiDataId(8), read, Description("OC Order id.")] + uint32 OCOrderid; + + [WmiDataId(9), read, Description("NON-OC Order id.")] + uint32 NOCOrderid; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Fancooling 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")] + uint32 EventId; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Smart 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")] + uint32 mode; + + [WmiDataId(2), read, Description("version of FN+Q")] + uint32 version; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Smart Fan setting mode change event"), + guid("{D320289E-8FEA-41E1-86F9-611D83151B5F}")] + 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("POWER 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")] + uint32 mode; + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("Thermal Mode Real Mode change event"), + guid("{D320289E-8FEA-41E0-86F9-911D83151B5F}")] + class LENOVO_GAMEZONE_THERMAL_MODE_EVENT: WMIEvent { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiDataId(1), read, Description("Thermal Mode Real Mode")] + uint32 mode; + }; diff --git a/Documentation/wmi/devices/lenovo-wmi-other-method.rst b/Documentation/wmi/devices/lenovo-wmi-other-method.rst new file mode 100644 index 000000000000..d555f1ed9588 --- /dev/null +++ b/Documentation/wmi/devices/lenovo-wmi-other-method.rst @@ -0,0 +1,142 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later +=========================================================== +Lenovo WMI Interface Other Mode Driver (lenovo-wmi-other) +=========================================================== + +Introduction +============ +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 fw_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 attibute 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. + +The following attributes are supported: + - 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 + +Each attribute has the following properties: + - current_value + - default_value + - display_name + - max_value + - min_value + - scalar_increment + - type + + +WMI interface description +========================= + +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("LENOVO_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 ")] + void GetDataByCommand([in] uint32 IDs, [in] uint32 Command, [out] uint32 DataSize, [out, WmiSizeIs("DataSize")] uint32 Data[]); + + [WmiMethodId(99), Implemented, Description("Get Data By Package for TAC")] + void GetDataByPackage([in, Max(40)] uint8 Input[], [out] uint32 DataSize, [out, WmiSizeIs("DataSize")] uint8 Data[]); + }; + + [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), + Description("LENOVO 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("LENOVO 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 DefaultValue; + + [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("LENOVO 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 6f78d6bcbc7b..e20c32b3c480 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13151,6 +13151,13 @@ S: Maintained W: http://legousb.sourceforge.net/ F: drivers/usb/misc/legousbtower.c +LENOVO WMI drivers +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 + LETSKETCH HID TABLET DRIVER M: Hans de Goede L: linux-input@vger.kernel.org From patchwork Tue Feb 25 21:59:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Derek J. Clark" X-Patchwork-Id: 13991034 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 D5A9E2139A1; Tue, 25 Feb 2025 22:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520861; cv=none; b=aMry02xthsZpRmWiRSbDdPtiT59oeruMTohjJ3ZtTetb0bYgPD8OT5SbXI1UxNupz7GaINvs8/B1hFpqVIVZG6rduYBly3SobOnAEZb3L0pZ9+VlC2pun8Y3id3s0mKA66ldU8Rwy+IaME01aJYIfVEN/6t5QRztLwtUCKWartQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520861; c=relaxed/simple; bh=p0TIaqKuB9K7upm2B6/WydO6vYh1n7OLqqe5pGuD4cU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=piO/kOSO22QyBZCTZWKJDg0DcVWF0bwEg3myHOMuKkGBsHGhrZP7GUJRF5DQIW7LJOd1vykYcDWHr0vejL8WFofynNHN5BG+NasTv8x0+DuHM0pIkzImqNpmUNtCMymxN0iH9w3CnSJ6w9gjpvmqQ8UQIbVLmErxjgg7lmX/IwI= 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=Aq3ZeJ0z; arc=none smtp.client-ip=209.85.214.176 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="Aq3ZeJ0z" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-220ecbdb4c2so55997295ad.3; Tue, 25 Feb 2025 14:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740520859; x=1741125659; 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=TvlSIjdr8at7Dduq+DXOaEk62Flvmo8cn+Fh3H1DkZs=; b=Aq3ZeJ0zGakFO3Bhi3FTGH4CBQNmhBR95FIa1o9w8bRZLw/6PpB5vqlQeniDfqkvdv zKemICx3FC7oNSGhz+WfZj9LqT2KkNKPc4uCbKWqYpBmJiyqOKEhYIcBfzORq7at3TXC UGUvumsnYTSH0Lz5+xwxJq2KUWaxzeOjVPuLxDTLyLVwJYNslWJIWp5NvRnnyJrIJXoh Pkd5ttZozvreQlqsZ+y8wchUfo0pcHpBQAdia3+HadKfltUbUCnefelUY3ZxcsRrHD/s 18dqa9YJBy+nqAFjLuSF+Uv97GmRuY4KTDcxre/N7gvgOQGXUY66mMyup7eKojEVnMNM VuhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740520859; x=1741125659; 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=TvlSIjdr8at7Dduq+DXOaEk62Flvmo8cn+Fh3H1DkZs=; b=PjdvwcanXysGhFAbjVNaMT7dFnOYwyjK6ZyTVe8z06a39QYcY/9z2LFr+irG2JmQrC yy1LuWG1Ns/6hRDuZjlblDVnqpyFzjw0S6uCoHHvU7jAxee9EoBnnEMSTKa3WR09Qf9O bJtqypVYn5p52hNfVAKbNNm3cHc+iZi3sEoVMC10/S4O84av+riG1lZO06OMZme4fSXb o1EwVA6ODS2I4HeSJXZAnJgwI+VtT+wTb9f+Wlws0LvnSDtRmZGPJecp2+QdmmD6jVqe E3yyireqqklEXwAGD5nOI3iUGtVPF/pEJQNVP4p+9oz4G4xE0E3SJ+XaYFx7wVMRd7wg vcPw== X-Forwarded-Encrypted: i=1; AJvYcCUphb39ldP6q1w7n+Ar97NIQiuWLWrzK6Ls6DYzvnajcOn7TywRUA2BxRw9vOVk4agC4VRwwpXMOxo=@vger.kernel.org, AJvYcCUqVDjmP9iixyf7Zi3AWZ1cjWbalXBwOQVUZ7oj2oK81nTtHNLjD0idmvSoEQfFM6RvDEyNzQ4UTZ0eDz+/wjEFE/cENQ==@vger.kernel.org, AJvYcCVE29yPYntiUIMUYYKu9TfF6h62Q9q3aM2//lmQ+JFCSRhIHCc5AS2ydBqPcpy/5fpGi6fqZBsYrCVc+LMH@vger.kernel.org X-Gm-Message-State: AOJu0YxdUX9fMBwB8uly74Fes027OwCy3WKgRV408R0xka7Gfn+zJvyt +CSDlLtCt8MKq2eqtTaFrDWSiVHWEA7k3lt5vI4XEZLeJ7AZ8t7S X-Gm-Gg: ASbGncsW1Z9K9oYZmy7i81lrb71QNeF2NLpLHHXjz8FBeS+fNWM+JnRvux3lInv9a84 pWc4F5vg0eUFMsO4GiUfw6/KLRfi6pJW963NaGV11TqAcncm7mKUhVFHBepQ9o2uZVcZI/AfjGT VEB7Y57gFjJApYgwFgTnyGhTyf07VhBZqDb1fsJmfqHmxzItfyDwED/Sv7cdUkrCT3dafXKjW+H IN7MwYkYbeay/N+gXy9I25qFG84nT57HH5aMzFJ3Ehzw+OP/u6r8P2CufBYI4pD77vrhegMKs8s LMbQzoMy+T2xXZpEtWf6Hfz/6QhWJYX/52QUr6WlSSua/+M9saX6iW3GP5H2xPhYFJ2Hc5KNXGt nM6IohR/ahZIOFieF+qW+sfks X-Google-Smtp-Source: AGHT+IG6L3ieaeaQC+kDSRb4gTOleSrvpGjc38QlawGfHJR95qpiK7VZK8Ef/Y05J90A/13nTd6DnA== X-Received: by 2002:a05:6a00:27a1:b0:72a:9ddf:55ab with SMTP id d2e1a72fcca58-73426cbf981mr28272594b3a.10.1740520858868; Tue, 25 Feb 2025 14:00:58 -0800 (PST) Received: from localhost.localdomain (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a6f912fsm2114122b3a.61.2025.02.25.14.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 14:00:56 -0800 (PST) From: "Derek J. Clark" To: Hans de Goede , =?utf-8?q?Ilpo_J=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 , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] platform/x86: Add Lenovo Gamezone WMI Driver Date: Tue, 25 Feb 2025 13:59:53 -0800 Message-ID: <20250225220037.16073-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250225220037.16073-1-derekjohn.clark@gmail.com> References: <20250225220037.16073-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds lenovo-wmi-gamezone.c which provides a driver for the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI. Adds lenovo-wmi.h and lenovo-wmi.c which provide helper functions for wmidev_evaluate_method as well as prototypes for exported functions. v3: - Use notifier chain to report platform profile changes to any subscribed drivers. - Adds THERMAL_MODE_EVENT GUID and .notify function to trigger notifier chain. - Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented. - Update to include recent changes to platform-profile. 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 gamezone_wmi to lenovo_wmi_gz_priv and gz_wmi to priv. - Remove GZ_WMI symbol exporting. Signed-off-by: Derek J. Clark --- MAINTAINERS | 3 + drivers/platform/x86/Kconfig | 16 + drivers/platform/x86/Makefile | 2 + drivers/platform/x86/lenovo-wmi-gamezone.c | 374 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi.c | 77 +++++ drivers/platform/x86/lenovo-wmi.h | 62 ++++ 6 files changed, 534 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.c create mode 100644 drivers/platform/x86/lenovo-wmi.c create mode 100644 drivers/platform/x86/lenovo-wmi.h diff --git a/MAINTAINERS b/MAINTAINERS index e20c32b3c480..cf7f4fce1a25 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13157,6 +13157,9 @@ 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-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi.c +F: drivers/platform/x86/lenovo-wmi.h LETSKETCH HID TABLET DRIVER M: Hans de Goede diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 7e20a58861eb..875822e6bd65 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -459,6 +459,22 @@ config IBM_RTL state = 0 (BIOS SMIs on) state = 1 (BIOS SMIs off) +config LENOVO_WMI + tristate + depends on ACPI_WMI + +config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMI + select ACPI_PLATFORM_PROFILE + select LENOVO_WMI + 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. + config IDEAPAD_LAPTOP tristate "Lenovo IdeaPad Laptop Extras" depends on ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 5f6307246e69..4a7b2d14eb82 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -67,7 +67,9 @@ obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o +obj-$(CONFIG_LENOVO_WMI) += lenovo-wmi.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o +obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o # Intel obj-y += intel/ diff --git a/drivers/platform/x86/lenovo-wmi-gamezone.c b/drivers/platform/x86/lenovo-wmi-gamezone.c new file mode 100644 index 000000000000..d5329fecba47 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi-gamezone.c @@ -0,0 +1,374 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo GameZone WMI interface driver. The GameZone WMI interface provides + * platform profile and fan curve settings for devices that fall under the + * "Gaming Series" of Lenovo Legion devices. + * + * Copyright(C) 2024 Derek J. Clark + */ + +#include "linux/container_of.h" +#include "linux/printk.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "lenovo-wmi.h" + +/* Interface GUIDs */ +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" +#define THERMAL_MODE_EVENT_GUID "D320289E-8FEA-41E0-86F9-911D83151B5F" + +/* Method IDs */ +#define WMI_METHOD_ID_SMARTFAN_SUPP 43 /* IsSupportSmartFan */ +#define WMI_METHOD_ID_SMARTFAN_SET 44 /* SetSmartFanMode */ +#define WMI_METHOD_ID_SMARTFAN_GET 45 /* GetSmartFanMode */ + +enum lenovo_wmi_gz_type { + GAMEZONE_FULL = 1, + THERMAL_MODE, +}; + +#define GAMEZONE_WMI_DEVICE(guid, type) \ + .guid_string = (guid), .context = &(enum lenovo_wmi_gz_type) \ + { \ + type \ + } + +static BLOCKING_NOTIFIER_HEAD(gz_chain_head); +static DEFINE_MUTEX(gz_chain_mutex); + +struct lenovo_wmi_gz_priv { + enum platform_profile_option current_profile; + struct wmi_device *wdev; + bool extreme_supported; + struct device *ppdev; /*platform profile device */ + enum lenovo_wmi_gz_type type; + struct blocking_notifier_head nhead; +}; + +struct quirk_entry { + bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug = { + .extreme_supported = false, +}; + +/* Platform Profile Methods & Setup */ +static int +lenovo_wmi_gz_platform_profile_supported(struct lenovo_wmi_gz_priv *priv, + int *supported) +{ + return lenovo_wmidev_evaluate_method_1(priv->wdev, 0x0, + WMI_METHOD_ID_SMARTFAN_SUPP, 0, supported); +} + +static int lenovo_wmi_gz_profile_get(struct device *dev, + enum platform_profile_option *profile) +{ + struct lenovo_wmi_gz_priv *priv = dev_get_drvdata(dev); + int sel_prof; + int ret; + + ret = lenovo_wmidev_evaluate_method_1(priv->wdev, 0x0, + WMI_METHOD_ID_SMARTFAN_GET, 0, &sel_prof); + if (ret) + return ret; + + switch (sel_prof) { + case SMARTFAN_MODE_QUIET: + *profile = PLATFORM_PROFILE_LOW_POWER; + break; + case SMARTFAN_MODE_BALANCED: + *profile = PLATFORM_PROFILE_BALANCED; + break; + case SMARTFAN_MODE_PERFORMANCE: + if (priv->extreme_supported) { + *profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE; + break; + } + *profile = PLATFORM_PROFILE_PERFORMANCE; + break; + case SMARTFAN_MODE_EXTREME: + *profile = PLATFORM_PROFILE_PERFORMANCE; + break; + case SMARTFAN_MODE_CUSTOM: + *profile = PLATFORM_PROFILE_CUSTOM; + break; + default: + return -EINVAL; + } + + priv->current_profile = *profile; + + ret = blocking_notifier_call_chain(&gz_chain_head, THERMAL_MODE_EVENT, + &sel_prof); + if (ret == NOTIFY_BAD) + pr_err("Failed to send notification to call chain for WMI event %u\n", + priv->type); + return 0; +} + +static int lenovo_wmi_gz_profile_set(struct device *dev, + enum platform_profile_option profile) +{ + struct lenovo_wmi_gz_priv *priv = dev_get_drvdata(dev); + int sel_prof; + int ret; + + switch (profile) { + case PLATFORM_PROFILE_LOW_POWER: + sel_prof = SMARTFAN_MODE_QUIET; + break; + case PLATFORM_PROFILE_BALANCED: + sel_prof = SMARTFAN_MODE_BALANCED; + break; + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: + sel_prof = SMARTFAN_MODE_PERFORMANCE; + break; + case PLATFORM_PROFILE_PERFORMANCE: + if (priv->extreme_supported) { + sel_prof = SMARTFAN_MODE_EXTREME; + break; + } + sel_prof = SMARTFAN_MODE_PERFORMANCE; + break; + case PLATFORM_PROFILE_CUSTOM: + sel_prof = SMARTFAN_MODE_CUSTOM; + break; + default: + return -EOPNOTSUPP; + } + + ret = lenovo_wmidev_evaluate_method_1(priv->wdev, 0x0, + WMI_METHOD_ID_SMARTFAN_SET, sel_prof, NULL); + if (ret) + return ret; + + return 0; +} + +static const struct dmi_system_id fwbug_list[] = { + { + .ident = "Legion Go 8APU1", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go 8APU1"), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident = "Legion Go S 8ARP1", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go S 8ARP1"), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident = "Legion Go S 8APU1", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "Legion Go S 8APU1"), + }, + .driver_data = &quirk_no_extreme_bug, + }, + {}, + +}; + +static bool 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 = dmi_first_match(fwbug_list); + if (!dmi_id) + return true; + + quirks = dmi_id->driver_data; + return quirks->extreme_supported; +} + +static int lenovo_wmi_platform_profile_probe(void *drvdata, + unsigned long *choices) +{ + struct lenovo_wmi_gz_priv *priv = drvdata; + enum platform_profile_option profile; + int profile_support_ver; + int ret; + + ret = lenovo_wmi_gz_platform_profile_supported(priv, + &profile_support_ver); + if (ret) + return ret; + + if (profile_support_ver < 1) + return -ENODEV; + + priv->extreme_supported = extreme_supported(profile_support_ver); + + 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); + + if (priv->extreme_supported) + set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices); + + return 0; +} + +static const struct platform_profile_ops lenovo_wmi_gz_platform_profile_ops = { + .probe = lenovo_wmi_platform_profile_probe, + .profile_get = lenovo_wmi_gz_profile_get, + .profile_set = lenovo_wmi_gz_profile_set, +}; + +/* Notifier Methods */ +int lenovo_wmi_gz_register_notifier(struct notifier_block *nb) +{ + guard(mutex)(&gz_chain_mutex); + return blocking_notifier_chain_register(&gz_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lenovo_wmi_gz_register_notifier, "GZ_WMI"); + +int lenovo_wmi_gz_unregister_notifier(struct notifier_block *nb) +{ + guard(mutex)(&gz_chain_mutex); + return blocking_notifier_chain_unregister(&gz_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lenovo_wmi_gz_unregister_notifier, "GZ_WMI"); + +static void devm_lenovo_wmi_gz_unregister_notifier(void *data) +{ + struct notifier_block *nb = data; + + lenovo_wmi_gz_unregister_notifier(nb); +} + +int devm_lenovo_wmi_gz_register_notifier(struct device *dev, + struct notifier_block *nb) +{ + int ret; + + ret = lenovo_wmi_gz_register_notifier(nb); + if (ret < 0) + return ret; + + return devm_add_action_or_reset(dev, devm_lenovo_wmi_gz_unregister_notifier, nb); +} +EXPORT_SYMBOL_NS_GPL(devm_lenovo_wmi_gz_register_notifier, "GZ_WMI"); + +/* Driver Methods */ +static void lenovo_wmi_gz_notify(struct wmi_device *wdev, + union acpi_object *obj) +{ + struct lenovo_wmi_gz_priv *tm_priv = dev_get_drvdata(&wdev->dev); + struct lenovo_wmi_gz_priv *gz_priv = + container_of(&gz_chain_head, struct lenovo_wmi_gz_priv, nhead); + int sel_prof; + int ret; + + if (obj->type != ACPI_TYPE_INTEGER) + return; + + switch (tm_priv->type) { + case THERMAL_MODE: + sel_prof = obj->integer.value; + break; + default: + return; + } + + /* Update primary Gamezone instance */ + switch (sel_prof) { + case SMARTFAN_MODE_QUIET: + gz_priv->current_profile = PLATFORM_PROFILE_LOW_POWER; + break; + case SMARTFAN_MODE_BALANCED: + gz_priv->current_profile = PLATFORM_PROFILE_BALANCED; + break; + case SMARTFAN_MODE_PERFORMANCE: + if (gz_priv->extreme_supported) { + gz_priv->current_profile = + PLATFORM_PROFILE_BALANCED_PERFORMANCE; + break; + } + gz_priv->current_profile = PLATFORM_PROFILE_PERFORMANCE; + break; + case SMARTFAN_MODE_EXTREME: + gz_priv->current_profile = PLATFORM_PROFILE_PERFORMANCE; + break; + case SMARTFAN_MODE_CUSTOM: + gz_priv->current_profile = PLATFORM_PROFILE_CUSTOM; + break; + default: + break; + } + + ret = blocking_notifier_call_chain(&gz_chain_head, THERMAL_MODE_EVENT, + &sel_prof); + if (ret == NOTIFY_BAD) + pr_err("Failed to send notification to call chain for WMI event %u\n", + tm_priv->type); +} + +static int lenovo_wmi_gz_probe(struct wmi_device *wdev, const void *context) +{ + struct lenovo_wmi_gz_priv *priv = + devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + + if (!priv) + return -ENOMEM; + + if (!context) + return -EINVAL; + + priv->wdev = wdev; + priv->type = *((enum lenovo_wmi_gz_type *)context); + + dev_set_drvdata(&wdev->dev, priv); + + if (priv->type != GAMEZONE_FULL) + return 0; + + priv->nhead = gz_chain_head; + priv->ppdev = platform_profile_register(&wdev->dev, "lenovo-wmi-gamezone", + priv, &lenovo_wmi_gz_platform_profile_ops); + + return 0; +} + +static const struct wmi_device_id lenovo_wmi_gz_id_table[] = { + { GAMEZONE_WMI_DEVICE(LENOVO_GAMEZONE_GUID, GAMEZONE_FULL) }, + { GAMEZONE_WMI_DEVICE(THERMAL_MODE_EVENT_GUID, THERMAL_MODE) }, + {} +}; + +static struct wmi_driver lenovo_wmi_gz_driver = { + .driver = { + .name = "lenovo_wmi_gamezone", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = lenovo_wmi_gz_id_table, + .probe = lenovo_wmi_gz_probe, + .notify = lenovo_wmi_gz_notify, + .no_singleton = true, +}; + +module_wmi_driver(lenovo_wmi_gz_driver); + +MODULE_IMPORT_NS("LENOVO_WMI"); +MODULE_DEVICE_TABLE(wmi, lenovo_wmi_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.c b/drivers/platform/x86/lenovo-wmi.c new file mode 100644 index 000000000000..0de2c37e69bd --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo Legion WMI interface driver. The Lenovo Legion WMI interface is + * broken up into multiple GUID interfaces that require cross-references + * between GUID's for some functionality. The "Custom Method" interface is a + * legacy interface for managing and displaying CPU & GPU power and hwmon + * settings and readings. The "Other Mode" interface is a modern interface + * that replaces or extends the "Custom Method" interface methods. The + * "Gamezone" interface adds advanced features such as fan profiles and + * overclocking. The "Lighting" interface adds control of various status + * lights related to different hardware components. "Other Mode" uses + * the data structs LENOVO_CAPABILITY_DATA_00, LENOVO_CAPABILITY_DATA_01 + * and LENOVO_CAPABILITY_DATA_02 structs for capability information. + * + * Copyright(C) 2024 Derek J. Clark + * + */ + +#include +#include "lenovo-wmi.h" + +/* wmidev_evaluate_method helper functions */ +static int lenovo_wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, + u32 method_id, struct acpi_buffer *in, + struct acpi_buffer *out) +{ + acpi_status status; + + status = wmidev_evaluate_method(wdev, instance, method_id, in, out); + + if (ACPI_FAILURE(status)) + return -EIO; + + return 0; +}; + +int lenovo_wmidev_evaluate_method_2(struct wmi_device *wdev, u8 instance, + u32 method_id, u32 arg0, u32 arg1, + u32 *retval) +{ + struct wmi_method_args args = { arg0, arg1 }; + struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *ret_obj __free(kfree) = NULL; + int err; + + err = lenovo_wmidev_evaluate_method(wdev, instance, method_id, &input, + &output); + + if (err) + return err; + + if (retval) { + ret_obj = (union acpi_object *)output.pointer; + if (!ret_obj) + return -ENODATA; + + if (ret_obj->type != ACPI_TYPE_INTEGER) + return -ENXIO; + + *retval = (u32)ret_obj->integer.value; + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(lenovo_wmidev_evaluate_method_2, "LENOVO_WMI"); + +int lenovo_wmidev_evaluate_method_1(struct wmi_device *wdev, u8 instance, + u32 method_id, u32 arg0, u32 *retval) +{ + return lenovo_wmidev_evaluate_method_2(wdev, instance, method_id, arg0, + 0, retval); +} +EXPORT_SYMBOL_NS_GPL(lenovo_wmidev_evaluate_method_1, "LENOVO_WMI"); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo WMI Common Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo-wmi.h b/drivers/platform/x86/lenovo-wmi.h new file mode 100644 index 000000000000..113928b4fc0f --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * + * Lenovo Legion WMI interface driver. The Lenovo Legion WMI interface is + * broken up into multiple GUID interfaces that require cross-references + * between GUID's for some functionality. The "Custom Method" interface is a + * legacy interface for managing and displaying CPU & GPU power and hwmon + * settings and readings. The "Other Mode" interface is a modern interface + * that replaces or extends the "Custom Method" interface methods. The + * "Gamezone" interface adds advanced features such as fan profiles and + * overclocking. The "Lighting" interface adds control of various status + * lights related to different hardware components. "Other Mode" uses + * the data structs LENOVO_CAPABILITY_DATA_00, LENOVO_CAPABILITY_DATA_01 + * and LENOVO_CAPABILITY_DATA_02 structs for capability information. + * + * Copyright(C) 2024 Derek J. Clark + * + */ +#include +#include + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#ifndef _LENOVO_WMI_H_ +#define _LENOVO_WMI_H_ + +#include +#include +#include + +struct wmi_method_args { + u32 arg0; + u32 arg1; +}; + +/* gamezone structs */ +enum thermal_mode { + SMARTFAN_MODE_QUIET = 0x01, + SMARTFAN_MODE_BALANCED = 0x02, + SMARTFAN_MODE_PERFORMANCE = 0x03, + SMARTFAN_MODE_EXTREME = 0xE0, /* Ver 6+ */ + SMARTFAN_MODE_CUSTOM = 0xFF, +}; + +enum lenovo_wmi_action { + THERMAL_MODE_EVENT = 1, +}; + +/* wmidev_evaluate_method helper functions */ +int lenovo_wmidev_evaluate_method_2(struct wmi_device *wdev, u8 instance, + u32 method_id, u32 arg0, u32 arg1, + u32 *retval); +int lenovo_wmidev_evaluate_method_1(struct wmi_device *wdev, u8 instance, + u32 method_id, u32 arg0, u32 *retval); + +/* lenovo_wmi_gz_driver notifier functions */ +int lenovo_wmi_gz_notifier_call(struct notifier_block *nb, unsigned long action, + enum platform_profile_option *profile); +int lenovo_wmi_gz_register_notifier(struct notifier_block *nb); +int lenovo_wmi_gz_unregister_notifier(struct notifier_block *nb); +int devm_lenovo_wmi_gz_register_notifier(struct device *dev, + struct notifier_block *nb); +#endif /* !_LENOVO_WMI_H_ */ From patchwork Tue Feb 25 21:59:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Derek J. Clark" X-Patchwork-Id: 13991035 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 A856C213E71; Tue, 25 Feb 2025 22:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520865; cv=none; b=MijO9rzUmEq07MRtXb4PqnUVN7T8j1fZegQvIu8yQ/OrewRKwgRYg0G9rr/d0X9irzBZ//PNxgfKr/42gaNzg7P2RqyfjkVnuoieq/XEALrnGb5W/K+0PoOWbWjpN4nG8REnM0osyE4t48evhjjUuMYfd2q0Mj6t0lVdtGcjXIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520865; c=relaxed/simple; bh=0ohKyiHeUnWLo4t+bwTpZU53hcgGcF1n7nOwHd6jGx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LUlC0UdYLCa0vJmcBSIZPEIEgQcU+1DO2DEZV1a3WNjctsP5QH0DZQ/Yc119iFC08S5j6qWX8nGALDoc+zY/epOZGWhhHbKLW1dRZoVbAQRvP+KRWW4GMj432fEjP3oO6JOd6p2PyhGgWkLq3BxlAHLR3wezN7mvTbdVwGuF1Bo= 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=a0wnrHl4; arc=none smtp.client-ip=209.85.214.169 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="a0wnrHl4" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-221050f3f00so139685935ad.2; Tue, 25 Feb 2025 14:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740520863; x=1741125663; 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=jbfElIS/OfppmRAJwL8J8XnWcD9jZJ+jmout7v0/MhU=; b=a0wnrHl4f10y8XLiPiXTZ+xe3d+O4lifimioLIxv/o6zqRhunmrvQYbgNZFhU03VMY csbOm+7F1lCkcQgXjngZFFQTh7B1Mg/qigeqRXoa2BNAtEaYIuGhhdE72pMaiIyyOEqO 6U25WzXAW/iwp7ZuyUunf7qsdVoy1En0C0GDXtceqUpF8R4hmmRSaB1aaaDUzIe0XdAT jwHTEKHyUOa8A7Wou1ZvZuJ/4DKCFlsNjjgHznVqw8iErs2zXm6XwL4eyHLKrP/VLZno 33ZJhw9Sg9nBhQj90db+C4mvk5ieN6llssKG6qMUxrbYL6bJLzgxIC6Ak/EdUquw4Voo B/SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740520863; x=1741125663; 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=jbfElIS/OfppmRAJwL8J8XnWcD9jZJ+jmout7v0/MhU=; b=LLhqnvCZVGCRY3Eg18pKeo3Sl72WECoz9addkPKi39p8G6KlCye6/LAzTn/WB0cZa6 K9u6g7O6So+NKGiizCVCaZTKWBo/Jru6HoppNBQvGTStM5zQqk/6lG3I7OKwguHhVyoj zQXC2OXDCxdU7EOe6bF5zZVr/sqBFn/MIOjspJHaFh/94vAYulaYvaeuxJXBuqeZPB5U 4EOq3NaclajIK3v/EoVZhmxMiLNCZcI7BGd50AJ5Z2WC6LoDRUEYq7d+yr1xvTJsKr8D nQ5heW/I1cTv6I86iIsUA7l7bKEbtmYBartKOFqvjASJvob5VyuLL8/S67lasnkxYoCi lUFA== X-Forwarded-Encrypted: i=1; AJvYcCUsobwjCrC6xFYZS8fy4442hIYKEeyyYJ4eTlXMEqqdQrNUI0jBRnkpgXFyenj/G34iKvccWSuEgx7wgv/6@vger.kernel.org, AJvYcCVkd1QPFXgYo/n9XSmHJFapbGVRWanJBxl6QvQ/5XgDwiST17HJRMQWthJ6lpxa6lwLn5ELSANthZj17f/gKq1DFGMjYA==@vger.kernel.org, AJvYcCWluizy1KcMQziDj6laC5E8r18nRjjOb/izgGFOkHIVJgzIOtyD97RJDwqBUHIhTdrEMNGr/ZKYMJA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywauwwxgz5u/Azc1hmzsX2yc81CDWmhrwpt6yeGjBbmIEdR/0gH Vj8NOjPR+HUDPAr2qMbnecIWFcmZZqxyI8SOeN/8jIo83xxbblLf X-Gm-Gg: ASbGncvAWoy1LJnsBp3vS/JR7/4YdeIsGo22KnORpyCcHI1I3VvenGvIwglJIoSa8Ax bg8VEcVP4AJadKlfBOdycvyVaSyBPkRNNmEe4OdJNkwiGVrIMNbssD0HJRQojrko1t9I+GbXqhl D59QI3Q8A8lAn3EqmQuCqwdkA8PIBkcSwZmNKrq/A0O3V+t664/3HFfNql9Bl1+MH8B83ij0+Vv yzMMfrFiEfmXodbhNdOUAwrg/KQ9UlvmFdoHHnIz3Z08IcNNkhWicN7/osWVe/9r4rVZIGCSQK/ 1ujl3JTAdrItono4ejhxxioIwwfZMgD++id+06LbYpCcrFGOJ2MPHTAtq8mLw8nhR1EVf0c9mtU 8xxbqWOC1D60HGb0J/N+luy9u X-Google-Smtp-Source: AGHT+IH0cam5xu4pPnpjz/1Cf1EydOtBa1ogwwcIIWyeqhm8UBJU/HNcNuKGH+DhLkRJnMXn2xW7LA== X-Received: by 2002:a05:6a00:a26:b0:730:8a0a:9ef8 with SMTP id d2e1a72fcca58-734791ab253mr8109116b3a.22.1740520862775; Tue, 25 Feb 2025 14:01:02 -0800 (PST) Received: from localhost.localdomain (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a6f912fsm2114122b3a.61.2025.02.25.14.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 14:01:02 -0800 (PST) From: "Derek J. Clark" To: Hans de Goede , =?utf-8?q?Ilpo_J=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 , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] platform/x86: Add Lenovo Capability Data 01 WMI Driver Date: Tue, 25 Feb 2025 13:59:54 -0800 Message-ID: <20250225220037.16073-4-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250225220037.16073-1-derekjohn.clark@gmail.com> References: <20250225220037.16073-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds lenovo-wmi-capdata01.c which provides a driver for 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. 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. Signed-off-by: Derek J. Clark --- MAINTAINERS | 1 + drivers/platform/x86/Kconfig | 5 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-capdata01.c | 140 ++++++++++++++++++++ drivers/platform/x86/lenovo-wmi.h | 19 +++ 5 files changed, 166 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-capdata01.c diff --git a/MAINTAINERS b/MAINTAINERS index cf7f4fce1a25..f6d3e79e50ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13157,6 +13157,7 @@ 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-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-gamezone.c F: drivers/platform/x86/lenovo-wmi.c F: drivers/platform/x86/lenovo-wmi.h diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 875822e6bd65..56336dc3c2d0 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -475,6 +475,11 @@ config LENOVO_WMI_GAMEZONE To compile this driver as a module, choose M here: the module will be called lenovo-wmi-gamezone. +config LENOVO_WMI_DATA01 + tristate + depends on ACPI_WMI + select LENOVO_WMI + config IDEAPAD_LAPTOP tristate "Lenovo IdeaPad Laptop Extras" depends on ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 4a7b2d14eb82..be9031bea090 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI) += lenovo-wmi.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o +obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o # Intel obj-y += intel/ diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.c b/drivers/platform/x86/lenovo-wmi-capdata01.c new file mode 100644 index 000000000000..0fe156d5d770 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides + * information on tunable attributes used by the "Other Mode" WMI interface, + * including if it is supported by the hardware, the default_value, max_value, + * min_value, and step increment. + * + * Copyright(C) 2024 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include "lenovo-wmi.h" + +/* Interface GUIDs */ +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154" + +static int lenovo_cd01_component_bind(struct device *cd01_dev, + struct device *om_dev, void *data) +{ + struct lenovo_wmi_cd01 *cd01 = dev_get_drvdata(cd01_dev); + struct lenovo_wmi_om *om = dev_get_drvdata(om_dev); + + om->cd01 = cd01; + return 0; +} + +static void lenovo_cd01_component_unbind(struct device *cd01_dev, + struct device *om_dev, void *data) + +{ + struct wmi_device *om_wdev = + container_of(om_dev, struct wmi_device, dev); + struct lenovo_wmi_om *om = + container_of(&om_wdev, struct lenovo_wmi_om, wdev); + + om->cd01 = NULL; +} + +static const struct component_ops lenovo_cd01_component_ops = { + .bind = lenovo_cd01_component_bind, + .unbind = lenovo_cd01_component_unbind, +}; + +static int lenovo_wmi_cd01_setup(struct lenovo_wmi_cd01 *cd01) +{ + size_t cd_size = sizeof(struct capdata01); + int count, idx; + + count = wmidev_instance_count(cd01->wdev); + + cd01->capdata = devm_kmalloc_array(&cd01->wdev->dev, (size_t)count, + sizeof(*cd01->capdata), GFP_KERNEL); + if (!cd01->capdata) + return -ENOMEM; + + cd01->instance_count = count; + + for (idx = 0; idx < count; idx++) { + union acpi_object *ret_obj __free(kfree) = NULL; + struct capdata01 *cap_ptr = + devm_kmalloc(&cd01->wdev->dev, cd_size, GFP_KERNEL); + ret_obj = wmidev_block_query(cd01->wdev, idx); + if (!ret_obj) + continue; + + if (ret_obj->type != ACPI_TYPE_BUFFER) + continue; + + if (ret_obj->buffer.length != cd_size) + continue; + + memcpy(cap_ptr, ret_obj->buffer.pointer, + ret_obj->buffer.length); + cd01->capdata[idx] = cap_ptr; + } + return 0; +} + +static int lenovo_wmi_cd01_probe(struct wmi_device *wdev, const void *context) + +{ + struct lenovo_wmi_cd01 *cd01; + int ret; + + cd01 = devm_kzalloc(&wdev->dev, sizeof(*cd01), GFP_KERNEL); + if (!cd01) + return -ENOMEM; + + cd01->wdev = wdev; + + ret = lenovo_wmi_cd01_setup(cd01); + if (ret) + return ret; + + dev_set_drvdata(&wdev->dev, cd01); + + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops); + + return ret; +} + +static void lenovo_wmi_cd01_remove(struct wmi_device *wdev) +{ + component_del(&wdev->dev, &lenovo_cd01_component_ops); +} + +static const struct wmi_device_id lenovo_wmi_cd01_id_table[] = { + { LENOVO_CAPABILITY_DATA_01_GUID, NULL }, + {} +}; + +static struct wmi_driver lenovo_wmi_cd01_driver = { + .driver = { + .name = "lenovo_wmi_cd01", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = lenovo_wmi_cd01_id_table, + .probe = lenovo_wmi_cd01_probe, + .remove = lenovo_wmi_cd01_remove, + .no_singleton = true, +}; + +int lenovo_wmi_cd01_match(struct device *dev, void *data) +{ + return dev->driver == &lenovo_wmi_cd01_driver.driver; +} +EXPORT_SYMBOL_GPL(lenovo_wmi_cd01_match); + +module_wmi_driver(lenovo_wmi_cd01_driver); + +MODULE_DEVICE_TABLE(wmi, lenovo_wmi_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.h b/drivers/platform/x86/lenovo-wmi.h index 113928b4fc0f..07fa67ed89d6 100644 --- a/drivers/platform/x86/lenovo-wmi.h +++ b/drivers/platform/x86/lenovo-wmi.h @@ -45,6 +45,22 @@ enum lenovo_wmi_action { THERMAL_MODE_EVENT = 1, }; +/* capdata01 structs */ +struct lenovo_wmi_cd01 { + struct capdata01 **capdata; + struct wmi_device *wdev; + int instance_count; +}; + +struct capdata01 { + u32 id; + u32 supported; + u32 default_value; + u32 step; + u32 min_value; + u32 max_value; +}; + /* wmidev_evaluate_method helper functions */ int lenovo_wmidev_evaluate_method_2(struct wmi_device *wdev, u8 instance, u32 method_id, u32 arg0, u32 arg1, @@ -52,6 +68,9 @@ int lenovo_wmidev_evaluate_method_2(struct wmi_device *wdev, u8 instance, int lenovo_wmidev_evaluate_method_1(struct wmi_device *wdev, u8 instance, u32 method_id, u32 arg0, u32 *retval); +/* lenovo_wmi_cd01_driver match function */ +int lenovo_wmi_cd01_match(struct device *dev, void *data); + /* lenovo_wmi_gz_driver notifier functions */ int lenovo_wmi_gz_notifier_call(struct notifier_block *nb, unsigned long action, enum platform_profile_option *profile); From patchwork Tue Feb 25 21:59:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Derek J. Clark" X-Patchwork-Id: 13991036 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2AC421420D; Tue, 25 Feb 2025 22:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520868; cv=none; b=l/c+xN4klo+R9pj6sehFvwktRsefgZ8uBRwtU+/VQZcndR8RqEjqlWHdeUYb3oocLk9f7W+tlQcxBTQCQwrKKwi+wwni7un0+XWxkVN10ot8oKbQW0PWPeaJtlEDViCck7W3lvb6iFK9YKhbr8SLMvSFYoOkl0Pytw2l6iZPPvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740520868; c=relaxed/simple; bh=tsIn0aucyxBof+SRqlAMePMDtOcsrMOwMvbJ9ArZUng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+0r6/7dcci8hQCLwbRiO0cKV13fa0nPc7asGOREZj/+ALkoClUqnsXEhfPR7hCkh3gXuC92xuuq7kneFKIqr/L4TwWSXkWGCi5kVDE1mvXMUm+2HMFSs5awqR3kAdYGRm16eB+dLVTMSqi74zelCb1w9UuWkF+9J7z99dMb8BM= 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=ls45Ht4M; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ls45Ht4M" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-22185cddbffso4204165ad.1; Tue, 25 Feb 2025 14:01:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740520866; x=1741125666; 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=4TXKd6UkN3Hg8KFSyjnRrCcr9fJdV1PGOq0/4yh+RTo=; b=ls45Ht4MCdiDYYmQibDfQ7BzOlTRPXVefnIWo9fssJ89P0raDu7dfTYl9oxC8LNPJE Fs8QrXJijQllfSrOwxOtKK/IVFizr5SNYEPgVbJRBkeNb2dsDC5Wbsd5MUtNrpTWca/4 mb8Mb/+oPMl+0wjzHS0c1tua2CeO1zEFljJMZ8bw6lX1DeVaLcpCFUhW6YUzVAE841R6 G7+kKp8sgb6+ta/0OtO+Z00W1V+lheJCl2h5TPe3YWxtb0BWVvZkto9CtrJmy24RNNkJ CYXu8Wf1twVMJRmwGy1tG2DdmTMif2PKh4zVBxIl32KWrla0IWup5yww7OfnhnhJUnCc vcQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740520866; x=1741125666; 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=4TXKd6UkN3Hg8KFSyjnRrCcr9fJdV1PGOq0/4yh+RTo=; b=Vwf8UG0vblYESHACDeSolH2IRT4O2fr11ZTo/yy/LldQ3h8sVr0XuBiiMDeoK4HfoY xCrjdoosK52tncGVdTH4l6Qt3P16Sfoj2RaohCd9VE8SxnXSrsTTfyShzmhDycQq1La2 P0rEdUrxviR7eYKmvB8BIFHPiT+gNioOvtwJ0tcMIVJxOefCQWvmoabkDULRgA8eM0Ro V91lhM1Kdw5JwhRfci8Hm7ryFXo7LrZN45IxdD/nIuPcwOhls1HQRrG1XYKfzGBHf3Tm Qm1Ynzhnb/3fBZEMrobfvKhKhMVHUs3Kc21i3adgEweTV4iQIlHwpZbipquCqBU+DDZH 9MGQ== X-Forwarded-Encrypted: i=1; AJvYcCUtlfoyu0ygk7zt0T7K/iE1xTgEZDG6NzEG8oQIDvrv21K6KV72dQ7KHiYzArv6LGjmuc56CBQ9GuWT8N87@vger.kernel.org, AJvYcCWJzhLj9osiaSk6iTyoJaCQ6fpKWKwxn8thM+GnznYueRNcPfjSYHVQ5El3wYc79w5eR8WKukRmDtwwUtzDrQo3AbxLlA==@vger.kernel.org, AJvYcCWdBOazsONqcOPwz0X+eLChBXa4FfUX+Z2ux2Ao8yYD6LAplUaccYlIkBcIxm7w2/P0v45LqcXTv1k=@vger.kernel.org X-Gm-Message-State: AOJu0YymPWcyWc5wPHGe/B0VvwFyMC3t7zZsSk95gA5zMEPbjXpNdGZz Bwjt24rEwpwIjcGuFyY0aWX6Fhe1gsbBcyThEJo+ILx2HkUUXzA7 X-Gm-Gg: ASbGnctA1aQUuy0mwH0MiBGAzwfiXbSt9USGRN3OecWC4klFxuedF13m0q/Rzb8x/wu /jhUo1psgDXXdn8ULvVnh9Wm6IenKww9P0JAjU9hkCzZjRFg9kdSWvf5OHZAQlWVp20zYjgL/Du hDxcfLXnLT2bL8XJ3SHV9cn8PEi3I6WTo2id873zCbBygnQlghwh74XluTyqt/wquruAeAlEh13 Jmrd2d7tg2hGAxkFG4bQNGouigSy6IDIePrCmG/TztT6GW1YBsCVRytI9MF+QhaQTIoDd+/THpc EWKTeTNt3cwwU8ECMpryJxY5q2Ey+TEmEAgyiVb1FDKdJqVLtY7P7wAWVZayr3GhI93WYMPy303 dsa6yuU20t7mzdBZxgXWcSK+q X-Google-Smtp-Source: AGHT+IG1RrKlRDfngAvylxvoMEi15LzJW7Nx6bQ22Pmj48nHvZtGseZxIh9WwH3aIxMYP9z6kurjlA== X-Received: by 2002:a05:6a00:3a1e:b0:732:5875:eb95 with SMTP id d2e1a72fcca58-734140898f3mr46112860b3a.4.1740520865748; Tue, 25 Feb 2025 14:01:05 -0800 (PST) Received: from localhost.localdomain (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a6f912fsm2114122b3a.61.2025.02.25.14.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 14:01:05 -0800 (PST) From: "Derek J. Clark" To: Hans de Goede , =?utf-8?q?Ilpo_J=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 , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] platform/x86: Add Lenovo Other Mode WMI Driver Date: Tue, 25 Feb 2025 13:59:55 -0800 Message-ID: <20250225220037.16073-5-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250225220037.16073-1-derekjohn.clark@gmail.com> References: <20250225220037.16073-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds lenovo-wmi-other.c which provides a driver for 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. 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. Signed-off-by: Derek J. Clark --- MAINTAINERS | 1 + drivers/platform/x86/Kconfig | 14 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-other.c | 549 ++++++++++++++++++++++++ drivers/platform/x86/lenovo-wmi.h | 13 + 5 files changed, 578 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-other.c diff --git a/MAINTAINERS b/MAINTAINERS index f6d3e79e50ce..f6e16b2346a2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13159,6 +13159,7 @@ F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst F: Documentation/wmi/devices/lenovo-wmi-other.rst F: drivers/platform/x86/lenovo-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi-other.c F: drivers/platform/x86/lenovo-wmi.c F: drivers/platform/x86/lenovo-wmi.h diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 56336dc3c2d0..017ecdfad8ce 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -480,6 +480,20 @@ config LENOVO_WMI_DATA01 depends on ACPI_WMI select LENOVO_WMI +config LENOVO_WMI_TUNING + tristate "Lenovo Other Mode WMI Driver" + depends on ACPI_WMI + select FW_ATTR_CLASS + select LENOVO_WMI + select LENOVO_WMI_DATA01 + 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 exposed by + Lenovo software in Windows. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-other. + config IDEAPAD_LAPTOP tristate "Lenovo IdeaPad Laptop Extras" depends on ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index be9031bea090..28ce39631a6d 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -71,6 +71,7 @@ obj-$(CONFIG_LENOVO_WMI) += lenovo-wmi.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o +obj-$(CONFIG_LENOVO_WMI_TUNING) += lenovo-wmi-other.o # Intel obj-y += intel/ diff --git a/drivers/platform/x86/lenovo-wmi-other.c b/drivers/platform/x86/lenovo-wmi-other.c new file mode 100644 index 000000000000..cd04ead94ba3 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi-other.c @@ -0,0 +1,549 @@ +// 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 functions provided by the "Other Mode" WMI + * interface. This enables CPU and GPU power limit as well as various other + * attributes for devices that fall under the "Gaming Series" of Lenovo laptop + * devices. Each attribute exposed by the "Other Mode"" interface has a + * corresponding LENOVO_CAPABILITY_DATA_01 struct that allows the driver to + * probe details about the attribute such as set/get support, step, min, max, + * and default value. Each attibute has multiple pages, one for each of the + * fan profiles managed by the Gamezone interface. + * + * 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) 2024 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lenovo-wmi.h" +#include "firmware_attributes_class.h" + +/* Interface GUIDs */ +#define LENOVO_OTHER_METHOD_GUID "DC2A8805-3A8C-41BA-A6F7-092E0089CD3B" + +/* Device IDs */ +#define WMI_DEVICE_ID_CPU 0x01 + +/* WMI_DEVICE_ID_CPU feature IDs */ +#define WMI_FEATURE_ID_CPU_SPPT 0x01 /* Short Term Power Limit */ +#define WMI_FEATURE_ID_CPU_FPPT 0x03 /* Long Term Power Limit */ +#define WMI_FEATURE_ID_CPU_SPL 0x02 /* Peak Power Limit */ + +/* Type IDs*/ +#define WMI_TYPE_ID_NONE 0x00 + +/* Method IDs */ +#define WMI_FAN_TABLE_GET 5 /* Other Mode FAN_METHOD Getter */ +#define WMI_FAN_TABLE_SET 6 /* Other Mode FAN_METHOD Setter */ +#define WMI_FEATURE_VALUE_GET 17 /* Other Mode Getter */ +#define WMI_FEATURE_VALUE_SET 18 /* Other Mode Setter */ + +/* Attribute ID bitmasks */ +#define ATTR_DEV_ID_MASK GENMASK(31, 24) +#define ATTR_FEAT_ID_MASK GENMASK(23, 16) +#define ATTR_MODE_ID_MASK GENMASK(15, 8) +#define ATTR_TYPE_ID_MASK GENMASK(7, 0) + +enum attribute_property { + DEFAULT_VAL, + MAX_VAL, + MIN_VAL, + STEP_VAL, + SUPPORTED, +}; + +/* Tunable attribute that uses LENOVO_CAPABILITY_DATA_01 */ +struct tunable_attr_01 { + u32 type_id; + u32 device_id; + u32 feature_id; + u32 store_value; + struct device *dev; + struct capdata01 *capdata; +}; + +/* Tunable Attributes */ +struct tunable_attr_01 ppt_pl1_spl = { .device_id = WMI_DEVICE_ID_CPU, + .feature_id = WMI_FEATURE_ID_CPU_SPL, + .type_id = WMI_TYPE_ID_NONE }; +struct tunable_attr_01 ppt_pl2_sppt = { .device_id = WMI_DEVICE_ID_CPU, + .feature_id = WMI_FEATURE_ID_CPU_SPPT, + .type_id = WMI_TYPE_ID_NONE }; +struct tunable_attr_01 ppt_pl3_fppt = { .device_id = WMI_DEVICE_ID_CPU, + .feature_id = WMI_FEATURE_ID_CPU_FPPT, + .type_id = WMI_TYPE_ID_NONE }; + +struct capdata01_attr_group { + const struct attribute_group *attr_group; + struct tunable_attr_01 *tunable_attr; +}; + +#define FW_ATTR_FOLDER "lenovo-wmi-other" + +/** + * int_type_show() - Emit the data type for an integer attribute + * @kobj: Pointer to the driver object. + * @kobj_attribute: Pointer to the attribute calling this function. + * @buf: The buffer to write to. + * + * Returns: 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_get - Get the data of the specified attribute + * from lenovo_wmi_om->cd01. + * @tunable_attr: The attribute to be populated. + * + * Returns: Either 0 or an error. + */ +static struct capdata01 * +attr_capdata01_get_data(struct lenovo_wmi_om *om, + struct tunable_attr_01 *tunable_attr, + enum thermal_mode mode) +{ + u32 attribute_id = + FIELD_PREP(ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(ATTR_MODE_ID_MASK, mode) | + FIELD_PREP(ATTR_TYPE_ID_MASK, tunable_attr->type_id); + int idx; + + if (!om->cd01) + return NULL; + + for (idx = 0; idx < om->cd01->instance_count; idx++) { + if (om->cd01->capdata[idx]->id != attribute_id) + continue; + return om->cd01->capdata[idx]; + } + + return NULL; +} + +/** + * attr_capdata01_show() - Get the value of the specified attribute property + * from LENOVO_CAPABILITY_DATA_01. + * @kobj: Pointer to the driver object. + * @kobj_attribute: 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. + * + * This function is intended to be generic so it can be called from any "_show" + * attribute which works only with integers. + * + * If the WMI is success, then the sysfs attribute is notified. + * + * Returns: Either number of characters written to buf, or an error. + */ +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 lenovo_wmi_om *om = dev_get_drvdata(tunable_attr->dev); + struct capdata01 *capdata; + int value; + + if (!om) + return -ENODEV; + + capdata = attr_capdata01_get_data(om, tunable_attr, + SMARTFAN_MODE_CUSTOM); + + if (!capdata) + return -ENODEV; + + switch (prop) { + case DEFAULT_VAL: + value = capdata->default_value; + break; + case MAX_VAL: + value = capdata->max_value; + break; + case MIN_VAL: + value = capdata->min_value; + break; + case STEP_VAL: + value = capdata->step; + break; + default: + return -EINVAL; + } + return sysfs_emit(buf, "%d\n", value); +} + +/* Simple attribute creation */ + +/* + * att_current_value_store() - Set the current value of the given attribute + * @kobj: Pointer to the driver object. + * @kobj_attribute: 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 attr. + * @tunable_attr: The attribute to be stored. + * + * This function is intended to be generic so it can be called from any + * attribute's "current_value_store" which works only with integers. The + * integer to be sent to the WMI method is range checked and an error returned + * if out of range. + * + * If the value is valid and WMI is success, then the sysfs attribute is + * notified. + * + * Returns: Either count, or an error. + */ +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 lenovo_wmi_om *om = dev_get_drvdata(tunable_attr->dev); + struct capdata01 *capdata; + u32 attribute_id; + u32 value; + int err; + + if (!om) + return -ENODEV; + + capdata = attr_capdata01_get_data(om, tunable_attr, + SMARTFAN_MODE_CUSTOM); + + if (!capdata) + return -ENODEV; + + attribute_id = FIELD_PREP(ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(ATTR_MODE_ID_MASK, SMARTFAN_MODE_CUSTOM) | + FIELD_PREP(ATTR_TYPE_ID_MASK, tunable_attr->type_id); + + err = kstrtouint(buf, 10, &value); + if (err) + return err; + + if (value < capdata->min_value || value > capdata->max_value) + return -EINVAL; + + err = lenovo_wmidev_evaluate_method_2(om->wdev, 0x0, + WMI_FEATURE_VALUE_SET, + attribute_id, value, NULL); + + if (err) + return err; + + tunable_attr->store_value = value; + return count; +}; + +/* + * attr_current_value_show() - Get the current value of the given attribute + * @kobj: Pointer to the driver object. + * @kobj_attribute: Pointer to the attribute calling this function. + * @buf: The buffer to write to. + * @tunable_attr: The attribute to be read. + * + * This function is intended to be generic so it can be called from any "_show" + * attribute which works only with integers. + * + * If the WMI is success, then the sysfs attribute is notified. + * + * Returns: Either number of characters written to buf, or an error. + */ +static ssize_t attr_current_value_show(struct kobject *kobj, + struct kobj_attribute *kattr, char *buf, + struct tunable_attr_01 *tunable_attr) +{ + struct lenovo_wmi_om *om = dev_get_drvdata(tunable_attr->dev); + u32 attribute_id; + int retval; + int err; + + if (!om) + return -ENODEV; + + attribute_id = FIELD_PREP(ATTR_DEV_ID_MASK, tunable_attr->device_id) | + FIELD_PREP(ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | + FIELD_PREP(ATTR_MODE_ID_MASK, om->mode) | + FIELD_PREP(ATTR_TYPE_ID_MASK, tunable_attr->type_id); + + err = lenovo_wmidev_evaluate_method_1(om->wdev, 0x0, WMI_FEATURE_VALUE_GET, + attribute_id, &retval); + + if (err) + return err; + + return sysfs_emit(buf, "%d\n", retval); +} + +/* Attribute macros */ +#define __LL_ATTR_RO(_func, _name) \ + { \ + .attr = { .name = __stringify(_name), .mode = 0444 }, \ + .show = _func##_##_name##_show, \ + } + +#define __LL_ATTR_RO_AS(_name, _show) \ + { \ + .attr = { .name = __stringify(_name), .mode = 0444 }, \ + .show = _show, \ + } + +#define __LL_ATTR_RW(_func, _name) \ + __ATTR(_name, 0644, _func##_##_name##_show, _func##_##_name##_store) + +/* Shows a formatted static variable */ +#define __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 = \ + __LL_ATTR_RO(_attrname, _prop) + +/* Attribute current value read/write */ +#define __LL_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 = \ + __LL_ATTR_RW(_attrname, current_value) + +/* Attribute property read only */ +#define __LL_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 = \ + __LL_ATTR_RO(_attrname, _prop) + +#define ATTR_GROUP_LL_TUNABLE_CAP01(_attrname, _fsname, _dispname) \ + __LL_TUNABLE_CURRENT_VALUE_CAP01(_attrname); \ + __LL_TUNABLE_RO_CAP01(default_value, _attrname, DEFAULT_VAL); \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + __LL_TUNABLE_RO_CAP01(max_value, _attrname, MAX_VAL); \ + __LL_TUNABLE_RO_CAP01(min_value, _attrname, MIN_VAL); \ + __LL_TUNABLE_RO_CAP01(scalar_increment, _attrname, STEP_VAL); \ + static struct kobj_attribute attr_##_attrname##_type = \ + __LL_ATTR_RO_AS(type, int_type_show); \ + static struct attribute *_attrname##_attrs[] = { \ + &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 = { \ + .name = _fsname, .attrs = _attrname##_attrs \ + } + +ATTR_GROUP_LL_TUNABLE_CAP01(ppt_pl1_spl, "ppt_pl1_spl", + "Set the CPU sustained power limit"); +ATTR_GROUP_LL_TUNABLE_CAP01(ppt_pl2_sppt, "ppt_pl2_sppt", + "Set the CPU slow package power tracking limit"); +ATTR_GROUP_LL_TUNABLE_CAP01(ppt_pl3_fppt, "ppt_pl3_fppt", + "Set the CPU fast package power tracking limit"); + +static struct capdata01_attr_group capdata01_attr_groups[] = { + { &ppt_pl1_spl_attr_group, &ppt_pl1_spl }, + { &ppt_pl2_sppt_attr_group, &ppt_pl2_sppt }, + { &ppt_pl3_fppt_attr_group, &ppt_pl3_fppt }, + {}, +}; + +static int lenovo_wmi_om_fw_attr_add(struct lenovo_wmi_om *om) +{ + int err, i; + + om->fw_attr_dev = device_create(&firmware_attributes_class, NULL, + MKDEV(0, 0), NULL, "%s", + FW_ATTR_FOLDER); + if (IS_ERR(om->fw_attr_dev)) { + err = PTR_ERR(om->fw_attr_dev); + return err; + } + + om->fw_attr_kset = + kset_create_and_add("attributes", NULL, &om->fw_attr_dev->kobj); + if (!om->fw_attr_kset) { + err = -ENOMEM; + goto err_destroy_classdev; + } + + for (i = 0; i < ARRAY_SIZE(capdata01_attr_groups) - 1; i++) { + err = sysfs_create_group(&om->fw_attr_kset->kobj, + capdata01_attr_groups[i].attr_group); + if (err) { + pr_debug("Failed to create sysfs-group for %s: %d\n", + capdata01_attr_groups[i].attr_group->name, + err); + goto err_remove_groups; + } + capdata01_attr_groups[i].tunable_attr->dev = &om->wdev->dev; + } + return 0; + +err_remove_groups: + while (i-- > 0) { + sysfs_remove_group(&om->fw_attr_kset->kobj, + capdata01_attr_groups[i].attr_group); + } + kset_unregister(om->fw_attr_kset); + +err_destroy_classdev: + device_unregister(om->fw_attr_dev); + return err; +} + +static int lenovo_wmi_om_notifier(struct notifier_block *nb, unsigned long cmd, + void *data) +{ + struct lenovo_wmi_om *om = container_of(nb, struct lenovo_wmi_om, nb); + + if (!om) + NOTIFY_BAD; + + if (cmd != THERMAL_MODE_EVENT) + NOTIFY_OK; + + om->mode = *((enum thermal_mode *)data); + + return NOTIFY_OK; +} + +static int lenovo_wmi_om_master_bind(struct device *dev) +{ + struct lenovo_wmi_om *om = dev_get_drvdata(dev); + + int ret; + + ret = component_bind_all(dev, om); + if (ret) + return ret; + + return lenovo_wmi_om_fw_attr_add(om); +} + +static void lenovo_wmi_om_master_unbind(struct device *dev) +{ + component_unbind_all(dev, NULL); +} + +static const struct component_master_ops lenovo_wmi_om_master_ops = { + .bind = lenovo_wmi_om_master_bind, + .unbind = lenovo_wmi_om_master_unbind, +}; + +static int lenovo_wmi_other_probe(struct wmi_device *wdev, const void *context) +{ + struct notifier_block lenovo_wmi_om_notifier_block = { + .notifier_call = lenovo_wmi_om_notifier, + }; + struct component_match *master_match = NULL; + struct lenovo_wmi_om *om; + int ret; + + om = devm_kzalloc(&wdev->dev, sizeof(*om), GFP_KERNEL); + if (!om) { + ret = -ENOMEM; + goto err_exit; + } + + om->wdev = wdev; + om->nb = lenovo_wmi_om_notifier_block; + om->mode = SMARTFAN_MODE_CUSTOM; /* fallback */ + + dev_set_drvdata(&wdev->dev, om); + + ret = devm_lenovo_wmi_gz_register_notifier(&wdev->dev, &om->nb); + if (ret) { + pr_err("Failed to register notifier_block\n"); + goto err_exit; + } + + component_match_add(&wdev->dev, &master_match, lenovo_wmi_cd01_match, + NULL); + if (IS_ERR_OR_NULL(master_match)) { + ret = -ENOMEM; + goto err_exit; + } + + ret = component_master_add_with_match(&wdev->dev, + &lenovo_wmi_om_master_ops, + master_match); + if (ret < 0) { + dev_err(&wdev->dev, "Master comp add failed %d\n", ret); + goto err_exit; + } + + return 0; +err_exit: + kfree(om); + return ret; +} + +static void lenovo_wmi_other_remove(struct wmi_device *wdev) +{ + struct lenovo_wmi_om *om = dev_get_drvdata(&wdev->dev); + + kset_unregister(om->fw_attr_kset); + device_destroy(&firmware_attributes_class, MKDEV(0, 0)); + component_master_del(&wdev->dev, &lenovo_wmi_om_master_ops); +} + +static const struct wmi_device_id lenovo_wmi_other_id_table[] = { + { LENOVO_OTHER_METHOD_GUID, NULL }, + {} +}; + +static struct wmi_driver lenovo_wmi_other_driver = { + .driver = { + .name = "lenovo_wmi_other", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = lenovo_wmi_other_id_table, + .probe = lenovo_wmi_other_probe, + .remove = lenovo_wmi_other_remove, + .no_singleton = true, +}; + +module_wmi_driver(lenovo_wmi_other_driver); + +MODULE_IMPORT_NS("CAPDATA_WMI"); +MODULE_IMPORT_NS("GZ_WMI"); +MODULE_IMPORT_NS("LENOVO_WMI"); +MODULE_DEVICE_TABLE(wmi, lenovo_wmi_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.h b/drivers/platform/x86/lenovo-wmi.h index 07fa67ed89d6..40b6418fbf02 100644 --- a/drivers/platform/x86/lenovo-wmi.h +++ b/drivers/platform/x86/lenovo-wmi.h @@ -61,6 +61,19 @@ struct capdata01 { u32 max_value; }; +/* other method structs */ +struct lenovo_wmi_om { + struct component_master_ops *ops; + struct lenovo_wmi_cd01 *cd01; + struct capdata01 **capdata; + struct device *fw_attr_dev; + struct kset *fw_attr_kset; + struct notifier_block nb; + struct wmi_device *wdev; + enum thermal_mode mode; + int instance_count; +}; + /* wmidev_evaluate_method helper functions */ int lenovo_wmidev_evaluate_method_2(struct wmi_device *wdev, u8 instance, u32 method_id, u32 arg0, u32 arg1,