From: "Marek Behún" <kabel@kernel.org>
To: linux-serial@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Pali Rohár" <pali@kernel.org>, "Marek Behún" <kabel@kernel.org>
Subject: [PATCH 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed for ASYNC_SPD_CUST
Date: Thu, 7 Jul 2022 16:53:53 +0200 [thread overview]
Message-ID: <20220707145354.29705-7-kabel@kernel.org> (raw)
In-Reply-To: <20220707145354.29705-1-kabel@kernel.org>
From: Pali Rohár <pali@kernel.org>
When ASYNC_SPD_CUST is used, update and recalculate custom_divisor and
c_*speed fields from newly set baudrate value, so that userspace GET
functions can see current configuration.
Signed-off-by: Pali Rohár <pali@kernel.org>
Tested-by: Marek Behún <kabel@kernel.org>
---
drivers/usb/serial/ftdi_sio.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ac84d5779966..3bf5750e76de 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1303,6 +1303,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct device *dev = &port->dev;
+ int fix_custom_divisor = 0;
u32 div_value = 0;
int div_okay = 1;
int baud;
@@ -1317,6 +1318,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
if (baud == 38400 &&
((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
(priv->custom_divisor)) {
+ fix_custom_divisor = 1;
baud = DIV_ROUND_CLOSEST(priv->baud_base, priv->custom_divisor);
dev_dbg(dev, "%s - custom divisor %d sets baud rate to %d\n",
__func__, priv->custom_divisor, baud);
@@ -1401,7 +1403,19 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
ftdi_chip_name[priv->chip_type]);
}
+ /* Fix deprecated async-compatible custom_divisor hack and update tty baudrate */
+ if (fix_custom_divisor) {
+ priv->custom_divisor = DIV_ROUND_CLOSEST(priv->baud_base, baud);
+ old_baud = baud;
+ baud = 38400;
+ }
+
tty_encode_baud_rate(tty, baud, baud);
+
+ /* For async-compatible custom_divisor store into TCGETS2 c_*speed fields real baudrate */
+ if (fix_custom_divisor)
+ tty->termios.c_ispeed = tty->termios.c_ospeed = old_baud;
+
return div_value;
}
@@ -2674,6 +2688,8 @@ static void ftdi_set_termios(struct tty_struct *tty,
dev_dbg(ddev, "%s: forcing baud rate for this device\n", __func__);
tty_encode_baud_rate(tty, priv->force_baud,
priv->force_baud);
+ termios->c_ispeed = termios->c_ospeed =
+ DIV_ROUND_CLOSEST(priv->baud_base, priv->custom_divisor);
}
/* Force RTS-CTS if this device requires it. */
--
2.35.1
next prev parent reply other threads:[~2022-07-07 14:55 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 14:53 [PATCH 0/7] ftdi_sio driver improvements Marek Behún
2022-07-07 14:53 ` [PATCH 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-07 15:07 ` Greg Kroah-Hartman
2022-07-07 15:37 ` Marek Behún
2022-07-07 15:50 ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 2/7] USB: serial: ftdi_sio: Add missing baudrate validation Marek Behún
2022-07-07 15:08 ` Greg Kroah-Hartman
2022-07-07 16:22 ` Marek Behún
2022-07-07 16:50 ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Marek Behún
2022-07-07 15:06 ` Greg Kroah-Hartman
2022-07-07 15:41 ` Marek Behún
2022-07-07 15:09 ` Greg Kroah-Hartman
2022-07-07 15:50 ` Marek Behún
2022-07-07 14:53 ` [PATCH 4/7] USB: serial: ftdi_sio: Do not reset baudrate to 9600 on error Marek Behún
2022-07-07 15:10 ` Greg Kroah-Hartman
2022-07-07 15:52 ` Marek Behún
2022-07-07 16:06 ` Greg Kroah-Hartman
2022-07-08 15:51 ` Andy Shevchenko
2022-07-12 11:28 ` m.brock
2022-07-12 12:09 ` Marek Behún
2022-07-12 12:11 ` Marek Behún
2022-07-07 14:53 ` [PATCH 5/7] USB: serial: ftdi_sio: Fix baudrate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-07 15:11 ` Greg Kroah-Hartman
2022-07-07 16:08 ` Marek Behún
2022-07-07 16:12 ` Greg Kroah-Hartman
2022-07-07 14:53 ` Marek Behún [this message]
2022-07-07 14:53 ` [PATCH 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baudrate Marek Behún
2022-07-07 15:11 ` Greg Kroah-Hartman
2022-07-07 15:07 ` [PATCH 0/7] ftdi_sio driver improvements Greg Kroah-Hartman
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=20220707145354.29705-7-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-serial@vger.kernel.org \
--cc=pali@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.