Lines Matching +full:em +full:- +full:uart
1 // SPDX-License-Identifier: GPL-2.0
9 * Copyright (C) 1998-2000 Harald Koerfgen
20 * DIN-7 MJ-4 signal SCC
21 * 2 1 TxD <- A.TxD
22 * 3 4 RxD -> A.RxD
24 * EIA-232/EIA-423:
25 * DB-25 MMJ-6 signal SCC
26 * 2 2 TxD <- B.TxD
27 * 3 5 RxD -> B.RxD
28 * 4 RTS <- ~A.RTS
29 * 5 CTS -> ~B.CTS
30 * 6 6 DSR -> ~A.SYNC
31 * 8 CD -> ~B.DCD
32 * 12 DSRS(DCE) -> ~A.CTS (*)
33 * 15 TxC -> B.TxC
34 * 17 RxC -> B.RxC
35 * 20 1 DTR <- ~A.DTR
36 * 22 RI -> ~A.DCD
37 * 23 DSRS(DTE) <- ~B.RTS
39 * (*) EIA-232 defines the signal at this pin to be SCD, while DSRS(DCE)
76 MODULE_AUTHOR("Maciej W. Rozycki <macro@linux-mips.org>");
96 of the 16-bit IOBUS. */
140 void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET; in read_zsreg()
155 void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET; in write_zsreg()
169 void __iomem *data = zport->port.membase + in read_zsdata()
180 void __iomem *data = zport->port.membase + in write_zsdata()
198 if (!zport->scc) in zs_dump()
202 printk("W%-2d = 0x%02x\t", j, zport->regs[j]); in zs_dump()
205 printk("R%-2d = 0x%02x\t", j, read_zsreg(zport, j)); in zs_dump()
232 while ((read_zsreg(zport, R0) & Rx_CH_AV) && --loops) in zs_receive_drain()
239 struct zs_scc *scc = zport->scc; in zs_transmit_drain()
242 while (!(read_zsreg(zport, R0) & Tx_BUF_EMP) && --loops) { in zs_transmit_drain()
243 zs_spin_unlock_cond_irq(&scc->zlock, irq); in zs_transmit_drain()
245 zs_spin_lock_cond_irq(&scc->zlock, irq); in zs_transmit_drain()
252 struct zs_scc *scc = zport->scc; in zs_line_drain()
255 while (!(read_zsreg(zport, R1) & ALL_SNT) && --loops) { in zs_line_drain()
256 zs_spin_unlock_cond_irq(&scc->zlock, irq); in zs_line_drain()
258 zs_spin_lock_cond_irq(&scc->zlock, irq); in zs_line_drain()
268 /* Load 'em up. */ in load_zsregs()
295 * zs_tx_empty() -- get the transmitter empty status
297 * Purpose: Let user call ioctl() to get info when the UART physically
307 struct zs_scc *scc = zport->scc; in zs_tx_empty()
311 spin_lock_irqsave(&scc->zlock, flags); in zs_tx_empty()
313 spin_unlock_irqrestore(&scc->zlock, flags); in zs_tx_empty()
337 struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A]; in zs_raw_get_mctrl()
344 struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A]; in zs_raw_xor_mctrl()
351 mask_a = zport_a->regs[15]; in zs_raw_xor_mctrl()
352 mask_b = zport->regs[15]; in zs_raw_xor_mctrl()
359 mctrl = zport->mctrl; in zs_raw_xor_mctrl()
365 delta = mctrl ^ zport->mctrl; in zs_raw_xor_mctrl()
367 zport->mctrl = mctrl; in zs_raw_xor_mctrl()
375 struct zs_scc *scc = zport->scc; in zs_get_mctrl()
378 spin_lock(&scc->zlock); in zs_get_mctrl()
380 spin_unlock(&scc->zlock); in zs_get_mctrl()
388 struct zs_scc *scc = zport->scc; in zs_set_mctrl()
389 struct zs_port *zport_a = &scc->zport[ZS_CHAN_A]; in zs_set_mctrl()
392 spin_lock(&scc->zlock); in zs_set_mctrl()
395 zport_a->regs[5] |= DTR; in zs_set_mctrl()
397 zport_a->regs[5] &= ~DTR; in zs_set_mctrl()
399 zport_a->regs[5] |= RTS; in zs_set_mctrl()
401 zport_a->regs[5] &= ~RTS; in zs_set_mctrl()
402 write_zsreg(zport_a, R5, zport_a->regs[5]); in zs_set_mctrl()
406 oldloop = zport->regs[14]; in zs_set_mctrl()
413 zport->regs[14] = newloop; in zs_set_mctrl()
414 write_zsreg(zport, R14, zport->regs[14]); in zs_set_mctrl()
416 spin_unlock(&scc->zlock); in zs_set_mctrl()
422 zport->tx_stopped = 1; in zs_raw_stop_tx()
428 struct zs_scc *scc = zport->scc; in zs_stop_tx()
430 spin_lock(&scc->zlock); in zs_stop_tx()
432 spin_unlock(&scc->zlock); in zs_stop_tx()
440 struct zs_scc *scc = zport->scc; in zs_start_tx()
442 spin_lock(&scc->zlock); in zs_start_tx()
443 if (zport->tx_stopped) { in zs_start_tx()
445 zport->tx_stopped = 0; in zs_start_tx()
448 spin_unlock(&scc->zlock); in zs_start_tx()
454 struct zs_scc *scc = zport->scc; in zs_stop_rx()
455 struct zs_port *zport_a = &scc->zport[ZS_CHAN_A]; in zs_stop_rx()
457 spin_lock(&scc->zlock); in zs_stop_rx()
458 zport->regs[15] &= ~BRKIE; in zs_stop_rx()
459 zport->regs[1] &= ~(RxINT_MASK | TxINT_ENAB); in zs_stop_rx()
460 zport->regs[1] |= RxINT_DISAB; in zs_stop_rx()
463 /* A-side DCD tracks RI and SYNC tracks DSR. */ in zs_stop_rx()
464 zport_a->regs[15] &= ~(DCDIE | SYNCIE); in zs_stop_rx()
465 write_zsreg(zport_a, R15, zport_a->regs[15]); in zs_stop_rx()
466 if (!(zport_a->regs[15] & BRKIE)) { in zs_stop_rx()
467 zport_a->regs[1] &= ~EXT_INT_ENAB; in zs_stop_rx()
468 write_zsreg(zport_a, R1, zport_a->regs[1]); in zs_stop_rx()
471 /* This-side DCD tracks DCD and CTS tracks CTS. */ in zs_stop_rx()
472 zport->regs[15] &= ~(DCDIE | CTSIE); in zs_stop_rx()
473 zport->regs[1] &= ~EXT_INT_ENAB; in zs_stop_rx()
476 if (!(zport->regs[15] & (DCDIE | SYNCIE))) in zs_stop_rx()
477 zport->regs[1] &= ~EXT_INT_ENAB; in zs_stop_rx()
480 write_zsreg(zport, R15, zport->regs[15]); in zs_stop_rx()
481 write_zsreg(zport, R1, zport->regs[1]); in zs_stop_rx()
482 spin_unlock(&scc->zlock); in zs_stop_rx()
488 struct zs_scc *scc = zport->scc; in zs_enable_ms()
489 struct zs_port *zport_a = &scc->zport[ZS_CHAN_A]; in zs_enable_ms()
494 spin_lock(&scc->zlock); in zs_enable_ms()
497 if (!(zport_a->regs[1] & EXT_INT_ENAB)) in zs_enable_ms()
500 /* A-side DCD tracks RI and SYNC tracks DSR. */ in zs_enable_ms()
501 zport_a->regs[1] |= EXT_INT_ENAB; in zs_enable_ms()
502 zport_a->regs[15] |= DCDIE | SYNCIE; in zs_enable_ms()
504 /* This-side DCD tracks DCD and CTS tracks CTS. */ in zs_enable_ms()
505 zport->regs[15] |= DCDIE | CTSIE; in zs_enable_ms()
509 write_zsreg(zport_a, R1, zport_a->regs[1]); in zs_enable_ms()
510 write_zsreg(zport_a, R15, zport_a->regs[15]); in zs_enable_ms()
511 write_zsreg(zport, R15, zport->regs[15]); in zs_enable_ms()
512 spin_unlock(&scc->zlock); in zs_enable_ms()
518 struct zs_scc *scc = zport->scc; in zs_break_ctl()
521 spin_lock_irqsave(&scc->zlock, flags); in zs_break_ctl()
522 if (break_state == -1) in zs_break_ctl()
523 zport->regs[5] |= SND_BRK; in zs_break_ctl()
525 zport->regs[5] &= ~SND_BRK; in zs_break_ctl()
526 write_zsreg(zport, R5, zport->regs[5]); in zs_break_ctl()
527 spin_unlock_irqrestore(&scc->zlock, flags); in zs_break_ctl()
539 struct uart_port *uport = &zport->port; in zs_receive_chars()
540 struct zs_scc *scc = zport->scc; in zs_receive_chars()
546 for (count = 16; count; count--) { in zs_receive_chars()
547 spin_lock(&scc->zlock); in zs_receive_chars()
549 spin_unlock(&scc->zlock); in zs_receive_chars()
553 spin_lock(&scc->zlock); in zs_receive_chars()
556 spin_unlock(&scc->zlock); in zs_receive_chars()
560 icount = &uport->icount; in zs_receive_chars()
561 icount->rx++; in zs_receive_chars()
565 status |= zport->tty_break; in zs_receive_chars()
568 zport->tty_break = 0; in zs_receive_chars()
572 spin_lock(&scc->zlock); in zs_receive_chars()
574 spin_unlock(&scc->zlock); in zs_receive_chars()
578 icount->brk++; in zs_receive_chars()
583 icount->frame++; in zs_receive_chars()
585 icount->parity++; in zs_receive_chars()
587 icount->overrun++; in zs_receive_chars()
589 status &= uport->read_status_mask; in zs_receive_chars()
604 tty_flip_buffer_push(&uport->state->port); in zs_receive_chars()
609 struct circ_buf *xmit = &zport->port.state->xmit; in zs_raw_transmit_chars()
612 if (zport->port.x_char) { in zs_raw_transmit_chars()
613 write_zsdata(zport, zport->port.x_char); in zs_raw_transmit_chars()
614 zport->port.icount.tx++; in zs_raw_transmit_chars()
615 zport->port.x_char = 0; in zs_raw_transmit_chars()
620 if (uart_circ_empty(xmit) || uart_tx_stopped(&zport->port)) { in zs_raw_transmit_chars()
626 write_zsdata(zport, xmit->buf[xmit->tail]); in zs_raw_transmit_chars()
627 uart_xmit_advance(&zport->port, 1); in zs_raw_transmit_chars()
630 uart_write_wakeup(&zport->port); in zs_raw_transmit_chars()
639 struct zs_scc *scc = zport->scc; in zs_transmit_chars()
641 spin_lock(&scc->zlock); in zs_transmit_chars()
643 spin_unlock(&scc->zlock); in zs_transmit_chars()
648 struct uart_port *uport = &zport->port; in zs_status_handle()
649 struct zs_scc *scc = zport->scc; in zs_status_handle()
653 spin_lock(&scc->zlock); in zs_status_handle()
658 if (zport->regs[15] & BRKIE) { in zs_status_handle()
660 if (brk && !zport->brk) { in zs_status_handle()
661 spin_unlock(&scc->zlock); in zs_status_handle()
663 zport->tty_break = Rx_SYS; in zs_status_handle()
665 zport->tty_break = Rx_BRK; in zs_status_handle()
666 spin_lock(&scc->zlock); in zs_status_handle()
668 zport->brk = brk; in zs_status_handle()
673 spin_unlock(&scc->zlock); in zs_status_handle()
677 zport->mctrl & TIOCM_CTS); in zs_status_handle()
680 zport->mctrl & TIOCM_CAR); in zs_status_handle()
682 uport->icount.dsr++; in zs_status_handle()
684 uport->icount.rng++; in zs_status_handle()
687 wake_up_interruptible(&uport->state->port.delta_msr_wait); in zs_status_handle()
689 spin_lock(&scc->zlock); in zs_status_handle()
695 spin_unlock(&scc->zlock); in zs_status_handle()
704 struct zs_port *zport_a = &scc->zport[ZS_CHAN_A]; in zs_interrupt()
705 struct zs_port *zport_b = &scc->zport[ZS_CHAN_B]; in zs_interrupt()
717 for (count = 16; count; count--) { in zs_interrupt()
718 spin_lock(&scc->zlock); in zs_interrupt()
720 spin_unlock(&scc->zlock); in zs_interrupt()
755 struct zs_scc *scc = zport->scc; in zs_startup()
760 irq_guard = atomic_add_return(1, &scc->irq_guard); in zs_startup()
762 ret = request_irq(zport->port.irq, zs_interrupt, in zs_startup()
765 atomic_add(-1, &scc->irq_guard); in zs_startup()
767 zport->port.irq); in zs_startup()
772 spin_lock_irqsave(&scc->zlock, flags); in zs_startup()
781 if (!(zport->regs[1] & EXT_INT_ENAB)) in zs_startup()
785 zport->regs[1] &= ~RxINT_MASK; in zs_startup()
786 zport->regs[1] |= RxINT_ALL | TxINT_ENAB | EXT_INT_ENAB; in zs_startup()
787 zport->regs[3] |= RxENABLE; in zs_startup()
788 zport->regs[15] |= BRKIE; in zs_startup()
789 write_zsreg(zport, R1, zport->regs[1]); in zs_startup()
790 write_zsreg(zport, R3, zport->regs[3]); in zs_startup()
791 write_zsreg(zport, R5, zport->regs[5]); in zs_startup()
792 write_zsreg(zport, R15, zport->regs[15]); in zs_startup()
795 zport->mctrl = zs_raw_get_mctrl(zport); in zs_startup()
796 zport->brk = read_zsreg(zport, R0) & BRK_ABRT; in zs_startup()
798 zport->tx_stopped = 1; in zs_startup()
800 spin_unlock_irqrestore(&scc->zlock, flags); in zs_startup()
808 struct zs_scc *scc = zport->scc; in zs_shutdown()
812 spin_lock_irqsave(&scc->zlock, flags); in zs_shutdown()
814 zport->regs[3] &= ~RxENABLE; in zs_shutdown()
815 write_zsreg(zport, R5, zport->regs[5]); in zs_shutdown()
816 write_zsreg(zport, R3, zport->regs[3]); in zs_shutdown()
818 spin_unlock_irqrestore(&scc->zlock, flags); in zs_shutdown()
820 irq_guard = atomic_add_return(-1, &scc->irq_guard); in zs_shutdown()
822 free_irq(zport->port.irq, scc); in zs_shutdown()
828 struct zs_scc *scc = zport->scc; in zs_reset()
832 spin_lock_irqsave(&scc->zlock, flags); in zs_reset()
834 if (!scc->initialised) { in zs_reset()
842 scc->initialised = 1; in zs_reset()
844 load_zsregs(zport, zport->regs, irq); in zs_reset()
845 spin_unlock_irqrestore(&scc->zlock, flags); in zs_reset()
852 struct zs_scc *scc = zport->scc; in zs_set_termios()
853 struct zs_port *zport_a = &scc->zport[ZS_CHAN_A]; in zs_set_termios()
858 spin_lock_irqsave(&scc->zlock, flags); in zs_set_termios()
862 zport->regs[3] &= ~RxNBITS_MASK; in zs_set_termios()
863 zport->regs[5] &= ~TxNBITS_MASK; in zs_set_termios()
864 switch (termios->c_cflag & CSIZE) { in zs_set_termios()
866 zport->regs[3] |= Rx5; in zs_set_termios()
867 zport->regs[5] |= Tx5; in zs_set_termios()
870 zport->regs[3] |= Rx6; in zs_set_termios()
871 zport->regs[5] |= Tx6; in zs_set_termios()
874 zport->regs[3] |= Rx7; in zs_set_termios()
875 zport->regs[5] |= Tx7; in zs_set_termios()
879 zport->regs[3] |= Rx8; in zs_set_termios()
880 zport->regs[5] |= Tx8; in zs_set_termios()
885 zport->regs[4] &= ~(XCLK_MASK | SB_MASK | PAR_ENA | PAR_EVEN); in zs_set_termios()
886 if (termios->c_cflag & CSTOPB) in zs_set_termios()
887 zport->regs[4] |= SB2; in zs_set_termios()
889 zport->regs[4] |= SB1; in zs_set_termios()
890 if (termios->c_cflag & PARENB) in zs_set_termios()
891 zport->regs[4] |= PAR_ENA; in zs_set_termios()
892 if (!(termios->c_cflag & PARODD)) in zs_set_termios()
893 zport->regs[4] |= PAR_EVEN; in zs_set_termios()
894 switch (zport->clk_mode) { in zs_set_termios()
896 zport->regs[4] |= X64CLK; in zs_set_termios()
899 zport->regs[4] |= X32CLK; in zs_set_termios()
902 zport->regs[4] |= X16CLK; in zs_set_termios()
905 zport->regs[4] |= X1CLK; in zs_set_termios()
912 uport->uartclk / zport->clk_mode / 4); in zs_set_termios()
914 brg = ZS_BPS_TO_BRG(baud, uport->uartclk / zport->clk_mode); in zs_set_termios()
915 zport->regs[12] = brg & 0xff; in zs_set_termios()
916 zport->regs[13] = (brg >> 8) & 0xff; in zs_set_termios()
918 uart_update_timeout(uport, termios->c_cflag, baud); in zs_set_termios()
920 uport->read_status_mask = Rx_OVR; in zs_set_termios()
921 if (termios->c_iflag & INPCK) in zs_set_termios()
922 uport->read_status_mask |= FRM_ERR | PAR_ERR; in zs_set_termios()
923 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in zs_set_termios()
924 uport->read_status_mask |= Rx_BRK; in zs_set_termios()
926 uport->ignore_status_mask = 0; in zs_set_termios()
927 if (termios->c_iflag & IGNPAR) in zs_set_termios()
928 uport->ignore_status_mask |= FRM_ERR | PAR_ERR; in zs_set_termios()
929 if (termios->c_iflag & IGNBRK) { in zs_set_termios()
930 uport->ignore_status_mask |= Rx_BRK; in zs_set_termios()
931 if (termios->c_iflag & IGNPAR) in zs_set_termios()
932 uport->ignore_status_mask |= Rx_OVR; in zs_set_termios()
935 if (termios->c_cflag & CREAD) in zs_set_termios()
936 zport->regs[3] |= RxENABLE; in zs_set_termios()
938 zport->regs[3] &= ~RxENABLE; in zs_set_termios()
941 if (!(termios->c_cflag & CLOCAL)) { in zs_set_termios()
942 zport->regs[15] |= DCDIE; in zs_set_termios()
944 zport->regs[15] &= ~DCDIE; in zs_set_termios()
945 if (termios->c_cflag & CRTSCTS) { in zs_set_termios()
946 zport->regs[15] |= CTSIE; in zs_set_termios()
948 zport->regs[15] &= ~CTSIE; in zs_set_termios()
953 load_zsregs(zport, zport->regs, irq); in zs_set_termios()
955 spin_unlock_irqrestore(&scc->zlock, flags); in zs_set_termios()
960 * Required solely so that the initial PROM-based console
969 zport->regs[5] |= TxENAB; in zs_pm()
971 zport->regs[5] &= ~TxENAB; in zs_pm()
972 write_zsreg(zport, R5, zport->regs[5]); in zs_pm()
983 iounmap(uport->membase); in zs_release_port()
984 uport->membase = NULL; in zs_release_port()
985 release_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE); in zs_release_port()
990 if (!uport->membase) in zs_map_port()
991 uport->membase = ioremap(uport->mapbase, in zs_map_port()
993 if (!uport->membase) { in zs_map_port()
995 return -ENOMEM; in zs_map_port()
1004 if (!request_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE, "scc")) { in zs_request_port()
1006 return -EBUSY; in zs_request_port()
1010 release_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE); in zs_request_port()
1024 uport->type = PORT_ZS; in zs_config_port()
1035 if (ser->type != PORT_UNKNOWN && ser->type != PORT_ZS) in zs_verify_port()
1036 ret = -EINVAL; in zs_verify_port()
1037 if (ser->irq != uport->irq) in zs_verify_port()
1038 ret = -EINVAL; in zs_verify_port()
1039 if (ser->baud_base != uport->uartclk / zport->clk_mode / 4) in zs_verify_port()
1040 ret = -EINVAL; in zs_verify_port()
1092 return -ENXIO; in zs_probe_sccs()
1100 struct uart_port *uport = &zport->port; in zs_probe_sccs()
1102 zport->scc = &zs_sccs[chip]; in zs_probe_sccs()
1103 zport->clk_mode = 16; in zs_probe_sccs()
1105 uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ZS_CONSOLE); in zs_probe_sccs()
1106 uport->irq = zs_parms.irq[chip]; in zs_probe_sccs()
1107 uport->uartclk = ZS_CLOCK; in zs_probe_sccs()
1108 uport->fifosize = 1; in zs_probe_sccs()
1109 uport->iotype = UPIO_MEM; in zs_probe_sccs()
1110 uport->flags = UPF_BOOT_AUTOCONF; in zs_probe_sccs()
1111 uport->ops = &zs_ops; in zs_probe_sccs()
1112 uport->line = chip * ZS_NUM_CHAN + side; in zs_probe_sccs()
1113 uport->mapbase = dec_kn_slot_base + in zs_probe_sccs()
1118 zport->regs[i] = zs_init_regs[i]; in zs_probe_sccs()
1130 struct zs_scc *scc = zport->scc; in zs_console_putchar()
1134 spin_lock_irqsave(&scc->zlock, flags); in zs_console_putchar()
1138 spin_unlock_irqrestore(&scc->zlock, flags); in zs_console_putchar()
1148 int chip = co->index / ZS_NUM_CHAN, side = co->index % ZS_NUM_CHAN; in zs_console_write()
1150 struct zs_scc *scc = zport->scc; in zs_console_write()
1156 spin_lock_irqsave(&scc->zlock, flags); in zs_console_write()
1157 txint = zport->regs[1]; in zs_console_write()
1158 txenb = zport->regs[5]; in zs_console_write()
1160 zport->regs[1] = txint & ~TxINT_ENAB; in zs_console_write()
1161 write_zsreg(zport, R1, zport->regs[1]); in zs_console_write()
1164 zport->regs[5] = txenb | TxENAB; in zs_console_write()
1165 write_zsreg(zport, R5, zport->regs[5]); in zs_console_write()
1167 spin_unlock_irqrestore(&scc->zlock, flags); in zs_console_write()
1169 uart_console_write(&zport->port, s, count, zs_console_putchar); in zs_console_write()
1172 spin_lock_irqsave(&scc->zlock, flags); in zs_console_write()
1176 zport->regs[5] &= ~TxENAB; in zs_console_write()
1177 write_zsreg(zport, R5, zport->regs[5]); in zs_console_write()
1180 zport->regs[1] |= TxINT_ENAB; in zs_console_write()
1181 write_zsreg(zport, R1, zport->regs[1]); in zs_console_write()
1184 if (!zport->tx_stopped) in zs_console_write()
1187 spin_unlock_irqrestore(&scc->zlock, flags); in zs_console_write()
1192 * - construct a cflag setting for the first uart_open()
1193 * - initialise the serial port
1194 * Return non-zero if we didn't find a serial port.
1198 int chip = co->index / ZS_NUM_CHAN, side = co->index % ZS_NUM_CHAN; in zs_console_setup()
1200 struct uart_port *uport = &zport->port; in zs_console_setup()
1212 zs_pm(uport, 0, -1); in zs_console_setup()
1226 .index = -1,
1280 struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN]; in zs_init()
1281 struct uart_port *uport = &zport->port; in zs_init()
1283 if (zport->scc) in zs_init()
1294 for (i = ZS_NUM_SCCS * ZS_NUM_CHAN - 1; i >= 0; i--) { in zs_exit()
1296 struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN]; in zs_exit()
1297 struct uart_port *uport = &zport->port; in zs_exit()
1299 if (zport->scc) in zs_exit()