USB: serial: make use of UART_LCR_WLEN() + tty_get_char_size()

Having a generic UART_LCR_WLEN() macro and the tty_get_char_size()
helper, we can remove all those repeated switch-cases in drivers.

Cc: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20220224095558.30929-3-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jiri Slaby 2022-02-24 10:55:56 +01:00 committed by Greg Kroah-Hartman
parent 988c5bbea5
commit 5e1440bc23
6 changed files with 7 additions and 94 deletions

View File

@ -200,21 +200,8 @@ static void ark3116_set_termios(struct tty_struct *tty,
__u8 lcr, hcr, eval;
/* set data bit count */
switch (cflag & CSIZE) {
case CS5:
lcr = UART_LCR_WLEN5;
break;
case CS6:
lcr = UART_LCR_WLEN6;
break;
case CS7:
lcr = UART_LCR_WLEN7;
break;
default:
case CS8:
lcr = UART_LCR_WLEN8;
break;
}
lcr = UART_LCR_WLEN(tty_get_char_size(cflag));
if (cflag & CSTOPB)
lcr |= UART_LCR_STOP;
if (cflag & PARENB)

View File

@ -643,21 +643,7 @@ static void f81232_set_termios(struct tty_struct *tty,
if (C_CSTOPB(tty))
new_lcr |= UART_LCR_STOP;
switch (C_CSIZE(tty)) {
case CS5:
new_lcr |= UART_LCR_WLEN5;
break;
case CS6:
new_lcr |= UART_LCR_WLEN6;
break;
case CS7:
new_lcr |= UART_LCR_WLEN7;
break;
default:
case CS8:
new_lcr |= UART_LCR_WLEN8;
break;
}
new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag));
mutex_lock(&priv->lock);

View File

@ -970,21 +970,7 @@ static void f81534_set_termios(struct tty_struct *tty,
if (C_CSTOPB(tty))
new_lcr |= UART_LCR_STOP;
switch (C_CSIZE(tty)) {
case CS5:
new_lcr |= UART_LCR_WLEN5;
break;
case CS6:
new_lcr |= UART_LCR_WLEN6;
break;
case CS7:
new_lcr |= UART_LCR_WLEN7;
break;
default:
case CS8:
new_lcr |= UART_LCR_WLEN8;
break;
}
new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag));
baud = tty_get_baud_rate(tty);
if (!baud)

View File

@ -1380,30 +1380,12 @@ static void change_port_settings(struct tty_struct *tty,
return;
}
lData = UART_LCR_WLEN8;
lStop = 0x00; /* 1 stop bit */
lParity = 0x00; /* No parity */
cflag = tty->termios.c_cflag;
/* Change the number of bits */
switch (cflag & CSIZE) {
case CS5:
lData = UART_LCR_WLEN5;
break;
case CS6:
lData = UART_LCR_WLEN6;
break;
case CS7:
lData = UART_LCR_WLEN7;
break;
default:
case CS8:
lData = UART_LCR_WLEN8;
break;
}
lData = UART_LCR_WLEN(tty_get_char_size(cflag));
/* Change the Parity bit */
if (cflag & PARENB) {

View File

@ -281,21 +281,7 @@ static void qt2_set_termios(struct tty_struct *tty,
new_lcr |= SERIAL_EVEN_PARITY;
}
switch (cflag & CSIZE) {
case CS5:
new_lcr |= UART_LCR_WLEN5;
break;
case CS6:
new_lcr |= UART_LCR_WLEN6;
break;
case CS7:
new_lcr |= UART_LCR_WLEN7;
break;
default:
case CS8:
new_lcr |= UART_LCR_WLEN8;
break;
}
new_lcr |= UART_LCR_WLEN(tty_get_char_size(cflag));
baud = tty_get_baud_rate(tty);
if (!baud)

View File

@ -231,21 +231,7 @@ static void ssu100_set_termios(struct tty_struct *tty,
urb_value |= SERIAL_EVEN_PARITY;
}
switch (cflag & CSIZE) {
case CS5:
urb_value |= UART_LCR_WLEN5;
break;
case CS6:
urb_value |= UART_LCR_WLEN6;
break;
case CS7:
urb_value |= UART_LCR_WLEN7;
break;
default:
case CS8:
urb_value |= UART_LCR_WLEN8;
break;
}
urb_value |= UART_LCR_WLEN(tty_get_char_size(cflag));
baud = tty_get_baud_rate(tty);
if (!baud)