diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2021-01-11 17:19:18 +0300 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2021-01-13 11:42:58 +0300 |
commit | 5a9d5ecd69ed65fc2d49cdecfc1c1ab1e4d7af34 (patch) | |
tree | 8d190bbac664e269da05b278451c3d838842213c /include/linux/can | |
parent | 3e77f70e734584e0ad1038e459ed3fd2400f873a (diff) | |
download | linux-5a9d5ecd69ed65fc2d49cdecfc1c1ab1e4d7af34.tar.xz |
can: dev: move bittiming related code into seperate file
This patch moves the bittiming related code of the CAN device infrastructure
into a separate file.
Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20210111141930.693847-4-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'include/linux/can')
-rw-r--r-- | include/linux/can/bittiming.h | 44 | ||||
-rw-r--r-- | include/linux/can/dev.h | 16 |
2 files changed, 45 insertions, 15 deletions
diff --git a/include/linux/can/bittiming.h b/include/linux/can/bittiming.h new file mode 100644 index 000000000000..707575c668f4 --- /dev/null +++ b/include/linux/can/bittiming.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> + */ + +#ifndef _CAN_BITTIMING_H +#define _CAN_BITTIMING_H + +#include <linux/netdevice.h> +#include <linux/can/netlink.h> + +#define CAN_SYNC_SEG 1 + +#ifdef CONFIG_CAN_CALC_BITTIMING +int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, + const struct can_bittiming_const *btc); +#else /* !CONFIG_CAN_CALC_BITTIMING */ +static inline int +can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, + const struct can_bittiming_const *btc) +{ + netdev_err(dev, "bit-timing calculation not available\n"); + return -EINVAL; +} +#endif /* CONFIG_CAN_CALC_BITTIMING */ + +int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt, + const struct can_bittiming_const *btc, + const u32 *bitrate_const, + const unsigned int bitrate_const_cnt); + +/* + * can_bit_time() - Duration of one bit + * + * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for + * additional information. + * + * Return: the number of time quanta in one bit. + */ +static inline unsigned int can_bit_time(const struct can_bittiming *bt) +{ + return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2; +} + +#endif /* !_CAN_BITTIMING_H */ diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 197a79535cc2..054c3bed190b 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -15,6 +15,7 @@ #define _CAN_DEV_H #include <linux/can.h> +#include <linux/can/bittiming.h> #include <linux/can/error.h> #include <linux/can/led.h> #include <linux/can/netlink.h> @@ -82,21 +83,6 @@ struct can_priv { #endif }; -#define CAN_SYNC_SEG 1 - -/* - * can_bit_time() - Duration of one bit - * - * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for - * additional information. - * - * Return: the number of time quanta in one bit. - */ -static inline unsigned int can_bit_time(const struct can_bittiming *bt) -{ - return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2; -} - /* * can_cc_dlc2len(value) - convert a given data length code (dlc) of a * Classical CAN frame into a valid data length of max. 8 bytes. |