All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: kernel@pengutronix.de, michael@walle.cc, qiangqing.zhang@nxp.com,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 16/20] can: flexcan: add ISO CAN FD feature support
Date: Tue, 22 Sep 2020 16:44:25 +0200	[thread overview]
Message-ID: <20200922144429.2613631-17-mkl@pengutronix.de> (raw)
In-Reply-To: <20200922144429.2613631-1-mkl@pengutronix.de>

From: Joakim Zhang <qiangqing.zhang@nxp.com>

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.

NOTE: If you only set "fd on", driver will use ISO FD mode by default.
You should set "fd-non-iso on" after setting "fd on" if you want to use
NON ISO FD mode.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Link: https://lore.kernel.org/r/20190712075926.7357-6-qiangqing.zhang@nxp.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 8dca553fa545..e3ecce80eadb 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -94,6 +94,7 @@
 #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)
@@ -1165,7 +1166,7 @@ static void flexcan_set_bittiming_cbt(const struct net_device *dev)
 	priv->write(reg_cbt, &regs->cbt);
 
 	if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
-		u32 reg_fdcbt;
+		u32 reg_fdcbt, reg_ctrl2;
 
 		if (bt->brp != dbt->brp)
 			netdev_warn(dev, "Data brp=%d and brp=%d don't match, this may result in a phase error. Consider using different bitrate and/or data bitrate.\n",
@@ -1184,7 +1185,14 @@ static void flexcan_set_bittiming_cbt(const struct net_device *dev)
 			dbt->phase_seg1 = 0x8;
 		}
 
-		reg_fdcbt = FIELD_PREP(FLEXCAN_FDCBT_FPRESDIV_MASK, dbt->brp - 1) |
+		reg_fdcbt = priv->read(&regs->fdcbt);
+		reg_fdcbt &= ~(FIELD_PREP(FLEXCAN_FDCBT_FPRESDIV_MASK, 0x3ff) |
+			       FIELD_PREP(FLEXCAN_FDCBT_FRJW_MASK, 0x7) |
+			       FIELD_PREP(FLEXCAN_FDCBT_FPROPSEG_MASK, 0x1f) |
+			       FIELD_PREP(FLEXCAN_FDCBT_FPSEG1_MASK, 0x7) |
+			       FIELD_PREP(FLEXCAN_FDCBT_FPSEG2_MASK, 0x7));
+
+		reg_fdcbt |= FIELD_PREP(FLEXCAN_FDCBT_FPRESDIV_MASK, dbt->brp - 1) |
 			FIELD_PREP(FLEXCAN_FDCBT_FRJW_MASK, dbt->sjw - 1) |
 			FIELD_PREP(FLEXCAN_FDCBT_FPROPSEG_MASK, dbt->prop_seg) |
 			FIELD_PREP(FLEXCAN_FDCBT_FPSEG1_MASK, dbt->phase_seg1 - 1) |
@@ -1192,6 +1200,15 @@ static void flexcan_set_bittiming_cbt(const struct net_device *dev)
 
 		netdev_dbg(dev, "writing fdcbt=0x%08x\n", reg_fdcbt);
 		priv->write(reg_fdcbt, &regs->fdcbt);
+
+		/* CTRL2 */
+		reg_ctrl2 = priv->read(&regs->ctrl2);
+		reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;
+		if (!(priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO))
+			reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
+
+		netdev_dbg(dev, "writing ctrl2=0x%08x\n", reg_ctrl2);
+		priv->write(reg_ctrl2, &regs->ctrl2);
 	}
 
 	/* FDCTRL */
@@ -1204,11 +1221,11 @@ static void flexcan_set_bittiming_cbt(const struct net_device *dev)
 	netdev_dbg(dev, "writing fdctrl=0x%08x\n", reg_fdctrl);
 	priv->write(reg_fdctrl, &regs->fdctrl);
 
-	netdev_dbg(dev, "%s: mcr=0x%08x ctrl=0x%08x fdctrl=0x%08x cbt=0x%08x fdcbt=0x%08x\n",
+	netdev_dbg(dev, "%s: mcr=0x%08x ctrl=0x%08x ctrl2=0x%08x fdctrl=0x%08x cbt=0x%08x fdcbt=0x%08x\n",
 		   __func__,
 		   priv->read(&regs->mcr), priv->read(&regs->ctrl),
-		   priv->read(&regs->fdctrl), priv->read(&regs->cbt),
-		   priv->read(&regs->fdcbt));
+		   priv->read(&regs->ctrl2), priv->read(&regs->fdctrl),
+		   priv->read(&regs->cbt), priv->read(&regs->fdcbt));
 }
 
 static void flexcan_set_bittiming(struct net_device *dev)
@@ -1911,7 +1928,8 @@ static int flexcan_probe(struct platform_device *pdev)
 	priv->reg_xceiver = reg_xceiver;
 
 	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_FD) {
-		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->can.data_bittiming_const =
 			&flexcan_fd_data_bittiming_const;
-- 
2.28.0


  parent reply	other threads:[~2020-09-22 14:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 14:44 [RFC]: flexcan FD support - can-next 2020-09-22 Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 01/20] can: flexcan: sort include files alphabetically Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 02/20] can: flexcan: flexcan_exit_stop_mode(): remove stray empty line Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 03/20] can: flexcan: more register names Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 04/20] can: flexcan: struct flexcan_regs: document registers not affected by soft reset Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 05/20] can: flexcan: quirks: get rid of long lines Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 06/20] can: flexcan: Ack wakeup interrupt separately Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 07/20] can: flexcan: flexcan_probe(): make regulator xceiver optional Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 08/20] can: flexcan: Add check for transceiver maximum bitrate limitation Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 09/20] can: flexcan: add correctable errors correction when HW supports ECC Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 10/20] can: flexcan: flexcan_chip_stop(): add error handling and propagate error value Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 11/20] can: flexcan: disable clocks during stop mode Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 12/20] can: flexcan: add LPSR mode support Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 13/20] can: flexcan: flexcan_set_bittiming(): move setup of CAN-2.0 bitiming into separate function Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 14/20] can: flexcan: use struct canfd_frame for CAN classic frame Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 15/20] can: flexcan: add CAN-FD mode support Marc Kleine-Budde
2020-09-22 14:44 ` Marc Kleine-Budde [this message]
2020-09-22 14:44 ` [PATCH 17/20] can: flexcan: add CAN FD BRS support Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 18/20] can: flexcan: add Transceiver Delay Compensation support Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 19/20] can: flexcan: add imx8qm support Marc Kleine-Budde
2020-09-22 14:44 ` [PATCH 20/20] can: flexcan: add lx2160ar1 support Marc Kleine-Budde
2020-09-23  7:45   ` Michael Walle
2020-09-23  7:54     ` Marc Kleine-Budde
2020-09-23  8:02       ` Michael Walle
2020-09-23  8:10         ` Marc Kleine-Budde
2020-09-23  8:31           ` Joakim Zhang
2020-09-23  8:58             ` Marc Kleine-Budde
2020-09-23  9:38               ` Michael Walle
2020-09-23  9:50               ` Joakim Zhang
2020-09-23  8:53 pull-request: can-next 2020-09-23 Marc Kleine-Budde
2020-09-23  8:54 ` [PATCH 16/20] can: flexcan: add ISO CAN FD feature support Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200922144429.2613631-17-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=qiangqing.zhang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.