1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2020 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de>
3 * Copyright (c) 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
6 #ifndef _CAN_BITTIMING_H
7 #define _CAN_BITTIMING_H
9 #include <linux/netdevice.h>
10 #include <linux/can/netlink.h>
12 #define CAN_SYNC_SEG 1
15 * struct can_tdc - CAN FD Transmission Delay Compensation parameters
17 * At high bit rates, the propagation delay from the TX pin to the RX
18 * pin of the transceiver causes measurement errors: the sample point
19 * on the RX pin might occur on the previous bit.
21 * To solve this issue, ISO 11898-1 introduces in section 11.3.3
22 * "Transmitter delay compensation" a SSP (Secondary Sample Point)
23 * equal to the distance, in time quanta, from the start of the bit
24 * time on the TX pin to the actual measurement on the RX pin.
26 * This structure contains the parameters to calculate that SSP.
28 * @tdcv: Transmitter Delay Compensation Value. Distance, in time
29 * quanta, from when the bit is sent on the TX pin to when it is
30 * received on the RX pin of the transmitter. Possible options:
32 * O: automatic mode. The controller dynamically measure @tdcv
33 * for each transmitted CAN FD frame.
35 * Other values: manual mode. Use the fixed provided value.
37 * @tdco: Transmitter Delay Compensation Offset. Offset value, in time
38 * quanta, defining the distance between the start of the bit
39 * reception on the RX pin of the transceiver and the SSP
40 * position such as SSP = @tdcv + @tdco.
42 * If @tdco is zero, then TDC is disabled and both @tdcv and
43 * @tdcf should be ignored.
45 * @tdcf: Transmitter Delay Compensation Filter window. Defines the
46 * minimum value for the SSP position in time quanta. If SSP is
47 * less than @tdcf, then no delay compensations occur and the
48 * normal sampling point is used instead. The feature is enabled
49 * if and only if @tdcv is set to zero (automatic mode) and @tdcf
50 * is configured to a value greater than @tdco.
59 * struct can_tdc_const - CAN hardware-dependent constant for
60 * Transmission Delay Compensation
62 * @tdcv_max: Transmitter Delay Compensation Value maximum value.
63 * Should be set to zero if the controller does not support
64 * manual mode for tdcv.
65 * @tdco_max: Transmitter Delay Compensation Offset maximum value.
66 * Should not be zero. If the controller does not support TDC,
67 * then the pointer to this structure should be NULL.
68 * @tdcf_max: Transmitter Delay Compensation Filter window maximum
69 * value. Should be set to zero if the controller does not
70 * support this feature.
72 struct can_tdc_const {
78 #ifdef CONFIG_CAN_CALC_BITTIMING
79 int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
80 const struct can_bittiming_const *btc);
82 void can_calc_tdco(struct net_device *dev);
83 #else /* !CONFIG_CAN_CALC_BITTIMING */
85 can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
86 const struct can_bittiming_const *btc)
88 netdev_err(dev, "bit-timing calculation not available\n");
92 static inline void can_calc_tdco(struct net_device *dev)
95 #endif /* CONFIG_CAN_CALC_BITTIMING */
97 int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
98 const struct can_bittiming_const *btc,
99 const u32 *bitrate_const,
100 const unsigned int bitrate_const_cnt);
103 * can_bit_time() - Duration of one bit
105 * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
106 * additional information.
108 * Return: the number of time quanta in one bit.
110 static inline unsigned int can_bit_time(const struct can_bittiming *bt)
112 return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2;
115 #endif /* !_CAN_BITTIMING_H */