From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Chandrasekar Ramakrishnan <rcsekar@samsung.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
Patrik Flykt <patrik.flykt@linux.intel.com>,
Dong Aisheng <b29396@freescale.com>,
Varka Bhadram <varkabhadram@gmail.com>,
Wu Bo <wubo.oduw@gmail.com>,
Markus Schneider-Pargmann <msp@baylibre.com>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH v2 7/7] can: m_can: add optional support for reset
Date: Tue, 09 Sep 2025 19:53:23 +0200 [thread overview]
Message-ID: <20250909-m_can-fix-state-handling-v2-7-af9fa240b68a@pengutronix.de> (raw)
In-Reply-To: <20250909-m_can-fix-state-handling-v2-0-af9fa240b68a@pengutronix.de>
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. The
STM32MP15 SoC provides an external reset, which is shared between both
M_CAN cores.
Add support for an optional external reset. Take care of shared
resets, de-assert reset during the probe phase in
m_can_class_register() and while the interface is up, assert the reset
otherwise.
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/m_can.c | 26 +++++++++++++++++++++++---
drivers/net/can/m_can/m_can.h | 1 +
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 9528af8500af..93085bf1c267 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -23,6 +23,7 @@
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/reset.h>
#include "m_can.h"
@@ -1834,6 +1835,7 @@ static int m_can_close(struct net_device *dev)
close_candev(dev);
+ reset_control_assert(cdev->rst);
m_can_clk_stop(cdev);
phy_power_off(cdev->transceiver);
@@ -2076,11 +2078,15 @@ static int m_can_open(struct net_device *dev)
if (err)
goto out_phy_power_off;
+ err = reset_control_deassert(cdev->rst);
+ if (err)
+ goto exit_disable_clks;
+
/* open the can device */
err = open_candev(dev);
if (err) {
netdev_err(dev, "failed to open can device\n");
- goto exit_disable_clks;
+ goto out_reset_control_assert;
}
if (cdev->is_peripheral)
@@ -2136,6 +2142,8 @@ static int m_can_open(struct net_device *dev)
else
napi_disable(&cdev->napi);
close_candev(dev);
+out_reset_control_assert:
+ reset_control_assert(cdev->rst);
exit_disable_clks:
m_can_clk_stop(cdev);
out_phy_power_off:
@@ -2426,15 +2434,23 @@ int m_can_class_register(struct m_can_classdev *cdev)
}
}
+ cdev->rst = devm_reset_control_get_optional_shared(cdev->dev, NULL);
+ if (IS_ERR(cdev->rst))
+ return PTR_ERR(cdev->rst);
+
ret = m_can_clk_start(cdev);
if (ret)
return ret;
+ ret = reset_control_deassert(cdev->rst);
+ if (ret)
+ goto clk_disable;
+
if (cdev->is_peripheral) {
ret = can_rx_offload_add_manual(cdev->net, &cdev->offload,
NAPI_POLL_WEIGHT);
if (ret)
- goto clk_disable;
+ goto out_reset_control_assert;
}
if (!cdev->net->irq) {
@@ -2463,8 +2479,10 @@ int m_can_class_register(struct m_can_classdev *cdev)
KBUILD_MODNAME, cdev->net->irq, cdev->version);
/* Probe finished
- * Stop clocks. They will be reactivated once the M_CAN device is opened
+ * Assert reset and stop clocks.
+ * They will be reactivated once the M_CAN device is opened
*/
+ reset_control_assert(cdev->rst);
m_can_clk_stop(cdev);
return 0;
@@ -2472,6 +2490,8 @@ int m_can_class_register(struct m_can_classdev *cdev)
rx_offload_del:
if (cdev->is_peripheral)
can_rx_offload_del(&cdev->offload);
+out_reset_control_assert:
+ reset_control_assert(cdev->rst);
clk_disable:
m_can_clk_stop(cdev);
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index bd4746c63af3..7b7600697c6b 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -86,6 +86,7 @@ struct m_can_classdev {
struct device *dev;
struct clk *hclk;
struct clk *cclk;
+ struct reset_control *rst;
struct workqueue_struct *tx_wq;
struct phy *transceiver;
--
2.51.0
next prev parent reply other threads:[~2025-09-09 17:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 17:53 [PATCH v2 0/7] can: m_can: fix pm_runtime and CAN state handling Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 1/7] can: m_can: m_can_plat_remove(): add missing pm_runtime_disable() Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 2/7] can: m_can: only handle active interrupts Marc Kleine-Budde
2025-09-10 8:41 ` Markus Schneider-Pargmann
2025-09-10 14:28 ` Marc Kleine-Budde
2025-09-10 15:06 ` Marc Kleine-Budde
2025-09-10 16:04 ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 3/7] can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active Marc Kleine-Budde
2025-09-10 8:47 ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 4/7] can: m_can: m_can_chip_config(): bring up interface in correct state Marc Kleine-Budde
2025-09-10 8:57 ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 5/7] can: m_can: fix CAN state in system PM Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 6/7] can: m_can: m_can_get_berr_counter(): don't wake up controller if interface is down Marc Kleine-Budde
2025-09-09 17:53 ` Marc Kleine-Budde [this message]
2025-09-10 9:32 ` [PATCH v2 7/7] can: m_can: add optional support for reset Markus Schneider-Pargmann
2025-09-10 14:35 ` Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250909-m_can-fix-state-handling-v2-7-af9fa240b68a@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=b29396@freescale.com \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=msp@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=patrik.flykt@linux.intel.com \
--cc=rcsekar@samsung.com \
--cc=varkabhadram@gmail.com \
--cc=wubo.oduw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).