From patchwork Mon Jul 10 06:23:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9832315 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 66D7060318 for ; Mon, 10 Jul 2017 06:30:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D2B528419 for ; Mon, 10 Jul 2017 06:30:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 505FB28434; Mon, 10 Jul 2017 06:30:12 +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 F31D628419 for ; Mon, 10 Jul 2017 06:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751835AbdGJGaL (ORCPT ); Mon, 10 Jul 2017 02:30:11 -0400 Received: from anchovy1.45ru.net.au ([203.30.46.145]:51832 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751161AbdGJGaL (ORCPT ); Mon, 10 Jul 2017 02:30:11 -0400 Received: (qmail 7598 invoked by uid 5089); 10 Jul 2017 06:23:27 -0000 Received: by simscan 1.2.0 ppid: 7552, pid: 7555, t: 0.0296s 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 28FB9301EBAB6; 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 3/4] power: supply: sbs-battery: Add delay when changing capacity mode bit Date: Mon, 10 Jul 2017 14:23:19 +0800 Message-Id: <1499667800-69055-4-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 At least with the Inspired Energy compatible batteries a delay is required after setting the capacity mode bit from amp to watts or the reverse. Setting the bit and then immediately pooling the status register results in an unknown error being returned in the register. Add the delay results in and ok status being return. This was also seen when reading the charge and energy registers where the wrong value was returned for the requested mode. Signed-off-by: Phil Reid --- drivers/power/supply/sbs-battery.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 4594ed1..3473b45 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -14,6 +14,7 @@ * more details. */ +#include #include #include #include @@ -511,6 +512,8 @@ static enum sbs_battery_mode sbs_set_battery_mode(struct i2c_client *client, if (ret < 0) return ret; + usleep_range(1000, 2000); + return original_val & BATTERY_MODE_MASK; }