Skip to content

Commit

Permalink
drivers: can: add support for specifying minimum supported CAN bitrate
Browse files Browse the repository at this point in the history
Add support for specifying the minimum bitrate supported by a CAN
controller in CAN_DT_DRIVER_CONFIG_GET() and
CAN_DT_DRIVER_CONFIG_INST_GET().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
  • Loading branch information
henrikbrixandersen committed Mar 12, 2024
1 parent 57c015d commit 6d35ec7
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drivers/can/can_fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static const struct can_driver_api fake_can_driver_api = {

#define FAKE_CAN_INIT(inst) \
static const struct fake_can_config fake_can_config_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0U), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 0), \
}; \
\
static struct fake_can_data fake_can_data_##inst; \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ static int can_loopback_init(const struct device *dev)

#define CAN_LOOPBACK_INIT(inst) \
static const struct can_loopback_config can_loopback_config_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0U), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 0), \
}; \
\
static struct can_loopback_data can_loopback_data_##inst; \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcp2515.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ static int mcp2515_init(const struct device *dev)
}; \
\
static const struct mcp2515_config mcp2515_config_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 1000000), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 1000000), \
.bus = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 0), \
.int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
.int_thread_stack_size = CONFIG_CAN_MCP2515_INT_THREAD_STACK_SIZE, \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcp251xfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ static const struct can_driver_api mcp251xfd_api_funcs = {
.int_thread_stack = mcp251xfd_int_stack_##inst, \
}; \
static const struct mcp251xfd_config mcp251xfd_config_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 8000000), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 8000000), \
.bus = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 0), \
.int_gpio_dt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
\
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_mcux_flexcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ static const struct can_driver_api mcux_flexcan_fd_driver_api = {
static void mcux_flexcan_irq_disable_##id(void); \
\
static const struct mcux_flexcan_config mcux_flexcan_config_##id = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(id, FLEXCAN_MAX_BITRATE(id)), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(id, 0, FLEXCAN_MAX_BITRATE(id)), \
.base = (CAN_Type *)DT_INST_REG_ADDR(id), \
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(id)), \
.clock_subsys = (clock_control_subsys_t) \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_native_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static int can_native_linux_init(const struct device *dev)
#define CAN_NATIVE_LINUX_INIT(inst) \
\
static const struct can_native_linux_config can_native_linux_cfg_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 0), \
.if_name = DT_INST_PROP(inst, host_interface), \
}; \
\
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_nxp_s32_canxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ static const struct can_driver_api can_nxp_s32_driver_api = {
(Canexcel_Ip_RxFifoFilterID_ADDR *)&rx_fifo_filter##n,))\
}; \
static struct can_nxp_s32_config can_nxp_s32_config_##n = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(n, CAN_NXP_S32_MAX_BITRATE), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(n, 0, CAN_NXP_S32_MAX_BITRATE), \
.base_sic = (CANXL_SIC_Type *)DT_INST_REG_ADDR_BY_NAME(n, sic), \
IF_ENABLED(CONFIG_CAN_NXP_S32_RX_FIFO, \
(.base_rx_fifo = (CANXL_RXFIFO_Type *) \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_rcar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ static const struct can_driver_api can_rcar_driver_api = {
PINCTRL_DT_INST_DEFINE(n); \
static void can_rcar_##n##_init(const struct device *dev); \
static const struct can_rcar_cfg can_rcar_cfg_##n = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(n, 1000000), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(n, 0, 1000000), \
.reg_addr = DT_INST_REG_ADDR(n), \
.reg_size = DT_INST_REG_SIZE(n), \
.init_func = can_rcar_##n##_init, \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_stm32_bxcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ static void config_can_##inst##_irq(CAN_TypeDef *can) \
#define CAN_STM32_CONFIG_INST(inst) \
PINCTRL_DT_INST_DEFINE(inst); \
static const struct can_stm32_config can_stm32_cfg_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 1000000), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 1000000), \
.can = (CAN_TypeDef *)DT_INST_REG_ADDR(inst), \
.master_can = (CAN_TypeDef *)DT_INST_PROP_OR(inst, \
master_can_reg, DT_INST_REG_ADDR(inst)), \
Expand Down
2 changes: 1 addition & 1 deletion drivers/can/can_xmc4xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ static const struct can_driver_api can_xmc4xxx_api_funcs = {
\
static struct can_xmc4xxx_data can_xmc4xxx_data_##inst; \
static const struct can_xmc4xxx_config can_xmc4xxx_config_##inst = { \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 1000000), \
.common = CAN_DT_DRIVER_CONFIG_INST_GET(inst, 0, 1000000), \
.can = (CAN_NODE_TypeDef *)DT_INST_REG_ADDR(inst), \
.clock_div8 = DT_INST_PROP(inst, clock_div8), \
.irq_config_func = can_xmc4xxx_irq_config_##inst, \
Expand Down
11 changes: 8 additions & 3 deletions include/zephyr/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ typedef void (*can_state_change_callback_t)(const struct device *dev,
struct can_driver_config {
/** Pointer to the device structure for the associated CAN transceiver device or NULL. */
const struct device *phy;
/** The minimum bitrate supported by the CAN controller/transceiver combination. */
uint32_t min_bitrate;
/** The maximum bitrate supported by the CAN controller/transceiver combination. */
uint32_t max_bitrate;
/** Initial CAN classic/CAN FD arbitration phase bitrate. */
Expand All @@ -347,11 +349,13 @@ struct can_driver_config {
* @brief Static initializer for @p can_driver_config struct
*
* @param node_id Devicetree node identifier
* @param _min_bitrate minimum bitrate supported by the CAN controller
* @param _max_bitrate maximum bitrate supported by the CAN controller
*/
#define CAN_DT_DRIVER_CONFIG_GET(node_id, _max_bitrate) \
#define CAN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate) \
{ \
.phy = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, phys)), \
.min_bitrate = DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, _min_bitrate), \
.max_bitrate = DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, _max_bitrate), \
.bus_speed = DT_PROP(node_id, bus_speed), \
.sample_point = DT_PROP_OR(node_id, sample_point, 0), \
Expand All @@ -364,11 +368,12 @@ struct can_driver_config {
* @brief Static initializer for @p can_driver_config struct from DT_DRV_COMPAT instance
*
* @param inst DT_DRV_COMPAT instance number
* @param _min_bitrate minimum bitrate supported by the CAN controller
* @param _max_bitrate maximum bitrate supported by the CAN controller
* @see CAN_DT_DRIVER_CONFIG_GET()
*/
#define CAN_DT_DRIVER_CONFIG_INST_GET(inst, _max_bitrate) \
CAN_DT_DRIVER_CONFIG_GET(DT_DRV_INST(inst), _max_bitrate)
#define CAN_DT_DRIVER_CONFIG_INST_GET(inst, _min_bitrate, _max_bitrate) \
CAN_DT_DRIVER_CONFIG_GET(DT_DRV_INST(inst), _min_bitrate, _max_bitrate)

/**
* @brief Common CAN controller driver data.
Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/drivers/can/can_mcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ struct can_mcan_config {
#ifdef CONFIG_CAN_FD_MODE
#define CAN_MCAN_DT_CONFIG_GET(node_id, _custom, _ops, _cbs) \
{ \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 8000000), \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 0, 8000000), \
.ops = _ops, \
.callbacks = _cbs, \
.mram_elements = CAN_MCAN_DT_MRAM_ELEMENTS_GET(node_id), \
Expand All @@ -1306,7 +1306,7 @@ struct can_mcan_config {
#else /* CONFIG_CAN_FD_MODE */
#define CAN_MCAN_DT_CONFIG_GET(node_id, _custom, _ops, _cbs) \
{ \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 8000000), \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 0, 1000000), \
.ops = _ops, \
.callbacks = _cbs, \
.mram_elements = CAN_MCAN_DT_MRAM_ELEMENTS_GET(node_id), \
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/drivers/can/can_sja1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct can_sja1000_config {
*/
#define CAN_SJA1000_DT_CONFIG_GET(node_id, _custom, _read_reg, _write_reg, _ocr, _cdr) \
{ \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 1000000), \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, 0, 1000000), \
.read_reg = _read_reg, \
.write_reg = _write_reg, \
.ocr = _ocr, \
Expand Down

0 comments on commit 6d35ec7

Please sign in to comment.