drivers: can: Add get_max_filters API

The maximum number of concurrent filters depends on the hardware and
the driver implementation. This API allows the application to obtain
the maximum number of available filters.

Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
Martin Jäger 2021-10-12 11:46:44 +02:00 committed by Christopher Friedt
commit 5511cba5fe
7 changed files with 78 additions and 0 deletions

View file

@ -236,6 +236,13 @@ int can_loopback_get_core_clock(const struct device *dev, uint32_t *rate)
return 0;
}
int can_loopback_get_max_filters(const struct device *dev, enum can_ide id_type)
{
ARG_UNUSED(id_type);
return CONFIG_CAN_MAX_FILTER;
}
static const struct can_driver_api can_api_funcs = {
.set_mode = can_loopback_set_mode,
.set_timing = can_loopback_set_timing,
@ -248,6 +255,7 @@ static const struct can_driver_api can_api_funcs = {
#endif
.register_state_change_isr = can_loopback_register_state_change_isr,
.get_core_clock = can_loopback_get_core_clock,
.get_max_filters = can_loopback_get_max_filters,
.timing_min = {
.sjw = 0x1,
.prop_seg = 0x01,

View file

@ -314,6 +314,12 @@ static int mcp2515_get_core_clock(const struct device *dev, uint32_t *rate)
return 0;
}
int mcp2515_get_max_filters(const struct device *dev, enum can_ide id_type)
{
ARG_UNUSED(id_type);
return CONFIG_CAN_MAX_FILTER;
}
static int mcp2515_set_timing(const struct device *dev,
const struct can_timing *timing,
@ -785,6 +791,7 @@ static const struct can_driver_api can_api_funcs = {
#endif
.register_state_change_isr = mcp2515_register_state_change_isr,
.get_core_clock = mcp2515_get_core_clock,
.get_max_filters = mcp2515_get_max_filters,
.timing_min = {
.sjw = 0x1,
.prop_seg = 0x01,

View file

@ -127,6 +127,13 @@ static int mcux_flexcan_get_core_clock(const struct device *dev, uint32_t *rate)
return clock_control_get_rate(config->clock_dev, config->clock_subsys, rate);
}
int mcux_flexcan_get_max_filters(const struct device *dev, enum can_ide id_type)
{
ARG_UNUSED(id_type);
return CONFIG_CAN_MAX_FILTER;
}
static int mcux_flexcan_set_timing(const struct device *dev,
const struct can_timing *timing,
const struct can_timing *timing_data)
@ -747,6 +754,7 @@ static const struct can_driver_api mcux_flexcan_driver_api = {
#endif
.register_state_change_isr = mcux_flexcan_register_state_change_isr,
.get_core_clock = mcux_flexcan_get_core_clock,
.get_max_filters = mcux_flexcan_get_max_filters,
/*
* FlexCAN timing limits are specified in the "FLEXCANx_CTRL1 field
* descriptions" table in the SoC reference manual.

View file

@ -981,6 +981,13 @@ static int can_rcar_get_core_clock(const struct device *dev, uint32_t *rate)
return 0;
}
int can_rcar_get_max_filters(const struct device *dev, enum can_ide id_type)
{
ARG_UNUSED(id_type);
return CONFIG_CAN_RCAR_MAX_FILTER;
}
static const struct can_driver_api can_rcar_driver_api = {
.set_mode = can_rcar_set_mode,
.set_timing = can_rcar_set_timing,
@ -993,6 +1000,7 @@ static const struct can_driver_api can_rcar_driver_api = {
#endif
.register_state_change_isr = can_rcar_register_state_change_isr,
.get_core_clock = can_rcar_get_core_clock,
.get_max_filters = can_rcar_get_max_filters,
.timing_min = {
.sjw = 0x1,
.prop_seg = 0x00,

View file

@ -412,6 +412,13 @@ int can_stm32_get_core_clock(const struct device *dev, uint32_t *rate)
return 0;
}
int can_stm32_get_max_filters(const struct device *dev, enum can_ide id_type)
{
ARG_UNUSED(id_type);
return CONFIG_CAN_MAX_FILTER;
}
static int can_stm32_init(const struct device *dev)
{
const struct can_stm32_config *cfg = DEV_CFG(dev);
@ -1105,6 +1112,7 @@ static const struct can_driver_api can_api_funcs = {
#endif
.register_state_change_isr = can_stm32_register_state_change_isr,
.get_core_clock = can_stm32_get_core_clock,
.get_max_filters = can_stm32_get_max_filters,
.timing_min = {
.sjw = 0x1,
.prop_seg = 0x00,

View file

@ -38,6 +38,15 @@ int can_stm32fd_get_core_clock(const struct device *dev, uint32_t *rate)
return 0;
}
int can_stm32fd_get_max_filters(const struct device *dev, enum can_ide id_type)
{
if (id_type == CAN_STANDARD_IDENTIFIER) {
return NUM_STD_FILTER_DATA;
} else {
return NUM_EXT_FILTER_DATA;
}
}
void can_stm32fd_clock_enable(void)
{
LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1);
@ -175,6 +184,7 @@ static const struct can_driver_api can_api_funcs = {
.recover = can_mcan_recover,
#endif
.get_core_clock = can_stm32fd_get_core_clock,
.get_max_filters = can_stm32fd_get_max_filters,
.register_state_change_isr = can_stm32fd_register_state_change_isr,
.timing_min = {
.sjw = 0x7f,