Commit Graph

588 Commits

Author SHA1 Message Date
Henrik Brix Andersen 927c7ba193 drivers: can: fake: use delegate for reporting core clock rate
Use a delegate for reporting the core clock rate of the fake CAN
driver. This allows overriding the delegate at run-time and inspecting its
call count.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-02-01 13:19:46 +00:00
Andriy Gelman c7dab3df08 drivers: can: Add xmc4xxx CAN support
Adds CAN drivers for XMC4xxx SoCs.

XMC4xxx has multiple CAN nodes. The nodes share a common clock and
a message object pool.

The CAN nodes do not have a loopback mode. Instead there is an
internal bus which can be used to exchange messages between
nodes on the SoC. For this reason tests/samples which rely on the
loopback feature have been disabled.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2024-01-30 19:06:06 +01:00
Pisit Sawangvonganan defab59dc4 drivers: can: mcp251xfd: reducing number of *reg pointer dereferences
Reducing the number of times the code dereferences the pointer *reg,
which points to SRAM. By using a local variable tmp for operations before
assigning it to *reg.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-30 08:29:52 -05:00
Henrik Brix Andersen 64cedb5f35 drivers: can: stm32: bxcan: fix header order
Sort the included headers by name, remove unneeded includes and ensure
soc.h is included prior to the Zephyr CAN headers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-28 20:03:34 +01:00
Henrik Brix Andersen 5e9da13200 drivers: can: propagate CAN controller operation mode to CAN transceiver
Propagate the current CAN controller operation mode to the CAN transceiver
when enabling it.

Some more advanced CAN transceivers, especially those supporting Partial
Networking (CAN PN), require knowledge of the intended CAN operation mode
(e.g. normal mode vs. listen-only mode).

This commit simply prepares the CAN transceiver API for supporting such CAN
transceivers, although no in-tree drivers require this information yet.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 15:55:18 +00:00
Henrik Brix Andersen bde074714e drivers: can: shell: print name of associated CAN transceiver if present
Print the name of the associated CAN transceiver in the "can show" shell
subcommand.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 14:27:57 +01:00
Henrik Brix Andersen 583d44d7d5 drivers: can: add can_get_transceiver() system call
Add system call can_get_transceiver() for getting the CAN transceiver
associated with a CAN controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 14:27:57 +01:00
Henrik Brix Andersen 336d7ef7b4 drivers: can: shell: print current operation mode in show subcommand
Print the current operation mode in the "can show" shell subcommand.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 14:27:57 +01:00
Henrik Brix Andersen 69d072ad2f drivers: can: add can_get_mode() system call
Add system call can_get_mode() for getting the current operation mode of a
CAN controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 14:27:57 +01:00
Henrik Brix Andersen bc8d69caa6 drivers: can: stm32: bxcan: store current operation mode
Store the current operation mode in the can_driver_data structure.

Fixes: 9051824fa3

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-26 14:27:57 +01:00
Cong Nguyen Huu 7e5c260708 drivers: nxp_s32_canxl: remove support CAN FD mode for non-RX_FIFO
This is driver limitation after removing CAN_FILTER_FDF flag #65108.
CANXL driver need to know CAN_FILTER_FDF for configuring Rx filter
so that it receives CAN classic or CAN FD frames when using non RX_FIFO.
So update driver that just supports CAN classic for non RX_FIFO.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2024-01-24 12:28:00 +00:00
Andriy Gelman 12bc02031e drivers: can_mcp251xfd: Fix setting data phase parameters
Commit eeec09eb9a unintentionally modified
can_calc_timing_data() to be called with the nominal phase parameters
instead of the data phase parameters.

Before the change, the parameters were properly initialized in the macro
MCP251XFD_SET_TIMING_MACRO(inst, _data).
After the commit, can_calc_timing_data() gets called with the parameters
pointing to dev_cfg->common.sample_point instead of
dev_cfg->commom.sample_point_data.

This PR creates a separate function mcp251xfd_set_timing_data()
which calls can_calc_timing_data with the correct data parameters.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2024-01-24 10:45:00 +01:00
Henrik Brix Andersen 4340724fd0 drivers: can: use common accessor for getting maximum supported bitrate
Use a common accessor for getting the maximum supported bitrate of a CAN
controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-22 13:09:09 +01:00
Henrik Brix Andersen 766ce3c1e2 drivers: can: fake: add common configuration and data structures
Add common configuration and data structures to the fake CAN driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-22 13:09:09 +01:00
Henrik Brix Andersen fb639ab81b drivers: can: loopback: add common configuration structure
Add the common configuration structure to the CAN loopback driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-22 13:09:09 +01:00
Henrik Brix Andersen 3436c93387 drivers: can: remove run-time RTR filtering, add build-time RTR filter
A growing number of CAN controllers do not have support for individual RX
hardware filters based on the Remote Transmission Request (RTR) bit. This
leads to various work-arounds on the driver level mixing hardware and
software filtering.

