Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1387507lqg; Sun, 3 Mar 2024 07:44:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX01diWBUEsnXykVHttO0dbkxqWOR5fn8wDRAT71gTYNHPcKXknNXQhhhTzWAkY5BdqWb5UtzxV4TRb+Wcah391x9f86T3ABfrxEOATEw== X-Google-Smtp-Source: AGHT+IHzZu+v1V693ZPxuQqQU6vEj125FmRAnhC13zoiwIceKOm1sSvdzy3urKY1IQKjpAqw87yE X-Received: by 2002:a05:6e02:2164:b0:365:28e6:daa8 with SMTP id s4-20020a056e02216400b0036528e6daa8mr10400974ilv.12.1709480689981; Sun, 03 Mar 2024 07:44:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709480689; cv=pass; d=google.com; s=arc-20160816; b=r9mtDEhwRS34HSIXSfYgG8O3ERBfQ2cYq/ghMwaINpC1nwnc/rqBEJd6v0exJNTpU8 UzgbPM2V6qPMsaOSA4RwNMZxZiP5HICC9zEDbf+lq+OONRWQ8jVj1rlmAXrMR/CrVuqD frrHW9fhvu1R4/nLoNNUQ4rCBdnCmY8zCh6j02Hzkmfl9/w6hd+Ls2yU5pjdnmyZtdzX NYqEJxnvXh33KlUYZJt8+i6rkh9zSBwsnxE8rTt2b1e3S7TtEJRxvttQ1hBv0WWqCgMZ cIKgxMjFqZP9VVQixZTcPaNN/7fGFni2raydPmwmgielvQxmhfuZiwJ+ZFJ/AuRxClZO VJIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=IDXCSR7rsE+YK67QmmhztJKlieIzCBqDX0ECWnAbMZU=; fh=dENBTHx7kJ0jlNJaErTJ7Ld+rhETTNznjDk+Wc/4RaE=; b=sR8UrF8z/65W4GuVLfuTTObjpnUfCGaLCNGJ7koEtn6IA+7Ateo/S38XBPpyPMlBGT QVZgdA59EhmVk42fv2BdKwCUdoNhj3U3BZl2jEbuny9BiL7sl0nmKNqBsPJbZlkKU0n9 za3CxdIj/Nl+BgpS/YQthdYYEsUArmD5W6XGRpagaNfK37sYgjQOKj1DhLmPRuAupjDA 8U79XTZnVi2/DqOR/z25dQvVM1ABz71bE6hpse6VpBnsPTXcqep/XW4hkXuDjKYj8gpV zxC5ZByCbbg7jX35YTZ5i0Up1uwltCySD1ExCXIYiNH0I7mc/ZYXwfanunxtWzD5p/B/ EWQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b="Af/JS/9K"; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-89802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89802-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 135-20020a63028d000000b005dc4da21221si6947667pgc.419.2024.03.03.07.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 07:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b="Af/JS/9K"; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-89802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89802-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 714E8B23A8B for ; Sun, 3 Mar 2024 15:32:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3E1267E96; Sun, 3 Mar 2024 15:31:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Af/JS/9K" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 47D7467A19; Sun, 3 Mar 2024 15:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709479893; cv=none; b=RN8HViUZkMR+iv+CLbuTR1NpeyBohM1NjEkpD8Nn4gWnNcpRfdxtA1jHALCS/yc9ULvlqbXUuqViLyE4eMt4drZHmzTFdK34t1rCEXuUI0bg8U8whSJB0Ftmr0xA6BM2Z1eZL84tHOL0rG3cYzJeLM42KtXrLtWjQY8uZKrtHUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709479893; c=relaxed/simple; bh=fE1ygv1xYb2HYZUOI0x3ptRJowm9HrcXCdzDrxnyxeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IhTS+eIKAwr8F1sFPFz1WWEB5dRsY35g6hWOLB6+QZ1XSp8BOKsTy2zC5vVtRCX/mVkAMkyOIFey5gl2enJoVisOxzNHyYJyHyxpRYHUVo5EuRrpKpuijevg+HPxjCZcu7Ua6zQJWFcHufUO99HJRcdMTOh5LHSTA0F6oX34Te8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Af/JS/9K; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1709479880; bh=fE1ygv1xYb2HYZUOI0x3ptRJowm9HrcXCdzDrxnyxeM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Af/JS/9Kt4KdQ6bu0kzZ8NvVB/YI2b3GVeQ9EiWlSbJ4xdPKjZWi3OVYzImqhNrU4 atexIMqonVVXufcC+DUjT6ON0NzfZXHUNkReyHRy1zWAFBUeaiR/oNZqI5OmL3iP1Y kyscKTMdSLW4TK4zjN7YUZkD4khUu4jXZUoDj75I= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 03 Mar 2024 16:31:15 +0100 Subject: [PATCH v2 3/4] power: supply: core: fix charge_behaviour formatting Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240303-power_supply-charge_behaviour_prop-v2-3-8ebb0a7c2409@weissschuh.net> References: <20240303-power_supply-charge_behaviour_prop-v2-0-8ebb0a7c2409@weissschuh.net> In-Reply-To: <20240303-power_supply-charge_behaviour_prop-v2-0-8ebb0a7c2409@weissschuh.net> To: Sebastian Reichel , Hans de Goede , Konrad Dybcio Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1709479879; l=2886; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=fE1ygv1xYb2HYZUOI0x3ptRJowm9HrcXCdzDrxnyxeM=; b=sfdWoZTYKANqBRjwaPPhtrEBieQe4GFAgpyFXMfHn5dcLMAEOywqcu6+l/zZo5uoqEXNF+6A7 qaRltUz4qwWDk8YzAzd6maTHUomulkZmcj4SoPGHmJwjg5q3CAOc+9w X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= This property is documented to have a special format which exposes all available behaviours and the currently active one at the same time. For this special format some helpers are provided. However the default property logic in power_supply_sysfs.c is not using the helper and the default logic only prints the currently active behaviour. Adjust power_supply_sysfs.c to follow the documented format. There are currently two in-tree drivers exposing charge behaviours: thinkpad_acpi and mm8013. thinkpad_acpi is not affected by the change, as it directly uses the helpers and does not use the power_supply_sysfs.c logic. As mm8013 does not set implement desc->charge_behaviours. the new logic will preserve the simple output format in this case. Fixes: 1b0b6cc8030d ("power: supply: add charge_behaviour attributes") Signed-off-by: Thomas Weißschuh --- drivers/power/supply/power_supply_sysfs.c | 20 ++++++++++++++++++++ include/linux/power_supply.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 10fec411794b..a20aa0156b0a 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -271,6 +271,23 @@ static ssize_t power_supply_show_usb_type(struct device *dev, return count; } +static ssize_t power_supply_show_charge_behaviour(struct device *dev, + struct power_supply *psy, + union power_supply_propval *value, + char *buf) +{ + int ret; + + ret = power_supply_get_property(psy, + POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR, + value); + if (ret < 0) + return ret; + + return power_supply_charge_behaviour_show(dev, psy->desc->charge_behaviours, + value->intval, buf); +} + static ssize_t power_supply_show_property(struct device *dev, struct device_attribute *attr, char *buf) { @@ -303,6 +320,9 @@ static ssize_t power_supply_show_property(struct device *dev, ret = power_supply_show_usb_type(dev, psy->desc, &value, buf); break; + case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR: + ret = power_supply_show_charge_behaviour(dev, psy, &value, buf); + break; case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER: ret = sysfs_emit(buf, "%s\n", value.strval); break; diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index c0992a77feea..a50ee69503bf 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -242,6 +242,7 @@ struct power_supply_config { struct power_supply_desc { const char *name; enum power_supply_type type; + u8 charge_behaviours; const enum power_supply_usb_type *usb_types; size_t num_usb_types; const enum power_supply_property *properties; -- 2.44.0