Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ramesh Shanmugasundaram and committed by
Marc Kleine-Budde
6f4c2eea 2781ff5c

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