Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp687187pxy; Sat, 14 Aug 2021 20:37:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyae9vuF95D8+0zQ01jwWVgS9XDKS4q5VKt3xK1NKZ0r1H9PpfxTDLvbnfV3LxSuxmdqiv3 X-Received: by 2002:a05:6402:2288:: with SMTP id cw8mr12101423edb.216.1628998672858; Sat, 14 Aug 2021 20:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628998672; cv=none; d=google.com; s=arc-20160816; b=iIPHsTTeEpovmVMgY5CslZiYQgqPXvvRepXyaHPuZiVmidfkuhl+82/i9Iym+0M2k9 niGpHTpjaBA7m6s+YTVkUsmUeUT9ykdGs32tBvfu8l7X3aETonsTpnFf1NrVABTBEi+M dZ+pNZ0nk1IkXE7Gk2cq+5xx/qgXRQ7ZmWO1EwvpzhsHLvGuQDXbeW+gzUoNwolCXSDo w4QuLWD/Wm52+VAnwgFe4nawVSL8+kfHTG79Cfq/KtUvvLq21L2OfjP4w+1vRXOsV3ar pb93deeL4OrFfy8yRLuIgvkB32CojQQkDR/8TX5sWQPubh0WYiScFBRbPOmawObk9R9S dp5A== 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=YMvCqLYhPXbO9Ee13yU4I6Rcuy/n/szJthDVBPInnY3DeJto1qdZFdSY5xT+Yl3jNS FnJv+9Vip0fQsAxSbUWoaWS+gFWLTMhotjamMz3mRyM7YiYi7ixXlHAV2mFiZeVigAzT 2d1CLxSO9DZlrDpMTnaXcg/tmDYbxQRI8WBJxDrwU94rUVbEvXdfvwdlkJFjRYp89dIz egjoNryM/EXnZ3I4D3sp3PhvcGRRigdgZNiVEVOo4/cMhwIXshmCUUKVVhvwGiiy/mER WZ81qxTxj5Mkkt4tVFGGQ5SwSK6X60NzZEVRuQjZPA/XouUowcK+VMpC/mISKcVkZPvs CWlw== 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 i18si7252754edc.336.2021.08.14.20.37.29; Sat, 14 Aug 2021 20:37:52 -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 S236223AbhHODec (ORCPT + 99 others); Sat, 14 Aug 2021 23:34:32 -0400 Received: from smtp11.smtpout.orange.fr ([80.12.242.133]:38681 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236284AbhHODea (ORCPT ); Sat, 14 Aug 2021 23:34:30 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by mwinf5d21 with ME id hfZ7250050zjR6y03fZyy5; Sun, 15 Aug 2021 05:34:00 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: bWFpbGhvbC52aW5jZW50QHdhbmFkb28uZnI= X-ME-Date: Sun, 15 Aug 2021 05:34:00 +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 v5 4/7] can: dev: add can_tdc_get_relative_tdco() helper function Date: Sun, 15 Aug 2021 12:32:45 +0900 Message-Id: <20210815033248.98111-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210815033248.98111-1-mailhol.vincent@wanadoo.fr> References: <20210815033248.98111-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