Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DB06236437 for ; Wed, 26 Nov 2025 12:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764158495; cv=none; b=P79SlCY3FZJ5uYk7Pzoh+Uhs9QbiodJ7XHKMuVx4PuwFEfnMbq1fmNkCAYSpdTvjHu2sFflnr64KionWwrNIxBII9DOC0C/OyfkB7mtj+Bt1L/dAViVWxGAnpL/vG8SxhE43tiO2PV84wDfqu8V7188Y8qyQ/oIxvVWIFDIWsNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764158495; c=relaxed/simple; bh=Y6gkgFCyJ7mlx+2AT4QZ1M7yvI5edBOG9qAOAgMkrLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H993rLAz8Zpwi2YrKaHDCYlO9+ROVFTyOPB392q2+5xQhsvro9nUv26ry4pEL7PioaHf9527yl4kQQ/K8ZtpbP2XsDs+1psMMvdrxRgxMuOoSgprBNZxOrlegB0cFR40S2la59S9T5i/pJ79sjyfbvsOvLEwYb4FIt46K8x6RVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vOECt-0004TD-2G; Wed, 26 Nov 2025 13:01:11 +0100 Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOECs-002bEf-1i; Wed, 26 Nov 2025 13:01:10 +0100 Received: from blackshift.org (p54b152ce.dip0.t-ipconnect.de [84.177.82.206]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 481DC4A8A98; Wed, 26 Nov 2025 12:01:10 +0000 (UTC) From: Marc Kleine-Budde To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org, kernel@pengutronix.de, Vincent Mailhol , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH net-next 13/27] can: calc_bittiming: add can_calc_sample_point_nrz() Date: Wed, 26 Nov 2025 12:57:02 +0100 Message-ID: <20251126120106.154635-14-mkl@pengutronix.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251126120106.154635-1-mkl@pengutronix.de> References: <20251126120106.154635-1-mkl@pengutronix.de> Precedence: bulk X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-can@vger.kernel.org From: Vincent Mailhol CAN XL optimal sample point for PWM encoding (when TMS is on) differs from the NRZ optimal one. There is thus a need to calculate a different sample point depending whether TMS is on or off. This is a preparation change: move the sample point calculation from can_calc_bittiming() into the new can_calc_sample_point_nrz() function. In an upcoming change, a function will be added to calculate the sample point for PWM encoding. Signed-off-by: Vincent Mailhol Signed-off-by: Oliver Hartkopp Link: https://patch.msgid.link/20251126-canxl-v8-13-e7e3eb74f889@pengutronix.de Signed-off-by: Marc Kleine-Budde --- drivers/net/can/dev/calc_bittiming.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c index c8c166b383cd..bacdf3b218d3 100644 --- a/drivers/net/can/dev/calc_bittiming.c +++ b/drivers/net/can/dev/calc_bittiming.c @@ -10,6 +10,18 @@ #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ +/* CiA recommended sample points for Non Return to Zero encoding. */ +static int can_calc_sample_point_nrz(const struct can_bittiming *bt) +{ + if (bt->bitrate > 800 * KILO /* BPS */) + return 750; + + if (bt->bitrate > 500 * KILO /* BPS */) + return 800; + + return 875; +} + /* Bit-timing calculation derived from: * * Code based on LinCAN sources and H8S2638 project @@ -79,17 +91,10 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, u64 v64; int err; - /* Use CiA recommended sample points */ - if (bt->sample_point) { + if (bt->sample_point) sample_point_reference = bt->sample_point; - } else { - if (bt->bitrate > 800 * KILO /* BPS */) - sample_point_reference = 750; - else if (bt->bitrate > 500 * KILO /* BPS */) - sample_point_reference = 800; - else - sample_point_reference = 875; - } + else + sample_point_reference = can_calc_sample_point_nrz(bt); /* tseg even = round down, odd = round up */ for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1; -- 2.51.0