As the use of RTR frames is discouraged by CAN in Automation (CiA) - and
not even supported by newer standards, e.g. CAN FD - this often leads to
unnecessary overhead, added complexity, and worst-case to non-portable
behavior between various CAN controller drivers.

Instead, move to a simpler approach where the ability to accept/reject RTR
frames is globally configured via Kconfig. By default, all incoming RTR
frames are rejected at the driver level, a setting which can be supported
in hardware by most in-tree CAN controllers drivers.

Legacy applications or protocol implementations, where RTR reception is
required, can now select CONFIG_CAN_ACCEPT_RTR to accept incoming RTR
frames matching added CAN filters. These applications or protocols will
need to distinguish between RTR and data frames in their respective CAN RX
frame handling routines.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-21 11:00:31 +01:00
Henrik Brix Andersen 75117a0deb drivers: can: remove CAN_FILTER_FDF flag
Remove the CAN_FILTER_FDF flag for filtering on classic CAN/CAN FD frames
as it is not supported natively by any known CAN controller.

Applications can still filter on classic CAN/CAN FD frames in their receive
callback functions as needed.

Fixes: #64554

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:55:43 +01:00
Henrik Brix Andersen eeec09eb9a drivers: can: mcp251xfd: flexcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen 639085b614 drivers: can: mcp2515: flexcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen b55051ca9e drivers: can: native_linux: flexcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen 2c7970d875 drivers: can: nxp: flexcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen fbe90f993b drivers: can: nxp: canxl: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen dfafe4c161 drivers: can: rcar: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen 9051824fa3 drivers: can: stm32: bxcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen b41714b1a6 drivers: can: sja1000: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen c71ae7d7c5 drivers: can: mcan: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Henrik Brix Andersen 38565a18fa drivers: can: loopback: use common config and data structures
Use the common CAN controller driver configuration and data structures.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-19 09:45:29 +01:00
Alexander Kozhinov 5db55b01af drivers: can: can_stm32h7_fdcan: add device fail on invalid fed clock value
Fail on wrong FDCAN clock in can_stm32h7_clock_enable() stage.

Signed-off-by: Alexander Kozhinov <ak.alexander.kozhinov@gmail.com>
2024-01-18 11:03:21 +01:00
Cong Nguyen Huu 9eb0a554f9 drivers: nxp_s32_canxl: add support RX FIFO
Driver supports both CAN classic and CAN FD frames
when using RX FIFO mode

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2024-01-16 20:50:49 -05:00
Alberto Escolar Piedras 5382f827d6 drivers can_native_linux: Avoid using ssize
ssize is a POSIX.1-2001 extension, which may or may
not be provided by the C library, or may be defined
to a different size in the host and embedded C library.

Two internal functions were returning ssize, but
one of them was a trampoline into the same host API,
which is already provided by the native simulator
so let's just use that instead.

The other is only carrying data that fits into an
int and is anyhow being cast in/to ints, so let's just
avoid the trouble by defining it as returning int.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-15 21:59:56 +01:00
Henrik Brix Andersen bc69500b0e drivers: can: stm32h7: fdcan: add support for domain clock and divider
Add support for specifying the domain/kernel clock along with a common
clock divider for the STM32H7 CAN controller driver via devicetree.

Previously, the driver only supported using the PLL1_Q clock for
domain/kernel clock, but now the driver defaults to the HSE clock, which is
the chip default. Update existing boards to continue to use the PLL1_Q
clock.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-10 20:59:55 -05:00
Henrik Brix Andersen 8785438d31 drivers: can: nuvoton: numaker: fix init function reference
Fix the reference to the init function.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-09 18:28:30 +01:00
Henrik Brix Andersen e24a3f5975 drivers: can: nuvoton: numaker: use named IRQs
Switch to using named IRQs as index-based access makes no guarantees about
devicetree interrupt order.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-09 18:28:30 +01:00
Henrik Brix Andersen b1cf5f0ffc drivers: can: nxp: mcan: use named IRQs
Switch to using named IRQs as index-based access makes no guarantees about
devicetree interrupt order.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-09 18:28:30 +01:00
Henrik Brix Andersen c9263db28f drivers: can: bosch: mcan: use int0 and int1 as interrupt names
Consistently use "int0" and "int1" as interrupt names for CAN controllers
based on the Bosch M_CAN IP core. This aligns with the upstream Linux
bindings.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-01-09 18:28:30 +01:00
Manuel Argüelles fa0b1b5fe8 drivers: can: flexcan: add support for S32K1xx
Add message buffer allowed values for S32K1xx devices. Except S32K14xW
parts which supports 64 MBs, the rest of the parts support a maximum of
32 MBs.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2024-01-08 08:30:49 -06:00
Henrik Brix Andersen 6d5d06689b drivers: can: native_linux: leave room for null termination of string
Only copy up to IFNAMSIZ - 1 number of characters of the interface name to
leave room for null termination of string.

