summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2017-09-24 11:32:52 +0100
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>2022-05-23 16:41:11 +0100
commitecc787d936cfc7dafaf675ecac8cfb13410c1134 (patch)
tree4c3b969d1cec2681328a38c32c2358c4751d585d
parentbc24295f9a91e7b67b3f088e471acc9629143fec (diff)
rtc: pcf8523: provide set_offset_nsec
When we set the time, we set the STOP bit, set the time, and then clear the STOP bit. Concerning the timing, the PCF8523 data sheet says: "The first increment of the time circuits is between 0.499878s and 0.500000s after STOP is released." However, practical measurement shows this is not the case - with the I2C bus speed at 100kHz on iMX6, it takes about 5ms for the rtclib call for setting the time to complete. However, reading back when the second actually flips shows that there's an additional 10ms which can't be accounted for by the read - a read of the RTC takes 1.7 to 1.8 ms. Practical measurement shows that the first increment occurs about 515ms after the write, which means we need to set the current second 485ms after it has started. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
-rw-r--r--drivers/rtc/rtc-pcf8523.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index b1b1943de844..cb5d6878a8bd 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -371,6 +371,16 @@ static int pcf8523_rtc_set_offset(struct device *dev, long offset)
return regmap_write(pcf8523->regmap, PCF8523_REG_OFFSET, value);
}
+static void pcf8523_rtc_pre_register(struct rtc_device *rtc)
+{
+ /*
+ * "The first increment of the time circuits is between 0.499878s
+ * and 0.5s after STOP is released. Measurement on iMX6 show that
+ * -485ms gives a time set within +/- 5ms.
+ */
+ rtc->set_offset_nsec = -495 * NSEC_PER_MSEC;
+}
+
static const struct rtc_class_ops pcf8523_rtc_ops = {
.read_time = pcf8523_rtc_read_time,
.set_time = pcf8523_rtc_set_time,
@@ -382,6 +392,7 @@ static const struct rtc_class_ops pcf8523_rtc_ops = {
.set_offset = pcf8523_rtc_set_offset,
.param_get = pcf8523_param_get,
.param_set = pcf8523_param_set,
+ .pre_register = pcf8523_rtc_pre_register,
};
static const struct regmap_config regmap_config = {