counter: nxp_pit: use clock control to obtain module's clock rate
Use standard clock control API to retrieve the PIT clock rate instead of using the HAL. Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
This commit is contained in:
parent
ddaacd9ee8
commit
45c8cb2343
4 changed files with 32 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
||||||
#define DT_DRV_COMPAT nxp_kinetis_pit
|
#define DT_DRV_COMPAT nxp_kinetis_pit
|
||||||
|
|
||||||
#include <zephyr/drivers/counter.h>
|
#include <zephyr/drivers/counter.h>
|
||||||
|
#include <zephyr/drivers/clock_control.h>
|
||||||
#include <zephyr/irq.h>
|
#include <zephyr/irq.h>
|
||||||
#include <fsl_pit.h>
|
#include <fsl_pit.h>
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ struct mcux_pit_config {
|
||||||
pit_chnl_t pit_channel;
|
pit_chnl_t pit_channel;
|
||||||
uint32_t pit_period;
|
uint32_t pit_period;
|
||||||
void (*irq_config_func)(const struct device *dev);
|
void (*irq_config_func)(const struct device *dev);
|
||||||
|
const struct device *clock_dev;
|
||||||
|
clock_control_subsys_t clock_subsys;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mcux_pit_data {
|
struct mcux_pit_data {
|
||||||
|
@ -114,6 +117,19 @@ static uint32_t mcux_pit_get_pending_int(const struct device *dev)
|
||||||
return ((flags & mask) == mask);
|
return ((flags & mask) == mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t mcux_pit_get_frequency(const struct device *dev)
|
||||||
|
{
|
||||||
|
const struct mcux_pit_config *config = dev->config;
|
||||||
|
uint32_t clock_rate;
|
||||||
|
|
||||||
|
if (clock_control_get_rate(config->clock_dev, config->clock_subsys, &clock_rate)) {
|
||||||
|
LOG_ERR("Failed to get clock rate");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clock_rate;
|
||||||
|
}
|
||||||
|
|
||||||
static void mcux_pit_isr(const struct device *dev)
|
static void mcux_pit_isr(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct mcux_pit_config *config = dev->config;
|
const struct mcux_pit_config *config = dev->config;
|
||||||
|
@ -130,9 +146,14 @@ static void mcux_pit_isr(const struct device *dev)
|
||||||
|
|
||||||
static int mcux_pit_init(const struct device *dev)
|
static int mcux_pit_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct mcux_pit_config *config =
|
const struct mcux_pit_config *config = dev->config;
|
||||||
(struct mcux_pit_config *)dev->config;
|
|
||||||
pit_config_t pit_config;
|
pit_config_t pit_config;
|
||||||
|
uint32_t clock_rate;
|
||||||
|
|
||||||
|
if (!device_is_ready(config->clock_dev)) {
|
||||||
|
LOG_ERR("Clock control device not ready");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
PIT_GetDefaultConfig(&pit_config);
|
PIT_GetDefaultConfig(&pit_config);
|
||||||
pit_config.enableRunInDebug = config->enableRunInDebug;
|
pit_config.enableRunInDebug = config->enableRunInDebug;
|
||||||
|
@ -141,9 +162,9 @@ static int mcux_pit_init(const struct device *dev)
|
||||||
|
|
||||||
config->irq_config_func(dev);
|
config->irq_config_func(dev);
|
||||||
|
|
||||||
|
clock_rate = mcux_pit_get_frequency(dev);
|
||||||
PIT_SetTimerPeriod(config->base, config->pit_channel,
|
PIT_SetTimerPeriod(config->base, config->pit_channel,
|
||||||
USEC_TO_COUNT(config->pit_period,
|
USEC_TO_COUNT(config->pit_period, clock_rate));
|
||||||
CLOCK_GetFreq(kCLOCK_BusClk)));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +176,7 @@ static const struct counter_driver_api mcux_pit_driver_api = {
|
||||||
.set_top_value = mcux_pit_set_top_value,
|
.set_top_value = mcux_pit_set_top_value,
|
||||||
.get_pending_int = mcux_pit_get_pending_int,
|
.get_pending_int = mcux_pit_get_pending_int,
|
||||||
.get_top_value = mcux_pit_get_top_value,
|
.get_top_value = mcux_pit_get_top_value,
|
||||||
|
.get_freq = mcux_pit_get_frequency,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define COUNTER_MCUX_PIT_IRQ_CONFIG(idx, n) \
|
#define COUNTER_MCUX_PIT_IRQ_CONFIG(idx, n) \
|
||||||
|
@ -174,12 +196,14 @@ static const struct counter_driver_api mcux_pit_driver_api = {
|
||||||
.info = { \
|
.info = { \
|
||||||
.max_top_value = DT_INST_PROP(n, max_load_value), \
|
.max_top_value = DT_INST_PROP(n, max_load_value), \
|
||||||
.channels = 0, \
|
.channels = 0, \
|
||||||
.freq = DT_INST_PROP(n, clock_frequency), \
|
|
||||||
}, \
|
}, \
|
||||||
.base = (PIT_Type *)DT_INST_REG_ADDR(n), \
|
.base = (PIT_Type *)DT_INST_REG_ADDR(n), \
|
||||||
.pit_channel = DT_INST_PROP(n, pit_channel), \
|
.pit_channel = DT_INST_PROP(n, pit_channel), \
|
||||||
.pit_period = DT_INST_PROP(n, pit_period), \
|
.pit_period = DT_INST_PROP(n, pit_period), \
|
||||||
.irq_config_func = mcux_pit_irq_config_##n, \
|
.irq_config_func = mcux_pit_irq_config_##n, \
|
||||||
|
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
|
||||||
|
.clock_subsys = (clock_control_subsys_t) \
|
||||||
|
DT_INST_CLOCKS_CELL(n, name), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
DEVICE_DT_INST_DEFINE(n, &mcux_pit_init, NULL, \
|
DEVICE_DT_INST_DEFINE(n, &mcux_pit_init, NULL, \
|
||||||
|
|
|
@ -535,7 +535,6 @@
|
||||||
status = "disabled";
|
status = "disabled";
|
||||||
pit-channel = <0>;
|
pit-channel = <0>;
|
||||||
pit-period = <1000000>;
|
pit-period = <1000000>;
|
||||||
clock-frequency = <60000000>;
|
|
||||||
max-load-value = <0xffffffff>;
|
max-load-value = <0xffffffff>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -394,7 +394,6 @@
|
||||||
status = "disabled";
|
status = "disabled";
|
||||||
pit-channel = <0>;
|
pit-channel = <0>;
|
||||||
pit-period = <1000000>;
|
pit-period = <1000000>;
|
||||||
clock-frequency = <60000000>;
|
|
||||||
max-load-value = <0xffffffff>;
|
max-load-value = <0xffffffff>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ properties:
|
||||||
reg:
|
reg:
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
|
clocks:
|
||||||
|
required: true
|
||||||
|
|
||||||
pit-channel:
|
pit-channel:
|
||||||
type: int
|
type: int
|
||||||
required: true
|
required: true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue