public inbox for platform-driver-x86@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Maximilian Luz <luzmaximilian@gmail.com>,
	Mark Gross <markgross@kernel.org>,
	Andy Shevchenko <andy@kernel.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>
Subject: Re: [PATCH] surface: surface3_power: Fix battery readings on batteries with a serial no
Date: Thu, 24 Feb 2022 11:57:48 +0100	[thread overview]
Message-ID: <a6968627-687c-9627-acdb-bc2ff4841b76@redhat.com> (raw)
In-Reply-To: <CAO-hwJ+MAjqnBXOWruEoEduxMwoTkJtDFoBc9FRsmZoG+WZfiQ@mail.gmail.com>

Hi,

On 2/24/22 11:55, Benjamin Tissoires wrote:
> On Thu, Feb 24, 2022 at 11:19 AM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> 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.
>>
>> Fixes: b1f81b496b0d ("platform/x86: surface3_power: MSHW0011 rev-eng implementation")
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> 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 ?


> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Thanks.

Regards,

Hans


>> ---
>>  drivers/platform/surface/surface3_power.c | 13 ++++++++++---
>>  1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/platform/surface/surface3_power.c b/drivers/platform/surface/surface3_power.c
>> index abac3eec565e..b283bc9bb5fd 100644
>> --- a/drivers/platform/surface/surface3_power.c
>> +++ b/drivers/platform/surface/surface3_power.c
>> @@ -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
>>
> 


  reply	other threads:[~2022-02-24 10:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 10:18 [PATCH] surface: surface3_power: Fix battery readings on batteries with a serial no Hans de Goede
2022-02-24 10:55 ` Benjamin Tissoires
2022-02-24 10:57   ` Hans de Goede [this message]
2022-02-24 11:00     ` Benjamin Tissoires
2022-02-24 10:55 ` Andy Shevchenko
2022-02-24 10:56   ` Hans de Goede
2022-02-24 12:35 ` Maximilian Luz
2022-02-24 12:50   ` Hans de Goede

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=a6968627-687c-9627-acdb-bc2ff4841b76@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andy@kernel.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=luzmaximilian@gmail.com \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox