From patchwork Tue Aug 4 09:45:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 503472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x23a.google.com (mail-wi0-x23a.google.com [IPv6:2a00:1450:400c:c05::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 11FDB140321 for ; Tue, 4 Aug 2015 19:45:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=AGD8l/oE; dkim-atps=neutral Received: by wibdx1 with SMTP id dx1sf2221742wib.0 for ; Tue, 04 Aug 2015 02:45:47 -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:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:content-type:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=64wce1r1UsnzJwNYojiz2QnO1OWd3gx360OFkxzlyQQ=; b=AGD8l/oE7OKM73jpd+WkCeqePR0yiXoMs51629TgtjhfUPDgdgzosNk3aQCIf/Pm/T gCsMv5pfzNVMY1WeLVvQ38hGs/6nWtUEX4C4Hb2hm+REeFj8sGs3EOE77JcAstSeLiV1 iJ31FiboAkXeIxKwFr7tY53VDU7XTBisFd20EtughPHRrOf59nJjDTfH87GO9Kj+PEkn +V/M5zIcZgK8BeLhVqYWvOmqope+QZonynsIj9bFxNwBpC54GUk/Qny79DJPjd4wz2PZ YD/HL1PO6qmiVjC3pUbeUaxNsSlKSZIhmdnBgSu0NQqqUcLU28E6eX5fF5hLw0mvNF/e CGdQ== X-Received: by 10.180.97.167 with SMTP id eb7mr92392wib.6.1438681547811; Tue, 04 Aug 2015 02:45:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.35.193 with SMTP id k1ls883990wij.25.canary; Tue, 04 Aug 2015 02:45:47 -0700 (PDT) X-Received: by 10.194.19.33 with SMTP id b1mr860717wje.6.1438681547462; Tue, 04 Aug 2015 02:45:47 -0700 (PDT) Received: from mail.free-electrons.com (down.free-electrons.com. [37.187.137.238]) by gmr-mx.google.com with ESMTP id jf3si51225wic.0.2015.08.04.02.45.47 for ; Tue, 04 Aug 2015 02:45:47 -0700 (PDT) Received-SPF: pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) client-ip=37.187.137.238; Received: by mail.free-electrons.com (Postfix, from userid 106) id 0D47A6AB; Tue, 4 Aug 2015 11:45:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (128-79-216-6.hfc.dyn.abo.bbox.fr [128.79.216.6]) by mail.free-electrons.com (Postfix) with ESMTPSA id 6EE27DEA; Tue, 4 Aug 2015 11:45:42 +0200 (CEST) From: Alexandre Belloni To: rtc-linux@googlegroups.com Cc: Alessandro Zummo , linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [rtc-linux] [PATCH 08/15] rtc: rx8025: don't reset the time Date: Tue, 4 Aug 2015 11:45:27 +0200 Message-Id: <1438681534-12027-9-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438681534-12027-1-git-send-email-alexandre.belloni@free-electrons.com> References: <1438681534-12027-1-git-send-email-alexandre.belloni@free-electrons.com> X-Original-Sender: alexandre.belloni@free-electrons.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) smtp.mail=alexandre.belloni@free-electrons.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Stop setting the time to epoch when it is invalid. The proper way to handle that is to return an error when it is invalid instead of returning an incorrect value. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-rx8025.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c index 771558602409..d158a640299e 100644 --- a/drivers/rtc/rtc-rx8025.c +++ b/drivers/rtc/rtc-rx8025.c @@ -166,9 +166,23 @@ out: static int rx8025_get_time(struct device *dev, struct rtc_time *dt) { struct rx8025_data *rx8025 = dev_get_drvdata(dev); - u8 date[7]; + u8 date[7], ctrl; int err; + err = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2, &ctrl); + if (err) + return err; + + if (ctrl & RX8025_BIT_CTRL2_PON) { + dev_warn(dev, "power-on reset detected, date is invalid\n"); + return -EINVAL; + } + + if (!(ctrl & RX8025_BIT_CTRL2_XST)) { + dev_warn(dev, "crystal stopped, date is invalid\n"); + return -EINVAL; + } + err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date); if (err) return err; @@ -230,7 +244,7 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date); } -static int rx8025_init_client(struct i2c_client *client, int *need_reset) +static int rx8025_init_client(struct i2c_client *client) { struct rx8025_data *rx8025 = i2c_get_clientdata(client); u8 ctrl[2], ctrl2; @@ -247,19 +261,19 @@ static int rx8025_init_client(struct i2c_client *client, int *need_reset) if (ctrl[1] & RX8025_BIT_CTRL2_PON) { dev_warn(&client->dev, "power-on reset was detected, " "you may have to readjust the clock\n"); - *need_reset = 1; + need_clear = 1; } if (ctrl[1] & RX8025_BIT_CTRL2_VDET) { dev_warn(&client->dev, "a power voltage drop was detected, " "you may have to readjust the clock\n"); - *need_reset = 1; + need_clear = 1; } if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) { dev_warn(&client->dev, "Oscillation stop was detected," "you may have to readjust the clock\n"); - *need_reset = 1; + need_clear = 1; } if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) { @@ -270,7 +284,7 @@ static int rx8025_init_client(struct i2c_client *client, int *need_reset) if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG)) need_clear = 1; - if (*need_reset || need_clear) { + if (need_clear) { ctrl2 = ctrl[0]; ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET | RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG | @@ -508,7 +522,7 @@ static int rx8025_probe(struct i2c_client *client, { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct rx8025_data *rx8025; - int err = 0, need_reset = 0; + int err = 0; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) { @@ -525,18 +539,10 @@ static int rx8025_probe(struct i2c_client *client, rx8025->client = client; i2c_set_clientdata(client, rx8025); - err = rx8025_init_client(client, &need_reset); + err = rx8025_init_client(client); if (err) return err; - if (need_reset) { - struct rtc_time tm; - dev_info(&client->dev, - "bad conditions detected, resetting date\n"); - rtc_time_to_tm(0, &tm); /* 1970/1/1 */ - rx8025_set_time(&client->dev, &tm); - } - rx8025->rtc = devm_rtc_device_register(&client->dev, client->name, &rx8025_rtc_ops, THIS_MODULE); if (IS_ERR(rx8025->rtc)) {