From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932408AbcHKLcT (ORCPT ); Thu, 11 Aug 2016 07:32:19 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33015 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751963AbcHKLcD (ORCPT ); Thu, 11 Aug 2016 07:32:03 -0400 From: Daniel Romell X-Google-Original-From: Daniel Romell To: a.zummo@towertech.it Cc: alexandre.belloni@free-electrons.com, rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, daro@hms.se, jao@hms.se, mago@hms.se Subject: [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag Date: Thu, 11 Aug 2016 13:31:44 +0200 Message-Id: <1470915104-10683-3-git-send-email-daro@hms.se> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470915104-10683-1-git-send-email-daro@hms.se> References: <1470915104-10683-1-git-send-email-daro@hms.se> MIME-Version: 1.0 In-Reply-To: <1470909555-9226-1-git-send-email-daro@hms.se> References: <1470909555-9226-1-git-send-email-daro@hms.se> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Östlund While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time. The failure flag is cleared the next time the clock is set. Signed-off-by: Daniel Romell --- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c index 5a0c137..3977424 100644 --- a/drivers/rtc/rtc-bq32k.c +++ b/drivers/rtc/rtc-bq32k.c @@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struct rtc_time *tm) if (error) return error; + /* + * In case of oscillator failure, the register contents should be + * considered invalid. The flag is cleared the next time the RTC is set. + */ + if (regs.minutes & BQ32K_OF) + return -EINVAL; + tm->tm_sec = bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min = bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour = bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); @@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client, /* Check Oscillator Failure flag */ error = bq32k_read(dev, ®, BQ32K_MINUTES, 1); - if (!error && (reg & BQ32K_OF)) { - dev_warn(dev, "Oscillator Failure. Check RTC battery.\n"); - reg &= ~BQ32K_OF; - error = bq32k_write(dev, ®, BQ32K_MINUTES, 1); - } if (error) return error; + if (reg & BQ32K_OF) + dev_warn(dev, "Oscillator Failure. Check RTC battery.\n"); if (client->dev.of_node) trickle_charger_of_init(dev, client->dev.of_node); -- 2.7.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Sender: rtc-linux@googlegroups.com Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com. [2a00:1450:400c:c09::243]) by gmr-mx.google.com with ESMTPS id o85si706225wme.0.2016.08.11.04.32.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 04:32:01 -0700 (PDT) Received: by mail-wm0-x243.google.com with SMTP id q128so816621wma.1 for ; Thu, 11 Aug 2016 04:32:01 -0700 (PDT) From: Daniel Romell To: a.zummo@towertech.it Cc: alexandre.belloni@free-electrons.com, rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, daro@hms.se, jao@hms.se, mago@hms.se Subject: [rtc-linux] [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag Date: Thu, 11 Aug 2016 13:31:44 +0200 Message-Id: <1470915104-10683-3-git-send-email-daro@hms.se> In-Reply-To: <1470915104-10683-1-git-send-email-daro@hms.se> References: <1470915104-10683-1-git-send-email-daro@hms.se> MIME-Version: 1.0 In-Reply-To: <1470909555-9226-1-git-send-email-daro@hms.se> References: <1470909555-9226-1-git-send-email-daro@hms.se> Content-Type: text/plain; charset=UTF-8 Reply-To: rtc-linux@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , From: Jan =C3=96stlund While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time. The failure flag is cleared the next time the clock is set. Signed-off-by: Daniel Romell --- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c index 5a0c137..3977424 100644 --- a/drivers/rtc/rtc-bq32k.c +++ b/drivers/rtc/rtc-bq32k.c @@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struc= t rtc_time *tm) if (error) return error; =20 + /* + * In case of oscillator failure, the register contents should be + * considered invalid. The flag is cleared the next time the RTC is set. + */ + if (regs.minutes & BQ32K_OF) + return -EINVAL; + tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); @@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client, =20 /* Check Oscillator Failure flag */ error =3D bq32k_read(dev, ®, BQ32K_MINUTES, 1); - if (!error && (reg & BQ32K_OF)) { - dev_warn(dev, "Oscillator Failure. Check RTC battery.\n"); - reg &=3D ~BQ32K_OF; - error =3D bq32k_write(dev, ®, BQ32K_MINUTES, 1); - } if (error) return error; + if (reg & BQ32K_OF) + dev_warn(dev, "Oscillator Failure. Check RTC battery.\n"); =20 if (client->dev.of_node) trickle_charger_of_init(dev, client->dev.of_node); --=20 2.7.4 --=20 You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. ---=20 You received this message because you are subscribed to the Google Groups "= rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to rtc-linux+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.