3
幾天來我一直困擾於RTC問題:我無法寫入RTC寄存器。CMOS_WRITE無法正常工作的原因是什麼?
以下是代碼片段,我從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。
UPDATE:每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);