1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (c) 2020 Pengutronix, Marc Kleine-Budde <[email protected]> 3 */ 4 5 #ifndef _CAN_BITTIMING_H 6 #define _CAN_BITTIMING_H 7 8 #include <linux/netdevice.h> 9 #include <linux/can/netlink.h> 10 11 #define CAN_SYNC_SEG 1 12 13 #ifdef CONFIG_CAN_CALC_BITTIMING 14 int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, 15 const struct can_bittiming_const *btc); 16 #else /* !CONFIG_CAN_CALC_BITTIMING */ 17 static inline int 18 can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, 19 const struct can_bittiming_const *btc) 20 { 21 netdev_err(dev, "bit-timing calculation not available\n"); 22 return -EINVAL; 23 } 24 #endif /* CONFIG_CAN_CALC_BITTIMING */ 25 26 int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt, 27 const struct can_bittiming_const *btc, 28 const u32 *bitrate_const, 29 const unsigned int bitrate_const_cnt); 30 31 /* 32 * can_bit_time() - Duration of one bit 33 * 34 * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for 35 * additional information. 36 * 37 * Return: the number of time quanta in one bit. 38 */ 39 static inline unsigned int can_bit_time(const struct can_bittiming *bt) 40 { 41 return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2; 42 } 43 44 #endif /* !_CAN_BITTIMING_H */ 45