From patchwork Sun May 3 15:21:10 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: 212147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DEEDC47258 for ; Sun, 3 May 2020 15:22:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40E83207DD for ; Sun, 3 May 2020 15:22: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="HhhKdvWP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728653AbgECPVN (ORCPT ); Sun, 3 May 2020 11:21:13 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:35642 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbgECPVM (ORCPT ); Sun, 3 May 2020 11:21:12 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7V1X1KzGj; Sun, 3 May 2020 17:21:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519270; bh=9+54rd/b9MFSvGJ5H7aKdvK4EyDceTpr1Ul1xvO7tH8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=HhhKdvWPt8ojeOojYUmj4BOYsBqW+vWR/x9jk4+hE0l7fLPYtUAgk+l7T1i+ybTvR d5iz0uMsTJpfWEvCXaJOsr9N6OkJwCCHXK/gSrkxOOYFDWg8+ynCbyW9LCxxCPJ9Jc lttnWQxa0Nwlp9cupfyTJVgZZaFtLJ4+oXgguVXjliNSqOV8uUz6v/AQMVkh94DI2+ j1q8mz2QCGsl676C54+sfZB1PMKpY4XQ0gmrIQyoGI52eHLP6WDwsIseRyOsSBe3+x SHYmnjQ0UDyMtNVz9inyMSqyjR7rVM/6YdPTaCsRF6y4vZOF7Xp1eEaWoMroxellQR BS3NXdreBXsDg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:10 +0200 Message-Id: <1b3c0d2b01c56cfc073f9ff4961f077098edbe67.1588517058.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 01/11] power: bq25890: remove redundant I2C bus check MIME-Version: 1.0 To: Sebastian Reichel , Rob Herring Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@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 Sun May 3 15:21:10 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: 212148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F2D6C47247 for ; Sun, 3 May 2020 15:21:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5688620836 for ; Sun, 3 May 2020 15:21:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="Kp1cDprU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728869AbgECPVw (ORCPT ); Sun, 3 May 2020 11:21:52 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:43713 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728627AbgECPVN (ORCPT ); Sun, 3 May 2020 11:21:13 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7W0x0HzKc; Sun, 3 May 2020 17:21:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519271; bh=aHxtsC8N7E1pudNhXZCf8OSOZbxQCCFh3AVsjrqFoGw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Kp1cDprUo9JxAqyaSmhflDRfLxph2C3xK63hbVGONN3KhsQTD4zKJ81Y6S51mJMil lj4fQzOr3ss2zY18IrsUtBSoh/h1X/qCPNcMiwa5kiXtzW+2CQPvnkweDxpt8rSKxS O0xerEJigOeHJpFZQY0TEeAe49eVwD0PZ4cfE9IQk+JFDbIUwH6E55kvAc9l2f9W1t QoOR6WbNjWpsdINW/JNUNZXi/0T0EYIIPBQiYTqF/Cq5Ck8Jdv820cPI+ag/iXCiJh GO8/HV1LY7AdF8Ftwyr7fpa4f6RqzPedsD/gt9nPdvEpAZrgWiTgN8r+RzqUwGH6/Z wydbTYZkX+asA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:10 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 03/11] power: bq25890: make property table const MIME-Version: 1.0 To: Rob Herring , Sebastian Reichel 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 Property list should not change, so mark it const. Signed-off-by: Michał Mirosław --- 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 Sun May 3 15:21:11 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: 212149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FE77C47256 for ; Sun, 3 May 2020 15:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FECE20836 for ; Sun, 3 May 2020 15:21:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="YYZvbsHI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728835AbgECPVk (ORCPT ); Sun, 3 May 2020 11:21:40 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:36391 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728689AbgECPVP (ORCPT ); Sun, 3 May 2020 11:21:15 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7X0z6xzT9; Sun, 3 May 2020 17:21:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519272; bh=YIDfMUMGzJXrR0o8/w9xvesAyrjX19dF5+drN1MGEM8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=YYZvbsHIEeaaJt4gR9SCgsZ08NixsTa1klycZhXmRmzuOcfYN4UiwInPBg4I88RCb i6/fIDEBmbRg/ZvQscK7TkL3RecHg2PqUQTJeMg3SYtNuesG82E3tGtaVDhZ/pJSJN ZEQ2wxMZceSl4f8US6OtRLDIXzAAvD/T5Z0XwS/1dVk5jLtpEPFdGoI/cyXYvoJ7eg X0nLdiWsTCpX67BSI5dJ6gJG314fhoYZk6VURq0wy0GLqoPhMDQ3sJmMStEclWC6wt NtBUeBLh+dUD9G4CaoNLuQEF8+o7H7pJJA+JTwrFyIDKpJXuxp7ECWN9Ao25r4lEIL wnzjBKh3SYEug== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:11 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 05/11] power: bq25890: fix ADC mode configuration MIME-Version: 1.0 To: Rob Herring , Sebastian Reichel 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 --- 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 Sun May 3 15:21:12 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: 212152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 514AFC4725A for ; Sun, 3 May 2020 15:21:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26B722071C for ; Sun, 3 May 2020 15:21: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="iJkQy5Wj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728739AbgECPVQ (ORCPT ); Sun, 3 May 2020 11:21:16 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:34101 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728699AbgECPVP (ORCPT ); Sun, 3 May 2020 11:21:15 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7X31HqzfV; Sun, 3 May 2020 17:21:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519272; bh=X6di/kZ9JXtfx1MiBhjtRiHxgwlcVR2sOcyLvmd+Kuk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=iJkQy5WjomYB9rOwyo93wOUgoSQnHTuwg9EeOBxUThjQ3uVn45QuVMor/q2XrucnT TrQuLdTHTLC5nIO1NkMou8t48udmThxM3KQSz877MrKCBOKTZdLA4tj8+fGTFF2JFq b17jmceveqZZT03PfPz2xYNvvQJiIY5S8JaMrZLSeDKXVip31hiNiDJftB63LsqebX GCh2hNtKEWTYeP8jPsbJ7pCAkqFMd45MzY7bH5MpSkADff0N9UfKOFp5PJIfQ2QBrK NN28r18PEa/iCOxy7/0+pbHebZ36O62qFaeJN3EqWlTu4dHU9DnYXBO1tjDQTyHrXy As/FvQxWBabQQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:12 +0200 Message-Id: <5c8e8f4c5a7fc2cecb62342f9a964f69f3fde7ae.1588517058.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 06/11] power: bq25890: update state on property read MIME-Version: 1.0 To: Rob Herring , Sebastian Reichel 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 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 Sun May 3 15:21:12 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: 212150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B645C28CBC for ; Sun, 3 May 2020 15:21:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DC1D20836 for ; Sun, 3 May 2020 15:21:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="AEeTte93" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728842AbgECPVl (ORCPT ); Sun, 3 May 2020 11:21:41 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:27795 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728706AbgECPVP (ORCPT ); Sun, 3 May 2020 11:21:15 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7X6YLPzrB; Sun, 3 May 2020 17:21:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519273; bh=CtdnXaW3M9J6/3+oqZVerhtAMCemduwcslAGnqFReTw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=AEeTte93WKS/0qvl8ztsPhc0rzYLe3cAQXqzsiWa3GE8ChbGHXHAheLr8MGpCupwe wFbfobROysFQ7hb9vmTF/btBWTQZrMD4feNxBJwf8Noecbcvkl59DVbUZXaidcmt5d L4ENHvR+wSi4TrEP9j54sCI26BCBbAjYAAskbjl5caLckSg2uEPvhFus1QTcXPhL5y v5u2V3MkiSAYTu9QssmP+fnq07SqCQzEH0U/LjYo8yb5j8BJb6euuBoUeIOubXGJ4c KMHS1F7k6WWWE/IzXONciD3JM55NIg9VUnHoW4duXmioXREXF7jczyFE8OvPSQcs3y F/3Q84C9k0FGQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:12 +0200 Message-Id: <9b3bd77de9cfef8af8f8ab76270b46599f9e5ab1.1588517058.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 07/11] power: bq25890: implement CHARGE_TYPE property MIME-Version: 1.0 To: Rob Herring , Sebastian Reichel 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 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 Sun May 3 15:21:13 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: 212151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 227C5C47256 for ; Sun, 3 May 2020 15:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E938F2495E for ; Sun, 3 May 2020 15:21:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="XdOrHPWZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728786AbgECPVT (ORCPT ); Sun, 3 May 2020 11:21:19 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:44073 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728731AbgECPVR (ORCPT ); Sun, 3 May 2020 11:21:17 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 49FV7Y5Y3YzGj; Sun, 3 May 2020 17:21:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1588519273; bh=gRqyNiKmpXtCcJah85qRJb4ZmdxMMi1xeLY32RUkzmw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=XdOrHPWZRiIUVwKr8xqvyDxjKdLqwZ+yKi0xARn1bSUANXrFnGLH5Csiov+g3DrhB mqlqKgdQltrnzTA4OmGXpVB8iUdMMoyoEDvykwEObBmVmdiC2J+qZVtg4La4NFpMNu VLgXt7D2+x8NMdzNHVjSFICQULOmeoHesXIeOtxlIKMCxDrQJ/0+RhvacfkL7qctsU +9eEmFoRZNSPCnU4q/kR7mg5yph3cQClBotymVBl1QDYzx0j124ncNvpX+Mb+nae2P ZZIEptvTnKe33SoYloW7t/fa6B2ymTIHTvtAVbIkg1Y3HdVnsz949//5PNj41sXDl8 CAajXGp1bvnrw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at mail Date: Sun, 03 May 2020 17:21:13 +0200 Message-Id: <48d71a9b286e688ce8155449f62dc8fe0da39f17.1588517058.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v2 09/11] power: bq25890: implement INPUT_CURRENT_LIMIT property MIME-Version: 1.0 To: Rob Herring , Sebastian Reichel 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 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, };