Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: m_can: add support for optional reset

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>
Link: https://patch.msgid.link/20251008-m_can-add-reset-v1-1-49f0bbf820c4@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+25 -3
+24 -3
drivers/net/can/m_can/m_can.c
··· 23 23 #include <linux/pinctrl/consumer.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/pm_runtime.h> 26 + #include <linux/reset.h> 26 27 27 28 #include "m_can.h" 28 29 ··· 1828 1827 1829 1828 close_candev(dev); 1830 1829 1830 + reset_control_assert(cdev->rst); 1831 1831 m_can_clk_stop(cdev); 1832 1832 phy_power_off(cdev->transceiver); 1833 1833 ··· 2071 2069 if (err) 2072 2070 goto out_phy_power_off; 2073 2071 2072 + err = reset_control_deassert(cdev->rst); 2073 + if (err) 2074 + goto exit_disable_clks; 2075 + 2074 2076 /* open the can device */ 2075 2077 err = open_candev(dev); 2076 2078 if (err) { 2077 2079 netdev_err(dev, "failed to open can device\n"); 2078 - goto exit_disable_clks; 2080 + goto out_reset_control_assert; 2079 2081 } 2080 2082 2081 2083 if (cdev->is_peripheral) ··· 2135 2129 else 2136 2130 napi_disable(&cdev->napi); 2137 2131 close_candev(dev); 2132 + out_reset_control_assert: 2133 + reset_control_assert(cdev->rst); 2138 2134 exit_disable_clks: 2139 2135 m_can_clk_stop(cdev); 2140 2136 out_phy_power_off: ··· 2425 2417 } 2426 2418 } 2427 2419 2420 + cdev->rst = devm_reset_control_get_optional_shared(cdev->dev, NULL); 2421 + if (IS_ERR(cdev->rst)) 2422 + return dev_err_probe(cdev->dev, PTR_ERR(cdev->rst), 2423 + "Failed to get reset line\n"); 2424 + 2428 2425 ret = m_can_clk_start(cdev); 2429 2426 if (ret) 2430 2427 return ret; 2428 + 2429 + ret = reset_control_deassert(cdev->rst); 2430 + if (ret) 2431 + goto clk_disable; 2431 2432 2432 2433 if (cdev->is_peripheral) { 2433 2434 ret = can_rx_offload_add_manual(cdev->net, &cdev->offload, 2434 2435 NAPI_POLL_WEIGHT); 2435 2436 if (ret) 2436 - goto clk_disable; 2437 + goto out_reset_control_assert; 2437 2438 } 2438 2439 2439 2440 if (!cdev->net->irq) { ··· 2471 2454 KBUILD_MODNAME, cdev->net->irq, cdev->version); 2472 2455 2473 2456 /* Probe finished 2474 - * Stop clocks. They will be reactivated once the M_CAN device is opened 2457 + * Assert reset and stop clocks. 2458 + * They will be reactivated once the M_CAN device is opened 2475 2459 */ 2460 + reset_control_assert(cdev->rst); 2476 2461 m_can_clk_stop(cdev); 2477 2462 2478 2463 return 0; ··· 2482 2463 rx_offload_del: 2483 2464 if (cdev->is_peripheral) 2484 2465 can_rx_offload_del(&cdev->offload); 2466 + out_reset_control_assert: 2467 + reset_control_assert(cdev->rst); 2485 2468 clk_disable: 2486 2469 m_can_clk_stop(cdev); 2487 2470
+1
drivers/net/can/m_can/m_can.h
··· 86 86 struct device *dev; 87 87 struct clk *hclk; 88 88 struct clk *cclk; 89 + struct reset_control *rst; 89 90 90 91 struct workqueue_struct *tx_wq; 91 92 struct phy *transceiver;