MLK-21412 can: flexcan: add ISO CAN FD feature support
authorJoakim Zhang <qiangqing.zhang@nxp.com>
Mon, 8 Apr 2019 04:56:35 +0000 (12:56 +0800)
committerJoakim Zhang <qiangqing.zhang@nxp.com>
Thu, 18 Apr 2019 09:16:19 +0000 (17:16 +0800)
ISO CAN FD is introduced to increase the failture detection capability
than non-ISO CAN FD. The non-ISO CAN FD is still supported by FlexCAN so
that it can be used mainly during an intermediate phase, for evaluation
and development purposes.

Therefore, it is strongly recommended to configure FlexCAN to the ISO
CAN FD protocol by setting the ISOCANFDEN field in the CTRL2 register.

Test Command:
ISO FD MODE:
ip link set can0 type can bitrate 1000000 dbitrate 4000000 fd on
fd-non-iso off

non-ISO FD MODE:
ip link set can0 type can bitrate 1000000 dbitrate 4000000 fd on
fd-non-iso on

NOTE: if you only set fd on, driver will use ISO FD MODE by default.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
drivers/net/can/flexcan.c

index f59c207..2de17d9 100644 (file)
 #define FLEXCAN_CTRL2_MRP              BIT(18)
 #define FLEXCAN_CTRL2_RRS              BIT(17)
 #define FLEXCAN_CTRL2_EACEN            BIT(16)
+#define FLEXCAN_CTRL2_ISOCANFDEN       BIT(12)
 
 /* FLEXCAN memory error control register (MECR) bits */
 #define FLEXCAN_MECR_ECRWRDIS          BIT(31)
@@ -1364,6 +1365,11 @@ static int flexcan_chip_start(struct net_device *dev)
                reg_mcr = flexcan_read_le(&regs->mcr);
                flexcan_write_le(reg_mcr | FLEXCAN_MCR_FDEN, &regs->mcr);
 
+               if (!(priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)) {
+                       reg_ctrl2 = priv->read(&regs->ctrl2);
+                       priv->write(reg_ctrl2 | FLEXCAN_CTRL2_ISOCANFDEN, &regs->ctrl2);
+               }
+
                priv->mb_size = FLEXCAN_MB_FD_SIZE;
                priv->mb_num = FLEXCAN_MB_FD_NUM;
        } else {
@@ -1828,7 +1834,7 @@ static int flexcan_probe(struct platform_device *pdev)
        if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
                if (priv->devtype_data->quirks & FLEXCAN_QUIRK_TIMESTAMP_SUPPORT_FD) {
                        if (!(of_find_property(np, "disable-fd-mode", NULL))) {
-                               priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
+                               priv->can.ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO;
                                priv->can.bittiming_const = &flexcan_fd_bittiming_const;
                                priv->offload.is_canfd = true;
                        }