Skip to content

Commit 7efd885

Browse files
jakubtopicnashif
authored andcommitted
drivers: rtc: update alarm_set_callback to return ENOTSUP
This commit addresses the issue related to the rtc.h API returning ENOSYS for a driver not implementing alarm_set_callback when the ALARM functionality is enabled but interrupts, and thus alarm callbacks, are not supported by the current configuration. The following drivers have been modified to return correct code: - rtc_pcf8523 - rtc_pcf8563 - rtc_rv3028 Signed-off-by: Jakub Topic <[email protected]>
1 parent 3de1747 commit 7efd885

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

drivers/rtc/rtc_pcf8523.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,17 @@ static int pcf8523_alarm_is_pending(const struct device *dev, uint16_t id)
581581
return err;
582582
}
583583

584-
#if PCF8523_INT1_GPIOS_IN_USE
585584
static int pcf8523_alarm_set_callback(const struct device *dev, uint16_t id,
586585
rtc_alarm_callback callback, void *user_data)
587586
{
587+
#ifndef PCF8523_INT1_GPIOS_IN_USE
588+
ARG_UNUSED(dev);
589+
ARG_UNUSED(id);
590+
ARG_UNUSED(callback);
591+
ARG_UNUSED(user_data);
592+
593+
return -ENOTSUP;
594+
#else
588595
const struct pcf8523_config *config = dev->config;
589596
struct pcf8523_data *data = dev->data;
590597
uint8_t control_1;
@@ -638,8 +645,8 @@ static int pcf8523_alarm_set_callback(const struct device *dev, uint16_t id,
638645
k_sem_give(&data->int1_sem);
639646

640647
return err;
641-
}
642648
#endif /* PCF8523_INT1_GPIOS_IN_USE */
649+
}
643650
#endif /* CONFIG_RTC_ALARM */
644651

645652
#if PCF8523_INT1_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE)
@@ -928,9 +935,7 @@ static const struct rtc_driver_api pcf8523_driver_api = {
928935
.alarm_set_time = pcf8523_alarm_set_time,
929936
.alarm_get_time = pcf8523_alarm_get_time,
930937
.alarm_is_pending = pcf8523_alarm_is_pending,
931-
#if PCF8523_INT1_GPIOS_IN_USE
932938
.alarm_set_callback = pcf8523_alarm_set_callback,
933-
#endif /* PCF8523_INT1_GPIOS_IN_USE */
934939
#endif /* CONFIG_RTC_ALARM */
935940
#if PCF8523_INT1_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE)
936941
.update_set_callback = pcf8523_update_set_callback,

drivers/rtc/rtc_pcf8563.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,19 @@ void gpio_callback_function(const struct device *dev, struct gpio_callback *cb,
380380

381381
}
382382

383+
#endif
384+
383385
static int pcf8563_alarm_set_callback(const struct device *dev, uint16_t id,
384386
rtc_alarm_callback callback, void *user_data)
385387
{
388+
#ifndef PCF8563_INT1_GPIOS_IN_USE
389+
ARG_UNUSED(dev);
390+
ARG_UNUSED(id);
391+
ARG_UNUSED(callback);
392+
ARG_UNUSED(user_data);
393+
394+
return -ENOTSUP;
395+
#else
386396
const struct pcf8563_config *config = dev->config;
387397
struct pcf8563_data *data = dev->data;
388398
int ret;
@@ -416,8 +426,8 @@ static int pcf8563_alarm_set_callback(const struct device *dev, uint16_t id,
416426
gpio_add_callback(config->int1.port, &data->int1_callback);
417427
LOG_DBG("Alarm set");
418428
return 0;
419-
}
420429
#endif
430+
}
421431

422432
static const struct rtc_driver_api pcf8563_driver_api = {
423433
.set_time = pcf8563_set_time,
@@ -427,10 +437,8 @@ static const struct rtc_driver_api pcf8563_driver_api = {
427437
.alarm_set_time = pcf8563_alarm_set_time,
428438
.alarm_get_time = pcf8563_alarm_get_time,
429439
.alarm_is_pending = pcf8563_alarm_is_pending,
430-
#ifdef PCF8563_INT1_GPIOS_IN_USE
431440
.alarm_set_callback = pcf8563_alarm_set_callback,
432441
#endif
433-
#endif
434442
};
435443

436444

drivers/rtc/rtc_rv3028.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,17 @@ static int rv3028_alarm_is_pending(const struct device *dev, uint16_t id)
711711
return err;
712712
}
713713

714-
#if RV3028_INT_GPIOS_IN_USE
715-
716714
static int rv3028_alarm_set_callback(const struct device *dev, uint16_t id,
717715
rtc_alarm_callback callback, void *user_data)
718716
{
717+
#ifndef RV3028_INT_GPIOS_IN_USE
718+
ARG_UNUSED(dev);
719+
ARG_UNUSED(id);
720+
ARG_UNUSED(callback);
721+
ARG_UNUSED(user_data);
722+
723+
return -ENOTSUP;
724+
#else
719725
const struct rv3028_config *config = dev->config;
720726
struct rv3028_data *data = dev->data;
721727
uint8_t control_2;
@@ -766,9 +772,9 @@ static int rv3028_alarm_set_callback(const struct device *dev, uint16_t id,
766772
k_work_submit(&data->work);
767773

768774
return err;
775+
#endif /* RV3028_INT_GPIOS_IN_USE */
769776
}
770777

771-
#endif /* RV3028_INT_GPIOS_IN_USE */
772778
#endif /* CONFIG_RTC_ALARM */
773779

774780
#if RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE)
@@ -952,9 +958,7 @@ static const struct rtc_driver_api rv3028_driver_api = {
952958
.alarm_set_time = rv3028_alarm_set_time,
953959
.alarm_get_time = rv3028_alarm_get_time,
954960
.alarm_is_pending = rv3028_alarm_is_pending,
955-
#if RV3028_INT_GPIOS_IN_USE
956961
.alarm_set_callback = rv3028_alarm_set_callback,
957-
#endif /* RV3028_INT_GPIOS_IN_USE */
958962
#endif /* CONFIG_RTC_ALARM */
959963
#if RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE)
960964
.update_set_callback = rv3028_update_set_callback,

0 commit comments

Comments
 (0)