surface: surface3_power: Fix battery readings on batteries with a serial no
PATCH 1/1 surface: surface3_power: Fix battery readings on batteries with a serial no
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing mshw0011_bix() to fail causing the battery readings to not work at all.
Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/platform/surface/surface3_power.c +10 -3
@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement +* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT );
Signature · 1 line
2.35.1
Quoted 5 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
Quoted 8 lines
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>
LGTM, (and scratching this off my list):
Cheers,
Benjamin
Quoted 36 lines
--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +10
-4@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement +* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT ); --2.35.1
Hi,
Quoted 9 lines · Benjamin Tissoires
Quoted 8 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.
Quoted 7 lines
Quoted 5 lines
Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>LGTM, (and scratching this off my list):
Ah, so I guess this was already a known issue also hit by others ?
Do you have a buglink which I can add to the commit message ?
Quoted 1 line
Reviewed-by Benjamin Tissoires <[email protected]>
Thanks.
Regards,
Hans
Quoted 37 lines
Quoted 36 lines
--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +10
-4@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement +* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT ); --2.35.1
Quoted 16 lines · Hans de Goede
Hi,
Quoted 12 lines · Benjamin Tissoires
Quoted 11 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>LGTM, (and scratching this off my list):
Ah, so I guess this was already a known issue also hit by others ?
Do you have a buglink which I can add to the commit message ?
Oh, no, sorry. The email popped up, and instead of adding it at the end of the TODO list, I spent a few minutes checking it and answering. Sorry for the confusion.
The problem in itself is entirely new to me.
Cheers,
Benjamin
Quoted 49 lines
Quoted 3 lines
Reviewed-by Benjamin Tissoires <[email protected]>Thanks.
Regards,
Hans
Quoted 37 lines
Quoted 36 lines
--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +10
-4@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement +* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT ); --2.35.1
Quoted 10 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Maybe in all cases
serial no --> Serial Number
? This "no" requires to re-read again.
Quoted 12 lines
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +0
-0
drivers/platform/surface/surface3_power.c static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) · line 236
Quoted 6 lines
drivers/platform/surface/surface3_power.c +2
-1@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement
Get
Quoted 21 lines
drivers/platform/surface/surface3_power.c +8
-3+* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT ); --2.35.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.
Quoted 8 lines
Quoted 2 lines
Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Maybe in all cases
serial no --> Serial Number
? This "no" requires to re-read again.
Ack, will fix before merging.
Quoted 14 lines
Quoted 14 lines
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +0
-0@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret;
Quoted 5 lines
drivers/platform/surface/surface3_power.c static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) · line 236
Quoted 3 lines
drivers/platform/surface/surface3_power.c +2
-1-/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement Get
Ack.
Quoted 17 lines
Quoted 17 lines
drivers/platform/surface/surface3_power.c +8
-2+* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);
Quoted 7 lines
Quoted 5 lines
drivers/platform/surface/surface3_power.c +0
-1/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT ); --2.35.1
Regards,
Hans
Quoted 4 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
Quoted 8 lines
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>
Thanks for fixing this! This has been bugging us over at
https://github.com/linux-surface/linux-surface/issues/608.
Quoted 33 lines
--- drivers/platform/surface/surface3_power.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +10
-3@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret; -/* get serial number */ +/* +* get serial number, on some devices (with unofficial replacement +* battery?) reading any of the serial no range addresses gets nacked +* in this case just leave the serial no empty. +*/ ret =i2c_smbus_read_i2c_block_data (client,MSHW0011_BAT0_REG_SERIAL_NO ,sizeof (buf), buf); -if (ret !=sizeof (buf)) { +if (ret == -EREMOTEIO ) { +/* no serial number available */ + }else if (ret !=sizeof (buf)) {dev_err (&client->dev,"Error reading serial no: %d\n" , ret);return ret; + }else { +snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf); } -snprintf (bix->serial,ARRAY_SIZE (bix->serial),"%3pE%6pE" , buf +7 , buf);/* get cycle count */ ret =i2c_smbus_read_word_data (client,MSHW0011_BAT0_REG_CYCLE_CNT );
Hi,
Quoted 11 lines · Maximilian Luz
Quoted 10 lines · Hans de Goede
The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial no programmed in. This results in any I2C reads from the registers containing the serial no failing with an I2C NACK.
This was causing
mshw0011_bix()to fail causing the battery readings to not work at all.Ignore EREMOTEIO (I2C NACK) errors when retrieving the serial no and continue with an empty serial no to fix this.
Quoted 7 lines
Quoted 2 lines
Fixes b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")Signed-off-by Hans de Goede <[email protected]>Thanks for fixing this! This has been bugging us over at
https://github.com/linux-surface/linux-surface/issues/608.Reviewed-by Maximilian Luz <[email protected]>
Thank you, I have merged this into the pdx86/review-hans and /fixes branches now. I've also added a buglink to the commit message.
I'll also take a look at some of the other bugs from:
https://github.com/linux-surface/linux-surface/labels/D%3A%20Surface%203
when I can make some time for this.
Regards,
Hans
Quoted 33 lines
Quoted 32 lines
---
drivers/platform/surface/surface3_power.c| 13 ++++++++++---1 file changed, 10 insertions(+), 3 deletions(-)drivers/platform/surface/surface3_power.c +0
-0@@ -232,14 +232,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) } bix->last_full_charg_capacity = ret;- /* get serial number */
+ /*
+ * get serial number, on some devices (with unofficial replacement + * battery?) reading any of the serial no range addresses gets nacked + * in this case just leave the serial no empty.
+ */
ret =i2c_smbus_read_i2c_block_data(client, MSHW0011_BAT0_REG_SERIAL_NO, sizeof(buf), buf);
- if (ret != sizeof(buf)) {
+ if (ret ==-EREMOTEIO) {
+ /* no serial number available */
+ } else if (ret != sizeof(buf)) {
dev_err(&client->dev, "Error reading serial no: %d\n", ret); return ret;
+ } else {
+snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf); }
-snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf); /* get cycle count */
ret =i2c_smbus_read_word_data(client, MSHW0011_BAT0_REG_CYCLE_CNT);