From patchwork Thu Apr 2 14:58: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: 11470971 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 6F8B992A for ; Thu, 2 Apr 2020 14:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 436FA20757 for ; Thu, 2 Apr 2020 14:58:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="fD/KixoE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388923AbgDBO6b (ORCPT ); Thu, 2 Apr 2020 10:58:31 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:30174 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388782AbgDBO6b (ORCPT ); Thu, 2 Apr 2020 10:58:31 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5f2JwnzHd; Thu, 2 Apr 2020 16:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839510; bh=9+54rd/b9MFSvGJ5H7aKdvK4EyDceTpr1Ul1xvO7tH8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=fD/KixoETC6wnb4NjFzbS6rBcLYkFUzKnwIkEyAe6Em1zr5q5CVSS+omMZrenu4wB 9gImfXsp7eBG31v9jil0QotWAGe4jOqX4osO83JizCqVi+rFrkMkUxVOvTTIYgdCQy vbtF/wb8veaKNQLTItLia9uJ6p1sg3dyAgr7+TUV/9e9g3kDnglnbRhBybLMjBcRQI RJggPu9dwNVAHpFANsoNVnmBA+qw3eCLxgpxsDAS+MHAGyQCO5zjEkkoDRXWqO0DlF gYv6pCw1Ph0Tq5JkOmvWoCESQTr0TV3B0JQLYPVMn/TY6SidF96tSsoqtdA52Ba/vL C1Lv2PNRjZCHA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:30 +0200 Message-Id: <6a0db93bd3345ed634f489e93526f3317fbefe31.1585838678.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 01/14] power: supply: bq25890: remove redundant I2C bus check MIME-Version: 1.0 To: Sebastian Reichel Cc: linux-pm@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 regmap initialization will check I2C adapter functionality. Remove redundant check in the driver. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index aebd1253dbc9..c642519ef7b2 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -881,17 +881,11 @@ static int bq25890_fw_probe(struct bq25890_device *bq) static int bq25890_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct i2c_adapter *adapter = client->adapter; struct device *dev = &client->dev; struct bq25890_device *bq; int ret; int i; - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_err(dev, "No support for SMBUS_BYTE_DATA\n"); - return -ENODEV; - } - bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); if (!bq) return -ENOMEM; From patchwork Thu Apr 2 14:58: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: 11470973 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 123FE1668 for ; Thu, 2 Apr 2020 14:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E338820784 for ; Thu, 2 Apr 2020 14:58:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="LFINZhAi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389043AbgDBO6e (ORCPT ); Thu, 2 Apr 2020 10:58:34 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:38650 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388810AbgDBO6c (ORCPT ); Thu, 2 Apr 2020 10:58:32 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5f4N0ZzpX; Thu, 2 Apr 2020 16:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839510; bh=mKRZQCnghprUjuua4YgNrBV4tEAzgIfaruToSEdSL8Q=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=LFINZhAiLjqUgJM3G8AuCdh6p8gNHhyiDpTZKTo5nwKm2tNUr2q2VUI+IeJpCEOtX MtMNFCjEzO5uWYIrRN6eiJoLS/JtuL3o8yD9VJ5J4/Sk39UAdy1p7zwzmuj3rZqORK rEHFEQ26x03oy1Yroib7fgpYYZIouoccSIM74JjH6MIoTdcVD9rMzq8p2f7lfqSXCY 2wHu6Ld5L7EUlmbTPdxu0c0HrLaRIEBRWxiEneWd7QB1gRhCVYAYdGLC5aanroEaol rYt+eirrkjdAqheuNIALyf6h61nLphPHh7I6G0euXnzF3+vdhlG/HSL63VKbnG3nzJ GA3LHzPkp4d1g== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:30 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 02/14] power: supply: bq25890: simplify chip name property getter MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 Driver rejects unknown chips early in the probe(), so when bq25890_power_supply_get_property() is made reachable, bq->chip_version will already be set to correct value - there is no need to check it again. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index c642519ef7b2..f9f29edadddc 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -32,6 +32,13 @@ enum bq25890_chip_version { BQ25896, }; +static const char *const bq25890_chip_name[] = { + "BQ25890", + "BQ25892", + "BQ25895", + "BQ25896", +}; + enum bq25890_fields { F_EN_HIZ, F_EN_ILIM, F_IILIM, /* Reg00 */ F_BHOT, F_BCOLD, F_VINDPM_OFS, /* Reg01 */ @@ -400,17 +407,7 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_MODEL_NAME: - if (bq->chip_version == BQ25890) - val->strval = "BQ25890"; - else if (bq->chip_version == BQ25892) - val->strval = "BQ25892"; - else if (bq->chip_version == BQ25895) - val->strval = "BQ25895"; - else if (bq->chip_version == BQ25896) - val->strval = "BQ25896"; - else - val->strval = "UNKNOWN"; - + val->strval = bq25890_chip_name[bq->chip_version]; break; case POWER_SUPPLY_PROP_ONLINE: From patchwork Thu Apr 2 14:58: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: 11470975 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 7DE6D17EA for ; Thu, 2 Apr 2020 14:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 524BD2080C for ; Thu, 2 Apr 2020 14:58:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="IQefsOsZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389006AbgDBO6f (ORCPT ); Thu, 2 Apr 2020 10:58:35 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:55245 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388836AbgDBO6d (ORCPT ); Thu, 2 Apr 2020 10:58:33 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5f6wnCzqB; Thu, 2 Apr 2020 16:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839511; bh=aHxtsC8N7E1pudNhXZCf8OSOZbxQCCFh3AVsjrqFoGw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=IQefsOsZdmpl1GYa4eHhaiWo6dqrxNummNHFhVfbtryIyvpgb3iPHfO0xEPoQhcRw QQIUp1TamaUdbVZ/sYm+zIb+1VHrW4Ffxtvhx9MvYhjPlOf3nvPAqOIjnI1n6W4qE5 xJDe0DhCAMea3wwxFPvxyxZD4AQjkW99JZBXWk6vyXzWRN93XCo08rSwFmjJaPSTWy slJazljJIheIKQ/+UMdVdcx1PbqrpiMPKXHJ4Z84PMfh7Sp17cnt+X8bbh8jrQcZ8s ZSEBxvCs51KHR+veFn2csFumoshZ+urcZixmhmYvX2lGAQoxcmj4KeiuEysKrnKvL7 Pu2MBPueRRRcA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:30 +0200 Message-Id: <3d647e5c2f69c0cef461ef19004ec40b14e799ca.1585838678.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 03/14] power: supply: bq25890: make property table const MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 Property list should not change, so mark it const. Signed-off-by: Michał Mirosław Reported-by: kbuild test robot Reported-by: kbuild test robot --- drivers/power/supply/bq25890_charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index f9f29edadddc..c4a69fd69f34 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -668,7 +668,7 @@ static int bq25890_hw_init(struct bq25890_device *bq) return 0; } -static enum power_supply_property bq25890_power_supply_props[] = { +static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_STATUS, From patchwork Thu Apr 2 14:58:31 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: 11471001 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 8475E92A for ; Thu, 2 Apr 2020 14:59:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B0C1206E9 for ; Thu, 2 Apr 2020 14:59: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="Ov6S14+1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389165AbgDBO7O (ORCPT ); Thu, 2 Apr 2020 10:59:14 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:54329 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388782AbgDBO6d (ORCPT ); Thu, 2 Apr 2020 10:58:33 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5g3T37zwy; Thu, 2 Apr 2020 16:58:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839511; bh=Ol/Fy27tVQcocJtHbCOujmzZ2avDxeNSc4gh5D0opQs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Ov6S14+1qIUTfiLKzfv9pmaec6kaL1/TzSMpOudtm+W8wRakdS0mmEaIeNrHQlD+S jiGEI4YO1P3yKat7Z3grQ5QWfliU1cp0TDMDqhpv5gO4EVu2KKBOUDwyK8KT5Y7hXp T3DQjnxVA6VnmbWBZbR1UpLPrDiD96OvyVWmU5t2DTVandgCTOeA3rlyNqJPFUK4lE r6AruVThZvDl+YnXZ+jrpD88Sv4PhTjz7WwcPZYkWD5/0r+rwzKdhI66MCoGhRZoGG 45I9Q8WDOoMkEX9e4ajY+Eek+ViCpLRF4GqJX20RYFoA3zu7FS/G+zy3KRD5UvnLVO wY4z4Gh8mjHWA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:31 +0200 Message-Id: <58a369bc6c2cb1f5ee28dd6dda634999f78fa8b4.1585838678.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 04/14] power: supply: bq25890: protect view of the chip's state MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 Extend bq->lock over whole updating of the chip's state. Might get useful later for switching ADC modes correctly. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 82 ++++++++------------------ 1 file changed, 26 insertions(+), 56 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index c4a69fd69f34..9339e216651f 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -510,74 +510,50 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, return 0; } -static bool bq25890_state_changed(struct bq25890_device *bq, - struct bq25890_state *new_state) -{ - struct bq25890_state old_state; - - mutex_lock(&bq->lock); - old_state = bq->state; - mutex_unlock(&bq->lock); - - return (old_state.chrg_status != new_state->chrg_status || - old_state.chrg_fault != new_state->chrg_fault || - old_state.online != new_state->online || - old_state.bat_fault != new_state->bat_fault || - old_state.boost_fault != new_state->boost_fault || - old_state.vsys_status != new_state->vsys_status); -} - -static void bq25890_handle_state_change(struct bq25890_device *bq, - struct bq25890_state *new_state) +static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq) { + struct bq25890_state new_state; int ret; - struct bq25890_state old_state; - mutex_lock(&bq->lock); - old_state = bq->state; - mutex_unlock(&bq->lock); + ret = bq25890_get_chip_state(bq, &new_state); + if (ret < 0) + return IRQ_NONE; - if (!new_state->online) { /* power removed */ + if (!memcmp(&bq->state, &new_state, sizeof(new_state))) + return IRQ_NONE; + + if (!new_state.online && bq->state.online) { /* power removed */ /* disable ADC */ ret = bq25890_field_write(bq, F_CONV_START, 0); if (ret < 0) goto error; - } else if (!old_state.online) { /* power inserted */ + } else if (new_state.online && !bq->state.online) { /* power inserted */ /* enable ADC, to have control of charge current/voltage */ ret = bq25890_field_write(bq, F_CONV_START, 1); if (ret < 0) goto error; } - return; + bq->state = new_state; + power_supply_changed(bq->charger); + return IRQ_HANDLED; error: - dev_err(bq->dev, "Error communicating with the chip.\n"); + dev_err(bq->dev, "Error communicating with the chip: %pe\n", + ERR_PTR(ret)); + return IRQ_HANDLED; } static irqreturn_t bq25890_irq_handler_thread(int irq, void *private) { struct bq25890_device *bq = private; - int ret; - struct bq25890_state state; - - ret = bq25890_get_chip_state(bq, &state); - if (ret < 0) - goto handled; - - if (!bq25890_state_changed(bq, &state)) - goto handled; - - bq25890_handle_state_change(bq, &state); + irqreturn_t ret; mutex_lock(&bq->lock); - bq->state = state; + ret = __bq25890_handle_irq(bq); mutex_unlock(&bq->lock); - power_supply_changed(bq->charger); - -handled: - return IRQ_HANDLED; + return ret; } static int bq25890_chip_reset(struct bq25890_device *bq) @@ -607,7 +583,6 @@ static int bq25890_hw_init(struct bq25890_device *bq) { int ret; int i; - struct bq25890_state state; const struct { enum bq25890_fields id; @@ -655,16 +630,12 @@ static int bq25890_hw_init(struct bq25890_device *bq) return ret; } - ret = bq25890_get_chip_state(bq, &state); + ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) { dev_dbg(bq->dev, "Get state failed %d\n", ret); return ret; } - mutex_lock(&bq->lock); - bq->state = state; - mutex_unlock(&bq->lock); - return 0; } @@ -1001,19 +972,16 @@ static int bq25890_suspend(struct device *dev) static int bq25890_resume(struct device *dev) { int ret; - struct bq25890_state state; struct bq25890_device *bq = dev_get_drvdata(dev); - ret = bq25890_get_chip_state(bq, &state); + mutex_lock(&bq->lock); + + ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) return ret; - mutex_lock(&bq->lock); - bq->state = state; - mutex_unlock(&bq->lock); - /* Re-enable ADC only if charger is plugged in. */ - if (state.online) { + if (bq->state.online) { ret = bq25890_field_write(bq, F_CONV_START, 1); if (ret < 0) return ret; @@ -1022,6 +990,8 @@ static int bq25890_resume(struct device *dev) /* signal userspace, maybe state changed while suspended */ power_supply_changed(bq->charger); + mutex_unlock(&bq->lock); + return 0; } #endif From patchwork Thu Apr 2 14:58:31 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: 11470997 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 A757B92A for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8322C206E9 for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="CwqCA3gO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389016AbgDBO7E (ORCPT ); Thu, 2 Apr 2020 10:59:04 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:58435 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389039AbgDBO6e (ORCPT ); Thu, 2 Apr 2020 10:58:34 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5g68HZz1qr; Thu, 2 Apr 2020 16:58:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839511; bh=YIDfMUMGzJXrR0o8/w9xvesAyrjX19dF5+drN1MGEM8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=CwqCA3gOMW4H5jNO4XJq9mvy+p1zklcf96jTPFBeHrSL2a1WNX2PHManYfsea/Hpi 19uFmkYfihkIiRdpg7MFWSandOAufCg7HhjxUUrXE6k+FnnToenwQk/NycXnNOtGbd NLsczVYpti+lIGMDRmANxEO/DPn8nAmxPkTF2yXPfXNmlC6cKqLT4AZlrjz9atw1Xx GiG8O4PXi0XNg9vYP7CZMDxQHOWckcgEO1BbM3NUbiULV5OHU5yebPUZJslH9Z/8kH pClKAqW1Kl2tKYlX1aqIkNR2VTQPrZeXy0RjZD4KIP1cGUqIDkxvuSQaceSs56Q2kL 6cLyTJeYWKkLg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:31 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 05/14] power: supply: bq25890: fix ADC mode configuration MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 Reported-by: kbuild test robot Reported-by: kbuild test robot Reported-by: kbuild test robot --- drivers/power/supply/bq25890_charger.c | 33 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 9339e216651f..3b02fa80aedd 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,40 @@ 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_INPUT_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW: + 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 +646,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 +989,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 +1005,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 Thu Apr 2 14:58:32 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: 11470995 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 78E8E17EA for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5650C20719 for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="aKsvPqp9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389140AbgDBO7F (ORCPT ); Thu, 2 Apr 2020 10:59:05 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:37958 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388781AbgDBO6e (ORCPT ); Thu, 2 Apr 2020 10:58:34 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5h2hkPz1vW; Thu, 2 Apr 2020 16:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839512; bh=X6di/kZ9JXtfx1MiBhjtRiHxgwlcVR2sOcyLvmd+Kuk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=aKsvPqp9eEE1e3/OOmvgA0P552rUjkO0alh15EpymshDJkzGwBF5W4tGdNFcA7Pyz EXIS12pOUL3N5yIYHdfNIec2P57TahFr1eZYjvoJIGQVcKrhDoxPE0S/bZ2S75aUB9 7K6IFE3wO1hCNCb11zuzdCnGHflAG4JjhQ0urRc6cNkWg3+KL7z0KMr9hh+CsRnGeR rwMD7gdEa0SS3uecNeagcwvSW3ihusPGLtIn+pqmitwraRUFeGKhV8rLM6kRdLddCn j+DmTsv7guGRMnsBxLF91I0wKxGXCauFe/nB1jmh/mke9CyxSRHoTjDTMo+L9tinUF laUrPPhFFGdrQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:32 +0200 Message-Id: <3aa6336d84b67425a1c590e18668b2da92f618a3.1585838678.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 06/14] power: supply: bq25890: update state on property read MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 3b02fa80aedd..e4368d01396a 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -389,6 +389,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) @@ -399,6 +401,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 Thu Apr 2 14:58:32 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: 11470999 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 E41D718C6 for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B517721707 for ; Thu, 2 Apr 2020 14:59:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="Kdmo72yw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388972AbgDBO7E (ORCPT ); Thu, 2 Apr 2020 10:59:04 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:40831 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389041AbgDBO6f (ORCPT ); Thu, 2 Apr 2020 10:58:35 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5j2Bpvz9j; Thu, 2 Apr 2020 16:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839513; bh=CtdnXaW3M9J6/3+oqZVerhtAMCemduwcslAGnqFReTw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Kdmo72ywkGxiqa5vrzjpXFuEm59PmujDUIiEgUrQ1yB8yhMkO37IDPZu4A608+kFn dETm6BpadQ+/JuYUGw4gFiR/wc24zZ+DjjQIk2EwBMBKHbCiCyo1ZLOOwO1ZuerPrE /HyCyYMXBXB2nHNtFyDIi5PIMx9XSGEv9qI3s0wG2uPJKiPDi11NPEUHcnmm7QWB2u CLhzzbzsr5RsFnHGWjV5rIwku7Hd2MZClonth48ZGUfTYSuUCA20fffwNyacbcORLP xYXbEW+FLMlhn3ysqu8S4R0RCZVNt6/gJnj/pdtkpjdYRXEMj+IlvfUptGdI9MwZjr NNlid/rDhU9Yg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:32 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 07/14] power: supply: bq25890: implement CHARGE_TYPE property MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 e4368d01396a..ad0901fdceb6 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -429,6 +429,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; @@ -670,6 +682,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, From patchwork Thu Apr 2 14:58:33 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: 11470977 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 B927192A for ; Thu, 2 Apr 2020 14:58:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E1902078B for ; Thu, 2 Apr 2020 14:58:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="rmFm6V7v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389057AbgDBO6g (ORCPT ); Thu, 2 Apr 2020 10:58:36 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:36003 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389042AbgDBO6g (ORCPT ); Thu, 2 Apr 2020 10:58:36 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5j53x1zHd; Thu, 2 Apr 2020 16:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839513; bh=j/RXM+fNBpI5abZHjWXnC0UL+wj8lzgTO3a3XRS4VRU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=rmFm6V7voMtzUHDPx3PWN0+P4CziTICw6Z7LysscEHLrdiP7/ecGP58nkJ/5c2RSm cvp9U/v4FK3s0UmhzE91eNGmraL97/NOqfM/34/ZOeICAa1dJxTjTBL68nnCynORK2 MlnKexcT2l5bNmNZa2VyO7xvIPjqHgK7BJ9NRBBpjZ24EG+EqsKHvO4RpBppEHGSZ3 FcvugbBbO9UeW7+x3PfsBWSust7bIWhhoswfY//j+NqLOECLIr4ttvSe6BoWWkj2QU 8OeCJk+N8YTkbMDFqMsjnnS7qtol6RKsPur9RUqv8Cpa8n0xNM4pEThTFPxTqnPL+T 4LaCur2WhwNPQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:33 +0200 Message-Id: <42a64bb02651d731de1a88d382eec9ca61885994.1585838679.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 08/14] power: supply: bq25890: implement PRECHARGE_CURRENT property MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 ad0901fdceb6..b48685009048 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -497,6 +497,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; @@ -689,6 +693,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, }; From patchwork Thu Apr 2 14:58:33 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: 11470991 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 3D17692A for ; Thu, 2 Apr 2020 14:59:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AC8D20757 for ; Thu, 2 Apr 2020 14:59:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="py4C8dEl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389114AbgDBO64 (ORCPT ); Thu, 2 Apr 2020 10:58:56 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:45187 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389047AbgDBO6g (ORCPT ); Thu, 2 Apr 2020 10:58:36 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5k2S3Rz1vh; Thu, 2 Apr 2020 16:58:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839514; bh=gRqyNiKmpXtCcJah85qRJb4ZmdxMMi1xeLY32RUkzmw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=py4C8dEl3mEDGP6diNl5IGaONluJgCjEUrAgpOdCMlmzzGB+kSQ8UsqPbkOmzyB/6 ClF+RNRKliZzAMgD302oZzOfqzGBH91lP/LL0REBDLF9uktKub9S/AcvzjwuT7be/B 09VS8Z68vdLkgpsbzDuCP/xI22ZvTc57YzfZsU4HBWXswZOgj9Ouj7AsuLVusj5gzd idMtkYtb7qbKhj7zbvaZbJrQniLkQs3Ny85rtAdjBsZeKYvMI5jFcV7YAGgS42bP5t K7fz5257DiYFWmRpbG4sZ8zhz84k7fLyTLf+Q9Ot+zfPGh4+vvrNLiqjMDfScm6tVz m3+K+7kTpS06Q== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:33 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 09/14] power: supply: bq25890: implement INPUT_CURRENT_LIMIT property MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 b48685009048..87c5832e23d3 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 */ @@ -505,6 +507,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) @@ -695,6 +705,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, }; From patchwork Thu Apr 2 14:58:34 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: 11470989 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 B1C2D17EA for ; Thu, 2 Apr 2020 14:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90DCD21707 for ; Thu, 2 Apr 2020 14:58:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="rrDhLWww" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389117AbgDBO65 (ORCPT ); Thu, 2 Apr 2020 10:58:57 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:37958 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388977AbgDBO6g (ORCPT ); Thu, 2 Apr 2020 10:58:36 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5k5lvLzpX; Thu, 2 Apr 2020 16:58:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839514; bh=kjx6NBawS358bbnB/tg0fAzXbSbFFBICYGk9a+ABk0A=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=rrDhLWwwOv2K3yJ5/l7mfu+jCrprIToh4RnTswITiG4RiatJfxyRHYcWcWp8U9Ya3 2Y+orVzVVkQORT0M8aVFsD87kjZbxFK/X2fHYe8x6WtOac+8rCt2S07sGJG1Dun6kt yo04h7IbG5mqcOuQbt0nT8wE/ysQaEzPhEuoAutbK3aHCiroImlCdZdnyZJoacgTK4 CPzMYoX0kd9WijF9cbpIl5UhhvDTh7toQp7igMx1EaoYQHkhsVLfnGs1tdpO7BLKdA +QAcPRECOUNyXj1gd3HTIutkShoYCHoFyWi+LRwqnwgFl0agPIZY0Ux9Z47lD2ajWV un2BiGAbQtzsg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:34 +0200 Message-Id: <2d7728cc62804d0773254337aae8eed9905786b3.1585838679.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 10/14] power: supply: bq25890: use proper CURRENT_NOW property for I_BAT MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 87c5832e23d3..250468f3ff18 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -468,15 +468,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; @@ -524,6 +515,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; } @@ -699,7 +699,6 @@ 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, @@ -707,6 +706,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, }; static char *bq25890_charger_supplied_to[] = { From patchwork Thu Apr 2 14:58:34 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: 11470985 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 3DDBE92A for ; Thu, 2 Apr 2020 14:58:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BA102080C for ; Thu, 2 Apr 2020 14:58:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="h9N6AWMC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389062AbgDBO6h (ORCPT ); Thu, 2 Apr 2020 10:58:37 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:58435 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389052AbgDBO6h (ORCPT ); Thu, 2 Apr 2020 10:58:37 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5l4kdYzqB; Thu, 2 Apr 2020 16:58:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839515; bh=5DdryG9hn452PH5otkZQyLTHjkaK1jF+yu4xhWcJIes=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=h9N6AWMCD+bl1pulxoTnpTmk+uql18JADPHUv+phnMgiiMlnp/lW0hqb1Xy3XJ8ju 3hKe8DL45eAS0Vzn30DiDyWgKgB0QuAxiirZauvgjdPAAa7ZeEsFknfHcjCoTyF921 9bN7X+nzY/1FCo8eCbEVLtqwU+S32L193dKa+ZwNDdRKW47K3D++g+/7vmYV5E+lGD VkO/5Szv2X7AsJgr/OECkSJ/5gruXoIbA6QA4LuQYILi6JNOLDi74OKQS3o2nerHZ7 WlfuLM3oxTbJGcnikJySZX6nh8vVWfYzIQfVxDqUTOAWGv4Ug2mK1EAnoTERJMjf3w WC4mGYplJ/3MQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:34 +0200 Message-Id: <32ec8cef47cb49e02542916ae15972ba2e619e5a.1585838679.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 11/14] power: supply: bq25890: show measured VBUS MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 Export VBUS measurement via INPUT_VOLTAGE_NOW property. Signed-off-by: Michał Mirosław Reported-by: kbuild test robot Reported-by: kbuild test robot --- drivers/power/supply/bq25890_charger.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 250468f3ff18..d23274d13263 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -506,6 +506,24 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = bq25890_find_val(ret, TBL_IILIM); break; + case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW: + ret = bq25890_field_read(bq, F_VBUS_GD); /* is VBUS connected? */ + if (ret < 0) + return ret; + + if (!ret) { + val->intval = 0; + break; + } + + ret = bq25890_field_read(bq, F_VBUSV); /* read measured value */ + if (ret < 0) + return ret; + + /* converted_val = 2.6V + ADC_val * 100mV */ + val->intval = 2600000 + ret * 100000; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ if (ret < 0) @@ -705,6 +723,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_PRECHARGE_CURRENT, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, }; From patchwork Thu Apr 2 14:58:35 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: 11470987 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 7F9D81668 for ; Thu, 2 Apr 2020 14:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D83D2074D for ; Thu, 2 Apr 2020 14:58:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="jJB8aqYO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389013AbgDBO6x (ORCPT ); Thu, 2 Apr 2020 10:58:53 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:40831 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389055AbgDBO6h (ORCPT ); Thu, 2 Apr 2020 10:58:37 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5m1387z9j; Thu, 2 Apr 2020 16:58:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839516; bh=Z5m6v9PbZvsaRy/wVOFR85m5686ZzFRztIiMSmfJt0Y=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=jJB8aqYOYrf5iDaTcb/lF5MHMkUwjVaUeqF4a/YRAGx2sY+fdFn4VVR3HWuXHi36v jubybgYGUlcnuFMD723dnaqwVYrL8dRKEuhZTWuoWpE0Zz8HgDOlQ1dH5WGCR1kW6b VXxjnzWmGHnSTqHtliwzDwHAaTSi0PveGaX20uSMkB+2M5HD+mj4wCZO0efxz8hmnO tIiUUXNkNFRpCBe9d1sxkO4O/ep0qWYU5QWxur6zMA2602Ej1+hmbw77sXWVBhwtWc z6Yb4oJd34Te4l52DWJpCIaxb2GVpoGX7sVJ2J6t+YhQBpot5hs0jR0js9mcuftaDJ yML3BCxzEDF3Q== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:35 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 12/14] power: supply: bq25890: show VSYS as output voltage MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 VSYS is the voltage that is provided to the rest of the system. Show measurement OUTPUT_VOLTAGE and supplement it with VSYSMIN setting. Signed-off-by: Michał Mirosław Reported-by: kbuild test robot --- drivers/power/supply/bq25890_charger.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index d23274d13263..6c277f2dbae2 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -524,7 +524,7 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = 2600000 + ret * 100000; break; - case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW: ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ if (ret < 0) return ret; @@ -533,6 +533,10 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = 2304000 + ret * 20000; break; + case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN: + val->intval = bq25890_find_val(bq->init_data.sysvmin, TBL_SYSVMIN); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ if (ret < 0) @@ -724,7 +728,8 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW, - POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW, + POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN, POWER_SUPPLY_PROP_CURRENT_NOW, }; From patchwork Thu Apr 2 14:58:36 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: 11470983 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 3320C1668 for ; Thu, 2 Apr 2020 14:58:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 108B320787 for ; Thu, 2 Apr 2020 14:58: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="KfaNHBU3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388836AbgDBO6j (ORCPT ); Thu, 2 Apr 2020 10:58:39 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:36003 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389058AbgDBO6i (ORCPT ); Thu, 2 Apr 2020 10:58:38 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5m5G7TzHd; Thu, 2 Apr 2020 16:58:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839516; bh=NtMCc186Ug9cBLzwsJyjA0kM4Gsfruxf11Rj7KVafeI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=KfaNHBU3d1npBIHJjyQTNrCNQ3KQkTDOztK0zUrUTz6ZFiLDYk0aJiqOB6/Icguh5 4GaL3VEq1Vw2KH0sUvy7Bpxt8SymotQsXqS4Xsmp5eK1H67X6F8MAQ5RSO1CSHk/NF Bo6yhIVoBJjWg9ECvjllRTkWJNzjlzz5dbX56GqUTsXKYvy9KvYZ9+7mIxbQYv3zFl T1/BfWyf2CLsqKfxy8ywMg6AiTqBpYJyE32E4NpRmJZpysbWv0JVm16k3yckeRmyfE YG4ZOFZ9SgPDrZLvTjcR0xtheqZpitJvr0RsprnkTGYBijRUaIPNlRJUUSkG0X7/aG 1JcD4K0FKZdyw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:36 +0200 Message-Id: <695c9066c94ce73ffe9330e0342194980d581122.1585838679.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 13/14] power: supply: bq25890: show VBAT as VOLTAGE_NOW MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 CONSTANT_CHARGE_VOLTAGE is a currently programmed CC voltage limit and not instaneous reading of a VBAT. Move the measurement to correct property. !online check is removed, as it is useful to read the voltage when not charging. Signed-off-by: Michał Mirosław --- drivers/power/supply/bq25890_charger.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 6c277f2dbae2..a61eab6a4552 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -472,20 +472,6 @@ 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_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; @@ -537,6 +523,15 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, val->intval = bq25890_find_val(bq->init_data.sysvmin, TBL_SYSVMIN); break; + case POWER_SUPPLY_PROP_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_CURRENT_NOW: ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ if (ret < 0) @@ -722,7 +717,6 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_HEALTH, 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, @@ -730,6 +724,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = { POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW, POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW, POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN, + POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, }; From patchwork Thu Apr 2 14:58:36 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: 11470979 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 4869492A for ; Thu, 2 Apr 2020 14:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2668120757 for ; Thu, 2 Apr 2020 14:58:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="BUQAgeEb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389072AbgDBO6j (ORCPT ); Thu, 2 Apr 2020 10:58:39 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:45187 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389060AbgDBO6j (ORCPT ); Thu, 2 Apr 2020 10:58:39 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 48tR5n2L4szpX; Thu, 2 Apr 2020 16:58:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1585839517; bh=K0kGzxg39yXWXSUEEmrAX5O79dFH60rAvb0VYzqfkq4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=BUQAgeEbaQo7vEZ70u/oDSCKsw+v5485zBKPRB2tuYWUIbvv1Nvsl+ZqdN4Ck2Nq7 i3zV0w7F6xlJZFctGDMlcngHZyIn11F4ozCHVgGejY6d7rfhoPzekUUd1LfoLFE49Q 8AVlsuiLwucyjJ6Ckx3gztCPFvP7lL2nLwV3QHoLoPzhDR6vy37x0LNMPUC7SDslA5 LcHIzSkbN9MoXbRjO39CjOd+P7B4D93oyjktH0Nn+IYGLL9uMH6h10BgnOVigKYHRC +O7QqDxkKPbGHMjgNimDz0rNNlifzr8CxpWTSeIkcTCx41ksflgnqjNBxULaP/qoO6 75wEgBU6UYIgg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Thu, 02 Apr 2020 16:58:36 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH 14/14] power: supply: bq25890: support IBAT compensation MIME-Version: 1.0 To: Sebastian Reichel Cc: 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 a61eab6a4552..ba1562968bec 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} }, @@ -667,7 +673,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); @@ -880,11 +888,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,