aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>2016-06-22 08:31:46 -0400
committerMarc Kleine-Budde <mkl@pengutronix.de>2016-06-23 05:23:49 -0400
commit6f4c2eea353809fb85386d5ce17a30e37042847d (patch)
tree12435f92ba47dc1a23518832f7991379d6cf2bed
parent2781ff5c8fc7722e97503f96686bf6d7093069a9 (diff)
can: rcar_canfd: Add Classical CAN only mode support
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 <ramesh.shanmugasundaram@bp.renesas.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--Documentation/devicetree/bindings/net/can/rcar_canfd.txt21
-rw-r--r--drivers/net/can/rcar/rcar_canfd.c355
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 d45182bd21dd..22a6f10bab05 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.
32- assigned-clocks: phandle of canfd clock. 32- assigned-clocks: phandle of canfd clock.
33- assigned-clock-rates: maximum frequency of this clock. 33- assigned-clock-rates: maximum frequency of this clock.
34 34
35Optional property:
36The controller can operate in either CAN FD only mode (default) or
37Classical CAN only mode. The mode is global to both the channels. In order to
38enable the later, define the following optional property.
39 - renesas,no-can-fd: puts the controller in Classical CAN only mode.
40
35Example 41Example
36------- 42-------
37 43
@@ -63,12 +69,13 @@ SoC common .dtsi file:
63 69
64Board specific .dts file: 70Board specific .dts file:
65 71
66E.g. below enables Channel 1 alone in the board. 72E.g. below enables Channel 1 alone in the board in Classical CAN only mode.
67 73
68&canfd { 74&canfd {
69 pinctrl-0 = <&canfd1_pins>; 75 pinctrl-0 = <&canfd1_pins>;
70 pinctrl-names = "default"; 76 pinctrl-names = "default";
71 status = "okay"; 77 renesas,no-can-fd;
78 status = "okay";
72 79
73 channel1 { 80 channel1 {
74 status = "okay"; 81 status = "okay";
@@ -79,9 +86,9 @@ E.g. below enables Channel 0 alone in the board using External clock
79as fCAN clock. 86as fCAN clock.
80 87
81&canfd { 88&canfd {
82 pinctrl-0 = <&canfd0_pins &can_clk_pins>; 89 pinctrl-0 = <&canfd0_pins &can_clk_pins>;
83 pinctrl-names = "default"; 90 pinctrl-names = "default";
84 status = "okay"; 91 status = "okay";
85 92
86 channel0 { 93 channel0 {
87 status = "okay"; 94 status = "okay";
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index a39d9224166c..6bcc47408423 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -16,8 +16,9 @@
16 * mode, the controller acts as a CAN FD node that can also interoperate with 16 * mode, the controller acts as a CAN FD node that can also interoperate with
17 * CAN 2.0 nodes. 17 * CAN 2.0 nodes.
18 * 18 *
19 * As of now, this driver does not support the Classical CAN (CAN 2.0) mode, 19 * To switch the controller to Classical CAN (CAN 2.0) only mode, add
20 * which is handled by a different register map compared to CAN FD only mode. 20 * "renesas,no-can-fd" optional property to the device tree node. A h/w reset is
21 * also required to switch modes.
21 * 22 *
22 * Note: The h/w manual register naming convention is clumsy and not acceptable 23 * Note: The h/w manual register naming convention is clumsy and not acceptable
23 * to use as it is in the driver. However, those names are added as comments 24 * to use as it is in the driver. However, those names are added as comments
@@ -48,15 +49,16 @@
48/* RSCFDnCFDGRMCFG */ 49/* RSCFDnCFDGRMCFG */
49#define RCANFD_GRMCFG_RCMC BIT(0) 50#define RCANFD_GRMCFG_RCMC BIT(0)
50 51
51/* RSCFDnCFDGCFG */ 52/* RSCFDnCFDGCFG / RSCFDnGCFG */
52#define RCANFD_GCFG_CMPOC BIT(5) 53#define RCANFD_GCFG_EEFE BIT(6)
54#define RCANFD_GCFG_CMPOC BIT(5) /* CAN FD only */
53#define RCANFD_GCFG_DCS BIT(4) 55#define RCANFD_GCFG_DCS BIT(4)
54#define RCANFD_GCFG_DCE BIT(1) 56#define RCANFD_GCFG_DCE BIT(1)
55#define RCANFD_GCFG_TPRI BIT(0) 57#define RCANFD_GCFG_TPRI BIT(0)
56 58
57/* RSCFDnCFDGCTR */ 59/* RSCFDnCFDGCTR / RSCFDnGCTR */
58#define RCANFD_GCTR_TSRST BIT(16) 60#define RCANFD_GCTR_TSRST BIT(16)
59#define RCANFD_GCTR_CFMPOFIE BIT(11) 61#define RCANFD_GCTR_CFMPOFIE BIT(11) /* CAN FD only */
60#define RCANFD_GCTR_THLEIE BIT(10) 62#define RCANFD_GCTR_THLEIE BIT(10)
61#define RCANFD_GCTR_MEIE BIT(9) 63#define RCANFD_GCTR_MEIE BIT(9)
62#define RCANFD_GCTR_DEIE BIT(8) 64#define RCANFD_GCTR_DEIE BIT(8)
@@ -66,7 +68,7 @@
66#define RCANFD_GCTR_GMDC_GRESET (0x1) 68#define RCANFD_GCTR_GMDC_GRESET (0x1)
67#define RCANFD_GCTR_GMDC_GTEST (0x2) 69#define RCANFD_GCTR_GMDC_GTEST (0x2)
68 70
69/* RSCFDnCFDGSTS */ 71/* RSCFDnCFDGSTS / RSCFDnGSTS */
70#define RCANFD_GSTS_GRAMINIT BIT(3) 72#define RCANFD_GSTS_GRAMINIT BIT(3)
71#define RCANFD_GSTS_GSLPSTS BIT(2) 73#define RCANFD_GSTS_GSLPSTS BIT(2)
72#define RCANFD_GSTS_GHLTSTS BIT(1) 74#define RCANFD_GSTS_GHLTSTS BIT(1)
@@ -74,44 +76,50 @@
74/* Non-operational status */ 76/* Non-operational status */
75#define RCANFD_GSTS_GNOPM (BIT(0) | BIT(1) | BIT(2) | BIT(3)) 77#define RCANFD_GSTS_GNOPM (BIT(0) | BIT(1) | BIT(2) | BIT(3))
76 78
77/* RSCFDnCFDGERFL */ 79/* RSCFDnCFDGERFL / RSCFDnGERFL */
78#define RCANFD_GERFL_EEF1 BIT(17) 80#define RCANFD_GERFL_EEF1 BIT(17)
79#define RCANFD_GERFL_EEF0 BIT(16) 81#define RCANFD_GERFL_EEF0 BIT(16)
80#define RCANFD_GERFL_CMPOF BIT(3) 82#define RCANFD_GERFL_CMPOF BIT(3) /* CAN FD only */
81#define RCANFD_GERFL_THLES BIT(2) 83#define RCANFD_GERFL_THLES BIT(2)
82#define RCANFD_GERFL_MES BIT(1) 84#define RCANFD_GERFL_MES BIT(1)
83#define RCANFD_GERFL_DEF BIT(0) 85#define RCANFD_GERFL_DEF BIT(0)
84 86
85#define RCANFD_GERFL_ERR(x) ((x) & (RCANFD_GERFL_EEF1 |\ 87#define RCANFD_GERFL_ERR(gpriv, x) ((x) & (RCANFD_GERFL_EEF1 |\
86 RCANFD_GERFL_EEF0 |\ 88 RCANFD_GERFL_EEF0 | RCANFD_GERFL_MES |\
87 RCANFD_GERFL_MES |\ 89 (gpriv->fdmode ?\
88 RCANFD_GERFL_CMPOF)) 90 RCANFD_GERFL_CMPOF : 0)))
89 91
90/* AFL Rx rules registers */ 92/* AFL Rx rules registers */
91 93
92/* RSCFDnCFDGAFLCFG0 */ 94/* RSCFDnCFDGAFLCFG0 / RSCFDnGAFLCFG0 */
93#define RCANFD_GAFLCFG_SETRNC(n, x) (((x) & 0xff) << (24 - n * 8)) 95#define RCANFD_GAFLCFG_SETRNC(n, x) (((x) & 0xff) << (24 - n * 8))
94#define RCANFD_GAFLCFG_GETRNC(n, x) (((x) >> (24 - n * 8)) & 0xff) 96#define RCANFD_GAFLCFG_GETRNC(n, x) (((x) >> (24 - n * 8)) & 0xff)
95 97
96/* RSCFDnCFDGAFLECTR */ 98/* RSCFDnCFDGAFLECTR / RSCFDnGAFLECTR */
97#define RCANFD_GAFLECTR_AFLDAE BIT(8) 99#define RCANFD_GAFLECTR_AFLDAE BIT(8)
98#define RCANFD_GAFLECTR_AFLPN(x) ((x) & 0x1f) 100#define RCANFD_GAFLECTR_AFLPN(x) ((x) & 0x1f)
99 101
100/* RSCFDnCFDGAFLIDj */ 102/* RSCFDnCFDGAFLIDj / RSCFDnGAFLIDj */
101#define RCANFD_GAFLID_GAFLLB BIT(29) 103#define RCANFD_GAFLID_GAFLLB BIT(29)
102 104
103/* RSCFDnCFDGAFLP1_j */ 105/* RSCFDnCFDGAFLP1_j / RSCFDnGAFLP1_j */
104#define RCANFD_GAFLP1_GAFLFDP(x) (1 << (x)) 106#define RCANFD_GAFLP1_GAFLFDP(x) (1 << (x))
105 107
106/* Channel register bits */ 108/* Channel register bits */
107 109
108/* RSCFDnCFDCmNCFG */ 110/* RSCFDnCmCFG - Classical CAN only */
111#define RCANFD_CFG_SJW(x) (((x) & 0x3) << 24)
112#define RCANFD_CFG_TSEG2(x) (((x) & 0x7) << 20)
113#define RCANFD_CFG_TSEG1(x) (((x) & 0xf) << 16)
114#define RCANFD_CFG_BRP(x) (((x) & 0x3ff) << 0)
115
116/* RSCFDnCFDCmNCFG - CAN FD only */
109#define RCANFD_NCFG_NTSEG2(x) (((x) & 0x1f) << 24) 117#define RCANFD_NCFG_NTSEG2(x) (((x) & 0x1f) << 24)
110#define RCANFD_NCFG_NTSEG1(x) (((x) & 0x7f) << 16) 118#define RCANFD_NCFG_NTSEG1(x) (((x) & 0x7f) << 16)
111#define RCANFD_NCFG_NSJW(x) (((x) & 0x1f) << 11) 119#define RCANFD_NCFG_NSJW(x) (((x) & 0x1f) << 11)
112#define RCANFD_NCFG_NBRP(x) (((x) & 0x3ff) << 0) 120#define RCANFD_NCFG_NBRP(x) (((x) & 0x3ff) << 0)
113 121
114/* RSCFDnCFDCmCTR */ 122/* RSCFDnCFDCmCTR / RSCFDnCmCTR */
115#define RCANFD_CCTR_CTME BIT(24) 123#define RCANFD_CCTR_CTME BIT(24)
116#define RCANFD_CCTR_ERRD BIT(23) 124#define RCANFD_CCTR_ERRD BIT(23)
117#define RCANFD_CCTR_BOM_MASK (0x3 << 21) 125#define RCANFD_CCTR_BOM_MASK (0x3 << 21)
@@ -136,7 +144,7 @@
136#define RCANFD_CCTR_CHDMC_CRESET (0x1) 144#define RCANFD_CCTR_CHDMC_CRESET (0x1)
137#define RCANFD_CCTR_CHDMC_CHLT (0x2) 145#define RCANFD_CCTR_CHDMC_CHLT (0x2)
138 146
139/* RSCFDnCFDCmSTS */ 147/* RSCFDnCFDCmSTS / RSCFDnCmSTS */
140#define RCANFD_CSTS_COMSTS BIT(7) 148#define RCANFD_CSTS_COMSTS BIT(7)
141#define RCANFD_CSTS_RECSTS BIT(6) 149#define RCANFD_CSTS_RECSTS BIT(6)
142#define RCANFD_CSTS_TRMSTS BIT(5) 150#define RCANFD_CSTS_TRMSTS BIT(5)
@@ -149,7 +157,7 @@
149#define RCANFD_CSTS_TECCNT(x) (((x) >> 24) & 0xff) 157#define RCANFD_CSTS_TECCNT(x) (((x) >> 24) & 0xff)
150#define RCANFD_CSTS_RECCNT(x) (((x) >> 16) & 0xff) 158#define RCANFD_CSTS_RECCNT(x) (((x) >> 16) & 0xff)
151 159
152/* RSCFDnCFDCmERFL */ 160/* RSCFDnCFDCmERFL / RSCFDnCmERFL */
153#define RCANFD_CERFL_ADERR BIT(14) 161#define RCANFD_CERFL_ADERR BIT(14)
154#define RCANFD_CERFL_B0ERR BIT(13) 162#define RCANFD_CERFL_B0ERR BIT(13)
155#define RCANFD_CERFL_B1ERR BIT(12) 163#define RCANFD_CERFL_B1ERR BIT(12)
@@ -239,14 +247,14 @@
239#define RCANFD_CFFDCSTS_CFBRS BIT(1) 247#define RCANFD_CFFDCSTS_CFBRS BIT(1)
240#define RCANFD_CFFDCSTS_CFESI BIT(0) 248#define RCANFD_CFFDCSTS_CFESI BIT(0)
241 249
242/* This controller supports classical CAN only mode or CAN FD only mode. These 250/* This controller supports either Classical CAN only mode or CAN FD only mode.
243 * modes are supported in two separate set of register maps & names. However, 251 * These modes are supported in two separate set of register maps & names.
244 * some of the register offsets are common for both modes. Those offsets are 252 * However, some of the register offsets are common for both modes. Those
245 * listed below as Common registers. 253 * offsets are listed below as Common registers.
246 * 254 *
247 * The CAN FD only specific registers are listed separately and their names 255 * The CAN FD only mode specific registers & Classical CAN only mode specific
248 * starts with RCANFD_F_xxx names. When classical CAN only specific registers 256 * registers are listed separately. Their register names starts with
249 * are added, those specific registers can be prefixed as RCANFD_C_xxx. 257 * RCANFD_F_xxx & RCANFD_C_xxx respectively.
250 */ 258 */
251 259
252/* Common registers */ 260/* Common registers */
@@ -353,7 +361,7 @@
353#define RCANFD_GTSTCTR (0x046c) 361#define RCANFD_GTSTCTR (0x046c)
354/* RSCFDnCFDGLOCKK / RSCFDnGLOCKK */ 362/* RSCFDnCFDGLOCKK / RSCFDnGLOCKK */
355#define RCANFD_GLOCKK (0x047c) 363#define RCANFD_GLOCKK (0x047c)
356/* RSCFDnCFDGRMCFG / RSCFDnGRMCFG */ 364/* RSCFDnCFDGRMCFG */
357#define RCANFD_GRMCFG (0x04fc) 365#define RCANFD_GRMCFG (0x04fc)
358 366
359/* RSCFDnCFDGAFLIDj / RSCFDnGAFLIDj */ 367/* RSCFDnCFDGAFLIDj / RSCFDnGAFLIDj */
@@ -365,6 +373,46 @@
365/* RSCFDnCFDGAFLP1j / RSCFDnGAFLP1j */ 373/* RSCFDnCFDGAFLP1j / RSCFDnGAFLP1j */
366#define RCANFD_GAFLP1(offset, j) ((offset) + 0x0c + (0x10 * (j))) 374#define RCANFD_GAFLP1(offset, j) ((offset) + 0x0c + (0x10 * (j)))
367 375
376/* Classical CAN only mode register map */
377
378/* RSCFDnGAFLXXXj offset */
379#define RCANFD_C_GAFL_OFFSET (0x0500)
380
381/* RSCFDnRMXXXq -> RCANFD_C_RMXXX(q) */
382#define RCANFD_C_RMID(q) (0x0600 + (0x10 * (q)))
383#define RCANFD_C_RMPTR(q) (0x0604 + (0x10 * (q)))
384#define RCANFD_C_RMDF0(q) (0x0608 + (0x10 * (q)))
385#define RCANFD_C_RMDF1(q) (0x060c + (0x10 * (q)))
386
387/* RSCFDnRFXXx -> RCANFD_C_RFXX(x) */
388#define RCANFD_C_RFOFFSET (0x0e00)
389#define RCANFD_C_RFID(x) (RCANFD_C_RFOFFSET + (0x10 * (x)))
390#define RCANFD_C_RFPTR(x) (RCANFD_C_RFOFFSET + 0x04 + \
391 (0x10 * (x)))
392#define RCANFD_C_RFDF(x, df) (RCANFD_C_RFOFFSET + 0x08 + \
393 (0x10 * (x)) + (0x04 * (df)))
394
395/* RSCFDnCFXXk -> RCANFD_C_CFXX(ch, k) */
396#define RCANFD_C_CFOFFSET (0x0e80)
397#define RCANFD_C_CFID(ch, idx) (RCANFD_C_CFOFFSET + (0x30 * (ch)) + \
398 (0x10 * (idx)))
399#define RCANFD_C_CFPTR(ch, idx) (RCANFD_C_CFOFFSET + 0x04 + \
400 (0x30 * (ch)) + (0x10 * (idx)))
401#define RCANFD_C_CFDF(ch, idx, df) (RCANFD_C_CFOFFSET + 0x08 + \
402 (0x30 * (ch)) + (0x10 * (idx)) + \
403 (0x04 * (df)))
404
405/* RSCFDnTMXXp -> RCANFD_C_TMXX(p) */
406#define RCANFD_C_TMID(p) (0x1000 + (0x10 * (p)))
407#define RCANFD_C_TMPTR(p) (0x1004 + (0x10 * (p)))
408#define RCANFD_C_TMDF0(p) (0x1008 + (0x10 * (p)))
409#define RCANFD_C_TMDF1(p) (0x100c + (0x10 * (p)))
410
411/* RSCFDnTHLACCm */
412#define RCANFD_C_THLACC(m) (0x1800 + (0x04 * (m)))
413/* RSCFDnRPGACCr */
414#define RCANFD_C_RPGACC(r) (0x1900 + (0x04 * (r)))
415
368/* CAN FD mode specific regsiter map */ 416/* CAN FD mode specific regsiter map */
369 417
370/* RSCFDnCFDCmXXX -> RCANFD_F_XXX(m) */ 418/* RSCFDnCFDCmXXX -> RCANFD_F_XXX(m) */
@@ -468,6 +516,7 @@ struct rcar_canfd_global {
468 struct clk *can_clk; /* fCAN clock */ 516 struct clk *can_clk; /* fCAN clock */
469 enum rcar_canfd_fcanclk fcan; /* CANFD or Ext clock */ 517 enum rcar_canfd_fcanclk fcan; /* CANFD or Ext clock */
470 unsigned long channels_mask; /* Enabled channels mask */ 518 unsigned long channels_mask; /* Enabled channels mask */
519 bool fdmode; /* CAN FD or Classical CAN only mode */
471}; 520};
472 521
473/* CAN FD mode nominal rate constants */ 522/* CAN FD mode nominal rate constants */
@@ -496,6 +545,19 @@ static const struct can_bittiming_const rcar_canfd_data_bittiming_const = {
496 .brp_inc = 1, 545 .brp_inc = 1,
497}; 546};
498 547
548/* Classical CAN mode bitrate constants */
549static const struct can_bittiming_const rcar_canfd_bittiming_const = {
550 .name = RCANFD_DRV_NAME,
551 .tseg1_min = 4,
552 .tseg1_max = 16,
553 .tseg2_min = 2,
554 .tseg2_max = 8,
555 .sjw_max = 4,
556 .brp_min = 1,
557 .brp_max = 1024,
558 .brp_inc = 1,
559};
560
499/* Helper functions */ 561/* Helper functions */
500static inline void rcar_canfd_update(u32 mask, u32 val, u32 __iomem *reg) 562static inline void rcar_canfd_update(u32 mask, u32 val, u32 __iomem *reg)
501{ 563{
@@ -593,8 +655,13 @@ static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv)
593 /* Reset Global error flags */ 655 /* Reset Global error flags */
594 rcar_canfd_write(gpriv->base, RCANFD_GERFL, 0x0); 656 rcar_canfd_write(gpriv->base, RCANFD_GERFL, 0x0);
595 657
596 /* Set the controller into FD mode */ 658 /* Set the controller into appropriate mode */
597 rcar_canfd_set_bit(gpriv->base, RCANFD_GRMCFG, RCANFD_GRMCFG_RCMC); 659 if (gpriv->fdmode)
660 rcar_canfd_set_bit(gpriv->base, RCANFD_GRMCFG,
661 RCANFD_GRMCFG_RCMC);
662 else
663 rcar_canfd_clear_bit(gpriv->base, RCANFD_GRMCFG,
664 RCANFD_GRMCFG_RCMC);
598 665
599 /* Transition all Channels to reset mode */ 666 /* Transition all Channels to reset mode */
600 for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) { 667 for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
@@ -624,8 +691,12 @@ static void rcar_canfd_configure_controller(struct rcar_canfd_global *gpriv)
624 691
625 /* Global configuration settings */ 692 /* Global configuration settings */
626 693
627 /* Truncate payload to configured message size RFPLS */ 694 /* ECC Error flag Enable */
628 cfg = RCANFD_GCFG_CMPOC; 695 cfg = RCANFD_GCFG_EEFE;
696
697 if (gpriv->fdmode)
698 /* Truncate payload to configured message size RFPLS */
699 cfg |= RCANFD_GCFG_CMPOC;
629 700
630 /* Set External Clock if selected */ 701 /* Set External Clock if selected */
631 if (gpriv->fcan != RCANFD_CANFDCLK) 702 if (gpriv->fcan != RCANFD_CANFDCLK)
@@ -647,7 +718,7 @@ static void rcar_canfd_configure_afl_rules(struct rcar_canfd_global *gpriv,
647 u32 ch) 718 u32 ch)
648{ 719{
649 u32 cfg; 720 u32 cfg;
650 int start, page, num_rules = RCANFD_CHANNEL_NUMRULES; 721 int offset, start, page, num_rules = RCANFD_CHANNEL_NUMRULES;
651 u32 ridx = ch + RCANFD_RFFIFO_IDX; 722 u32 ridx = ch + RCANFD_RFFIFO_IDX;
652 723
653 if (ch == 0) { 724 if (ch == 0) {
@@ -667,19 +738,19 @@ static void rcar_canfd_configure_afl_rules(struct rcar_canfd_global *gpriv,
667 /* Write number of rules for channel */ 738 /* Write number of rules for channel */
668 rcar_canfd_set_bit(gpriv->base, RCANFD_GAFLCFG0, 739 rcar_canfd_set_bit(gpriv->base, RCANFD_GAFLCFG0,
669 RCANFD_GAFLCFG_SETRNC(ch, num_rules)); 740 RCANFD_GAFLCFG_SETRNC(ch, num_rules));
741 if (gpriv->fdmode)
742 offset = RCANFD_F_GAFL_OFFSET;
743 else
744 offset = RCANFD_C_GAFL_OFFSET;
670 745
671 /* Accept all IDs */ 746 /* Accept all IDs */
672 rcar_canfd_write(gpriv->base, 747 rcar_canfd_write(gpriv->base, RCANFD_GAFLID(offset, start), 0);
673 RCANFD_GAFLID(RCANFD_F_GAFL_OFFSET, start), 0);
674 /* IDE or RTR is not considered for matching */ 748 /* IDE or RTR is not considered for matching */
675 rcar_canfd_write(gpriv->base, 749 rcar_canfd_write(gpriv->base, RCANFD_GAFLM(offset, start), 0);
676 RCANFD_GAFLM(RCANFD_F_GAFL_OFFSET, start), 0);
677 /* Any data length accepted */ 750 /* Any data length accepted */
678 rcar_canfd_write(gpriv->base, 751 rcar_canfd_write(gpriv->base, RCANFD_GAFLP0(offset, start), 0);
679 RCANFD_GAFLP0(RCANFD_F_GAFL_OFFSET, start), 0);
680 /* Place the msg in corresponding Rx FIFO entry */ 752 /* Place the msg in corresponding Rx FIFO entry */
681 rcar_canfd_write(gpriv->base, 753 rcar_canfd_write(gpriv->base, RCANFD_GAFLP1(offset, start),
682 RCANFD_GAFLP1(RCANFD_F_GAFL_OFFSET, start),
683 RCANFD_GAFLP1_GAFLFDP(ridx)); 754 RCANFD_GAFLP1_GAFLFDP(ridx));
684 755
685 /* Disable write access to page */ 756 /* Disable write access to page */
@@ -697,7 +768,10 @@ static void rcar_canfd_configure_rx(struct rcar_canfd_global *gpriv, u32 ch)
697 u32 ridx = ch + RCANFD_RFFIFO_IDX; 768 u32 ridx = ch + RCANFD_RFFIFO_IDX;
698 769
699 rfdc = 2; /* b010 - 8 messages Rx FIFO depth */ 770 rfdc = 2; /* b010 - 8 messages Rx FIFO depth */
700 rfpls = 7; /* b111 - Max 64 bytes payload */ 771 if (gpriv->fdmode)
772 rfpls = 7; /* b111 - Max 64 bytes payload */
773 else
774 rfpls = 0; /* b000 - Max 8 bytes payload */
701 775
702 cfg = (RCANFD_RFCC_RFIM | RCANFD_RFCC_RFDC(rfdc) | 776 cfg = (RCANFD_RFCC_RFIM | RCANFD_RFCC_RFDC(rfdc) |
703 RCANFD_RFCC_RFPLS(rfpls) | RCANFD_RFCC_RFIE); 777 RCANFD_RFCC_RFPLS(rfpls) | RCANFD_RFCC_RFIE);
@@ -718,16 +792,20 @@ static void rcar_canfd_configure_tx(struct rcar_canfd_global *gpriv, u32 ch)
718 cftml = 0; /* 0th buffer */ 792 cftml = 0; /* 0th buffer */
719 cfm = 1; /* b01 - Transmit mode */ 793 cfm = 1; /* b01 - Transmit mode */
720 cfdc = 2; /* b010 - 8 messages Tx FIFO depth */ 794 cfdc = 2; /* b010 - 8 messages Tx FIFO depth */
721 cfpls = 7; /* b111 - Max 64 bytes payload */ 795 if (gpriv->fdmode)
796 cfpls = 7; /* b111 - Max 64 bytes payload */
797 else
798 cfpls = 0; /* b000 - Max 8 bytes payload */
722 799
723 cfg = (RCANFD_CFCC_CFTML(cftml) | RCANFD_CFCC_CFM(cfm) | 800 cfg = (RCANFD_CFCC_CFTML(cftml) | RCANFD_CFCC_CFM(cfm) |
724 RCANFD_CFCC_CFIM | RCANFD_CFCC_CFDC(cfdc) | 801 RCANFD_CFCC_CFIM | RCANFD_CFCC_CFDC(cfdc) |
725 RCANFD_CFCC_CFPLS(cfpls) | RCANFD_CFCC_CFTXIE); 802 RCANFD_CFCC_CFPLS(cfpls) | RCANFD_CFCC_CFTXIE);
726 rcar_canfd_write(gpriv->base, RCANFD_CFCC(ch, RCANFD_CFFIFO_IDX), cfg); 803 rcar_canfd_write(gpriv->base, RCANFD_CFCC(ch, RCANFD_CFFIFO_IDX), cfg);
727 804
728 /* Clear FD mode specific control/status register */ 805 if (gpriv->fdmode)
729 rcar_canfd_write(gpriv->base, 806 /* Clear FD mode specific control/status register */
730 RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), 0); 807 rcar_canfd_write(gpriv->base,
808 RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), 0);
731} 809}
732 810
733static void rcar_canfd_enable_global_interrupts(struct rcar_canfd_global *gpriv) 811static void rcar_canfd_enable_global_interrupts(struct rcar_canfd_global *gpriv)
@@ -739,7 +817,8 @@ static void rcar_canfd_enable_global_interrupts(struct rcar_canfd_global *gpriv)
739 817
740 /* Global interrupts setup */ 818 /* Global interrupts setup */
741 ctr = RCANFD_GCTR_MEIE; 819 ctr = RCANFD_GCTR_MEIE;
742 ctr |= RCANFD_GCTR_CFMPOFIE; 820 if (gpriv->fdmode)
821 ctr |= RCANFD_GCTR_CFMPOFIE;
743 822
744 rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, ctr); 823 rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, ctr);
745} 824}
@@ -790,6 +869,7 @@ static void rcar_canfd_disable_channel_interrupts(struct rcar_canfd_channel
790static void rcar_canfd_global_error(struct net_device *ndev) 869static void rcar_canfd_global_error(struct net_device *ndev)
791{ 870{
792 struct rcar_canfd_channel *priv = netdev_priv(ndev); 871 struct rcar_canfd_channel *priv = netdev_priv(ndev);
872 struct rcar_canfd_global *gpriv = priv->gpriv;
793 struct net_device_stats *stats = &ndev->stats; 873 struct net_device_stats *stats = &ndev->stats;
794 u32 ch = priv->channel; 874 u32 ch = priv->channel;
795 u32 gerfl, sts; 875 u32 gerfl, sts;
@@ -823,7 +903,7 @@ static void rcar_canfd_global_error(struct net_device *ndev)
823 sts & ~RCANFD_RFSTS_RFMLT); 903 sts & ~RCANFD_RFSTS_RFMLT);
824 } 904 }
825 } 905 }
826 if (gerfl & RCANFD_GERFL_CMPOF) { 906 if (gpriv->fdmode && gerfl & RCANFD_GERFL_CMPOF) {
827 /* Message Lost flag will be set for respective channel 907 /* Message Lost flag will be set for respective channel
828 * when this condition happens with counters and flags 908 * when this condition happens with counters and flags
829 * already updated. 909 * already updated.
@@ -1018,7 +1098,7 @@ static irqreturn_t rcar_canfd_global_interrupt(int irq, void *dev_id)
1018 1098
1019 /* Global error interrupts */ 1099 /* Global error interrupts */
1020 gerfl = rcar_canfd_read(priv->base, RCANFD_GERFL); 1100 gerfl = rcar_canfd_read(priv->base, RCANFD_GERFL);
1021 if (RCANFD_GERFL_ERR(gerfl)) 1101 if (RCANFD_GERFL_ERR(gpriv, gerfl))
1022 rcar_canfd_global_error(ndev); 1102 rcar_canfd_global_error(ndev);
1023 1103
1024 /* Handle Rx interrupts */ 1104 /* Handle Rx interrupts */
@@ -1077,25 +1157,37 @@ static void rcar_canfd_set_bittiming(struct net_device *dev)
1077 tseg1 = bt->prop_seg + bt->phase_seg1 - 1; 1157 tseg1 = bt->prop_seg + bt->phase_seg1 - 1;
1078 tseg2 = bt->phase_seg2 - 1; 1158 tseg2 = bt->phase_seg2 - 1;
1079 1159
1080 cfg = (RCANFD_NCFG_NTSEG1(tseg1) | RCANFD_NCFG_NBRP(brp) | 1160 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1081 RCANFD_NCFG_NSJW(sjw) | RCANFD_NCFG_NTSEG2(tseg2)); 1161 /* CAN FD only mode */
1162 cfg = (RCANFD_NCFG_NTSEG1(tseg1) | RCANFD_NCFG_NBRP(brp) |
1163 RCANFD_NCFG_NSJW(sjw) | RCANFD_NCFG_NTSEG2(tseg2));
1082 1164
1083 rcar_canfd_write(priv->base, RCANFD_CCFG(ch), cfg); 1165 rcar_canfd_write(priv->base, RCANFD_CCFG(ch), cfg);
1084 netdev_dbg(priv->ndev, "nrate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n", 1166 netdev_dbg(priv->ndev, "nrate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
1085 brp, sjw, tseg1, tseg2); 1167 brp, sjw, tseg1, tseg2);
1086 1168
1087 /* Data bit timing settings */ 1169 /* Data bit timing settings */
1088 brp = dbt->brp - 1; 1170 brp = dbt->brp - 1;
1089 sjw = dbt->sjw - 1; 1171 sjw = dbt->sjw - 1;
1090 tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1; 1172 tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
1091 tseg2 = dbt->phase_seg2 - 1; 1173 tseg2 = dbt->phase_seg2 - 1;
1092 1174
1093 cfg = (RCANFD_DCFG_DTSEG1(tseg1) | RCANFD_DCFG_DBRP(brp) | 1175 cfg = (RCANFD_DCFG_DTSEG1(tseg1) | RCANFD_DCFG_DBRP(brp) |
1094 RCANFD_DCFG_DSJW(sjw) | RCANFD_DCFG_DTSEG2(tseg2)); 1176 RCANFD_DCFG_DSJW(sjw) | RCANFD_DCFG_DTSEG2(tseg2));
1095 1177
1096 rcar_canfd_write(priv->base, RCANFD_F_DCFG(ch), cfg); 1178 rcar_canfd_write(priv->base, RCANFD_F_DCFG(ch), cfg);
1097 netdev_dbg(priv->ndev, "drate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n", 1179 netdev_dbg(priv->ndev, "drate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
1098 brp, sjw, tseg1, tseg2); 1180 brp, sjw, tseg1, tseg2);
1181 } else {
1182 /* Classical CAN only mode */
1183 cfg = (RCANFD_CFG_TSEG1(tseg1) | RCANFD_CFG_BRP(brp) |
1184 RCANFD_CFG_SJW(sjw) | RCANFD_CFG_TSEG2(tseg2));
1185
1186 rcar_canfd_write(priv->base, RCANFD_CCFG(ch), cfg);
1187 netdev_dbg(priv->ndev,
1188 "rate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
1189 brp, sjw, tseg1, tseg2);
1190 }
1099} 1191}
1100 1192
1101static int rcar_canfd_start(struct net_device *ndev) 1193static int rcar_canfd_start(struct net_device *ndev)
@@ -1233,27 +1325,37 @@ static netdev_tx_t rcar_canfd_start_xmit(struct sk_buff *skb,
1233 if (cf->can_id & CAN_RTR_FLAG) 1325 if (cf->can_id & CAN_RTR_FLAG)
1234 id |= RCANFD_CFID_CFRTR; 1326 id |= RCANFD_CFID_CFRTR;
1235 1327
1236 rcar_canfd_write(priv->base,
1237 RCANFD_F_CFID(ch, RCANFD_CFFIFO_IDX), id);
1238 dlc = RCANFD_CFPTR_CFDLC(can_len2dlc(cf->len)); 1328 dlc = RCANFD_CFPTR_CFDLC(can_len2dlc(cf->len));
1239 rcar_canfd_write(priv->base,
1240 RCANFD_F_CFPTR(ch, RCANFD_CFFIFO_IDX), dlc);
1241 1329
1242 if (can_is_canfd_skb(skb)) { 1330 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1243 /* CAN FD frame format */ 1331 rcar_canfd_write(priv->base,
1244 sts |= RCANFD_CFFDCSTS_CFFDF; 1332 RCANFD_F_CFID(ch, RCANFD_CFFIFO_IDX), id);
1245 if (cf->flags & CANFD_BRS) 1333 rcar_canfd_write(priv->base,
1246 sts |= RCANFD_CFFDCSTS_CFBRS; 1334 RCANFD_F_CFPTR(ch, RCANFD_CFFIFO_IDX), dlc);
1247 1335
1248 if (priv->can.state == CAN_STATE_ERROR_PASSIVE) 1336 if (can_is_canfd_skb(skb)) {
1249 sts |= RCANFD_CFFDCSTS_CFESI; 1337 /* CAN FD frame format */
1250 } 1338 sts |= RCANFD_CFFDCSTS_CFFDF;
1339 if (cf->flags & CANFD_BRS)
1340 sts |= RCANFD_CFFDCSTS_CFBRS;
1251 1341
1252 rcar_canfd_write(priv->base, RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), 1342 if (priv->can.state == CAN_STATE_ERROR_PASSIVE)
1253 sts); 1343 sts |= RCANFD_CFFDCSTS_CFESI;
1344 }
1345
1346 rcar_canfd_write(priv->base,
1347 RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), sts);
1254 1348
1255 rcar_canfd_put_data(priv, cf, 1349 rcar_canfd_put_data(priv, cf,
1256 RCANFD_F_CFDF(ch, RCANFD_CFFIFO_IDX, 0)); 1350 RCANFD_F_CFDF(ch, RCANFD_CFFIFO_IDX, 0));
1351 } else {
1352 rcar_canfd_write(priv->base,
1353 RCANFD_C_CFID(ch, RCANFD_CFFIFO_IDX), id);
1354 rcar_canfd_write(priv->base,
1355 RCANFD_C_CFPTR(ch, RCANFD_CFFIFO_IDX), dlc);
1356 rcar_canfd_put_data(priv, cf,
1357 RCANFD_C_CFDF(ch, RCANFD_CFFIFO_IDX, 0));
1358 }
1257 1359
1258 priv->tx_len[priv->tx_head % RCANFD_FIFO_DEPTH] = cf->len; 1360 priv->tx_len[priv->tx_head % RCANFD_FIFO_DEPTH] = cf->len;
1259 can_put_echo_skb(skb, ndev, priv->tx_head % RCANFD_FIFO_DEPTH); 1361 can_put_echo_skb(skb, ndev, priv->tx_head % RCANFD_FIFO_DEPTH);
@@ -1280,47 +1382,61 @@ static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv)
1280 struct net_device_stats *stats = &priv->ndev->stats; 1382 struct net_device_stats *stats = &priv->ndev->stats;
1281 struct canfd_frame *cf; 1383 struct canfd_frame *cf;
1282 struct sk_buff *skb; 1384 struct sk_buff *skb;
1283 u32 sts = 0, id, ptr; 1385 u32 sts = 0, id, dlc;
1284 u32 ch = priv->channel; 1386 u32 ch = priv->channel;
1285 u32 ridx = ch + RCANFD_RFFIFO_IDX; 1387 u32 ridx = ch + RCANFD_RFFIFO_IDX;
1286 1388
1287 id = rcar_canfd_read(priv->base, RCANFD_F_RFID(ridx)); 1389 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1288 ptr = rcar_canfd_read(priv->base, RCANFD_F_RFPTR(ridx)); 1390 id = rcar_canfd_read(priv->base, RCANFD_F_RFID(ridx));
1391 dlc = rcar_canfd_read(priv->base, RCANFD_F_RFPTR(ridx));
1289 1392
1290 sts = rcar_canfd_read(priv->base, RCANFD_F_RFFDSTS(ridx)); 1393 sts = rcar_canfd_read(priv->base, RCANFD_F_RFFDSTS(ridx));
1291 if (sts & RCANFD_RFFDSTS_RFFDF) 1394 if (sts & RCANFD_RFFDSTS_RFFDF)
1292 skb = alloc_canfd_skb(priv->ndev, &cf); 1395 skb = alloc_canfd_skb(priv->ndev, &cf);
1293 else 1396 else
1294 skb = alloc_can_skb(priv->ndev, 1397 skb = alloc_can_skb(priv->ndev,
1295 (struct can_frame **)&cf); 1398 (struct can_frame **)&cf);
1399 } else {
1400 id = rcar_canfd_read(priv->base, RCANFD_C_RFID(ridx));
1401 dlc = rcar_canfd_read(priv->base, RCANFD_C_RFPTR(ridx));
1402 skb = alloc_can_skb(priv->ndev, (struct can_frame **)&cf);
1403 }
1296 1404
1297 if (!skb) { 1405 if (!skb) {
1298 stats->rx_dropped++; 1406 stats->rx_dropped++;
1299 return; 1407 return;
1300 } 1408 }
1301 1409
1302 if (sts & RCANFD_RFFDSTS_RFFDF)
1303 cf->len = can_dlc2len(RCANFD_RFPTR_RFDLC(ptr));
1304 else
1305 cf->len = get_can_dlc(RCANFD_RFPTR_RFDLC(ptr));
1306
1307 if (sts & RCANFD_RFFDSTS_RFESI) {
1308 cf->flags |= CANFD_ESI;
1309 netdev_dbg(priv->ndev, "ESI Error\n");
1310 }
1311
1312 if (id & RCANFD_RFID_RFIDE) 1410 if (id & RCANFD_RFID_RFIDE)
1313 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG; 1411 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
1314 else 1412 else
1315 cf->can_id = id & CAN_SFF_MASK; 1413 cf->can_id = id & CAN_SFF_MASK;
1316 1414
1317 if (!(sts & RCANFD_RFFDSTS_RFFDF) && (id & RCANFD_RFID_RFRTR)) { 1415 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1318 cf->can_id |= CAN_RTR_FLAG; 1416 if (sts & RCANFD_RFFDSTS_RFFDF)
1319 } else { 1417 cf->len = can_dlc2len(RCANFD_RFPTR_RFDLC(dlc));
1320 if (sts & RCANFD_RFFDSTS_RFBRS) 1418 else
1321 cf->flags |= CANFD_BRS; 1419 cf->len = get_can_dlc(RCANFD_RFPTR_RFDLC(dlc));
1420
1421 if (sts & RCANFD_RFFDSTS_RFESI) {
1422 cf->flags |= CANFD_ESI;
1423 netdev_dbg(priv->ndev, "ESI Error\n");
1424 }
1425
1426 if (!(sts & RCANFD_RFFDSTS_RFFDF) && (id & RCANFD_RFID_RFRTR)) {
1427 cf->can_id |= CAN_RTR_FLAG;
1428 } else {
1429 if (sts & RCANFD_RFFDSTS_RFBRS)
1430 cf->flags |= CANFD_BRS;
1322 1431
1323 rcar_canfd_get_data(priv, cf, RCANFD_F_RFDF(ridx, 0)); 1432 rcar_canfd_get_data(priv, cf, RCANFD_F_RFDF(ridx, 0));
1433 }
1434 } else {
1435 cf->len = get_can_dlc(RCANFD_RFPTR_RFDLC(dlc));
1436 if (id & RCANFD_RFID_RFRTR)
1437 cf->can_id |= CAN_RTR_FLAG;
1438 else
1439 rcar_canfd_get_data(priv, cf, RCANFD_C_RFDF(ridx, 0));
1324 } 1440 }
1325 1441
1326 /* Write 0xff to RFPC to increment the CPU-side 1442 /* Write 0xff to RFPC to increment the CPU-side
@@ -1428,13 +1544,19 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
1428 priv->can.clock.freq = fcan_freq; 1544 priv->can.clock.freq = fcan_freq;
1429 dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq); 1545 dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq);
1430 1546
1431 priv->can.bittiming_const = &rcar_canfd_nom_bittiming_const; 1547 if (gpriv->fdmode) {
1432 priv->can.data_bittiming_const = 1548 priv->can.bittiming_const = &rcar_canfd_nom_bittiming_const;
1433 &rcar_canfd_data_bittiming_const; 1549 priv->can.data_bittiming_const =
1550 &rcar_canfd_data_bittiming_const;
1434 1551
1435 /* Controller starts in CAN FD only mode */ 1552 /* Controller starts in CAN FD only mode */
1436 can_set_static_ctrlmode(ndev, CAN_CTRLMODE_FD); 1553 can_set_static_ctrlmode(ndev, CAN_CTRLMODE_FD);
1437 priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING; 1554 priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
1555 } else {
1556 /* Controller starts in Classical CAN only mode */
1557 priv->can.bittiming_const = &rcar_canfd_bittiming_const;
1558 priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
1559 }
1438 1560
1439 priv->can.do_set_mode = rcar_canfd_do_set_mode; 1561 priv->can.do_set_mode = rcar_canfd_do_set_mode;
1440 priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter; 1562 priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter;
@@ -1482,6 +1604,10 @@ static int rcar_canfd_probe(struct platform_device *pdev)
1482 struct device_node *of_child; 1604 struct device_node *of_child;
1483 unsigned long channels_mask = 0; 1605 unsigned long channels_mask = 0;
1484 int err, ch_irq, g_irq; 1606 int err, ch_irq, g_irq;
1607 bool fdmode = true; /* CAN FD only mode - default */
1608
1609 if (of_property_read_bool(pdev->dev.of_node, "renesas,no-can-fd"))
1610 fdmode = false; /* Classical CAN only mode */
1485 1611
1486 of_child = of_get_child_by_name(pdev->dev.of_node, "channel0"); 1612 of_child = of_get_child_by_name(pdev->dev.of_node, "channel0");
1487 if (of_child && of_device_is_available(of_child)) 1613 if (of_child && of_device_is_available(of_child))
@@ -1513,6 +1639,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
1513 } 1639 }
1514 gpriv->pdev = pdev; 1640 gpriv->pdev = pdev;
1515 gpriv->channels_mask = channels_mask; 1641 gpriv->channels_mask = channels_mask;
1642 gpriv->fdmode = fdmode;
1516 1643
1517 /* Peripheral clock */ 1644 /* Peripheral clock */
1518 gpriv->clkp = devm_clk_get(&pdev->dev, "fck"); 1645 gpriv->clkp = devm_clk_get(&pdev->dev, "fck");
@@ -1623,8 +1750,8 @@ static int rcar_canfd_probe(struct platform_device *pdev)
1623 } 1750 }
1624 1751
1625 platform_set_drvdata(pdev, gpriv); 1752 platform_set_drvdata(pdev, gpriv);
1626 dev_info(&pdev->dev, "global operational state (clk %d)\n", 1753 dev_info(&pdev->dev, "global operational state (clk %d, fdmode %d)\n",
1627 gpriv->fcan); 1754 gpriv->fcan, gpriv->fdmode);
1628 return 0; 1755 return 0;
1629 1756
1630fail_channel: 1757fail_channel: