linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Jungclaus <frank.jungclaus@esd.eu>
To: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
	Wolfgang Grandegger <wg@grandegger.com>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: "Stefan Mätje" <stefan.maetje@esd.eu>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Frank Jungclaus" <frank.jungclaus@esd.eu>
Subject: [PATCH 1/6] can: esd_usb: Make use of existing kernel macros
Date: Wed, 17 May 2023 21:22:46 +0200	[thread overview]
Message-ID: <20230517192251.2405290-2-frank.jungclaus@esd.eu> (raw)
In-Reply-To: <20230517192251.2405290-1-frank.jungclaus@esd.eu>

As suggested by Vincent Mailhol make use of existing kernel macros:
- Use the unit suffixes from linux/units.h for the controller clock
frequencies
- Use the BIT() 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 <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/all/CAMZ6RqLaDNy-fZ2G0+QMhUEckkXLL+ZyELVSDFmqpd++aBzZQg@mail.gmail.com/
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
---
 drivers/net/can/usb/esd_usb.c | 38 ++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index d33bac3a6c10..042dda98b3db 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -3,19 +3,20 @@
  * CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro
  *
  * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <socketcan@esd.eu>
- * Copyright (C) 2022 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
+ * Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
  */
+#include <linux/can.h>
+#include <linux/can/dev.h>
+#include <linux/can/error.h>
+
 #include <linux/ethtool.h>
-#include <linux/signal.h>
-#include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/signal.h>
+#include <linux/slab.h>
+#include <linux/units.h>
 #include <linux/usb.h>
 
-#include <linux/can.h>
-#include <linux/can/dev.h>
-#include <linux/can/error.h>
-
 MODULE_AUTHOR("Matthias Fuchs <socketcan@esd.eu>");
 MODULE_AUTHOR("Frank Jungclaus <frank.jungclaus@esd.eu>");
 MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro interfaces");
@@ -27,8 +28,8 @@ MODULE_LICENSE("GPL v2");
 #define USB_CANUSBM_PRODUCT_ID	0x0011
 
 /* CAN controller clock frequencies */
-#define ESD_USB2_CAN_CLOCK	60000000
-#define ESD_USBM_CAN_CLOCK	36000000
+#define ESD_USB2_CAN_CLOCK	(60 * MEGA) /* Hz */
+#define ESD_USBM_CAN_CLOCK	(36 * MEGA) /* Hz */
 
 /* Maximum number of CAN nets */
 #define ESD_USB_MAX_NETS	2
@@ -42,20 +43,21 @@ MODULE_LICENSE("GPL v2");
 #define CMD_IDADD		6 /* also used for IDADD_REPLY */
 
 /* esd CAN message flags - dlc field */
-#define ESD_RTR			0x10
+#define ESD_RTR	BIT(4) /* 0x10 */
+
 
 /* esd CAN message flags - id field */
-#define ESD_EXTID		0x20000000
-#define ESD_EVENT		0x40000000
-#define ESD_IDMASK		0x1fffffff
+#define ESD_EXTID	BIT(29) /* 0x20000000 */
+#define ESD_EVENT	BIT(30) /* 0x40000000 */
+#define ESD_IDMASK	0x1fffffff
 
 /* esd CAN event ids */
 #define ESD_EV_CAN_ERROR_EXT	2 /* CAN controller specific diagnostic data */
 
 /* baudrate message flags */
-#define ESD_USB_UBR		0x80000000
-#define ESD_USB_LOM		0x40000000
-#define ESD_USB_NO_BAUDRATE	0x7fffffff
+#define ESD_USB_LOM	BIT(30) /* 0x40000000, Listen Only Mode */
+#define ESD_USB_UBR	BIT(31) /* 0x80000000, User Bit Rate (controller BTR) in bits 0..27 */
+#define ESD_USB_NO_BAUDRATE	0x7fffffff /* bit rate unconfigured */
 
 /* bit timing CAN-USB/2 */
 #define ESD_USB2_TSEG1_MIN	1
@@ -128,7 +130,7 @@ struct rx_msg {
 	__le32 ts;
 	__le32 id; /* upper 3 bits contain flags */
 	union {
-		u8 data[8];
+		u8 data[CAN_MAX_DLEN];
 		struct {
 			u8 status; /* CAN Controller Status */
 			u8 ecc;    /* Error Capture Register */
@@ -145,7 +147,7 @@ struct tx_msg {
 	u8 dlc;
 	u32 hnd;	/* opaque handle, not used by device */
 	__le32 id; /* upper 3 bits contain flags */
-	u8 data[8];
+	u8 data[CAN_MAX_DLEN];
 };
 
 struct tx_done_msg {
-- 
2.25.1


  reply	other threads:[~2023-05-17 19:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 19:22 [PATCH 0/6] *** can: esd_usb: More preparation before supporting esd CAN-USB/3 *** Frank Jungclaus
2023-05-17 19:22 ` Frank Jungclaus [this message]
2023-05-18 10:00   ` [PATCH 1/6] can: esd_usb: Make use of existing kernel macros Marc Kleine-Budde
2023-05-17 19:22 ` [PATCH 2/6] can: esd_usb: Replace initializer macros used for struct can_bittiming_const Frank Jungclaus
2023-05-17 19:22 ` [PATCH 3/6] can: esd_usb: Use consistent prefixes for macros Frank Jungclaus
2023-05-18  9:09   ` Vincent MAILHOL
2023-05-17 19:22 ` [PATCH 4/6] can: esd_usb: Prefix all structures with the device name Frank Jungclaus
2023-05-17 19:22 ` [PATCH 5/6] can: esd_usb: Replace hardcoded message length given to USB commands Frank Jungclaus
2023-05-17 19:22 ` [PATCH 6/6] can: esd_usb: Don't bother the user with nonessential log message Frank Jungclaus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230517192251.2405290-2-frank.jungclaus@esd.eu \
    --to=frank.jungclaus@esd.eu \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=stefan.maetje@esd.eu \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).