summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>2015-08-04 11:33:59 +0200
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2015-09-05 13:19:12 +0200
commitefbbb4fd6b6fe0d3d2cfb3c5bbcdf00f1995cb60 (patch)
tree9f7822eaf64ffbc15e64840da6d275ba53a14c60 /drivers/rtc
parent5c66e1e0b79bd63dcdfbc03b80823522643a1f14 (diff)
rtc: rx8025: check time validity when necessary
Check time validity when reading time as this is when we need to know. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-rx8025.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index f3f1de26c228..24c3d69ce1b9 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -104,6 +104,31 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
length, values);
}
+static int rx8025_check_validity(struct device *dev)
+{
+ struct rx8025_data *rx8025 = dev_get_drvdata(dev);
+ int ctrl2;
+
+ ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
+ if (ctrl2 < 0)
+ return ctrl2;
+
+ if (ctrl2 & RX8025_BIT_CTRL2_VDET)
+ dev_warn(dev, "power voltage drop detected\n");
+
+ if (ctrl2 & RX8025_BIT_CTRL2_PON) {
+ dev_warn(dev, "power-on reset detected, date is invalid\n");
+ return -EINVAL;
+ }
+
+ if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) {
+ dev_warn(dev, "crystal stopped, date is invalid\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int rx8025_reset_validity(struct i2c_client *client)
{
int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
@@ -154,21 +179,11 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
{
struct rx8025_data *rx8025 = dev_get_drvdata(dev);
u8 date[7];
- int ctrl, err;
-
- ctrl = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
- if (ctrl < 0)
- return ctrl;
-
- if (ctrl & RX8025_BIT_CTRL2_PON) {
- dev_warn(dev, "power-on reset detected, date is invalid\n");
- return -EINVAL;
- }
+ int err;
- if (!(ctrl & RX8025_BIT_CTRL2_XST)) {
- dev_warn(dev, "crystal stopped, date is invalid\n");
- return -EINVAL;
- }
+ err = rx8025_check_validity(dev);
+ if (err)
+ return err;
err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
if (err)
@@ -250,21 +265,6 @@ static int rx8025_init_client(struct i2c_client *client)
/* Keep test bit zero ! */
rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
- if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
- dev_warn(&client->dev, "power-on reset was detected, "
- "you may have to readjust the clock\n");
- }
-
- if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
- dev_warn(&client->dev, "a power voltage drop was detected, "
- "you may have to readjust the clock\n");
- }
-
- if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
- dev_warn(&client->dev, "Oscillation stop was detected,"
- "you may have to readjust the clock\n");
- }
-
if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
dev_warn(&client->dev, "Alarm was detected\n");
need_clear = 1;