From: Emanuele Ghidoli emanuele.ghidoli@toradex.com
Hi,
I am submitting two patches related to the RX8310 RTC configuration:
1. **Correct RX8310 RTC Features Configuration:** - Sets one-minute alarm resolution. - Disables update IRQ.
Without this patch, if the interrupt is configured in the device tree, `hwclock` fails to read the RTC as it waits for the update IRQ.
2. **Avoid rtctest Alarm Test Failures:** - Ensures rtctest alarm tests do not fail on hardware that only supports one-minute alarm resolution.
I know the second patch creates conflict with this one: https://lore.kernel.org/all/20240524013807.154338-1-jjang@nvidia.com/. I think that series can reuse the rtc_get_features function I implemented.
Best regards, Emanuele Ghidoli
Emanuele Ghidoli (2): rtc: ds1307: set one-minute alarm resolution for rx_8130 selftests: rtc: rtctest: skip alarm test if alarm resolution is one minute
drivers/rtc/rtc-ds1307.c | 14 +++++++++++-- tools/testing/selftests/rtc/rtctest.c | 30 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-)
From: Emanuele Ghidoli emanuele.ghidoli@toradex.com
Set one-minute alarm resolution for the rx_8130 by setting the RTC_FEATURE_ALARM_RES_MINUTE flag according to the hw capabilities.
Additionally, set the no_upd_irq flag to disable update interrupts, as it is not possible to generate update IRQs. hwclock fails reading the date and time if the no update irq flag is not set and IRQs is defined in DT.
Signed-off-by: Emanuele Ghidoli emanuele.ghidoli@toradex.com --- drivers/rtc/rtc-ds1307.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 506b7d1c2397..96e4d82ad915 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -181,6 +181,8 @@ struct ds1307 {
struct chip_desc { unsigned alarm:1; + unsigned alarm_res_min:1; + unsigned no_upd_irq:1; u16 nvram_offset; u16 nvram_size; u8 offset; /* register's offset */ @@ -1015,6 +1017,8 @@ static const struct chip_desc chips[last_ds_type] = { }, [rx_8130] = { .alarm = 1, + .alarm_res_min = 1, + .no_upd_irq = 1, /* this is battery backed SRAM */ .nvram_offset = 0x20, .nvram_size = 4, /* 32bit (4 word x 8 bit) */ @@ -1946,10 +1950,16 @@ static int ds1307_probe(struct i2c_client *client) if (IS_ERR(ds1307->rtc)) return PTR_ERR(ds1307->rtc);
- if (want_irq || ds1307_can_wakeup_device) + if (want_irq || ds1307_can_wakeup_device) { device_set_wakeup_capable(ds1307->dev, true); - else + if (chip->alarm_res_min) + set_bit(RTC_FEATURE_ALARM_RES_MINUTE, ds1307->rtc->features); + } else { clear_bit(RTC_FEATURE_ALARM, ds1307->rtc->features); + } + + if (chip->no_upd_irq) + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, ds1307->rtc->features);
if (ds1307_can_wakeup_device && !want_irq) { dev_info(ds1307->dev,
From: Emanuele Ghidoli emanuele.ghidoli@toradex.com
There are two types of alarm tests: one that tests alarms on minute boundaries and another that tests alarms on second boundaries. For RTCs with one-minute resolution, only the minute boundary test should be run. Skip the second boundary alarm test for these RTCs.
Signed-off-by: Emanuele Ghidoli emanuele.ghidoli@toradex.com --- tools/testing/selftests/rtc/rtctest.c | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index 63ce02d1d5cc..d741a548ef76 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -82,6 +82,22 @@ static void nanosleep_with_retries(long ns) } }
+static int rtc_get_features(int fd, uint64_t *features) +{ + struct rtc_param param = { 0 }; + int rc; + + param.param = RTC_PARAM_FEATURES; + param.index = 0; + rc = ioctl(fd, RTC_PARAM_GET, ¶m); + if (rc < 0) + return rc; + + *features = param.uvalue; + + return 0; +} + TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) { int rc; long iter_count = 0; @@ -197,6 +213,13 @@ TEST_F(rtc, alarm_alm_set) { fd_set readfds; time_t secs, new; int rc; + int rc_feat; + uint64_t rtc_feat; + + rc_feat = rtc_get_features(self->fd, &rtc_feat); + + if (!rc_feat && (rtc_feat & _BITUL(RTC_FEATURE_ALARM_RES_MINUTE))) + SKIP(return, "Skipping test since only one minute resolution alarms are supported.");
if (self->fd == -1 && errno == ENOENT) SKIP(return, "Skipping test since %s does not exist", rtc_file); @@ -255,6 +278,13 @@ TEST_F(rtc, alarm_wkalm_set) { fd_set readfds; time_t secs, new; int rc; + int rc_feat; + uint64_t rtc_feat; + + rc_feat = rtc_get_features(self->fd, &rtc_feat); + + if (!rc_feat && (rtc_feat & _BITUL(RTC_FEATURE_ALARM_RES_MINUTE))) + SKIP(return, "Skipping test since only one minute resolution alarms are supported.");
if (self->fd == -1 && errno == ENOENT) SKIP(return, "Skipping test since %s does not exist", rtc_file);
linux-kselftest-mirror@lists.linaro.org