Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp124510pxy; Sat, 14 Aug 2021 02:21:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMgBXia2yQdrFWlXICTbGok4kVNAvtjg88EjkXytWJdTR/nAX688wxurIHYDiBUr2Pbiqc X-Received: by 2002:a5d:824e:: with SMTP id n14mr5063100ioo.134.1628932883816; Sat, 14 Aug 2021 02:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628932883; cv=none; d=google.com; s=arc-20160816; b=F3NS9FTC7h6oCuiQDFdi9O+CkRdlmzNL/4KFVysIoiPRIKrEjCSUpiyveFv4L29wfP dz0VmCMxmOviqe1lOdI43ak1laPPFlDmUVNnz4EAJRPTNvlGLDsfM15KG/ajmALCMnWn N8Nxg2dVPlmuxqAJmZT0FZf2EHIkBmRtxncms1cmYtFLbemko2c8/xWtE1Vq0ExXfKkF RZmf8KDGo1MJGrEnDBXMcnEy00uVQXPvbNdmkSI1Ye9pq72DIr8F6vipTBPnFy1dxo8O 1ixNgSOOoka8soiokMlhDjW2LSufjCcuaTlIelGqLbrc15nSWWdUD7syoBGED5U/AqHT EB6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jz+A7FpaYd7cmrQvV3d6metv4m5Tx2phdSm6EBDQ/mM=; b=Lo5fSA16dQurYqrndg2nN4l86wa+GB76P9a0vdwpAUuPCfJi74NZdj6ouVd3OphiFQ B4FpQ6SIRelYjrLZFFyogbTgkr8oLjs0y/fVDy4zlBKmF83BbaAyirCond0nPWutOku9 PlSsI52wCACy3baMzMgjxztSATzEM2MnB9dn0Gxot0FmoIZtNKmPL1nmPYG/yNMC7Orc HoSigD3kf8QAI6ZmqLqYIBkGTA/l7/tR2KXR+9yR7y5Vxm5HnT2ljKYmal+nuVTSNLMo Ql1VDyK5oESACM6x8YjLii3UQP3dnC1+Kj6hzmXq7heSHK5lG/v362XQJ7KgnpOeGhzr rqYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si4352378iol.59.2021.08.14.02.21.13; Sat, 14 Aug 2021 02:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237861AbhHNJUY (ORCPT + 99 others); Sat, 14 Aug 2021 05:20:24 -0400 Received: from smtp03.smtpout.orange.fr ([80.12.242.125]:48190 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237860AbhHNJUT (ORCPT ); Sat, 14 Aug 2021 05:20:19 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by mwinf5d19 with ME id hMJz250060zjR6y03MKolq; Sat, 14 Aug 2021 11:19:50 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: bWFpbGhvbC52aW5jZW50QHdhbmFkb28uZnI= X-ME-Date: Sat, 14 Aug 2021 11:19:50 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: =?UTF-8?q?Stefan=20M=C3=A4tje?= , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 4/7] can: dev: add can_tdc_get_relative_tdco() helper function Date: Sat, 14 Aug 2021 18:17:47 +0900 Message-Id: <20210814091750.73931-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210814091750.73931-1-mailhol.vincent@wanadoo.fr> References: <20210814091750.73931-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct can_tdc::tdco represents the absolute offset from TDCV. Some controllers use instead an offset relative to the Sample Point (SP) such that: | SSP = TDCV + absolute TDCO | = TDCV + SP + relative TDCO Consequently: | relative TDCO = absolute TDCO - SP The function can_tdc_get_relative_tdco() allow to retrieve this relative TDCO value. CC: Stefan Mätje Signed-off-by: Vincent Mailhol --- include/linux/can/dev.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 0be982fd22fb..fa75e29182a3 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -93,6 +93,35 @@ static inline bool can_tdc_is_enabled(const struct can_priv *priv) return !!(priv->ctrlmode & CAN_CTRLMODE_TDC_MASK); } +/* + * can_get_relative_tdco() - TDCO relative to the sample point + * + * struct can_tdc::tdco represents the absolute offset from TDCV. Some + * controllers use instead an offset relative to the Sample Point (SP) + * such that: + * + * SSP = TDCV + absolute TDCO + * = TDCV + SP + relative TDCO + * + * -+----------- one bit ----------+-- TX pin + * |<--- Sample Point --->| + * + * --+----------- one bit ----------+-- RX pin + * |<-------- TDCV -------->| + * |<------------------------>| absolute TDCO + * |<--- Sample Point --->| + * | |<->| relative TDCO + * |<------------- Secondary Sample Point ------------>| + */ +static inline s32 can_get_relative_tdco(const struct can_priv *priv) +{ + const struct can_bittiming *dbt = &priv->data_bittiming; + s32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg + + dbt->phase_seg1) * dbt->brp; + + return (s32)priv->tdc.tdco - sample_point_in_tc; +} + /* helper to define static CAN controller features at device creation time */ static inline void can_set_static_ctrlmode(struct net_device *dev, u32 static_mode) -- 2.31.1