Patchwork Fix the rx8581 setdatetime

login
register
mail settings
Submitter Rudolf Marek
Date July 15, 2010, 9:12 a.m.
Message ID <4C3ED0E2.10905@sysgo.com>
Download mbox | patch
Permalink /patch/58968/
State New
Headers show

Comments

Rudolf Marek - July 15, 2010, 9:12 a.m.
Hello,

This patch fixes the logic while writing new date/time to the chip. The
driver incorrectly written back register values to different registers
and even with wrong mask. The patch adds clearing of the VLF register,
which should be cleared if all date/time values are set.

Signed-off-by: Rudolf Marek <rudolf.marek@sysgo.com>

I'm attaching this as an attachment because Thunderbird will break it otherwise.
For your reference, datasheet is here:

http://www.epsontoyocom.co.jp/english/product/RTC/set03/ra8581sa/index.html

Thanks,
Rudolf
Wan ZongShun - July 15, 2010, 9:45 a.m.
2010/7/15 Rudolf Marek <rudolf.marek@sysgo.com>:
> Hello,
>
> This patch fixes the logic while writing new date/time to the chip. The
> driver incorrectly written back register values to different registers
> and even with wrong mask. The patch adds clearing of the VLF register,
> which should be cleared if all date/time values are set.
>
> Signed-off-by: Rudolf Marek <rudolf.marek@sysgo.com>
>
> I'm attaching this as an attachment because Thunderbird will break it

Not everyone has time and willing to download your patch for reviewing,
so why not try to setting your Thunderbird to solve this break?

Anyway, this is a good patch, thanks!

Acked-by: Wan ZongShun <mcuos.com@gmail.com>

> otherwise.
> For your reference, datasheet is here:
>
> http://www.epsontoyocom.co.jp/english/product/RTC/set03/ra8581sa/index.html
>
> Thanks,
> Rudolf
>
> --
>
> S přátelským pozdravem / Best regards / Mit freundlichen Grüßen
>
> Ing. Rudolf Marek
> SYSGO s.r.o.
> Zelený pruh 99
> CZ-14800 Praha 4
> Phone: +420 222138 627, +49 6136 9948 627
> Fax: +420 296374890, +49 6136 9948 1 627
> rudolf.marek@sysgo.com
>
> http://www.sysgo.com | http://www.elinos.com | http://www.pikeos.com
>
> --
> 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.
>

Patch

This patch fixes the logic while writing new date/time to the chip. The
driver incorrectly written back register values to different registers
and even with wrong mask. The patch adds clearing of the VLF register,
which should be cleared if all date/time values are set.

Signed-off-by: Rudolf Marek <rudolf.marek@sysgo.com>

Index: linux/drivers/rtc/rtc-rx8581.c
===================================================================
--- linux.orig/drivers/rtc/rtc-rx8581.c	2010-07-12 11:21:27.000000000 +0200
+++ linux/drivers/rtc/rtc-rx8581.c	2010-07-12 12:30:01.000000000 +0200
@@ -168,7 +168,7 @@ 
 		return -EIO;
 	}
 
-	err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG,
+	err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL,
 		(data | RX8581_CTRL_STOP));
 	if (err < 0) {
 		dev_err(&client->dev, "Unable to write control register\n");
@@ -182,6 +182,20 @@ 
 		return -EIO;
 	}
 
+	/* get VLF and clear it */
+	data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG);
+	if (data < 0) {
+		dev_err(&client->dev, "Unable to read flag register\n");
+		return -EIO;
+	}
+
+	err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG,
+		(data & ~(RX8581_FLAG_VLF)));
+	if (err != 0) {
+		dev_err(&client->dev, "Unable to write flag register\n");
+		return -EIO;
+	}
+
 	/* Restart the clock */
 	data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL);
 	if (data < 0) {
@@ -189,8 +203,8 @@ 
 		return -EIO;
 	}
 
-	err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG,
-		(data | ~(RX8581_CTRL_STOP)));
+	err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL,
+		(data & ~(RX8581_CTRL_STOP)));
 	if (err != 0) {
 		dev_err(&client->dev, "Unable to write control register\n");
 		return -EIO;