drivers: rtc: stm32: Fixes RTC issues related to device runtime pm

When device runtime pm is enabled, Backup Domain protection is active
most of the time. RTC driver need this protection to be disabled in
order to set the time or calibration. This fix disable the protection in
set time and set calibration functions.

Fixes: 62843
Signed-off-by: Petr Hlineny <development@hlineny.cz>
This commit is contained in:
Petr Hlineny 2023-11-23 17:02:37 +01:00 committed by Carles Cufí
commit 4a4543569e

View file

@ -181,6 +181,10 @@ static int rtc_stm32_init(const struct device *dev)
err = rtc_stm32_configure(dev);
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
return err;
}
@ -208,10 +212,18 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
}
LOG_INF("Setting clock");
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_EnableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
LL_RTC_DisableWriteProtection(RTC);
err = rtc_stm32_enter_initialization_mode(true);
if (err) {
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
k_mutex_unlock(&data->lock);
return err;
}
@ -237,6 +249,10 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
LL_RTC_EnableWriteProtection(RTC);
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
k_mutex_unlock(&data->lock);
return err;
@ -359,12 +375,20 @@ static int rtc_stm32_set_calibration(const struct device *dev, int32_t calibrati
return -EIO;
}
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_EnableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
LL_RTC_DisableWriteProtection(RTC);
MODIFY_REG(RTC->CALR, RTC_CALR_CALP | RTC_CALR_CALM, calp | calm);
LL_RTC_EnableWriteProtection(RTC);
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
return 0;
}