Commit graph

622 commits

Author SHA1 Message Date
Henrik Brix Andersen 0cfca8be85 drivers: can: add accessor functions for the CAN statistics
Add accessor functions for the individual CAN statistics.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-23 10:33:04 +02:00
Anas Nashif 85c4703a46 drivers: fake: now just check for CONFIG_ZTEST
Old ztest API is deprecated, so only check for CONFIG_ZTEST.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Henrik Brix Andersen b9675b05d3 drivers: can: mcux: flexcan: override maximum HAL wait loop iterations
Add option for overriding the maximum number of wait loop iterations for
entering/leaving freeze mode. Set the default to 10000 (as opposed to a
default of 1000 used in the HAL).

Fixes: #56171

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:04:57 +01:00
Henrik Brix Andersen e6197fed5f drivers: can: stm32: bxcan: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen cb207c4a11 drivers: can: sja1000: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen bb4a22fdbc drivers: can: rcar: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen 443847f0f6 drivers: can: nxp: s32: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen c986dcc027 drivers: can: mcux: flexcan: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data. The limitation of how much data to copy is currently handled in the
NXP HAL.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen 66daf05435 drivers: can: mcp251xfd: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen 4d321448ad drivers: can: mcp2515: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data. Limit the amount of data copied to the actual DLC.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen 27323a8af5 drivers: can: mcan: only copy frame data for non-RTR frames
Only copy frame data for non-RTR frames as RTR frames do not carry any
data.

Fixes: #57002

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-13 10:08:45 +03:00
Henrik Brix Andersen fc078f9d02 drivers: can: sja1000: do not attempt to sleep in IRQ context
The can_sja1000_handle_error_warning_irq() function should only attempt to
start bus-off recovery, but not wait for the result.

Fixes: #63712

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-09 23:54:47 +03:00
Stephan Linz e7f399f4a3 drivers: can: avoid integer overflow in expression
Change the integer arithmetic to divide first before multiply.

The muliplication of sys_clock_hw_cycles_per_sec() by ten leads
to a really big number on boards with high-speed clocking, thus
to the overflow warning, and to errors for integration tests.

Fixes: #63678

Signed-off-by: Stephan Linz <linz@li-pro.net>
2023-10-09 10:39:43 +01:00
Henrik Brix Andersen 410c02ac57 drivers: can: sja1000: remove excessive debug logging
Remove excessive debug logging from the SJA1000 driver backend. Logging
each register access makes generic CAN debug logging unusable.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-06 17:43:36 +03:00
Abram Early 6e789e7492 drivers: can: mcan: Move RF0L and RF1L to line 1
The code is designed to handle RF0L and RF1L in
line 1, but they were being sent to line 0. Becuase
they weren't handled, the interrupts would never
be handled which locked up the chip.

Signed-off-by: Abram Early <abram.early@gmail.com>
2023-10-06 16:14:03 +03:00
Henrik Brix Andersen f91bfae0a7 drivers: can: mcux: flexcan: validate initial timing parameters
Validate the initial timing parameters set via devicetree.

Fixes: #61909

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-03 18:16:46 +01:00
Henrik Brix Andersen 9bf17f9276 drivers: can: remove unnecessary asserts in timing callbacks
Remove unnecessary calls to __ASSERT_NO_MSG() in CAN controller driver
timing setter callbacks. The CAN API functions can_set_timing and
can_set_timing_data() already provide run-time timing parameter validation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-10-02 16:59:42 +01:00
Andriy Gelman 31bef35897 drivers: can: mcp251xfd: Add driver
This continue PR #31270. The updated changes are:
- Updated to work with latest zephyr
- Inplace reads/writes of registers
- Batch read of RX messages when multiple messages can be read
- FIFO abstraction of RX/TEF queues
- Handle ivmif errors
- Use READ_CRC for register reads
- Use bitmasks instead of bitfield members
- Rename mcp25xxfd to mcp251xfd
- General cleanups

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-10-01 09:20:37 +03:00
Abram Early 33277f9b48 drivers: can: Implement MCP25xxFD driver
Implementation for Microchip MCP2517FD/MCP2518FD SPI based CAN-FD
controller.

Signed-off-by: Abram Early <abram.early@gmail.com>
2023-10-01 09:20:37 +03:00
Henrik Brix Andersen a9d3935fa0 drivers: can: solely use sjw from devicetree for initial timing
Update the CAN controller drivers to solely use the sjw and sjw-data
devicetree properties for setting the initial timing when devicetree timing
parameters are specified in Time Quanta (TQ).

Any timing set via the CAN timing APIs will contain either user-provided or
automatically calculated SJW values. This includes any timing parameters
calculated from bus-speed and bus-speed-data devicetree properties.

Update the CAN controller driver tests accordingly and remove the
CAN_SJW_NO_CHANGE definition as it has lost its meaning.

Fixes: #63033

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-28 16:28:56 +02:00
Henrik Brix Andersen e397b85eb8 drivers: can: calculate a default SJW value
Change the CAN timing calculation APIs to automatically calculate a default
(Re-)Synchronization Jump Width (SJW) value. The calculated value can be
overwritten by the caller if desired.

