Skip to content

Commit efbbb4f

Browse files
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 <[email protected]>
1 parent 5c66e1e commit efbbb4f

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

drivers/rtc/rtc-rx8025.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
104104
length, values);
105105
}
106106

107+
static int rx8025_check_validity(struct device *dev)
108+
{
109+
struct rx8025_data *rx8025 = dev_get_drvdata(dev);
110+
int ctrl2;
111+
112+
ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
113+
if (ctrl2 < 0)
114+
return ctrl2;
115+
116+
if (ctrl2 & RX8025_BIT_CTRL2_VDET)
117+
dev_warn(dev, "power voltage drop detected\n");
118+
119+
if (ctrl2 & RX8025_BIT_CTRL2_PON) {
120+
dev_warn(dev, "power-on reset detected, date is invalid\n");
121+
return -EINVAL;
122+
}
123+
124+
if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) {
125+
dev_warn(dev, "crystal stopped, date is invalid\n");
126+
return -EINVAL;
127+
}
128+
129+
return 0;
130+
}
131+
107132
static int rx8025_reset_validity(struct i2c_client *client)
108133
{
109134
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)
154179
{
155180
struct rx8025_data *rx8025 = dev_get_drvdata(dev);
156181
u8 date[7];
157-
int ctrl, err;
158-
159-
ctrl = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
160-
if (ctrl < 0)
161-
return ctrl;
162-
163-
if (ctrl & RX8025_BIT_CTRL2_PON) {
164-
dev_warn(dev, "power-on reset detected, date is invalid\n");
165-
return -EINVAL;
166-
}
182+
int err;
167183

168-
if (!(ctrl & RX8025_BIT_CTRL2_XST)) {
169-
dev_warn(dev, "crystal stopped, date is invalid\n");
170-
return -EINVAL;
171-
}
184+
err = rx8025_check_validity(dev);
185+
if (err)
186+
return err;
172187

173188
err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
174189
if (err)
@@ -250,21 +265,6 @@ static int rx8025_init_client(struct i2c_client *client)
250265
/* Keep test bit zero ! */
251266
rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
252267

253-
if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
254-
dev_warn(&client->dev, "power-on reset was detected, "
255-
"you may have to readjust the clock\n");
256-
}
257-
258-
if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
259-
dev_warn(&client->dev, "a power voltage drop was detected, "
260-
"you may have to readjust the clock\n");
261-
}
262-
263-
if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
264-
dev_warn(&client->dev, "Oscillation stop was detected,"
265-
"you may have to readjust the clock\n");
266-
}
267-
268268
if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
269269
dev_warn(&client->dev, "Alarm was detected\n");
270270
need_clear = 1;

0 commit comments

Comments
 (0)