drivers: counter: gpt: enable MMIO memory mapping
Map the device memory in case of running with MMU on Cortex-A Core. Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
This commit is contained in:
parent
399c2cba65
commit
6a9407ede4
|
@ -7,5 +7,6 @@ config COUNTER_MCUX_GPT
|
|||
bool "MCUX GPT driver"
|
||||
default y
|
||||
depends on DT_HAS_NXP_IMX_GPT_ENABLED
|
||||
select KERNEL_DIRECT_MAP if MMU
|
||||
help
|
||||
Enable support for mcux General Purpose Timer (GPT) driver.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Linaro Limited.
|
||||
* Copyright 2024 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -15,55 +16,66 @@
|
|||
|
||||
LOG_MODULE_REGISTER(mcux_gpt, CONFIG_COUNTER_LOG_LEVEL);
|
||||
|
||||
#define DEV_CFG(_dev) ((const struct mcux_gpt_config *)(_dev)->config)
|
||||
#define DEV_DATA(_dev) ((struct mcux_gpt_data *)(_dev)->data)
|
||||
|
||||
struct mcux_gpt_config {
|
||||
/* info must be first element */
|
||||
struct counter_config_info info;
|
||||
|
||||
DEVICE_MMIO_NAMED_ROM(gpt_mmio);
|
||||
|
||||
const struct device *clock_dev;
|
||||
clock_control_subsys_t clock_subsys;
|
||||
GPT_Type *base;
|
||||
clock_name_t clock_source;
|
||||
};
|
||||
|
||||
struct mcux_gpt_data {
|
||||
DEVICE_MMIO_NAMED_RAM(gpt_mmio);
|
||||
counter_alarm_callback_t alarm_callback;
|
||||
counter_top_callback_t top_callback;
|
||||
void *alarm_user_data;
|
||||
void *top_user_data;
|
||||
};
|
||||
|
||||
static GPT_Type *get_base(const struct device *dev)
|
||||
{
|
||||
return (GPT_Type *)DEVICE_MMIO_NAMED_GET(dev, gpt_mmio);
|
||||
}
|
||||
|
||||
static int mcux_gpt_start(const struct device *dev)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
|
||||
GPT_StartTimer(config->base);
|
||||
GPT_StartTimer(base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mcux_gpt_stop(const struct device *dev)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
|
||||
GPT_StopTimer(config->base);
|
||||
GPT_StopTimer(base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mcux_gpt_get_value(const struct device *dev, uint32_t *ticks)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
|
||||
*ticks = GPT_GetCurrentTimerCount(config->base);
|
||||
*ticks = GPT_GetCurrentTimerCount(base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mcux_gpt_set_alarm(const struct device *dev, uint8_t chan_id,
|
||||
const struct counter_alarm_cfg *alarm_cfg)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
struct mcux_gpt_data *data = dev->data;
|
||||
|
||||
uint32_t current = GPT_GetCurrentTimerCount(config->base);
|
||||
uint32_t current = GPT_GetCurrentTimerCount(base);
|
||||
uint32_t ticks = alarm_cfg->ticks;
|
||||
|
||||
if (chan_id != 0) {
|
||||
|
@ -82,16 +94,16 @@ static int mcux_gpt_set_alarm(const struct device *dev, uint8_t chan_id,
|
|||
data->alarm_callback = alarm_cfg->callback;
|
||||
data->alarm_user_data = alarm_cfg->user_data;
|
||||
|
||||
GPT_SetOutputCompareValue(config->base, kGPT_OutputCompare_Channel1,
|
||||
GPT_SetOutputCompareValue(base, kGPT_OutputCompare_Channel1,
|
||||
ticks);
|
||||
GPT_EnableInterrupts(config->base, kGPT_OutputCompare1InterruptEnable);
|
||||
GPT_EnableInterrupts(base, kGPT_OutputCompare1InterruptEnable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mcux_gpt_cancel_alarm(const struct device *dev, uint8_t chan_id)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
struct mcux_gpt_data *data = dev->data;
|
||||
|
||||
if (chan_id != 0) {
|
||||
|
@ -99,7 +111,7 @@ static int mcux_gpt_cancel_alarm(const struct device *dev, uint8_t chan_id)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
GPT_DisableInterrupts(config->base, kGPT_OutputCompare1InterruptEnable);
|
||||
GPT_DisableInterrupts(base, kGPT_OutputCompare1InterruptEnable);
|
||||
data->alarm_callback = NULL;
|
||||
|
||||
return 0;
|
||||
|
@ -107,18 +119,18 @@ static int mcux_gpt_cancel_alarm(const struct device *dev, uint8_t chan_id)
|
|||
|
||||
void mcux_gpt_isr(const struct device *dev)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
struct mcux_gpt_data *data = dev->data;
|
||||
uint32_t current = GPT_GetCurrentTimerCount(config->base);
|
||||
uint32_t current = GPT_GetCurrentTimerCount(base);
|
||||
uint32_t status;
|
||||
|
||||
status = GPT_GetStatusFlags(config->base, kGPT_OutputCompare1Flag |
|
||||
status = GPT_GetStatusFlags(base, kGPT_OutputCompare1Flag |
|
||||
kGPT_RollOverFlag);
|
||||
GPT_ClearStatusFlags(config->base, status);
|
||||
GPT_ClearStatusFlags(base, status);
|
||||
barrier_dsync_fence_full();
|
||||
|
||||
if ((status & kGPT_OutputCompare1Flag) && data->alarm_callback) {
|
||||
GPT_DisableInterrupts(config->base,
|
||||
GPT_DisableInterrupts(base,
|
||||
kGPT_OutputCompare1InterruptEnable);
|
||||
counter_alarm_callback_t alarm_cb = data->alarm_callback;
|
||||
data->alarm_callback = NULL;
|
||||
|
@ -132,15 +144,16 @@ void mcux_gpt_isr(const struct device *dev)
|
|||
|
||||
static uint32_t mcux_gpt_get_pending_int(const struct device *dev)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
|
||||
return GPT_GetStatusFlags(config->base, kGPT_OutputCompare1Flag);
|
||||
return GPT_GetStatusFlags(base, kGPT_OutputCompare1Flag);
|
||||
}
|
||||
|
||||
static int mcux_gpt_set_top_value(const struct device *dev,
|
||||
const struct counter_top_cfg *cfg)
|
||||
{
|
||||
const struct mcux_gpt_config *config = dev->config;
|
||||
GPT_Type *base = get_base(dev);
|
||||
struct mcux_gpt_data *data = dev->data;
|
||||
|
||||
if (cfg->ticks != config->info.max_top_value) {
|
||||
|
@ -152,7 +165,7 @@ static int mcux_gpt_set_top_value(const struct device *dev,
|
|||
data->top_callback = cfg->callback;
|
||||
data->top_user_data = cfg->user_data;
|
||||
|
||||
GPT_EnableInterrupts(config->base, kGPT_RollOverFlagInterruptEnable);
|
||||
GPT_EnableInterrupts(base, kGPT_RollOverFlagInterruptEnable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -169,6 +182,9 @@ static int mcux_gpt_init(const struct device *dev)
|
|||
const struct mcux_gpt_config *config = dev->config;
|
||||
gpt_config_t gptConfig;
|
||||
uint32_t clock_freq;
|
||||
GPT_Type *base;
|
||||
|
||||
DEVICE_MMIO_NAMED_MAP(dev, gpt_mmio, K_MEM_CACHE_NONE | K_MEM_DIRECT_MAP);
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
|
@ -191,7 +207,8 @@ static int mcux_gpt_init(const struct device *dev)
|
|||
gptConfig.enableFreeRun = true; /* Do not reset on compare */
|
||||
gptConfig.clockSource = kGPT_ClockSource_Periph;
|
||||
gptConfig.divider = clock_freq / config->info.freq;
|
||||
GPT_Init(config->base, &gptConfig);
|
||||
base = get_base(dev);
|
||||
GPT_Init(base, &gptConfig);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -211,7 +228,7 @@ static const struct counter_driver_api mcux_gpt_driver_api = {
|
|||
static struct mcux_gpt_data mcux_gpt_data_ ## n; \
|
||||
\
|
||||
static const struct mcux_gpt_config mcux_gpt_config_ ## n = { \
|
||||
.base = (void *)DT_INST_REG_ADDR(n), \
|
||||
DEVICE_MMIO_NAMED_ROM_INIT(gpt_mmio, DT_DRV_INST(n)), \
|
||||
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
|
||||
.clock_subsys = \
|
||||
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
|
||||
|
|
Loading…
Reference in a new issue