Skip to content

Commit

Permalink
drivers/rtc/rtc-rx8581.c: fix setdatetime
Browse files Browse the repository at this point in the history
Fix the logic while writing new date/time to the chip.  The driver
incorrectly wrote 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 <[email protected]>
Acked-by: Wan ZongShun <[email protected]>
Cc: Martyn Welch <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Rudolf Marek authored and torvalds committed Jul 27, 2010
1 parent b82bab4 commit 2884fce
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions drivers/rtc/rtc-rx8581.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
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");
Expand All @@ -182,15 +182,29 @@ static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
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) {
dev_err(&client->dev, "Unable to read control register\n");
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;
Expand Down

0 comments on commit 2884fce

Please sign in to comment.