From patchwork Fri Oct 14 17:24:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A86E1C433FE for ; Fri, 14 Oct 2022 17:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiJNRYp (ORCPT ); Fri, 14 Oct 2022 13:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbiJNRYo (ORCPT ); Fri, 14 Oct 2022 13:24:44 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E4B8F581 for ; Fri, 14 Oct 2022 10:24:42 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id E17A584B2B; Fri, 14 Oct 2022 19:24:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768281; bh=Z/JdrWVE+bUsHIAmKuHFgeNsx+Og1FVroPqDTEuFGhw=; h=From:To:Cc:Subject:Date:From; b=l5Jr81REN6lIEe2dmy3EwM70R+UsPjQvayBzO2Ul/1S0Iwue4SL294rY65+xiYSvd 6t3E2rAiQL2DLccKLo+xKvc64kSPpFOYa4sJFvNNYxhdJDlu0I9B40Fl2PgB0IkjAt 8jeqSAgWyIyLdRWMT1dl8N9uTRwnBe6TI/dDTjCQp6aRbgVi67AbOhsPi+GK+/BZM1 DhHGsJvlskS33M3m4Q6uI5xucDLXsZOMgIjznK8C/jqFk2fNCrVFTs1sVw40cDYgCi ecrUGbBjJLrNhuhGqbgyk1HaGC/+0bROVrPK7LrZioE/bFy5uoM2DtDJeP3Gl0EsW0 BvRETDFXhmtnw== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Hans de Goede , Andy Shevchenko , =?utf-8?b?TWljaGHFgiBN?= =?utf-8?b?aXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 1/7] power: supply: bq25890: Document POWER_SUPPLY_PROP_CURRENT_NOW Date: Fri, 14 Oct 2022 19:24:21 +0200 Message-Id: <20221014172427.128512-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Document that POWER_SUPPLY_PROP_CURRENT_NOW really does refer to ADC-sampled immediate battery charge current I_BAT , since the meaning is not clear with all the currents which might be measured by charger chips. Reviewed-by: Hans de Goede Signed-off-by: Marek Vasut --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Add RB from Hans --- drivers/power/supply/bq25890_charger.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 6020b58c641d2..1298d5720aa4b 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -588,7 +588,14 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = 2304000 + ret * 20000; break; - case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_NOW: /* I_BAT now */ + /* + * This is ADC-sampled immediate charge current supplied + * from charger to battery. The property name is confusing, + * for clarification refer to: + * Documentation/ABI/testing/sysfs-class-power + * /sys/class/power_supply//current_now + */ ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ if (ret < 0) return ret; From patchwork Fri Oct 14 17:24:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB2FFC4321E for ; Fri, 14 Oct 2022 17:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbiJNRYr (ORCPT ); Fri, 14 Oct 2022 13:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbiJNRYo (ORCPT ); Fri, 14 Oct 2022 13:24:44 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F5E712610 for ; Fri, 14 Oct 2022 10:24:42 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 3458384BEF; Fri, 14 Oct 2022 19:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768281; bh=pSHsiAWQjte0t9KWE2lb3uDk8o0JetWAI43bTz2KT2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmxUQN/exoPPT5C5nv+8XmNwQMkAaz6mamt71EJzX295LnQqZVPPX0t7eevYGR9Hn dWtxy9XizhPKETS1jM5LBNigCr7VR9wWDlP+UpiazCmPDlXjuYlp7N9zr6GshAQU8F kNiQE5Br8IEw4WZl2z73ghz1vJypRimBGxX6QDZgSSB7HrWgFpokLaMU3uYTDdXBFP w4QHiDy33pM1AWmpf4aUEj9adX5H45+szRno5ePwIX0b3f2yF9qGBQB8icaaZ4WzsA IkeR3g1fLgwDjYFvLoRLV23XVtmK1m42rpdcfYHs13h3ZgXbusZdVAv8ovrzsasOsL hYz03tYXwXV2g== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Hans de Goede , Andy Shevchenko , =?utf-8?b?TWljaGHFgiBN?= =?utf-8?b?aXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 2/7] power: supply: bq25890: Clean up POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT Date: Fri, 14 Oct 2022 19:24:22 +0200 Message-Id: <20221014172427.128512-2-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Clean up misuse of POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX and document what exactly each value means. The POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT content is newly read back from hardware, while POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX is reported as the maximum value set in DT. Reviewed-by: Hans de Goede Signed-off-by: Marek Vasut --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Add RB from Hans --- drivers/power/supply/bq25890_charger.c | 57 ++++++++++++++++++-------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 1298d5720aa4b..5924b036b1588 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -529,22 +529,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; break; - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: - val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); - - /* When temperature is too low, charge current is decreased */ - if (bq->state.ntc_fault == NTC_FAULT_COOL) { - ret = bq25890_field_read(bq, F_JEITA_ISET); - if (ret < 0) - return ret; - - if (ret) - val->intval /= 5; - else - val->intval /= 2; - } - break; - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: if (!state.online) { val->intval = 0; @@ -604,6 +588,46 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = ret * -50000; break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: /* I_BAT user limit */ + /* + * This is user-configured constant charge current supplied + * from charger to battery in first phase of charging, when + * battery voltage is below constant charge voltage. + * + * This value reflects the current hardware setting. + * + * The POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX is the + * maximum value of this property. + */ + ret = bq25890_field_read(bq, F_ICHG); + if (ret < 0) + return ret; + val->intval = bq25890_find_val(ret, TBL_ICHG); + + /* When temperature is too low, charge current is decreased */ + if (bq->state.ntc_fault == NTC_FAULT_COOL) { + ret = bq25890_field_read(bq, F_JEITA_ISET); + if (ret < 0) + return ret; + + if (ret) + val->intval /= 5; + else + val->intval /= 2; + } + break; + + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: /* I_BAT max */ + /* + * This is maximum allowed constant charge current supplied + * from charger to battery in first phase of charging, when + * battery voltage is below constant charge voltage. + * + * This value is constant for each battery and set from DT. + */ + val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); + break; + case POWER_SUPPLY_PROP_TEMP: ret = bq25890_field_read(bq, F_TSPCT); if (ret < 0) @@ -887,6 +911,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_CHARGE_TYPE, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, From patchwork Fri Oct 14 17:24:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB247C43219 for ; Fri, 14 Oct 2022 17:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiJNRYq (ORCPT ); Fri, 14 Oct 2022 13:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbiJNRYo (ORCPT ); Fri, 14 Oct 2022 13:24:44 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 385BE12743 for ; Fri, 14 Oct 2022 10:24:43 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 7DF0B84C4C; Fri, 14 Oct 2022 19:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768281; bh=kc/nOTBnvKgjkwFhU37dDIuaOU5uxNTq+2XnGJCtEfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXz2KRgylzUGiwgCENAox5Mt6EGKUilHedlNCApEwYbunGQ79MipAcwS6pah4lDqb BdpsNIPGXqg0hTGn36ZsVuZlifycsMvaerIYSWS8T36X94ftyqx7EeBjodOLEp0aRk ecVB2NU5B1wikjDvojveFlKhbo4YtxC6vGEnSQFpvvZG0GubcL+FDrvt11DAMmX6RD IAD9ErviurmUpqhFtOn0j0MKWlaELFgDivdPKjdNBCEllqlfhK6zEmvvKiWxQeeMEe zWmFAf5cC/DMZEXLoCP4ZcJ/rwa2hmz/7HakP0x1CQmk28hD3oWims/t1OzL1YrFKb qr7Sy/nWqzXpQ== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Hans de Goede , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 3/7] power: supply: bq25890: Clean up POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE Date: Fri, 14 Oct 2022 19:24:23 +0200 Message-Id: <20221014172427.128512-3-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Clean up misuse of POWER_SUPPLY_PROP_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX and POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE and document what exactly each value means. The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE content is newly read back from hardware, while POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is reported as the maximum value set in DT. The POWER_SUPPLY_PROP_VOLTAGE is newly used to report immediate value of battery voltage V_BAT, which is what this property was intended to report and which has been thus far misused to report the charger chip output voltage V_SYS. The V_SYS is no longer reported as there is currently no suitable property to report V_SYS. V_SYS reporting will be reinstated in subsequent patch. Signed-off-by: Marek Vasut Reviewed-by: Hans de Goede --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Drop the state online check from new POWER_SUPPLY_PROP_VOLTAGE_NOW since the VBAT can be measured even when discharging --- drivers/power/supply/bq25890_charger.c | 72 ++++++++++++++++---------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 5924b036b1588..050eef2571e8e 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -529,24 +529,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; break; - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: - if (!state.online) { - val->intval = 0; - break; - } - - ret = bq25890_field_read(bq, F_BATV); /* read measured value */ - if (ret < 0) - return ret; - - /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */ - val->intval = 2304000 + ret * 20000; - break; - - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: - val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); - break; - case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM); break; @@ -563,15 +545,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = bq25890_find_val(ret, TBL_IINLIM); break; - case POWER_SUPPLY_PROP_VOLTAGE_NOW: - ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ - if (ret < 0) - return ret; - - /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */ - val->intval = 2304000 + ret * 20000; - break; - case POWER_SUPPLY_PROP_CURRENT_NOW: /* I_BAT now */ /* * This is ADC-sampled immediate charge current supplied @@ -628,6 +601,51 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: /* V_BAT now */ + /* + * This is ADC-sampled immediate charge voltage supplied + * from charger to battery. The property name is confusing, + * for clarification refer to: + * Documentation/ABI/testing/sysfs-class-power + * /sys/class/power_supply//voltage_now + */ + ret = bq25890_field_read(bq, F_BATV); /* read measured value */ + if (ret < 0) + return ret; + + /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */ + val->intval = 2304000 + ret * 20000; + break; + + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: /* V_BAT user limit */ + /* + * This is user-configured constant charge voltage supplied + * from charger to battery in second phase of charging, when + * battery voltage reached constant charge voltage. + * + * This value reflects the current hardware setting. + * + * The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is the + * maximum value of this property. + */ + ret = bq25890_field_read(bq, F_VREG); + if (ret < 0) + return ret; + + val->intval = bq25890_find_val(ret, TBL_VREG); + break; + + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: /* V_BAT max */ + /* + * This is maximum allowed constant charge voltage supplied + * from charger to battery in second phase of charging, when + * battery voltage reached constant charge voltage. + * + * This value is constant for each battery and set from DT. + */ + val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); + break; + case POWER_SUPPLY_PROP_TEMP: ret = bq25890_field_read(bq, F_TSPCT); if (ret < 0) From patchwork Fri Oct 14 17:24:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E7D5C4332F for ; Fri, 14 Oct 2022 17:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbiJNRYq (ORCPT ); Fri, 14 Oct 2022 13:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiJNRYo (ORCPT ); Fri, 14 Oct 2022 13:24:44 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6271D12772 for ; Fri, 14 Oct 2022 10:24:43 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C2C3B84CEC; Fri, 14 Oct 2022 19:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768282; bh=PhXjV6jN5ijdU5PGjs2wM6ZBulRp6OrVemxvxjFD3gw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AoLY5ntFphks9Wl4EV8wGSVpiwI2JyYhUBp+r1L6O3fIEwbXXMl5uUZx14vgvKkIG Wly8weTmYBfGLbS8R/EkPs42bAoFfG7EEOH0A9XRIW4+PT/+Gy6zPzQZcB27By2nCz d/tNH6fIUjc5w/VvC30oUdYqSYvK7ID6CFMSc0VVssx9OHbbTgIlfKF/EiSAXf/OC8 YyLYZT5S6xrdfJlz0U15m09c0tWIzniwWLd/W7ZvKAtrPgd4doPtYsGPD86g4J0pco s8dyEuD4r4TvJBxKrUofDqsIYKTPBw2wAuTB6W/+pNv6cyhOXzQNDZAurgkeUskzST bn69D14las9ww== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Hans de Goede , Andy Shevchenko , =?utf-8?b?TWljaGHFgiBN?= =?utf-8?b?aXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 4/7] power: supply: bq25890: Add support for setting user charge current and voltage limit Date: Fri, 14 Oct 2022 19:24:24 +0200 Message-Id: <20221014172427.128512-4-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Let user set battery charge current and voltage limit via sysfs. This is useful in case the user space needs to reduce charge current to keep the system within thermal limits. The maximum charge current and voltage are still limited to "ti,charge-current" and "ti,battery-regulation-voltage" values to avoid damaging the hardware in case too high values are set by user space. Reviewed-by: Hans de Goede Signed-off-by: Marek Vasut --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Add RB from Hans --- drivers/power/supply/bq25890_charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 050eef2571e8e..95803157ac4af 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -667,9 +667,18 @@ static int bq25890_power_supply_set_property(struct power_supply *psy, const union power_supply_propval *val) { struct bq25890_device *bq = power_supply_get_drvdata(psy); + int maxval; u8 lval; switch (psp) { + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: + maxval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); + lval = bq25890_find_idx(min(val->intval, maxval), TBL_ICHG); + return bq25890_field_write(bq, F_ICHG, lval); + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + maxval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); + lval = bq25890_find_idx(min(val->intval, maxval), TBL_VREG); + return bq25890_field_write(bq, F_VREG, lval); case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: lval = bq25890_find_idx(val->intval, TBL_IINLIM); return bq25890_field_write(bq, F_IINLIM, lval); @@ -682,6 +691,8 @@ static int bq25890_power_supply_property_is_writeable(struct power_supply *psy, enum power_supply_property psp) { switch (psp) { + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return true; default: From patchwork Fri Oct 14 17:24:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1109C433FE for ; Fri, 14 Oct 2022 17:24:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbiJNRYt (ORCPT ); Fri, 14 Oct 2022 13:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbiJNRYr (ORCPT ); Fri, 14 Oct 2022 13:24:47 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30DAB15A29 for ; Fri, 14 Oct 2022 10:24:43 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 1BE3484D60; Fri, 14 Oct 2022 19:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768282; bh=TciFiHLuOGZpwS92HXKexR058loqiznd2zZrc8W2vyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nUvK4rYg+HPri3V4X5ptgEVJVTA47xqvm4F7a4mqRXADf6yX6JQIyJ5IwbB7lZ/bx /ersFbIP6h0lJeWygpGTDooGJxpUQus/xC/I/1bqoRxvuQIkQVqN96GEOOGwGsb/qb WOjejfW2R66y8N+4zx1TlWTtFJfUcb1jQd9XZwi73b+w30Jw9MbsZW2mEfQFiXNSlF +tvOjd7sxnUnbAwzTGSr8Oyp5nPzA2A7ptbrkJM+Ed7GXh86Iw4mw+Wubfupf9sFFS NjzJftKlVUNUSB7pVcogDPGK2EkfNYiTe+7SNHbH+0K3CWzBtX8ASLk9akgSR2v4+t q3sXUrDam7m8w== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Hans de Goede , Andy Shevchenko , =?utf-8?b?TWljaGHFgiBN?= =?utf-8?b?aXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 5/7] power: supply: bq25890: Factor out regulator registration code Date: Fri, 14 Oct 2022 19:24:25 +0200 Message-Id: <20221014172427.128512-5-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Pull the regulator registration code into separate function, so it can be extended to register more regulators later. Currently this is only moving ifdeffery into one place and other preparatory changes. The dev_err_probe() output string is changed to explicitly list vbus regulator failure, so that once more regulators are registered, it would be clear which one failed. Reviewed-by: Hans de Goede Signed-off-by: Marek Vasut --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: - Add the missing semicolon past return 0 in bq25890_register_regulator() in negative REGULATOR macro check branch - Add RB from Hans --- drivers/power/supply/bq25890_charger.c | 51 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 95803157ac4af..dad98b782a2f8 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1110,6 +1110,36 @@ static const struct regulator_desc bq25890_vbus_desc = { .fixed_uV = 5000000, .n_voltages = 1, }; + +static int bq25890_register_regulator(struct bq25890_device *bq) +{ + struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev); + struct regulator_config cfg = { + .dev = bq->dev, + .driver_data = bq, + }; + struct regulator_dev *reg; + + if (!IS_ERR_OR_NULL(bq->usb_phy)) + return 0; + + if (pdata) + cfg.init_data = pdata->regulator_init_data; + + reg = devm_regulator_register(bq->dev, &bq25890_vbus_desc, &cfg); + if (IS_ERR(reg)) { + return dev_err_probe(bq->dev, PTR_ERR(reg), + "registering vbus regulator"); + } + + return 0; +} +#else +static inline int +bq25890_register_regulator(struct bq25890_device *bq) +{ + return 0; +} #endif static int bq25890_get_chip_version(struct bq25890_device *bq) @@ -1305,27 +1335,16 @@ static int bq25890_probe(struct i2c_client *client, /* OTG reporting */ bq->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); + + ret = bq25890_register_regulator(bq); + if (ret) + return ret; + if (!IS_ERR_OR_NULL(bq->usb_phy)) { INIT_WORK(&bq->usb_work, bq25890_usb_work); bq->usb_nb.notifier_call = bq25890_usb_notifier; usb_register_notifier(bq->usb_phy, &bq->usb_nb); } -#ifdef CONFIG_REGULATOR - else { - struct bq25890_platform_data *pdata = dev_get_platdata(dev); - struct regulator_config cfg = { }; - struct regulator_dev *reg; - - cfg.dev = dev; - cfg.driver_data = bq; - if (pdata) - cfg.init_data = pdata->regulator_init_data; - - reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg); - if (IS_ERR(reg)) - return dev_err_probe(dev, PTR_ERR(reg), "registering regulator"); - } -#endif ret = bq25890_power_supply_init(bq); if (ret < 0) { From patchwork Fri Oct 14 17:24:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 539B6C4332F for ; Fri, 14 Oct 2022 17:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbiJNRYt (ORCPT ); Fri, 14 Oct 2022 13:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbiJNRYr (ORCPT ); Fri, 14 Oct 2022 13:24:47 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF3D02034C for ; Fri, 14 Oct 2022 10:24:45 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 66C2484E06; Fri, 14 Oct 2022 19:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768282; bh=K2k5df5lZclEJ1dGj4cIudVKupk1fZ4v4yq/yYhJEsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bCVdXEFO5imgHhfEoc4Vy3yAZKCkPQx0gQnZ6glftwZuJJ+j37fS4SZFuKmmXPAVN UNNGGWbVFQbk/ZfdbJnfagBX1QIBhZk3L2ifiFDgCgwFhLwFPRZo7FH5EapvistFp/ q2T7/e6QeVY0hrw7vLI1SkebdDEi7w9tiERWZK9h9M9HIpNfvnw7j3s8JQwm1IQBTI WAGRDMi+VKL1DS8JXarG5OYyU8IGlwfP8QLlPnctRHYPs7ktbZz0mQhvOi3ESF6IXV n3mxmpYzXCGlEIQ1NcOC5qKX/BVLYV1KPGpczj385ArT3z821Fcusi/Nb2Rz9JcdpS t7tDiNjJN+ovA== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Hans de Goede , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 6/7] power: supply: bq25890: Add get_voltage support to Vbus regulator Date: Fri, 14 Oct 2022 19:24:26 +0200 Message-Id: <20221014172427.128512-6-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The chip is capable of reporting Vbus voltage, add .get_voltage implementation to Vbus regulator to report current Vbus voltage. This requires for the Vbus regulator to be registered always instead of the current state where the regulator is registered only in case USB PHY is not found. Do not provide Vbus regulator enable/disable ops in case USB PHY is present, as they would race with USB PHY notifier which is also used to toggle OTG boost mode. Signed-off-by: Marek Vasut Reviewed-by: Hans de Goede --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Simplify the Vbus regulator registration, quoting Hans: " AFAIK if the Vboost regulator is not referenced in dt because it is controller through the usb-phy framework then valid_ops_mask will be empty, so the 2 sets of ops + 2 descs are not necessary I believe. So I believe this can be simplified to just adding bq25890_vbus_get_voltage to the ops, dropping .fixed_uV and .n_voltages from the desc, and just completely dropping the IS_ERR_OR_NULL(bq->usb_phy) check. " --- drivers/power/supply/bq25890_charger.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index dad98b782a2f8..ad5811304f88a 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1095,10 +1095,18 @@ static int bq25890_vbus_is_enabled(struct regulator_dev *rdev) return bq25890_field_read(bq, F_OTG_CFG); } +static int bq25890_vbus_get_voltage(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_get_vbus_voltage(bq); +} + static const struct regulator_ops bq25890_vbus_ops = { .enable = bq25890_vbus_enable, .disable = bq25890_vbus_disable, .is_enabled = bq25890_vbus_is_enabled, + .get_voltage = bq25890_vbus_get_voltage, }; static const struct regulator_desc bq25890_vbus_desc = { @@ -1107,8 +1115,6 @@ static const struct regulator_desc bq25890_vbus_desc = { .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, .ops = &bq25890_vbus_ops, - .fixed_uV = 5000000, - .n_voltages = 1, }; static int bq25890_register_regulator(struct bq25890_device *bq) @@ -1120,9 +1126,6 @@ static int bq25890_register_regulator(struct bq25890_device *bq) }; struct regulator_dev *reg; - if (!IS_ERR_OR_NULL(bq->usb_phy)) - return 0; - if (pdata) cfg.init_data = pdata->regulator_init_data; From patchwork Fri Oct 14 17:24:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13007224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E797C43219 for ; Fri, 14 Oct 2022 17:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbiJNRYu (ORCPT ); Fri, 14 Oct 2022 13:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230337AbiJNRYr (ORCPT ); Fri, 14 Oct 2022 13:24:47 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF8AF20356 for ; Fri, 14 Oct 2022 10:24:45 -0700 (PDT) Received: from tr.lan (ip-86-49-12-201.bb.vodafone.cz [86.49.12.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id B407384EA8; Fri, 14 Oct 2022 19:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1665768282; bh=MwkRKajwC9OjsHcqszKSG7RdYaNHhDBu9jjx3tOZ8vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cnZfB++qNyCKJ5Lb/SR8NLUHe43pnnfFiAPODTtlcXNpbxpG3U9K58de89EM/HFj9 oqSUOxAGpPbckgemiB4yB6uw0CDcwL1aCNjwv9cXcom5Hi5uTwhAGn5zYbrC/O4LiR fhijz0sDybi+8YCSuGrz4HHOiW+7p8Q/H1ldiaGYGQxhrXADZp2vCPbZrbGwelhgRY 84RksGIZHxsnI6WOgUVF1J6gZGJY31O9QweyhwCKxXoTTMk3HnhYygbCYEjbSjD+BW eErR1auysQvQqKjOfWKeiH1e0y4gks17jTja2prvZ+LgwhkhRHtu2XjbR9zPjSyvhu 5wcqB91+nVwBw== From: Marek Vasut To: linux-pm@vger.kernel.org Cc: Marek Vasut , Hans de Goede , Andy Shevchenko , =?utf-8?b?TWljaGHFgiBN?= =?utf-8?b?aXJvc8WCYXc=?= , Sebastian Reichel Subject: [PATCH v2 7/7] power: supply: bq25890: Add Vsys regulator Date: Fri, 14 Oct 2022 19:24:27 +0200 Message-Id: <20221014172427.128512-7-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014172427.128512-1-marex@denx.de> References: <20221014172427.128512-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The chip is capable of reporting Vsys voltage supplied to the system. Add regulator which represents the Vsys supply. This can be used e.g. as a supply for system PMIC input. Reviewed-by: Hans de Goede Signed-off-by: Marek Vasut --- Cc: Andy Shevchenko Cc: Hans de Goede Cc: Michał Mirosław Cc: Sebastian Reichel To: linux-pm@vger.kernel.org --- V2: Add RB from Hans --- drivers/power/supply/bq25890_charger.c | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index ad5811304f88a..f0362dcb935e9 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1102,6 +1102,20 @@ static int bq25890_vbus_get_voltage(struct regulator_dev *rdev) return bq25890_get_vbus_voltage(bq); } +static int bq25890_vsys_get_voltage(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + int ret; + + /* Should be some output voltage ? */ + ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ + if (ret < 0) + return ret; + + /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */ + return 2304000 + ret * 20000; +} + static const struct regulator_ops bq25890_vbus_ops = { .enable = bq25890_vbus_enable, .disable = bq25890_vbus_disable, @@ -1117,6 +1131,18 @@ static const struct regulator_desc bq25890_vbus_desc = { .ops = &bq25890_vbus_ops, }; +static const struct regulator_ops bq25890_vsys_ops = { + .get_voltage = bq25890_vsys_get_voltage, +}; + +static const struct regulator_desc bq25890_vsys_desc = { + .name = "vsys", + .of_match = "vsys", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &bq25890_vsys_ops, +}; + static int bq25890_register_regulator(struct bq25890_device *bq) { struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev); @@ -1135,6 +1161,12 @@ static int bq25890_register_regulator(struct bq25890_device *bq) "registering vbus regulator"); } + reg = devm_regulator_register(bq->dev, &bq25890_vsys_desc, &cfg); + if (IS_ERR(reg)) { + return dev_err_probe(bq->dev, PTR_ERR(reg), + "registering vsys regulator"); + } + return 0; } #else