File tree 1 file changed +22
-3
lines changed
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -181,8 +181,28 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
181
181
if (err < 0 )
182
182
return err ;
183
183
184
- if (regs [0 ] & REG_SECONDS_OS )
185
- return - EINVAL ;
184
+ if (regs [0 ] & REG_SECONDS_OS ) {
185
+ /*
186
+ * If the oscillator was stopped, try to clear the flag. Upon
187
+ * power-up the flag is always set, but if we cannot clear it
188
+ * the oscillator isn't running properly for some reason. The
189
+ * sensible thing therefore is to return an error, signalling
190
+ * that the clock cannot be assumed to be correct.
191
+ */
192
+
193
+ regs [0 ] &= ~REG_SECONDS_OS ;
194
+
195
+ err = pcf8523_write (client , REG_SECONDS , regs [0 ]);
196
+ if (err < 0 )
197
+ return err ;
198
+
199
+ err = pcf8523_read (client , REG_SECONDS , & regs [0 ]);
200
+ if (err < 0 )
201
+ return err ;
202
+
203
+ if (regs [0 ] & REG_SECONDS_OS )
204
+ return - EAGAIN ;
205
+ }
186
206
187
207
tm -> tm_sec = bcd2bin (regs [0 ] & 0x7f );
188
208
tm -> tm_min = bcd2bin (regs [1 ] & 0x7f );
@@ -218,7 +238,6 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
218
238
return err ;
219
239
220
240
regs [0 ] = REG_SECONDS ;
221
- /* This will purposely overwrite REG_SECONDS_OS */
222
241
regs [1 ] = bin2bcd (tm -> tm_sec );
223
242
regs [2 ] = bin2bcd (tm -> tm_min );
224
243
regs [3 ] = bin2bcd (tm -> tm_hour );
You can’t perform that action at this time.
0 commit comments