drivers: can: Enable pinctrl for mcux_flexcan

Enable pinctrl support for mcux flexcan driver

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-03-07 16:36:16 -06:00 committed by Carles Cufí
commit a7f85f1ca1
2 changed files with 27 additions and 1 deletions

View file

@ -16,6 +16,10 @@
#include <fsl_flexcan.h> #include <fsl_flexcan.h>
#include <logging/log.h> #include <logging/log.h>
#ifdef CONFIG_PINCTRL
#include <drivers/pinctrl.h>
#endif
LOG_MODULE_REGISTER(can_mcux_flexcan, CONFIG_CAN_LOG_LEVEL); LOG_MODULE_REGISTER(can_mcux_flexcan, CONFIG_CAN_LOG_LEVEL);
#define SP_IS_SET(inst) DT_INST_NODE_HAS_PROP(inst, sample_point) || #define SP_IS_SET(inst) DT_INST_NODE_HAS_PROP(inst, sample_point) ||
@ -87,6 +91,9 @@ struct mcux_flexcan_config {
void (*irq_config_func)(const struct device *dev); void (*irq_config_func)(const struct device *dev);
const struct device *phy; const struct device *phy;
uint32_t max_bitrate; uint32_t max_bitrate;
#ifdef CONFIG_PINCTRL
const struct pinctrl_dev_config *pincfg;
#endif
}; };
struct mcux_flexcan_rx_callback { struct mcux_flexcan_rx_callback {
@ -724,6 +731,13 @@ static int mcux_flexcan_init(const struct device *dev)
} }
} }
#ifdef CONFIG_PINCTRL
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
if (err != 0) {
return err;
}
#endif
err = mcux_flexcan_set_mode(dev, CAN_NORMAL_MODE); err = mcux_flexcan_set_mode(dev, CAN_NORMAL_MODE);
if (err) { if (err) {
return err; return err;
@ -797,7 +811,18 @@ static const struct can_driver_api mcux_flexcan_driver_api = {
COND_CODE_1(DT_INST_IRQ_HAS_NAME(id, name), \ COND_CODE_1(DT_INST_IRQ_HAS_NAME(id, name), \
(FLEXCAN_IRQ_CODE(id, name)), ()) (FLEXCAN_IRQ_CODE(id, name)), ())
#ifdef CONFIG_PINCTRL
#define FLEXCAN_PINCTRL_DEFINE(id) PINCTRL_DT_INST_DEFINE(id);
#define FLEXCAN_PINCTRL_INIT(id) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(id),
#else
#define FLEXCAN_PINCTRL_DEFINE(id)
#define FLEXCAN_PINCTRL_INIT(id)
#endif /* CONFIG_PINCTRL */
#define FLEXCAN_DEVICE_INIT_MCUX(id) \ #define FLEXCAN_DEVICE_INIT_MCUX(id) \
FLEXCAN_PINCTRL_DEFINE(id) \
\
static void mcux_flexcan_irq_config_##id(const struct device *dev); \ static void mcux_flexcan_irq_config_##id(const struct device *dev); \
\ \
static const struct mcux_flexcan_config mcux_flexcan_config_##id = { \ static const struct mcux_flexcan_config mcux_flexcan_config_##id = { \
@ -815,6 +840,7 @@ static const struct can_driver_api mcux_flexcan_driver_api = {
.irq_config_func = mcux_flexcan_irq_config_##id, \ .irq_config_func = mcux_flexcan_irq_config_##id, \
.phy = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(id, phys)),\ .phy = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(id, phys)),\
.max_bitrate = DT_INST_CAN_TRANSCEIVER_MAX_BITRATE(id, 1000000), \ .max_bitrate = DT_INST_CAN_TRANSCEIVER_MAX_BITRATE(id, 1000000), \
FLEXCAN_PINCTRL_INIT(id) \
}; \ }; \
\ \
static struct mcux_flexcan_data mcux_flexcan_data_##id; \ static struct mcux_flexcan_data mcux_flexcan_data_##id; \

View file

@ -5,7 +5,7 @@ description: NXP FlexCAN controller
compatible: "nxp,kinetis-flexcan" compatible: "nxp,kinetis-flexcan"
include: can-controller.yaml include: ["can-controller.yaml", "pinctrl-device.yaml"]
properties: properties:
reg: reg: