]> www.infradead.org Git - users/hch/misc.git/commitdiff
can: m_can: m_can_chip_config(): bring up interface in correct state
authorMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 6 Aug 2025 16:24:12 +0000 (18:24 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 8 Oct 2025 08:18:56 +0000 (10:18 +0200)
In some SoCs (observed on the STM32MP15) the M_CAN IP core keeps the
CAN state and CAN error counters over an internal reset cycle. An
external reset is not always possible, due to the shared reset with
the other CAN core. This caused the core not always be in Error Active
state when bringing up the controller.

Instead of always setting the CAN state to Error Active in
m_can_chip_config(), fix this by reading and decoding the Protocol
Status Regitser (PSR) and set the CAN state accordingly.

Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
Link: https://patch.msgid.link/20250929-m_can-fix-state-handling-v4-3-682b49b49d9a@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/m_can/m_can.c

index ac864183a536495ac264287ca8555c5e223a8355..b6db5b57241cc81883c145d1d7e6c1d477a3b3ad 100644 (file)
@@ -1617,7 +1617,7 @@ static int m_can_start(struct net_device *dev)
        netdev_queue_set_dql_min_limit(netdev_get_tx_queue(cdev->net, 0),
                                       cdev->tx_max_coalesced_frames);
 
-       cdev->can.state = CAN_STATE_ERROR_ACTIVE;
+       cdev->can.state = m_can_state_get_by_psr(cdev);
 
        m_can_enable_all_interrupts(cdev);