Devicetree
 help / color / mirror / Atom feed
* [PATCH v1] riscv: dts: spacemit: k1: describe the CAN0 controller
@ 2026-11-29 13:31 Liu Changjie
  2026-12-01  3:22 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Changjie @ 2026-11-29 13:31 UTC (permalink / raw)
  To: Yixun Lan
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Troy Mitchell,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	devicetree, linux-riscv, spacemit, linux-kernel, linux-can

The K1 APB clock controller offers three protocol clock rates for CAN0: 20,
40 and 80 MHz. The FlexCAN driver defaults to protocol clock source 1 when
the device tree omits fsl,clk-source.

Select protocol clock source 0 and an 80 MHz clock rate for CAN FD. Leave
CAN0 disabled so boards can opt in when GPIO75 and GPIO76 connect to a CAN
transceiver.

Signed-off-by: Liu Changjie <liucj1228@outlook.com>
---
Based on v7.4-rc4. The binding is patch 1/3 of the CAN driver series:
https://lore.kernel.org/r/CH5PR19MB99715661A6B795896AA15DFBD8AC4F2@CH5PR19MB997156.namprd19.prod.outlook.com

Codex assisted with preparing and validating this patch.

 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi | 11 +++++++++++
 arch/riscv/boot/dts/spacemit/k1.dtsi         | 14 ++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi b/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi
index 8c57ca05d..084e4765c 100644
--- a/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi
@@ -11,6 +11,17 @@
 #define K1_GPIO(x)	(x / 32) (x % 32)
 
 &pinctrl {
+	/omit-if-no-ref/
+	can0_cfg: can0-cfg {
+		can0-pins {
+			pinmux = <K1_PADCONF(75, 3)>,	/* can_tx0 */
+				 <K1_PADCONF(76, 3)>;	/* can_rx0 */
+			power-source = <3300>;
+			bias-pull-up = <0>;
+			drive-strength = <19>;
+		};
+	};
+
 	gmac0_cfg: gmac0-cfg {
 		gmac0-pins {
 			pinmux = <K1_PADCONF(0, 1)>,	/* gmac0_rxdv */
diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spacemit/k1.dtsi
index 5d5f7f8a3..64f554aa9 100644
--- a/arch/riscv/boot/dts/spacemit/k1.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k1.dtsi
@@ -1078,6 +1078,20 @@ uart9: serial@d4017800 {
 				status = "disabled";
 			};
 
+			can0: can@d4028000 {
+				compatible = "spacemit,k1-flexcan";
+				reg = <0x0 0xd4028000 0x0 0x4000>;
+				interrupts = <16>;
+				clocks = <&syscon_apbc CLK_CAN0_BUS>,
+					 <&syscon_apbc CLK_CAN0>;
+				clock-names = "ipg", "per";
+				assigned-clocks = <&syscon_apbc CLK_CAN0>;
+				assigned-clock-rates = <80000000>;
+				resets = <&syscon_apbc RESET_CAN0>;
+				fsl,clk-source = /bits/ 8 <0>;
+				status = "disabled";
+			};
+
 			qspi: spi@d420c000 {
 				compatible = "spacemit,k1-qspi";
 				#address-cells = <1>;

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] riscv: dts: spacemit: k1: describe the CAN0 controller
  2026-11-29 13:31 [PATCH v1] riscv: dts: spacemit: k1: describe the CAN0 controller Liu Changjie
@ 2026-12-01  3:22 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01  3:22 UTC (permalink / raw)
  To: liucj1228
  Cc: dlan, robh, krzk+dt, conor+dt, troy.mitchell, pjw, palmer, aou,
	alex, devicetree, linux-riscv, spacemit, linux-kernel, linux-can,
	kuba

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The `can0` node in arch/riscv/boot/dts/spacemit/k1.dtsi
  selects CTRL[CLK_SRC]=0 with `fsl,clk-source = /bits/ 8 <0>`.
- [Low] In arch/riscv/boot/dts/spacemit/k1.dtsi, the new node `can0:
  can@d4028000` (lines 1081-1093) uses `compatible =…

--

riscv: dts: spacemit: k1: describe the CAN0 controller

This commit adds a disabled CAN0 FlexCAN node to the SpacemiT K1 dtsi,
along with a pinctrl group for GPIO75/GPIO76. It selects protocol clock
source 0 and sets the per clock to 80 MHz for CAN FD.

> diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spacemit/k1.dtsi
> index 5d5f7f8a393d3..64f554aa9aab5 100644
> --- a/arch/riscv/boot/dts/spacemit/k1.dtsi
> +++ b/arch/riscv/boot/dts/spacemit/k1.dtsi
> @@ -1078,6 +1078,20 @@ uart9: serial@d4017800 {
>  				status = "disabled";
>  			};
>  
> +			can0: can@d4028000 {
> +				compatible = "spacemit,k1-flexcan";

[Severity: Low]
Does anything in the tree handle this compatible yet? It only appears in
this dtsi. It is missing from the compatible list in
Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml, and the OF
match table in drivers/net/can/flexcan/flexcan-core.c does not have it
either.

That binding also sets additionalProperties: false and does not define a
resets property. Would make dtbs_check then reject both the compatible and
this line further down?

    resets = <&syscon_apbc RESET_CAN0>;

flexcan_probe() also has no reset_control handling. It reads only
clock-frequency, fsl,clk-source, the ipg/per clocks, the regulator and the
phy. RESET_CAN0 is a real reset line in
drivers/reset/spacemit/reset-spacemit-k1.c:

    [RESET_CAN0]	= RESET_DATA(APBC_CAN0_CLK_RST,		BIT(2), 0),

so nothing in the in-tree driver would deassert it.

The notes after the commit message say the binding is patch 1/3 of a
separate CAN driver series that has not been merged. Does that series also
add resets to the binding and a reset deassert to flexcan_probe()?

If it does not, this node would still fail validation once the binding is
merged, and a board that enables it would leave the controller in reset.
In either case, this patch has to be applied after that series.

> +				reg = <0x0 0xd4028000 0x0 0x4000>;
> +				interrupts = <16>;
> +				clocks = <&syscon_apbc CLK_CAN0_BUS>,
> +					 <&syscon_apbc CLK_CAN0>;
> +				clock-names = "ipg", "per";
> +				assigned-clocks = <&syscon_apbc CLK_CAN0>;
> +				assigned-clock-rates = <80000000>;
> +				resets = <&syscon_apbc RESET_CAN0>;
> +				fsl,clk-source = /bits/ 8 <0>;

[Severity: Medium]
With this setting, does the protocol engine clock end up faster than the
bus clock?

With fsl,clk-source = 0, flexcan_chip_start() clears CTRL[CLK_SRC]:

	if (priv->clk_src)
		reg |= FLEXCAN_CTRL_CLK_SRC;
	else
		reg &= ~FLEXCAN_CTRL_CLK_SRC;

flexcan_probe() then takes the CAN clock from clk_get_rate(clk_per), and
assigned-clock-rates above sets that clock to 80 MHz.

The ipg clock, CLK_CAN0_BUS, is modelled as the 24 MHz crystal in
drivers/clk/spacemit/ccu-k1.c:

CCU_GATE_DEFINE(can0_bus_clk, CCU_PARENT_NAME(vctcxo_24m), APBC_CAN0_CLK_RST, BIT(0), 0);

The other APBC bus gates nearby use apb_clk as their parent, and so do the
K3 CAN bus gates in ccu-k3.c.

The NXP FlexCAN reference manuals say that with CLKSRC=0 the oscillator
(protocol engine) clock must be slower than the bus clock. Every in-tree
user of fsl,clk-source = 0 (imx8mp, imx8qm, imx93, imx94, imx95, imx952)
pairs a 40/80 MHz per clock with a much faster ipg clock.

Suppose the SpacemiT IP keeps that rule and the bus clock really is 24 MHz.
Could register and message buffer access, and bit timing, then be
unreliable on any board that enables can0? Of the 20/40/80 MHz rates on
offer, only 20 MHz would meet that rule.

Is the vctcxo_24m parent in ccu-k1.c only an approximation that should be
fixed, or does the SpacemiT IP not have this restriction? Could the commit
message say which one applies?

> +				status = "disabled";
> +			};
> +

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CH5PR19MB9971565990F421482921CF595DAC4F2%40CH5PR19MB997156.namprd19.prod.outlook.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 13:31 [PATCH v1] riscv: dts: spacemit: k1: describe the CAN0 controller Liu Changjie
2026-12-01  3:22 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox