aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-ab-b5ze-s3.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c
index 65de9cf4a48d..ef895ae431c1 100644
--- a/drivers/rtc/rtc-ab-b5ze-s3.c
+++ b/drivers/rtc/rtc-ab-b5ze-s3.c
@@ -438,28 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
438{ 438{
439 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); 439 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
440 struct rtc_time *alarm_tm = &alarm->time; 440 struct rtc_time *alarm_tm = &alarm->time;
441 unsigned long rtc_secs, alarm_secs;
442 u8 regs[ABB5ZES3_ALRM_SEC_LEN]; 441 u8 regs[ABB5ZES3_ALRM_SEC_LEN];
443 struct rtc_time rtc_tm; 442 struct rtc_time rtc_tm;
444 int ret, enable = 1; 443 int ret, enable = 1;
445 444
446 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); 445 if (!alarm->enabled) {
447 if (ret)
448 return ret;
449
450 rtc_secs = rtc_tm_to_time64(&rtc_tm);
451 alarm_secs = rtc_tm_to_time64(alarm_tm);
452
453 /* If alarm time is before current time, disable the alarm */
454 if (!alarm->enabled || alarm_secs <= rtc_secs) {
455 enable = 0; 446 enable = 0;
456 } else { 447 } else {
448 unsigned long rtc_secs, alarm_secs;
449
457 /* 450 /*
458 * Chip only support alarms up to one month in the future. Let's 451 * Chip only support alarms up to one month in the future. Let's
459 * return an error if we get something after that limit. 452 * return an error if we get something after that limit.
460 * Comparison is done by incrementing rtc_tm month field by one 453 * Comparison is done by incrementing rtc_tm month field by one
461 * and checking alarm value is still below. 454 * and checking alarm value is still below.
462 */ 455 */
456 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
457 if (ret)
458 return ret;
459
463 if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ 460 if (rtc_tm.tm_mon == 11) { /* handle year wrapping */
464 rtc_tm.tm_mon = 0; 461 rtc_tm.tm_mon = 0;
465 rtc_tm.tm_year += 1; 462 rtc_tm.tm_year += 1;
@@ -468,6 +465,7 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
468 } 465 }
469 466
470 rtc_secs = rtc_tm_to_time64(&rtc_tm); 467 rtc_secs = rtc_tm_to_time64(&rtc_tm);
468 alarm_secs = rtc_tm_to_time64(alarm_tm);
471 469
472 if (alarm_secs > rtc_secs) { 470 if (alarm_secs > rtc_secs) {
473 dev_err(dev, "%s: alarm maximum is one month in the " 471 dev_err(dev, "%s: alarm maximum is one month in the "