drivers: rtc_qmsi: Move rtc driver apis to unified interface
patch modifies rtc apis to unified interface. Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
This commit is contained in:
parent
9cd7803579
commit
aa15f3973a
6 changed files with 88 additions and 43 deletions
|
@ -8,5 +8,6 @@ zephyr_library_sources_ifdef(CONFIG_COUNTER_DTMR_CMSDK_APB counter_dtmr_cmsdk_ap
|
|||
zephyr_library_sources_ifdef(CONFIG_TIMER_DTMR_CMSDK_APB timer_dtmr_cmsdk_apb.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_COUNTER_NRF_TIMER counter_nrfx_timer.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_COUNTER_NRF_RTC counter_nrfx_rtc.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_RTC_QMSI counter_rtc_qmsi.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE counter_handlers.c)
|
||||
|
|
|
@ -43,3 +43,26 @@ config AON_API_REENTRANCY
|
|||
depends on AON_TIMER_QMSI
|
||||
help
|
||||
Enable support for AON driver API reentrancy.
|
||||
|
||||
config RTC_QMSI
|
||||
bool "QMSI RTC Driver"
|
||||
depends on QMSI
|
||||
help
|
||||
Build QMSI RTC driver.
|
||||
|
||||
if RTC_QMSI
|
||||
|
||||
config RTC_QMSI_API_REENTRANCY
|
||||
bool
|
||||
prompt "RTC shim driver API reentrancy"
|
||||
help
|
||||
Enable support for RTC shim driver API reentrancy.
|
||||
|
||||
config RTC_PRESCALER
|
||||
int
|
||||
default 1
|
||||
prompt "Prescaler size"
|
||||
help
|
||||
RTC prescaler used to determine ticks per second
|
||||
|
||||
endif
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#include <device.h>
|
||||
#include <drivers/ioapic.h>
|
||||
#include <counter.h>
|
||||
#include <init.h>
|
||||
#include <kernel.h>
|
||||
#include <rtc.h>
|
||||
#include <power.h>
|
||||
#include <soc.h>
|
||||
#include <misc/util.h>
|
||||
|
@ -18,6 +18,13 @@
|
|||
#include "qm_isr.h"
|
||||
#include "qm_rtc.h"
|
||||
|
||||
static void rtc_callback(void *user_data);
|
||||
static counter_alarm_callback_t user_cb;
|
||||
|
||||
struct rtc_config {
|
||||
struct counter_config_info info;
|
||||
};
|
||||
|
||||
struct rtc_data {
|
||||
#ifdef CONFIG_RTC_QMSI_API_REENTRANCY
|
||||
struct k_sem sem;
|
||||
|
@ -62,31 +69,52 @@ static u32_t rtc_qmsi_get_power_state(struct device *dev)
|
|||
#define rtc_qmsi_set_power_state(...)
|
||||
#endif
|
||||
|
||||
static void rtc_qmsi_enable(struct device *dev)
|
||||
static int rtc_qmsi_enable(struct device *dev)
|
||||
{
|
||||
clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rtc_qmsi_disable(struct device *dev)
|
||||
static int rtc_qmsi_disable(struct device *dev)
|
||||
{
|
||||
clk_periph_disable(CLK_PERIPH_RTC_REGISTER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtc_qmsi_disable_alarm(struct device *dev,
|
||||
const struct counter_alarm_cfg *alarm_cfg)
|
||||
{
|
||||
clk_periph_disable(CLK_PERIPH_RTC_REGISTER);
|
||||
|
||||
static int rtc_qmsi_set_config(struct device *dev, struct rtc_config *cfg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtc_qmsi_set_wrap(struct device *dev, u32_t ticks,
|
||||
counter_wrap_callback_t callback,
|
||||
void *user_data)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
static int rtc_qmsi_set_alarm(struct device *dev,
|
||||
const struct counter_alarm_cfg *alarm_cfg)
|
||||
{
|
||||
qm_rtc_config_t qm_cfg;
|
||||
int result = 0;
|
||||
|
||||
qm_cfg.init_val = cfg->init_val;
|
||||
qm_cfg.alarm_en = cfg->alarm_enable;
|
||||
qm_cfg.alarm_val = cfg->alarm_val;
|
||||
qm_cfg.init_val = 0;
|
||||
qm_cfg.alarm_en = 1;
|
||||
qm_cfg.alarm_val = alarm_cfg->ticks;
|
||||
|
||||
user_cb = alarm_cfg->handler;
|
||||
/* Casting callback type due different input parameter from QMSI
|
||||
* compared aganst the Zephyr callback from void cb(struct device *dev)
|
||||
* to void cb(void *)
|
||||
*/
|
||||
qm_cfg.callback = (void *) cfg->cb_fn;
|
||||
qm_cfg.callback_data = dev;
|
||||
qm_cfg.callback = rtc_callback;
|
||||
qm_cfg.callback_data = (void *)alarm_cfg;
|
||||
|
||||
/* Set prescaler value. Ideally, the divider should come from struct
|
||||
* rtc_config instead. It's safe to use RTC_DIVIDER here for now since
|
||||
|
@ -109,12 +137,9 @@ static int rtc_qmsi_set_config(struct device *dev, struct rtc_config *cfg)
|
|||
|
||||
k_busy_wait(60);
|
||||
|
||||
return result;
|
||||
}
|
||||
qm_rtc_set_alarm(QM_RTC_0, alarm_cfg->ticks);
|
||||
|
||||
static int rtc_qmsi_set_alarm(struct device *dev, const u32_t alarm_val)
|
||||
{
|
||||
return qm_rtc_set_alarm(QM_RTC_0, alarm_val);
|
||||
return result;
|
||||
}
|
||||
|
||||
static u32_t rtc_qmsi_read(struct device *dev)
|
||||
|
@ -127,12 +152,13 @@ static u32_t rtc_qmsi_get_pending_int(struct device *dev)
|
|||
return QM_RTC[QM_RTC_0]->rtc_stat;
|
||||
}
|
||||
|
||||
static const struct rtc_driver_api api = {
|
||||
.enable = rtc_qmsi_enable,
|
||||
.disable = rtc_qmsi_disable,
|
||||
static const struct counter_driver_api api = {
|
||||
.start = rtc_qmsi_enable,
|
||||
.stop = rtc_qmsi_disable,
|
||||
.read = rtc_qmsi_read,
|
||||
.set_config = rtc_qmsi_set_config,
|
||||
.set_wrap = rtc_qmsi_set_wrap,
|
||||
.set_alarm = rtc_qmsi_set_alarm,
|
||||
.disable_alarm = rtc_qmsi_disable_alarm,
|
||||
.get_pending_int = rtc_qmsi_get_pending_int,
|
||||
};
|
||||
|
||||
|
@ -199,6 +225,24 @@ static int rtc_qmsi_device_ctrl(struct device *dev, u32_t ctrl_command,
|
|||
}
|
||||
#endif
|
||||
|
||||
static const struct rtc_config rtc_conf_info = {
|
||||
.info = {
|
||||
.max_wrap = UINT32_MAX,
|
||||
.freq = 32768,
|
||||
.count_up = true,
|
||||
.channels = 1,
|
||||
}
|
||||
};
|
||||
|
||||
DEVICE_DEFINE(rtc, CONFIG_RTC_0_NAME, &rtc_qmsi_init, rtc_qmsi_device_ctrl,
|
||||
RTC_CONTEXT, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
&api);
|
||||
RTC_CONTEXT, &rtc_conf_info, POST_KERNEL,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &api);
|
||||
|
||||
static void rtc_callback(void *user_data)
|
||||
{
|
||||
const struct counter_alarm_cfg *cfg = user_data;
|
||||
|
||||
if (user_cb) {
|
||||
(*user_cb)(DEVICE_GET(rtc), cfg, cfg->ticks);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
zephyr_library()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_RTC_QMSI rtc_qmsi.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_RTC_MCUX rtc_mcux.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_RTC_STM32 rtc_ll_stm32.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE rtc_handlers.c)
|
||||
|
|
|
@ -29,7 +29,6 @@ config RTC_0_NAME
|
|||
|
||||
comment "RTC drivers"
|
||||
|
||||
source "drivers/rtc/Kconfig.qmsi"
|
||||
source "drivers/rtc/Kconfig.mcux_rtc"
|
||||
source "drivers/rtc/Kconfig.stm32_rtc"
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
config RTC_QMSI
|
||||
bool "QMSI RTC Driver"
|
||||
depends on QMSI
|
||||
help
|
||||
Build QMSI RTC driver.
|
||||
|
||||
if RTC_QMSI
|
||||
|
||||
config RTC_QMSI_API_REENTRANCY
|
||||
bool "RTC shim driver API reentrancy"
|
||||
help
|
||||
Enable support for RTC shim driver API reentrancy.
|
||||
|
||||
config RTC_PRESCALER
|
||||
int "Prescaler size"
|
||||
default 1
|
||||
help
|
||||
RTC prescaler used to determine ticks per second
|
||||
|
||||
endif
|
Loading…
Add table
Add a link
Reference in a new issue