From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Marek Vasut <marex@denx.de>,
kernel@pengutronix.de, linux-rtc@vger.kernel.org
Subject: [PATCH 4/5] rtc: ds1307: rx8130: honor Voltage Loss Flag when reading the time
Date: Fri, 25 Jan 2019 15:35:57 +0100 [thread overview]
Message-ID: <20190125143558.27450-4-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20190125143558.27450-1-u.kleine-koenig@pengutronix.de>
When voltage dropped since the RTC was last set the reported time is not
reliable. In this case return an error indicator instead of a bogus
time.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/rtc/rtc-ds1307.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 81e20653700d..974eafda9de4 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -194,6 +194,20 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
const struct chip_desc *chip = &chips[ds1307->type];
u8 regs[7];
+ if (ds1307->type == rx_8130) {
+ unsigned int regflag;
+ ret = regmap_read(ds1307->regmap, RX8130_REG_FLAG, ®flag);
+ if (ret) {
+ dev_err(dev, "%s error %d\n", "read", ret);
+ return ret;
+ }
+
+ if (regflag & RX8130_REG_FLAG_VLF) {
+ dev_warn_once(dev, "oscillator failed, set time!\n");
+ return -EINVAL;
+ }
+ }
+
/* read the RTC date and time registers all at once */
ret = regmap_bulk_read(ds1307->regmap, chip->offset, regs,
sizeof(regs));
@@ -293,6 +307,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
dev_err(dev, "%s error %d\n", "write", result);
return result;
}
+
+ if (ds1307->type == rx_8130) {
+ /* clear Voltage Loss Flag as data is available now */
+ result = regmap_write(ds1307->regmap, RX8130_REG_FLAG,
+ ~(u8)RX8130_REG_FLAG_VLF);
+ if (result) {
+ dev_err(dev, "%s error %d\n", "write", result);
+ return result;
+ }
+ }
+
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2019-01-25 14:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 14:35 [PATCH 1/5] rtc: ds1307: Move register definitions to start of file Uwe Kleine-König
2019-01-25 14:35 ` [PATCH 2/5] rtc: ds1307: forward declare chips array instead of a bunch of functions Uwe Kleine-König
2019-01-25 14:35 ` [PATCH 3/5] rtc: ds1307: correct register offset for rx8130 Uwe Kleine-König
2019-01-25 14:35 ` Uwe Kleine-König [this message]
2019-01-25 14:35 ` [PATCH 5/5] rtc: ds1307: rx8130: Fix alarm handling Uwe Kleine-König
2019-02-07 20:37 ` [PATCH 1/5] rtc: ds1307: Move register definitions to start of file Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190125143558.27450-4-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=alexandre.belloni@free-electrons.com \
--cc=kernel@pengutronix.de \
--cc=linux-rtc@vger.kernel.org \
--cc=marex@denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).