From patchwork Tue Nov 1 19:53:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 13857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3176241wru; Tue, 1 Nov 2022 12:57:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AOWDrTy8bmw9WXZlMKk7kE4bGMmVY5/ZwLaEY6delg0yRKuEZDZZYobf6aZvA0mMw2pmm X-Received: by 2002:a17:902:a612:b0:17e:539:c415 with SMTP id u18-20020a170902a61200b0017e0539c415mr20344568plq.173.1667332673583; Tue, 01 Nov 2022 12:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667332673; cv=none; d=google.com; s=arc-20160816; b=kAY6HBOSntyhPNfJQbUqu8c7U2JsOSFKCy9KsxrR1tZBD2qjp4gPz0wX9+2hMYSGTV vD7MLVK9vM8NZQKVAr1mdyGSsoONDFq++BwAs81Nwf1FiGgEAC83TT9rcsoXSRemaXAS Zg8T8Dr7xqrZi5+FFcSPH5Bex6/kUBn+GmygoKreuMg8X1HD2pk/T5GCYZE4NbWyJuMV tK0jjC3jeSibe9czAfCwrDUYNzVkQtBKDe0mQMKHk1aaHnOp3LrICcSQ8GBcUzGNwCcY o8GJ9Qd4iF4MIglbMCcFQYCvhZOPc5DYupKGy2exwWeBAFygpVuO3OGQ9Hopn8Wx/kSv P2ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qMLvz91JxdD1ON81vyAGas2R1qe681rjzzgx71DZVdI=; b=Le3z1Y1Yylm89b96/LZILcUQ5Q9YFPilzvuEK7cBaSpqxXS2AOwfBF7qmOuO1HKZSt CSLzAgr6wN828HcM9CCKV7PY2zyx+EO0LXDfdAPMK7ewf8kUUkBGndSfl5TcL79CZrla uaA2sHJVDRs11OmjcCh3RkSLsmvAbmjTFEssT7Bpnu5x8FEHRLMGB+wogKPGcsJ8SSSK QdUE/Hst4lWukkjbdkThFnSJiaAYqLtACZvabb1iDl8wM0OyJjeSw2IEYFij8JAhHLqf f/64c4WaW+XIgBCV1wl9FUnp++SUC/EmH6GRbjE/8Vw784HA/tzYgxZYx0ECEVsldUYP WmwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AsdJI5HU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a170902ef5000b00186e114bedfsi14024106plx.126.2022.11.01.12.57.39; Tue, 01 Nov 2022 12:57:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AsdJI5HU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbiKATyO (ORCPT + 99 others); Tue, 1 Nov 2022 15:54:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiKATyK (ORCPT ); Tue, 1 Nov 2022 15:54:10 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A251B9E6; Tue, 1 Nov 2022 12:54:07 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l16-20020a05600c4f1000b003c6c0d2a445so10532270wmq.4; Tue, 01 Nov 2022 12:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qMLvz91JxdD1ON81vyAGas2R1qe681rjzzgx71DZVdI=; b=AsdJI5HULHCv9VmdCc1ZdAEq2+6JDar7zcys5fSi//ueKHj00uKnY+5eADzPW4qjrT TDPm3e+QZfXB82yAzyptOsINAZBw1BcML1pjhTMw86prwCtl9AZWwqwqry1aDJ0lr6CO RSUqHcZaZZP4qAe+TrAhVnWuikr9jBXMdN3McRN6dOHk8pRRXA7snsDRPREpTsOllddB rtCfYmqOeaKsi1Co4mX76wSXaReBfRkuU+M3n/6L36eXOnTVyqdUU2/qNwD8apAM5VpU OjX7SH1yRx9Vom7TAcj7KG5Nc+R48ZOaUfD2TXy0Up6QPs9BsgM4UGhHnUrspI+AYyO7 RXXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qMLvz91JxdD1ON81vyAGas2R1qe681rjzzgx71DZVdI=; b=cxJmmxFKKF0MQrwZRFjz3pM066z5COEB4zT2yJJsTp9OLVvFs2t+fuLmoVYsr4kOA1 XNOSFfwZ6M52/5ZeyULBNszE7LxXt5U/2xQW5P4GxoFaa0BWXbwRjrUq5SHSA7ZunL/8 Q4HiqI/v0QLA3v9/AUbJOxSG7emG+Jc/51q0CdWZUMB7QpZMk18q8u9aQCQ/dQ7p+e3W mQcpm3u/Vr1dD9uNJvHfLuwSHbAoRordpFVI0R5UvIErUdnriAukGmQZKvlXB985Vz3F 6bMRN9gLC7SiD0cz9aCQPv1Qh0jwrr4jFcwD+KlnmodLvfreSIPJDKKXoU21DWyurl8t oEdQ== X-Gm-Message-State: ACrzQf0eIR3GMa4exUQc+JTvj8t8U8tWhCu4s1WxtoQKdgvg+sD+sLNq FscqFec2TO1BrkG3gl/yE34= X-Received: by 2002:a05:600c:4e47:b0:3c6:fc59:5eff with SMTP id e7-20020a05600c4e4700b003c6fc595effmr23083213wmq.18.1667332446282; Tue, 01 Nov 2022 12:54:06 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c468b00b003cf75213bb9sm6092617wmo.8.2022.11.01.12.54.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2022 12:54:05 -0700 (PDT) From: Ivaylo Dimitrov To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, tony@atomide.com, philipp@uvos.xyz, Ivaylo Dimitrov Subject: [PATCH 1/3] power: cpcap-battery: Do not issue low signal too frequently Date: Tue, 1 Nov 2022 21:53:43 +0200 Message-Id: <1667332425-12536-2-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1667332425-12536-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <1667332425-12536-1-git-send-email-ivo.g.dimitrov.75@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748325025929281124?= X-GMAIL-MSGID: =?utf-8?q?1748325025929281124?= It seems that low battery irq may be generated tens of times per second, leading to userspace being flooded with unnecessary events. Fix that by preventing such events being generated more than once every 30 seconds. Signed-off-by: Ivaylo Dimitrov --- drivers/power/supply/cpcap-battery.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 4676560..2659df7 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -137,6 +137,7 @@ struct cpcap_battery_ddata { struct power_supply *psy; struct cpcap_battery_config config; struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR]; + struct timer_list low_timer; u32 cc_lsb; /* μAms per LSB */ atomic_t active; int charge_full; @@ -914,9 +915,14 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data) dev_info(ddata->dev, "Coulomb counter calibration done\n"); break; case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW: - if (latest->current_ua >= 0) + if (latest->current_ua >= 0 && + !timer_pending(&ddata->low_timer)) { dev_warn(ddata->dev, "Battery low at %imV!\n", latest->voltage / 1000); + mod_timer(&ddata->low_timer, + jiffies + msecs_to_jiffies(30000)); + disable_irq_nosync(d->irq); + } break; case CPCAP_BATTERY_IRQ_ACTION_POWEROFF: if (latest->current_ua >= 0 && latest->voltage <= 3200000) { @@ -1087,6 +1093,19 @@ static int cpcap_battery_calibrate(struct cpcap_battery_ddata *ddata) return error; } +static void cpcap_battery_lowbph_enable(struct timer_list *t) +{ + struct cpcap_battery_ddata *ddata = from_timer(ddata, t, low_timer); + struct cpcap_interrupt_desc *d; + + list_for_each_entry(d, &ddata->irq_list, node) { + if (d->action == CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW) + break; + } + + enable_irq(d->irq); +} + #ifdef CONFIG_OF static const struct of_device_id cpcap_battery_id_table[] = { { @@ -1118,6 +1137,8 @@ static int cpcap_battery_probe(struct platform_device *pdev) if (!ddata) return -ENOMEM; + timer_setup(&ddata->low_timer, cpcap_battery_lowbph_enable, 0); + cpcap_battery_detect_battery_type(ddata); INIT_LIST_HEAD(&ddata->irq_list); @@ -1185,6 +1206,8 @@ static int cpcap_battery_remove(struct platform_device *pdev) if (error) dev_err(&pdev->dev, "could not disable: %i\n", error); + del_timer_sync(&ddata->low_timer); + return 0; }