From: "Marek Behún" <kabel@kernel.org>
To: linux-usb@vger.kernel.org
Cc: "Pali Rohár" <pali@kernel.org>, "Johan Hovold" <johan@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH v2 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function
Date: Tue, 12 Jul 2022 13:53:02 +0200 [thread overview]
Message-ID: <20220712115306.26471-4-kabel@kernel.org> (raw)
In-Reply-To: <20220712115306.26471-1-kabel@kernel.org>
From: Pali Rohár <pali@kernel.org>
In preparation for following changes, extract divisor code for SIO chip
into new function ftdi_sio_baud_to_divisor(), as is done for other
chips.
No functional change.
Signed-off-by: Pali Rohár <pali@kernel.org>
Tested-by: Marek Behún <kabel@kernel.org>
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/usb/serial/ftdi_sio.c | 36 ++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 717b97f4e094..5b109714612f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1150,6 +1150,23 @@ static struct usb_serial_driver * const serial_drivers[] = {
* ***************************************************************************
*/
+static int ftdi_sio_baud_to_divisor(int baud)
+{
+ switch (baud) {
+ case 300: return ftdi_sio_b300;
+ case 600: return ftdi_sio_b600;
+ case 1200: return ftdi_sio_b1200;
+ case 2400: return ftdi_sio_b2400;
+ case 4800: return ftdi_sio_b4800;
+ case 9600: return ftdi_sio_b9600;
+ case 19200: return ftdi_sio_b19200;
+ case 38400: return ftdi_sio_b38400;
+ case 57600: return ftdi_sio_b57600;
+ case 115200: return ftdi_sio_b115200;
+ default: return -1;
+ }
+}
+
static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
{
unsigned short int divisor;
@@ -1286,7 +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;
- u32 div_value = 0;
+ int div_value = 0;
int div_okay = 1;
int baud;
@@ -1309,23 +1326,12 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
baud = 9600;
switch (priv->chip_type) {
case SIO: /* SIO chip */
- switch (baud) {
- case 300: div_value = ftdi_sio_b300; break;
- case 600: div_value = ftdi_sio_b600; break;
- case 1200: div_value = ftdi_sio_b1200; break;
- case 2400: div_value = ftdi_sio_b2400; break;
- case 4800: div_value = ftdi_sio_b4800; break;
- case 9600: div_value = ftdi_sio_b9600; break;
- case 19200: div_value = ftdi_sio_b19200; break;
- case 38400: div_value = ftdi_sio_b38400; break;
- case 57600: div_value = ftdi_sio_b57600; break;
- case 115200: div_value = ftdi_sio_b115200; break;
- } /* baud */
- if (div_value == 0) {
+ div_value = ftdi_sio_baud_to_divisor(baud);
+ if (div_value == -1) {
dev_dbg(dev, "%s - Baudrate (%d) requested is not supported\n",
__func__, baud);
- div_value = ftdi_sio_b9600;
baud = 9600;
+ div_value = ftdi_sio_baud_to_divisor(baud);
div_okay = 0;
}
break;
--
2.35.1
next prev parent reply other threads:[~2022-07-12 11:54 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 11:52 [PATCH v2 0/7] ftdi_sio driver improvements Marek Behún
2022-07-12 11:53 ` [PATCH v2 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-24 12:02 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 2/7] USB: serial: ftdi_sio: Add missing baud rate validation Marek Behún
2022-07-12 17:27 ` Rob Pearce
2022-07-12 22:24 ` Marek Behún
2022-07-12 11:53 ` Marek Behún [this message]
2022-07-24 12:06 ` [PATCH v2 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Johan Hovold
2022-08-18 14:11 ` Pali Rohár
2022-09-13 14:49 ` Johan Hovold
2022-09-13 15:30 ` Pali Rohár
2022-09-13 15:44 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 4/7] USB: serial: ftdi_sio: Do not reset baud rate to 9600 Baud on error Marek Behún
2022-07-24 12:20 ` Johan Hovold
2022-08-18 14:12 ` Pali Rohár
2022-09-13 14:54 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 5/7] USB: serial: ftdi_sio: Fix baud rate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-24 12:26 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed " Marek Behún
2022-07-24 12:28 ` Johan Hovold
2022-07-24 12:33 ` Pali Rohár
2022-07-24 12:54 ` Johan Hovold
2022-07-24 12:59 ` Pali Rohár
2022-07-24 13:08 ` Johan Hovold
2022-08-18 14:09 ` Pali Rohár
2022-09-13 14:59 ` Johan Hovold
2022-09-14 8:48 ` Pali Rohár
2022-09-14 8:58 ` Johan Hovold
2022-09-14 9:10 ` Pali Rohár
2022-09-14 9:18 ` Johan Hovold
2022-09-14 9:20 ` Pali Rohár
2022-07-12 11:53 ` [PATCH v2 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baud rate Marek Behún
2022-07-24 12:41 ` Johan Hovold
2022-08-18 14:17 ` Pali Rohár
2022-09-13 15:02 ` Johan Hovold
2022-09-13 15:24 ` Pali Rohár
2022-09-13 15:34 ` 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=20220712115306.26471-4-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-usb@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.