Commit graph

507 commits

Author SHA1 Message Date
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