Comments
Patch
@@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
}
}
+static int snvs_rtc_enable_done(void __iomem *ioaddr, bool enable)
+{
+ u32 lpcr = readl(ioaddr + SNVS_LPCR);
+
+ return enable ^ !(lpcr & SNVS_LPCR_SRTC_ENV);
+}
+
static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
{
unsigned long timeout = jiffies + msecs_to_jiffies(1);
@@ -99,18 +106,15 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
spin_unlock_irqrestore(&data->lock, flags);
while (1) {
- lpcr = readl(data->ioaddr + SNVS_LPCR);
+ if (snvs_rtc_enable_done(data->ioaddr, enable))
+ break;
- if (enable) {
- if (lpcr & SNVS_LPCR_SRTC_ENV)
- break;
- } else {
- if (!(lpcr & SNVS_LPCR_SRTC_ENV))
+ if (time_after(jiffies, timeout)) {
+ if (snvs_rtc_enable_done(data->ioaddr, enable))
break;
+ else
+ return -ETIMEDOUT;
}
-
- if (time_after(jiffies, timeout))
- return -ETIMEDOUT;
}
return 0;