Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp769249ybz; Fri, 1 May 2020 08:13:28 -0700 (PDT) X-Google-Smtp-Source: APiQypKutrNx8BZtTmoVOp6ghluz46Hh5Vezp7al/kaZ/J7/3Y28vWd69X2thMVNkQ9PvPgQhxgW X-Received: by 2002:a17:906:7804:: with SMTP id u4mr3704730ejm.328.1588346008051; Fri, 01 May 2020 08:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588346008; cv=none; d=google.com; s=arc-20160816; b=ZcEvJP5Ok01CjPxTxoBkHDcrGtA90WiaJmw5zH0LfXQ9lguyAsBEzTpw7O2MO6fOdq EVGYt5JzRPMNCbuZNEOft31TCY7I8xbZowES110v4dgfs11NDj2YNtI23606HeW2Q/Fp xzVsHsial9Ur54TwwJTXXxwto2+mmRo3oKeqaoQIHCsMXbje6FoZbbyiEOEcF4ai6S+1 mTbb4xMu9p17LKelT9/a6cInJCeLbxL5xILrZIIx7Dn2kYnEcvFq0B3k7Vpvdsajthbn wazYhmO5KgZLECDaOujcgV1Tcin6lzsSNvUnfUeVax+OHnFX7lNsbY550BR2Cbj76KFO wL/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:content-transfer-encoding :mime-version:subject:from:references:in-reply-to:message-id:date :dkim-signature; bh=AoWg9t+mxqJF9/KIbYY6QIWGqNM/hEkvoc6jGxHds34=; b=0QvtHB/RE9XuTPU2SAJHwejLLW/K5uZ0BF6jOXJG5G8dWylBooFKXANmCjT1kDqIi+ YhGaVx0eGWFvWkK6zoZiVe92gNY6a4Z5gain5rQi3aPsF230kyUdw7ARWUqXmllcdhqr 0gSBoQi7DCEwzTMnlmoymAeArzeYwXplrbwjhz7oFy5Z4dPD3p5j8prbtzLk1O/xk5Mx 8dqVfUjR3BaPg+sRYfV0rnKnWvKoRVWi+FvR5ToeRU1/IYf/ZbNjvHTugLb0RZr2U/2w xpR4y+dlFAaeRmk8dDmbSpQx2DUxKtFNCojSzMcnHcXo2xb94E8VB/+ttpLn0xnRbWEv Zh3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=BUm2psIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si1707254edv.500.2020.05.01.08.13.05; Fri, 01 May 2020 08:13:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=BUm2psIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729627AbgEAPLY (ORCPT + 99 others); Fri, 1 May 2020 11:11:24 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:3422 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729229AbgEAPLW (ORCPT ); Fri, 1 May 2020 11:11:22 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49DG135MzJzT9; Fri, 1 May 2020 17:11:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588345879; bh=+wIBzwrX5ahM3oS+NP3Mk3ATTvfRc5hfitHIs59H+xs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=BUm2psIrv7/tgPPi3w476tQfxw4xkF+moTcpOsSPp0367jZYtSf7b9p4w+5j7NYIe 0Uozy6M7WZ6JJruFalZHmmAygDAkNkwJ3z7aKQm48NMqjbVLOhdo8L3zZ7wmtEhB9H 2U3UZXELmHcmqYrYJIpv7j2BOj5jV/WFMraL3H047m4eCK6MGJXRE6Wvf/bPQ+Di/d lTO1ynXjqlod6buVN7KTWzBpqn9FGfi0N3ow1dym0SIV3ZOfN306ipGZs+cP65WDN6 E+CVQBKaF18ZNbXTGLs/KafztaCeE8MsVdOd730z3YRjx7aKZAJ6dQvWL9K0wzCqHm gNWGKr9ZUdSBg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Fri, 01 May 2020 17:11:19 +0200 Message-Id: In-Reply-To: References: From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH v4 3/4] power: supply: core: add output voltage measurements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: Sebastian Reichel Cc: clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for supply output voltage to be measured and configured. This might be different from the voltage on the storage element (battery). Signed-off-by: Michał Mirosław --- drivers/power/supply/power_supply_hwmon.c | 25 +++++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 3 +++ include/linux/power_supply.h | 3 +++ 3 files changed, 31 insertions(+) diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index 3863b2a73ecf..626a344fbad1 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -16,6 +16,7 @@ struct power_supply_hwmon { static const char *const ps_input_label[] = { "battery", "external source", + "load", }; static const char *const ps_temp_label[] = { @@ -51,6 +52,20 @@ static int power_supply_hwmon_in1_to_property(u32 attr) } } +static int power_supply_hwmon_in2_to_property(u32 attr) +{ + switch (attr) { + case hwmon_in_min: + return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN; + case hwmon_in_max: + return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX; + case hwmon_in_input: + return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW; + default: + return -EINVAL; + } +} + static int power_supply_hwmon_in_to_property(u32 attr, int channel) { switch (channel) { @@ -58,6 +73,8 @@ static int power_supply_hwmon_in_to_property(u32 attr, int channel) return power_supply_hwmon_in0_to_property(attr); case 1: return power_supply_hwmon_in1_to_property(attr); + case 2: + return power_supply_hwmon_in2_to_property(attr); default: return -EINVAL; } @@ -399,6 +416,11 @@ static const struct hwmon_channel_info *power_supply_hwmon_info[] = { HWMON_I_LABEL | HWMON_I_MAX | + HWMON_I_INPUT, + + HWMON_I_LABEL | + HWMON_I_MIN | + HWMON_I_MAX | HWMON_I_INPUT), NULL @@ -469,6 +491,9 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy) case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW: case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN: + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX: + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW: set_bit(prop, psyhw->props); break; default: diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 1d1fb69516a8..fb6f113b52bb 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -278,6 +278,9 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(input_voltage_now), POWER_SUPPLY_ATTR(input_voltage_limit), POWER_SUPPLY_ATTR(input_power_limit), + POWER_SUPPLY_ATTR(output_voltage_now), + POWER_SUPPLY_ATTR(output_voltage_min), + POWER_SUPPLY_ATTR(output_voltage_max), POWER_SUPPLY_ATTR(energy_full_design), POWER_SUPPLY_ATTR(energy_empty_design), POWER_SUPPLY_ATTR(energy_full), diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 5313d1284aad..f1ff8d230488 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -132,6 +132,9 @@ enum power_supply_property { POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW, POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, POWER_SUPPLY_PROP_INPUT_POWER_LIMIT, + POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW, + POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN, + POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, POWER_SUPPLY_PROP_ENERGY_FULL, -- 2.20.1