diff options
author | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2015-08-04 05:33:59 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2015-09-05 07:19:12 -0400 |
commit | efbbb4fd6b6fe0d3d2cfb3c5bbcdf00f1995cb60 (patch) | |
tree | 9f7822eaf64ffbc15e64840da6d275ba53a14c60 /drivers/rtc | |
parent | 5c66e1e0b79bd63dcdfbc03b80823522643a1f14 (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.c | 58 |
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, | |||
104 | length, values); | 104 | length, values); |
105 | } | 105 | } |
106 | 106 | ||
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 | |||
107 | static int rx8025_reset_validity(struct i2c_client *client) | 132 | static int rx8025_reset_validity(struct i2c_client *client) |
108 | { | 133 | { |
109 | int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); | 134 | 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) | |||
154 | { | 179 | { |
155 | struct rx8025_data *rx8025 = dev_get_drvdata(dev); | 180 | struct rx8025_data *rx8025 = dev_get_drvdata(dev); |
156 | u8 date[7]; | 181 | u8 date[7]; |
157 | int ctrl, err; | 182 | int 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 | } | ||
167 | 183 | ||
168 | if (!(ctrl & RX8025_BIT_CTRL2_XST)) { | 184 | err = rx8025_check_validity(dev); |
169 | dev_warn(dev, "crystal stopped, date is invalid\n"); | 185 | if (err) |
170 | return -EINVAL; | 186 | return err; |
171 | } | ||
172 | 187 | ||
173 | err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date); | 188 | err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date); |
174 | if (err) | 189 | if (err) |
@@ -250,21 +265,6 @@ static int rx8025_init_client(struct i2c_client *client) | |||
250 | /* Keep test bit zero ! */ | 265 | /* Keep test bit zero ! */ |
251 | rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST; | 266 | rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST; |
252 | 267 | ||
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 | |||
268 | if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) { | 268 | if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) { |
269 | dev_warn(&client->dev, "Alarm was detected\n"); | 269 | dev_warn(&client->dev, "Alarm was detected\n"); |
270 | need_clear = 1; | 270 | need_clear = 1; |