Skip to content

Commit 5e1440b

Browse files
Jiri Slabygregkh
authored andcommitted
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>
1 parent 988c5bb commit 5e1440b

6 files changed

Lines changed: 7 additions & 94 deletions

File tree

drivers/usb/serial/ark3116.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,8 @@ static void ark3116_set_termios(struct tty_struct *tty,
200200
__u8 lcr, hcr, eval;
201201

202202
/* set data bit count */
203-
switch (cflag & CSIZE) {
204-
case CS5:
205-
lcr = UART_LCR_WLEN5;
206-
break;
207-
case CS6:
208-
lcr = UART_LCR_WLEN6;
209-
break;
210-
case CS7:
211-
lcr = UART_LCR_WLEN7;
212-
break;
213-
default:
214-
case CS8:
215-
lcr = UART_LCR_WLEN8;
216-
break;
217-
}
203+
lcr = UART_LCR_WLEN(tty_get_char_size(cflag));
204+
218205
if (cflag & CSTOPB)
219206
lcr |= UART_LCR_STOP;
220207
if (cflag & PARENB)

drivers/usb/serial/f81232.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,7 @@ static void f81232_set_termios(struct tty_struct *tty,
643643
if (C_CSTOPB(tty))
644644
new_lcr |= UART_LCR_STOP;
645645

646-
switch (C_CSIZE(tty)) {
647-
case CS5:
648-
new_lcr |= UART_LCR_WLEN5;
649-
break;
650-
case CS6:
651-
new_lcr |= UART_LCR_WLEN6;
652-
break;
653-
case CS7:
654-
new_lcr |= UART_LCR_WLEN7;
655-
break;
656-
default:
657-
case CS8:
658-
new_lcr |= UART_LCR_WLEN8;
659-
break;
660-
}
646+
new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag));
661647

662648
mutex_lock(&priv->lock);
663649

drivers/usb/serial/f81534.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -970,21 +970,7 @@ static void f81534_set_termios(struct tty_struct *tty,
970970
if (C_CSTOPB(tty))
971971
new_lcr |= UART_LCR_STOP;
972972

973-
switch (C_CSIZE(tty)) {
974-
case CS5:
975-
new_lcr |= UART_LCR_WLEN5;
976-
break;
977-
case CS6:
978-
new_lcr |= UART_LCR_WLEN6;
979-
break;
980-
case CS7:
981-
new_lcr |= UART_LCR_WLEN7;
982-
break;
983-
default:
984-
case CS8:
985-
new_lcr |= UART_LCR_WLEN8;
986-
break;
987-
}
973+
new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag));
988974

989975
baud = tty_get_baud_rate(tty);
990976
if (!baud)

drivers/usb/serial/mos7720.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,30 +1380,12 @@ static void change_port_settings(struct tty_struct *tty,
13801380
return;
13811381
}
13821382

1383-
lData = UART_LCR_WLEN8;
13841383
lStop = 0x00; /* 1 stop bit */
13851384
lParity = 0x00; /* No parity */
13861385

13871386
cflag = tty->termios.c_cflag;
13881387

1389-
/* Change the number of bits */
1390-
switch (cflag & CSIZE) {
1391-
case CS5:
1392-
lData = UART_LCR_WLEN5;
1393-
break;
1394-
1395-
case CS6:
1396-
lData = UART_LCR_WLEN6;
1397-
break;
1398-
1399-
case CS7:
1400-
lData = UART_LCR_WLEN7;
1401-
break;
1402-
default:
1403-
case CS8:
1404-
lData = UART_LCR_WLEN8;
1405-
break;
1406-
}
1388+
lData = UART_LCR_WLEN(tty_get_char_size(cflag));
14071389

14081390
/* Change the Parity bit */
14091391
if (cflag & PARENB) {

drivers/usb/serial/quatech2.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,7 @@ static void qt2_set_termios(struct tty_struct *tty,
281281
new_lcr |= SERIAL_EVEN_PARITY;
282282
}
283283

284-
switch (cflag & CSIZE) {
285-
case CS5:
286-
new_lcr |= UART_LCR_WLEN5;
287-
break;
288-
case CS6:
289-
new_lcr |= UART_LCR_WLEN6;
290-
break;
291-
case CS7:
292-
new_lcr |= UART_LCR_WLEN7;
293-
break;
294-
default:
295-
case CS8:
296-
new_lcr |= UART_LCR_WLEN8;
297-
break;
298-
}
284+
new_lcr |= UART_LCR_WLEN(tty_get_char_size(cflag));
299285

300286
baud = tty_get_baud_rate(tty);
301287
if (!baud)

drivers/usb/serial/ssu100.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,7 @@ static void ssu100_set_termios(struct tty_struct *tty,
231231
urb_value |= SERIAL_EVEN_PARITY;
232232
}
233233

234-
switch (cflag & CSIZE) {
235-
case CS5:
236-
urb_value |= UART_LCR_WLEN5;
237-
break;
238-
case CS6:
239-
urb_value |= UART_LCR_WLEN6;
240-
break;
241-
case CS7:
242-
urb_value |= UART_LCR_WLEN7;
243-
break;
244-
default:
245-
case CS8:
246-
urb_value |= UART_LCR_WLEN8;
247-
break;
248-
}
234+
urb_value |= UART_LCR_WLEN(tty_get_char_size(cflag));
249235

250236
baud = tty_get_baud_rate(tty);
251237
if (!baud)

0 commit comments

Comments
 (0)