This allows automatically scaling the SJW according to the number of Time
Quanta (TQ) used for phase segment 2 instead of relying on a compile-time
fallback value defined in devicetree.

This reduces the can_set_timing()/can_set_timing_data() API functions to
simple setters (with validation).

Fixes: #63033

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-28 16:28:56 +02:00
Henrik Brix Andersen c1ad82e5fb drivers: can: mcux: flexcan: fix initial of CAN-FD timing when using TQs
Fix the assignment of initial CAN bus timing parameters for the CAN-FD data
phase.

Fixes: #62979

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-24 20:47:32 -05:00
Henrik Brix Andersen 49ab0b22f0 drivers: can: switch to CAN_DEVICE_DT_INST_DEFINE for remaining drivers
Switch from using DEVICE_DT_DEFINE()/DEVICE_DT_INST_DEFINE() to using
CAN_DEVICE_DT_DEFINE()/CAN_DEVICE_DT_INST_DEFINE() for remaining drivers.

This unifies CAN controller device driver initialization regardless of the
driver implementing CAN statistics support or not.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-22 08:37:05 -05:00
Manuel Argüelles af7d972f4c can: nxp_s32_canxl: use clock control APIs
Use clock control API to retrieve the module's frequency and
update the boards using it to provide the source clocks.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-09-21 13:37:19 +02:00
Grant Ramsay 663826a9f9 drivers: can: mcan: Add CAN statistics
Add CAN stats for MCAN drivers.

Update MCAN drivers to use CAN_DEVICE_DT_INST_DEFINE
which initialises and registers CAN stats if enabled.

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-09-21 13:36:52 +02:00
Henrik Brix Andersen 9bd62f16b6 drivers: can: add tcan4x5x CAN controller driver
Add driver for the TI TCAN4x5x series of CAN controllers. These CAN
controllers are based on the Bosch M_CAN IP and interfaced via an SPI bus.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-11 19:55:44 +02:00
Max van Kessel efaf4a6b34 drivers: can: stm32: fix typo in phy dt assignment
To attach the correct phy, the instance must be givin instead of the id.

Signed-off-by: Max van Kessel <max_van_kessel@msn.com>
2023-08-31 09:59:36 -04:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Grant Ramsay 12c568f43a drivers: can: mcan: fix format string warning
A warning was being produced on compilers where size_t is an unsigned long

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay 12d6e268cd drivers: can: mcan: tidy TX complete semaphore usage
"callback != NULL" is used to determine if the callback is in use.
The TX complete semaphone should only be given back after setting the
callback to NULL.

This would likely only be a race condition if the ISR is processed on a
different core to the TX call.

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay e9bc195bf4 drivers: can: mcan: manually track available TX buffers
The MCAN driver operates in TX queue mode (TXBC.TFQM = 1). In this mode
TXFQS.TFQPI returns the first available buffer (usually buffer zero).

Hardware is free to re-use a buffer as soon as TX completes, it does not
have to wait for the matching TX event to be processed.

If a TX completes and that TX buffer is re-used before processing the TX
event, two TX events for the same buffer occur. The first event calls the
second events TX callback, and the second event results in a NULL pointer
exception.

In a "normal" configuration, the TX event ISR will always preempt the
queuing of a TX frame to the same TX buffer.
However, this issue could occur if:
 * Sending a message with ISRs temporarily disabled.
 * The ISR is processed on a different core to the TX call.

The fix is to manually track which TX buffers are available, only freeing
a buffer after the TX event has been processed.

The MCAN user manual states that this is allowed:
"The application may use register TXBRP instead of the Put Index and may
place messages to any Tx Buffer without pending transmission request"

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay cff1496166 drivers: can: mcan: fix off-by-one error in assert
Fix off-by-one error in assert

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay 08d19954b9 drivers: can: mcan: clear TX callback on failed TX
Elsewhere, "callback != NULL" is used to determine if the callback is in
use

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay e98f7b8fb7 drivers: can: mcan: give back semaphore on failed TX
Give back semaphore on failed TX

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Grant Ramsay 58e60a028f drivers: can: mcan: unlock mutex on failed TX mram write
Unlock mutex on failed TX mram write

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-28 08:23:37 +01:00
Henrik Brix Andersen de172f88d0 drivers: can: stm32h7: fdcan: rename driver to match reference manuals
Rename the STM32H7 FDCAN driver Kconfig symbol and implementation file to
match the naming used in the ST reference manuals.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Henrik Brix Andersen 8b16dbe308 drivers: can: stm32h7: fdcan: fold Kconfig file into stm32 Kconfig file
Fold the Kconfig options for the STM32H7 FDCAN driver into the main
Kconfig.stm32 file.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Henrik Brix Andersen 8410e9ab85 drivers: can: stm32: fdcan: rename driver to match reference manuals
Rename the STM32 FDCAN driver Kconfig symbol and implementation file to
match the naming used in the ST reference manuals.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Henrik Brix Andersen ff85523d04 drivers: can: stm32: fdcan: fold Kconfig file into stm32 Kconfig file
Fold the Kconfig options for the STM32 FDCAN driver into the main
Kconfig.stm32 file.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Henrik Brix Andersen 913e59c5ea drivers: can: stm32: bxcan: rename driver to match reference manuals
Rename the STM32 bxCAN driver DTS compatible, Kconfig symbol, and
implementation file to match the naming used in the ST reference manuals.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Henrik Brix Andersen ff722597e8 drivers: can: stm32: bxcan: fold private header into implementation file
Fold the contents of the private header for the STM32 bxCAN driver into the
implementation file.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-08-16 13:03:00 +02:00
Thomas Stranger cec279b5b6 drivers: can: stm32: correct timing_max parameters
The timing_max parameters defined in the stm32 bxcan driver don't match the
register description in the reference manuals.
- sjw does have only 2 bits representing 1 to 4 tq.
- phase_seg1 and phase_seg2 max is one tq higher.

