1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (c) 2020 Pengutronix, Marc Kleine 2 /* Copyright (c) 2020 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> 3 * Copyright (c) 2021 Vincent Mailhol <mailhol 3 * Copyright (c) 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr> 4 */ 4 */ 5 5 6 #ifndef _CAN_BITTIMING_H 6 #ifndef _CAN_BITTIMING_H 7 #define _CAN_BITTIMING_H 7 #define _CAN_BITTIMING_H 8 8 9 #include <linux/netdevice.h> 9 #include <linux/netdevice.h> 10 #include <linux/can/netlink.h> 10 #include <linux/can/netlink.h> 11 11 12 #define CAN_SYNC_SEG 1 12 #define CAN_SYNC_SEG 1 13 13 14 #define CAN_BITRATE_UNSET 0 << 15 #define CAN_BITRATE_UNKNOWN (-1U) << 16 14 17 #define CAN_CTRLMODE_TDC_MASK !! 15 /* Kilobits and Megabits per second */ 18 (CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_ !! 16 #define CAN_KBPS 1000UL >> 17 #define CAN_MBPS 1000000UL >> 18 >> 19 /* Megahertz */ >> 20 #define CAN_MHZ 1000000UL 19 21 20 /* 22 /* 21 * struct can_tdc - CAN FD Transmission Delay 23 * struct can_tdc - CAN FD Transmission Delay Compensation parameters 22 * 24 * 23 * At high bit rates, the propagation delay fr 25 * At high bit rates, the propagation delay from the TX pin to the RX 24 * pin of the transceiver causes measurement e 26 * pin of the transceiver causes measurement errors: the sample point 25 * on the RX pin might occur on the previous b 27 * on the RX pin might occur on the previous bit. 26 * 28 * 27 * To solve this issue, ISO 11898-1 introduces 29 * To solve this issue, ISO 11898-1 introduces in section 11.3.3 28 * "Transmitter delay compensation" a SSP (Sec 30 * "Transmitter delay compensation" a SSP (Secondary Sample Point) 29 * equal to the distance from the start of the !! 31 * equal to the distance, in time quanta, from the start of the bit 30 * to the actual measurement on the RX pin. !! 32 * time on the TX pin to the actual measurement on the RX pin. 31 * 33 * 32 * This structure contains the parameters to c 34 * This structure contains the parameters to calculate that SSP. 33 * 35 * 34 * -+----------- one bit ----------+-- TX pin !! 36 * @tdcv: Transmitter Delay Compensation Value. Distance, in time 35 * |<--- Sample Point --->| !! 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: >> 39 * >> 40 * O: automatic mode. The controller dynamically measure @tdcv >> 41 * for each transmitted CAN FD frame. >> 42 * >> 43 * Other values: manual mode. Use the fixed provided value. >> 44 * >> 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. 36 * 49 * 37 * --+----------- one !! 50 * If @tdco is zero, then TDC is disabled and both @tdcv and 38 * |<-------- TDCV -------->| !! 51 * @tdcf should be ignored. 39 * |<------- TDCO -- << 40 * |<----------- Secondary Sample Point ----- << 41 * << 42 * To increase precision, contrary to the othe << 43 * which are measured in time quanta, the TDC << 44 * in clock periods (also referred as "minimum << 45 * 11898-1). << 46 * << 47 * @tdcv: Transmitter Delay Compensation Value << 48 * the signal to propagate, i.e. the dist << 49 * from the start of the bit on the TX pi << 50 * on the RX pin. @tdcv depends on the co << 51 * << 52 * CAN_CTRLMODE_TDC_AUTO is set: The tr << 53 * measures @tdcv for each transmitted << 54 * value provided here should be ignore << 55 * << 56 * CAN_CTRLMODE_TDC_MANUAL is set: use << 57 * value. << 58 * << 59 * N.B. CAN_CTRLMODE_TDC_AUTO and CAN_CTR << 60 * mutually exclusive. Only one can be se << 61 * CAN_TDC_CTRLMODE_AUTO and CAN_TDC_CTRL << 62 * TDC is disabled and all the values of << 63 * ignored. << 64 * << 65 * @tdco: Transmitter Delay Compensation Offse << 66 * clock periods, defining the distance b << 67 * bit reception on the RX pin of the tra << 68 * position such that SSP = @tdcv + @tdco << 69 * 52 * 70 * @tdcf: Transmitter Delay Compensation Filte 53 * @tdcf: Transmitter Delay Compensation Filter window. Defines the 71 * minimum value for the SSP position in !! 54 * minimum value for the SSP position in time quanta. If SSP is 72 * SSP position is less than @tdcf, then !! 55 * less than @tdcf, then no delay compensations occur and the 73 * occur and the normal sampling point is !! 56 * normal sampling point is used instead. The feature is enabled 74 * feature is enabled if and only if @tdc !! 57 * if and only if @tdcv is set to zero (automatic mode) and @tdcf 75 * (automatic mode) and @tdcf is configur !! 58 * is configured to a value greater than @tdco. 76 * than @tdco. << 77 */ 59 */ 78 struct can_tdc { 60 struct can_tdc { 79 u32 tdcv; 61 u32 tdcv; 80 u32 tdco; 62 u32 tdco; 81 u32 tdcf; 63 u32 tdcf; 82 }; 64 }; 83 65 84 /* 66 /* 85 * struct can_tdc_const - CAN hardware-depende 67 * struct can_tdc_const - CAN hardware-dependent constant for 86 * Transmission Delay Compensation 68 * Transmission Delay Compensation 87 * 69 * 88 * @tdcv_min: Transmitter Delay Compensation V !! 70 * @tdcv_max: Transmitter Delay Compensation Value maximum value. 89 * the controller does not support manual !! 71 * Should be set to zero if the controller does not support 90 * (c.f. flag CAN_CTRLMODE_TDC_MANUAL) th !! 72 * manual mode for tdcv. 91 * ignored. << 92 * @tdcv_max: Transmitter Delay Compensation V << 93 * the controller does not support manual << 94 * (c.f. flag CAN_CTRLMODE_TDC_MANUAL) th << 95 * ignored. << 96 * << 97 * @tdco_min: Transmitter Delay Compensation O << 98 * @tdco_max: Transmitter Delay Compensation O 73 * @tdco_max: Transmitter Delay Compensation Offset maximum value. 99 * Should not be zero. If the controller 74 * Should not be zero. If the controller does not support TDC, 100 * then the pointer to this structure sho 75 * then the pointer to this structure should be NULL. 101 * << 102 * @tdcf_min: Transmitter Delay Compensation F << 103 * value. If @tdcf_max is zero, this valu << 104 * @tdcf_max: Transmitter Delay Compensation F 76 * @tdcf_max: Transmitter Delay Compensation Filter window maximum 105 * value. Should be set to zero if the co 77 * value. Should be set to zero if the controller does not 106 * support this feature. 78 * support this feature. 107 */ 79 */ 108 struct can_tdc_const { 80 struct can_tdc_const { 109 u32 tdcv_min; << 110 u32 tdcv_max; 81 u32 tdcv_max; 111 u32 tdco_min; << 112 u32 tdco_max; 82 u32 tdco_max; 113 u32 tdcf_min; << 114 u32 tdcf_max; 83 u32 tdcf_max; 115 }; 84 }; 116 85 117 #ifdef CONFIG_CAN_CALC_BITTIMING 86 #ifdef CONFIG_CAN_CALC_BITTIMING 118 int can_calc_bittiming(const struct net_device !! 87 int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, 119 const struct can_bittim !! 88 const struct can_bittiming_const *btc); 120 89 121 void can_calc_tdco(struct can_tdc *tdc, const !! 90 void can_calc_tdco(struct net_device *dev); 122 const struct can_bittiming << 123 u32 *ctrlmode, u32 ctrlmode << 124 #else /* !CONFIG_CAN_CALC_BITTIMING */ 91 #else /* !CONFIG_CAN_CALC_BITTIMING */ 125 static inline int 92 static inline int 126 can_calc_bittiming(const struct net_device *de !! 93 can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, 127 const struct can_bittiming_ !! 94 const struct can_bittiming_const *btc) 128 { 95 { 129 netdev_err(dev, "bit-timing calculatio 96 netdev_err(dev, "bit-timing calculation not available\n"); 130 return -EINVAL; 97 return -EINVAL; 131 } 98 } 132 99 133 static inline void !! 100 static inline void can_calc_tdco(struct net_device *dev) 134 can_calc_tdco(struct can_tdc *tdc, const struc << 135 const struct can_bittiming *dbt, << 136 u32 *ctrlmode, u32 ctrlmode_supp << 137 { 101 { 138 } 102 } 139 #endif /* CONFIG_CAN_CALC_BITTIMING */ 103 #endif /* CONFIG_CAN_CALC_BITTIMING */ 140 104 141 void can_sjw_set_default(struct can_bittiming !! 105 int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt, 142 << 143 int can_sjw_check(const struct net_device *dev << 144 const struct can_bittiming_c << 145 << 146 int can_get_bittiming(const struct net_device << 147 const struct can_bittimi 106 const struct can_bittiming_const *btc, 148 const u32 *bitrate_const 107 const u32 *bitrate_const, 149 const unsigned int bitra !! 108 const unsigned int bitrate_const_cnt); 150 struct netlink_ext_ack * << 151 109 152 /* 110 /* 153 * can_bit_time() - Duration of one bit 111 * can_bit_time() - Duration of one bit 154 * 112 * 155 * Please refer to ISO 11898-1:2015, section 1 113 * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for 156 * additional information. 114 * additional information. 157 * 115 * 158 * Return: the number of time quanta in one bi 116 * Return: the number of time quanta in one bit. 159 */ 117 */ 160 static inline unsigned int can_bit_time(const 118 static inline unsigned int can_bit_time(const struct can_bittiming *bt) 161 { 119 { 162 return CAN_SYNC_SEG + bt->prop_seg + b 120 return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2; 163 } 121 } 164 122 165 #endif /* !_CAN_BITTIMING_H */ 123 #endif /* !_CAN_BITTIMING_H */ 166 124
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.