From patchwork Tue Jul 18 08:19:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9847219 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 5585D60392 for ; Tue, 18 Jul 2017 08:20:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4724D27E63 for ; Tue, 18 Jul 2017 08:20:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BDC628503; Tue, 18 Jul 2017 08:20:19 +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 44646284C7 for ; Tue, 18 Jul 2017 08:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751445AbdGRIUP (ORCPT ); Tue, 18 Jul 2017 04:20:15 -0400 Received: from anchovy2.45ru.net.au ([203.30.46.146]:59968 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751453AbdGRIT6 (ORCPT ); Tue, 18 Jul 2017 04:19:58 -0400 Received: (qmail 13762 invoked by uid 5089); 18 Jul 2017 08:19:56 -0000 Received: by simscan 1.2.0 ppid: 13631, pid: 13633, t: 0.1201s 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 anchovy3.45ru.net.au with ESMTPA; 18 Jul 2017 08:19:55 -0000 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id 1377530376262; Tue, 18 Jul 2017 16:19:50 +0800 (AWST) From: Phil Reid To: wsa@the-dreams.de, robh+dt@kernel.org, mark.rutland@arm.com, sre@kernel.org, jdelvare@suse.com, jglauber@cavium.com, david.daney@cavium.com, peda@axentia.se, benjamin.tissoires@redhat.com, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org Cc: Phil Reid Subject: [PATCH v8 9/9] power: supply: sbs-battery: move gpio present detect to sbs_get_property Date: Tue, 18 Jul 2017 16:19:44 +0800 Message-Id: <1500365984-61404-10-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500365984-61404-1-git-send-email-preid@electromag.com.au> References: <1500365984-61404-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 Currently when a gpio is defined for battery presence it is only used in the sbs_get_battery_presence_and_health function for 2 properties. All other properties currently try to read data form the battery before returning an error if not present. We should know in advance that no data is going to returned. As the driver tries multiple times to access a property, this prevents a lot of smbus accesses, which had a significant effect on device boot-up. As when the device is registered lots of property accesses are attempted during boot. If no gpio is used for presence detection no change in behaviour should occur. Signed-off-by: Phil Reid Reviewed-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index f705945..686e7cb 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -325,16 +325,6 @@ static int sbs_get_battery_presence_and_health( union power_supply_propval *val) { s32 ret; - struct sbs_info *chip = i2c_get_clientdata(client); - - if (psp == POWER_SUPPLY_PROP_PRESENT && chip->gpio_detect) { - ret = gpiod_get_value_cansleep(chip->gpio_detect); - if (ret < 0) - return ret; - val->intval = ret; - chip->is_present = val->intval; - return ret; - } /* * Write to ManufacturerAccess with ManufacturerAccess command @@ -600,6 +590,19 @@ static int sbs_get_property(struct power_supply *psy, struct sbs_info *chip = power_supply_get_drvdata(psy); struct i2c_client *client = chip->client; + if (chip->gpio_detect) { + ret = gpiod_get_value_cansleep(chip->gpio_detect); + if (ret < 0) + return ret; + if (psp == POWER_SUPPLY_PROP_PRESENT) { + val->intval = ret; + chip->is_present = val->intval; + return 0; + } + if (ret == 0) + return -ENODATA; + } + switch (psp) { case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_HEALTH: