From patchwork Tue May 26 08:17:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rnd4@dave-tech.it X-Patchwork-Id: 476398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x23f.google.com (mail-wi0-x23f.google.com [IPv6:2a00:1450:400c:c05::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3DB30140E11 for ; Tue, 26 May 2015 18:17:53 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=iavzZpsK; dkim-atps=neutral Received: by wibbw19 with SMTP id bw19sf12850342wib.1 for ; Tue, 26 May 2015 01:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:reply-to:content-type:precedence :mailing-list:list-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=KgdMaLn4kQf0dDmDn2a9sdnLlofTTziuRVyeFcOQ1CY=; b=iavzZpsK1FbPpkan8mnVeMhxsnQBhh8IX8Z8lqw0yfl+GW/6X/tMh8gsgZkoAF2rCZ 9YWgUOtHwcFjHhaxp3Huopr0ZFA2mJCBYzp6lQNXvkdMAd/aqUz/Cok7WnRONrlvmjTH de+FmXJ0jBcPvffWsjaiie6BmPI6JZ9vF9o1/jQRkm3oLnj0kjd2/5pFIMQ/DQ4UcxZN pNsRfeC6goPnXrERz6nirof/GGMlhksaCus4/BPxX9QSYEMuDCmggBBMK+0/tW/fheg/ zxerr8XRlWhATp9zQB3zWneRQbKaAdXDIg07jE8scaF/uaS6GVykZLk4MPGij6dP4PYd 8NMw== X-Received: by 10.152.207.9 with SMTP id ls9mr261369lac.16.1432628270350; Tue, 26 May 2015 01:17:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.152.181.34 with SMTP id dt2ls781455lac.14.gmail; Tue, 26 May 2015 01:17:49 -0700 (PDT) X-Received: by 10.152.2.169 with SMTP id 9mr26332470lav.1.1432628269678; Tue, 26 May 2015 01:17:49 -0700 (PDT) Received: from mx.dave-tech.it (mx.dave-tech.it. [2.229.21.40]) by gmr-mx.google.com with ESMTP id bc3si471292wib.2.2015.05.26.01.17.49 for ; Tue, 26 May 2015 01:17:49 -0700 (PDT) Received-SPF: neutral (google.com: 2.229.21.40 is neither permitted nor denied by best guess record for domain of amon@linuxserver2.dave-lan) client-ip=2.229.21.40; Received: from linuxserver2.dave-lan (unknown [192.168.0.23]) by mx.dave-tech.it (Postfix) with ESMTP id 109178F; Tue, 26 May 2015 10:17:49 +0200 (CEST) Received: by linuxserver2.dave-lan (Postfix, from userid 500) id DA8655065E; Tue, 26 May 2015 10:17:48 +0200 (CEST) From: rnd4@dave-tech.it To: r.cerrato@til-technologies.fr Cc: a.zummo@towertech.it, rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Andrea Scian Subject: [rtc-linux] [PATCH] driver: rtc: pcf2127: use OFS flag to detect unreliable date and warn the user Date: Tue, 26 May 2015 10:17:40 +0200 Message-Id: <1432628260-24652-1-git-send-email-rnd4@dave-tech.it> X-Mailer: git-send-email 1.7.9.5 X-Original-Sender: rnd4@dave-tech.it X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2.229.21.40 is neither permitted nor denied by best guess record for domain of amon@linuxserver2.dave-lan) smtp.mail=amon@linuxserver2.dave-lan Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , From: Andrea Scian I'm using PCF2127 in a custom ARM-based board and, by looking into PCF2127 datasheet I've found that, in my understanding, it's wrong to say that the date in unreliable if BLF (battery low flag) is set but you should use OSF flag (seconds register) to check if oscillator, for any reason, stopped. Battery may be low (usually below 2V5 threshold) but the date may be anyway correct (tipically date is unreliable when input voltage is below 1V2). Feel free to comment and apply if useful. Kind Regards, Andrea --- Also change the power fail message, which does NOT mean that time is not valid but also states that user should replace the battery Signed-off-by: Andrea Scian --- drivers/rtc/rtc-pcf2127.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 1ee514a..2365788 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -59,7 +59,16 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm) if (buf[PCF2127_REG_CTRL3] & 0x04) { pcf2127->voltage_low = 1; dev_info(&client->dev, - "low voltage detected, date/time is not reliable.\n"); + "low voltage detected, check/replace RTC battery.\n"); + } + + if (buf[PCF2127_REG_SC] & 0x80) { + dev_warn(&client->dev, + "oscillator stop detected, date/time is not reliable.\n"); + /* + * no need clear the flag here, + * it will be cleared once the new date is saved + */ } dev_dbg(&client->dev, @@ -112,7 +121,7 @@ static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) buf[i++] = PCF2127_REG_SC; /* hours, minutes and seconds */ - buf[i++] = bin2bcd(tm->tm_sec); + buf[i++] = bin2bcd(tm->tm_sec); /* this will also clear OFS flag */ buf[i++] = bin2bcd(tm->tm_min); buf[i++] = bin2bcd(tm->tm_hour); buf[i++] = bin2bcd(tm->tm_mday); @@ -144,7 +153,7 @@ static int pcf2127_rtc_ioctl(struct device *dev, switch (cmd) { case RTC_VL_READ: if (pcf2127->voltage_low) - dev_info(dev, "low voltage detected, date/time is not reliable.\n"); + dev_info(dev, "low voltage detected, check/replace battery\n"); if (copy_to_user((void __user *)arg, &pcf2127->voltage_low, sizeof(int)))