* [PATCH] sbs-battery: make writes to ManufacturerAccess optional
@ 2016-09-09 2:10 Guenter Roeck
2016-09-19 19:02 ` Sebastian Reichel
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2016-09-09 2:10 UTC (permalink / raw)
To: Sebastian Reichel
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm, linux-kernel,
Guenter Roeck, Brian Norris
According to the Smart Battery Data Specification, the use
of ManufacturerAcess (register 0x0) is implementation-defined.
It appears that some batteries use writes to this register
in order to implement certain functionality, but others may
simply NAK all writes to it. As a result, write failures to
ManufacturerAccess should not be used as an indicator of
battery presence, nor as a failure to enter sleep mode.
The failed write access was seen with SANYO AP13J3K.
Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/power/sbs-battery.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 768b9fcb58ea..5621b8c048cf 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -313,21 +313,22 @@ static int sbs_get_battery_presence_and_health(
return ret;
}
- /* Write to ManufacturerAccess with
- * ManufacturerAccess command and then
- * read the status */
- ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
- MANUFACTURER_ACCESS_STATUS);
+ /*
+ * Write to ManufacturerAccess with ManufacturerAccess command
+ * and then read the status. Do not check for error on the write
+ * since not all batteries implement write access to this command,
+ * while others mandate it.
+ */
+ sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
+ MANUFACTURER_ACCESS_STATUS);
+
+ ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr);
if (ret < 0) {
if (psp == POWER_SUPPLY_PROP_PRESENT)
val->intval = 0; /* battery removed */
return ret;
}
- ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr);
- if (ret < 0)
- return ret;
-
if (ret < sbs_data[REG_MANUFACTURER_DATA].min_value ||
ret > sbs_data[REG_MANUFACTURER_DATA].max_value) {
val->intval = 0;
@@ -950,16 +951,16 @@ static int sbs_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct sbs_info *chip = i2c_get_clientdata(client);
- s32 ret;
if (chip->poll_time > 0)
cancel_delayed_work_sync(&chip->work);
- /* write to manufacturer access with sleep command */
- ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
+ /*
+ * Write to manufacturer access with sleep command.
+ * Support is manufacturer dependend, so ignore errors.
+ */
+ sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
MANUFACTURER_ACCESS_SLEEP);
- if (chip->is_present && ret < 0)
- return ret;
return 0;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sbs-battery: make writes to ManufacturerAccess optional
2016-09-09 2:10 [PATCH] sbs-battery: make writes to ManufacturerAccess optional Guenter Roeck
@ 2016-09-19 19:02 ` Sebastian Reichel
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2016-09-19 19:02 UTC (permalink / raw)
To: Guenter Roeck
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm, linux-kernel,
Brian Norris
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
Hi,
On Thu, Sep 08, 2016 at 07:10:00PM -0700, Guenter Roeck wrote:
> According to the Smart Battery Data Specification, the use
> of ManufacturerAcess (register 0x0) is implementation-defined.
> It appears that some batteries use writes to this register
> in order to implement certain functionality, but others may
> simply NAK all writes to it. As a result, write failures to
> ManufacturerAccess should not be used as an indicator of
> battery presence, nor as a failure to enter sleep mode.
>
> The failed write access was seen with SANYO AP13J3K.
>
> Cc: Brian Norris <briannorris@chromium.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Thanks, queued.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] sbs-battery: make writes to ManufacturerAccess optional
@ 2013-12-27 1:06 Andrew Bresticker
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Bresticker @ 2013-12-27 1:06 UTC (permalink / raw)
To: Anton Vorontsov, David Woodhouse, Rhyland Klein
Cc: linux-kernel, Andrew Bresticker
According to the Smart Battery Data Specification, the use
of ManufacturerAcess (register 0x0) is implementation-defined.
It appears that some batteries use writes to this register
in order to implement certain functionality, but others may
simply NAK all writes to it. As a result, write failures to
ManufacturerAccess should not be used as an indicator of battery
presence.
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
---
drivers/power/sbs-battery.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index b5f2a76..1240a9c 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -228,13 +228,8 @@ static int sbs_get_battery_presence_and_health(
/* Write to ManufacturerAccess with
* ManufacturerAccess command and then
* read the status */
- ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
+ sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
MANUFACTURER_ACCESS_STATUS);
- if (ret < 0) {
- if (psp == POWER_SUPPLY_PROP_PRESENT)
- val->intval = 0; /* battery removed */
- return ret;
- }
ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr);
if (ret < 0)
@@ -827,16 +822,13 @@ static int sbs_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct sbs_info *chip = i2c_get_clientdata(client);
- s32 ret;
if (chip->poll_time > 0)
cancel_delayed_work_sync(&chip->work);
/* write to manufacturer access with sleep command */
- ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
+ sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr,
MANUFACTURER_ACCESS_SLEEP);
- if (chip->is_present && ret < 0)
- return ret;
return 0;
}
--
1.8.5.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-19 19:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 2:10 [PATCH] sbs-battery: make writes to ManufacturerAccess optional Guenter Roeck
2016-09-19 19:02 ` Sebastian Reichel
-- strict thread matches above, loose matches on Subject: below --
2013-12-27 1:06 Andrew Bresticker
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).