Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2087509ybp; Thu, 10 Oct 2019 01:59:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYk+x2ECpIAwCPk4HSj8AT06b3nWsSRZPgiG3ceT/SKL7Rl16J21F4ph3xv2PU72N6+95M X-Received: by 2002:aa7:d3d3:: with SMTP id o19mr6890046edr.230.1570697948951; Thu, 10 Oct 2019 01:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697948; cv=none; d=google.com; s=arc-20160816; b=NLUoTlwFmLecuYe9gYuE1sE3MjO2cYO+S3jolBvNTsCxAv+yTI/k0AcgswTQLC4dVx Y3XUi4uQ5wQYH21yhze7vdZD6CAb9zB6iKUuFkizl4LV4JIoCYxZcDYDSqWutAFyy83g sy8IvU9WnZrFy88ym7Wyrpprk+wkDer5XW82BFynNGhSlpQIR8IQVsZMWY6xN/M5gRPH eu5WCSTJCu8f4uIKOetTArR8GTC1zHGcmt0J9EQm6xl30oJA2P4ouA9BkjvDqt+/MgUa e8dmJnNPHYaTp0Tg9nWi3qccLZueIYiXy66Dqy8yVmdTTay4YLC0h2xrg2VJyLd8wJek BhFA== 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=enVSpCW5IAV/aD395Csw7K9FVUivvF3mjyCLic5d+HU=; b=A0Oz5adUO2pakM+X6OxDtvtwpLAvdBx6n6mEX6UQMjupVjLop2/8uOWM3nLHXl8KsL Kvok5wO2lWfQRkuz8K6Jlfgq3TN5My1IjLgVo5+0R6LSg8hrB3c7bicv7w52n2mqBs3L /8MCpNJtuGLxWVm3dpqE2Wh1RE9aoBLU/+Y3H4Hv07zG/ahyr3KambG/xuR+0zBQ6J+G bLtBmdkS3g+0uON1J5yroBd/0tyt3fIL6F5svXjYBT0EMfGBZE6IBNEQJpk1O4GwB2Ke 8mxhHvTTE5+UWRDNao/2S/+sPyRGsxYAuOEUwFnQSrUsh5kSiRnE6O77rdiMFBqefrxh EIvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2JF/OY2S"; 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 w12si2822542ejb.303.2019.10.10.01.58.46; Thu, 10 Oct 2019 01:59:08 -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="2JF/OY2S"; 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 S2389083AbfJJI6k (ORCPT + 99 others); Thu, 10 Oct 2019 04:58:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:51106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387710AbfJJIpa (ORCPT ); Thu, 10 Oct 2019 04:45:30 -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 AF51021A4A; Thu, 10 Oct 2019 08:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697130; bh=WfoyCfdIo3r6xcNuaQI/cVJPvfzJANcGm0c2yQ8l61M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2JF/OY2SJvMtYkMekangTKcmu5IFr62atZz7dA3MshOdtmAxnRFAzJKBwW3X5jt9X wPg1jZY1Q0Xi/95QwFSubiyhLTvf+bPwfiqGzaXLXuLU7dImaodjWlSZZbxKX2v2xq poGfMsV2mxvHyJQw91uONgfw6Ev+poNAjQBP1MW4= 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 4.19 029/114] power: supply: sbs-battery: only return health when battery present Date: Thu, 10 Oct 2019 10:35:36 +0200 Message-Id: <20191010083559.078712124@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083544.711104709@linuxfoundation.org> References: <20191010083544.711104709@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 @@ -323,17 +323,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; } @@ -635,6 +640,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;