I have checked the following reference manuals and all match:
- RM0090: STM32F405, F415, F407, F417, F427, F437 AND F429
- RM0008: STM32F101, F102, F103, F105, F107 advanced arm-based mcus
- RM0351, RM0394: all STM32L4
- RM0091: all STM32F0 with CAN support

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2023-08-16 10:24:26 +02:00
Thomas Stranger 8009ccce43 drivers: can: mcux: flexcan: can_set_mode supports can_mode_3_samples
In case CAN-FD mode is not enabled the mcux flexcan driver supports
CAN_MODE_3_SAMPLES.
This has been removed inadvertently while adding can-fd support.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2023-08-15 10:11:32 -07:00
Henrik Brix Andersen de656c1169 drivers: can: sam: do not select cache management
Do not select CONFIG_CACHE_MANAGEMENT in the Microchip SAM CAN driver
Kconfig but rather leave it up to the SoC/platform Kconfig to enable it as
needed and enable CACHE_MANAGEMENT by default for the Atmel SAM E70/V71 SoC
series.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2023-07-31 19:38:22 +00:00
Henrik Brix Andersen b809d5ce10 drivers: can: stm32h7: fix message RAM address calculations
Calculate the Bosch M_CAN Message RAM addresses relative to the Message RAM
Base Address (MRBA), not the offset.

Fixes: #59624

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2023-07-31 10:09:47 +02:00
Cong Nguyen Huu a3fb2dcc2f drivers: can: add kconfig CAN_MAX_MB
Each CAN instance of S32K344 has different maximum number
of message buffers, depends on payload. Add kconfig that
defines maximum number of message buffers for concurrent
active instances and update driver to compatible
support S32k344.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-07-27 11:06:45 -05:00
Marek Matej 938732c00d drivers: can: fix long lines
Change the line length to comply with the rules.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-25 18:12:33 +02:00
Marek Matej 6b57b3b786 soc: xtensa,riscv: esp32xx: refactor folder structure
Refactor the ESP32 target SOCs together with
all related boards. Most braking changes includes:

- changing the CONFIG_SOC_ESP32* to refer to
  the actual soc line (esp32,esp32s2,esp32s3,esp32c3)
- replacing CONFIG_SOC with the CONFIG_SOC_SERIES
- creating CONFIG_SOC_FAMILY_ESP32 to embrace all
  the ESP32 across all used architectures
- introducing CONFIG_SOC_PART_NUMBER_* to
  provide a SOC model config
- introducing the 'common' folder to hide all
  commonly used configs and files.
- updating west.yml to reflect previous changes in hal

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-25 18:12:33 +02:00
Daniel Leung 26ecaba4af drivers: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Henrik Brix Andersen c05d629841 drivers: can: mcan: remove excessive debug on register access
Remove excessive debug output on Bosch M_CAN register access. This was
accidentially included in commit bbfc1f905c.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-12 07:28:57 -04:00
Henrik Brix Andersen bb513c974b drivers: can: mcan: fix IRQ acknowledge
Change the Bosch M_CAN ISRs to only acknowledge the IRQs handled in the
given loop iteration (and not all IRQs supported by the given ISR) and move
IRQ acknowledge to the front of the ISRs.

Fixes: #58631

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-02 15:06:40 -04:00
Henrik Brix Andersen defdbc2fae drivers: can: mcp2515: increase default stack size
Increase the default stack size for the MCP2515 CAN controller driver from
512 to 1024 bytes.

Fixes: #58761

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-02 09:43:16 +02:00
Henrik Brix Andersen bab0c0879d drivers: can: mcp2515: set thread name
Set the thread name for the MCP2515 CAN controller driver to aid in
debugging.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-02 09:43:16 +02:00
Henrik Brix Andersen b12eb78f35 drivers: can: increase default initialization priority from 50 to 80
Increase the default CAN controller driver initialization priority from
KERNEL_INIT_PRIORITY_DEVICE (50) to 80 to allow CAN controllers on SPI
busses have their bus initialized prior to initializing the CAN controller
driver.

The only in-bound dependency on CAN controller drivers - apart from
application level code - is the drivers/net/canbus.c driver, which already
defaults to an initialization level of 81.

Fixes: #55745

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-01 19:03:12 -04:00
Henrik Brix Andersen c9f97cf386 drivers: can: mcan: move header file to public includes
Move the Bosch M_CAN header file to include/zephyr/drivers/can/can_mcan.h
for use in out-of-tree drivers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-01 18:04:42 -04:00
Henrik Brix Andersen 3932b9f124 drivers: can: mcan: document remaining header
Add documentation for the remaining functions, structs, and definitions in
the Bosch M_CAN header file. Fix a few mistyped Message RAM field names
along with misnamed macros and function found while adding documentation.

