Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp273593lqb; Tue, 28 May 2024 15:24:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWG9Q6JrHRuGdVOzkgceNSzmT3Wc3ZWR6+kCN99n5jFhx9lbR8DLV6RLp9/+7CYSchbchEMfdpJOQpd/J3S1cwh4sRula7hcLqv3Qyx8g== X-Google-Smtp-Source: AGHT+IEtLF52bT0LsPNhxc71rY9umrweW9MK4cIV3vq5iqK6wrhwNSViVNKhO8OfR6aAVVb1i+Yu X-Received: by 2002:a05:6871:7428:b0:22e:cd9f:4e55 with SMTP id 586e51a60fabf-24ca1486080mr14431252fac.50.1716935068027; Tue, 28 May 2024 15:24:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716935067; cv=pass; d=google.com; s=arc-20160816; b=JH+XL8YFW7ja/KTehusa/gE7ApTJHLNCoHDQsfIlcOeQm7xpKJHUGn4tpQRDUJxq/x 3vyB2T+YEOd1qTNg3EDQP/4BNnaUq4QVqqC8usmnObbckozyeCJZR0yoht5gafN7RIxA otw4BfAprDss1HLsWO3FJgSUMIHXfsIhCGBgH0iGNI/INgfiIRnAR4j5A5px+crPx2xb YWBG2ImxsAYErTx1lLmusVWFz+VK0D/Q1WwomsQ/1idHT5vRXJgJFbaSmUvpnB6PC3f7 8EDuOzmzlyeJIJmxqK3OjsbiFd+HATHRmcHNlwyFM5oJ8A9D7rH1GxO2+DI6gEp7Ldd4 2pfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=ToPzc8UjXVCcaTha/DNLgmdKIEd80W2Fq2fuFm19kEs=; fh=7maV+9VHjTqgSWU1TBVybwO1v/Gt3U3r6TntCHDnGMk=; b=KlytmkoU1LUEnFDmHp5CQ/6A2AvCMODmzHVhb1j7SVfb+0oNip5VQ+uudaA/JUNHKo rSTfQHJy3yovQ3IJmxDgXJ8KL4XmZW175LpG7irdElltVq+zdDs1SgYc8EKT3wu6A0hj YOk3cSApHsgZqXNEZs/4YzPd1qvdrtjzjA8+KwU58G2/tqnbcKc9XqkdUeZdHBBVkgHY QDqrj3DZU1Z9K48p2UxXIq4boz4yducugv69GvWXN7F4dFSrN7UFh+mAt64117iS9TCN 09dKARMDzs8GDHf9R0OQzqJm3iWbByw0sMFtu7XljUeMKUJN94vxhZY6h1fC47DE5z+X 7qhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=LqSEIs2R; arc=pass (i=1 spf=pass spfdomain=gmx.de dkim=pass dkdomain=gmx.de dmarc=pass fromdomain=gmx.de); spf=pass (google.com: domain of linux-kernel+bounces-193176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18b315asi123327921cf.439.2024.05.28.15.24.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 15:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=LqSEIs2R; arc=pass (i=1 spf=pass spfdomain=gmx.de dkim=pass dkdomain=gmx.de dmarc=pass fromdomain=gmx.de); spf=pass (google.com: domain of linux-kernel+bounces-193176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A893B1C24819 for ; Tue, 28 May 2024 22:24:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B8D213E05D; Tue, 28 May 2024 22:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="LqSEIs2R" Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E188627469; Tue, 28 May 2024 22:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934887; cv=none; b=G9ws6HvvMRB/TEjCz19yQ/TUu/0E3v0TrMZ0xC0d/pBGQhy3bR70yqlCbyupk/Ax8sjzIfp4H0Ar7KQC01R9wl4hV6MUMTyJ6LeJ8MkvdlS2hOgdSznmLEmAkvAgQwnfwsjorUXoha2SoCIQFOATMpbCRHPQkSD/sq80ZV2hGOE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934887; c=relaxed/simple; bh=9ABvswqm9FAVUHd9AZJLhRmlzApUYd45RCUg60b48fU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=i1oyrCV4NlqEEtGpVDofHEdzQw4Q7gzaeULJdq7qIxuqz/CDWxUxK6vLXckXZ6VRcUdv4GzlM7L7vY1D7qGU6ePJ5gh8yeaUmdU58oqB4B3UIyQqhv2pkD23+U4CMMQr6FLskUTaVe11V1pDuAO2LhcaRdwsZELMVkv88ZBh7fk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=LqSEIs2R; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1716934878; x=1717539678; i=w_armin@gmx.de; bh=ToPzc8UjXVCcaTha/DNLgmdKIEd80W2Fq2fuFm19kEs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=LqSEIs2RaQffCUS4JahNNFBP4evIhWPhLkk8i3oJkhO/smDb/N2yduJgILboJRXR cs8GVDzuivnga9egfQjjxzY6WnvmsNq6qc8KBbX14nMwVMWS+6nRkNcNzi6LwN/F1 S5kolC1EuJqUpCp4oAP+vyH0S0Z1e9TcXlJ/Xfhc5QDvRJmr8GQRlhr5IG2Ah9FJh BgB74AieFR5xXabDCVQEcOUbFm8FvmUv7fXPPFpgrJnMDB6g83DVb/LhtI/7WBSkN /qEZQdRqKnVdARow/ysYf2u6xc7h+0zhY52p7VodPoZSmi1+ig0Ue5sTZj6t/glnC PlilwEEqJH2/GHH5gQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mo6qv-1srknt0l8F-00pbIA; Wed, 29 May 2024 00:21:18 +0200 From: Armin Wolf To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] power: supply: hwmon: Add support for power sensors Date: Wed, 29 May 2024 00:21:15 +0200 Message-Id: <20240528222115.791511-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:FEqlk1Wk9wPKKxQpRuKz+TUGv6lXZlVd8YsCE1zXFr84RvScPfM Lj/u5pm3WAaECWlLCziTZxTu+Nu0xnxcKPv2Cr8mMK9OOCZ1JAdsKOmiTGnHygbm+/vZUkb JuTaI8weA/AzpcK5cBMzW2n44oDOS+z96lm7oWmwZ+ao5Oe0KxtgTyoXNvPQHYvuFPVDlj3 sdhl2aWjOu1vFyoIOh4dA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:ZMIeB4k30RQ=;fiqhq/3tNLWw+fa8MG8kwNjzMfg UjE+n1q09VnC0rJEWEGJGSpDWwg1ClD93BdL+bdJT71exB6e+qimqNeiet/qG+k38HvOmO+4C 3lGTgKIBGu09bbxpOyRHkvEhRx8DY1NAadXjwU20yWKPCQESo1Z25hos+e+6XWsArm1eXSr3f A+LlncM4Ec4vXSIdI6mPpnNwganEzgUxekm4NjaeSWk8Q+HKbj1gV86qS3nALBZFAxASSsvV7 k14lRLc23Y9nP2Vf++TFNUHnp8XFKvli2WecuyXosVwyHs0CsIstjbnkuiOBIkODPEt0mAeC9 JdbMNex8SQYMjgyeVvEn8UhlVvlgmdOKuf3UvXxY6wkCrJRZVpv3Sle3itMfBtk7JfjzkGrtE Za1cMJRlrT8tHk4J8L1GOW7oWgavyRAjEPThdvyxGFwoJ1mlOKlfanswXS15L+5djU/D4BlNy K27GwKIwjeUG9HTP6QgZ9Oa+ScpVWF2TFjNIdrd7YTjA85q+yKl8qjXqcQnJCIvaaIYhBxiyr 48c05m3ZzcI8Z4V9zOouCVRMtWkHbN6PXDotAeXDEeqD5XzpVYjDpl8xRsfQks+O7H4mUEuJ5 OWdPYuRJoKpNylY3xww4ezB2o/vjgMkOuGR6W5je5OdH35EAqH1tsWza0C3uimjASRInS4OBz H8rv/TRKlf4CYb5lemT/fNlDVf6iv6bgxqv9GtT6j9nmzG1BP7d3YAhnhw1+wrzM0wKK9XTy4 PFKfbe7JwwItybQXIURphSy/nN3btmRkBerjZiZXtFMgNkZRkYm39xM8t4EikZkolMZPDW7jf f954HFwHleUNiCWx3ZMwm2QCYgC2CBHRLgXRUrbdKbkhQ= Currently, more than seven power supply drivers are supporting POWER_SUPPLY_PROP_POWER_NOW, but their power readings are not being reported through the hwmon subsystem. Fix this by adding support for power sensors to the power supply hwmon integration. Signed-off-by: Armin Wolf =2D-- drivers/power/supply/power_supply_hwmon.c | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/sup= ply/power_supply_hwmon.c index c97893d4c25e..baacefbdf768 100644 =2D-- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -48,6 +48,18 @@ static int power_supply_hwmon_curr_to_property(u32 attr= ) } } +static int power_supply_hwmon_power_to_property(u32 attr) +{ + switch (attr) { + case hwmon_power_input: + return POWER_SUPPLY_PROP_POWER_NOW; + case hwmon_power_average: + return POWER_SUPPLY_PROP_POWER_AVG; + default: + return -EINVAL; + } +} + static int power_supply_hwmon_temp_to_property(u32 attr, int channel) { if (channel) { @@ -90,6 +102,8 @@ power_supply_hwmon_to_property(enum hwmon_sensor_types = type, return power_supply_hwmon_in_to_property(attr); case hwmon_curr: return power_supply_hwmon_curr_to_property(attr); + case hwmon_power: + return power_supply_hwmon_power_to_property(attr); case hwmon_temp: return power_supply_hwmon_temp_to_property(attr, channel); default: @@ -229,6 +243,11 @@ power_supply_hwmon_read(struct device *dev, enum hwmo= n_sensor_types type, case hwmon_in: pspval.intval =3D DIV_ROUND_CLOSEST(pspval.intval, 1000); break; + case hwmon_power: + /* + * Power properties are already in microwatts. + */ + break; /* * Temp needs to be converted from 1/10 C to milli-C */ @@ -311,6 +330,10 @@ static const struct hwmon_channel_info * const power_= supply_hwmon_info[] =3D { HWMON_C_MAX | HWMON_C_INPUT), + HWMON_CHANNEL_INFO(power, + HWMON_P_INPUT | + HWMON_P_AVERAGE), + HWMON_CHANNEL_INFO(in, HWMON_I_AVERAGE | HWMON_I_MIN | @@ -359,6 +382,8 @@ int power_supply_add_hwmon_sysfs(struct power_supply *= psy) case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_CURRENT_MAX: case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_POWER_AVG: + case POWER_SUPPLY_PROP_POWER_NOW: case POWER_SUPPLY_PROP_TEMP: case POWER_SUPPLY_PROP_TEMP_MAX: case POWER_SUPPLY_PROP_TEMP_MIN: =2D- 2.39.2