All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Reid <preid@electromag.com.au>
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	[thread overview]
Message-ID: <1499667800-69055-5-git-send-email-preid@electromag.com.au> (raw)
In-Reply-To: <1499667800-69055-1-git-send-email-preid@electromag.com.au>

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 <preid@electromag.com.au>
---
 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;
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2017-07-10  6:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10  6:23 [PATCH 0/4] power: supply: sbs-battery: Add delay when changing capacity mode Phil Reid
2017-07-10  6:23 ` [PATCH 1/4] power: supply: sbs-battery: Remove FSF mailing address from comments Phil Reid
2017-07-10  6:23 ` [PATCH 2/4] power: supply: sbs-battery: sort includes Phil Reid
2017-07-11  8:37   ` Michael Heinemann
2017-07-11  8:47     ` Phil Reid
2017-07-10  6:23 ` [PATCH 3/4] power: supply: sbs-battery: Add delay when changing capacity mode bit Phil Reid
2017-07-10  6:23 ` Phil Reid [this message]
2017-07-11  4:57   ` [PATCH 4/4] power: supply: sbs-battery: Don't reset mode in get_battery_capacity Phil Reid
2017-07-11 10:03     ` Michael Heinemann

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=1499667800-69055-5-git-send-email-preid@electromag.com.au \
    --to=preid@electromag.com.au \
    --cc=linux-pm@vger.kernel.org \
    --cc=posted@heine.so \
    --cc=sre@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.