From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: Crescent Hsieh <crescentcy.hsieh@moxa.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] USB: serial: mxuport: update number-of-ports encoding
Date: Thu, 7 May 2026 16:11:14 +0200 [thread overview]
Message-ID: <20260507141114.284470-1-johan@kernel.org> (raw)
In preparation for adding support for 3, 5, 6 and 7 port devices, replace
the current one-bit-per-type encoding of the number of ports with a more
compact four bit encoding (2..16 ports or undefined).
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/mxuport.c | 38 +++++++++++++++---------------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c
index ad5fdf55a02e..591be1fe3737 100644
--- a/drivers/usb/serial/mxuport.c
+++ b/drivers/usb/serial/mxuport.c
@@ -146,11 +146,6 @@
#define MX_WAIT_FOR_LOW_WATER 0x0040
#define MX_WAIT_FOR_SEND_NEXT 0x0080
-#define MX_UPORT_2_PORT BIT(0)
-#define MX_UPORT_4_PORT BIT(1)
-#define MX_UPORT_8_PORT BIT(2)
-#define MX_UPORT_16_PORT BIT(3)
-
/* This structure holds all of the local port information */
struct mxuport_port {
u8 mcr_state; /* Last MCR state */
@@ -159,26 +154,31 @@ struct mxuport_port {
spinlock_t spinlock; /* Protects msr_state */
};
+/* Encode number of ports (2..16 or undefined) */
+#define MX_PORTS_MASK GENMASK(3, 0)
+#define MX_PORTS_OFFSET 1
+#define MX_PORTS(n) (((n) - MX_PORTS_OFFSET) & MX_PORTS_MASK)
+
/* Table of devices that work with this driver */
static const struct usb_device_id mxuport_idtable[] = {
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1250_PID),
- .driver_info = MX_UPORT_2_PORT },
+ .driver_info = MX_PORTS(2) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1251_PID),
- .driver_info = MX_UPORT_2_PORT },
+ .driver_info = MX_PORTS(2) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1410_PID),
- .driver_info = MX_UPORT_4_PORT },
+ .driver_info = MX_PORTS(4) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1450_PID),
- .driver_info = MX_UPORT_4_PORT },
+ .driver_info = MX_PORTS(4) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1451_PID),
- .driver_info = MX_UPORT_4_PORT },
+ .driver_info = MX_PORTS(4) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1618_PID),
- .driver_info = MX_UPORT_8_PORT },
+ .driver_info = MX_PORTS(8) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1658_PID),
- .driver_info = MX_UPORT_8_PORT },
+ .driver_info = MX_PORTS(8) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1613_PID),
- .driver_info = MX_UPORT_16_PORT },
+ .driver_info = MX_PORTS(16) },
{ USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1653_PID),
- .driver_info = MX_UPORT_16_PORT },
+ .driver_info = MX_PORTS(16) },
{} /* Terminating entry */
};
@@ -942,14 +942,8 @@ static int mxuport_calc_num_ports(struct usb_serial *serial,
int num_ports;
int i;
- if (features & MX_UPORT_2_PORT) {
- num_ports = 2;
- } else if (features & MX_UPORT_4_PORT) {
- num_ports = 4;
- } else if (features & MX_UPORT_8_PORT) {
- num_ports = 8;
- } else if (features & MX_UPORT_16_PORT) {
- num_ports = 16;
+ if (features & MX_PORTS_MASK) {
+ num_ports = (features & MX_PORTS_MASK) + MX_PORTS_OFFSET;
} else {
dev_warn(&serial->interface->dev,
"unknown device, assuming two ports\n");
--
2.53.0
next reply other threads:[~2026-05-07 14:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 14:11 Johan Hovold [this message]
2026-05-08 5:16 ` [PATCH] USB: serial: mxuport: update number-of-ports encoding Greg KH
2026-05-11 7:19 ` Johan Hovold
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=20260507141114.284470-1-johan@kernel.org \
--to=johan@kernel.org \
--cc=crescentcy.hsieh@moxa.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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