Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp434749pxb; Tue, 14 Sep 2021 00:23:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCV01OeBPY9cfWJXgJgHLEHVluhPNAtgMeCGjjpCnvNJayXEWUaglVOMQohsmbx2S+z8hz X-Received: by 2002:a05:6830:2473:: with SMTP id x51mr12964093otr.34.1631604218647; Tue, 14 Sep 2021 00:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631604218; cv=none; d=google.com; s=arc-20160816; b=UjUrnfth/KdzDtyG0Z/QFrM9RnKdVcpxOriLdnxDSP7lQaRF/D8uycfhNUIDvklmM3 zzRXFvb52HXXNkFii1mnqX3kADyxLtwMEAwvJTtGfLccaOflE3mVS4LSfvpFbQNvnYzF CIzu+nqvSGncvoF/xqzcyumFAwEsNb5ltnl0DjNP6Noz1s0lamPTbsZGJyM1yHLnyq9J EHCM1W1xquRvdVSdzh/oHpo8QpX3I53jVpm9cPNE5iQl5PWMTiOPFRP+nTnbB6eC3HOu L+36/ZYE0SrottyCl5XmJAv+PLjACj66iFStqoPjNv2k20nqGPY+QefRMT7PpODcydEO dyhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=CTieqUfrN3QD2Y917kpYPbjsuUgn/zzRL0HRoSY4mxA=; b=qu5DMyNdieUnl9bCfk0hdM6VxVha/Kob0Rs6hJmyCMIE10Fm+ehtxiYyKJpK8lIB2S TXXxYipFwq4+bbUzSl7J80NEmrQnLY2op3z3K0O+hTTZ5B7a08U/Ln0uzaff18ODQoWn o2L8YJfLgSejlWUsGcQRnN7p507RC5EpgLt25m+2fsD6vl2gS5YeElPTfHOPtj9gYpSw tgSoueCaPDGUbuzbgac5/DldqGxkmbkEvrXTdTPa4Cdg4suhLivNG44uWkfbheVk0mCI 6m+ZDSeb79wnT+oLaNo6xgfblJFx6u6aip2NRwYSK0qcW9gzqqRjVsbp/rjEEofP/xFF fqaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=V8DyrMwT; 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u3si8434595jae.21.2021.09.14.00.23.27; Tue, 14 Sep 2021 00:23:38 -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=@canonical.com header.s=20210705 header.b=V8DyrMwT; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238642AbhINHWg (ORCPT + 99 others); Tue, 14 Sep 2021 03:22:36 -0400 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:59300 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232880AbhINHWf (ORCPT ); Tue, 14 Sep 2021 03:22:35 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id BFF8E4017B for ; Tue, 14 Sep 2021 07:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1631604077; bh=CTieqUfrN3QD2Y917kpYPbjsuUgn/zzRL0HRoSY4mxA=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=V8DyrMwTlNsppkAUjKLe0Pt14bQP1U4xP2T++pOPHm2BQploQMcSaPZWp4FTSCrFD CCf4iyU99bgstDvxyGg+BphVe88WB/hHi5z1gHFmxElvhfqi3c/pDiF6H+6ineWpoT r3R+0/lHTCCsR1t/HH+G5ZYVnkPmlpYAUJCOTbdqRO8Hry/mcSt9xiRdtV4oA8YpIJ KUD6SoAwxko6TCCTYHrQ/+dEdh78ZGQahdFpahATg+UdgplYbUO15Y8xtJgxC7p9xC aV0NJn7lbcvb3iaeEJNb5gnNx+lsJRbzxxc9bAln4AFYx9aTylsHi08Rn2C8ecV+Ig Ybc+iG2n0TQCw== Received: by mail-wr1-f69.google.com with SMTP id i16-20020adfded0000000b001572ebd528eso3580726wrn.19 for ; Tue, 14 Sep 2021 00:21:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=CTieqUfrN3QD2Y917kpYPbjsuUgn/zzRL0HRoSY4mxA=; b=t1R3ZwfdT3HqEUDx9bMKjGHsoboM/q08XkYInKGl22i0MJk9tZEe2QAEN9vpu2+Bu0 CABkaQcL/Ut1ijZEuDOLRJUZo4Cd+SBU6zi6liSNFjpln0Ibs6wGgxatCgK1VIVJ+K44 egc/POMlyPv9opdIvUwRE7DtLi1R82e2O24D7BECFthbZFk4pxQQRvlEht0qT8VE2mx4 PzJLYGBe1Rkw2JLnXuUIESub4AQPy9NvM7ornLwib4BwFMrqY4i64oOmuA6klbP6nMLb /foLhXRRRMJXrM8WFsv3JespB4v5V5PZ48iMytYI+ZBZeWqOyzXFjd4H8jjXLi5wUze0 8N/g== X-Gm-Message-State: AOAM533udtaPLFv0ZUiVvWTamLew7X1mb31+xhIv1hFxSmlB8EJX7UTy Brz2XinUWFgzBWXOg51px3FDmqvUcvqcsD5y1i6yk3P5ZYeTD6VZwZQSw70pO26IvnR7UBGQle9 0N2dmQEtIRWYpz7CLt5x5j0fMNuBWnXxjxVksWgURBw== X-Received: by 2002:a05:6000:1569:: with SMTP id 9mr17026231wrz.343.1631604077420; Tue, 14 Sep 2021 00:21:17 -0700 (PDT) X-Received: by 2002:a05:6000:1569:: with SMTP id 9mr17026215wrz.343.1631604077251; Tue, 14 Sep 2021 00:21:17 -0700 (PDT) Received: from [192.168.3.211] (lk.84.20.244.219.dc.cable.static.lj-kabel.net. [84.20.244.219]) by smtp.gmail.com with ESMTPSA id v17sm9346322wrr.69.2021.09.14.00.21.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Sep 2021 00:21:16 -0700 (PDT) Subject: Re: [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler To: Sebastian Krzyszkowiak , Sebastian Reichel , linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Anton Vorontsov , Ramakrishna Pallala , Dirk Brandewie , stable@vger.kernel.org, kernel@puri.sm References: <20210912205402.160939-1-sebastian.krzyszkowiak@puri.sm> <0123524d-b767-5b5b-8b14-60d8cea3c429@canonical.com> <5702731.UytLkSCjyO@pliszka> From: Krzysztof Kozlowski Message-ID: <6affbb35-7b79-db6e-a346-e74d2ba2e886@canonical.com> Date: Tue, 14 Sep 2021 09:21:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <5702731.UytLkSCjyO@pliszka> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/09/2021 20:32, Sebastian Krzyszkowiak wrote: > On poniedziałek, 13 września 2021 15:02:34 CEST Krzysztof Kozlowski wrote: >> On 12/09/2021 22:54, Sebastian Krzyszkowiak wrote: >>> The gauge requires us to clear the status bits manually for some alerts >>> to be properly dismissed. Previously the IRQ was configured to react only >>> on falling edge, which wasn't technically correct (the ALRT line is active >>> low), but it had a happy side-effect of preventing interrupt storms >>> on uncleared alerts from happening. >>> >>> Fixes: 7fbf6b731bca ("power: supply: max17042: Do not enforce (incorrect) >>> interrupt trigger type") Cc: >>> Signed-off-by: Sebastian Krzyszkowiak >>> --- >>> >>> drivers/power/supply/max17042_battery.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/drivers/power/supply/max17042_battery.c >>> b/drivers/power/supply/max17042_battery.c index >>> 8dffae76b6a3..c53980c8432a 100644 >>> --- a/drivers/power/supply/max17042_battery.c >>> +++ b/drivers/power/supply/max17042_battery.c >>> @@ -876,6 +876,9 @@ static irqreturn_t max17042_thread_handler(int id, >>> void *dev)> >>> max17042_set_soc_threshold(chip, 1); >>> >>> } >>> >>> + regmap_clear_bits(chip->regmap, MAX17042_STATUS, >>> + 0xFFFF & ~(STATUS_POR_BIT | > STATUS_BST_BIT)); >>> + >> >> Are you sure that this was the reason of interrupt storm? Not incorrect >> SoC value (read from register for ModelGauge m3 while not configuring >> fuel gauge model). > > Yes, I am sure. I have observed this on a fully configured max17055 with > ModelGauge m5. It also makes sense to me based on what I read in the code and > datasheets. > > There were two kinds of storms - the short ones happening on each SOC change > caused by SOC threshold alerts set by max17042_set_soc_threshold which > eventually got cleared by reconfiguring the thresholds; and a huge one > happening when SOC got down to 0% that did not get away until the battery got > charged to at least 1% at which point the thresholds got reconfigured again > (which is how I noticed the underflow fixed by the second patch). OK, undestood. > > Besides, I also have patches for configuring m5 gauge via DT that I'll send > once I clean them up. That's cool! Happy to see such work. > >> You should only clear bits which you are awaken for... Have in mind that >> in DT-configuration the fuel gauge is most likely broken by missing >> configuration. With alert enabled, several other config fields should be >> cleared. > > I have checked all the bits in the Status register and aside of Bst, POR and > bunch of "don't-care" bits they're all alert indicators that we either handle > explicitly in the interrupt handler (Smn/Smx) or implicitly via > power_supply_changed (Imn/Imx, Vmn/Vmx, Tmn/Tmx, dSOCi, Bi/Br). The driver > unconditionally enables alerts for SOC thresholds and all the rest stays > effectively disabled at POR; however, a bootloader or firmware may configure it > differently, which may be wanted for things like resuming from suspend when a > bad condition happens. Therefore we need to clear all the bits anyway and I'm > not sure whether iterating through them in a "if set then clear" loop gains us > anything aside of additional lines of code. Seems reasonable, you're right. Could you mention this expolanation in commit msg or comment in the code? Best regards, Krzysztof