drivers: nxp: Add reset code to driver inits

Add peripheral reset handling code to driver init for:

- mcan
- i2c flexcomm
- spi flexcomm
- lpc mailbox
- mrt timer

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2024-05-06 12:23:58 -05:00 committed by Anas Nashif
commit eeb3e808f5
10 changed files with 90 additions and 1 deletions

View file

@ -59,5 +59,6 @@ config CAN_MCUX_MCAN
depends on CLOCK_CONTROL
select CAN_MCAN
select PINCTRL
select RESET
help
Enable support for mcux mcan driver.

View file

@ -11,6 +11,7 @@
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
#include <zephyr/drivers/reset.h>
LOG_MODULE_REGISTER(can_mcux_mcan, CONFIG_CAN_LOG_LEVEL);
@ -27,6 +28,7 @@ struct mcux_mcan_config {
clock_control_subsys_t clock_subsys;
void (*irq_config_func)(const struct device *dev);
const struct pinctrl_dev_config *pincfg;
const struct reset_dt_spec reset;
};
static int mcux_mcan_read_reg(const struct device *dev, uint16_t reg, uint32_t *val)
@ -91,6 +93,16 @@ static int mcux_mcan_init(const struct device *dev)
return -ENODEV;
}
if (!device_is_ready(mcux_config->reset.dev)) {
LOG_ERR("Reset device not ready");
return -ENODEV;
}
err = reset_line_toggle(mcux_config->reset.dev, mcux_config->reset.id);
if (err) {
return err;
}
err = pinctrl_apply_state(mcux_config->pincfg, PINCTRL_STATE_DEFAULT);
if (err) {
return err;
@ -197,6 +209,7 @@ static const struct can_mcan_ops mcux_mcan_ops = {
DT_INST_CLOCKS_CELL(n, name), \
.irq_config_func = mcux_mcan_irq_config_##n, \
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
.reset = RESET_DT_SPEC_INST_GET(n), \
}; \
\
static const struct can_mcan_config can_mcan_config_##n = \

View file

@ -6,5 +6,6 @@ config COUNTER_NXP_MRT
default y
depends on DT_HAS_NXP_MRT_CHANNEL_ENABLED && \
DT_HAS_NXP_MRT_ENABLED
select RESET
help
Enable driver for the NXP Multirate Timer (MRT).

View file

@ -21,6 +21,8 @@
#include <zephyr/devicetree.h>
#include <zephyr/device.h>
#include <zephyr/irq.h>
#include <zephyr/drivers/reset.h>
#include <soc.h>
#define LOG_MODULE_NAME counter_mrt
@ -55,6 +57,7 @@ struct nxp_mrt_config {
void (*irq_config_func)(const struct device *dev);
struct nxp_mrt_channel_data *const *data;
const struct device *const *channels;
const struct reset_dt_spec reset;
};
static int nxp_mrt_stop(const struct device *dev)
@ -210,6 +213,17 @@ static int nxp_mrt_init(const struct device *dev)
const struct nxp_mrt_config *config = dev->config;
MRT_Type *base = config->base;
uint32_t num_channels = (base->MODCFG & MRT_MODCFG_NOC_MASK) >> MRT_MODCFG_NOC_SHIFT;
int ret = 0;
if (!device_is_ready(config->reset.dev)) {
LOG_ERR("Reset device not ready");
return -ENODEV;
}
ret = reset_line_toggle(config->reset.dev, config->reset.id);
if (ret) {
return ret;
}
clock_control_on(config->clock_dev, config->clock_subsys);
@ -331,6 +345,7 @@ struct counter_driver_api nxp_mrt_api = {
.irq_config_func = nxp_mrt_##n##_irq_config_func, \
.data = nxp_mrt_##n##_channel_datas, \
.channels = nxp_mrt_##n##_channels, \
.reset = RESET_DT_SPEC_INST_GET(n), \
}; \
\
/* Init parent device in order to handle ISR and init. */ \

View file

@ -8,6 +8,7 @@ menuconfig I2C_MCUX_FLEXCOMM
default y
depends on DT_HAS_NXP_LPC_I2C_ENABLED
select PINCTRL
select RESET
help
Enable the mcux flexcomm i2c driver.

View file

@ -12,6 +12,7 @@
#include <zephyr/drivers/clock_control.h>
#include <fsl_i2c.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/reset.h>
#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
@ -32,6 +33,7 @@ struct mcux_flexcomm_config {
void (*irq_config_func)(const struct device *dev);
uint32_t bitrate;
const struct pinctrl_dev_config *pincfg;
const struct reset_dt_spec reset;
};
#ifdef CONFIG_I2C_TARGET
@ -470,6 +472,16 @@ static int mcux_flexcomm_init(const struct device *dev)
i2c_master_config_t master_config;
int error;
if (!device_is_ready(config->reset.dev)) {
LOG_ERR("Reset device not ready");
return -ENODEV;
}
error = reset_line_toggle(config->reset.dev, config->reset.id);
if (error) {
return error;
}
error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
if (error) {
return error;
@ -527,6 +539,7 @@ static const struct i2c_driver_api mcux_flexcomm_driver_api = {
.irq_config_func = mcux_flexcomm_config_func_##id, \
.bitrate = DT_INST_PROP(id, clock_frequency), \
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(id), \
.reset = RESET_DT_SPEC_INST_GET(id), \
}; \
static struct mcux_flexcomm_data mcux_flexcomm_data_##id; \
I2C_DEVICE_DT_INST_DEFINE(id, \

View file

@ -5,6 +5,7 @@ config IPM_MCUX
bool "MCUX IPM driver"
default y
depends on DT_HAS_NXP_LPC_MAILBOX_ENABLED
select RESET
help
Driver for MCUX mailbox

View file

@ -14,6 +14,8 @@
#include <soc.h>
#include <zephyr/irq.h>
#include <zephyr/sys/barrier.h>
#include <zephyr/drivers/reset.h>
#include <zephyr/sys/util_macro.h>
#define MCUX_IPM_DATA_REGS 1
#define MCUX_IPM_MAX_ID_VAL 0
@ -36,9 +38,12 @@
#endif
#endif
#define MAILBOX_USES_RESET COND_CODE_1(DT_ANY_INST_HAS_PROP_STATUS_OKAY(resets), (true), (false))
struct mcux_mailbox_config {
MAILBOX_Type *base;
void (*irq_config_func)(const struct device *dev);
const struct reset_dt_spec reset;
};
struct mcux_mailbox_data {
@ -143,10 +148,34 @@ static int mcux_mailbox_ipm_set_enabled(const struct device *d, int enable)
return 0;
}
static inline int mcux_mailbox_reset(const struct device *dev)
{
const struct mcux_mailbox_config *config = dev->config;
int ret = 0;
/* on some platforms, explicit reset is not needed or possible for the mailbox */
if (!MAILBOX_USES_RESET) {
return 0;
}
if (!device_is_ready(config->reset.dev)) {
ret = -ENODEV;
} else {
ret = reset_line_toggle(config->reset.dev, config->reset.id);
}
return ret;
}
static int mcux_mailbox_init(const struct device *dev)
{
const struct mcux_mailbox_config *config = dev->config;
int ret = 0;
ret = mcux_mailbox_reset(dev);
if (ret) {
return ret;
}
MAILBOX_Init(config->base);
config->irq_config_func(dev);
@ -169,6 +198,7 @@ static void mcux_mailbox_config_func_0(const struct device *dev);
static const struct mcux_mailbox_config mcux_mailbox_0_config = {
.base = (MAILBOX_Type *)DT_INST_REG_ADDR(0),
.irq_config_func = mcux_mailbox_config_func_0,
.reset = RESET_DT_SPEC_INST_GET_OR(0, {0}),
};
static struct mcux_mailbox_data mcux_mailbox_0_data;

View file

@ -7,6 +7,7 @@ config SPI_MCUX_FLEXCOMM
default y
depends on DT_HAS_NXP_LPC_SPI_ENABLED
select PINCTRL
select RESET
help
Enable support for mcux flexcomm spi driver.

View file

@ -18,6 +18,7 @@
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/sys_clock.h>
#include <zephyr/irq.h>
#include <zephyr/drivers/reset.h>
LOG_MODULE_REGISTER(spi_mcux_flexcomm, CONFIG_SPI_LOG_LEVEL);
@ -37,6 +38,7 @@ struct spi_mcux_config {
uint32_t transfer_delay;
uint32_t def_char;
const struct pinctrl_dev_config *pincfg;
const struct reset_dt_spec reset;
};
#ifdef CONFIG_SPI_MCUX_FLEXCOMM_DMA
@ -764,9 +766,19 @@ static int spi_mcux_release(const struct device *dev,
static int spi_mcux_init(const struct device *dev)
{
int err;
const struct spi_mcux_config *config = dev->config;
struct spi_mcux_data *data = dev->data;
int err = 0;
if (!device_is_ready(config->reset.dev)) {
LOG_ERR("Reset device not ready");
return -ENODEV;
}
err = reset_line_toggle(config->reset.dev, config->reset.id);
if (err) {
return err;
}
config->irq_config_func(dev);
@ -866,6 +878,7 @@ static void spi_mcux_config_func_##id(const struct device *dev) \
.transfer_delay = DT_INST_PROP_OR(id, transfer_delay, 0), \
.def_char = DT_INST_PROP_OR(id, def_char, 0), \
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(id), \
.reset = RESET_DT_SPEC_INST_GET(id), \
}; \
static struct spi_mcux_data spi_mcux_data_##id = { \
SPI_CONTEXT_INIT_LOCK(spi_mcux_data_##id, ctx), \