Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp695652lqt; Thu, 6 Jun 2024 16:10:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzBk5VQk0b7723sE35oP7NQFhoZl7D0uMyP9SlPGlRt96ddwvLAUvXw5/+t7hvu5JHaevOjmlorN2UYQs5ioFp7hjDGeNiJxUDIe9zwA== X-Google-Smtp-Source: AGHT+IFfpe+dXdm04LXYGNwIBQMdlhGvISgroFeh24QtKlwK3ncL52xjj+lrBjyxldZvqV5J2T8/ X-Received: by 2002:a05:6a20:a11f:b0:1af:f92c:de8e with SMTP id adf61e73a8af0-1b2f9ddfa22mr1069326637.52.1717715432537; Thu, 06 Jun 2024 16:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717715432; cv=pass; d=google.com; s=arc-20160816; b=coKrVdmKSwwhla05DxTMlO/39XZS/k/xRMWLE8TYtEWcHP9pAP6clAK1AltXAlo98f Dl6n7eI9W8x2MWxc91BvUxIE9OM3AhmK5qOwnJ7WLmEVtcBSphBSU8M236mhE7CWGolZ gKoFy/JvPjydzgS2h4uhLWHF7NQ2XuQHKNBqeo4ervCaQ1WdZ4MMLCKw0jiFDMJkA132 PqCMJxGr2eZhcajY+Prw9cfBsZbhSJGpWB1qZepiWw/T3/q70r73t4Vs92HN2R3+du1g KN9+XKc1yzK67Ur80yH+WXLG4Kfe0aExpB5wVLFAgXGHWpMGSx45LEjcUqLwytpxaviI fX9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=r3UGZP34pSdCmuoOJgMLTbyJg868znqcxvx43HN2viE=; fh=EC46q6FJ4ouqfZVbzETVxk888NKBsLFqjDyyUTRyPPQ=; b=XW3TKfvTISP+EVueAGFys7dWrd7fpU6O7d2j+qS2xWFctNX7IUSOOmoxOhtEdXDKUg HFif5h/9PEusbOctWfsKiEZtI03HuemY6t/xQ9i8eHec7BcCAdNgbhMLWxfZUHSgO7eh XgfVyBJjrXppF+P387wLzMKbtze3ITyFBzLToSen+X8+IHNTw1SWGN1OODiSDRzVADhk otWxKyy4/0tla4pGsMa6JN4EKQAdizpvSBsKziMGlTlrJHg/MgM4c1TILKQgNf/gsWud vXcyIQyhw2B97ZqbQGgnbUouj7v5Rds16yZ8XcEKXGaiK/xIta72Rya04QlzHOrLB88h x0SQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=q6gQnW5b; 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-205137-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205137-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de262c1112si35607a12.304.2024.06.06.16.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 16:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205137-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=q6gQnW5b; 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-205137-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205137-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 21E5C289B59 for ; Thu, 6 Jun 2024 23:10:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACE9713E034; Thu, 6 Jun 2024 23:10:24 +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="q6gQnW5b" Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 351A2535C8; Thu, 6 Jun 2024 23:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717715423; cv=none; b=RsIivA2gUSgbHWSHVw4IwafTsquJMFEBha4nhBokWB6FyZdoHFNOlJOebH8xAzIB7adLqWPGsovW7Vo/zCQmUX6YhQJEx91B+guogYrZct0cAZBNVBkvFEdJ5igdx/LJ+qa3HJcDmtMIv6NTiJ8l4ca+8RB6IN7LhCsO62+ACww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717715423; c=relaxed/simple; bh=uZpkgoX0ZHSHKRvOkliopYBpBqKI54AIsFmuJuGonpM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TgDST6D1mQq9GJW7ZE5uaJKiUmKhvW0CjqfwYy/oQQjSninrC9+iVV68zx/RP2ShTNIK7EhRxcopr3VC6igpqClXa2Bzy92dValULIkZ2/sd4R6YaCWLIivJwy0oCVPHDLr4JzLXQ77ycgnAh5bDpePSH3EwCIUGy52JCyKeCAY= 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=q6gQnW5b; arc=none smtp.client-ip=212.227.17.22 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=1717715406; x=1718320206; i=w_armin@gmx.de; bh=r3UGZP34pSdCmuoOJgMLTbyJg868znqcxvx43HN2viE=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=q6gQnW5bOtCEi1nVGIYxOcAaBidptP7+BrLsnZg9avgowE50UZV9iwyKRFNjrDuC x5Y0TiClPTp+sddKKPgODlZ790UGsU+aVV2TGG4o5Zww1fH6lCbix2AxEnWeIZMCt JY4nHotNpQUA23uJK5tU2kKIw2eg5MIeFJuVyreff19Sva3k4fM0LOPDMBukW8nE7 BO1P4Dt7cqa5HQPAR31+kVIM00epm8dvvF7OKoW060xftdQjcU5Gp2H9f0r33tgQV 7lR249t/jW8yoaijCJWSNSEWwr1eYcvyjI0dgNABx6mTsxh+B+tVmgUmcXjiTL0UG 4yt91Htsroe3Ss6ScQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.2.35] ([91.137.126.34]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M5wPb-1sLi2I3U79-004ZsM; Fri, 07 Jun 2024 01:10:06 +0200 Message-ID: <41964782-222c-45fa-846e-3656eff5b3a9@gmx.de> Date: Fri, 7 Jun 2024 01:10:02 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 0/6] power: supply: extension API To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= , Sebastian Reichel , Jeremy Soller , System76 Product Development , Hans de Goede , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org References: <20240606-power-supply-extensions-v1-0-b45669290bdc@weissschuh.net> Content-Language: en-US From: Armin Wolf In-Reply-To: <20240606-power-supply-extensions-v1-0-b45669290bdc@weissschuh.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:XnmGkXgamiaRxbeD1IgTCuqVk0j44qy6FU4T+qzoOk8JwvhHzkv YWoTQXvyvgvBhvD0ChNHo3jLStW1ghBT4BArjhDhFTXAiknsDMFIabIuzXgqb/UH9lCTOTw cMXs0pWkNAMPFWgEYcuTVfw5y05Xw7LKcuwBXKIjhWCP2RNmXKbELwxw5yAw9phpqJDugsL YlWXebXi0sAXHDnHVWzZg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:8wTKlJo3rsU=;SqIwOCNJCMxsa8ebkdNaNyBqs8Q zoSwcJsNH5kreIpL5om/BP5kCqirGqrg6lkcwNqMgO0i118AI8cTU30HRAcrTIRxoE/TpV4I5 gWniWCYXI4lpIu+KdUS/WRF9wc3HrMDe4hWRHTeNCWRviGX9mr7MpuLi0ZcxbiRkmHxDmuA8F n/T5Pw0TeaIclOV9P9dIzcbud4dsZMQqwlkAFnlQgxYOSw/9V1LCIDbfKumyVBxvQ+TVTdWyS daFu0MwdnZ6oTCrA0H/Pz7u2ggPTmavD535yKYhyQ3O+kGaKbR6ZlqWsG+xUFKuBupQiBgFx8 pyGfD1CZPiSNunQORGpVyr7K/5LBIprPNLJXUTiP2gsWf0IoaHOelsco2G6ISsCOBrlco7+45 WNrOA2rij2E8PeemO4Z4PdVKMsxj5cPvu/C8co9rQtlvGAa2JW/0U9SKIi67d/AVoBDxz+nn0 VemW/lhxkY65QC0tm1xe62c2tABLdJBysEAmmB/esq9nlUkReM+tuNAp/8iD60AXskPqk4bly +eYtgFWdNBmm9LtPfNFsf6Ch3t/OsK5IozgHtKKQ+2WgP2bU8LwJVEYgCB/+IdSmW2o32ymvx x8N7BLea37/9c0zaBvEL0t2f5yEFV6QgDB81MTfzqQz6OW55YGCGgJi/WwytwP7kJYiDYW9X4 EUve18pVY1YTgNJHMD4T9tqs0HwB8xQthn7zfF/WBIEQGyKEQON9nKGagMy/fV/9bblcUFmXB ItjPIh4UBwGmfE/c3BCI333wHnAvUpc7DGkTTsu1RgOn+PwMZBPItZ7m6HO9oH5mWqM/pqzkT Mfyvwh4NgRP0JoRaUnaSTShUJm+8araJLJ/lN8m87WYuY= Am 06.06.24 um 16:50 schrieb Thomas Wei=C3=9Fschuh: > Introduce a mechanism for drivers to extend the properties implemented > by a power supply. > > Motivation > ---------- > > Various drivers, mostly in platform/x86 extend the ACPI battery driver > with additional sysfs attributes to implement more UAPIs than are > exposed through ACPI by using various side-channels, like WMI, > nonstandard ACPI or EC communication. > > While the created sysfs attributes look similar to the attributes > provided by the powersupply core, there are various deficiencies: > > * They don't show up in uevent payload. > * They can't be queried with the standard in-kernel APIs. > * They don't work with triggers. > * The extending driver has to reimplement all of the parsing, > formatting and sysfs display logic. > * Writing a extension driver is completely different from writing a > normal power supply driver. > * Properties can not be properly overriden. > > The proposed extension API avoids all of these issues. > An extension is just a "struct power_supply_ext" with the same kind of > callbacks as in a normal "struct power_supply_desc". > > The API is meant to be used via battery_hook_register(), the same way as > the current extensions. > > For example my upcoming cros_ec charge control driver[0] saves 80 lines > of code with this patchset. > > Contents > -------- > > * Patch 1 and 2 are generic preparation patches, that probably make > sense without this series. > * Patch 3 implements the extension API itself. > * Patch 4 implements a PoC locking scheme for the extension API. > * Patch 5 adds extension support to test_power.c > * Patch 6 converts the in-tree platform/x86/system76 driver to the > extension API. > > Open issues > ----------- > > * Newly registered properties will not show up in hwmon. > To do that properly would require some changes in the hwmon core. > As far as I know, no current driver would extend the hwmon properties= anyways. > * As this is only useful with the hooks of CONFIG_ACPI_BATTERY, should > it also be gated behind this or another config? > * Only one extension can be used at a time. > So far this should be enough, having more would complicate the > implementation. > * Is an rw_semaphore acceptable? > > [0] https://lore.kernel.org/lkml/20240528-cros_ec-charge-control-v2-0-81= fb27e1cff4@weissschuh.net/ Nice, i love this proposal! I agree that the hwmon update functionality will need some changes in the = hwmon core to work, but there would be at least one driver benefiting from this (dell-wmi-ddv)= . Maybe we can add support for this at a later point in time. The possibility of registering multiple power supply extensions on a singl= e power supply will be necessary to support battery charge control on Dell notebooks in the fu= ture. This is because there will be two drivers on Dell notebooks which register battery extensi= ons: dell-wmi-ddv and dell-laptop (when support for battery charge control is supported someday)= . How difficult would it be to support such scenarios? If its very difficult= , then maybe we can implement this later when the need arises. Thanks, Armin Wolf > Signed-off-by: Thomas Wei=C3=9Fschuh > --- > Thomas Wei=C3=9Fschuh (6): > power: supply: sysfs: use power_supply_property_is_writeable() > power: supply: core: avoid iterating properties directly > power: supply: core: implement extension API > power: supply: core: add locking around extension access > power: supply: test-power: implement a power supply extension > platform/x86: system76: Use power_supply extension API > > drivers/platform/x86/system76_acpi.c | 83 +++++++++--------- > drivers/power/supply/power_supply.h | 9 ++ > drivers/power/supply/power_supply_core.c | 136 ++++++++++++++++++++++= ++++++-- > drivers/power/supply/power_supply_hwmon.c | 48 +++++------ > drivers/power/supply/power_supply_sysfs.c | 39 ++++++--- > drivers/power/supply/test_power.c | 102 ++++++++++++++++++++++ > include/linux/power_supply.h | 25 ++++++ > 7 files changed, 357 insertions(+), 85 deletions(-) > --- > base-commit: 2df0193e62cf887f373995fb8a91068562784adc > change-id: 20240602-power-supply-extensions-07d949f509d9 > > Best regards,