Fixes: #66777

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-22 09:49:39 +01:00
Henrik Brix Andersen c067f4d263 drivers: can: native_linux: add missing return value check
Check return value from linux_socketcan_set_mode_fd() function call.

Fixes: #66798

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-22 09:49:39 +01:00
Sebastian Schlupp b504932ae9 drivers: can_sam0: added clock configuration for SAME5x devices
Added clock source configuration depending on SAM SoC series.

Signed-off-by: Sebastian Schlupp <sebastian.schlupp@gmail.com>
2023-12-12 16:25:46 +01:00
Henrik Brix Andersen fe74ffe2d5 drivers: can: drop POSIX from the native Linux SocketCAN driver name
Rename the native Linux SocketCAN driver to reflect that it can can now be
used in both native_posix and native_sim (with or without an embedded
C-library).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-12 14:28:26 +00:00
Henrik Brix Andersen c86f5c0f61 drivers: can: native_posix_linux: add embedded libc support
Add support for compiling the native POSIX Linux (SocketCAN) driver with an
embedded C-library.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-10 09:24:30 +01:00
Henrik Brix Andersen 399eb55381 drivers: can: native_posix_linux: remove unused functions
Remove the functions linux_socketcan_setsockopt() and
linux_socketcan_getsockopt() as they are unused.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-10 09:24:30 +01:00
Parthiban Nallathambi e9e430c40d can: mcp251xfd: fix compilation
Either switching to CAN_DEVICE_DT_INST_DEFINE with [1] missed
updating mcp251xfd or missed in merge. Fix using function
pointer for init in mcp251xfd.

[1]: https://github.com/zephyrproject-rtos/zephyr/pull/62925

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2023-12-01 10:48:23 +01:00
Andriy Gelman 1282194ac5 drivers: can: mcp251xfd: Skip payload in spi transfer when RTR flag is set
There's no need to transfer the payload bytes when the RTR flag set.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-11-20 09:25:08 +01:00
Andriy Gelman 8c607bf401 drivers: can: mcp251xfd: Increase max filters and change filter usage type
The mcp251xfd supports upto 32 filters. Also store the filter usage in
uint32_t instead of uint64_t.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-11-20 09:25:08 +01:00
Henrik Brix Andersen c0c8952739 shell: do not enable subsystem/driver shell modules by default
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.

The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.

This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-11-20 09:21:40 +01:00
Manuel Argüelles 8ca4f5b4a1 soc: nxp_s32: s32k3: drop `M7` suffix from options
The existing S32K3 Kconfig options employ the `M7` suffix, which is
redundant given that all cores in this series utilize an Arm Cortex-M7
core. Therefore, we should remove it.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-11-15 10:25:43 -06:00
Henrik Brix Andersen 4c33323c05 drivers: can: shell: add support for setting raw timing values
Add support for setting raw timing values.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-11-15 10:01:59 +01:00
Manuel Argüelles 1572ea16fc drivers: can: nxp_s32_canxl: use instance-based DT macros
At present, many of the NXP S32 shim drivers do not make use of
devicetree instance-based macros because the NXP S32 HAL relies on an
index-based approach, requiring knowledge of the peripheral instance
index during both compilation and runtime, and this index might not
align with the devicetree instance index.

The proposed solution in this patch eliminates this limitation by
determining the peripheral instance index during compilation
through macrobatics and defining the driver's ISR within the shim
driver itself.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-11-09 18:22:01 +01:00
Declan Snyder 6c25136e60 drivers: can: Fix Z_SYSCALL_OBJ->K_SYSCALL_OBJ
Fix can handler calling removed Z_SYSCALL_OBJ instead
of K_SYSCALL_OBJ

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-11-03 16:05:01 -05:00