What is the likelihood that CMOS_WRITE will not work?

I was puzzled by the RTC problem for several days: I could not write to the RTC register.

The following is a snippet of code, and the value that I read from reg (the last line) is always different from what I just wrote in reg. Can anyone help me figure this out?

    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 the linux 2.6 kernel, and the platforms I tried were PPC and x86.

UPDATE: more code snippets per Amardeep 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);
+3
source share
1 answer

RTC? RTC, , "" , / , "" , . .

, , , , ?

0

Source: https://habr.com/ru/post/1750947/


All Articles