Skip to content

Commit 1ad549c

Browse files
Frank Jungclausmarckleinebudde
authored andcommitted
can: esd_usb: Make use of existing kernel macros
Make use of existing kernel macros: - Use the unit suffixes from linux/units.h for the controller clock frequencies - Use the BIT() and the GENMASK() macro to set specific bits in some constants - Use CAN_MAX_DLEN (instead of directly using the value 8) for the maximum CAN payload length Additionally: - Spend some commenting for the previously changed constants - Add the current year to the copyright notice - While adding the header linux/units.h to the list of include files also sort that list alphabetically Suggested-by: Vincent MAILHOL <[email protected]> Link: https://lore.kernel.org/all/CAMZ6RqLaDNy-fZ2G0+QMhUEckkXLL+ZyELVSDFmqpd++aBzZQg@mail.gmail.com/ Link: https://lore.kernel.org/all/CAMZ6RqKdg5YBufa0C+ttzJvoG=9yuti-8AmthCi4jBbd08JEtw@mail.gmail.com/ Suggested-by: Marc Kleine-Budde <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Frank Jungclaus <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mkl: remove hex constants in comments after BIT()] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent d7588f0 commit 1ad549c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

drivers/net/can/usb/esd_usb.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
* CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro
44
*
55
* Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <[email protected]>
6-
* Copyright (C) 2022 esd electronics gmbh, Frank Jungclaus <[email protected]>
6+
* Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <[email protected]>
77
*/
8-
#include <linux/ethtool.h>
9-
#include <linux/signal.h>
10-
#include <linux/slab.h>
11-
#include <linux/module.h>
12-
#include <linux/netdevice.h>
13-
#include <linux/usb.h>
148

159
#include <linux/can.h>
1610
#include <linux/can/dev.h>
1711
#include <linux/can/error.h>
12+
#include <linux/ethtool.h>
13+
#include <linux/module.h>
14+
#include <linux/netdevice.h>
15+
#include <linux/signal.h>
16+
#include <linux/slab.h>
17+
#include <linux/units.h>
18+
#include <linux/usb.h>
1819

1920
MODULE_AUTHOR("Matthias Fuchs <[email protected]>");
2021
MODULE_AUTHOR("Frank Jungclaus <[email protected]>");
@@ -27,8 +28,8 @@ MODULE_LICENSE("GPL v2");
2728
#define USB_CANUSBM_PRODUCT_ID 0x0011
2829

2930
/* CAN controller clock frequencies */
30-
#define ESD_USB2_CAN_CLOCK 60000000
31-
#define ESD_USBM_CAN_CLOCK 36000000
31+
#define ESD_USB2_CAN_CLOCK (60 * MEGA) /* Hz */
32+
#define ESD_USBM_CAN_CLOCK (36 * MEGA) /* Hz */
3233

3334
/* Maximum number of CAN nets */
3435
#define ESD_USB_MAX_NETS 2
@@ -42,20 +43,21 @@ MODULE_LICENSE("GPL v2");
4243
#define CMD_IDADD 6 /* also used for IDADD_REPLY */
4344

4445
/* esd CAN message flags - dlc field */
45-
#define ESD_RTR 0x10
46+
#define ESD_RTR BIT(4)
47+
4648

4749
/* esd CAN message flags - id field */
48-
#define ESD_EXTID 0x20000000
49-
#define ESD_EVENT 0x40000000
50-
#define ESD_IDMASK 0x1fffffff
50+
#define ESD_EXTID BIT(29)
51+
#define ESD_EVENT BIT(30)
52+
#define ESD_IDMASK GENMASK(28, 0)
5153

5254
/* esd CAN event ids */
5355
#define ESD_EV_CAN_ERROR_EXT 2 /* CAN controller specific diagnostic data */
5456

5557
/* baudrate message flags */
56-
#define ESD_USB_UBR 0x80000000
57-
#define ESD_USB_LOM 0x40000000
58-
#define ESD_USB_NO_BAUDRATE 0x7fffffff
58+
#define ESD_USB_LOM BIT(30) /* Listen Only Mode */
59+
#define ESD_USB_UBR BIT(31) /* User Bit Rate (controller BTR) in bits 0..27 */
60+
#define ESD_USB_NO_BAUDRATE GENMASK(30, 0) /* bit rate unconfigured */
5961

6062
/* bit timing CAN-USB/2 */
6163
#define ESD_USB2_TSEG1_MIN 1
@@ -70,7 +72,7 @@ MODULE_LICENSE("GPL v2");
7072
#define ESD_USB2_BRP_MIN 1
7173
#define ESD_USB2_BRP_MAX 1024
7274
#define ESD_USB2_BRP_INC 1
73-
#define ESD_USB2_3_SAMPLES 0x00800000
75+
#define ESD_USB2_3_SAMPLES BIT(23)
7476

7577
/* esd IDADD message */
7678
#define ESD_ID_ENABLE 0x80
@@ -128,7 +130,7 @@ struct rx_msg {
128130
__le32 ts;
129131
__le32 id; /* upper 3 bits contain flags */
130132
union {
131-
u8 data[8];
133+
u8 data[CAN_MAX_DLEN];
132134
struct {
133135
u8 status; /* CAN Controller Status */
134136
u8 ecc; /* Error Capture Register */
@@ -145,7 +147,7 @@ struct tx_msg {
145147
u8 dlc;
146148
u32 hnd; /* opaque handle, not used by device */
147149
__le32 id; /* upper 3 bits contain flags */
148-
u8 data[8];
150+
u8 data[CAN_MAX_DLEN];
149151
};
150152

151153
struct tx_done_msg {

0 commit comments

Comments
 (0)