* [PATCH can-next] can: m_can: add support for optional reset
@ 2025-10-08 9:38 Marc Kleine-Budde
2025-10-08 10:26 ` Marc Kleine-Budde
0 siblings, 1 reply; 2+ messages in thread
From: Marc Kleine-Budde @ 2025-10-08 9:38 UTC (permalink / raw)
To: Chandrasekar Ramakrishnan, Vincent Mailhol, Philipp Zabel
Cc: linux-can, linux-kernel, kernel, Markus Schneider-Pargmann,
Marc Kleine-Budde
This patch has been split from the original series [1].
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.
[1] https://lore.kernel.org/all/20250923-m_can-fix-state-handling-v3-0-06d8baccadbf@pengutronix.de
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/m_can.c | 27 ++++++++++++++++++++++++---
drivers/net/can/m_can/m_can.h | 1 +
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index e1d725979685..520e079d2bd4 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"
@@ -1816,6 +1817,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);
@@ -2058,11 +2060,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)
@@ -2118,6 +2124,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:
@@ -2406,15 +2414,24 @@ 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 dev_err_probe(cdev->dev, PTR_ERR(cdev->rst),
+ "Failed to get reset line\n");
+
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) {
@@ -2443,8 +2460,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;
@@ -2452,6 +2471,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;
---
base-commit: 07fdad3a93756b872da7b53647715c48d0f4a2d0
change-id: 20251008-m_can-add-reset-af10ab0c38ab
Best regards,
--
Marc Kleine-Budde <mkl@pengutronix.de>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH can-next] can: m_can: add support for optional reset
2025-10-08 9:38 [PATCH can-next] can: m_can: add support for optional reset Marc Kleine-Budde
@ 2025-10-08 10:26 ` Marc Kleine-Budde
0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2025-10-08 10:26 UTC (permalink / raw)
To: Chandrasekar Ramakrishnan, Vincent Mailhol, Philipp Zabel
Cc: linux-can, linux-kernel, kernel, Markus Schneider-Pargmann
[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]
On 08.10.2025 11:38:30, Marc Kleine-Budde wrote:
> This patch has been split from the original series [1].
>
> 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.
>
> [1] https://lore.kernel.org/all/20250923-m_can-fix-state-handling-v3-0-06d8baccadbf@pengutronix.de
>
> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
> Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Added to linux-can-next.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-08 10:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08 9:38 [PATCH can-next] can: m_can: add support for optional reset Marc Kleine-Budde
2025-10-08 10:26 ` Marc Kleine-Budde
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).