@@ -127,6 +127,7 @@ struct abx80x_priv {
struct rtc_device *rtc;
struct i2c_client *client;
struct watchdog_device wdog;
+ bool wrote_time;
};
static int abx80x_write_config_key(struct i2c_client *client, u8 key)
@@ -179,6 +180,7 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client,
static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct i2c_client *client = to_i2c_client(dev);
+ struct abx80x_priv *priv = i2c_get_clientdata(client);
unsigned char buf[8];
int err, flags, rc_mode = 0;
@@ -193,7 +195,18 @@ static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
return flags;
if (flags & ABX8XX_OSS_OF) {
- dev_err(dev, "Oscillator failure, data is invalid.\n");
+ /*
+ * The OF bit can be set either because of a reset
+ * (POR/Software reset) or because of an oscillator
+ * failure. Effectively, it indicates that the stored
+ * time is invalid. When we write the time, we clear
+ * this bit. If it stays set, then this indicates an
+ * oscillator failure.
+ */
+ if (priv->wrote_time)
+ dev_err(dev, "Oscillator failure\n");
+ else
+ dev_info(dev, "Time data invalid\n");
return -EINVAL;
}
}
@@ -219,6 +232,7 @@ static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct i2c_client *client = to_i2c_client(dev);
+ struct abx80x_priv *priv = i2c_get_clientdata(client);
unsigned char buf[8];
int err, flags;
@@ -252,6 +266,7 @@ static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
dev_err(&client->dev, "Unable to write oscillator status register\n");
return err;
}
+ priv->wrote_time = true;
return 0;
}