diff mbox series

[3/3] rtc: rtc_update_irq_enable: rework UIE emulation

Message ID 20210330000343.801566-3-alexandre.belloni@bootlin.com
State Superseded
Headers show
Series [1/3] rtc: ds1307: replace HAS_ALARM by RTC_FEATURE_ALARM | expand

Commit Message

Alexandre Belloni March 30, 2021, 12:03 a.m. UTC
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.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/interface.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

Comments

Łukasz Stelmach April 2, 2021, 10:28 a.m. UTC | #1
It was <2021-03-30 wto 02:03>, when Alexandre Belloni wrote:
> 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.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/interface.c | 28 +++++++---------------------
>  1 file changed, 7 insertions(+), 21 deletions(-)
>

Tested-by: Łukasz Stelmach <l.stelmach@samsung.com>

> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index dcb34c73319e..b162964d2b39 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -561,8 +561,12 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
>  	if (rtc->uie_rtctimer.enabled == enabled)
>  		goto out;
>  
> -	if (rtc->uie_unsupported) {
> +	if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) {
> +#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
> +		err = rtc_dev_update_irq_enable_emul(rtc, enabled);
> +#else
>  		err = -EINVAL;
> +#endif
>  		goto out;
>  	}
>  
> @@ -570,8 +574,8 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
>  		struct rtc_time tm;
>  		ktime_t now, onesec;
>  
> -		rc = __rtc_read_time(rtc, &tm);
> -		if (rc)
> +		err = __rtc_read_time(rtc, &tm);
> +		if (err)
>  			goto out;
>  		onesec = ktime_set(1, 0);
>  		now = rtc_tm_to_ktime(tm);
> @@ -585,24 +589,6 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
>  out:
>  	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;
>  }
>  EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
diff mbox series

Patch

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index dcb34c73319e..b162964d2b39 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -561,8 +561,12 @@  int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
 	if (rtc->uie_rtctimer.enabled == enabled)
 		goto out;
 
-	if (rtc->uie_unsupported) {
+	if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) {
+#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
+		err = rtc_dev_update_irq_enable_emul(rtc, enabled);
+#else
 		err = -EINVAL;
+#endif
 		goto out;
 	}
 
@@ -570,8 +574,8 @@  int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
 		struct rtc_time tm;
 		ktime_t now, onesec;
 
-		rc = __rtc_read_time(rtc, &tm);
-		if (rc)
+		err = __rtc_read_time(rtc, &tm);
+		if (err)
 			goto out;
 		onesec = ktime_set(1, 0);
 		now = rtc_tm_to_ktime(tm);
@@ -585,24 +589,6 @@  int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
 out:
 	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;
 }
 EXPORT_SYMBOL_GPL(rtc_update_irq_enable);