All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit@wsystem.com>
To: rtc-linux@googlegroups.com
Cc: linux-kernel@vger.kernel.org,
	"Alessandro Zummo" <a.zummo@towertech.it>,
	"Alexandre Belloni" <alexandre.belloni@free-electrons.com>,
	"Benoît Thébaudeau" <benoit@wsystem.com>
Subject: [PATCH 5/6] rtc: rv8803: Stop the clock while setting the time
Date: Thu, 21 Jul 2016 12:41:31 +0200	[thread overview]
Message-ID: <1469097692-103146-5-git-send-email-benoit@wsystem.com> (raw)
In-Reply-To: <1469097692-103146-1-git-send-email-benoit@wsystem.com>

According to the application manual of the RX8900, the RESET bit must be
set to 1 to prevent a timer update while setting the time. This also
resets the subsecond counter. The application manual of the RV-8803 does
not mention such a requirement, and it says that the 100th Seconds
register is cleared when writing to the Seconds register, but using the
RESET bit for the RV-8803 too should not be an issue and is probably
safer.

This change also ensures that the RESET bit is initialized properly in
all cases. Indeed, all the registers must be initialized if the voltage
has been lower than VLOW2 (triggering V2F), but not low enough to
trigger a POR.

Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
---
 drivers/rtc/rtc-rv8803.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 09ab5cb..24c688e 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -223,11 +223,21 @@ static int rv8803_set_time(struct device *dev, struct rtc_time *tm)
 {
 	struct rv8803_data *rv8803 = dev_get_drvdata(dev);
 	u8 date[7];
-	int flags, ret;
+	int ctrl, flags, ret;
 
 	if ((tm->tm_year < 100) || (tm->tm_year > 199))
 		return -EINVAL;
 
+	ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL);
+	if (ctrl < 0)
+		return ctrl;
+
+	/* Stop the clock */
+	ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
+			       ctrl | RV8803_CTRL_RESET);
+	if (ret)
+		return ret;
+
 	date[RV8803_SEC]   = bin2bcd(tm->tm_sec);
 	date[RV8803_MIN]   = bin2bcd(tm->tm_min);
 	date[RV8803_HOUR]  = bin2bcd(tm->tm_hour);
@@ -240,6 +250,12 @@ static int rv8803_set_time(struct device *dev, struct rtc_time *tm)
 	if (ret)
 		return ret;
 
+	/* Restart the clock */
+	ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
+			       ctrl & ~RV8803_CTRL_RESET);
+	if (ret)
+		return ret;
+
 	mutex_lock(&rv8803->flags_lock);
 
 	flags = rv8803_read_reg(rv8803->client, RV8803_FLAG);
-- 
2.5.0

WARNING: multiple messages have this Message-ID (diff)
From: "Benoît Thébaudeau" <benoit@wsystem.com>
To: rtc-linux@googlegroups.com
Cc: linux-kernel@vger.kernel.org,
	"Alessandro Zummo" <a.zummo@towertech.it>,
	"Alexandre Belloni" <alexandre.belloni@free-electrons.com>,
	"Benoît Thébaudeau" <benoit@wsystem.com>
Subject: [rtc-linux] [PATCH 5/6] rtc: rv8803: Stop the clock while setting the time
Date: Thu, 21 Jul 2016 12:41:31 +0200	[thread overview]
Message-ID: <1469097692-103146-5-git-send-email-benoit@wsystem.com> (raw)
In-Reply-To: <1469097692-103146-1-git-send-email-benoit@wsystem.com>

According to the application manual of the RX8900, the RESET bit must be
set to 1 to prevent a timer update while setting the time. This also
resets the subsecond counter. The application manual of the RV-8803 does
not mention such a requirement, and it says that the 100th Seconds
register is cleared when writing to the Seconds register, but using the
RESET bit for the RV-8803 too should not be an issue and is probably
safer.

This change also ensures that the RESET bit is initialized properly in
all cases. Indeed, all the registers must be initialized if the voltage
has been lower than VLOW2 (triggering V2F), but not low enough to
trigger a POR.

Signed-off-by: Beno=C3=AEt Th=C3=A9baudeau <benoit@wsystem.com>
---
 drivers/rtc/rtc-rv8803.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 09ab5cb..24c688e 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -223,11 +223,21 @@ static int rv8803_set_time(struct device *dev, struct=
 rtc_time *tm)
 {
 	struct rv8803_data *rv8803 =3D dev_get_drvdata(dev);
 	u8 date[7];
-	int flags, ret;
+	int ctrl, flags, ret;
=20
 	if ((tm->tm_year < 100) || (tm->tm_year > 199))
 		return -EINVAL;
=20
+	ctrl =3D rv8803_read_reg(rv8803->client, RV8803_CTRL);
+	if (ctrl < 0)
+		return ctrl;
+
+	/* Stop the clock */
+	ret =3D rv8803_write_reg(rv8803->client, RV8803_CTRL,
+			       ctrl | RV8803_CTRL_RESET);
+	if (ret)
+		return ret;
+
 	date[RV8803_SEC]   =3D bin2bcd(tm->tm_sec);
 	date[RV8803_MIN]   =3D bin2bcd(tm->tm_min);
 	date[RV8803_HOUR]  =3D bin2bcd(tm->tm_hour);
@@ -240,6 +250,12 @@ static int rv8803_set_time(struct device *dev, struct =
rtc_time *tm)
 	if (ret)
 		return ret;
=20
+	/* Restart the clock */
+	ret =3D rv8803_write_reg(rv8803->client, RV8803_CTRL,
+			       ctrl & ~RV8803_CTRL_RESET);
+	if (ret)
+		return ret;
+
 	mutex_lock(&rv8803->flags_lock);
=20
 	flags =3D rv8803_read_reg(rv8803->client, RV8803_FLAG);
--=20
2.5.0

--=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.

  parent reply	other threads:[~2016-07-21 10:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21 10:41 [PATCH 1/6] rtc: rv8803: Kconfig: Indicate rx8900 support Benoît Thébaudeau
2016-07-21 10:41 ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 10:41 ` [PATCH 2/6] rtc: rv8803: Remove the check for valid time Benoît Thébaudeau
2016-07-21 10:41   ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 10:41 ` [PATCH 3/6] rtc: rv8803: Fix read day of week Benoît Thébaudeau
2016-07-21 10:41   ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 10:41 ` [PATCH 4/6] rtc: rv8803: Always apply the I²C workaround Benoît Thébaudeau
2016-07-21 10:41   ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 11:10   ` Alexandre Belloni
2016-07-21 11:10     ` [rtc-linux] " Alexandre Belloni
2016-07-21 12:34     ` Benoît Thébaudeau
2016-07-21 12:34       ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 18:30     ` Benoît Thébaudeau
2016-07-21 18:30       ` [rtc-linux] " Benoît Thébaudeau
2016-07-21 10:41 ` Benoît Thébaudeau [this message]
2016-07-21 10:41   ` [rtc-linux] [PATCH 5/6] rtc: rv8803: Stop the clock while setting the time Benoît Thébaudeau
2016-07-21 10:41 ` [PATCH 6/6] rtc: rv8803: Clear V1F when " Benoît Thébaudeau
2016-07-21 10:41   ` [rtc-linux] " Benoît Thébaudeau
2016-07-28  8:00 ` [PATCH 1/6] rtc: rv8803: Kconfig: Indicate rx8900 support Alexandre Belloni
2016-07-28  8:00   ` [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=1469097692-103146-5-git-send-email-benoit@wsystem.com \
    --to=benoit@wsystem.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=linux-kernel@vger.kernel.org \
    --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.