Skip to content

Commit a184f4d

Browse files
jwrdegoedegregkh
authored andcommitted
surface: surface3_power: Fix battery readings on batteries without a serial number
commit 21d90aa upstream. The battery on the 2nd hand Surface 3 which I recently bought appears to not have a serial number programmed in. This results in any I2C reads from the registers containing the serial number 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 number and continue with an empty serial number to fix this. Fixes: b1f81b4 ("platform/x86: surface3_power: MSHW0011 rev-eng implementation") BugLink: linux-surface/linux-surface#608 Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20220224101848.7219-1-hdegoede@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 91f56a8 commit a184f4d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎drivers/platform/x86/surface3_power.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,21 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix)
233233
}
234234
bix->last_full_charg_capacity = ret;
235235

236-
/* get serial number */
236+
/*
237+
* Get serial number, on some devices (with unofficial replacement
238+
* battery?) reading any of the serial number range addresses gets
239+
* nacked in this case just leave the serial number empty.
240+
*/
237241
ret = i2c_smbus_read_i2c_block_data(client, MSHW0011_BAT0_REG_SERIAL_NO,
238242
sizeof(buf), buf);
239-
if (ret != sizeof(buf)) {
243+
if (ret == -EREMOTEIO) {
244+
/* no serial number available */
245+
} else if (ret != sizeof(buf)) {
240246
dev_err(&client->dev, "Error reading serial no: %d\n", ret);
241247
return ret;
248+
} else {
249+
snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
242250
}
243-
snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
244251

245252
/* get cycle count */
246253
ret = i2c_smbus_read_word_data(client, MSHW0011_BAT0_REG_CYCLE_CNT);

0 commit comments

Comments
 (0)