1 /* SPDX-License-Identifier: GPL-2.0-only */
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 /* Kilobits and Megabits per second */
16 #define CAN_KBPS 1000UL
17 #define CAN_MBPS 1000000UL
20 #define CAN_MHZ 1000000UL
23 * struct can_tdc - CAN FD Transmission Delay Compensation parameters
25 * At high bit rates, the propagation delay from the TX pin to the RX
26 * pin of the transceiver causes measurement errors: the sample point
27 * on the RX pin might occur on the previous bit.
29 * To solve this issue, ISO 11898-1 introduces in section 11.3.3
30 * "Transmitter delay compensation" a SSP (Secondary Sample Point)
31 * equal to the distance, in time quanta, from the start of the bit
32 * time on the TX pin to the actual measurement on the RX pin.
34 * This structure contains the parameters to calculate that SSP.
36 * @tdcv: Transmitter Delay Compensation Value. Distance, in time
37 * quanta, from when the bit is sent on the TX pin to when it is
38 * received on the RX pin of the transmitter. Possible options:
40 * O: automatic mode. The controller dynamically measure @tdcv
41 * for each transmitted CAN FD frame.
43 * Other values: manual mode. Use the fixed provided value.
45 * @tdco: Transmitter Delay Compensation Offset. Offset value, in time
46 * quanta, defining the distance between the start of the bit
47 * reception on the RX pin of the transceiver and the SSP
48 * position such as SSP = @tdcv + @tdco.
50 * If @tdco is zero, then TDC is disabled and both @tdcv and
51 * @tdcf should be ignored.
53 * @tdcf: Transmitter Delay Compensation Filter window. Defines the
54 * minimum value for the SSP position in time quanta. If SSP is
55 * less than @tdcf, then no delay compensations occur and the
56 * normal sampling point is used instead. The feature is enabled
57 * if and only if @tdcv is set to zero (automatic mode) and @tdcf
58 * is configured to a value greater than @tdco.
67 * struct can_tdc_const - CAN hardware-dependent constant for
68 * Transmission Delay Compensation
70 * @tdcv_max: Transmitter Delay Compensation Value maximum value.
71 * Should be set to zero if the controller does not support
72 * manual mode for tdcv.
73 * @tdco_max: Transmitter Delay Compensation Offset maximum value.
74 * Should not be zero. If the controller does not support TDC,
75 * then the pointer to this structure should be NULL.
76 * @tdcf_max: Transmitter Delay Compensation Filter window maximum
77 * value. Should be set to zero if the controller does not
78 * support this feature.
80 struct can_tdc_const {
86 #ifdef CONFIG_CAN_CALC_BITTIMING
87 int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
88 const struct can_bittiming_const *btc);
90 void can_calc_tdco(struct net_device *dev);
91 #else /* !CONFIG_CAN_CALC_BITTIMING */
93 can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
94 const struct can_bittiming_const *btc)
96 netdev_err(dev, "bit-timing calculation not available\n");
100 static inline void can_calc_tdco(struct net_device *dev)
103 #endif /* CONFIG_CAN_CALC_BITTIMING */
105 int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
106 const struct can_bittiming_const *btc,
107 const u32 *bitrate_const,
108 const unsigned int bitrate_const_cnt);
111 * can_bit_time() - Duration of one bit
113 * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
114 * additional information.
116 * Return: the number of time quanta in one bit.
118 static inline unsigned int can_bit_time(const struct can_bittiming *bt)
120 return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2;
123 #endif /* !_CAN_BITTIMING_H */