Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1062159pxa; Wed, 12 Aug 2020 22:27:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoVP1L4Lk5+EjLSmTV9pMGnOk4RrRChOEMGISvENO2tBivbNzZtYSrDXvl8mXX7LAcG3Db X-Received: by 2002:aa7:d8d7:: with SMTP id k23mr3261875eds.54.1597296464543; Wed, 12 Aug 2020 22:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597296464; cv=none; d=google.com; s=arc-20160816; b=abVTB3ioy4x95tE+yU0rZxfrhBhdCX1MOAZbgDWb6fCw7fKGJi5PIy0hZ7nBwuKybO Wsofp8M73WuOMmgpcIubugg4wRaBPeArRIQne+6oy1L1mofA8gN5F+waWnUT7d6qGCnk KjgVapjgrClyKakfpNYi+aA6cdYcO0sl67LS8IBAi1am5T1fyY20zo/tnB8e8o6/Xul0 dbqLVgfXL9tS2Y2bXkHmRdQC80CetVKZGJqrowjJRBydjCvyEpxq+5y91WNKAT1gm7Te Ui8Jr6kPGJfwEk/sPtf0codi0UlTwVgKGVx2ULhaB4U7FPYdG21ULNolKFJqgzP7d34V 4q5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1rCJ4q+KoNSXFkFuWqVDiKXpOMoV1SjKATNbbYf89MU=; b=ZVpxiAJPxL7PjZe44wKeyDbHiFUYdKuIqEN4upR86Dpt6dZHOSBqsgU+CA0zgOlaUJ 9c3RxytZVp6d/EUzV3XDiSu3IVoGPyenzv9+Snna7WEl3gtZRfaqnOipmo9cu1V1Bf8/ d8C8jf4TBZ8l+t4GR7Ov8vOSWAWlEwGmE5WZx3eSLyk+f2nhFoJbTkvS0OkZn6WQbbBy Vnzxt0zkT92D+Y1v0INelRiFxBlCC2PbXnaRKDON+kYC1GoetoFqNqkZXeCaC0NOFypY H3XhxEMyfJKjeIQBgDQzZz65j9qpYKlzz5cSHHPPK1UY19KfQdkMre7KjJFf7M2Tc/Rw Q4jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nERanXOE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lt22si2504976ejb.376.2020.08.12.22.27.21; Wed, 12 Aug 2020 22:27:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nERanXOE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbgHMF01 (ORCPT + 99 others); Thu, 13 Aug 2020 01:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725891AbgHMF00 (ORCPT ); Thu, 13 Aug 2020 01:26:26 -0400 Received: from mail-ua1-x943.google.com (mail-ua1-x943.google.com [IPv6:2607:f8b0:4864:20::943]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB5EEC061757 for ; Wed, 12 Aug 2020 22:26:25 -0700 (PDT) Received: by mail-ua1-x943.google.com with SMTP id v20so1293336ual.4 for ; Wed, 12 Aug 2020 22:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1rCJ4q+KoNSXFkFuWqVDiKXpOMoV1SjKATNbbYf89MU=; b=nERanXOEelRjMIEt3IHqFWvSp9Zgn371nAANhRijyP8pGdoXeNmNMvcYL3i+6BS4TA stwfvcRTCqqq+ULufLYkL7IKvKAxxFD7LFbv98VIKPsP79Oovh7PW5IAa/zuhzrY+IJu tm1REjtH6S62Grx3JmA1usq0/EZBDxrsaqIaY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1rCJ4q+KoNSXFkFuWqVDiKXpOMoV1SjKATNbbYf89MU=; b=jLdVDtpYZUZf0sPAIP6PB9HhNfVflZP2mrO774rrFMlUwzNDSbi3uHSl2dcwDby+Zp Up4tikCR/2RX4nGYlxgm3FBfZxfC9iR5FOkwrOrZ1ZSlZBHqrwIeDg+GY6zEaTntUh18 iWNPKeLzki1cgd5E7RghQi4dbayBm2iE2V2xGDERE9cd7PXE0+guGDkjqb41H3ym3eQO u2N1NXuWuaWuZAZG+Baatlm01J48iZZ7XRW2Cu482NXj8UDYfrufBpxWyblwXjWO3Eyo S6vk7dqsUr6mwqXsBW6U4/iuG5jBP143h+u2mujk3XjGDv5goW6Ui5KvsF6eMXoh4L1P DBxw== X-Gm-Message-State: AOAM531dSv+iNRSbpgnwTGv42MMxe+4y9XNg++BrKinpRVYXVAMYXNao hKCuYutM6aJZVBlJBSiJv55xN+U7/dHnfj4VDZDwnA== X-Received: by 2002:ab0:1696:: with SMTP id e22mr1910356uaf.1.1597296384671; Wed, 12 Aug 2020 22:26:24 -0700 (PDT) MIME-Version: 1.0 References: <0200811065307.2094930-1-ikjn@chromium.org> <20200813051008.3461515-1-ikjn@chromium.org> <20200813051008.3461515-3-ikjn@chromium.org> In-Reply-To: <20200813051008.3461515-3-ikjn@chromium.org> From: Nicolas Boichat Date: Thu, 13 Aug 2020 13:26:09 +0800 Message-ID: Subject: Re: [PATCH v3 2/2] power: supply: sbs-battery: don't assume i2c errors as battery disconnect To: Ikjoon Jang Cc: Sebastian Reichel , "open list:THERMAL" , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13, 2020 at 1:11 PM Ikjoon Jang wrote: > > Current sbs-battery considers all smbus errors as disconnection events > when battery-detect pin isn't supplied, and restored to present state back > when any successful transaction is made. > > This can lead to unlimited state changes between present and !present > when one unsupported command was requested and other following commands > were successful, e.g. udev rules tries to read multiple properties. > > This patch checks battery presence by reading known good command to > check battery existence. > > Signed-off-by: Ikjoon Jang Looks good now, AFAICT. Thanks! Reviewed-by: Nicolas Boichat > --- > drivers/power/supply/sbs-battery.c | 25 +++++++++++++++++-------- > 1 file changed, 17 insertions(+), 8 deletions(-) > > diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c > index 6acb4ea25d2a..2e32fde04628 100644 > --- a/drivers/power/supply/sbs-battery.c > +++ b/drivers/power/supply/sbs-battery.c > @@ -878,10 +878,17 @@ static int sbs_get_property(struct power_supply *psy, > if (!chip->enable_detection) > goto done; > > - if (!chip->gpio_detect && > - chip->is_present != (ret >= 0)) { > - sbs_update_presence(chip, (ret >= 0)); > - power_supply_changed(chip->power_supply); > + if (!chip->gpio_detect && chip->is_present != (ret >= 0)) { > + bool old_present = chip->is_present; > + union power_supply_propval val; > + > + ret = sbs_get_battery_presence_and_health( > + client, POWER_SUPPLY_PROP_PRESENT, &val); > + > + sbs_update_presence(chip, !ret && val.intval); > + > + if (old_present != chip->is_present) > + power_supply_changed(chip->power_supply); > } > > done: > @@ -1067,11 +1074,13 @@ static int sbs_probe(struct i2c_client *client) > * to the battery. > */ > if (!(force_load || chip->gpio_detect)) { > - rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); > + union power_supply_propval val; > > - if (rc < 0) { > - dev_err(&client->dev, "%s: Failed to get device status\n", > - __func__); > + rc = sbs_get_battery_presence_and_health( > + client, POWER_SUPPLY_PROP_PRESENT, &val); > + if (rc < 0 || !val.intval) { > + dev_err(&client->dev, "Failed to get present status\n"); > + rc = -ENODEV; > goto exit_psupply; > } > } > -- > 2.28.0.236.gb10cc79966-goog >