@@ -100,6 +100,7 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
100
100
{
101
101
struct pcf8523 * pcf8523 = dev_get_drvdata (dev );
102
102
u8 regs [10 ];
103
+ u32 value ;
103
104
int err ;
104
105
105
106
err = regmap_bulk_read (pcf8523 -> regmap , PCF8523_REG_CONTROL1 , regs ,
@@ -110,6 +111,33 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
110
111
if ((regs [0 ] & PCF8523_CONTROL1_STOP ) || (regs [3 ] & PCF8523_SECONDS_OS ))
111
112
return - EINVAL ;
112
113
114
+ if (regs [0 ] & PCF8523_SECONDS_OS ) {
115
+ /*
116
+ * If the oscillator was stopped, try to clear the flag. Upon
117
+ * power-up the flag is always set, but if we cannot clear it
118
+ * the oscillator isn't running properly for some reason. The
119
+ * sensible thing therefore is to return an error, signalling
120
+ * that the clock cannot be assumed to be correct.
121
+ */
122
+
123
+ regs [0 ] &= ~PCF8523_SECONDS_OS ;
124
+
125
+ err = regmap_write (pcf8523 -> regmap , PCF8523_REG_SECONDS ,
126
+ regs [0 ]);
127
+ if (err < 0 )
128
+ return err ;
129
+
130
+ err = regmap_read (pcf8523 -> regmap , PCF8523_REG_SECONDS ,
131
+ & value );
132
+ if (err < 0 )
133
+ return err ;
134
+
135
+ if (value & PCF8523_SECONDS_OS )
136
+ return - EAGAIN ;
137
+
138
+ regs [0 ] = value ;
139
+ }
140
+
113
141
tm -> tm_sec = bcd2bin (regs [3 ] & 0x7f );
114
142
tm -> tm_min = bcd2bin (regs [4 ] & 0x7f );
115
143
tm -> tm_hour = bcd2bin (regs [5 ] & 0x3f );
0 commit comments