[PATCH can-next v1 3/3] can: flexcan: add support for SpacemiT K1 CAN0

Liu Changjie liucj1228 at outlook.com
Sun Nov 29 05:20:28 PST 2026


On K1, the RST bit in APBC_CAN_CLK_RST holds both the register interface
and the CAN protocol engine in reset at power-on. Enabling the two clocks
leaves both domains in reset when register_flexcandev() first accesses the
controller.

Deassert the K1 reset in flexcan_probe() and keep both domains out of reset
for as long as the driver owns the controller.

Signed-off-by: Liu Changjie <liucj1228 at outlook.com>
---
 drivers/net/can/flexcan/flexcan-core.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index a05928d5e..8753d5590 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -31,6 +31,7 @@
 #include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 
 #include "flexcan.h"
 
@@ -399,6 +400,14 @@ static const struct flexcan_devtype_data nxp_s32g2_devtype_data = {
 		FLEXCAN_QUIRK_SECONDARY_MB_IRQ,
 };
 
+static const struct flexcan_devtype_data spacemit_k1_devtype_data = {
+	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
+		FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
+		FLEXCAN_QUIRK_USE_RX_MAILBOX | FLEXCAN_QUIRK_SUPPORT_FD |
+		FLEXCAN_QUIRK_SUPPORT_ECC | FLEXCAN_QUIRK_ECC_WRITE32 |
+		FLEXCAN_QUIRK_SUPPORT_RX_MAILBOX | FLEXCAN_QUIRK_SUPPORT_RX_MAILBOX_RTR,
+};
+
 static const struct can_bittiming_const flexcan_bittiming_const = {
 	.name = DRV_NAME,
 	.tseg1_min = 4,
@@ -2084,6 +2093,7 @@ static const struct of_device_id flexcan_of_match[] = {
 	{ .compatible = "fsl,ls1021ar2-flexcan", .data = &fsl_ls1021a_r2_devtype_data, },
 	{ .compatible = "fsl,lx2160ar1-flexcan", .data = &fsl_lx2160a_r1_devtype_data, },
 	{ .compatible = "nxp,s32g2-flexcan", .data = &nxp_s32g2_devtype_data, },
+	{ .compatible = "spacemit,k1-flexcan", .data = &spacemit_k1_devtype_data, },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, flexcan_of_match);
@@ -2162,6 +2172,14 @@ static int flexcan_probe(struct platform_device *pdev)
 		return PTR_ERR(regs);
 
 	devtype_data = device_get_match_data(&pdev->dev);
+	if (devtype_data == &spacemit_k1_devtype_data) {
+		struct reset_control *rst;
+
+		rst = devm_reset_control_get_exclusive_deasserted(&pdev->dev, NULL);
+		if (IS_ERR(rst))
+			return dev_err_probe(&pdev->dev, PTR_ERR(rst),
+					     "failed to deassert reset\n");
+	}
 
 	if ((devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_FD) &&
 	    !((devtype_data->quirks &



More information about the linux-riscv mailing list