No functional changes.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-01 18:04:42 -04:00
Henrik Brix Andersen 17f0356c36 drivers: can: mcan: change asserts to match updated timing parameters
Update the asserts to match the updated Bosch M_CAN minimum/maximum CAN
timing parameters.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen fd6ba71076 drivers: can: stm32fd: use bosch m_can timing parameter initializers
The minimum/maximum CAN timing parameters for the STM32 FDCAN driver uses
the wrong values for the minimum, nominal phase segment values.

Using the static initializers fixes these and aligns them to the Bosch
M_CAN manual. The STM32G4 reference manual contains contradicting limits
for these register values.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 52a8f821fa drivers: can: stm32h7: use bosch m_can timing parameter initializers
The minimum/maximum CAN timing parameters for the STM32H7 FDCAN driver uses
the wrong values for the minimum, nominal phase segment values.

Using the static initializers fixes these and aligns them to the Bosch
M_CAN manual. The STM32H7 reference manual contains contradicting limits
for these register values.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 56b90e3f63 drivers: can: sam0: use bosch m_can timing parameter initializers
The minimum/maximum CAN timing parameters for the Atmel SAM0 CAN driver
uses the wrong values for the minimum, nominal phase segment values. The
same goes for the maximum, nominal SJW value.

Using the static initializers fixes these and aligns them to the Bosch
M_CAN manual. The Atmel SAM C20/C21 family data sheet contains
contradicting limits for these register values.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 6d2a42c21e drivers: can: sam: use bosch m_can timing parameter initializers
The minimum/maximum CAN timing parameters for the Atmel SAM CAN driver uses
the wrong values for the minimum, nominal phase segment values. The same
goes for the maximum, nominal SJW value.

Using the static initializers fixes these and aligns them to both the Bosch
M_CAN manual and the Atmel SAM E70 family data sheet.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 1871fa7823 drivers: can: mcux: mcan: use bosch m_can timing parameter initializers
Some NXP SoC reference manuals contain a bug regarding the minimum values
for nominal phase segments. Valid Bosch M_CAN nominal phase segment
register values are 1 and up. Same goes for the maximum value for data
phase segment 2. Here, valid Bosch M_CAN register values are 0 to 31.

Using the static initializers fixes these.

Fixes: #58429

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 6b13900618 drivers: can: mcan: add static initializer macros for timing parameters
Add static initializers for the Bosch M_CAN minimum/maximum CAN timing
parameter values.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-31 06:16:00 -04:00
Henrik Brix Andersen 5f67426b93 drivers: can: mcan: do not iterate all filter elements to find free one
There is no need for iterating all the Bosch M_CAN filter elements in
Message RAM in order to find a free filter as the driver already keeps
track of assigned filters.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen 0f36f1a3ee 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>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen d112e08f0c drivers: can: mcan: remove unused message marker split
The Bosch M_CAN Message Marker, an 8-bit field copied from Tx Buffer
elements to Tx Event FIFO elements to aid software in identifying Tx frame
status, need not be split into an index and a count, as the count is
unused.

Remove this split and replace "struct can_mcan_mm" with a simple "uint8_t".

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen d452a0043d drivers: can: mcan: add build asserts for message RAM configuration
Add build asserts to ensure the Message RAM configuration meets the
IP core restrictions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen de659f9f61 drivers: can: stm32: fdcan: message RAM layout is fixed
The Message RAM layout used by the STM32 FDCAN IPs contains a fixed number
of elements, even though the software can opt to use less standard/extended
filter elements. Change the BUILD_ASSERT() statements to reflect this.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen 3ed354eea1 drivers: can: mcan: let front-end drivers supply message RAM functions
Let the Bosch M_CAN front-end drivers supply their own Message RAM
read/write/clear functions.

This is preparation for supporting per-instance Bosch M_CAN Message RAM
layouts and for accessing Bosch M_CAN IP cores over peripheral busses.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen 6cd67e67fe dts: bindings: can: mcan: switch to using bosch,mram-cfg property
Switch the Bosch M_CAN devicetree binding to use a bosch,mram-cfg property
for specifying the memory layout of the Bosch M_CAN Message RAM. This is
identical to the Linux kernel devicetree binding for Bosch M_CAN IP core
based CAN controllers.

This introduces an offset cell which can be used for controllers with
shared Message RAM between Bosch M_CAN instances.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen c52499e447 drivers: can: mcan: document return values from typedef API functions
Document that the Bosch M_CAN read/write register functions are allowed to
return -ENOTSUP for unsupported registers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen 78f956f308 drivers: can: mcan: reindent register definitions
Reindent the Bosch M_CAN register definitions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-29 14:34:19 -04:00
Henrik Brix Andersen 183e0f854b drivers: can: sam0: remove unused variable
Remove unused variable (only ever assigned) from the Atmel SAM0 CAN driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-28 14:20:21 -04:00
Aymeric Aillet 8959b838bf drivers: can: Fix R-Car driver can_stop behavior
Calling for can_stop() method was not emptying FIFOs
and tx_msgq.
Resetting TX FIFO to empty it.
Emptying tx_msgq with "ENETDOWN" return code.

Fixes #50546

Signed-off-by: Aymeric Aillet <aymeric.aillet@iot.bzh>
2023-05-24 19:43:45 -04:00
Kamil Serwus b63a9af07d can: mcan: fix setup configuration ram
SAM0 required can module was in init state before configure
pointers to ram which handle can frames.

Signed-off-by: Kamil Serwus <kserwus@gmail.com>
2023-05-22 08:03:58 +00:00
Kamil Serwus 632704e04b sam: can: CAN driver for SAM0 socs
Driver was based on can_sam. SAMC21 has only 1 interrupt for one
can "output", so can interrupt has to executes two lines of
interrupts.
CAN is configured to use OSC48M clock via GLCK7. GLCK7 is set
by divider configured from dts.

Signed-off-by: Kamil Serwus <kserwus@gmail.com>
2023-05-22 08:03:58 +00:00
Henrik Brix Andersen 7c3a708ab8 drivers: can: stm32: guard Kconfig options
Add Kconfig guards for CONFIG_CAN_MAX_STD_ID_FILTER and
CONFIG_CAN_MAX_EXT_ID_FILTER as they only apply to the STM32 bxCAN driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-12 10:51:49 +00:00
Henrik Brix Andersen 10e25351d6 drivers: can: stm32h7: remove unused std/ext filter size Kconfig options
Remove the STM32H7 specific Kconfig overrides for setting the maximum
number of standard and extended CAN RX filters as they are unused.

The number of available standard and extended filter elements for Bosch
M_CAN can be configured via the devicetree.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-12 10:51:29 +00:00
Henrik Brix Andersen 3ee2b4c31a drivers: can: stm32: fdcan: move register definitions to implementation
Move definitions of the STM32 FDCAN specific registers to the front-end
driver implementation and implement remapping of these registers to/from
the standard Bosch M_CAN registers.

Some of the STM32 FDCAN register bit fields are limited in size compared to
the Bosch M_CAN specification. This is due to hardware limitations on the
number of elements in the various sections of the Message RAM. Add build
assertions to ensure the number of elements specified do not exceed the
hardware limitations instead of using custom definitions for these fields.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen 89f4330f94 drivers: can: mcux: mcan: move register definition to implementation
Move definition of the NXP LPC MCAN specific Message RAM Base Address
register (MRBA) to the front-end driver implementation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen a781ccde0f drivers: can: mcan: move message RAM configuration to front-end drivers
Some Bosch M_CAN IP core implementations use a fixed Message RAM
configuration, other use a fixed memory area and relative addressing,
others again have custom registers for configuring the Message RAM.

Move the responsibility for configuring the various Bosch M_CAN Message RAM
addresses to the front-end drivers. This removes some of the front-end
specific code from the backend. Provide a helper function for configuring
the most common variations.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen 65350b8362 drivers: can: mcan: allow drivers front-ends to read/write registers
Expose the can_mcan_read_reg()/can_mcan_write_reg() along with all the
Bosch M_CAN register definitions for use in Bosch M_CAN driver front-ends.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen bbfc1f905c drivers: can: mcan: let front-end drivers supply register r/w functions
Let the Bosch M_CAN front-end drivers supply their own register read/write
functions.

This is preparation for handling non-standard Bosch M_CAN register layouts
directly in the front-end and for accessing Bosch M_CAN IP cores over
peripheral busses.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen 1c0a43ec45 drivers: can: mcan: use sys_read32()/sys_write32() for register access
Use sys_read32()/sys_write32() instead of volatile struct for register
access. Be consistent in using unsigned constants in register
comparisons. Use locking around register read-modify-write operations.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-10 15:28:11 +02:00
Henrik Brix Andersen 6ae5efd663 drivers: can: mcan: regenerate register field definitions
Regenerate/rewrite the Bosch M_CAN register field definitions using the
GENMASK() and BIT() macros.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen d7ae40bbc2 drivers: can: mcan: use uintptr_t for pointer mathematics
Use uintptr_t for doing pointer mathematics.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen c4ae88bea0 drivers: can: mcan: use FIELD_PREP/FIELD_GET macros
Use the FIELD_PREP() and FIELD_GET() macros instead of manual bitshifts and
masking. Be consistent in the use of register field definition macros.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen 522f87edf6 drivers: can: mcan: remove unused includes
Remove unused includes and sort the remaining includes alphabetically.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen 73ecdd9c91 drivers: can: mcan: use consistent #ifdef ... #else ... #endif comments
Use consistent comments for #ifdef ... #else ... #endif statements to
improve code readability.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen 98eac75cb2 drivers: can: mcan: rename local config struct variables
Rename the local "const struct can_mcan_config *" variables from "cfg" to
"config" to be consistent with Zephyr conventions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen cb904c8a83 drivers: can: mcan: get rid of can_mcan_configure_timing() helper function
Get rid of the can_mcan_configure_timing() helper function as it provides
no benefit to just having the implementation split in can_mcan_set_timing()
and can_mcan_set_timing_data().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen df6eda64fb drivers: can: mcan: move the driver init function to the bottom of the file
Move the driver initialization function to the bottom of the file to be
consistent with Zephyr conventions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen a3a4144697 drivers: can: mcan: use proper namespace for internal functions
Use the "can_mcan_*" namespace for all driver-internal functions to improve
code readability.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen 2c2165dba3 drivers: can: mcan: pass struct device pointer to internal functions
Pass a pointer to the struct device for internal driver functions instead
of passing around a pointer to the register struct.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Henrik Brix Andersen e1fe5e9a1c drivers: can: mcan: reformat source files
Reformat source files using clang-format prior to refactoring the driver
code.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-02 19:26:09 +09:00
Cong Nguyen Huu cad17ff933 drivers: can: support NXP S32 CANEXCEL
This patch introduces support for NXP S32 CANEXCEL (CANXL) peripheral.

CAN protocol supporting:
- CAN classic
- CAN FD

Remote transmission request is not supported as this feature is not
available on NXP S32 CANXL HAL.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-04-29 12:23:40 +02:00
Gerard Marull-Paretas 989d103d53 drivers: all: mcux: remove conditional support for pinctrl
The MCUX platform always uses pinctrl, there's no need to keep extra
macrology around pinctrl. Also updated driver's Kconfig options to
`select PINCTRL` (note that some already did).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-24 13:34:22 +02:00
Gerard Marull-Paretas 1eb683a514 device: remove redundant init functions
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-19 10:00:25 +02:00
Henrik Brix Andersen 95b8bf3121 drivers: can: mcux: flexcan: add FlexCAN CANFD variant support
Add support for CAN-FD capable variants of the FlexCAN IP core.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-04-13 10:00:03 +02:00
Henrik Brix Andersen a082565dca dts: bindings: can: rename nxp,kinetis-flexcan binding to nxp,flexcan
Rename the nxp,kinetis-flexcan devicetree compatible to nxp,flexcan as it
is not specific to the NXP Kinetis series.

This is preparation for adding a nxp,flexcan-fd binding.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-04-13 10:00:03 +02:00
Gerard Marull-Paretas ba9b280893 drivers: can: mcan: remove unused CAN_DIV_CEIL
Macro is not used, so delete it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Pieter De Gendt 6b532ff43e treewide: Update clock control API usage
Replace all (clock_control_subsys_t *) casts with (clock_control_subsys_t)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-05 10:55:46 +02:00
Henrik Brix Andersen 4ec054aa45 drivers: can: mcux: flexcan: add missing mutex unlock in error path
Add missing mutex unlock to error handling path in
mcux_flexcan_add_rx_filter().

Fixes: #56284

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 21:45:43 +00:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Henrik Brix Andersen 718099607e drivers: can: common: document sample point calculation function
Add documentation for the update_sampling_pnt() function and rename a few
internal variables to improve readability.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-27 09:50:24 +02:00
Henrik Brix Andersen ffefc6441b drivers: can: common: respect the range limits of phase_seg1
Respect the range limits of phase_seg1 when attempting to distribute ts1
between prop_seg and phase_seg1.

Even distribution may not be possible if the allowed ranges of prop_seg and
phase_seg1 are not equal.

Fixes: #55919

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-27 09:50:24 +02:00
Henrik Brix Andersen 7073da0257 drivers: can: common: include sync segment in timing calculation
Always include the SYNC segment of 1 time quanta when calculating ts1 and
ts2.

Fixes: #55919

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-27 09:50:24 +02:00
Henrik Brix Andersen d5672c9ee3 drivers: can: check timing parameters
Check the requested CAN timing parameters against the min/max values
supported by the driver and return an error if they are out of range.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-23 09:40:34 +01:00
Henrik Brix Andersen 9dc9f0a0fd drivers: can: common: add missing static for sample_point_for_bitrate()
Add missing static keyword for internal function
sample_point_for_bitrate().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-23 09:40:34 +01:00
Gerson Fernando Budke 41ab680a4f drivers: can: sam: Update to use clock control
This update Atmel SAM can driver to use clock control driver.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-03-21 14:12:25 -07:00
Henrik Brix Andersen 37b3a11d72 drivers: can: shell: add debug log for calculated timing parameters
Add debug logs for the timing parameters calculated by the shell commands.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-20 09:53:14 +01:00
Henrik Brix Andersen 1c7feb3fd4 drivers: can: shell: show min/max timing parameters
Include the minimum/maximum timing parameters when showing details about a
CAN controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-20 09:53:14 +01:00
Henrik Brix Andersen 3c89bbf876 drivers: can: reset statistics when starting the CAN controller
Reset CAN controller statistics when starting the CAN controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-20 09:52:50 +01:00
Henrik Brix Andersen 7442637201 drivers: can: shell: add support for setting SJW
Add support for setting the Synchronization Jump Width (SJW) for both the
classic/arbitration phase and the CAN-FD data phase.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-15 09:12:04 +01:00
Henrik Brix Andersen 641b89801a drivers: can: mcan: add support for CAN-FD ESI flag
Add support for the CAN-FD Error State Indicator (ESI) flag in received
frames.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-11 19:45:14 +01:00
Henrik Brix Andersen e08546fe98 drivers: can: shell: add support for the CAN-FD ESI flag
Print the CAN-FD Error State Indicator (ESI) flag as "P" for "Passive" in
received frames.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-11 19:45:14 +01:00
Henrik Brix Andersen 0f2b17b5e1 drivers: can: shell: add support for CAN-FD frame format filters
Add shell support for adding filters for CAN-FD format frames.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-10 12:21:03 -08:00
Henrik Brix Andersen eb9bbf4490 drivers: can: sja1000: move public header file to public include path
Move the can_sja1000.h header file to the public
include/zephyr/drivers/can/ include path. This allows writing out-of-tree
SJA1000 based driver front-ends.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:34 +01:00
Henrik Brix Andersen 36bffb20ae drivers: can: move CAN utility function to public header
Rename the can_utils_filter_match() utility function to
can_frame_matches_filter(), move it to the public
include/zephyr/drivers/can.h header file, and add a missing mismatch for
standard (11-bit) ID frames passing extended (29-bit) filters.

This allows using the utility function in out-of-tree CAN drivers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:12 +01:00
Benjamin Björnsson 500809f8fa drivers: can: can_loopback: Abort pending messages when stopped
This commit aims at updating the drivers stop function to better
follow the CAN header file which specifiec that stopping the CAN
controller should "abort any pending CAN frame transmissions".

Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
2023-01-27 00:58:59 +09:00
Henrik Brix Andersen 55d0ffa874 drivers: can: remove CAN_HAS_CANFD Kconfig helper
Remove the CAN_HAS_CANFD Kconfig helper symbol in order to allow enabling
CAN-FD support in the API regardless of driver support.

Change default to CAN-FD support being disabled and have samples and tests
that require CAN-FD support turn it on. This aligns the default
configuration across CAN controller drivers regardless of their
capabilities.

The rationale behind this is that we are starting to see MCUs with multiple
CAN controllers, some CAN-FD compatible, some not (e.g. NXP i.MX RT1060 and
FPGAs). Automatically enabling CAN-FD support based on the presence of a
CAN-FD capable CAN controller leads to different application default
settings based on the CAN controller(s) in use.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-25 15:00:39 +00:00
Henrik Brix Andersen f1a7ec96db drivers: can: remove CAN_HAS_RX_TIMESTAMP Kconfig helper
Remove the CAN_HAS_RX_TIMESTAMP Kconfig helper symbol in order to allow
enabling CAN RX timestamps in the API regardless of driver support.

This simplifies application prj.conf settings across board supporting/not
supporting RX timestamps considerably.

CAN drivers not supporting RX timestamps already initialize the timestamp
to 0 for received frames.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-25 15:00:39 +00:00
Henrik Brix Andersen 51cac9e04f drivers: can: rcar: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the Renesas R-Car
CAN driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen 8b896fdf01 drivers: can: stm32: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the ST STM32 bxCAN
driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen 5517a935d0 drivers: can: mcux: flexcan: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the NXP FlexCAN
driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen 46136b3c12 drivers: can: mcux: flexcan: fix handling of failed RX MB reads
Fix handling of failed NXP FlexCAN RX mailbox reads. Instead of re-enabling
the RX MB in the ISR, we need to handle a failed RX MB read (e.g. due to a
busy MB bit).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Cong Nguyen Huu d167d3a29a driver: can: add new filter to match CAN-FD frames
Add support FD frame filter to configure type frame for
each Rx msg to receive corresponding frames (classic, FD frames).

The Bosch M_CAN driver does not support FD frame filter,
so inmplement driver to handle it in software.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-01-04 08:18:13 -06:00
Martin Jäger c8c0879963 drivers: can: mcan: Fix flag overflow for some MCUs
The number of extended filters can be up to 15 for MCUs like the NXP
LPC55Sxx series, so the flags don't fit into uint8_t.

Fixes #53417

Signed-off-by: Martin Jäger <martin@libre.solar>
2023-01-04 14:24:35 +01:00
Mikhail Siomin d4f65e4031 mcux: flexcan: fixes the race condition
Since the FLEXCAN_TransferSendNonBlocking() function has
read-modify-write operations on global resources, then
if interrupts are enabled and/or if there is more than
one thread with a different priority, threads with
a lower priority can overwrite global resource changes
made by higher priority threads.
Fixes #52673.

Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
2023-01-03 11:01:31 +01:00
Bartosz Bilas e077fb73ec drivers: tests: replace usage of spi_is_ready with spi_is_ready_dt
`spi_is_ready` function is being deprecated in favor of
`spi_is_ready_dt` so let's replace the old usage in the tree.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-12-07 09:40:23 -06:00
Carlo Caione cc427b4bb0 cache: Fix libraries and drivers
Fix the usage to be compliant to the new cache API.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-01 13:40:56 -05:00
Johan Hedberg e9b39efe9e drivers: can: kvaser_pci: Convert to use dynamic BDF lookup
Use the new PCIe core infrastructure for looking up the BDF at runtime
based on the VID/DID values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Johan Hedberg 54513c70d1 drivers: can: kvaser_pci: Fix incorrect RAM context struct type
The can_kvaser_pci_data_##inst type was supposed to be
can_kvaser_pci_data and not can_kvaser_pci_config. This got unnoticed
because there were no struct members to pre-initialize, and a reference
to the struct was stored using a void pointer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-11 12:10:09 +01:00
Perry Hung 9b5bc03f86 drivers: can: sam: select CACHE_MANAGEMENT for SAM M_CAN
A regression was introduced in ef804d8408
when the M_CAN driver was swapped to use the generic dcache API, but
cache management was not enabled on SAM devices.

Enable cache management on SAM devices when CAN_SAM is selected.

Signed-off-by: Perry Hung <perry@genrad.com>
2022-11-08 15:41:10 -05:00
Henrik Brix Andersen f30a5969d0 drivers: can: make the fake CAN driver generally available
Make the fake CAN controller driver available for use in tests outside of
the CAN shell test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 08:19:33 -07:00
Henrik Brix Andersen 566c64f0c0 drivers: can: loopback: guard against out-of-bounds filter IDs
Guard against out-of-bounds filter IDs when removing RX filters.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen efd0d3ba96 drivers: can: loopback: add log message for full TX msgq
Emit a debug log message if the TX message queue is full.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen 728138023b drivers: can: loopback: rename receive function
Rename the CAN loopback driver receive function to make the code easier to
understand. Add proper check against NULL for RX callback function
pointers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen a5e534a283 drivers: can: loopback: process TX callbacks in non-loopback mode
The TX callbacks must be processed regardless of the device being in
loopback mode or not.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen abf82013ac drivers: can: add support for configuring CAN emulation in QEMU
Add support for configuring CAN emulation support in QEMU. For now, the
only supported CAN controller is the single-channel Kvaser PCIcan PCI card.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Henrik Brix Andersen 58e12726bf drivers: can: add driver for the Kvaser PCIcan CAN controller PCI card
Add driver for the Kvaser PCIcan CAN controller PCI card for use with QEMU.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Henrik Brix Andersen 58afbc8f26 drivers: can: mcp2515: add support for multiple device instances
Add support for multiple MCP2515 CAN controller device instances.

Fixes: #51458

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-10-27 11:03:05 +02:00
Henrik Brix Andersen f8a88cdb27 drivers: can: use flags fields for can_frame and can_filter structs
The can_frame and can_filter structs support a number of different flags
(standard/extended CAN ID type, Remote Transmission Request, CAN-FD format,
Bit Rate Switch, ...). Each of these flags is represented as a discrete bit
in the given structure.

This design pattern requires every user of these structs to initialize all
of these flags to either 0 or 1, which does not scale well for future flag
additions.

Some of these flags have associated enumerations to be used for assignment,
some do not. CAN drivers and protocols tend to rely on the logical value of
the flag instead of using the enumeration, leading to a very fragile
API. The enumerations are used inconsistently between the can_frame and
can_filter structures, which further complicates the API.

Instead, convert these flags to bitfields with separate flag definitions
for the can_frame and can_filter structures. This API allows for future
extensions without having to revisit existing users of the two
structures. Furthermore, this allows driver to easily check for unsupported
flags in the respective API calls.

As this change leads to the "id_mask" field of the can_filter to be the
only mask present in that structure, rename it to "mask" for simplicity.

Fixes: #50776

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-25 16:32:10 +02:00
Henrik Brix Andersen fa54e3aa1d drivers: can: sja1000: remove unused variables
Remove unused variables from the CAN SJA1000 driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-22 14:37:18 +09:00
Henrik Brix Andersen 5f8983f2ec drivers: can: npl: ensure CANFD_FDF flag is defined
Linux kernels before v5.14 do not define the CANFD_FDF flag. The flag is
disregarded within the Linux kernel. It is just there for being able to
reuse the canfd_frame struct for classic CAN frames in Linux user-space
applications.

Define the CANFD_FDF flag locally if not already defined to allow compiling
against older Linux kernel headers.

See the following Linux kernel commit for further details:
02546884221279da2725e87e35348290470363d7

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-17 17:04:16 +02:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Martin Jäger 93681feaba drivers: can: sja1000: configure PHY from devicetree
The phys property was not considered during initialization of the
driver config, so that the transceiver was not enabled properly
in case it has an enable/standby pin.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 14:24:00 +02:00
Martin Jäger 2a035f775b drivers: can: esp32_twai: add support for newer MCUs
Newer ESP32 series MCUs like the ESP32-C3 contain some register changes
incompatible to the original ESP32 and the SJA1000.

The additions in this commit consider these changes and fix the
incompatibilities in the TWAI front-end for the SJA1000 driver.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 09:55:09 +02:00
Martin Jäger f936d68916 drivers: can: sja1000: use generic can_set_timing API
This is a preparation to use the custom implementation in ESP32 TWAI
frontend for newer ESP32 series chips like the ESP32-C3, which have
timing registers incompatible with the SJA1000.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 09:55:09 +02:00
Thad House f37db90541 drivers: Correct tx and rx error counts in mcan
TX and RX error counts are swapped in the mcan driver.

Signed-off-by: Thad House <thadhouse@fb.com>
2022-09-28 20:34:36 +00:00