The controller can operate in one of the two global modes
- CAN FD only mode (default)
- Classical CAN (CAN2.0) only mode
This patch adds support for Classical CAN only mode. It can be enabled
by defining the optional device tree property "renesas,no-can-fd" of this
node.
Note: R-Car Gen3 h/w manual v0.51E shows bit6 of RSCFDnCFDGCFG as
reserved, which is incorrect. This bit is same as RSCFDnGCFG.
Signed-off-by: Ramesh Shanmugasundaram
---
.../devicetree/bindings/net/can/rcar_canfd.txt | 21 +-
drivers/net/can/rcar/rcar_canfd.c | 355 ++---
2 files changed, 255 insertions(+), 121 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
index d45182b..22a6f10 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
@@ -32,6 +32,12 @@ below properties.
- assigned-clocks: phandle of canfd clock.
- assigned-clock-rates: maximum frequency of this clock.
+Optional property:
+The controller can operate in either CAN FD only mode (default) or
+Classical CAN only mode. The mode is global to both the channels. In order to
+enable the later, define the following optional property.
+ - renesas,no-can-fd: puts the controller in Classical CAN only mode.
+
Example
---
@@ -63,12 +69,13 @@ SoC common .dtsi file:
Board specific .dts file:
-E.g. below enables Channel 1 alone in the board.
+E.g. below enables Channel 1 alone in the board in Classical CAN only mode.
{
-pinctrl-0 = <_pins>;
-pinctrl-names = "default";
-status = "okay";
+ pinctrl-0 = <_pins>;
+ pinctrl-names = "default";
+ renesas,no-can-fd;
+ status = "okay";
channel1 {
status = "okay";
@@ -79,9 +86,9 @@ E.g. below enables Channel 0 alone in the board using
External clock
as fCAN clock.
{
-pinctrl-0 = <_pins _clk_pins>;
-pinctrl-names = "default";
-status = "okay";
+ pinctrl-0 = <_pins _clk_pins>;
+ pinctrl-names = "default";
+ status = "okay";
channel0 {
status = "okay";
diff --git a/drivers/net/can/rcar/rcar_canfd.c
b/drivers/net/can/rcar/rcar_canfd.c
index a39d922..6bcc474 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -16,8 +16,9 @@
* mode, the controller acts as a CAN FD node that can also interoperate with
* CAN 2.0 nodes.
*
- * As of now, this driver does not support the Classical CAN (CAN 2.0) mode,
- * which is handled by a different register map compared to CAN FD only mode.
+ * To switch the controller to Classical CAN (CAN 2.0) only mode, add
+ * "renesas,no-can-fd" optional property to the device tree node. A h/w reset
is
+ * also required to switch modes.
*
* Note: The h/w manual register naming convention is clumsy and not acceptable
* to use as it is in the driver. However, those names are added as comments
@@ -48,15 +49,16 @@
/* RSCFDnCFDGRMCFG */
#define RCANFD_GRMCFG_RCMC BIT(0)
-/* RSCFDnCFDGCFG */
-#define RCANFD_GCFG_CMPOC BIT(5)
+/* RSCFDnCFDGCFG / RSCFDnGCFG */
+#define RCANFD_GCFG_EEFE BIT(6)
+#define RCANFD_GCFG_CMPOC BIT(5) /* CAN FD only */
#define RCANFD_GCFG_DCSBIT(4)
#define RCANFD_GCFG_DCEBIT(1)
#define RCANFD_GCFG_TPRI BIT(0)
-/* RSCFDnCFDGCTR */
+/* RSCFDnCFDGCTR / RSCFDnGCTR */
#define RCANFD_GCTR_TSRST BIT(16)
-#define RCANFD_GCTR_CFMPOFIE BIT(11)
+#define RCANFD_GCTR_CFMPOFIE BIT(11) /* CAN FD only */
#define RCANFD_GCTR_THLEIE BIT(10)
#define RCANFD_GCTR_MEIE BIT(9)
#define RCANFD_GCTR_DEIE BIT(8)
@@ -66,7 +68,7 @@
#define RCANFD_GCTR_GMDC_GRESET(0x1)
#define RCANFD_GCTR_GMDC_GTEST (0x2)
-/* RSCFDnCFDGSTS */
+/* RSCFDnCFDGSTS / RSCFDnGSTS */
#define RCANFD_GSTS_GRAMINIT BIT(3)
#define RCANFD_GSTS_GSLPSTSBIT(2)
#define RCANFD_GSTS_GHLTSTSBIT(1)
@@ -74,44 +76,50 @@
/* Non-operational status */
#define RCANFD_GSTS_GNOPM (BIT(0) | BIT(1) | BIT(2) | BIT(3))
-/* RSCFDnCFDGERFL */
+/* RSCFDnCFDGERFL / RSCFDnGERFL */
#define RCANFD_GERFL_EEF1 BIT(17)
#define RCANFD_GERFL_EEF0 BIT(16)
-#define RCANFD_GERFL_CMPOF BIT(3)
+#define RCANFD_GERFL_CMPOF BIT(3) /* CAN FD only */
#define RCANFD_GERFL_THLES BIT(2)
#define RCANFD_GERFL_MES BIT(1)
#define RCANFD_GERFL_DEF BIT(0)
-#define RCANFD_GERFL_ERR(x)((x) & (RCANFD_GERFL_EEF1 |\
- RCANFD_GERFL_EEF0 |\
- RCANFD_GERFL_MES |\
-