[PATCH can-next v1 2/3] can: flexcan: support 32-bit writes when initializing ECC RAM

Marc Kleine-Budde mkl at pengutronix.de
Sun Nov 29 07:35:00 PST 2026


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 at 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, &regs->ctrl2);
>
> -	memset_io(&regs->init, 0, sizeof(regs->init));
> +	flexcan_clear_ram(priv, &regs->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   |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20261129/6075398e/attachment.sig>


More information about the linux-riscv mailing list