devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Reid <preid@electromag.com.au>
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, preid@electromag.com.au,
	benjamin.tissoires@redhat.com, linux-i2c@vger.kernel.org,
	devicetree@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH v11 10/10] power: supply: sbs-battery: move gpio present detect to sbs_get_property
Date: Thu, 24 Aug 2017 17:31:10 +0800	[thread overview]
Message-ID: <1503567070-115646-11-git-send-email-preid@electromag.com.au> (raw)
In-Reply-To: <1503567070-115646-1-git-send-email-preid@electromag.com.au>

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 <preid@electromag.com.au>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
---
 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:
-- 
1.8.3.1

  parent reply	other threads:[~2017-08-24  9:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24  9:31 [PATCH v11 00/10] Add sbs-manager with smbalert support Phil Reid
2017-08-24  9:31 ` [PATCH v11 01/10] i2c: i2c-smbus: Use threaded irq for smbalert Phil Reid
2017-08-24  9:31 ` [PATCH v11 03/10] i2c: i2c-smbus: add of_i2c_setup_smbus_alert Phil Reid
2017-08-24  9:31 ` [PATCH v11 05/10] i2c: mux: pca954x: call request irq after adding mux segments Phil Reid
     [not found] ` <1503567070-115646-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>
2017-08-24  9:31   ` [PATCH v11 02/10] i2c: i2c-smbus: Move i2c_setup_smbus_alert from i2c-smbus to i2c-core-smbus Phil Reid
     [not found]     ` <1503567070-115646-3-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>
2017-10-29 15:44       ` Wolfram Sang
2017-10-30  4:23         ` Phil Reid
     [not found]           ` <1397131b-c22d-9872-dbe0-9b691553cb9e-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>
2017-11-06 21:36             ` Wolfram Sang
2017-11-07  1:16               ` Phil Reid
2017-11-07  7:22                 ` Wolfram Sang
2017-11-17 12:15                   ` Phil Reid
2017-08-24  9:31   ` [PATCH v11 04/10] i2c: core: call of_i2c_setup_smbus_alert in i2c_register_adapter Phil Reid
2017-08-24  9:31   ` [PATCH v11 06/10] i2c: mux: pca954x: Return error if irq_create_mapping fails Phil Reid
2017-08-24  9:31   ` [PATCH v11 08/10] power: Adds support for Smart Battery System Manager Phil Reid
2017-08-24  9:31 ` [PATCH v11 07/10] Documentation: Add sbs-manager device tree node documentation Phil Reid
2017-08-24  9:31 ` [PATCH v11 09/10] power: supply: sbs-manager: Add alert callback and battery change notification Phil Reid
2017-08-24  9:31 ` Phil Reid [this message]
2017-09-28  7:38 ` [PATCH v11 00/10] Add sbs-manager with smbalert support Phil Reid
     [not found]   ` <66235a12-a209-be89-5bfd-dc69b769cab9-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>
2017-10-28 22:55     ` Wolfram Sang
2017-10-29 14:37       ` Sebastian Reichel
2017-10-29 15:05         ` Wolfram Sang
2017-11-01 22:52       ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1503567070-115646-11-git-send-email-preid@electromag.com.au \
    --to=preid@electromag.com.au \
    --cc=benjamin.tissoires@redhat.com \
    --cc=david.daney@cavium.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=jglauber@cavium.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peda@axentia.se \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).