From patchwork Thu Sep 27 20:08:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11797 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E218524140 for ; Thu, 27 Sep 2012 20:09:51 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 96CBBA18B18 for ; Thu, 27 Sep 2012 20:09:51 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5234801iej.11 for ; Thu, 27 Sep 2012 13:09:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=0gzoordXzolXC/JhWDBZBe/WztW7XZjMBSls2UpCBHo=; b=MAgE/jIrzYaGjW4jpOeUdHTysfBz7uvhkJrz/NLggeUvK8nswu1nZ7CQcmpD7xqomk ZgattsftskLDZUo6YWoOo1kRfZFRM16531f/Dpy/WqK0DqEpL7YAz2fCdcH/weKwmjST TMY1wDwWnf2rlk7iJbrqHwkFHWZlyXqGL1WBWYt3xojYMFMDttgeFYF1+NU7hlcYDmoW ZRWQppESIzQN2kC5ydFKvMOmF4VZnvS4a+HAqQK2+7gqUI2f6xB8Fq/D6gm/LOuNEPOj B0obVBmmn9JC+rHIxjpED2lgY0BhpuHit6O2D7ztyCf3VHQd3WT9Sj1x7E8q9lixVMZ9 eEyg== Received: by 10.50.0.193 with SMTP id 1mr4747350igg.0.1348776591368; Thu, 27 Sep 2012 13:09:51 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp436318igc; Thu, 27 Sep 2012 13:09:50 -0700 (PDT) Received: by 10.66.78.73 with SMTP id z9mr12225910paw.9.1348776590586; Thu, 27 Sep 2012 13:09:50 -0700 (PDT) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by mx.google.com with ESMTPS id vn9si8390651pbc.17.2012.09.27.13.09.50 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) client-ip=209.85.220.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) smtp.mail=mathieu.poirier@linaro.org Received: by mail-pa0-f50.google.com with SMTP id hz11so1847989pad.37 for ; Thu, 27 Sep 2012 13:09:50 -0700 (PDT) Received: by 10.68.189.161 with SMTP id gj1mr14515509pbc.21.1348776590277; Thu, 27 Sep 2012 13:09:50 -0700 (PDT) Received: from localhost.localdomain (S0106002369de4dac.cg.shawcable.net. [70.73.24.112]) by mx.google.com with ESMTPS id sa2sm1587890pbc.4.2012.09.27.13.09.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:49 -0700 (PDT) From: mathieu.poirier@linaro.org To: patches@linaro.org Subject: [PATCH 24/57] power: ab8500_fg: Adjust for RF bursts voltage drops. Date: Thu, 27 Sep 2012 14:08:41 -0600 Message-Id: <1348776554-10019-25-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> References: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> X-Gm-Message-State: ALoCoQlLI+2lz2LPIXRfObGddzJMifR0dQvT0klNzjsNLiJcdDM0ktDXUDwx+8KolPQrjiVYPy5p From: Hakan Berg Changed conditions for restarting low battery measurements counter and adjusted the interval between measurements to avoid RF burst induced voltage drops, and to shorten time to decide to shut down. Signed-off-by: Hakan Berg Signed-off-by: Martin Bergstrom Signed-off-by: Mathieu Poirier Reviewed-by: Jonas ABERG Reviewed-by: Marcus COOPER --- drivers/power/ab8500_fg.c | 44 ++++++++++++++++++++++++++++++-------------- 1 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 7c42150..861927d 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -42,7 +42,7 @@ #define NBR_AVG_SAMPLES 20 -#define LOW_BAT_CHECK_INTERVAL (2 * HZ) +#define LOW_BAT_CHECK_INTERVAL (HZ / 16) /* 62.5 ms */ #define VALID_CAPACITY_SEC (45 * 60) /* 45 minutes */ #define BATT_OK_MIN 2360 /* mV */ @@ -168,6 +168,7 @@ struct inst_curr_result_list { * @recovery_cnt: Counter for recovery mode * @high_curr_cnt: Counter for high current mode * @init_cnt: Counter for init mode + * @low_bat_cnt Counter for number of consecutive low battery measures * @nbr_cceoc_irq_cnt Counter for number of CCEOC irqs received since enabled * @recovery_needed: Indicate if recovery is needed * @high_curr_mode: Indicate if we're in high current mode @@ -210,6 +211,7 @@ struct ab8500_fg { int recovery_cnt; int high_curr_cnt; int init_cnt; + int low_bat_cnt; int nbr_cceoc_irq_cnt; bool recovery_needed; bool high_curr_mode; @@ -1882,25 +1884,29 @@ static void ab8500_fg_low_bat_work(struct work_struct *work) /* Check if LOW_BAT still fulfilled */ if (vbat < di->bat->fg_params->lowbat_threshold) { - di->flags.low_bat = true; - dev_warn(di->dev, "Battery voltage still LOW\n"); - - /* - * We need to re-schedule this check to be able to detect - * if the voltage increases again during charging - */ - queue_delayed_work(di->fg_wq, &di->fg_low_bat_work, - round_jiffies(LOW_BAT_CHECK_INTERVAL)); + /* Is it time to shut down? */ + if (di->low_bat_cnt < 1) { + di->flags.low_bat = true; + dev_warn(di->dev, "Shut down pending...\n"); + } else { + /* + * Else we need to re-schedule this check to be able + * to detect if the voltage increases again during + * charging or due to decreasing load. + */ + di->low_bat_cnt--; + dev_warn(di->dev, "Battery voltage still LOW\n"); + queue_delayed_work(di->fg_wq, &di->fg_low_bat_work, + round_jiffies(LOW_BAT_CHECK_INTERVAL)); + } } else { - di->flags.low_bat = false; + di->flags.low_bat_delay = false; + di->low_bat_cnt = 10; dev_warn(di->dev, "Battery voltage OK again\n"); } /* This is needed to dispatch LOW_BAT */ ab8500_fg_check_capacity_limits(di, false); - - /* Set this flag to check if LOW_BAT IRQ still occurs */ - di->flags.low_bat_delay = false; } /** @@ -2059,6 +2065,10 @@ static irqreturn_t ab8500_fg_lowbatf_handler(int irq, void *_di) { struct ab8500_fg *di = _di; + /* + * Initiate handling in ab8500_fg_low_bat_work() if not already + * initiated. + */ if (!di->flags.low_bat_delay) { dev_warn(di->dev, "Battery voltage is below LOW threshold\n"); di->flags.low_bat_delay = true; @@ -2748,6 +2758,12 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) INIT_DELAYED_WORK_DEFERRABLE(&di->fg_check_hw_failure_work, ab8500_fg_check_hw_failure_work); + /* Reset battery low voltage flag */ + di->flags.low_bat = false; + + /* Initialize low battery counter */ + di->low_bat_cnt = 10; + /* Initialize OVV, and other registers */ ret = ab8500_fg_init_hw_registers(di); if (ret) {