From patchwork Wed Oct 18 08:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ai Chao X-Patchwork-Id: 154736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4631680vqb; Wed, 18 Oct 2023 01:00:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELEOOde96zZTRQ7cuqfLzdjzXRrpx3Vc01mff5HDlgc+hpJ4Mg/TYbOD4MJo0efWWmK3Jl X-Received: by 2002:a05:6871:5c7:b0:1d6:4c63:7ba9 with SMTP id v7-20020a05687105c700b001d64c637ba9mr5188836oan.3.1697616058282; Wed, 18 Oct 2023 01:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697616058; cv=none; d=google.com; s=arc-20160816; b=Zd7Wj3icMsK1Sb8iS6gpV7Hc8vZ03SpM6Mu4sAZfChTkVIN+Qu66iRT+0JauTJ4nNS E9RWan+YpnY9QJoEiWHUL83tWgQLbdEhKCUy1KjxktIyW8lLF0nu1yrCAWYjZXmADFCA 9nBTwho0GbvYUyrvwyAlCjfP+u9mBC8daQUKqvKY+FswSXzoflH14eZ7yLvg8xNwE5vf 3OBPkJRbqvSTQpxVBygHP386Kome88VT1xVdelfVVNMa67Denw/uuRDI9N9lo/GoZ2x5 mRzp98WqGjOhatBnQk0g7oRldJfkBkSt1Y4SbWTwGSVfX9xTmSWiFb09nBJAEbHFMIb4 +cCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=szqWOVMmMsYs9pz+i4IiIS8aKIQS5ZXyZxqjotVoUEg=; fh=ivYmr0o8KDtItHztFMDVClSxkHWL1AET9bzZHT+FszU=; b=Fy2szUF3XB9/xEPEO7X+XFq+f696Szqw83eDgHKAdtXm/PZi2TzATQMkupPBArt8vD W88+4yF9wF+1pezKAwxudmOQfKmzDQ38zszUjiMvoEPp8T9UB0pIDkc0/azALFh8+nuN BTovU+h2z6/jS2g3Ab8DfW5nJGtp8vGAzQrjZJrPJUkP0IH2Bkxf2w9kY3s1VmyTrJgz u4yxOGOR3luLQ4Xl7+p66r/5SpgR+8x47TwL8F+ZT3pqFadWel8qaYFGJZuv2mjs0ewG hlFZsUMT81NH3jhKDDB58l+fMllR5Pfy3gHT2DqYjcksxXyTbvkyJL0NhyTo05z/srlM 7mGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t4-20020a63f344000000b005789c7e9bf2si1579921pgj.627.2023.10.18.01.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 01:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 31A138051A33; Wed, 18 Oct 2023 01:00:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234909AbjJRIAh (ORCPT + 24 others); Wed, 18 Oct 2023 04:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234836AbjJRIAf (ORCPT ); Wed, 18 Oct 2023 04:00:35 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E468AB6; Wed, 18 Oct 2023 01:00:29 -0700 (PDT) X-UUID: 7f0e3553ee3f4f6290557764006b6873-20231018 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:d0125bfd-6957-4a48-992d-1bb266fd9e14,IP:5,U RL:0,TC:0,Content:-5,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:10 X-CID-INFO: VERSION:1.1.32,REQID:d0125bfd-6957-4a48-992d-1bb266fd9e14,IP:5,URL :0,TC:0,Content:-5,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:10 X-CID-META: VersionHash:5f78ec9,CLOUDID:c392eef0-9a6e-4c39-b73e-f2bc08ca3dc5,B ulkID:231018160020CZ1VO4KK,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 7f0e3553ee3f4f6290557764006b6873-20231018 X-User: aichao@kylinos.cn Received: from localhost.localdomain [(112.64.161.44)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 177125245; Wed, 18 Oct 2023 16:00:17 +0800 From: Ai Chao To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, markgross@kernel.org Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, Ai Chao Subject: [PATCH v3] platform/x86: inspur-wmi: Add platform profile support Date: Wed, 18 Oct 2023 16:00:14 +0800 Message-Id: <20231018080014.536047-1-aichao@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 01:00:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780079455849202102 X-GMAIL-MSGID: 1780079455849202102 Add support for Inspur platforms to used the platform profile feature. This will allow users to determine and control the platform modes between low-power, balanced and performance modes. change for v3 - Remove input device - Using the platform profile interface change for v2 - Remove Event GUID, remove inspur_wmi_notify and inspur_wmi_notify. - Add more explanation. Signed-off-by: Ai Chao --- drivers/platform/x86/Kconfig | 10 ++ drivers/platform/x86/Makefile | 3 + drivers/platform/x86/inspur-wmi.c | 215 ++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 drivers/platform/x86/inspur-wmi.c diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 2a1070543391..d7bd27c53751 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -988,6 +988,16 @@ config TOUCHSCREEN_DMI the OS-image for the device. This option supplies the missing info. Enable this for x86 tablets with Silead or Chipone touchscreens. +config INSPUR_WMI + tristate "Inspur WMI platform profile driver" + depends on ACPI_WMI + help + This will allow users to determine and control the platform modes + between low-power, balanced and performance modes. + + To compile this driver as a module, choose M here: the module + will be called inspur-wmi. + source "drivers/platform/x86/x86-android-tablets/Kconfig" config FW_ATTR_CLASS diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index b457de5abf7d..9285c252757e 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -98,6 +98,9 @@ obj-$(CONFIG_TOSHIBA_WMI) += toshiba-wmi.o # before toshiba_acpi initializes obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o +# Inspur +obj-$(CONFIG_INSPUR_WMI) += inspur-wmi.o + # Laptop drivers obj-$(CONFIG_ACPI_CMPC) += classmate-laptop.o obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o diff --git a/drivers/platform/x86/inspur-wmi.c b/drivers/platform/x86/inspur-wmi.c new file mode 100644 index 000000000000..d0c5ae2e3fcb --- /dev/null +++ b/drivers/platform/x86/inspur-wmi.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Inspur WMI power mode + * + * Copyright (C) 2018 Ai Chao + */ + +#include +#include +#include +#include +#include + +#define WMI_INSPUR_POWERMODE_BIOS_GUID "596C31E3-332D-43C9-AEE9-585493284F5D" + +enum inspur_wmi_method_ids { + INSPUR_WMI_GET_POWERMODE = 0x02, + INSPUR_WMI_SET_POWERMODE = 0x03, +}; + +/** + * Power Mode: + * 0x0: Balance Mode + * 0x1: Performance Mode + * 0x2: Power Saver Mode + */ +enum inspur_tmp_profile { + INSPUR_TMP_PROFILE_BALANCE = 0, + INSPUR_TMP_PROFILE_PERFORMANCE = 1, + INSPUR_TMP_PROFILE_POWERSAVE = 2, +}; + +struct inspur_wmi_priv { + struct wmi_device *wdev; + struct platform_profile_handler handler; +}; + +static int inspur_wmi_perform_query(struct wmi_device *wdev, + enum inspur_wmi_method_ids query_id, + void *buffer, size_t insize, + size_t outsize) +{ + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer input = { insize, buffer}; + union acpi_object *obj; + acpi_status status; + int ret = 0; + + status = wmidev_evaluate_method(wdev, 0, query_id, &input, &output); + if (ACPI_FAILURE(status)) { + dev_err(&wdev->dev, "EC Powermode control failed: %s\n", + acpi_format_exception(status)); + return -EIO; + } + + obj = output.pointer; + if (!obj) + return -EINVAL; + + if (obj->type != ACPI_TYPE_BUFFER || + obj->buffer.length != outsize) { + ret = -EINVAL; + goto out_free; + } + + memcpy(buffer, obj->buffer.pointer, obj->buffer.length); + +out_free: + kfree(obj); + return ret; +} + +/** + * Set Power Mode to EC RAM. If Power Mode value greater than 0x3, + * return error + * Method ID: 0x3 + * Arg: 4 Bytes + * Byte [0]: Power Mode: + * 0x0: Balance Mode + * 0x1: Performance Mode + * 0x2: Power Saver Mode + * Return Value: 4 Bytes + * Byte [0]: Return Code + * 0x0: No Error + * 0x1: Error + */ +static int inspur_platform_profile_set(struct platform_profile_handler *pprof, + enum platform_profile_option profile) +{ + struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv, + handler); + u8 ret_code[4] = {0, 0, 0, 0}; + int ret; + + switch (profile) { + case PLATFORM_PROFILE_BALANCED: + ret_code[0] = INSPUR_TMP_PROFILE_BALANCE; + break; + case PLATFORM_PROFILE_PERFORMANCE: + ret_code[0] = INSPUR_TMP_PROFILE_PERFORMANCE; + break; + case PLATFORM_PROFILE_LOW_POWER: + ret_code[0] = INSPUR_TMP_PROFILE_POWERSAVE; + break; + default: + return -EOPNOTSUPP; + } + + ret = inspur_wmi_perform_query(priv->wdev, INSPUR_WMI_SET_POWERMODE, + ret_code, sizeof(ret_code), + sizeof(ret_code)); + + if (ret < 0) + return ret; + else if (ret_code[0]) + return -EBADRQC; + + return 0; +} + +/** + * Get Power Mode from EC RAM, If Power Mode value greater than 0x3, + * return error + * Method ID: 0x2 + * Return Value: 4 Bytes + * Byte [0]: Return Code + * 0x0: No Error + * 0x1: Error + * Byte [1]: Power Mode + * 0x0: Balance Mode + * 0x1: Performance Mode + * 0x2: Power Saver Mode + */ +static int inspur_platform_profile_get(struct platform_profile_handler *pprof, + enum platform_profile_option *profile) +{ + struct inspur_wmi_priv *priv = container_of(pprof, struct inspur_wmi_priv, + handler); + u8 ret_code[4] = {0, 0, 0, 0}; + int ret; + + ret = inspur_wmi_perform_query(priv->wdev, INSPUR_WMI_GET_POWERMODE, + &ret_code, sizeof(ret_code), + sizeof(ret_code)); + if (ret < 0) + return ret; + else if (ret_code[0]) + return -EBADRQC; + + switch (ret_code[1]) { + case INSPUR_TMP_PROFILE_BALANCE: + *profile = PLATFORM_PROFILE_BALANCED; + break; + case INSPUR_TMP_PROFILE_PERFORMANCE: + *profile = PLATFORM_PROFILE_PERFORMANCE; + break; + case INSPUR_TMP_PROFILE_POWERSAVE: + *profile = PLATFORM_PROFILE_LOW_POWER; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int inspur_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct inspur_wmi_priv *priv; + + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->wdev = wdev; + dev_set_drvdata(&wdev->dev, priv); + + priv->handler.profile_get = inspur_platform_profile_get; + priv->handler.profile_set = inspur_platform_profile_set; + + set_bit(PLATFORM_PROFILE_LOW_POWER, priv->handler.choices); + set_bit(PLATFORM_PROFILE_BALANCED, priv->handler.choices); + set_bit(PLATFORM_PROFILE_PERFORMANCE, priv->handler.choices); + + platform_profile_register(&priv->handler); + return 0; +} + +static void inspur_wmi_remove(struct wmi_device *wdev) +{ + platform_profile_remove(); +} + +static const struct wmi_device_id inspur_wmi_id_table[] = { + { .guid_string = WMI_INSPUR_POWERMODE_BIOS_GUID }, + { } +}; + +MODULE_DEVICE_TABLE(wmi, inspur_wmi_id_table); + +static struct wmi_driver inspur_wmi_driver = { + .driver = { + .name = "inspur-wmi", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = inspur_wmi_id_table, + .probe = inspur_wmi_probe, + .remove = inspur_wmi_remove, +}; + +module_wmi_driver(inspur_wmi_driver); + +MODULE_AUTHOR("Ai Chao "); +MODULE_DESCRIPTION("Inspur WMI hotkeys"); +MODULE_LICENSE("GPL");