Skip to content

Commit 00c3092

Browse files
groeckalexandrebelloni
authored andcommitted
rtc: cros-ec: Detect and report supported alarm window size
The RTC on some older Chromebooks can only handle alarms less than 24 hours in the future. The only way to find out is to try to set an alarm further in the future. If that fails, assume that the RTC connected to the EC can only handle less than 24 hours of alarm window, and report that value to the RTC core. After that change, it is no longer necessary to limit the alarm time when setting it. Report any excessive alarms to the caller instead. Cc: Brian Norris <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 781589e commit 00c3092

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

drivers/rtc/rtc-cros-ec.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,15 @@ static int cros_ec_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
182182

183183
ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset);
184184
if (ret < 0) {
185-
if (ret == -EINVAL && alarm_offset >= SECS_PER_DAY) {
186-
/*
187-
* RTC chips on some older Chromebooks can only handle
188-
* alarms up to 24h in the future. Try to set an alarm
189-
* below that limit to avoid suspend failures.
190-
*/
191-
ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM,
192-
SECS_PER_DAY - 1);
193-
}
194-
195-
if (ret < 0) {
196-
dev_err(dev, "error setting alarm in %u seconds: %d\n",
197-
alarm_offset, ret);
198-
return ret;
199-
}
185+
dev_err(dev, "error setting alarm in %u seconds: %d\n",
186+
alarm_offset, ret);
187+
/*
188+
* The EC code returns -EINVAL if the alarm time is too
189+
* far in the future. Convert it to the expected error code.
190+
*/
191+
if (ret == -EINVAL)
192+
ret = -ERANGE;
193+
return ret;
200194
}
201195

202196
return 0;
@@ -355,6 +349,20 @@ static int cros_ec_rtc_probe(struct platform_device *pdev)
355349
cros_ec_rtc->rtc->ops = &cros_ec_rtc_ops;
356350
cros_ec_rtc->rtc->range_max = U32_MAX;
357351

352+
/*
353+
* The RTC on some older Chromebooks can only handle alarms less than
354+
* 24 hours in the future. The only way to find out is to try to set an
355+
* alarm further in the future. If that fails, assume that the RTC
356+
* connected to the EC can only handle less than 24 hours of alarm
357+
* window.
358+
*/
359+
ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, SECS_PER_DAY * 2);
360+
if (ret == -EINVAL)
361+
cros_ec_rtc->rtc->alarm_offset_max = SECS_PER_DAY - 1;
362+
363+
(void)cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM,
364+
EC_RTC_ALARM_CLEAR);
365+
358366
ret = devm_rtc_register_device(cros_ec_rtc->rtc);
359367
if (ret)
360368
return ret;

0 commit comments

Comments
 (0)