From patchwork Thu Sep 27 20:08:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11814 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 233DC24140 for ; Thu, 27 Sep 2012 20:10:18 +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 C44E6A18351 for ; Thu, 27 Sep 2012 20:10:17 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5234855iej.11 for ; Thu, 27 Sep 2012 13:10:17 -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=pYW5WzKF+7HbMWxrqO7P3czzUMEANhNImUv2qryv1XM=; b=MOZTSXTp9LPEvcC+hh5d+r1r1yRGbuyASNMVAGYz00F90uB05AK4DgPxGLDL87Asru Ka+4fZPb2Kd5peDxHMbz5r5CfwbgrhhCsJZ9uc78WL7ONwOEbEx+juqmkpgluxmonK5c nhCu8+GzrDLNovOuV6oaHqBqfulLFGVcGijoStvi5mRHgFMHKCxBa2gtROR5Ct2NS5YU XsE75qlApscj9x+QXc8ev7ILyvFwr84X3crZcKwyAULhWCTyhnIYmWMR/pKYaq/9EI5N 0lA5+kuqlrPhlAiH2GHMd2YF1do1OWgfgN/RkxKdfWVPmsCVCOsFPBTXrJ3skiCutrLc 3cLQ== Received: by 10.50.0.193 with SMTP id 1mr4748368igg.0.1348776617460; Thu, 27 Sep 2012 13:10:17 -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 ex8csp436371igc; Thu, 27 Sep 2012 13:10:16 -0700 (PDT) Received: by 10.68.132.41 with SMTP id or9mr14769063pbb.67.1348776616763; Thu, 27 Sep 2012 13:10:16 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pi9si5467641pbb.12.2012.09.27.13.10.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:10:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.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-pb0-f50.google.com with SMTP id md4so1686045pbc.37 for ; Thu, 27 Sep 2012 13:10:16 -0700 (PDT) Received: by 10.66.89.6 with SMTP id bk6mr11962714pab.81.1348776616531; Thu, 27 Sep 2012 13:10:16 -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.10.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:10:15 -0700 (PDT) From: mathieu.poirier@linaro.org To: patches@linaro.org Subject: [PATCH 41/57] power: ab8500_btemp: Filter btemp readings Date: Thu, 27 Sep 2012 14:08:58 -0600 Message-Id: <1348776554-10019-42-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: ALoCoQmp+aouTWBKOYBWE/F9aVaJG0ZDWTvaSebJuW4e0Ab54qETJJXkcBWLdWfIDdHR3zokNIR8 From: Hakan Berg Battery tempreature readings sometimes fails and results in a value far from recent values. This patch adds a software filter that disposes such readings, by allowing direct updates on temperature only if two samples result in the same temperature. Else only allow 1 degree change from previous reported value in the direction of the new measurement. Signed-off-by: Hakan Berg Signed-off-by: Mathieu Poirier Reviewed-by: Marcus COOPER Reviewed-by: Martin SJOBLOM Reviewed-by: Rabin VINCENT --- drivers/power/ab8500_btemp.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c index 56a3bb9..b24835f 100644 --- a/drivers/power/ab8500_btemp.c +++ b/drivers/power/ab8500_btemp.c @@ -74,8 +74,8 @@ struct ab8500_btemp_ranges { * @dev: Pointer to the structure device * @node: List of AB8500 BTEMPs, hence prepared for reentrance * @curr_source: What current source we use, in uA - * @bat_temp: Battery temperature in degree Celcius - * @prev_bat_temp Last dispatched battery temperature + * @bat_temp: Dispatched battery temperature in degree Celcius + * @prev_bat_temp Last measured battery temperature in degree Celcius * @parent: Pointer to the struct ab8500 * @gpadc: Pointer to the struct gpadc * @fg: Pointer to the struct fg @@ -608,6 +608,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) static void ab8500_btemp_periodic_work(struct work_struct *work) { int interval; + int bat_temp; struct ab8500_btemp *di = container_of(work, struct ab8500_btemp, btemp_periodic_work.work); @@ -618,12 +619,26 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) dev_warn(di->dev, "failed to identify the battery\n"); } - di->bat_temp = ab8500_btemp_measure_temp(di); - - if (di->bat_temp != di->prev_bat_temp) { - di->prev_bat_temp = di->bat_temp; + bat_temp = ab8500_btemp_measure_temp(di); + /* + * Filter battery temperature. + * Allow direct updates on temperature only if two samples result in + * same temperature. Else only allow 1 degree change from previous + * reported value in the direction of the new measurement. + */ + if (bat_temp == di->prev_bat_temp || !di->initialized) { + if (di->bat_temp != di->prev_bat_temp || !di->initialized) { + di->bat_temp = bat_temp; + power_supply_changed(&di->btemp_psy); + } + } else if (bat_temp < di->prev_bat_temp) { + di->bat_temp--; + power_supply_changed(&di->btemp_psy); + } else if (bat_temp > di->prev_bat_temp) { + di->bat_temp++; power_supply_changed(&di->btemp_psy); } + di->prev_bat_temp = bat_temp; if (di->events.ac_conn || di->events.usb_conn) interval = di->bat->temp_interval_chg;