I've been puzzled by a RTC problem for several days: i couldn't write to the RTC register.
Following is the code snippet and the value I read from the reg(last line) is always different from what i just wrote to the reg. Anyone can help me understand this ?
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));
I am using linux 2.6 kernel and the platforms i tried were PPC and x86.
UPDATE: more code snippets per Amardeep's comment...
/* 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);