Skip to content

Commit 988c5bb

Browse files
Jiri Slabygregkh
authored andcommitted
tty: 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: Laxman Dewangan <ldewangan@nvidia.com> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Jonathan Hunter <jonathanh@nvidia.com> Cc: linux-tegra@vger.kernel.org Reviewed-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20220224095558.30929-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 797bd4d commit 988c5bb

8 files changed

Lines changed: 11 additions & 122 deletions

File tree

drivers/tty/serial/8250/8250_omap.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,7 @@ static void omap_8250_set_termios(struct uart_port *port,
357357
unsigned char cval = 0;
358358
unsigned int baud;
359359

360-
switch (termios->c_cflag & CSIZE) {
361-
case CS5:
362-
cval = UART_LCR_WLEN5;
363-
break;
364-
case CS6:
365-
cval = UART_LCR_WLEN6;
366-
break;
367-
case CS7:
368-
cval = UART_LCR_WLEN7;
369-
break;
370-
default:
371-
case CS8:
372-
cval = UART_LCR_WLEN8;
373-
break;
374-
}
360+
cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag));
375361

376362
if (termios->c_cflag & CSTOPB)
377363
cval |= UART_LCR_STOP;

drivers/tty/serial/8250/8250_port.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,21 +2605,7 @@ static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
26052605
{
26062606
unsigned char cval;
26072607

2608-
switch (c_cflag & CSIZE) {
2609-
case CS5:
2610-
cval = UART_LCR_WLEN5;
2611-
break;
2612-
case CS6:
2613-
cval = UART_LCR_WLEN6;
2614-
break;
2615-
case CS7:
2616-
cval = UART_LCR_WLEN7;
2617-
break;
2618-
default:
2619-
case CS8:
2620-
cval = UART_LCR_WLEN8;
2621-
break;
2622-
}
2608+
cval = UART_LCR_WLEN(tty_get_char_size(c_cflag));
26232609

26242610
if (c_cflag & CSTOPB)
26252611
cval |= UART_LCR_STOP;

drivers/tty/serial/jsm/jsm_cls.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,21 +737,7 @@ static void cls_param(struct jsm_channel *ch)
737737
if (ch->ch_c_cflag & CSTOPB)
738738
lcr |= UART_LCR_STOP;
739739

740-
switch (ch->ch_c_cflag & CSIZE) {
741-
case CS5:
742-
lcr |= UART_LCR_WLEN5;
743-
break;
744-
case CS6:
745-
lcr |= UART_LCR_WLEN6;
746-
break;
747-
case CS7:
748-
lcr |= UART_LCR_WLEN7;
749-
break;
750-
case CS8:
751-
default:
752-
lcr |= UART_LCR_WLEN8;
753-
break;
754-
}
740+
lcr |= UART_LCR_WLEN(tty_get_char_size(ch->ch_c_cflag));
755741

756742
ier = readb(&ch->ch_cls_uart->ier);
757743
uart_lcr = readb(&ch->ch_cls_uart->lcr);

drivers/tty/serial/jsm/jsm_neo.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,21 +1008,7 @@ static void neo_param(struct jsm_channel *ch)
10081008
if (ch->ch_c_cflag & CSTOPB)
10091009
lcr |= UART_LCR_STOP;
10101010

1011-
switch (ch->ch_c_cflag & CSIZE) {
1012-
case CS5:
1013-
lcr |= UART_LCR_WLEN5;
1014-
break;
1015-
case CS6:
1016-
lcr |= UART_LCR_WLEN6;
1017-
break;
1018-
case CS7:
1019-
lcr |= UART_LCR_WLEN7;
1020-
break;
1021-
case CS8:
1022-
default:
1023-
lcr |= UART_LCR_WLEN8;
1024-
break;
1025-
}
1011+
lcr |= UART_LCR_WLEN(tty_get_char_size(ch->ch_c_cflag));
10261012

10271013
ier = readb(&ch->ch_neo_uart->ier);
10281014
uart_lcr = readb(&ch->ch_neo_uart->lcr);

drivers/tty/serial/omap-serial.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -808,21 +808,7 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
808808
unsigned long flags;
809809
unsigned int baud, quot;
810810

811-
switch (termios->c_cflag & CSIZE) {
812-
case CS5:
813-
cval = UART_LCR_WLEN5;
814-
break;
815-
case CS6:
816-
cval = UART_LCR_WLEN6;
817-
break;
818-
case CS7:
819-
cval = UART_LCR_WLEN7;
820-
break;
821-
default:
822-
case CS8:
823-
cval = UART_LCR_WLEN8;
824-
break;
825-
}
811+
cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag));
826812

