CMOS_WRITE无法正常工作的可能原因是什么?

时间:2010-06-21 01:22:45

标签: linux linux-kernel interrupt kernel-module

我好几天都对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);

1 个答案:

答案 0 :(得分:0)

具体的RTC芯片是什么?大多数RTC,你必须翻转一下才能在读/写寄存器组时“暂停”它,然后在完成时“取消暂停”它。通常,您希望尽快完成此操作。

您是否也检查了芯片文档以确保您要写入的特定寄存器是否允许写入?