drivers: QMSI RTC: simplify driver reentrancy code using IS_ENABLED
This is one of the series of patches that simplifies the driver code by using the IS_ENABLED macro. This removes the need of the const variable and the wrapper functions on semaphore APIs. Jira: ZEP-1251 Change-Id: I84a09a0aaa3a00452d8c2b4bca7be0f6b2015218 Signed-off-by: Kuo-Lang Tseng <kuo-lang.tseng@intel.com>
This commit is contained in:
parent
74f7da1bb4
commit
8bf14d380b
1 changed files with 11 additions and 33 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <rtc.h>
|
||||
#include <power.h>
|
||||
#include <soc.h>
|
||||
#include <misc/util.h>
|
||||
|
||||
#include "qm_isr.h"
|
||||
#include "qm_rtc.h"
|
||||
|
@ -37,10 +38,8 @@ static struct rtc_data rtc_context;
|
|||
#endif /* RTC_HAS_CONTEXT_DATA */
|
||||
|
||||
#ifdef CONFIG_RTC_QMSI_API_REENTRANCY
|
||||
static const int reentrancy_protection = 1;
|
||||
#define RP_GET(dev) (&((struct rtc_data *)(dev->driver_data))->sem)
|
||||
#else
|
||||
static const int reentrancy_protection;
|
||||
#define RP_GET(dev) (NULL)
|
||||
#endif
|
||||
|
||||
|
@ -63,34 +62,6 @@ static uint32_t rtc_qmsi_get_power_state(struct device *dev)
|
|||
#define rtc_qmsi_set_power_state(...)
|
||||
#endif
|
||||
|
||||
static void rtc_reentrancy_init(struct device *dev)
|
||||
{
|
||||
if (!reentrancy_protection) {
|
||||
return;
|
||||
}
|
||||
|
||||
k_sem_init(RP_GET(dev), 0, UINT_MAX);
|
||||
k_sem_give(RP_GET(dev));
|
||||
}
|
||||
|
||||
static void rtc_critical_region_start(struct device *dev)
|
||||
{
|
||||
if (!reentrancy_protection) {
|
||||
return;
|
||||
}
|
||||
|
||||
k_sem_take(RP_GET(dev), K_FOREVER);
|
||||
}
|
||||
|
||||
static void rtc_critical_region_end(struct device *dev)
|
||||
{
|
||||
if (!reentrancy_protection) {
|
||||
return;
|
||||
}
|
||||
|
||||
k_sem_give(RP_GET(dev));
|
||||
}
|
||||
|
||||
static void rtc_qmsi_enable(struct device *dev)
|
||||
{
|
||||
clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK);
|
||||
|
@ -124,13 +95,17 @@ static int rtc_qmsi_set_config(struct device *dev, struct rtc_config *cfg)
|
|||
*/
|
||||
qm_cfg.prescaler = (clk_rtc_div_t)RTC_DIVIDER;
|
||||
|
||||
rtc_critical_region_start(dev);
|
||||
if (IS_ENABLED(CONFIG_RTC_QMSI_API_REENTRANCY)) {
|
||||
k_sem_take(RP_GET(dev), K_FOREVER);
|
||||
}
|
||||
|
||||
if (qm_rtc_set_config(QM_RTC_0, &qm_cfg)) {
|
||||
result = -EIO;
|
||||
}
|
||||
|
||||
rtc_critical_region_end(dev);
|
||||
if (IS_ENABLED(CONFIG_RTC_QMSI_API_REENTRANCY)) {
|
||||
k_sem_give(RP_GET(dev));
|
||||
}
|
||||
|
||||
k_busy_wait(60);
|
||||
|
||||
|
@ -163,7 +138,10 @@ static const struct rtc_driver_api api = {
|
|||
|
||||
static int rtc_qmsi_init(struct device *dev)
|
||||
{
|
||||
rtc_reentrancy_init(dev);
|
||||
if (IS_ENABLED(CONFIG_RTC_QMSI_API_REENTRANCY)) {
|
||||
k_sem_init(RP_GET(dev), 0, UINT_MAX);
|
||||
k_sem_give(RP_GET(dev));
|
||||
}
|
||||
|
||||
IRQ_CONNECT(IRQ_GET_NUMBER(QM_IRQ_RTC_0_INT), CONFIG_RTC_0_IRQ_PRI,
|
||||
qm_rtc_0_isr, NULL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue