Commit ff11d0780376a3821d790a6ceb8b297d976b14fe
Committed by
Linus Torvalds
1 parent
789c7048bf
Exists in
master
and in
7 other branches
dz: clean up and improve the setup of termios settings
A set of changes to the way termios settings are propagated to the serial port hardware. The DZ11 only supports a selection of fixed baud settings, so some requests may not be fulfilled. Keep the old setting in such a case and failing that resort to 9600bps. Also add a missing update of the transmit timeout. And remove the explicit encoding of the line selected from writes to the Line Parameters Register as it has been preencoded by the ->set_termios() call already. Finally, remove a duplicate macro for the Receiver Enable bit. Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 56 additions and 51 deletions Side-by-side Diff
drivers/serial/dz.c
... | ... | @@ -128,8 +128,8 @@ |
128 | 128 | { |
129 | 129 | struct dz_port *dport = (struct dz_port *)uport; |
130 | 130 | |
131 | - dport->cflag &= ~DZ_CREAD; | |
132 | - dz_out(dport, DZ_LPR, dport->cflag | dport->port.line); | |
131 | + dport->cflag &= ~DZ_RXENAB; | |
132 | + dz_out(dport, DZ_LPR, dport->cflag); | |
133 | 133 | } |
134 | 134 | |
135 | 135 | static void dz_enable_ms(struct uart_port *port) |
136 | 136 | |
... | ... | @@ -464,12 +464,51 @@ |
464 | 464 | spin_unlock_irqrestore(&uport->lock, flags); |
465 | 465 | } |
466 | 466 | |
467 | +static int dz_encode_baud_rate(unsigned int baud) | |
468 | +{ | |
469 | + switch (baud) { | |
470 | + case 50: | |
471 | + return DZ_B50; | |
472 | + case 75: | |
473 | + return DZ_B75; | |
474 | + case 110: | |
475 | + return DZ_B110; | |
476 | + case 134: | |
477 | + return DZ_B134; | |
478 | + case 150: | |
479 | + return DZ_B150; | |
480 | + case 300: | |
481 | + return DZ_B300; | |
482 | + case 600: | |
483 | + return DZ_B600; | |
484 | + case 1200: | |
485 | + return DZ_B1200; | |
486 | + case 1800: | |
487 | + return DZ_B1800; | |
488 | + case 2000: | |
489 | + return DZ_B2000; | |
490 | + case 2400: | |
491 | + return DZ_B2400; | |
492 | + case 3600: | |
493 | + return DZ_B3600; | |
494 | + case 4800: | |
495 | + return DZ_B4800; | |
496 | + case 7200: | |
497 | + return DZ_B7200; | |
498 | + case 9600: | |
499 | + return DZ_B9600; | |
500 | + default: | |
501 | + return -1; | |
502 | + } | |
503 | +} | |
504 | + | |
467 | 505 | static void dz_set_termios(struct uart_port *uport, struct ktermios *termios, |
468 | 506 | struct ktermios *old_termios) |
469 | 507 | { |
470 | 508 | struct dz_port *dport = (struct dz_port *)uport; |
471 | 509 | unsigned long flags; |
472 | 510 | unsigned int cflag, baud; |
511 | + int bflag; | |
473 | 512 | |
474 | 513 | cflag = dport->port.line; |
475 | 514 | |
476 | 515 | |
477 | 516 | |
... | ... | @@ -496,60 +535,26 @@ |
496 | 535 | cflag |= DZ_PARODD; |
497 | 536 | |
498 | 537 | baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600); |
499 | - switch (baud) { | |
500 | - case 50: | |
501 | - cflag |= DZ_B50; | |
502 | - break; | |
503 | - case 75: | |
504 | - cflag |= DZ_B75; | |
505 | - break; | |
506 | - case 110: | |
507 | - cflag |= DZ_B110; | |
508 | - break; | |
509 | - case 134: | |
510 | - cflag |= DZ_B134; | |
511 | - break; | |
512 | - case 150: | |
513 | - cflag |= DZ_B150; | |
514 | - break; | |
515 | - case 300: | |
516 | - cflag |= DZ_B300; | |
517 | - break; | |
518 | - case 600: | |
519 | - cflag |= DZ_B600; | |
520 | - break; | |
521 | - case 1200: | |
522 | - cflag |= DZ_B1200; | |
523 | - break; | |
524 | - case 1800: | |
525 | - cflag |= DZ_B1800; | |
526 | - break; | |
527 | - case 2000: | |
528 | - cflag |= DZ_B2000; | |
529 | - break; | |
530 | - case 2400: | |
531 | - cflag |= DZ_B2400; | |
532 | - break; | |
533 | - case 3600: | |
534 | - cflag |= DZ_B3600; | |
535 | - break; | |
536 | - case 4800: | |
537 | - cflag |= DZ_B4800; | |
538 | - break; | |
539 | - case 7200: | |
540 | - cflag |= DZ_B7200; | |
541 | - break; | |
542 | - case 9600: | |
543 | - default: | |
544 | - cflag |= DZ_B9600; | |
538 | + bflag = dz_encode_baud_rate(baud); | |
539 | + if (bflag < 0) { /* Try to keep unchanged. */ | |
540 | + baud = uart_get_baud_rate(uport, old_termios, NULL, 50, 9600); | |
541 | + bflag = dz_encode_baud_rate(baud); | |
542 | + if (bflag < 0) { /* Resort to 9600. */ | |
543 | + baud = 9600; | |
544 | + bflag = DZ_B9600; | |
545 | + } | |
546 | + tty_termios_encode_baud_rate(termios, baud, baud); | |
545 | 547 | } |
548 | + cflag |= bflag; | |
546 | 549 | |
547 | 550 | if (termios->c_cflag & CREAD) |
548 | 551 | cflag |= DZ_RXENAB; |
549 | 552 | |
550 | 553 | spin_lock_irqsave(&dport->port.lock, flags); |
551 | 554 | |
552 | - dz_out(dport, DZ_LPR, cflag | dport->port.line); | |
555 | + uart_update_timeout(uport, termios->c_cflag, baud); | |
556 | + | |
557 | + dz_out(dport, DZ_LPR, cflag); | |
553 | 558 | dport->cflag = cflag; |
554 | 559 | |
555 | 560 | /* setup accept flag */ |
drivers/serial/dz.h
... | ... | @@ -109,8 +109,8 @@ |
109 | 109 | #define DZ_B7200 0x0D00 |
110 | 110 | #define DZ_B9600 0x0E00 |
111 | 111 | |
112 | -#define DZ_CREAD 0x1000 /* Enable receiver */ | |
113 | -#define DZ_RXENAB 0x1000 /* enable receive char */ | |
112 | +#define DZ_RXENAB 0x1000 /* Receiver Enable */ | |
113 | + | |
114 | 114 | /* |
115 | 115 | * Addresses for the DZ registers |
116 | 116 | */ |