827813
if (termios->c_cflag & CSTOPB)
828814
cval |= UART_LCR_STOP;

drivers/tty/serial/pxa.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -430,21 +430,7 @@ serial_pxa_set_termios(struct uart_port *port, struct ktermios *termios,
430430
unsigned int baud, quot;
431431
unsigned int dll;
432432

433-
switch (termios->c_cflag & CSIZE) {
434-
case CS5:
435-
cval = UART_LCR_WLEN5;
436-
break;
437-
case CS6:
438-
cval = UART_LCR_WLEN6;
439-
break;
440-
case CS7:
441-
cval = UART_LCR_WLEN7;
442-
break;
443-
default:
444-
case CS8:
445-
cval = UART_LCR_WLEN8;
446-
break;
447-
}
433+
cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag));
448434

449435
if (termios->c_cflag & CSTOPB)
450436
cval |= UART_LCR_STOP;

drivers/tty/serial/serial-tegra.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ static void tegra_uart_set_termios(struct uart_port *u,
12771277
unsigned int baud;
12781278
unsigned long flags;
12791279
unsigned int lcr;
1280+
unsigned char char_bits;
12801281
int symb_bit = 1;
12811282
struct clk *parent_clk = clk_get_parent(tup->uart_clk);
12821283
unsigned long parent_clk_rate = clk_get_rate(parent_clk);
@@ -1316,25 +1317,10 @@ static void tegra_uart_set_termios(struct uart_port *u,
13161317
}
13171318
}
13181319

1320+
char_bits = tty_get_char_size(termios->c_cflag);
1321+
symb_bit += char_bits;
13191322
lcr &= ~UART_LCR_WLEN8;
1320-
switch (termios->c_cflag & CSIZE) {
1321-
case CS5:
1322-
lcr |= UART_LCR_WLEN5;
1323-
symb_bit += 5;
1324-
break;
1325-
case CS6:
1326-
lcr |= UART_LCR_WLEN6;
1327-
symb_bit += 6;
1328-
break;
1329-
case CS7:
1330-
lcr |= UART_LCR_WLEN7;
1331-
symb_bit += 7;
1332-
break;
1333-
default:
1334-
lcr |= UART_LCR_WLEN8;
1335-
symb_bit += 8;
1336-
break;
1337-
}
1323+
lcr |= UART_LCR_WLEN(char_bits);
13381324

13391325
/* Stop bits */
13401326
if (termios->c_cflag & CSTOPB) {

drivers/tty/serial/vr41xx_siu.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -504,20 +504,7 @@ static void siu_set_termios(struct uart_port *port, struct ktermios *new,
504504
unsigned long flags;
505505

506506
c_cflag = new->c_cflag;
507-
switch (c_cflag & CSIZE) {
508-
case CS5:
509-
lcr = UART_LCR_WLEN5;
510-
break;
511-
case CS6:
512-
lcr = UART_LCR_WLEN6;
513-
break;
514-
case CS7:
515-
lcr = UART_LCR_WLEN7;
516-
break;
517-
default:
518-
lcr = UART_LCR_WLEN8;
519-
break;
520-
}
507+
lcr = UART_LCR_WLEN(tty_get_char_size(c_cflag));
521508

522509
if (c_cflag & CSTOPB)
523510
lcr |= UART_LCR_STOP;

0 commit comments

Comments
 (0)