From patchwork Fri Feb 15 12:44:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14861 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 0EEB023E2E for ; Fri, 15 Feb 2013 12:46:22 +0000 (UTC) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by fiordland.canonical.com (Postfix) with ESMTP id A687EA1828F for ; Fri, 15 Feb 2013 12:46:21 +0000 (UTC) Received: by mail-ve0-f178.google.com with SMTP id db10so2936027veb.23 for ; Fri, 15 Feb 2013 04:46:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=LIwunULYKV7ISiqplIULtp0puYO4agr7PCQV7rIjCmE=; b=kg6ejMqcwRhWZ24/NAXUSeomlUzvIOQOMx9YKQYmooi7VrWb4BVOdGeN5LQV1iqudl XRed+1NfQRvnHSGHrYHTdtcd6W2cPEcKs/RM7DtRrlO/WbFHbJIrRJGfdvjo6HN3FKMO zNlGuhUx06tqpOgfOLmwyyKPDLvp4/0D3/A0oH14WJsc3m/FxrHf/fY58+eXmA3mbVmb XWF2LhzLEVryK+/yQ7J+JNG4r97W4niom59/R/6UBEGhvIjZWX1jOpoJUkPSlQJv4YoV i9QxjjNEWIKhm9TzuweI+ZgQaY5W3xWnR3b5Kftk5rA84ntfaF5iZh+0bWxadgYxRm9y wvPA== X-Received: by 10.220.153.143 with SMTP id k15mr2878812vcw.33.1360932381163; Fri, 15 Feb 2013 04:46:21 -0800 (PST) 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.221.4.5 with SMTP id oa5csp10859vcb; Fri, 15 Feb 2013 04:46:20 -0800 (PST) X-Received: by 10.194.58.175 with SMTP id s15mr3953094wjq.31.1360932378905; Fri, 15 Feb 2013 04:46:18 -0800 (PST) Received: from mail-we0-x22a.google.com ([2a00:1450:400c:c03::22a]) by mx.google.com with ESMTPS id bm6si1035273wib.89.2013.02.15.04.46.18 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:18 -0800 (PST) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22a is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=2a00:1450:400c:c03::22a; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c03::22a is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-we0-f170.google.com with SMTP id z53so2917708wey.29 for ; Fri, 15 Feb 2013 04:46:18 -0800 (PST) X-Received: by 10.180.79.37 with SMTP id g5mr5659342wix.24.1360932377304; Fri, 15 Feb 2013 04:46:17 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id bs6sm5133904wib.4.2013.02.15.04.46.15 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:16 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, linus.walleij@stericsson.com, cbouatmailru@gmail.com, sameo@linux.intel.com, Hakan Berg , Lee Jones Subject: [PATCH 16/40] ab8500-btemp: Filter btemp readings Date: Fri, 15 Feb 2013 12:44:46 +0000 Message-Id: <1360932310-30065-17-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> References: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlmWdhgnyOlzsYbKAqBgKrwIdxRac0V9/Cb3EJT21NRgk2EcYshdmoqLpx5v6Dw54wCW+JI From: Hakan Berg Battery tempreature readings sometimes fail 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: Lee Jones Reviewed-by: Marcus COOPER Reviewed-by: Martin SJOBLOM Reviewed-by: Rabin VINCENT --- drivers/power/ab8500_btemp.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c index 0768906..fa60e3a 100644 --- a/drivers/power/ab8500_btemp.c +++ b/drivers/power/ab8500_btemp.c @@ -76,8 +76,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 @@ -604,6 +604,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); @@ -614,12 +615,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->bm->temp_interval_chg;