]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/rtc/rtc-rx8581.c
drivers/rtc/rtc-rx8581.c: fix setdatetime
[net-next-2.6.git] / drivers / rtc / rtc-rx8581.c
index 9718aaaa821534c876240e1f254166f800bbbd7f..600b890a3c150f926be508633c49436cfae1b113 100644 (file)
@@ -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");
@@ -182,6 +182,20 @@ 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) {
@@ -189,8 +203,8 @@ 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,
-               (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;