Skip to content

Commit 533e322

Browse files
vincent-mailholgregkh
authored andcommitted
can: bittiming: replace CAN units with the generic ones from linux/units.h
[ Upstream commit 330c6d3 ] In [1], we introduced a set of units in linux/can/bittiming.h. Since then, generic SI prefixes were added to linux/units.h in [2]. Those new prefixes can perfectly replace CAN specific ones. This patch replaces all occurrences of the CAN units with their corresponding prefix (from linux/units) and the unit (as a comment) according to below table. CAN units SI metric prefix (from linux/units) + unit (as a comment) ------------------------------------------------------------------------ CAN_KBPS KILO /* BPS */ CAN_MBPS MEGA /* BPS */ CAM_MHZ MEGA /* Hz */ The definition are then removed from linux/can/bittiming.h [1] commit 1d77507 ("can: bittiming: add CAN_KBPS, CAN_MBPS and CAN_MHZ macros") [2] commit 26471d4 ("units: Add SI metric prefix definitions") Link: https://lore.kernel.org/all/20211124014536.782550-1-mailhol.vincent@wanadoo.fr Suggested-by: Jimmy Assarsson <extja@kvaser.com> Suggested-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Stable-dep-of: 38c0aba ("can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 33b83a9 commit 533e322

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

drivers/net/can/dev/bittiming.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
55
*/
66

7+
#include <linux/units.h>
78
#include <linux/can/dev.h>
89

910
#ifdef CONFIG_CAN_CALC_BITTIMING
@@ -81,9 +82,9 @@ int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
8182
if (bt->sample_point) {
8283
sample_point_nominal = bt->sample_point;
8384
} else {
84-
if (bt->bitrate > 800 * CAN_KBPS)
85+
if (bt->bitrate > 800 * KILO /* BPS */)
8586
sample_point_nominal = 750;
86-
else if (bt->bitrate > 500 * CAN_KBPS)
87+
else if (bt->bitrate > 500 * KILO /* BPS */)
8788
sample_point_nominal = 800;
8889
else
8990
sample_point_nominal = 875;

drivers/net/can/usb/etas_es58x/es581_4.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/kernel.h>
13+
#include <linux/units.h>
1314
#include <asm/unaligned.h>
1415

1516
#include "es58x_core.h"
@@ -469,8 +470,8 @@ const struct es58x_parameters es581_4_param = {
469470
.bittiming_const = &es581_4_bittiming_const,
470471
.data_bittiming_const = NULL,
471472
.tdc_const = NULL,
472-
.bitrate_max = 1 * CAN_MBPS,
473-
.clock = {.freq = 50 * CAN_MHZ},
473+
.bitrate_max = 1 * MEGA /* BPS */,
474+
.clock = {.freq = 50 * MEGA /* Hz */},
474475
.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC,
475476
.tx_start_of_frame = 0xAFAF,
476477
.rx_start_of_frame = 0xFAFA,

drivers/net/can/usb/etas_es58x/es58x_fd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <linux/kernel.h>
15+
#include <linux/units.h>
1516
#include <asm/unaligned.h>
1617

1718
#include "es58x_core.h"
@@ -521,8 +522,8 @@ const struct es58x_parameters es58x_fd_param = {
521522
* Mbps work in an optimal environment but are not recommended
522523
* for production environment.
523524
*/
524-
.bitrate_max = 8 * CAN_MBPS,
525-
.clock = {.freq = 80 * CAN_MHZ},
525+
.bitrate_max = 8 * MEGA /* BPS */,
526+
.clock = {.freq = 80 * MEGA /* Hz */},
526527
.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY |
527528
CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO |
528529
CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_TDC_AUTO,

include/linux/can/bittiming.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
#define CAN_SYNC_SEG 1
1313

1414

15-
/* Kilobits and Megabits per second */
16-
#define CAN_KBPS 1000UL
17-
#define CAN_MBPS 1000000UL
18-
19-
/* Megahertz */
20-
#define CAN_MHZ 1000000UL
21-
2215
#define CAN_CTRLMODE_TDC_MASK \
2316
(CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL)
2417

0 commit comments

Comments
 (0)