几天来,我一直对 RTC 问题感到困惑:我无法写入 RTC 寄存器。
以下是代码片段,我从 reg(最后一行)读取的值总是与我刚刚写入 reg 的值不同。任何人都可以帮助我理解这一点吗?
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
我使用的是 linux 2.6 内核,我尝试的平台是 PPC 和 x86。
更新: 每个 Amardeep 的评论有更多的代码片段......
/* disable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control &= ~RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
CMOS_READ(RTC_INTR_FLAGS);
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
/* ...... */
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
/* Enable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control |= RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
/* read the flags register to start interrupts */
CMOS_READ(RTC_INTR_FLAGS);