Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp590144pxb; Sat, 18 Sep 2021 11:26:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvgR++Adej+j9yahHxUKe+4nE5JOra+b4qF7OzojUy+7X/ZrOqwkPXCFuhGhqJQPau1AxN X-Received: by 2002:a5e:da01:: with SMTP id x1mr13487872ioj.43.1631989571053; Sat, 18 Sep 2021 11:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631989571; cv=none; d=google.com; s=arc-20160816; b=HG24AKIqrvhpr69UEUldusmblrJbF8xusApQOkMvQ/+R0kaxM9OSxoIN7tZ6lcaMRW kQ9selRhWY7rbq9IZy8qX/Epo/7QUbi7Y9BNxRo/R9A2fZ7eaaWIVaP+AaDImlpwQ1ko uMvfRA8VAz9eQ+LZPNVwNINFkRXjhPEp9hxMAjucCzJjYT5+wiQw5r7dVQL1vIu8tsE6 tYam+ya9G97s4p7x2qIW74dd9gpX3btio6+RaBvTHwQkAoWPFLfvRYUH++s6JaPHLKIH URqLdGtQCIOM/97AODI8BBgrDUSXxn/9mEEejqccZem3MTJx3OXeL39iuS8DCkU/UofQ WpoA== 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=Gd5mZCYQZUHW2uYIpgwr8exs0sDqCLoTkTQ3VKWDtv4=; b=hB8wJwvxZ9H9mvbNGwDxYo3PnEGiYHa98mJwUpLow9jwpl+r9XPKeSewrQ2ZXtHeKV zku5snh0aqxc4LXaw5REPvqyokHDvdVlzi584Fqo8zSWAL2xeaN+sVrN8GokbTAIE32O ZuzwZAJcvVu+2mgFBrgvEdLoQdBGfGFOXudkzGwSqrCQApjtAD0wKv/IKc0UkwlHnifE WD01xeyN5/LHwbOt8VCYaRMuAyHIkyEMgJTPjfkzHhnz0zp5ecrTbmz4hT2odfhy1ten cOV+z8LZd+zn4Dg8IK2daPHyuKxSOI1Dg+CtKJ9QBiFXHhaIZFDzvus1yueos1yclGxm M7RA== 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 r195si8746165ior.17.2021.09.18.11.26.00; Sat, 18 Sep 2021 11:26:11 -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 S244998AbhIRJ75 (ORCPT + 99 others); Sat, 18 Sep 2021 05:59:57 -0400 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:54826 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244994AbhIRJ7b (ORCPT ); Sat, 18 Sep 2021 05:59:31 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id RX5Zmuh4X1yYBRX6im0kJV; Sat, 18 Sep 2021 11:58:07 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Sat, 18 Sep 2021 11:58:07 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Stefan=20M=C3=A4tje?= , Vincent Mailhol Subject: [PATCH v6 6/6] can: dev: add can_tdc_get_relative_tdco() helper function Date: Sat, 18 Sep 2021 18:56:37 +0900 Message-Id: <20210918095637.20108-7-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210918095637.20108-1-mailhol.vincent@wanadoo.fr> References: <20210918095637.20108-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 --- Hi Marc, As Stefan pointed out in: https://lore.kernel.org/linux-can/79691916e4280970f583a54cd5010ece025a1c53.c amel@esd.eu/ it seems that no so many CAN devices are using the relative TDCO (maybe the ESDACC is the only one?). Depending on the output of your discussion with Microchip and if the mcp25xxfd is indeed using an absolute tdco, it might make sense to drop this patch from the series. Yours sincerely, Vincent --- 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 b4aa0f048cab..45f19d9db5ca 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -102,6 +102,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.32.0