drivers: can: mcan: use per-instance message RAM configuration
Restructure the Bosch M_CAN driver backend to use per-instance Message RAM configuration. This removes the need for a common, artificial "can" devicetree node for SoCs with multiple Bosch M_CAN-based CAN controllers and allows for per-instance configuration of the number of e.g. standard (11-bit) and extended (29-bit) filter elements. As part of the restructure, software handling of CAN filter flags was moved from per-flags bitfields to per-filter bitfields, solving an issue when using more than 32 standard (11-bit) filter elements or more than 16 extended (29-bit) filter elements. Fixes: #42030, #53417 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
d112e08f0c
commit
0f36f1a3ee
24 changed files with 878 additions and 546 deletions
|
@ -23,16 +23,13 @@ LOG_MODULE_REGISTER(can_mcux_mcan, CONFIG_CAN_LOG_LEVEL);
|
|||
|
||||
struct mcux_mcan_config {
|
||||
mm_reg_t base;
|
||||
mem_addr_t mram;
|
||||
const struct device *clock_dev;
|
||||
clock_control_subsys_t clock_subsys;
|
||||
void (*irq_config_func)(const struct device *dev);
|
||||
const struct pinctrl_dev_config *pincfg;
|
||||
};
|
||||
|
||||
struct mcux_mcan_data {
|
||||
struct can_mcan_msg_sram msg_ram __nocache;
|
||||
};
|
||||
|
||||
static int mcux_mcan_read_reg(const struct device *dev, uint16_t reg, uint32_t *val)
|
||||
{
|
||||
const struct can_mcan_config *mcan_config = dev->config;
|
||||
|
@ -51,27 +48,27 @@ static int mcux_mcan_write_reg(const struct device *dev, uint16_t reg, uint32_t
|
|||
|
||||
static int mcux_mcan_read_mram(const struct device *dev, uint16_t offset, void *dst, size_t len)
|
||||
{
|
||||
struct can_mcan_data *mcan_data = dev->data;
|
||||
struct mcux_mcan_data *mcux_data = mcan_data->custom;
|
||||
const struct can_mcan_config *mcan_config = dev->config;
|
||||
const struct mcux_mcan_config *mcux_config = mcan_config->custom;
|
||||
|
||||
return can_mcan_sys_read_mram(POINTER_TO_UINT(&mcux_data->msg_ram), offset, dst, len);
|
||||
return can_mcan_sys_read_mram(mcux_config->mram, offset, dst, len);
|
||||
}
|
||||
|
||||
static int mcux_mcan_write_mram(const struct device *dev, uint16_t offset, const void *src,
|
||||
size_t len)
|
||||
{
|
||||
struct can_mcan_data *mcan_data = dev->data;
|
||||
struct mcux_mcan_data *mcux_data = mcan_data->custom;
|
||||
const struct can_mcan_config *mcan_config = dev->config;
|
||||
const struct mcux_mcan_config *mcux_config = mcan_config->custom;
|
||||
|
||||
return can_mcan_sys_write_mram(POINTER_TO_UINT(&mcux_data->msg_ram), offset, src, len);
|
||||
return can_mcan_sys_write_mram(mcux_config->mram, offset, src, len);
|
||||
}
|
||||
|
||||
static int mcux_mcan_clear_mram(const struct device *dev, uint16_t offset, size_t len)
|
||||
{
|
||||
struct can_mcan_data *mcan_data = dev->data;
|
||||
struct mcux_mcan_data *mcux_data = mcan_data->custom;
|
||||
const struct can_mcan_config *mcan_config = dev->config;
|
||||
const struct mcux_mcan_config *mcux_config = mcan_config->custom;
|
||||
|
||||
return can_mcan_sys_clear_mram(POINTER_TO_UINT(&mcux_data->msg_ram), offset, len);
|
||||
return can_mcan_sys_clear_mram(mcux_config->mram, offset, len);
|
||||
}
|
||||
|
||||
static int mcux_mcan_get_core_clock(const struct device *dev, uint32_t *rate)
|
||||
|
@ -87,9 +84,7 @@ static int mcux_mcan_init(const struct device *dev)
|
|||
{
|
||||
const struct can_mcan_config *mcan_config = dev->config;
|
||||
const struct mcux_mcan_config *mcux_config = mcan_config->custom;
|
||||
struct can_mcan_data *mcan_data = dev->data;
|
||||
struct mcux_mcan_data *mcux_data = mcan_data->custom;
|
||||
const uintptr_t mrba = POINTER_TO_UINT(&mcux_data->msg_ram) & MCUX_MCAN_MRBA_BA;
|
||||
const uintptr_t mrba = mcux_config->mram & MCUX_MCAN_MRBA_BA;
|
||||
int err;
|
||||
|
||||
if (!device_is_ready(mcux_config->clock_dev)) {
|
||||
|
@ -113,7 +108,7 @@ static int mcux_mcan_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
err = can_mcan_configure_mram(dev, mrba, POINTER_TO_UINT(&mcux_data->msg_ram));
|
||||
err = can_mcan_configure_mram(dev, mrba, mcux_config->mram);
|
||||
if (err != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -204,12 +199,17 @@ static const struct can_mcan_ops mcux_mcan_ops = {
|
|||
};
|
||||
|
||||
#define MCUX_MCAN_INIT(n) \
|
||||
CAN_MCAN_DT_INST_BUILD_ASSERT_MRAM_CFG(n); \
|
||||
PINCTRL_DT_INST_DEFINE(n); \
|
||||
\
|
||||
static void mcux_mcan_irq_config_##n(const struct device *dev); \
|
||||
\
|
||||
CAN_MCAN_DT_INST_CALLBACKS_DEFINE(n, mcux_mcan_cbs_##n); \
|
||||
CAN_MCAN_DT_INST_MRAM_DEFINE(n, mcux_mcan_mram_##n); \
|
||||
\
|
||||
static const struct mcux_mcan_config mcux_mcan_config_##n = { \
|
||||
.base = (mm_reg_t)DT_INST_REG_ADDR(n), \
|
||||
.base = CAN_MCAN_DT_INST_MCAN_ADDR(n), \
|
||||
.mram = (mem_addr_t)POINTER_TO_UINT(&mcux_mcan_mram_##n), \
|
||||
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
|
||||
.clock_subsys = (clock_control_subsys_t) \
|
||||
DT_INST_CLOCKS_CELL(n, name), \
|
||||
|
@ -219,12 +219,11 @@ static const struct can_mcan_ops mcux_mcan_ops = {
|
|||
\
|
||||
static const struct can_mcan_config can_mcan_config_##n = \
|
||||
CAN_MCAN_DT_CONFIG_INST_GET(n, &mcux_mcan_config_##n, \
|
||||
&mcux_mcan_ops); \
|
||||
\
|
||||
static struct mcux_mcan_data mcux_mcan_data_##n; \
|
||||
&mcux_mcan_ops, \
|
||||
&mcux_mcan_cbs_##n); \
|
||||
\
|
||||
static struct can_mcan_data can_mcan_data_##n = \
|
||||
CAN_MCAN_DATA_INITIALIZER(&mcux_mcan_data_##n); \
|
||||
CAN_MCAN_DATA_INITIALIZER(NULL); \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &mcux_mcan_init, NULL, \
|
||||
&can_mcan_data_##n, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue