AnsweredAssumed Answered

iMX6 SRTC cannot set time

Question asked by Jeffrey Chang on Mar 16, 2018
Latest reply on Mar 29, 2018 by Jeffrey Chang

I have enabled CONFIG_RTC_DRV_SNVS configuration to build the SNVS SRTC driver "rtc-snvs.c" in my Android project. When the system boots up, I can see SRTC is working, the command "cat /sys/class/rtc/rtc1/time" returns the time. However when I try to set time from Android, it calls snvs_rtc_set_time() to set the time and the call hangs in the infinite loop waiting for SRTC to be re-enabled. Why does this happen? How to fix it?

 

int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct rtc_drv_data *pdata = dev_get_drvdata(dev);
void __iomem *ioaddr = pdata->ioaddr;
unsigned long time;
int ret;
u32 lp_cr;
u64 old_time_47bit, new_time_47bit;

printk("+-+-+-+-%s\n", __FUNCTION__);

ret = rtc_tm_to_time(tm, &time);
if (ret != 0)
return ret;

old_time_47bit = (((u64) (__raw_readl(ioaddr + SNVS_LPSRTCMR) &
((0x1 << CNTR_TO_SECS_SH) - 1)) << 32) |
((u64) __raw_readl(ioaddr + SNVS_LPSRTCLR)));

/* Disable RTC first */
lp_cr = __raw_readl(ioaddr + SNVS_LPCR) & ~SNVS_LPCR_SRTC_ENV;
__raw_writel(lp_cr, ioaddr + SNVS_LPCR);
printk("1\n");
while (__raw_readl(ioaddr + SNVS_LPCR) & SNVS_LPCR_SRTC_ENV)
;

/* Write 32-bit time to 47-bit timer, leaving 15 LSBs blank */
__raw_writel(time << CNTR_TO_SECS_SH, ioaddr + SNVS_LPSRTCLR);
__raw_writel(time >> (32 - CNTR_TO_SECS_SH), ioaddr + SNVS_LPSRTCMR);

/* Enable RTC again */
__raw_writel(lp_cr | SNVS_LPCR_SRTC_ENV, ioaddr + SNVS_LPCR);
printk("2\n");
while (!(__raw_readl(ioaddr + SNVS_LPCR) & SNVS_LPCR_SRTC_ENV)) // hangs here
;

 

.

.

.

}

Outcomes