Commit c55c3a51 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: rtc_update_irq_enable: rework UIE emulation

Now that the core is aware of whether alarms are available, it is possible
to decide whether UIE emulation is required before actually trying to set
the alarm.

This greatly simplifies rtc_update_irq_enable because there is now only one
error value to track and is not relying on the return value of
__rtc_set_alarm anymore.
Tested-by: default avatarŁukasz Stelmach <l.stelmach@samsung.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210418000023.995758-3-alexandre.belloni@bootlin.com
parent 4bf84b44
...@@ -545,7 +545,7 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); ...@@ -545,7 +545,7 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable);
int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
{ {
int rc = 0, err; int err;
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
...@@ -561,17 +561,21 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) ...@@ -561,17 +561,21 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
if (rtc->uie_rtctimer.enabled == enabled) if (rtc->uie_rtctimer.enabled == enabled)
goto out; goto out;
if (rtc->uie_unsupported) { if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) {
err = -EINVAL; mutex_unlock(&rtc->ops_lock);
goto out; #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
return rtc_dev_update_irq_enable_emul(rtc, enabled);
#else
return -EINVAL;
#endif
} }
if (enabled) { if (enabled) {
struct rtc_time tm; struct rtc_time tm;
ktime_t now, onesec; ktime_t now, onesec;
rc = __rtc_read_time(rtc, &tm); err = __rtc_read_time(rtc, &tm);
if (rc) if (err)
goto out; goto out;
onesec = ktime_set(1, 0); onesec = ktime_set(1, 0);
now = rtc_tm_to_ktime(tm); now = rtc_tm_to_ktime(tm);
...@@ -585,24 +589,6 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) ...@@ -585,24 +589,6 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
out: out:
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
/*
* __rtc_read_time() failed, this probably means that the RTC time has
* never been set or less probably there is a transient error on the
* bus. In any case, avoid enabling emulation has this will fail when
* reading the time too.
*/
if (rc)
return rc;
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
/*
* Enable emulation if the driver returned -EINVAL to signal that it has
* been configured without interrupts or they are not available at the
* moment.
*/
if (err == -EINVAL)
err = rtc_dev_update_irq_enable_emul(rtc, enabled);
#endif
return err; return err;
} }
EXPORT_SYMBOL_GPL(rtc_update_irq_enable); EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment