Commit graph

11 commits

Author SHA1 Message Date
Henrik Brix Andersen a57db0ddcb drivers: can: rework support for manual bus-off recovery
Since all CAN controllers drivers seem to support automatic recovery (for
any future drivers for hardware without this hardware capability this can
easily be implemented in the driver), change the Zephyr CAN controller API
policy to:

- Always enable automatic bus recovery upon driver initialization,
  regardless of Kconfig options. Since CAN controllers are initialized in
  "stopped" state, no unwanted bus-off recovery will be started at this
  point.

- Invert and rename the Kconfig CONFIG_CAN_AUTO_BUS_OFF_RECOVERY, which is
  enabled by default, to CONFIG_CAN_MANUAL_RECOVERY_MODE, which is disabled
  by default. Enabling CONFIG_CAN_MANUAL_RECOVERY_MODE=y enables support
  for the can_recover() API function and a new manual recovery mode (see
  next bullet). Keeping this guarded by Kconfig allows keeping the flash
  footprint down for applications not using manual bus-off recovery.

- Introduce a new CAN controller operational mode
  CAN_MODE_MANUAL_RECOVERY. Support for this is only enabled if
  CONFIG_CAN_MANUAL_RECOVERY_MODE=y. Having this as a mode allows
  applications to inquire whether the CAN controller supports manual
  recovery mode via the can_get_capabilities() API function and either fail
  or rely on automatic recovery - and it allows CAN controller drivers not
  supporting manual recovery mode to fail early in can_set_mode() during
  application startup instead of failing when can_recover() is called at a
  later point in time.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-03-02 18:26:48 +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 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
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
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 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 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 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 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 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
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