* [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller
[not found] <20261129-k1-can0-v1-0-liucj1228@outlook.com>
2026-11-29 13:20 ` [PATCH can-next v1 3/3] can: flexcan: add support for SpacemiT K1 CAN0 Liu Changjie
@ 2026-11-29 13:20 ` Liu Changjie
2026-11-29 14:01 ` sashiko-bot
2026-11-29 13:20 ` [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM Liu Changjie
2 siblings, 1 reply; 6+ messages in thread
From: Liu Changjie @ 2026-11-29 13:20 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: Vincent Mailhol, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-can, devicetree, linux-kernel, spacemit, linux-riscv,
Yixun Lan
The APB clock controller on K1 gates the CAN0 register and protocol clocks
independently. A nonzero clock-frequency makes flexcan_probe() skip both
clock lookups, leaving the driver unable to enable either clock.
Require both clocks and the reset line for the K1 controller.
Signed-off-by: Liu Changjie <liucj1228@outlook.com>
---
.../bindings/net/can/fsl,flexcan.yaml | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
index f81d56f7c..081237128 100644
--- a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
+++ b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
@@ -5,7 +5,7 @@ $id: http://devicetree.org/schemas/net/can/fsl,flexcan.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title:
- Flexcan CAN controller on Freescale's ARM and PowerPC system-on-a-chip (SOC).
+ FlexCAN CAN controller
maintainers:
- Marc Kleine-Budde <mkl@pengutronix.de>
@@ -26,6 +26,7 @@ properties:
- fsl,ls1021ar2-flexcan
- fsl,lx2160ar1-flexcan
- nxp,s32g2-flexcan
+ - spacemit,k1-flexcan
- items:
- enum:
- fsl,imx53-flexcan
@@ -75,6 +76,9 @@ properties:
boot loader. This property should only be used the used operating system
doesn't support the clocks and clock-names property.
+ resets:
+ maxItems: 1
+
power-domains:
maxItems: 1
@@ -152,6 +156,21 @@ required:
allOf:
- $ref: can-controller.yaml#
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: spacemit,k1-flexcan
+ then:
+ properties:
+ clock-frequency: false
+ required:
+ - resets
+ - clocks
+ - clock-names
+ else:
+ properties:
+ resets: false
- if:
properties:
compatible:
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM
[not found] <20261129-k1-can0-v1-0-liucj1228@outlook.com>
2026-11-29 13:20 ` [PATCH can-next v1 3/3] can: flexcan: add support for SpacemiT K1 CAN0 Liu Changjie
2026-11-29 13:20 ` [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller Liu Changjie
@ 2026-11-29 13:20 ` Liu Changjie
2026-11-29 15:35 ` Marc Kleine-Budde
2 siblings, 1 reply; 6+ messages in thread
From: Liu Changjie @ 2026-11-29 13:20 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: Vincent Mailhol, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-can, devicetree, linux-kernel, spacemit, linux-riscv,
Yixun Lan
On RV64, memset_io() uses 64-bit stores for aligned I/O ranges. The vendor
driver for the SpacemiT X1 initializes FlexCAN ECC RAM with 32-bit writes,
including the second RAM window when CAN FD is enabled.
Select the access width per device so FlexCAN can use its 32-bit register
accessor on this hardware and retain memset_io() elsewhere.
Link: https://github.com/orangepi-xunlong/linux-orangepi/blob/ae9e974d3e19f460b6397bfe8f0f1417a073ce05/drivers/net/can/flexcan/flexcan-core.c#L1382
Signed-off-by: Liu Changjie <liucj1228@outlook.com>
---
drivers/net/can/flexcan/flexcan-core.c | 18 ++++++++++++++++--
drivers/net/can/flexcan/flexcan.h | 3 +++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index 86b40abe9..a05928d5e 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -292,6 +292,8 @@ struct flexcan_regs {
};
static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8);
+static_assert(IS_ALIGNED(sizeof_field(struct flexcan_regs, init), sizeof(u32)));
+static_assert(IS_ALIGNED(sizeof_field(struct flexcan_regs, init_fd), sizeof(u32)));
static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = {
.quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE |
@@ -1354,6 +1356,18 @@ static void flexcan_set_bittiming(struct net_device *dev)
return flexcan_set_bittiming_ctrl(dev);
}
+static void flexcan_clear_ram(const struct flexcan_priv *priv, void __iomem *addr,
+ size_t size)
+{
+ if (!(priv->devtype_data.quirks & FLEXCAN_QUIRK_ECC_WRITE32)) {
+ memset_io(addr, 0, size);
+ return;
+ }
+
+ for (size_t offset = 0; offset < size; offset += sizeof(u32))
+ priv->write(0, addr + offset);
+}
+
static void flexcan_ram_init(struct net_device *dev)
{
struct flexcan_priv *priv = netdev_priv(dev);
@@ -1372,10 +1386,10 @@ static void flexcan_ram_init(struct net_device *dev)
reg_ctrl2 |= FLEXCAN_CTRL2_WRMFRZ;
priv->write(reg_ctrl2, ®s->ctrl2);
- memset_io(®s->init, 0, sizeof(regs->init));
+ flexcan_clear_ram(priv, ®s->init, sizeof(regs->init));
if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
- memset_io(®s->init_fd, 0, sizeof(regs->init_fd));
+ flexcan_clear_ram(priv, ®s->init_fd, sizeof(regs->init_fd));
reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ;
priv->write(reg_ctrl2, ®s->ctrl2);
diff --git a/drivers/net/can/flexcan/flexcan.h b/drivers/net/can/flexcan/flexcan.h
index 16692a250..06a7bd545 100644
--- a/drivers/net/can/flexcan/flexcan.h
+++ b/drivers/net/can/flexcan/flexcan.h
@@ -75,6 +75,9 @@
*/
#define FLEXCAN_QUIRK_SECONDARY_MB_IRQ BIT(18)
+/* Initialize ECC-protected RAM through 32-bit writes. */
+#define FLEXCAN_QUIRK_ECC_WRITE32 BIT(19)
+
struct flexcan_devtype_data {
u32 quirks; /* quirks needed for different IP cores */
};
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH can-next v1 3/3] can: flexcan: add support for SpacemiT K1 CAN0
[not found] <20261129-k1-can0-v1-0-liucj1228@outlook.com>
@ 2026-11-29 13:20 ` Liu Changjie
2026-11-29 13:20 ` [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller Liu Changjie
2026-11-29 13:20 ` [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM Liu Changjie
2 siblings, 0 replies; 6+ messages in thread
From: Liu Changjie @ 2026-11-29 13:20 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: Vincent Mailhol, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-can, devicetree, linux-kernel, spacemit, linux-riscv,
Yixun Lan
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@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 &
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH can-next v1 0/3] Add support for the SpacemiT K1 CAN0 controller
@ 2026-11-29 13:53 Liu Changjie
0 siblings, 0 replies; 6+ messages in thread
From: Liu Changjie @ 2026-11-29 13:53 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: Vincent Mailhol, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-can, devicetree, linux-kernel, spacemit, linux-riscv,
Yixun Lan
This series adds the interrupt-driven application processor CAN0 on
SpacemiT K1. The binding describes its clocks and reset. The driver
initializes the ECC RAM with 32-bit writes and uses FlexCAN's existing
CAN FD mailbox and interrupt paths. The SoC DTS change is separate.
An earlier version of the CAN0 path on Orange Pi RV2 received
4,617,536 of 4,617,536 frames from a ZLG USBCANFD-200U during a
900-second run at 1 Mbit/s arbitration and 5 Mbit/s data rate with
64-byte BRS frames. This measurement predates the present can-next
rebase and the change making reset acquisition mandatory for K1.
Codex assisted with the changes, commit messages and local validation.
Gemini Carbon High reviewed an earlier implementation.
Liu Changjie (3):
dt-bindings: can: flexcan: document the SpacemiT K1 controller
can: flexcan: support 32-bit writes when initializing ECC RAM
can: flexcan: add support for SpacemiT K1 CAN0
.../bindings/net/can/fsl,flexcan.yaml | 21 ++++++++++-
drivers/net/can/flexcan/flexcan-core.c | 36 +++++++++++++++++--
drivers/net/can/flexcan/flexcan.h | 3 ++
3 files changed, 57 insertions(+), 3 deletions(-)
base-commit: 573af801552999954caa8347e4490b04cf4763f0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller
2026-11-29 13:20 ` [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller Liu Changjie
@ 2026-11-29 14:01 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-29 14:01 UTC (permalink / raw)
To: Liu Changjie
Cc: linux-can, devicetree, robh, conor+dt, Marc Kleine-Budde,
Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: can: flexcan: required property order mismatch for
K1
--
commit ccefdbfb6523420c66f48631383414c8ba9e7248
Author: Liu Changjie <liucj1228@outlook.com>
dt-bindings: can: flexcan: document the SpacemiT K1 controller
This commit documents the spacemit,k1-flexcan compatible in the FlexCAN DT
binding schema, requiring clocks, clock-names, and resets while disallowing
clock-frequency.
> diff --git a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
> index f81d56f7c12a5..081237128480a 100644
> --- a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
> +++ b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
[ ... ]
> @@ -152,6 +156,21 @@ required:
>
> allOf:
> - $ref: can-controller.yaml#
> + - if:
> + properties:
> + compatible:
> + contains:
> + const: spacemit,k1-flexcan
> + then:
> + properties:
> + clock-frequency: false
> + required:
> + - resets
> + - clocks
> + - clock-names
[Severity: Low]
Should the required list place clocks and clock-names before resets to
match the order in the top-level properties section and canonical DT
schema conventions?
--
Sashiko AI review · https://sashiko.dev/#/patchset/CH5PR19MB99715661A6B795896AA15DFBD8AC4F2@CH5PR19MB997156.namprd19.prod.outlook.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM
2026-11-29 13:20 ` [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM Liu Changjie
@ 2026-11-29 15:35 ` Marc Kleine-Budde
0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-11-29 15:35 UTC (permalink / raw)
To: Liu Changjie
Cc: Vincent Mailhol, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-can, devicetree, linux-kernel, spacemit, linux-riscv,
Yixun Lan
[-- Attachment #1: Type: text/plain, Size: 2817 bytes --]
On 29.11.2026 21:20:28, Liu Changjie wrote:
> On RV64, memset_io() uses 64-bit stores for aligned I/O ranges. The vendor
> driver for the SpacemiT X1 initializes FlexCAN ECC RAM with 32-bit writes,
> including the second RAM window when CAN FD is enabled.
>
> Select the access width per device so FlexCAN can use its 32-bit register
> accessor on this hardware and retain memset_io() elsewhere.
As the flexcan IP core is 32 bit, it's probably a good idea to use 32
bit register access unconditionally.
> Link: https://github.com/orangepi-xunlong/linux-orangepi/blob/ae9e974d3e19f460b6397bfe8f0f1417a073ce05/drivers/net/can/flexcan/flexcan-core.c#L1382
> Signed-off-by: Liu Changjie <liucj1228@outlook.com>
> ---
> drivers/net/can/flexcan/flexcan-core.c | 18 ++++++++++++++++--
> drivers/net/can/flexcan/flexcan.h | 3 +++
> 2 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
> index 86b40abe9..a05928d5e 100644
> --- a/drivers/net/can/flexcan/flexcan-core.c
> +++ b/drivers/net/can/flexcan/flexcan-core.c
> @@ -292,6 +292,8 @@ struct flexcan_regs {
> };
>
> static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8);
> +static_assert(IS_ALIGNED(sizeof_field(struct flexcan_regs, init), sizeof(u32)));
> +static_assert(IS_ALIGNED(sizeof_field(struct flexcan_regs, init_fd), sizeof(u32)));
>
> static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = {
> .quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE |
> @@ -1354,6 +1356,18 @@ static void flexcan_set_bittiming(struct net_device *dev)
> return flexcan_set_bittiming_ctrl(dev);
> }
>
> +static void flexcan_clear_ram(const struct flexcan_priv *priv, void __iomem *addr,
> + size_t size)
> +{
> + if (!(priv->devtype_data.quirks & FLEXCAN_QUIRK_ECC_WRITE32)) {
> + memset_io(addr, 0, size);
> + return;
> + }
remove the memset_io unconditionally.
> +
> + for (size_t offset = 0; offset < size; offset += sizeof(u32))
> + priv->write(0, addr + offset);
> +}
> +
> static void flexcan_ram_init(struct net_device *dev)
> {
> struct flexcan_priv *priv = netdev_priv(dev);
> @@ -1372,10 +1386,10 @@ static void flexcan_ram_init(struct net_device *dev)
> reg_ctrl2 |= FLEXCAN_CTRL2_WRMFRZ;
> priv->write(reg_ctrl2, ®s->ctrl2);
>
> - memset_io(®s->init, 0, sizeof(regs->init));
> + flexcan_clear_ram(priv, ®s->init, sizeof(regs->init));
rename this function into flexcan_memset()
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: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-29 15:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261129-k1-can0-v1-0-liucj1228@outlook.com>
2026-11-29 13:20 ` [PATCH can-next v1 3/3] can: flexcan: add support for SpacemiT K1 CAN0 Liu Changjie
2026-11-29 13:20 ` [PATCH can-next v1 1/3] dt-bindings: can: flexcan: document the SpacemiT K1 controller Liu Changjie
2026-11-29 14:01 ` sashiko-bot
2026-11-29 13:20 ` [PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM Liu Changjie
2026-11-29 15:35 ` Marc Kleine-Budde
2026-11-29 13:53 [PATCH can-next v1 0/3] Add support for the SpacemiT K1 CAN0 controller Liu Changjie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox