public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1 1/1] USB: serial: f81232: fix incomplete serial port generation
@ 2025-10-08  2:38 Ji-Ze Hong (Peter Hong)
  2025-10-14 15:36 ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Ji-Ze Hong (Peter Hong) @ 2025-10-08  2:38 UTC (permalink / raw)
  To: johan
  Cc: gregkh, linux-usb, linux-kernel, tom_tsai, yu_chen,
	hpeter+linux_kernel, Ji-Ze Hong (Peter Hong)

The Fintek F81532A/534A/535/536 family relies on the
F81534A_CTRL_CMD_ENABLE_PORT (116h) register during initialization to
both determine serial port status and control port creation. If the
driver experiences fast load/unload cycles, the device state may becomes
unstable, resulting in the incomplete generation of serial ports.

Performing a dummy read operation on the register prior to the initial
write command resolves the issue. This clears the device's stale internal
state. Subsequent write operations will correctly generate all serial
ports.

Tested on: HygonDM1SLT(Hygon C86 3250 8-core Processor)

Signed-off-by: Ji-Ze Hong (Peter Hong) <peter_hong@fintek.com.tw>
---
 drivers/usb/serial/f81232.c | 58 +++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index 530b77fc2f78..84a9e3e43b5b 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -856,6 +856,41 @@ static int f81534a_ctrl_set_register(struct usb_interface *intf, u16 reg,
 	return status;
 }
 
+static int f81534a_ctrl_get_register(struct usb_interface *intf, u16 reg,
+					u16 size, void *val)
+{
+	struct usb_device *dev = interface_to_usbdev(intf);
+	int retry = F81534A_ACCESS_REG_RETRY;
+	int status;
+
+	while (retry--) {
+		status = usb_control_msg_recv(dev,
+					      0,
+					      F81232_REGISTER_REQUEST,
+					      F81232_GET_REGISTER,
+					      reg,
+					      0,
+					      val,
+					      size,
+					      USB_CTRL_GET_TIMEOUT,
+					      GFP_KERNEL);
+		if (status) {
+			status = usb_translate_errors(status);
+			if (status == -EIO)
+				continue;
+		}
+
+		break;
+	}
+
+	if (status) {
+		dev_err(&intf->dev, "failed to get register 0x%x: %d\n",
+				reg, status);
+	}
+
+	return status;
+}
+
 static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf, bool en)
 {
 	unsigned char enable[2] = {0};
@@ -869,6 +904,29 @@ static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf, bool en)
 	 * bit 0~11	: Serial port enable bit.
 	 */
 	if (en) {
+		/*
+		 * The Fintek F81532A/534A/535/536 family relies on the
+		 * F81534A_CTRL_CMD_ENABLE_PORT (116h) register during
+		 * initialization to both determine serial port status and
+		 * control port creation.
+		 *
+		 * If the driver experiences fast load/unload cycles, the
+		 * device state may becomes unstable, resulting in the
+		 * incomplete generation of serial ports.
+		 *
+		 * Performing a dummy read operation on the register prior
+		 * to the initial write command resolves the issue.
+		 *
+		 * This clears the device's stale internal state. Subsequent
+		 * write operations will correctly generate all serial ports.
+		 */
+		status = f81534a_ctrl_get_register(intf,
+						F81534A_CTRL_CMD_ENABLE_PORT,
+						sizeof(enable),
+						enable);
+		if (status)
+			return status;
+
 		enable[0] = 0xff;
 		enable[1] = 0x8f;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V1 1/1] USB: serial: f81232: fix incomplete serial port generation
  2025-10-08  2:38 [PATCH V1 1/1] USB: serial: f81232: fix incomplete serial port generation Ji-Ze Hong (Peter Hong)
@ 2025-10-14 15:36 ` Johan Hovold
  2025-10-15  2:24   ` Peter Hong
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2025-10-14 15:36 UTC (permalink / raw)
  To: Ji-Ze Hong (Peter Hong)
  Cc: gregkh, linux-usb, linux-kernel, tom_tsai, yu_chen,
	hpeter+linux_kernel

On Wed, Oct 08, 2025 at 10:38:58AM +0800, Ji-Ze Hong (Peter Hong) wrote:
> The Fintek F81532A/534A/535/536 family relies on the
> F81534A_CTRL_CMD_ENABLE_PORT (116h) register during initialization to
> both determine serial port status and control port creation. If the
> driver experiences fast load/unload cycles, the device state may becomes
> unstable, resulting in the incomplete generation of serial ports.

Do I understand correctly that you're only seeing this issue if you're
unloading and reloading the module (or rebinding the driver through
sysfs)?

> Performing a dummy read operation on the register prior to the initial
> write command resolves the issue. This clears the device's stale internal
> state. Subsequent write operations will correctly generate all serial
> ports.

Does this mean that the retry loop is no longer needed? Can it now be
removed in either or both accessor functions perhaps?

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V1 1/1] USB: serial: f81232: fix incomplete serial port generation
  2025-10-14 15:36 ` Johan Hovold
@ 2025-10-15  2:24   ` Peter Hong
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Hong @ 2025-10-15  2:24 UTC (permalink / raw)
  To: Johan Hovold
  Cc: gregkh, linux-usb, linux-kernel, tom_tsai, yu_chen,
	hpeter+linux_kernel

Hi Johan,

Johan Hovold 於 2025/10/14 下午 11:36 寫道:
> On Wed, Oct 08, 2025 at 10:38:58AM +0800, Ji-Ze Hong (Peter Hong) wrote:
>> The Fintek F81532A/534A/535/536 family relies on the
>> F81534A_CTRL_CMD_ENABLE_PORT (116h) register during initialization to
>> both determine serial port status and control port creation. If the
>> driver experiences fast load/unload cycles, the device state may becomes
>> unstable, resulting in the incomplete generation of serial ports.
> Do I understand correctly that you're only seeing this issue if you're
> unloading and reloading the module (or rebinding the driver through
> sysfs)?

Yes, this issue has only been observed and reported during module unload
and reload operations currently.

>> Performing a dummy read operation on the register prior to the initial
>> write command resolves the issue. This clears the device's stale internal
>> state. Subsequent write operations will correctly generate all serial
>> ports.
> Does this mean that the retry loop is no longer needed? Can it now be
> removed in either or both accessor functions perhaps?

OK, we'll test the loop removal in the accessor. If successful, we'll prepare
and send V2.


Thanks,



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-15  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08  2:38 [PATCH V1 1/1] USB: serial: f81232: fix incomplete serial port generation Ji-Ze Hong (Peter Hong)
2025-10-14 15:36 ` Johan Hovold
2025-10-15  2:24   ` Peter Hong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox