Skip to contentSkip to conversation

CAST Controller Area Network driver support

PATCH In review William Qiu 5 participants 19 messages Jan 29, 2024 – Jan 31, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover CAST Controller Area Network driver support

Hi,

This patchset adds initial rudimentary support for the CAST Controller Area Network driver. And we registered cast in kernel as well. This driver will be applied in JH7110 SoC first, so add relevant compatibility support.

William Qiu (4):
dt-bindings: vendor-prefixes: Add cast vendor prefix
dt-bindings: can: Add bindings for CAST CAN Controller
can: cast: add driver for CAST CAN controller
riscv: dts: starfive: jh7110: Add CAN node

 .../devicetree/bindings/net/can/cast,can.yaml |   95 ++
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 MAINTAINERS                                   |    7 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   32 +
 drivers/net/can/Kconfig                       |    7 +
 drivers/net/can/Makefile                      |    1 +
 drivers/net/can/cast_can.c                    | 1215 +++++++++++++++++
 7 files changed, 1359 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/cast,can.yaml
 create mode 100644 drivers/net/can/cast_can.c

--
2.34.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#1 lore raw

PATCH 1/4 dt-bindings: vendor-prefixes: Add cast vendor prefix

Add prefix for Computer-Aided Software Technologies, Inc.

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 1a0dc04f1db4..b9c6ce99d24d 100644
@@ -242,6 +242,8 @@ patternProperties:
     description: Capella Microsystems, Inc
   "^cascoda,.*":
     description: Cascoda, Ltd.
+  "^cast,.*":
+    description: Computer-Aided Software Technologies, Inc.
   "^catalyst,.*":
     description: Catalyst Semiconductor, Inc.
   "^cavium,.*":
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer Acked-by on v1 1/4
#2 lore raw

Re: [PATCH v1 1/4] dt-bindings: vendor-prefixes: Add cast vendor prefix

Quoted 3 lines · William Qiu

Add prefix for Computer-Aided Software Technologies, Inc.

Cheers,
Conor.

Quoted 25 lines
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 1a0dc04f1db4..b9c6ce99d24d 100644
@@ -242,6 +242,8 @@ patternProperties:
     description: Capella Microsystems, Inc
   "^cascoda,.*":
     description: Cascoda, Ltd.
+  "^cast,.*":
+    description: Computer-Aided Software Technologies, Inc.
   "^catalyst,.*":
     description: Catalyst Semiconductor, Inc.
   "^cavium,.*":
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#3 lore raw

Re: [PATCH v1 1/4] dt-bindings: vendor-prefixes: Add cast vendor prefix

In reply to William Qiu
Quoted 1 line · William Qiu

Add prefix for Computer-Aided Software Technologies, Inc.

The diff tells me this. The commit message should say who Computer-Aided Software Technologies, Inc. is. What do they make? Website? etc.

Quoted 22 lines
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 1a0dc04f1db4..b9c6ce99d24d 100644
@@ -242,6 +242,8 @@ patternProperties:
     description: Capella Microsystems, Inc
   "^cascoda,.*":
     description: Cascoda, Ltd.
+  "^cast,.*":
+    description: Computer-Aided Software Technologies, Inc.
   "^catalyst,.*":
     description: Catalyst Semiconductor, Inc.
   "^cavium,.*":
Signature · 1 line
2.34.1
#4 lore raw

PATCH 2/4 dt-bindings: can: Add bindings for CAST CAN Controller

In reply to William Qiu

Add bindings for CAST CAN Controller

---
 .../devicetree/bindings/net/can/cast,can.yaml | 95 +++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/cast,can.yaml
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +95 -0
new file mode 100644
index 000000000000..ea52132d9b1c
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/cast,can.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CAST CAN controller
+
+maintainers:
+  - William Qiu <[email protected]>
+
+allOf:
+  - $ref: can-controller.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: starfive,can
+    then:
+      required:
+        - starfive,syscon
+
+properties:
+  compatible:
+    enum:
+      - cast,can
+      - cast,canfd
+      - starfive,can
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 3
+
+  clock-names:
+    items:
+      - const: apb_clk
+      - const: timer_clk
+      - const: can_clk
+
+  resets:
+    minItems: 3
+
+  reset-names:
+    items:
+      - const: rst_apb
+      - const: rst_core
+      - const: rst_timer
+
+  starfive,syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to System Register Controller syscon node
+          - description: offset of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller
+          - description: shift of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller
+          - description: mask of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller
+    description:
+      Should be four parameters, the phandle to System Register Controller
+      syscon node and the offset/shift/mask of SYS_SYSCON_NE__SAIF__SYSCFG register
+      for CAN controller.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+
+additionalProperties: false
+
+examples:
+  - |
+    can@130d0000{
+        compatible = "starfive,can";
+        reg = <0x130d0000 0x1000>;
+        interrupts = <112>;
+        clocks = <&syscrg 115>,
+                 <&syscrg 116>,
+                 <&syscrg 117>;
+        clock-names = "apb_clk", "timer_clk", "can_clk";
+        resets = <&syscrg 111>,
+                 <&syscrg 112>,
+                 <&syscrg 113>;
+        reset-names = "rst_apb", "rst_core", "rst_timer";
+        starfive,syscon = <&sys_syscon 0x10 0x3 0x8>;
+    };
+
+...
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#5 lore raw

Re: [PATCH v1 2/4] dt-bindings: can: Add bindings for CAST CAN Controller

Hey William,

Quoted 25 lines · William Qiu

Add bindings for CAST CAN Controller

---
 .../devicetree/bindings/net/can/cast,can.yaml | 95 +++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/cast,can.yaml
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +11 -0
new file mode 100644
index 000000000000..ea52132d9b1c
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/cast,can.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CAST CAN controller
+
+maintainers:
+  - William Qiu <[email protected]>
+

Documentation/devicetree/bindings/net/can/cast,can.yaml line 21

Quoted 10 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +10 -0
+allOf:
+  - $ref: can-controller.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: starfive,can
+    then:
+      required:
+        - starfive,syscon

If you've got property related stuff in the allOf, move it down after the property definitions.

Documentation/devicetree/bindings/net/can/cast,can.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +5 -0
+properties:
+  compatible:
+    enum:
+      - cast,can
+      - cast,canfd

I don't like these uber generic compatibles that have no users as a fallback. Allowing them in the binding only really discourages people from creating device specific compatibles.
Secondly, this is some purchased IP that I am sure has a versioning scheme and the compatibles that you have created do not reflect that. If they were being used as a fallback, I would request some versioning. That's not going to really work though since the canfd features on the jh7110 require setting u0_can_ctrl_can_fd_enable, so neither of these compatibles really has a use right now.

Documentation/devicetree/bindings/net/can/cast,can.yaml line 28

Quoted 1 line
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +1 -0
+      - starfive,can

Just "starfive,can"? Can you please add device specific compatibles for the SoCs on which this is used?

Quoted 5 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +5 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:

Documentation/devicetree/bindings/net/can/cast,can.yaml line 43

Quoted 10 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +10 -0
+    maxItems: 1
+
+  clocks:
+    minItems: 3
+
+  clock-names:
+    items:
+      - const: apb_clk
+      - const: timer_clk
+      - const: can_clk

Drop _clk, they're all clocks!

Documentation/devicetree/bindings/net/can/cast,can.yaml line 52

Quoted 9 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +9 -0
+
+  resets:
+    minItems: 3
+
+  reset-names:
+    items:
+      - const: rst_apb
+      - const: rst_core
+      - const: rst_timer

Same here, drop rst_

Documentation/devicetree/bindings/net/can/cast,can.yaml line 59

Quoted 7 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +7 -0
+
+  starfive,syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to System Register Controller syscon node
+          - description: offset of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller

The docs I have call this register "SYS_SYSCONSAIF__SYSCFG". Did the names change since the TRM I have was written?

Documentation/devicetree/bindings/net/can/cast,can.yaml line 65

Quoted 6 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +6 -0
+          - description: shift of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller
+          - description: mask of SYS_SYSCON_NE__SAIF__SYSCFG register for CAN controller
+    description:
+      Should be four parameters, the phandle to System Register Controller
+      syscon node and the offset/shift/mask of SYS_SYSCON_NE__SAIF__SYSCFG register
+      for CAN controller.

Cheers,
Conor.

#6 lore raw

RE: [PATCH v1 2/4] dt-bindings: can: Add bindings for CAST CAN Controller

Quoted 52 lines

-----Original Message-----
From: Conor Dooley <[email protected]>
Sent: 2024年1月29日 23:37
To: William Qiu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Emil Renner Berthing <[email protected]>; Rob Herring <[email protected]>; Wolfgang Grandegger <[email protected]>; Philipp Zabel <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Marc Kleine-Budde <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>
Subject: Re: [PATCH v1 2/4] dt-bindings: can: Add bindings for CAST CAN Controller

Hey William,

Quoted 32 lines · William Qiu

Add bindings for CAST CAN Controller

---
 .../devicetree/bindings/net/can/cast,can.yaml | 95
+++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/can/cast,can.yaml

Documentation/devicetree/bindings/net/can/cast,can.yaml new file +15 -0
new file mode 100644
index 000000000000..ea52132d9b1c
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause %YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/cast,can.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CAST CAN controller
+
+maintainers:
+  - William Qiu <[email protected]>
+
+allOf:
+  - $ref: can-controller.yaml#
+  - if:
+      properties:
+        compatible:
Quoted 9 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 21

Quoted 5 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +5 -0
+          contains:
+            const: starfive,can
+    then:
+      required:
+        - starfive,syscon

If you've got property related stuff in the allOf, move it down after the property definitions.

Will update

Quoted 6 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +5 -0
+properties:
+  compatible:
+    enum:
+      - cast,can
+      - cast,canfd
Quoted 10 lines

I don't like these uber generic compatibles that have no users as a fallback. Allowing them in the binding only really discourages people from creating device specific compatibles.
Secondly, this is some purchased IP that I am sure has a versioning scheme and the compatibles that you have created do not reflect that.
If they were being used as a fallback, I would request some versioning. That's not going to really work though since the canfd features on the jh7110 require setting u0_can_ctrl_can_fd_enable, so neither of these compatibles really has a use right now.

I'll add some tag to do versioning.

Quoted 5 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 28

Quoted 1 line
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +1 -0
+      - starfive,can

Just "starfive,can"? Can you please add device specific compatibles for the SoCs on which this is used?

Will add.

Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +9 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 3
Quoted 9 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 43

Quoted 6 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +6 -0
+
+  clock-names:
+    items:
+      - const: apb_clk
+      - const: timer_clk
+      - const: can_clk

Drop _clk, they're all clocks!

Will drop.

Quoted 21 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 52

Quoted 9 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +9 -0
+
+  resets:
+    minItems: 3
+
+  reset-names:
+    items:
+      - const: rst_apb
+      - const: rst_core
+      - const: rst_timer

Same here, drop rst_
Will drop.

Documentation/devicetree/bindings/net/can/cast,can.yaml

Quoted 8 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +8 -0
+
+  starfive,syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to System Register Controller syscon node
+          - description: offset of SYS_SYSCON_NE__SAIF__SYSCFG
+ register for CAN controller
Quoted 3 lines

The docs I have call this register "SYS_SYSCONSAIF__SYSCFG". Did the names change since the TRM I have was written?

They do change on the 8100 SoC.
Other descriptions may be needed for compatibility. I'll think about it.

Thanks,
William

Quoted 4 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml line 59

Quoted 1 line
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +1 -0
+          - description: shift of SYS_SYSCON_NE__SAIF__SYSCFG register

for CAN controller

Documentation/devicetree/bindings/net/can/cast,can.yaml line 60

Quoted 1 line
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +1 -0
+          - description: mask of SYS_SYSCON_NE__SAIF__SYSCFG register

for CAN controller

Quoted 8 lines

Documentation/devicetree/bindings/net/can/cast,can.yaml

Quoted 3 lines
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +3 -0
+    description:
+      Should be four parameters, the phandle to System Register Controller
+      syscon node and the offset/shift/mask of

SYS_SYSCON_NE__SAIF__SYSCFG register

Documentation/devicetree/bindings/net/can/cast,can.yaml line 65

Quoted 1 line
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +1 -0
+      for CAN controller.

Cheers,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#7 lore raw

Re: [PATCH v1 2/4] dt-bindings: can: Add bindings for CAST CAN Controller

Quoted 19 lines · William Qiu
Quoted 9 lines

From: Conor Dooley <[email protected]>

Documentation/devicetree/bindings/net/can/cast,can.yaml line 27

Quoted 5 lines · William Qiu
Documentation/devicetree/bindings/net/can/cast,can.yaml new file +5 -0
+properties:
+  compatible:
+    enum:
+      - cast,can
+      - cast,canfd
Quoted 10 lines

I don't like these uber generic compatibles that have no users as a fallback. Allowing them in the binding only really discourages people from creating device specific compatibles.
Secondly, this is some purchased IP that I am sure has a versioning scheme and the compatibles that you have created do not reflect that.
If they were being used as a fallback, I would request some versioning. That's not going to really work though since the canfd features on the jh7110 require setting u0_can_ctrl_can_fd_enable, so neither of these compatibles really has a use right now.

Quoted 1 line

I'll add some tag to do versioning.

I don't want to see a "cast,can-<something>" compatible allowed in isolation either as there is no user for it.
The generic compatibles like that should only be permitted in combination with a device specific one - particularly since there are bits in implementation defined registers that control whether or not canfd is enabled.

#8 lore raw

PATCH 3/4 can: cast: add driver for CAST CAN controller

In reply to William Qiu

Add driver for CAST CAN Controller. And add compatibility code which based on StarFive JH7110 SoC.

---
 MAINTAINERS                |    7 +
 drivers/net/can/Kconfig    |    7 +
 drivers/net/can/Makefile   |    1 +
 drivers/net/can/cast_can.c | 1215 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1230 insertions(+)
 create mode 100644 drivers/net/can/cast_can.c
MAINTAINERS +7 -0
index 8d1052fa6a69..daa3af8b4f10 100644
@@ -4723,6 +4723,13 @@ S:	Maintained
 W:	https://wireless.wiki.kernel.org/en/users/Drivers/carl9170
 F:	drivers/net/wireless/ath/carl9170/
 
+CAST CAN DRIVER
+M:	William Qiu <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/net/can/cast,can.yaml
+F:	drivers/net/can/cast_can.c
+
 CAVIUM I2C DRIVER
 M:	Robert Richter <[email protected]>
 S:	Odd Fixes
drivers/net/can/Kconfig +7 -0
index eb410714afc2..d98ad06c8ff3 100644
@@ -124,6 +124,13 @@ config CAN_CAN327
 
 	  If this driver is built as a module, it will be called can327.
 
+config CAN_CASTCAN
+	tristate "CAST CAN"
+	depends on ARCH_STARFIVE || COMPILE_TEST
+	depends on COMMON_CLK && HAS_IOMEM
+	help
+	  CAST CAN driver. This driver supports both CAN and CANFD IP.
+
 config CAN_FLEXCAN
 	tristate "Support for Freescale FLEXCAN based chips"
 	depends on OF || COLDFIRE || COMPILE_TEST
drivers/net/can/Makefile +1 -0
index ff8f76295d13..d6fa47278859 100644
@@ -16,6 +16,7 @@ obj-y				+= softing/
 obj-$(CONFIG_CAN_AT91)		+= at91_can.o
 obj-$(CONFIG_CAN_BXCAN)		+= bxcan.o
 obj-$(CONFIG_CAN_CAN327)	+= can327.o
+obj-$(CONFIG_CAN_CASTCAN)	+= cast_can.o
 obj-$(CONFIG_CAN_CC770)		+= cc770/
 obj-$(CONFIG_CAN_C_CAN)		+= c_can/
 obj-$(CONFIG_CAN_CTUCANFD)	+= ctucanfd/
drivers/net/can/cast_can.c new file +1215 -0

1,215 lines not on this page · raw message

Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#9 lore raw

Re: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

Hello William Qiu,

thank you for your contribution. I've some quick notes about your driver.

Quoted 2 lines · William Qiu

Add driver for CAST CAN Controller. And add compatibility code which based on StarFive JH7110 SoC.

Please add yourself or someone else at starfivetech to the Maintainers file.

Please use BIT() and/or GEN_MASK() to create the _MASK enums. Please use FIELD_GET(), FIELD_PREP.

Please replace the ccan_ioread8() by a proper 32 bit read and use FIELD_GET to access any non 32 bit value. Instead of ccan_iowrite8() use FIELD_PREP and a proper 32 bit write.

The enum ccan_reg_bitchange looks very strange, why do you have OFF and SET values?

The ccan_reigister_set_bit() and ccan_reigister_off_bit() functions looks very strange, too. I suggest to use a 32 bit read, set, clear the bits followed by a 32 bit write. Having set_bit() clear_bit() functions may lead to more register accesses than needed, if not handled with care.

If you think the driver absolutely needs bit set/clear functions, please follow the name and signature of the regmap_update_bits(), regmap_set_bits() and regmap_clear_bits().

Please use can_put_echo_skb(), can_get_echo_skb().

Please implement proper TX-flow control. Stop the TX queue, if you HW queue is full, start the TX queue once the HW queue has space again.

Consider using the rx_offload helper

You claim you IRQ handler works with shared interrupts, but you return an error if there are no interrupts by your IP core.

Please enable the clocks during open() and disabled during close()

Marc

Signature · 4 lines
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   |
#10 lore raw

RE: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

Quoted 49 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2024年1月29日 16:26
To: William Qiu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Emil Renner Berthing <[email protected]>; Rob Herring <[email protected]>; Wolfgang Grandegger <[email protected]>; Philipp Zabel <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>
Subject: Re: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

Hello William Qiu,

thank you for your contribution. I've some quick notes about your driver.

Quoted 2 lines · William Qiu

Add driver for CAST CAN Controller. And add compatibility code which based on StarFive JH7110 SoC.

Please add yourself or someone else at starfivetech to the Maintainers file.

Please use BIT() and/or GEN_MASK() to create the _MASK enums. Please use FIELD_GET(), FIELD_PREP.

Please replace the ccan_ioread8() by a proper 32 bit read and use FIELD_GET to access any non 32 bit value. Instead of ccan_iowrite8() use FIELD_PREP and a proper 32 bit write.

The enum ccan_reg_bitchange looks very strange, why do you have OFF and SET values?

The ccan_reigister_set_bit() and ccan_reigister_off_bit() functions looks very strange, too. I suggest to use a 32 bit read, set, clear the bits followed by a 32 bit write. Having set_bit() clear_bit() functions may lead to more register accesses than needed, if not handled with care.

If you think the driver absolutely needs bit set/clear functions, please follow the name and signature of the regmap_update_bits(),
regmap_set_bits() and regmap_clear_bits().

Please use can_put_echo_skb(), can_get_echo_skb().

Please implement proper TX-flow control. Stop the TX queue, if you HW queue is full, start the TX queue once the HW queue has space again.

Quoted 9 lines

Consider using the rx_offload helper

You claim you IRQ handler works with shared interrupts, but you return an error if there are no interrupts by your IP core.

Please enable the clocks during open() and disabled during close()

Marc

Thank you for your notes. I will modify my driver one by one according to your notes。

Thanks,
William

Quoted 5 lines

--

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 |

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#11 lore raw

Re: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

In reply to William Qiu
kernel test robot noticed the following build warnings:

Hi William,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master mkl-can-next/testing v6.8-rc2 next-20240129] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/William-Qiu/dt-bindings-vendor-prefixes-Add-cast-vendor-prefix/20240129-114752
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240129031239.17037-4-william.qiu%40starfivetech.com
patch subject: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20240130/[email protected]/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 4a39d08908942b2d415db405844cbe4af73e75d4)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240130/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/net/can/cast_can.c:352:5: warning: no previous prototype for function 'ccan_get_freebuffer' [-Wmissing-prototypes]
     352 | int ccan_get_freebuffer(struct ccan_priv *priv)
         |     ^
   drivers/net/can/cast_can.c:352:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
     352 | int ccan_get_freebuffer(struct ccan_priv *priv)
         | ^
         | static 

1 warning generated.

vim +/ccan_get_freebuffer +352 drivers/net/can/cast_can.c

351

 > 352	int ccan_get_freebuffer(struct ccan_priv *priv)

353 {
354 /* Get next transmit buffer */
355 ccan_reigister_set_bit(priv, CCAN_TCTRL_OFFSET, CCAN_SET_TENEXT_MASK);
356
357 if (ccan_ioread8(priv->reg_base + CCAN_TCTRL_OFFSET) & CCAN_SET_TENEXT_MASK)
358 return -EPERM;
359
360 return 0;
361 }
362

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

In reply to William Qiu
kernel test robot noticed the following build warnings:

Hi William,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master mkl-can-next/testing v6.8-rc2 next-20240129] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/William-Qiu/dt-bindings-vendor-prefixes-Add-cast-vendor-prefix/20240129-114752
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240129031239.17037-4-william.qiu%40starfivetech.com
patch subject: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller
config: openrisc-allmodconfig (https://download.01.org/0day-ci/archive/20240130/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240130/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/net/can/cast_can.c:352:5: warning: no previous prototype for 'ccan_get_freebuffer' [-Wmissing-prototypes]

352 | int ccan_get_freebuffer(struct ccan_priv *priv)
| ^~~~~~~~~~~~~~~~~~~

vim +/ccan_get_freebuffer +352 drivers/net/can/cast_can.c

351

 > 352	int ccan_get_freebuffer(struct ccan_priv *priv)

353 {
354 /* Get next transmit buffer */
355 ccan_reigister_set_bit(priv, CCAN_TCTRL_OFFSET, CCAN_SET_TENEXT_MASK);
356
357 if (ccan_ioread8(priv->reg_base + CCAN_TCTRL_OFFSET) & CCAN_SET_TENEXT_MASK)
358 return -EPERM;
359
360 return 0;
361 }
362

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

Re: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller

In reply to William Qiu
kernel test robot noticed the following build warnings:

Hi William,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master mkl-can-next/testing v6.8-rc2 next-20240130] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/William-Qiu/dt-bindings-vendor-prefixes-Add-cast-vendor-prefix/20240129-114752
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240129031239.17037-4-william.qiu%40starfivetech.com
patch subject: [PATCH v1 3/4] can: cast: add driver for CAST CAN controller
config: arm-randconfig-r131-20240131 (https://download.01.org/0day-ci/archive/20240131/[email protected]/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project fdac7d0b6f74f919d319b31a0680c77f66732586)
reproduce: (https://download.01.org/0day-ci/archive/20240131/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/net/can/cast_can.c:277:41: sparse: sparse: subtraction of different types can't work (different address spaces)
   drivers/net/can/cast_can.c:295:41: sparse: sparse: subtraction of different types can't work (different address spaces)
>> drivers/net/can/cast_can.c:308:50: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:357:41: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
>> drivers/net/can/cast_can.c:352:5: sparse: sparse: symbol 'ccan_get_freebuffer' was not declared. Should it be static?
   drivers/net/can/cast_can.c:375:51: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:389:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:394:47: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:396:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:438:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:443:47: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:445:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:504:47: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:505:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:514:55: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:515:57: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:695:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
>> drivers/net/can/cast_can.c:697:43: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:732:48: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:733:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:760:44: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:761:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:762:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:765:48: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:837:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:838:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:849:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:852:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:921:58: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:926:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *addr @@     got void [noderef] __iomem * @@
   drivers/net/can/cast_can.c:934:43: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *addr @@     got void [noderef] __iomem * @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
   drivers/net/can/cast_can.c:260:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:262:31: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
   drivers/net/can/cast_can.c:260:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:262:31: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:244:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
   drivers/net/can/cast_can.c:260:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@
>> drivers/net/can/cast_can.c:262:31: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void volatile [noderef] __iomem *addr @@     got void *[assigned] addr_down @@

vim +277 drivers/net/can/cast_can.c

232
233 static inline unsigned char ccan_ioread8(const void *addr)
234 {
235 void *addr_down;
236 union val {
237 u8 val_8[4];
238 u32 val_32;
239 } val;
240 u32 offset = 0;
241
242 addr_down = (void *)ALIGN_DOWN((unsigned long)addr, 4);
243 offset = addr - addr_down;

 > 244		val.val_32 = ioread32(addr_down);
   245	
   246		return val.val_8[offset];
   247	}
   248	
   249	static inline void ccan_iowrite8(unsigned char value, void  *addr)
   250	{
   251		void  *addr_down;
   252		union val {
   253			u8 val_8[4];
   254			u32 val_32;
   255		} val;
   256		u8 offset = 0;
   257	
   258		addr_down = (void *)ALIGN_DOWN((unsigned long)addr, 4);
   259		offset = addr - addr_down;
   260		val.val_32 = ioread32(addr_down);
   261		val.val_8[offset] = value;
 > 262		iowrite32(val.val_32, addr_down);
   263	}
   264	
   265	static void ccan_reigister_set_bit(const struct ccan_priv *priv,
   266					   enum ccan_device_reg reg,
   267					   enum ccan_reg_bitchange mask)
   268	{
   269		void  *addr_down;
   270		union val {
   271			u8 val_8[4];
   272			u32 val_32;
   273		} val;
   274		u8 offset = 0;
   275	
   276		addr_down = (void *)ALIGN_DOWN((unsigned long)(priv->reg_base + reg), 4);
 > 277		offset = (priv->reg_base + reg) - addr_down;
   278		val.val_32 = ioread32(addr_down);
   279		val.val_8[offset] |= mask;
   280		iowrite32(val.val_32, addr_down);
   281	}
   282	
   283	static void ccan_reigister_off_bit(const struct ccan_priv *priv,
   284					   enum ccan_device_reg reg,
   285					   enum ccan_reg_bitchange mask)
   286	{
   287		void  *addr_down;
   288		union val {
   289			u8 val_8[4];
   290			u32 val_32;
   291		} val;
   292		u8 offset = 0;
   293	
   294		addr_down = (void *)ALIGN_DOWN((unsigned long)(priv->reg_base + reg), 4);
   295		offset = (priv->reg_base + reg) - addr_down;
   296		val.val_32 = ioread32(addr_down);
   297		val.val_8[offset] &= mask;
   298		iowrite32(val.val_32, addr_down);
   299	}
   300	
   301	static int ccan_device_driver_bittime_configuration(struct net_device *ndev)
   302	{
   303		struct ccan_priv *priv = netdev_priv(ndev);
   304		struct can_bittiming *bt = &priv->can.bittiming;
   305		struct can_bittiming *dbt = &priv->can.data_bittiming;
   306		u32 reset_test, bittiming_temp, data_bittiming;
   307	
 > 308		reset_test = ccan_ioread8(priv->reg_base + CCAN_CFG_STAT_OFFSET);
   309	
   310		if (!(reset_test & CCAN_SET_RST_MASK)) {
   311			netdev_alert(ndev, "Not in reset mode, cannot set bit timing\n");
   312			return -EPERM;
   313		}
   314	
   315		bittiming_temp = ((bt->phase_seg1 + bt->prop_seg + 1 - 2) << SEG_1_SHIFT) |
   316				 ((bt->phase_seg2 - 1) << SEG_2_SHIFT) |
   317				 ((bt->sjw - 1) << SJW_SHIFT) |
   318				 ((bt->brp - 1) << PRESC_SHIFT);
   319	
   320		/* Check the bittime parameter */
   321		if ((((int)(bt->phase_seg1 + bt->prop_seg + 1) - 2) < 0) ||
   322		    (((int)(bt->phase_seg2) - 1) < 0) ||
   323		    (((int)(bt->sjw) - 1) < 0) ||
   324		    (((int)(bt->brp) - 1) < 0))
   325			return -EINVAL;
   326	
   327		priv->write_reg(priv, CCAN_S_SEG_1_OFFSET, bittiming_temp);
   328	
   329		if (priv->cantype == CAST_CAN_TYPE_CANFD) {
   330			data_bittiming = ((dbt->phase_seg1 + dbt->prop_seg + 1 - 2) << SEG_1_SHIFT) |
   331					 ((dbt->phase_seg2 - 1) << SEG_2_SHIFT) |
   332					 ((dbt->sjw - 1) << SJW_SHIFT) |
   333					 ((dbt->brp - 1) << PRESC_SHIFT);
   334	
   335			if ((((int)(dbt->phase_seg1 + dbt->prop_seg + 1) - 2) < 0) ||
   336			    (((int)(dbt->phase_seg2) - 1) < 0) ||
   337			    (((int)(dbt->sjw) - 1) < 0) ||
   338			    (((int)(dbt->brp) - 1) < 0))
   339				return -EINVAL;
   340	
   341			priv->write_reg(priv, CCAN_F_SEG_1_OFFSET, data_bittiming);
   342		}
   343	
   344		ccan_reigister_off_bit(priv, CCAN_CFG_STAT_OFFSET, CCAN_OFF_RST_MASK);
   345	
   346		netdev_dbg(ndev, "Slow bit rate: %08x\n", priv->read_reg(priv, CCAN_S_SEG_1_OFFSET));
   347		netdev_dbg(ndev, "Fast bit rate: %08x\n", priv->read_reg(priv, CCAN_F_SEG_1_OFFSET));
   348	
   349		return 0;
   350	}
   351	
 > 352	int ccan_get_freebuffer(struct ccan_priv *priv)
   353	{
   354		/* Get next transmit buffer */
   355		ccan_reigister_set_bit(priv, CCAN_TCTRL_OFFSET, CCAN_SET_TENEXT_MASK);
   356	
   357		if (ccan_ioread8(priv->reg_base + CCAN_TCTRL_OFFSET) & CCAN_SET_TENEXT_MASK)
   358			return -EPERM;
   359	
   360		return 0;
   361	}
   362	
   363	static void ccan_tx_interrupt(struct net_device *ndev, u8 isr)
   364	{
   365		struct ccan_priv *priv = netdev_priv(ndev);
   366	
   367		/* wait till transmission of the PTB or STB finished */
   368		while (isr & (CCAN_SET_TPIF_MASK | CCAN_SET_TSIF_MASK)) {
   369			if (isr & CCAN_SET_TPIF_MASK)
   370				ccan_reigister_set_bit(priv, CCAN_RTIF_OFFSET, CCAN_SET_TPIF_MASK);
   371	
   372			if (isr & CCAN_SET_TSIF_MASK)
   373				ccan_reigister_set_bit(priv, CCAN_RTIF_OFFSET, CCAN_SET_TSIF_MASK);
   374	
   375			isr = ccan_ioread8(priv->reg_base + CCAN_RTIF_OFFSET);
   376		}
   377		netif_wake_queue(ndev);
   378	}
   379	
   380	static int ccan_rx(struct net_device *ndev)
   381	{
   382		struct ccan_priv *priv = netdev_priv(ndev);
   383		struct net_device_stats *stats = &ndev->stats;
   384		struct can_frame *cf;
   385		struct sk_buff *skb;
   386		u32 can_id;
   387		u8  dlc, control, rx_status;
   388	
   389		rx_status = ccan_ioread8(priv->reg_base + CCAN_RCTRL_OFFSET);
   390	
   391		if (!(rx_status & CCAN_RSTAT_NOT_EMPTY_MASK))
   392			return 0;
   393	
   394		control = ccan_ioread8(priv->reg_base + CCAN_RBUF_CTL_OFFSET);
   395		can_id = priv->read_reg(priv, CCAN_RUBF_ID_OFFSET);
 > 396		dlc = ccan_ioread8(priv->reg_base + CCAN_RBUF_CTL_OFFSET) & CCAN_SET_DLC_MASK;

397
398 skb = alloc_can_skb(ndev, (struct can_frame **)&cf);
399 if (!skb) {
400 stats->rx_dropped++;
401 return 0;
402 }
403 cf->can_dlc = can_cc_dlc2len(dlc);
404
405 /* change the CANFD id into socketcan id format */
406 cf->can_id = can_id;
407 if (control & CCAN_SET_IDE_MASK)
408 cf->can_id |= CAN_EFF_FLAG;
409 else
410 cf->can_id &= ~CAN_EFF_FLAG;
411
412 if (control & CCAN_SET_RTR_MASK)
413 cf->can_id |= CAN_RTR_FLAG;
414
415 if (!(control & CCAN_SET_RTR_MASK)) {
416 *((u32 *)(cf->data + 0)) = priv->read_reg(priv, CCAN_RBUF_DATA_OFFSET);
417 *((u32 *)(cf->data + 4)) = priv->read_reg(priv, CCAN_RBUF_DATA_OFFSET + 4);
418 }
419
420 ccan_reigister_set_bit(priv, CCAN_RCTRL_OFFSET, CCAN_SET_RREL_MASK);
421 stats->rx_bytes += can_fd_dlc2len(cf->can_dlc);
422 stats->rx_packets++;
423 netif_receive_skb(skb);
424
425 return 1;
426 }
427

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#14 lore raw

PATCH 4/4 riscv: dts: starfive: jh7110: Add CAN node

In reply to William Qiu

Add CAST CAN controller node in JH7110 SoC.

---
 arch/riscv/boot/dts/starfive/jh7110.dtsi | 32 ++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
arch/riscv/boot/dts/starfive/jh7110.dtsi +32 -0
index 45213cdf50dc..4d0469cb8ca9 100644
@@ -914,6 +914,38 @@ watchdog@13070000 {
 				 <&syscrg JH7110_SYSRST_WDT_CORE>;
 		};
 
+		can0: can@130d0000 {
+			compatible = "starfive,can";
+			reg = <0x0 0x130d0000 0x0 0x1000>;
+			interrupts = <112>;
+			clocks = <&syscrg JH7110_SYSCLK_CAN0_APB>,
+				 <&syscrg JH7110_SYSCLK_CAN0_TIMER>,
+				 <&syscrg JH7110_SYSCLK_CAN0_CAN>;
+			clock-names = "apb_clk", "timer_clk", "can_clk";
+			resets = <&syscrg JH7110_SYSRST_CAN0_APB>,
+				 <&syscrg JH7110_SYSRST_CAN0_CORE>,
+				 <&syscrg JH7110_SYSRST_CAN0_TIMER>;
+			reset-names = "rst_apb", "rst_core", "rst_timer";
+			starfive,syscon = <&sys_syscon 0x10 0x3 0x8>;
+			status = "disabled";
+		};
+
+		can1: can@130e0000 {
+			compatible = "starfive,can";
+			reg = <0x0 0x130e0000 0x0 0x1000>;
+			interrupts = <113>;
+			clocks = <&syscrg JH7110_SYSCLK_CAN1_APB>,
+				 <&syscrg JH7110_SYSCLK_CAN1_TIMER>,
+				 <&syscrg JH7110_SYSCLK_CAN1_CAN>;
+			clock-names = "apb_clk", "timer_clk", "can_clk";
+			resets = <&syscrg JH7110_SYSRST_CAN1_APB>,
+				 <&syscrg JH7110_SYSRST_CAN1_CORE>,
+				 <&syscrg JH7110_SYSRST_CAN1_TIMER>;
+			reset-names = "rst_apb", "rst_core", "rst_timer";
+			starfive,syscon = <&sys_syscon 0x88 0x12 0x40000>;
+			status = "disabled";
+		};
+
 		crypto: crypto@16000000 {
 			compatible = "starfive,jh7110-crypto";
 			reg = <0x0 0x16000000 0x0 0x4000>;
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#15 lore raw
In reply to William Qiu
Quoted 6 lines · William Qiu

Hi,

This patchset adds initial rudimentary support for the CAST Controller Area Network driver. And we registered cast in kernel as well. This driver will be applied in JH7110 SoC first, so add relevant compatibility support.

Is there a public available data sheet for the IP core?

Marc

Quoted 23 lines

William Qiu (4):
dt-bindings: vendor-prefixes: Add cast vendor prefix
dt-bindings: can: Add bindings for CAST CAN Controller
can: cast: add driver for CAST CAN controller
riscv: dts: starfive: jh7110: Add CAN node

 .../devicetree/bindings/net/can/cast,can.yaml |   95 ++
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 MAINTAINERS                                   |    7 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   32 +
 drivers/net/can/Kconfig                       |    7 +
 drivers/net/can/Makefile                      |    1 +
 drivers/net/can/cast_can.c                    | 1215 +++++++++++++++++
 7 files changed, 1359 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/cast,can.yaml
 create mode 100644 drivers/net/can/cast_can.c

--
2.34.1

Signature · 4 lines
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   |
#16 lore raw
Quoted 19 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2024年1月29日 15:58
To: William Qiu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Emil Renner Berthing <[email protected]>; Rob Herring <[email protected]>; Wolfgang Grandegger <[email protected]>; Philipp Zabel <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>
Subject: Re: [PATCH v1 0/4] CAST Controller Area Network driver support

Quoted 2 lines · William Qiu

Hi,

Quoted 9 lines
Quoted 4 lines

This patchset adds initial rudimentary support for the CAST Controller Area Network driver. And we registered cast in kernel as well. This driver will be applied in JH7110 SoC first, so add relevant compatibility support.

Is there a public available data sheet for the IP core?

Marc

We do have the data sheet, but I'm not sure if CAST is willing to make it public. I need to contact them first and then reply to you.
Or you can contact them on their website, which is https://www.cast-inc.com/.

Thanks,
William

Quoted 31 lines
Quoted 7 lines

William Qiu (4):
dt-bindings: vendor-prefixes: Add cast vendor prefix
dt-bindings: can: Add bindings for CAST CAN Controller
can: cast: add driver for CAST CAN controller
riscv: dts: starfive: jh7110: Add CAN node

Quoted 7 lines
 .../devicetree/bindings/net/can/cast,can.yaml |   95 ++
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 MAINTAINERS                                   |    7 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   32 +
 drivers/net/can/Kconfig                       |    7 +
 drivers/net/can/Makefile                      |    1 +
 drivers/net/can/cast_can.c                    | 1215

+++++++++++++++++

Quoted 10 lines
 7 files changed, 1359 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/net/can/cast,can.yaml
 create mode 100644 drivers/net/can/cast_can.c

--
2.34.1

--

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 |

#17 lore raw
Quoted 5 lines · William Qiu
Quoted 1 line

Is there a public available data sheet for the IP core?

We do have the data sheet, but I'm not sure if CAST is willing to make it public. I need to contact them first and then reply to you.
Or you can contact them on their website, which is https://www.cast-inc.com/.

I'll contact them via the website, but please ask them as well, as you have probably a better, more direct contact to them.

regards,
Marc

Signature · 4 lines
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   |
#18 lore raw
Quoted 23 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2024年1月29日 19:31
To: William Qiu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Emil Renner Berthing <[email protected]>; Rob Herring <[email protected]>; Wolfgang Grandegger <[email protected]>; Philipp Zabel <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>
Subject: Re: RE: [PATCH v1 0/4] CAST Controller Area Network driver support

Quoted 5 lines · William Qiu
Quoted 1 line

Is there a public available data sheet for the IP core?

We do have the data sheet, but I'm not sure if CAST is willing to make it public. I need to contact them first and then reply to you. Or you can contact them on their website, which is

Quoted 8 lines

https://www.cast-inc.com/.

I'll contact them via the website, but please ask them as well, as you have probably a better, more direct contact to them.

regards,
Marc

I see. I'll do it .

Thanks,
William

Quoted 5 lines

--

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 |