From patchwork Mon Jul 10 06:23:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9832317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62F0060318 for ; Mon, 10 Jul 2017 06:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5907228419 for ; Mon, 10 Jul 2017 06:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E13528434; Mon, 10 Jul 2017 06:30:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F04FD28419 for ; Mon, 10 Jul 2017 06:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752225AbdGJGaO (ORCPT ); Mon, 10 Jul 2017 02:30:14 -0400 Received: from anchovy1.45ru.net.au ([203.30.46.145]:51831 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751161AbdGJGaO (ORCPT ); Mon, 10 Jul 2017 02:30:14 -0400 Received: (qmail 7599 invoked by uid 5089); 10 Jul 2017 06:23:27 -0000 Received: by simscan 1.2.0 ppid: 7553, pid: 7554, t: 0.0331s scanners: regex: 1.2.0 attach: 1.2.0 clamav: 0.88.3/m:40/d:1950 X-RBL: $rbltext Received: from unknown (HELO preid-centos7.electromag.com.au) (preid@electromag.com.au@203.59.230.133) by anchovy1.45ru.net.au with ESMTPA; 10 Jul 2017 06:23:26 -0000 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id 2DD83301EBAB7; Mon, 10 Jul 2017 14:23:25 +0800 (AWST) From: Phil Reid To: sre@kernel.org, preid@electromag.com.au, linux-pm@vger.kernel.org, posted@heine.so Subject: [PATCH 4/4] power: supply: sbs-battery: Don't reset mode in get_battery_capacity Date: Mon, 10 Jul 2017 14:23:20 +0800 Message-Id: <1499667800-69055-5-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499667800-69055-1-git-send-email-preid@electromag.com.au> References: <1499667800-69055-1-git-send-email-preid@electromag.com.au> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There seems little point in resetting the capacity mode bit when reading a capacity register that is affected by this bit. The next call to the register read will set the bit if it's not in the correct mode. Signed-off-by: Phil Reid --- drivers/power/supply/sbs-battery.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 3473b45..441a576 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -491,22 +491,19 @@ static void sbs_unit_adjustment(struct i2c_client *client, } } -static enum sbs_battery_mode sbs_set_battery_mode(struct i2c_client *client, +static int sbs_set_battery_mode(struct i2c_client *client, enum sbs_battery_mode mode) { - int ret, original_val; + int ret; - original_val = sbs_read_word_data(client, BATTERY_MODE_OFFSET); - if (original_val < 0) - return original_val; + ret = sbs_read_word_data(client, BATTERY_MODE_OFFSET); + if (ret < 0) + return ret; - if ((original_val & BATTERY_MODE_MASK) == mode) - return mode; + if ((ret & BATTERY_MODE_MASK) == mode) + return 0; - if (mode == BATTERY_MODE_AMPS) - ret = original_val & ~BATTERY_MODE_MASK; - else - ret = original_val | BATTERY_MODE_MASK; + ret = (ret & ~BATTERY_MODE_MASK) | mode; ret = sbs_write_word_data(client, BATTERY_MODE_OFFSET, ret); if (ret < 0) @@ -514,7 +511,7 @@ static enum sbs_battery_mode sbs_set_battery_mode(struct i2c_client *client, usleep_range(1000, 2000); - return original_val & BATTERY_MODE_MASK; + return 0; } static int sbs_get_battery_capacity(struct i2c_client *client, @@ -527,9 +524,9 @@ static int sbs_get_battery_capacity(struct i2c_client *client, if (power_supply_is_amp_property(psp)) mode = BATTERY_MODE_AMPS; - mode = sbs_set_battery_mode(client, mode); - if (mode < 0) - return mode; + ret = sbs_set_battery_mode(client, mode); + if (ret < 0) + return ret; ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); if (ret < 0) @@ -542,10 +539,6 @@ static int sbs_get_battery_capacity(struct i2c_client *client, } else val->intval = ret; - ret = sbs_set_battery_mode(client, mode); - if (ret < 0) - return ret; - return 0; }