Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2073825ybp; Thu, 10 Oct 2019 01:42:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsaP5kBm1PqTLgd9ct3LeVZz4fWya3IbgP21P87kZOYUk7J4Wz0HoYBw/Mm14uuLTG4Pfa X-Received: by 2002:a17:906:3488:: with SMTP id g8mr6848905ejb.162.1570696960822; Thu, 10 Oct 2019 01:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570696960; cv=none; d=google.com; s=arc-20160816; b=QlfytdC4dOpL3ryyM4tuS/DwkYKXKUyL02D4dU1GD0bcTpYg+2ixN9OvkeLvigzTC+ 7+NDQ1R4E8Scx91VRLcgoAMfWgt+rHooFIUK1bOHyzwPSKLqvC736kDZO32CxvgUphTW Wh+EV0Ystv8EDIS2ARVNbFl+RTjhz9Qdf/Jtm8mIjTx3U4TKgycoiL/g1apKeJ8kvOFR By+wLFHxpMBlL8V2Ri+cyv6dzL0eCfgbKJDdMUuwt/wotyyTuypuxz+wudlQx5JQ+z6E Z0GnWO8KVS1hUPxbSkEyucgOfrb7U8MoZ7srgdeezJdmZL0xPG6sX/IFKPVXrl0Wm7aY O6Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IJ8o/F1i3YhY01yBUhUlWb9GkrJe0NpcxBUfYjXLg0U=; b=FfSokqKTH2/eXxyRs3nDWmpwG1YXZrpBq0gxQEmlYobokLAytwL2t1U9K5qGX/b/tZ PSQqC09LMPSW1KOXvJEgObo3gN86AtgM9pUOVvMu/1MzO/GqXO4pr8EMifxNZDzEva5Z zpMu+gmE5HPBORrP6LCZTMJBjheVUiOPAQRJqRtnnmjW415sOmRa8uWJYtNW+mNa8TFk ydWBPpaeFoP1N4pR+fF4ZHfTmXMdS8K7zRXQ8dMKac6WapglTIogXd+z378hqpO4s1XP c2GuZqdRgaphlCIoXtaDno6yeN/gSnCNnPXwSNO7N95hqwWn5wVRfMGFpb47ma20q0ws CYxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g2cOgXK4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si2718135ejr.416.2019.10.10.01.42.17; Thu, 10 Oct 2019 01:42:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g2cOgXK4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387914AbfJJIji (ORCPT + 99 others); Thu, 10 Oct 2019 04:39:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:43256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387908AbfJJIjg (ORCPT ); Thu, 10 Oct 2019 04:39:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1FCD320B7C; Thu, 10 Oct 2019 08:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696775; bh=6tbXvVaKRk6fxxefrdGvDY9Lbd+z9PQqGTiTVs0NcvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g2cOgXK4GmO3f5ohkGPOtpoZafhgSPnAMp/7ivsAm+HMoBmMvIJK/wPIPIcNBE1B1 9B2cEExgYwl6tukXqWus4g2otupYfYR/zG60ogrqJtBwkRUmFBoBkMLPXT/YM6j1kC qTEaJHVyI0hxeWxY7pZUw3s/+L1NEJYaBGCETcJ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Nosthoff , Brian Norris , Sebastian Reichel Subject: [PATCH 5.3 049/148] power: supply: sbs-battery: only return health when battery present Date: Thu, 10 Oct 2019 10:35:10 +0200 Message-Id: <20191010083614.117013387@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Nosthoff commit fe55e770327363304c4111423e6f7ff3c650136d upstream. when the battery is set to sbs-mode and no gpio detection is enabled "health" is always returning a value even when the battery is not present. All other fields return "not present". This leads to a scenario where the driver is constantly switching between "present" and "not present" state. This generates a lot of constant traffic on the i2c. This commit changes the response of "health" to an error when the battery is not responding leading to a consistent "not present" state. Fixes: 76b16f4cdfb8 ("power: supply: sbs-battery: don't assume MANUFACTURER_DATA formats") Cc: Signed-off-by: Michael Nosthoff Reviewed-by: Brian Norris Tested-by: Brian Norris Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/supply/sbs-battery.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -314,17 +314,22 @@ static int sbs_get_battery_presence_and_ { int ret; - if (psp == POWER_SUPPLY_PROP_PRESENT) { - /* Dummy command; if it succeeds, battery is present. */ - ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); - if (ret < 0) - val->intval = 0; /* battery disconnected */ - else - val->intval = 1; /* battery present */ - } else { /* POWER_SUPPLY_PROP_HEALTH */ + /* Dummy command; if it succeeds, battery is present. */ + ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); + + if (ret < 0) { /* battery not present*/ + if (psp == POWER_SUPPLY_PROP_PRESENT) { + val->intval = 0; + return 0; + } + return ret; + } + + if (psp == POWER_SUPPLY_PROP_PRESENT) + val->intval = 1; /* battery present */ + else /* POWER_SUPPLY_PROP_HEALTH */ /* SBS spec doesn't have a general health command. */ val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; - } return 0; } @@ -626,6 +631,8 @@ static int sbs_get_property(struct power else ret = sbs_get_battery_presence_and_health(client, psp, val); + + /* this can only be true if no gpio is used */ if (psp == POWER_SUPPLY_PROP_PRESENT) return 0; break;