From patchwork Mon May 4 19:47:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4F1F81 for ; Mon, 4 May 2020 19:48:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD6B320746 for ; Mon, 4 May 2020 19:48:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="pR6G9WK+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbgEDTrr (ORCPT ); Mon, 4 May 2020 15:47:47 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:25825 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbgEDTrr (ORCPT ); Mon, 4 May 2020 15:47:47 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0d0Qz7zGl; Mon, 4 May 2020 21:47:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621665; bh=oH1XIZw4GH2xVUffAb5wzH0/1tJUqjxVsHll5z4vw70=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=pR6G9WK+ablDEAZOMn54aXtJR51oob8GUFXeTcj94gZm3cXJizlzLRKAlXaTXWlTn GvQdoXVCODu8A7FAyfGS4L89nTFEoXceREFqjobrMd6psTppSUoCEnXy0Qx+4a4vEC mubVZa7NBS/RkR8AzAsGkP/n3epluiNgvg+8mcomV6FQoVpTFSIsbY0FtY2xag2lA9 4n5v3/9OHu2fcZJcA/4HZq+JzKHAOMScDHPMVJnJUV3Pt82c4lUtWIBphxOubQI0oO NqpPB/Ewcdn/BH6soJouOx9VxAjUD541+7JlTroP4VUiqAa2QTD/wDhyBbQcuhIZeL BZ72hAqE4nkGg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:30 +0200 Message-Id: <95202939328fff79f4bc002be54876cfb38e4f7d.1588621247.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 1/8] power: bq25890: use proper CURRENT_NOW property for I_BAT MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Charge Current is more apropriately reflected by CURRENT_NOW property (measured current) than CONSTANT_CURRENT_VOLTAGE (configured CC-phase current limit). Fix the reference and make the sign reflect direction of the current. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 9339e216651f..70ecc38fe772 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -427,15 +427,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: - ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ - if (ret < 0) - return ret; - - /* converted_val = ADC_val * 50mA (table 10.3.19) */ - val->intval = ret * 50000; - break; - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); break; @@ -471,6 +462,15 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = 2304000 + ret * 20000; break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ + if (ret < 0) + return ret; + + /* converted_val = ADC_val * 50mA (table 10.3.19) */ + val->intval = ret * -50000; + break; + default: return -EINVAL; } @@ -645,12 +645,12 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_STATUS, 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, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, }; static char *bq25890_charger_supplied_to[] = { From patchwork Mon May 4 19:47:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3A4992A for ; Mon, 4 May 2020 19:47:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93D520752 for ; Mon, 4 May 2020 19:47:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="ZWE2zh27" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727886AbgEDTrt (ORCPT ); Mon, 4 May 2020 15:47:49 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:27580 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726935AbgEDTrs (ORCPT ); Mon, 4 May 2020 15:47:48 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0d4Zw6zHm; Mon, 4 May 2020 21:47:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621665; bh=EbSm5+gnAl+lSmHRWVgxHCpfZGr2FXjwGmT2W8WyfjU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZWE2zh27y2h7FAcDCYKF15bYDiS7+dzmZa8zkxNUy+q6KS0z+Bp3cPky7Qn0cZ55z sevtnwo7Ma/EZw/zHLlQdFTxikyCKLJ73tmbxaa2+vag0xV7avoitCJsxPZm8G5yG9 whZMtJ4LWLRSpGYbt2kG7TZdmU3NBbeC1OcsqCKcVEr9R+lqBl3BY/m5jqthZxDy4h L3Pl8vYZRNvMErVPVJPY8wC9krRGZq4UEjezMCupmGVsFbPVfj/UmIV3cS7ql1XX64 83RbS5Bcv1li2xtv6Ol7dbe47aCy3wvFXDW9hz+lu7QNN7J7qEm9jjt6zljmOXAjxv tLICRYp9KbsiA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:45 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 2/8] power: bq25890: fix ADC mode configuration MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Datasheet describes two modes for reading ADC measurements: 1. continuous, 1 Hz - enabled and started by CONV_RATE bit 2. one-shot - triggered by CONV_START bit In continuous mode, CONV_START is read-only and signifies an ongoing conversion. Change the code to follow the datasheet and really disable continuous mode for power saving. Signed-off-by: Michał Mirosław --- v3: drop dependency on new input/output properties --- drivers/power/supply/bq25890_charger.c | 31 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 70ecc38fe772..325fdd1b1d23 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -126,6 +126,7 @@ static const struct regmap_access_table bq25890_writeable_regs = { static const struct regmap_range bq25890_volatile_reg_ranges[] = { regmap_reg_range(0x00, 0x00), + regmap_reg_range(0x02, 0x02), regmap_reg_range(0x09, 0x09), regmap_reg_range(0x0b, 0x14), }; @@ -374,18 +375,38 @@ enum bq25890_chrg_fault { CHRG_FAULT_TIMER_EXPIRED, }; +static bool bq25890_is_adc_property(enum power_supply_property psp) +{ + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_CURRENT_NOW: + return true; + + default: + return false; + } +} + static int bq25890_power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { - int ret; struct bq25890_device *bq = power_supply_get_drvdata(psy); struct bq25890_state state; + bool do_adc_conv; + int ret; mutex_lock(&bq->lock); state = bq->state; + do_adc_conv = !state.online && bq25890_is_adc_property(psp); + if (do_adc_conv) + bq25890_field_write(bq, F_CONV_START, 1); mutex_unlock(&bq->lock); + if (do_adc_conv) + regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START], + ret, !ret, 25000, 1000000); + switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (!state.online) @@ -623,8 +644,8 @@ static int bq25890_hw_init(struct bq25890_device *bq) } } - /* Configure ADC for continuous conversions. This does not enable it. */ - ret = bq25890_field_write(bq, F_CONV_RATE, 1); + /* Configure ADC for continuous conversions when charging */ + ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online); if (ret < 0) { dev_dbg(bq->dev, "Config ADC failed %d\n", ret); return ret; @@ -966,7 +987,7 @@ static int bq25890_suspend(struct device *dev) * If charger is removed, while in suspend, make sure ADC is diabled * since it consumes slightly more power. */ - return bq25890_field_write(bq, F_CONV_START, 0); + return bq25890_field_write(bq, F_CONV_RATE, 0); } static int bq25890_resume(struct device *dev) @@ -982,7 +1003,7 @@ static int bq25890_resume(struct device *dev) /* Re-enable ADC only if charger is plugged in. */ if (bq->state.online) { - ret = bq25890_field_write(bq, F_CONV_START, 1); + ret = bq25890_field_write(bq, F_CONV_RATE, 1); if (ret < 0) return ret; } From patchwork Mon May 4 19:47:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527491 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63BCA92A for ; Mon, 4 May 2020 19:48:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 426812073B for ; Mon, 4 May 2020 19:48:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="OYTK4tUC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgEDTru (ORCPT ); Mon, 4 May 2020 15:47:50 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:4943 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbgEDTrs (ORCPT ); Mon, 4 May 2020 15:47:48 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0d6Q5vzKc; Mon, 4 May 2020 21:47:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621665; bh=zqZch5CRr9vG4l7fwTEuCyzjtZ4uRNFWQY4JULm254Y=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=OYTK4tUCwQf3x2q+uUDM/U0F/s/8O4cMGyzT8nMqRgMOng/CM/qvm4sCOYeBhk8NA AGVsX4S0WcbEOHeEfnxxgTeXQhN1FghE0onTQe6o//sasvTUAIa0jQ4WZT8mUJYDI+ QRbHIKnkU0AZsnAu/yzr8w4BG2YNEA0l+7/jYCCqBHct9YnO9mf9f0Dwg8j+KiRFvI w/SKQv6gZa7t+OINHCEMaM+ynDsg7mTxUJdyXEE1OCWoW1Nr40jxQvifMsxm+Dtzd7 muTlS+dmyof9bc2RPXLRiGlUzT4XE7d4zkGB/q9PmCY22m9WST9vqubJycZosQPkIG Sc/QoRkWZPTFQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:45 +0200 Message-Id: <8dd5ede84b19ca24c0ee7fa00746923650070536.1588621247.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 3/8] power: bq25890: update state on property read MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Edge interrupts from the charger may be lost or stuck in fault mode since probe(). Check if something changed everytime userspace wants some data. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 325fdd1b1d23..322d48d28fe5 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -387,6 +387,8 @@ static bool bq25890_is_adc_property(enum power_supply_property psp) } } +static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq); + static int bq25890_power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -397,6 +399,8 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, int ret; mutex_lock(&bq->lock); + /* update state in case we lost an interrupt */ + __bq25890_handle_irq(bq); state = bq->state; do_adc_conv = !state.online && bq25890_is_adc_property(psp); if (do_adc_conv) From patchwork Mon May 4 19:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA28B81 for ; Mon, 4 May 2020 19:48:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D123A20746 for ; Mon, 4 May 2020 19:48:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="XZvSQYHN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728035AbgEDTsG (ORCPT ); Mon, 4 May 2020 15:48:06 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:2691 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbgEDTrt (ORCPT ); Mon, 4 May 2020 15:47:49 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0f3WsZzLn; Mon, 4 May 2020 21:47:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621666; bh=cQuVrUR3wgTd8lZabcNbfWQeqVxfRyNFlVyOZvgXwJk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=XZvSQYHN9LeJpr3cfWfmFvU1OLPJHpuQVUUKBiQZGCpGExaESjaBqGLsRiiZKF7YR LmLUoTX3yjb3cBHu+GIkAzjSL9CxlYwJxYxbUi6mfKNeuHPlGj5UN0UC1aanJAVXgn ks5GaQ2vtvABsuQMRtP83X8vrrOu875OupshO9WHR8ko+RIowC8SjpcGprhb/7K1DW WHHGwf8zNECtxWsyzoa6gn34k+nE3tLZR0htnY/DNdWIY+4d/OPzvNowzk+qZ5MNi/ 96T1fbyVjyLsmnkBadI16bmwWvArpficzy9334M3t8bqPIrUUWo5rH0/iy9FZkdbPs vt/OVUGdX68ew== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:46 +0200 Message-Id: <7c42c59a5f27a8f88dad6501d9032189d1878614.1588621247.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 4/8] power: bq25890: implement CHARGE_TYPE property MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Report charging type based on recently read state. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 322d48d28fe5..02e62ac76e15 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -427,6 +427,18 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, break; + case POWER_SUPPLY_PROP_CHARGE_TYPE: + if (!state.online || state.chrg_status == STATUS_NOT_CHARGING || + state.chrg_status == STATUS_TERMINATION_DONE) + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; + else if (state.chrg_status == STATUS_PRE_CHARGING) + val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; + else if (state.chrg_status == STATUS_FAST_CHARGING) + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; + else /* unreachable */ + val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: val->strval = BQ25890_MANUFACTURER; break; @@ -668,6 +680,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_TYPE, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, From patchwork Mon May 4 19:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DC0181 for ; Mon, 4 May 2020 19:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC37A20746 for ; Mon, 4 May 2020 19:48:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="O4pXp3vP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727889AbgEDTsF (ORCPT ); Mon, 4 May 2020 15:48:05 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:15765 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727874AbgEDTrt (ORCPT ); Mon, 4 May 2020 15:47:49 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0g0Jymzrw; Mon, 4 May 2020 21:47:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621667; bh=ntq4LsnQORIu89CAAoAWstxPg4wqt9nj/OAT5Y/wOmw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=O4pXp3vPql6IYtDedgKJMj1dOt1gY66txvYxvQ/BG3uVbOAFpwL24XkbnPGo9xt4+ xjxs2cCEE7w8vmTZuNLYE1yTzMjqeE3UsUt+09ltCZKL+OwvCAthetpPFl2JryhalJ L0yhGV2yKFZLraVElhXvndS5fomhlxL1oyLA2cRiHvyuQkKBZ/RKpE0BDNq8FmeCyo V1Rrk2X0c4gQzukHpusH+Z+DHqXPFRCLLpqzgxALQi6r9xIlErTQqSgN7H23rG4kED zSRqoK4yEwUR91nuYGZQJhQvRqyb80iB4Y7oNIdUt3IXoYj1lPzIHAREebda1TUlu/ eK4d2wnbdc3XA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:46 +0200 Message-Id: <8a4f95cce6625635380e804bd2ef931e62896ed3.1588621247.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 5/8] power: bq25890: implement PRECHARGE_CURRENT property MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Report configured precharge current. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 02e62ac76e15..dfd7bf9a3a55 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -486,6 +486,10 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, 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; + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM); break; @@ -686,6 +690,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, + POWER_SUPPLY_PROP_PRECHARGE_CURRENT, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, From patchwork Mon May 4 19:47:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BD5217E8 for ; Mon, 4 May 2020 19:48:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5999320746 for ; Mon, 4 May 2020 19:48:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="bM0G5Ssa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728029AbgEDTsF (ORCPT ); Mon, 4 May 2020 15:48:05 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:35878 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbgEDTrt (ORCPT ); Mon, 4 May 2020 15:47:49 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0g55STzGl; Mon, 4 May 2020 21:47:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621667; bh=PlaAuIlDy3wYhoSP1lLGpuqY1fWmmJ/2uPxVj7hhzBo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=bM0G5Ssafpcd4gQ6AmyrZCFs48qjeAEpBBHuN9KJaRivjld8/zmlpv3l+30I3mcAY 28QVdbNIAgA5JW/g4Yw+Bw0kGLXIkmlACNjLqLDsTTDVmMEhHRBDFURm4owlhJVy1u oCiAYLw8veflUtYcnWJhoeZn+IY6MvpwnvP7nBbD5lx7kOEL/+ipeponlPzzM1pxuv IhDx6V5PFPOj/7EXfj1L/7+mWdhL1ebd1K2B70QQXMby05PNVg6AA7HcJlIsZ2351y 5Ing8xufXREMRi/l7d++W2WOn0QGiX6qWxEPBpWxR70UYDf29Lj7onodsq0g/DeQm2 tHi9G5Z1T8N3g== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:47 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 6/8] power: bq25890: implement INPUT_CURRENT_LIMIT property MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Report REG00.IINLIM value as INPUT_CURRENT_LIMIT property. Signed-off-by: Michał Mirosław --- 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 dfd7bf9a3a55..cb57125ea988 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -254,6 +254,7 @@ enum bq25890_table_ids { /* range tables */ TBL_ICHG, TBL_ITERM, + TBL_IILIM, TBL_VREG, TBL_BOOSTV, TBL_SYSVMIN, @@ -294,6 +295,7 @@ static const union { /* TODO: BQ25896 has max ICHG 3008 mA */ [TBL_ICHG] = { .rt = {0, 5056000, 64000} }, /* uA */ [TBL_ITERM] = { .rt = {64000, 1024000, 64000} }, /* uA */ + [TBL_IILIM] = { .rt = {50000, 3200000, 50000} }, /* uA */ [TBL_VREG] = { .rt = {3840000, 4608000, 16000} }, /* uV */ [TBL_BOOSTV] = { .rt = {4550000, 5510000, 64000} }, /* uV */ [TBL_SYSVMIN] = { .rt = {3000000, 3700000, 100000} }, /* uV */ @@ -494,6 +496,14 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM); break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = bq25890_field_read(bq, F_IILIM); + if (ret < 0) + return ret; + + val->intval = bq25890_find_val(ret, TBL_IILIM); + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ if (ret < 0) @@ -692,6 +702,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, POWER_SUPPLY_PROP_PRECHARGE_CURRENT, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, }; From patchwork Mon May 4 19:47:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73EB392A for ; Mon, 4 May 2020 19:48:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AA2B20721 for ; Mon, 4 May 2020 19:48:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="C1WmJ9M8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgEDTrw (ORCPT ); Mon, 4 May 2020 15:47:52 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:57761 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727889AbgEDTru (ORCPT ); Mon, 4 May 2020 15:47:50 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0h1cX3zx2; Mon, 4 May 2020 21:47:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621668; bh=02QjF35bIYLrUMp0+nBPGRRjewlZ8g3tIFyMHy0VycA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=C1WmJ9M8dwnGHOocsWJBm/Lq2+dKHLuDNHF08QE2Y2PdiuIIXUFM/YRgBjSdp3cS1 zYfEZx9dOUAuuYyao+5QsueP12h+MNW8I+hYSqfDo8GgqhVJa6raqQnrPe9itr6iZ0 aEq/iobyWZGprYrtlp1phmef/w/sEWLFDhu79moJbKc5MrJyp6LYwRbrQ6OYk0Aem0 O1iSInXF5iJF1jr+9hmOQfJMLeYRzVvp68Wjnhx4huufQEBux61GzNBedn0E3AcK5/ PJnQ5uRk2pFCnoY9P5UGzBaS3I19RZ68r9epk2xKfQVF2AjCZEzvAnZsC8bZAgzhVy gcD6tkQL33kfg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:48 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 7/8] power: bq25890: support IBAT compensation MIME-Version: 1.0 To: Angus Ainslie , Rob Herring , Sebastian Reichel , Yauhen Kharuzhy Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add configuration for compensation of IBAT measuring resistor in series with the battery. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index cb57125ea988..80ff767b2422 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -83,6 +83,8 @@ struct bq25890_init_data { u8 boostf; /* boost frequency */ u8 ilim_en; /* enable ILIM pin */ u8 treg; /* thermal regulation threshold */ + u8 rbatcomp; /* IBAT sense resistor value */ + u8 vclamp; /* IBAT compensation voltage limit */ }; struct bq25890_state { @@ -258,6 +260,8 @@ enum bq25890_table_ids { TBL_VREG, TBL_BOOSTV, TBL_SYSVMIN, + TBL_VBATCOMP, + TBL_RBATCOMP, /* lookup tables */ TBL_TREG, @@ -299,6 +303,8 @@ static const union { [TBL_VREG] = { .rt = {3840000, 4608000, 16000} }, /* uV */ [TBL_BOOSTV] = { .rt = {4550000, 5510000, 64000} }, /* uV */ [TBL_SYSVMIN] = { .rt = {3000000, 3700000, 100000} }, /* uV */ + [TBL_VBATCOMP] ={ .rt = {0, 224000, 32000} }, /* uV */ + [TBL_RBATCOMP] ={ .rt = {0, 140000, 20000} }, /* uOhm */ /* lookup tables */ [TBL_TREG] = { .lt = {bq25890_treg_tbl, BQ25890_TREG_TBL_SIZE} }, @@ -648,7 +654,9 @@ static int bq25890_hw_init(struct bq25890_device *bq) {F_BOOSTI, bq->init_data.boosti}, {F_BOOSTF, bq->init_data.boostf}, {F_EN_ILIM, bq->init_data.ilim_en}, - {F_TREG, bq->init_data.treg} + {F_TREG, bq->init_data.treg}, + {F_BATCMP, bq->init_data.rbatcomp}, + {F_VCLAMP, bq->init_data.vclamp}, }; ret = bq25890_chip_reset(bq); @@ -859,11 +867,14 @@ static int bq25890_fw_read_u32_props(struct bq25890_device *bq) {"ti,boost-max-current", false, TBL_BOOSTI, &init->boosti}, /* optional properties */ - {"ti,thermal-regulation-threshold", true, TBL_TREG, &init->treg} + {"ti,thermal-regulation-threshold", true, TBL_TREG, &init->treg}, + {"ti,ibatcomp-resistance", true, TBL_RBATCOMP, &init->rbatcomp}, + {"ti,ibatcomp-clamp-voltage", true, TBL_VBATCOMP, &init->vclamp}, }; /* initialize data for optional properties */ init->treg = 3; /* 120 degrees Celsius */ + init->rbatcomp = init->vclamp = 0; /* IBAT compensation disabled */ for (i = 0; i < ARRAY_SIZE(props); i++) { ret = device_property_read_u32(bq->dev, props[i].name, From patchwork Mon May 4 19:47:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11527487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA08181 for ; Mon, 4 May 2020 19:47:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1F1B2073B for ; Mon, 4 May 2020 19:47:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="domxx5yj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727922AbgEDTrv (ORCPT ); Mon, 4 May 2020 15:47:51 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:11554 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727890AbgEDTrv (ORCPT ); Mon, 4 May 2020 15:47:51 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49GD0h51GbzxG; Mon, 4 May 2020 21:47:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588621668; bh=s1HXUgdptDiILL4CHASaCVMVwp8zJDwtvmtc4X9Z27M=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=domxx5yjMhpAYJy4SELZqPSdXKV/RtsW2NFICgsxNZFoLFqExgNYZ0tzqKIOZ/G04 0HvSqll7LkhlALoMU9wJkg2uMR8sSHiiXEL1oG12/BLHWc7NdJYotwowv46n76WIu6 sOOjE/+kenxKIHaCqSbW92FrR3OxItqNKPzVJgRBDMEpojfG+bI+tl8X1NYCbxSTmD luPdQkJw2ElkXRHvr8WMxLEQ9Jnc5gkl4HKcmJ/HGQkNGXs1I5c6ndSo/+NGbMliA5 zwzocNpXje+44WWj5lufPSii4UB9sbMsL3QuVL2bXoozTbeQsbeFPz4T9RHwYXV+i1 wfvi6ZMiJNZyA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Mon, 04 May 2020 21:47:48 +0200 Message-Id: <7bf8bb5654bf67e14b59c5f94d024ac6ef5ff0ce.1588621247.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 8/8] power: bq25890: document IBAT compensation DT properties MIME-Version: 1.0 To: Sebastian Reichel , Rob Herring , Angus Ainslie , Yauhen Kharuzhy Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Document newly introduced IBAT compensation settings. Signed-off-by: Michał Mirosław --- v2: initial version --- Documentation/devicetree/bindings/power/supply/bq25890.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/bq25890.txt b/Documentation/devicetree/bindings/power/supply/bq25890.txt index dc9c8f76e06c..bd214945d9dc 100644 --- a/Documentation/devicetree/bindings/power/supply/bq25890.txt +++ b/Documentation/devicetree/bindings/power/supply/bq25890.txt @@ -32,6 +32,10 @@ Optional properties: - ti,thermal-regulation-threshold: integer, temperature above which the charge current is lowered, to avoid overheating (in degrees Celsius). If omitted, the default setting will be used (120 degrees); +- ti,ibatcomp-resistance: integer, value of a resistor in series with + the battery (in uOhm); +- ti,ibatcomp-clamp-voltage: integer, maximum charging voltage adjustment due + to expected voltage drop on in-series resistor (in uV); Example: