Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2260918rwl; Sat, 5 Nov 2022 04:36:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62p0BQ/qggZCgWVUp/uQv1jXFHshnSxgqjTgRr/dW9g+z6X6rKbCEhFMn3j1G9PIPifU8A X-Received: by 2002:a17:907:318b:b0:740:33f2:9e8 with SMTP id xe11-20020a170907318b00b0074033f209e8mr37802401ejb.138.1667648162402; Sat, 05 Nov 2022 04:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667648162; cv=none; d=google.com; s=arc-20160816; b=x/L52FTKSY7aWKlkGWpByNqBRwpTH1Ar2Xo3CxV698EdY/lDriQ3nM+3Xhs2rLUfWU 6fSeKaujRADtWOFqYeGjS42Bn7PeBn3pt63ITK6dQGEfvNt4GFQi5cGBAD9WpQROTSNw tWj7zZDUEjbaaCQeNXFut8qfuBoOPnBMLHEXbQTBFZlziQJaFKlPC7ClW0uApA6cE01H ZpcGilkA//NUfAnv+lKU54xYIjh3EFiDjULMEvk5hwwtDtBNJByuElHms0xpSPRyec15 SVDQxfAzuNh3a5ljcSfivdHkI5YEUKbE2sUHSBA1ce6NvkXO2gsRMzmO0NfYyLkbwplv O70Q== 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=PIJ7hf/fFBlHGb3gaHRXBAK5sDqMN3APy8LXApKcTCc=; b=QAp5JfXmnM4frLdk7+IpbnIoIZFR/UgdBk6A+XSN/q5AhkAc9YqKZ+fd3trDexTkMG j8/eo8A1sJ9gqgMipgBNIJk/AJwyhafqPrycx9Y0wcv42s0kkMnRny+IHpMYEFOOOctn hRgnh1jyY8/iPC6nEX836dJSUnKeiZpOIkgKTqPCF6lu4Etc6mgJXi1U84kf1c0KVwbt SETC25s5C5EmAzyOqwluDdoxw3xdB7Cn7qtaisD1yy5TTMIyKGFZqpt0uNjmaYJCbMUG 4bBtq4Z9EAOTYIjn+HqZouDQULycpmMaSSwzXtdj5L7l9Fzz6KEngics6Z45cHqljVCC DCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hXEVWmvW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rv14-20020a17090710ce00b0073866c0672asi1705226ejb.73.2022.11.05.04.35.39; Sat, 05 Nov 2022 04:36:02 -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=hXEVWmvW; 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 S229801AbiKEL0Y (ORCPT + 96 others); Sat, 5 Nov 2022 07:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiKEL0S (ORCPT ); Sat, 5 Nov 2022 07:26:18 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34C21CB16; Sat, 5 Nov 2022 04:26:16 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id kt23so19234533ejc.7; Sat, 05 Nov 2022 04:26:16 -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=PIJ7hf/fFBlHGb3gaHRXBAK5sDqMN3APy8LXApKcTCc=; b=hXEVWmvWnxe69ninDDQWYoIBl3qLZ9ZNzW8y40rtZJSMghjsDd4Vfzi7QTiExEYmJn rABOv+nXVLVMi6nqHFtaZrZ6pS7BQoLKUd3snMgUOsNVya9d6qsfLW9V5a+gP45JUHzY vWrkU9dhMLzE6Iq64tRYRjs5bRNFfutjuujlOCjhOyewPLvDkCvhLpLnJeYL9CehKLZA 3+5z3nAzqkDI61LlXRCwZtN3gqyoJbB/gwh1xWDuOFb3pRLLSBkzcftntcoJSRGMxTOj Y1CNujlBW+5ZjUXtLUMZ6gH5LyKluLehm3xTfqRNzcL9jRQlhV//CVbZKbPfIeo5mFCs D3fA== 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=PIJ7hf/fFBlHGb3gaHRXBAK5sDqMN3APy8LXApKcTCc=; b=JejPxMlVybff5IQqElGlLO7xj850CZBWayH0yZN7AxaD2nRCuZOO1DroA0eXbmNb4H VU/ZBfEjvGg5vzZ3BFs6xgGdF19M6y3oS6DScaCZRVHOtv0Fi9LsMX+SsHUZn+6RD2Ve MUDTnNZ1e64W/6MEqQoqN2c0x+pzgGAkGWgeYjwwdNffFwwpCMmE4go6PTaPqlT9rQpk 0GdHVjQGGGlXipjpqra0zDRipCfWZt/DOU/cTb/d8qJxP+b6skFAeZxb4LbkGlURivs4 4OzSjo5wV8XBpmH9ju9MKyXyCnoNzPoMItiNE6pQyrCOc3IBDj4W+m0CaUnN3plnTUDq EleQ== X-Gm-Message-State: ACrzQf1eVW7O3xehp7FK8FqNF+gtoW/sBGojM2GESEZG2+W5ONhnLCY3 7dyHQpVfFw7ZZAWUsc55FjY= X-Received: by 2002:a17:907:2063:b0:7ad:fa6b:e84b with SMTP id qp3-20020a170907206300b007adfa6be84bmr20372498ejb.69.1667647575280; Sat, 05 Nov 2022 04:26:15 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id u18-20020a509512000000b004611c230bd0sm1050069eda.37.2022.11.05.04.26.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Nov 2022 04:26:14 -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: Sat, 5 Nov 2022 13:25:42 +0200 Message-Id: <1667647544-12945-2-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1667647544-12945-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <1667647544-12945-1-git-send-email-ivo.g.dimitrov.75@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 4676560..8869067 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 delayed_work low_irq_work; u32 cc_lsb; /* μAms per LSB */ atomic_t active; int charge_full; @@ -914,9 +915,13 @@ 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 && + !delayed_work_pending((&ddata->low_irq_work))) { dev_warn(ddata->dev, "Battery low at %imV!\n", latest->voltage / 1000); + schedule_delayed_work(&ddata->low_irq_work, 30 * HZ); + disable_irq_nosync(d->irq); + } break; case CPCAP_BATTERY_IRQ_ACTION_POWEROFF: if (latest->current_ua >= 0 && latest->voltage <= 3200000) { @@ -1087,6 +1092,21 @@ static int cpcap_battery_calibrate(struct cpcap_battery_ddata *ddata) return error; } +static void cpcap_battery_lowbph_enable(struct work_struct *work) +{ + struct delayed_work *d_work = to_delayed_work(work); + struct cpcap_battery_ddata *ddata = container_of(d_work, + struct cpcap_battery_ddata, low_irq_work); + 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 +1138,8 @@ static int cpcap_battery_probe(struct platform_device *pdev) if (!ddata) return -ENOMEM; + INIT_DELAYED_WORK(&ddata->low_irq_work, cpcap_battery_lowbph_enable); + cpcap_battery_detect_battery_type(ddata); INIT_LIST_HEAD(&ddata->irq_list); @@ -1185,6 +1207,9 @@ static int cpcap_battery_remove(struct platform_device *pdev) if (error) dev_err(&pdev->dev, "could not disable: %i\n", error); + /* make sure to call enable_irq() if needed */ + flush_delayed_work(&ddata->low_irq_work); + return 0; } -- 1.9.1