-
Notifications
You must be signed in to change notification settings - Fork 1.7k
(pcf8523) hwclock: ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument #1065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's a comprehensive explanation of the problem. My summary would be: Some PCF8523 RTC modules lose time, probably due to electrical issues when switching between external power and backup battery. When this happens, the read function returns an error rather than return an incorrect value, even though the error may be small. The device obviously has no way of knowing how much time elapses during the down time, hence the boolean right/wrong status. I have some sympathy for the author of the patch that introduced this behaviour, but if the oscillator stopping briefly is a regular occurrence on some boards then perhaps the error should be made optional. I'm prepared to add a Device Tree property to revert to the old behaviour, with an overlay parameter to enable it, if that is acceptable. |
I've been thinking some more about this, checking how other RTC kernel drivers implement the 'clock integrity' thing. Most of them return an error when the integrity cannot be assured (or the battery is low), as it is currently implemented in the rtc-pfc8523 driver. Theory Reality Removing the OS check fixed my problem in short term, so I'm open for any solution. Edit: if the rtc-pfc8523 driver is loaded, the fake-hwclock is ignored it seems, so the issue is worse than a fake-hwclock-only situation. |
I'm inclined to agree. There are at least two other RTC drivers that just log a warning under similar conditions, but there are others that return -EINVAL. As you are currently the only person to have reported this problem I'll leave the current (error) behaviour as the default. |
My understanding (and observation) is that the RTC module is more sensitive at the high-Z pins of the oscillator than to corruption of internal registers. So any disturbance may skip or add a few cycles in the oscillator, but register contents are not affected by the 0.7 V/ms requirement. Below I'll add the instructions to recompile the module so anyone with similar findings may check the workaround. |
Details for recompiling the rtc-pfc8523 module without OS (oscillator stop) check.
|
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
After oscillating a few times between DT property and module parameter I settled for reverting the original commit. |
That is due to negative feedback, or a second pole below the unity gain freq. ;-) |
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]> Signed-off-by: ahmedradaideh <[email protected]>
kernel: Revert Revert net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends See: raspberrypi/linux#2659 kernel: config: Add CONFIG_USBIP_VUDC See: #353 kernel: mmc/bcm2835-sdhost: Recover from MMC_SEND_EXT_CSD See: raspberrypi/linux#2728 kernel: overlays: pi3-disable-bt: Clear out bt_pins node kernel: Revert rtc: pcf8523: properly handle oscillator stop bit See: #1065 bootcode: Extend TEST_UNIT_READY timeout to 20 seconds, some hard drives take a really long time See: #898 firmware: video_render: Treat an empty buffer with ENDOFFRAME set as a flush firmware: dispmanx: Add option to ignore all layers lower than the current layer
kernel: Revert Revert net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends See: raspberrypi/linux#2659 kernel: config: Add CONFIG_USBIP_VUDC See: raspberrypi/firmware#353 kernel: mmc/bcm2835-sdhost: Recover from MMC_SEND_EXT_CSD See: raspberrypi/linux#2728 kernel: overlays: pi3-disable-bt: Clear out bt_pins node kernel: Revert rtc: pcf8523: properly handle oscillator stop bit See: raspberrypi/firmware#1065 bootcode: Extend TEST_UNIT_READY timeout to 20 seconds, some hard drives take a really long time See: raspberrypi/firmware#898 firmware: video_render: Treat an empty buffer with ENDOFFRAME set as a flush firmware: dispmanx: Add option to ignore all layers lower than the current layer
Latest rpi-update kernel contains this revert. |
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
TL;DR: The Adafruit PCF8523 Real Time Clock for Raspberry Pi loses time due to a combination of issues in (1) the pcf8523 chip, (2) the pcb design and the (3) rtc-pcf8523 kernel module. Here is why:
(Note: this is a technical explanation, so that anyone with similar experiences won't have to reinvent the wheel.)
Hardware (multiple devices were tested)
Setup
The module is loaded either with
dtoverlay i2c-rtc pcf8523=true
or at boot time usingdtoverlay=i2c-rtc,pcf8523
in /boot/config.txt, as explained here.Result
Then, the RTC is initialized using
hwclock --systohc --utc
orhwclock -w
.At this point the RTC works and can be checked with
timedatectl
orhwclock -r
. So far so good.Problem
The pcf8523 clock module looses time every once in a while (read time failed). On a reboot, on unplugging the power or even just by waiting long enough (10 minutes, sometimes days).
The purpose of a battery-backupped hw clock however is to keep time, especially on power loss.
Diagnosis
Origin of the
ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument
error.The origin can be tracked down to this commit and these 2 lines of code:
https://github.com/raspberrypi/linux/blob/961aa2356a25ad04528e91761e7081a25dc983dc/drivers/rtc/rtc-pcf8523.c#L181-L182
In short: the rtc-pcf8523 driver checks if the REG_SECONDS_OS flag is set. If it is set, the
Invalid argument
error is produced.According to the datasheet, the REG_SECONDS_OS flag indicates that
So, now the question is why it stops on multiple devices and intermittent times. According to the datasheet:
So, glitches on the power supply rails are not warmly welcomed by this IC. For this, the datasheet also has a solution:
Back to the Adafruit module:

According to the schematic there should be a 10uF capacitor on this board, however in reality it looks rather 100nF, i.e. not enough to guarantee the 0.7 V/ms and thus causing a VDD-to-battery failover failure.
Workaround
Further info
Detect the pcf_8523 module:
i2cdetect -y 1
Read the raw register contents:
i2cdump -y -f -r 0-15 1 0x68
Example output:
Register 0x03 contains the REG_SECONDS_OS flag at bit 7. When it is set the
Invalid argument
error occurs,hwclock -r
stops working while the timestamp provided by the IC is still ok.The text was updated successfully, but these errors were encountered: