From patchwork Tue Jul 11 09:43:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9834339 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 7577060393 for ; Tue, 11 Jul 2017 09:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 686BA283D0 for ; Tue, 11 Jul 2017 09:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CFB32842B; Tue, 11 Jul 2017 09:43:52 +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 08878283DA for ; Tue, 11 Jul 2017 09:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753195AbdGKJnv (ORCPT ); Tue, 11 Jul 2017 05:43:51 -0400 Received: from anchovy3.45ru.net.au ([203.30.46.155]:45850 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753105AbdGKJnt (ORCPT ); Tue, 11 Jul 2017 05:43:49 -0400 Received: (qmail 8799 invoked by uid 5089); 11 Jul 2017 09:43:46 -0000 Received: by simscan 1.2.0 ppid: 8740, pid: 8742, t: 0.0259s 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 anchovy2.45ru.net.au with ESMTPA; 11 Jul 2017 09:43:46 -0000 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id 3D3A4304BFCE9; Tue, 11 Jul 2017 17:43:46 +0800 (AWST) From: Phil Reid To: sre@kernel.org, preid@electromag.com.au, linux-pm@vger.kernel.org, posted@heine.so Subject: [PATCH v2 3/3] power: supply: sbs-battery: Add delay when changing capacity mode bit Date: Tue, 11 Jul 2017 17:43:43 +0800 Message-Id: <1499766223-130934-4-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499766223-130934-1-git-send-email-preid@electromag.com.au> References: <1499766223-130934-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 Tested-by: Michael Heinemann --- 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; }