All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabien Lahoudere <fabien.lahoudere@collabora.co.uk>
To: alexandre.belloni@free-electrons.com, a.zummo@towertech.it
Cc: rtc-linux@googlegroups.com,
	Fabien Lahoudere <fabien.lahoudere@collabora.co.uk>
Subject: [rtc-linux] [PATCH 1/2] RTC: s35390a: handle invalid RTC time
Date: Thu, 12 Jan 2017 11:43:37 +0100	[thread overview]
Message-ID: <1484217818-27845-2-git-send-email-fabien.lahoudere@collabora.co.uk> (raw)
In-Reply-To: <1484217818-27845-1-git-send-email-fabien.lahoudere@collabora.co.uk>

If RTC time have been altered by low voltage, we notify users
that RTC time is invalid by returning -EINVAL.
The RTC time needs to be set correctly to clear the invalid flag.
If the RTC is not set before restarting, the information will be lost.

Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.co.uk>
---
 drivers/rtc/rtc-s35390a.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index 5dab466..ef4ada9 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -62,6 +62,7 @@ struct s35390a {
 	struct i2c_client *client[8];
 	struct rtc_device *rtc;
 	int twentyfourhour;
+	int isinvalid;
 };
 
 static int s35390a_set_reg(struct s35390a *s35390a, int reg, char *buf, int len)
@@ -135,6 +136,8 @@ static int s35390a_reset(struct s35390a *s35390a, char *status1)
 	 * The 24H bit is kept over reset, so set it already here.
 	 */
 initialize:
+	/* set the RTC time as invalid */
+	s35390a->isinvalid = 1;
 	*status1 = S35390A_FLAG_24H;
 	buf = S35390A_FLAG_RESET | S35390A_FLAG_24H;
 	ret = s35390a_set_reg(s35390a, S35390A_CMD_STATUS1, &buf, 1);
@@ -221,6 +224,8 @@ static int s35390a_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 		buf[i] = bitrev8(buf[i]);
 
 	err = s35390a_set_reg(s35390a, S35390A_CMD_TIME1, buf, sizeof(buf));
+	if (err >= 0)
+		s35390a->isinvalid = 0;
 
 	return err;
 }
@@ -231,6 +236,9 @@ static int s35390a_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 	char buf[7];
 	int i, err;
 
+	if (s35390a->isinvalid)
+		return -EINVAL;
+
 	err = s35390a_get_reg(s35390a, S35390A_CMD_TIME1, buf, sizeof(buf));
 	if (err < 0)
 		return err;
@@ -418,6 +426,7 @@ static int s35390a_probe(struct i2c_client *client,
 
 	s35390a->client[0] = client;
 	i2c_set_clientdata(client, s35390a);
+	s35390a->isinvalid = 0;
 
 	/* This chip uses multiple addresses, use dummy devices for them */
 	for (i = 1; i < 8; ++i) {
-- 
1.8.3.1

-- 
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.
--- 
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 email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2017-01-12 10:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-12 10:43 [rtc-linux] [PATCH 0/2] Improve low voltage or invalid time detection Fabien Lahoudere
2017-01-12 10:43 ` Fabien Lahoudere [this message]
2017-01-16 17:50   ` [rtc-linux] Re: [PATCH 1/2] RTC: s35390a: handle invalid RTC time Alexandre Belloni
2017-01-17  8:24     ` Fabien Lahoudere
2017-01-17 11:00       ` Alexandre Belloni
2017-06-26  9:51         ` Fabien Lahoudere
2017-06-29  7:56           ` Alexandre Belloni
2017-07-04  8:55             ` Fabien Lahoudere
2017-07-04 11:19               ` Alexandre Belloni
2017-01-12 10:43 ` [rtc-linux] [PATCH 2/2] RTC: s35390a: implement ioctls Fabien Lahoudere
2017-01-16 17:48   ` [rtc-linux] " 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=1484217818-27845-2-git-send-email-fabien.lahoudere@collabora.co.uk \
    --to=fabien.lahoudere@collabora.co.uk \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=rtc-linux@googlegroups.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.