From patchwork Fri Jun 30 05:35:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10131672vqr; Thu, 29 Jun 2023 23:03:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WEEVvP//4U2XLBdlOXriokMJOb/HUaBPxt5ImX+3tiHtpAPLBsP/mu+UgEyI+ssNvbKQw X-Received: by 2002:a6b:c897:0:b0:780:cb36:6f24 with SMTP id y145-20020a6bc897000000b00780cb366f24mr2407013iof.2.1688105020926; Thu, 29 Jun 2023 23:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688105020; cv=none; d=google.com; s=arc-20160816; b=XxCbGkm614wkl3U+r45SWM8x0vFV+Mn17neATtWcfeEYrvsjYpBmsg0YXuobo4lNIp pLaBJmNIxPzZYBDSZSDhIt7ggvxTH25ZQjBt1OtHsWIdp6+9IpJb8GXzV3HaIijrf/kt A356CiYf071YGUZJFYM6UDwRZOs1ioZSdiYn71zXWwrKd6qf7G3retSzdwraD4kpywPW JMcFHmaOM4TXhhU0q7m3+uAzyoW4QsiAtp6HAgHwPlFon1DJio85/YL8ZgWt23206gdF v9cXJZahsiIF46xtmPBTxBDN+AOdVniMUgfgRTJJs5UpHIFnisF7CAZaJRWlnzk//4zI AV1w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=Ab/j1cmtr5gB7ZXPOJB+ktG4aqFLzuvR15XN6nPVFUap4LjY0DHW9ulP5XBpNbbRT5 87Jwt5odkRdjxVSCyFcvl6If32XYp3RnDuyTnF9csrOv0msIrkrdzNWOGOYPVNHGFS5w EXmHmhVwKi9ezCXvodNvfQq/QSiO1VY9wMammnPfHywvyp0ESbfR3yYGqn9CMAh9qIKH 28tLAUJUzdjYU0Mlj/A2pfgHyAft62fpRo5Tv1Ngs24CuepsQj3Fe5+T+So2sPIqXBmP nEgWDInX0T2h7gOxUk22orqMQcJ4GSBS6EEAlHVSFHdnrHYWo476mJuhTZk727CaEYM/ UDwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=lK78Ij8M; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=h89N3O7P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a634c11000000b0055384255b9bsi10891301pga.24.2023.06.29.23.03.24; Thu, 29 Jun 2023 23:03:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=lK78Ij8M; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=h89N3O7P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231899AbjF3FgP (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjF3FgJ (ORCPT ); Fri, 30 Jun 2023 01:36:09 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 018E210C3; Thu, 29 Jun 2023 22:36:07 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id A19B2320097B; Fri, 30 Jun 2023 01:36:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Jun 2023 01:36:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1688103366; x= 1688189766; bh=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; b=l K78Ij8M9TMWOgvTqmjHgozTkSju81NN0h0srfKtcTclZGuaSrLLxRzGnGWgCK660 PFS/U2fA2P7J/TwnbJc13f6S1soyBEil6ux9m5ZsNUxh+9D8KCeosyX6gthUATMO EF1udh09hJutwXD2dQXoG56/EPtn8GJzBL2FRjsh+9WV1TmH/P7YVam9BF7tlXf9 NVfWh3oxfUVcp9vYUGne6fMaS1uHKRU4QEfdlQbQ6qiHCmD6kfJn3wXqH9/BA0i5 UxwSLuNwKhYOdOP+UJplQB+ko2vaTh4TKT0PSgcf0s0raIYm+WjuonFDBty4K4nf bvHBiKPE57ZTZLnJ3cNaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1688103366; x= 1688189766; bh=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; b=h 89N3O7PLKiSGlGZkMzudZL8sQZnHml5XG045RhrsGBX7nTRFHYfdS/F4JBrXQul3 9hGTsbeLDvTOjnxow3FGu9T5yHsu7WY2rP4Wusjm/vGabx7/65F5PVc+cBi+XyfF Qa3U8Uc1LjFHU4JS+j2w5/wOSqOm3MYuDPFzMvB6bsyFzf/EDloYJWKrkaR3gtwQ HmFg5PKdVgc+w92OUYtZ8gJ4ohK3q7SyV1tpozQtgRjnjOd7fgCgR8RYsSdxc6c4 43A4lCfu/eJEPVCgxqN1GDudrsu0Qemzg1Yvr43H9AB6d+eoA+GS8VCcwwQoCW20 sCjwDdYgotEiwOfgXOLbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:02 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH v2 1/8] platform/x86: asus-wmi: add support for showing charger mode Date: Fri, 30 Jun 2023 17:35:45 +1200 Message-ID: <20230630053552.976579-2-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770106410181345190?= X-GMAIL-MSGID: =?utf-8?q?1770106410181345190?= Expose a WMI method in sysfs platform for showing which connected charger the laptop is currently using. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- .../ABI/testing/sysfs-platform-asus-wmi | 10 +++++++++ drivers/platform/x86/asus-wmi.c | 21 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index a77a004a1baa..eb29e3023c7b 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -98,3 +98,13 @@ Description: Enable an LCD response-time boost to reduce or remove ghosting: * 0 - Disable, * 1 - Enable + +What: /sys/devices/platform//charge_mode +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Get the current charging mode being used: + * 1 - Barrel connected charger, + * 2 - USB-C charging + * 3 - Both connected, barrel used for charging \ No newline at end of file diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 1038dfdcdd32..f23375d5fb82 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -237,6 +237,7 @@ struct asus_wmi { u8 fan_boost_mode_mask; u8 fan_boost_mode; + bool charge_mode_available; bool egpu_enable_available; bool dgpu_disable_available; bool gpu_mux_mode_available; @@ -586,6 +587,22 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) asus_wmi_tablet_sw_report(asus, result); } +/* Charging mode, 1=Barrel, 2=USB ******************************************/ +static ssize_t charge_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result, value; + + result = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CHARGE_MODE, &value); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", value & 0xff); +} + +static DEVICE_ATTR_RO(charge_mode); + /* dGPU ********************************************************************/ static ssize_t dgpu_disable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -3462,6 +3479,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_camera.attr, &dev_attr_cardr.attr, &dev_attr_touchpad.attr, + &dev_attr_charge_mode.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, &dev_attr_gpu_mux_mode.attr, @@ -3491,6 +3509,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_LID_RESUME; else if (attr == &dev_attr_als_enable.attr) devid = ASUS_WMI_DEVID_ALS_ENABLE; + else if (attr == &dev_attr_charge_mode.attr) + ok = asus->charge_mode_available; else if (attr == &dev_attr_egpu_enable.attr) ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) @@ -3757,6 +3777,7 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_platform; + asus->charge_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CHARGE_MODE); asus->egpu_enable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU); asus->dgpu_disable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU); asus->gpu_mux_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 28234dc9fa6a..f90cafe26af1 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -95,6 +95,9 @@ /* Keyboard dock */ #define ASUS_WMI_DEVID_KBD_DOCK 0x00120063 +/* Charging mode - 1=Barrel, 2=USB */ +#define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C + /* dgpu on/off */ #define ASUS_WMI_DEVID_EGPU 0x00090019