Lines Matching +full:shut +full:- +full:down +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
14 * (C) 2005-2006 MontaVista Software, Inc.
28 #include <linux/dma-mapping.h>
59 cpm_command(port->command, cmd); in cpm_line_cr_cmd()
69 cbd_t __iomem *bdp = pinfo->tx_bd_base; in cpm_uart_tx_empty()
73 if (in_be16(&bdp->cbd_sc) & BD_SC_READY) in cpm_uart_tx_empty()
76 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) { in cpm_uart_tx_empty()
83 pr_debug("CPM uart[%d]:tx_empty: %d\n", port->line, ret); in cpm_uart_tx_empty()
93 if (pinfo->gpios[GPIO_RTS]) in cpm_uart_set_mctrl()
94 gpiod_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS)); in cpm_uart_set_mctrl()
96 if (pinfo->gpios[GPIO_DTR]) in cpm_uart_set_mctrl()
97 gpiod_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR)); in cpm_uart_set_mctrl()
106 if (pinfo->gpios[GPIO_CTS]) { in cpm_uart_get_mctrl()
107 if (gpiod_get_value(pinfo->gpios[GPIO_CTS])) in cpm_uart_get_mctrl()
111 if (pinfo->gpios[GPIO_DSR]) { in cpm_uart_get_mctrl()
112 if (gpiod_get_value(pinfo->gpios[GPIO_DSR])) in cpm_uart_get_mctrl()
116 if (pinfo->gpios[GPIO_DCD]) { in cpm_uart_get_mctrl()
117 if (gpiod_get_value(pinfo->gpios[GPIO_DCD])) in cpm_uart_get_mctrl()
121 if (pinfo->gpios[GPIO_RI]) { in cpm_uart_get_mctrl()
122 if (!gpiod_get_value(pinfo->gpios[GPIO_RI])) in cpm_uart_get_mctrl()
136 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_stop_tx()
137 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_stop_tx()
139 pr_debug("CPM uart[%d]:stop tx\n", port->line); in cpm_uart_stop_tx()
142 clrbits8(&smcp->smc_smcm, SMCM_TX); in cpm_uart_stop_tx()
144 clrbits16(&sccp->scc_sccm, UART_SCCM_TX); in cpm_uart_stop_tx()
154 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_start_tx()
155 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_start_tx()
157 pr_debug("CPM uart[%d]:start tx\n", port->line); in cpm_uart_start_tx()
160 if (in_8(&smcp->smc_smcm) & SMCM_TX) in cpm_uart_start_tx()
163 if (in_be16(&sccp->scc_sccm) & UART_SCCM_TX) in cpm_uart_start_tx()
169 setbits8(&smcp->smc_smcm, SMCM_TX); in cpm_uart_start_tx()
171 setbits16(&sccp->scc_sccm, UART_SCCM_TX); in cpm_uart_start_tx()
183 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_stop_rx()
184 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_stop_rx()
186 pr_debug("CPM uart[%d]:stop rx\n", port->line); in cpm_uart_stop_rx()
189 clrbits8(&smcp->smc_smcm, SMCM_RX); in cpm_uart_stop_rx()
191 clrbits16(&sccp->scc_sccm, UART_SCCM_RX); in cpm_uart_stop_rx()
202 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line, in cpm_uart_break_ctl()
216 pr_debug("CPM uart[%d]:TX INT\n", port->line); in cpm_uart_int_tx()
233 struct tty_port *tport = &port->state->port; in cpm_uart_int_rx()
240 pr_debug("CPM uart[%d]:RX INT\n", port->line); in cpm_uart_int_rx()
245 bdp = pinfo->rx_cur; in cpm_uart_int_rx()
254 status = in_be16(&bdp->cbd_sc); in cpm_uart_int_rx()
259 /* get number of characters, and check spce in flip-buffer */ in cpm_uart_int_rx()
260 i = in_be16(&bdp->cbd_datlen); in cpm_uart_int_rx()
263 * later, which will be the next rx-interrupt or a timeout in cpm_uart_int_rx()
271 cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); in cpm_uart_int_rx()
274 while (i-- > 0) { in cpm_uart_int_rx()
276 port->icount.rx++; in cpm_uart_int_rx()
293 } /* End while (i--) */ in cpm_uart_int_rx()
296 clrbits16(&bdp->cbd_sc, BD_SC_BR | BD_SC_FR | BD_SC_PR | in cpm_uart_int_rx()
298 setbits16(&bdp->cbd_sc, BD_SC_EMPTY); in cpm_uart_int_rx()
300 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) in cpm_uart_int_rx()
301 bdp = pinfo->rx_bd_base; in cpm_uart_int_rx()
308 pinfo->rx_cur = bdp; in cpm_uart_int_rx()
320 port->icount.brk++; in cpm_uart_int_rx()
322 port->icount.parity++; in cpm_uart_int_rx()
324 port->icount.frame++; in cpm_uart_int_rx()
326 port->icount.overrun++; in cpm_uart_int_rx()
329 status &= port->read_status_mask; in cpm_uart_int_rx()
348 port->sysrq = 0; in cpm_uart_int_rx()
360 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_int()
361 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_int()
363 pr_debug("CPM uart[%d]:IRQ\n", port->line); in cpm_uart_int()
366 events = in_8(&smcp->smc_smce); in cpm_uart_int()
367 out_8(&smcp->smc_smce, events); in cpm_uart_int()
375 events = in_be16(&sccp->scc_scce); in cpm_uart_int()
376 out_be16(&sccp->scc_scce, events); in cpm_uart_int()
393 pr_debug("CPM uart[%d]:startup\n", port->line); in cpm_uart_startup()
396 if (!(pinfo->flags & FLAG_CONSOLE)) { in cpm_uart_startup()
399 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN); in cpm_uart_startup()
400 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX); in cpm_uart_startup()
402 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR); in cpm_uart_startup()
403 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); in cpm_uart_startup()
407 out_be32(&pinfo->smcup->smc_rstate, 0); in cpm_uart_startup()
408 out_be32(&pinfo->smcup->smc_tstate, 0); in cpm_uart_startup()
409 out_be16(&pinfo->smcup->smc_rbptr, in cpm_uart_startup()
410 in_be16(&pinfo->smcup->smc_rbase)); in cpm_uart_startup()
411 out_be16(&pinfo->smcup->smc_tbptr, in cpm_uart_startup()
412 in_be16(&pinfo->smcup->smc_tbase)); in cpm_uart_startup()
418 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port); in cpm_uart_startup()
422 /* Startup rx-int */ in cpm_uart_startup()
424 setbits8(&pinfo->smcp->smc_smcm, SMCM_RX); in cpm_uart_startup()
425 setbits16(&pinfo->smcp->smc_smcmr, (SMCMR_REN | SMCMR_TEN)); in cpm_uart_startup()
427 setbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); in cpm_uart_startup()
428 setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT)); in cpm_uart_startup()
437 schedule_timeout(pinfo->wait_closing); in cpm_uart_wait_until_send()
448 pr_debug("CPM uart[%d]:shutdown\n", port->line); in cpm_uart_shutdown()
451 free_irq(port->irq, port); in cpm_uart_shutdown()
454 if (!(pinfo->flags & FLAG_CONSOLE)) { in cpm_uart_shutdown()
461 if (pinfo->wait_closing) in cpm_uart_shutdown()
466 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_shutdown()
467 clrbits16(&smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); in cpm_uart_shutdown()
468 clrbits8(&smcp->smc_smcm, SMCM_RX | SMCM_TX); in cpm_uart_shutdown()
470 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_shutdown()
471 clrbits32(&sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); in cpm_uart_shutdown()
472 clrbits16(&sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); in cpm_uart_shutdown()
475 /* Shut them really down and reinit buffer descriptors */ in cpm_uart_shutdown()
477 out_be16(&pinfo->smcup->smc_brkcr, 0); in cpm_uart_shutdown()
480 out_be16(&pinfo->sccup->scc_brkcr, 0); in cpm_uart_shutdown()
497 smc_t __iomem *smcp = pinfo->smcp; in cpm_uart_set_termios()
498 scc_t __iomem *sccp = pinfo->sccp; in cpm_uart_set_termios()
501 pr_debug("CPM uart[%d]:set_termios\n", port->line); in cpm_uart_set_termios()
503 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); in cpm_uart_set_termios()
504 if (baud < HW_BUF_SPD_THRESHOLD || port->flags & UPF_LOW_LATENCY) in cpm_uart_set_termios()
505 pinfo->rx_fifosize = 1; in cpm_uart_set_termios()
507 pinfo->rx_fifosize = RX_BUF_SIZE; in cpm_uart_set_termios()
523 if (termios->c_cflag & CSTOPB) { in cpm_uart_set_termios()
528 if (termios->c_cflag & PARENB) { in cpm_uart_set_termios()
531 if (!(termios->c_cflag & PARODD)) { in cpm_uart_set_termios()
540 uart_update_timeout(port, termios->c_cflag, baud); in cpm_uart_set_termios()
545 port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV); in cpm_uart_set_termios()
546 if (termios->c_iflag & INPCK) in cpm_uart_set_termios()
547 port->read_status_mask |= BD_SC_FR | BD_SC_PR; in cpm_uart_set_termios()
548 if ((termios->c_iflag & BRKINT) || (termios->c_iflag & PARMRK)) in cpm_uart_set_termios()
549 port->read_status_mask |= BD_SC_BR; in cpm_uart_set_termios()
554 port->ignore_status_mask = 0; in cpm_uart_set_termios()
555 if (termios->c_iflag & IGNPAR) in cpm_uart_set_termios()
556 port->ignore_status_mask |= BD_SC_PR | BD_SC_FR; in cpm_uart_set_termios()
557 if (termios->c_iflag & IGNBRK) { in cpm_uart_set_termios()
558 port->ignore_status_mask |= BD_SC_BR; in cpm_uart_set_termios()
563 if (termios->c_iflag & IGNPAR) in cpm_uart_set_termios()
564 port->ignore_status_mask |= BD_SC_OV; in cpm_uart_set_termios()
569 if ((termios->c_cflag & CREAD) == 0) in cpm_uart_set_termios()
570 port->read_status_mask &= ~BD_SC_EMPTY; in cpm_uart_set_termios()
575 unsigned int bits = tty_get_frame_size(termios->c_cflag); in cpm_uart_set_termios()
579 * if it is done in a single bus cycle with one 16-bit move in cpm_uart_set_termios()
580 * (not two 8-bit bus cycles back-to-back). This occurs when in cpm_uart_set_termios()
586 out_be16(&pinfo->smcup->smc_mrblr, pinfo->rx_fifosize); in cpm_uart_set_termios()
587 out_be16(&pinfo->smcup->smc_maxidl, maxidl); in cpm_uart_set_termios()
593 prev_mode = in_be16(&smcp->smc_smcmr) & (SMCMR_REN | SMCMR_TEN); in cpm_uart_set_termios()
598 out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits - 1) | cval | in cpm_uart_set_termios()
601 unsigned int bits = tty_get_char_size(termios->c_cflag); in cpm_uart_set_termios()
603 out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); in cpm_uart_set_termios()
604 out_be16(&pinfo->sccup->scc_maxidl, maxidl); in cpm_uart_set_termios()
605 out_be16(&sccp->scc_psmr, (UART_LCR_WLEN(bits) << 12) | scval); in cpm_uart_set_termios()
608 if (pinfo->clk) in cpm_uart_set_termios()
609 clk_set_rate(pinfo->clk, baud); in cpm_uart_set_termios()
611 cpm_setbrg(pinfo->brg - 1, baud); in cpm_uart_set_termios()
617 pr_debug("CPM uart[%d]:uart_type\n", port->line); in cpm_uart_type()
619 return port->type == PORT_CPM ? "CPM UART" : NULL; in cpm_uart_type()
630 pr_debug("CPM uart[%d]:verify_port\n", port->line); in cpm_uart_verify_port()
632 if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM) in cpm_uart_verify_port()
633 ret = -EINVAL; in cpm_uart_verify_port()
634 if (ser->irq < 0 || ser->irq >= irq_get_nr_irqs()) in cpm_uart_verify_port()
635 ret = -EINVAL; in cpm_uart_verify_port()
636 if (ser->baud_base < 9600) in cpm_uart_verify_port()
637 ret = -EINVAL; in cpm_uart_verify_port()
651 struct tty_port *tport = &port->state->port; in cpm_uart_tx_pump()
654 if (port->x_char) { in cpm_uart_tx_pump()
656 bdp = pinfo->tx_cur; in cpm_uart_tx_pump()
658 p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); in cpm_uart_tx_pump()
660 *p++ = port->x_char; in cpm_uart_tx_pump()
662 out_be16(&bdp->cbd_datlen, 1); in cpm_uart_tx_pump()
663 setbits16(&bdp->cbd_sc, BD_SC_READY); in cpm_uart_tx_pump()
665 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) in cpm_uart_tx_pump()
666 bdp = pinfo->tx_bd_base; in cpm_uart_tx_pump()
669 pinfo->tx_cur = bdp; in cpm_uart_tx_pump()
671 port->icount.tx++; in cpm_uart_tx_pump()
672 port->x_char = 0; in cpm_uart_tx_pump()
676 if (kfifo_is_empty(&tport->xmit_fifo) || uart_tx_stopped(port)) { in cpm_uart_tx_pump()
682 bdp = pinfo->tx_cur; in cpm_uart_tx_pump()
684 while (!(in_be16(&bdp->cbd_sc) & BD_SC_READY) && in cpm_uart_tx_pump()
685 !kfifo_is_empty(&tport->xmit_fifo)) { in cpm_uart_tx_pump()
686 p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); in cpm_uart_tx_pump()
687 count = uart_fifo_out(port, p, pinfo->tx_fifosize); in cpm_uart_tx_pump()
688 out_be16(&bdp->cbd_datlen, count); in cpm_uart_tx_pump()
689 setbits16(&bdp->cbd_sc, BD_SC_READY); in cpm_uart_tx_pump()
691 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) in cpm_uart_tx_pump()
692 bdp = pinfo->tx_bd_base; in cpm_uart_tx_pump()
696 pinfo->tx_cur = bdp; in cpm_uart_tx_pump()
698 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in cpm_uart_tx_pump()
701 if (kfifo_is_empty(&tport->xmit_fifo)) { in cpm_uart_tx_pump()
718 pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line); in cpm_uart_initbd()
724 mem_addr = pinfo->mem_addr; in cpm_uart_initbd()
725 bdp = pinfo->rx_cur = pinfo->rx_bd_base; in cpm_uart_initbd()
726 for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) { in cpm_uart_initbd()
727 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); in cpm_uart_initbd()
728 out_be16(&bdp->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT); in cpm_uart_initbd()
729 mem_addr += pinfo->rx_fifosize; in cpm_uart_initbd()
732 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); in cpm_uart_initbd()
733 out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT); in cpm_uart_initbd()
739 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize); in cpm_uart_initbd()
740 bdp = pinfo->tx_cur = pinfo->tx_bd_base; in cpm_uart_initbd()
741 for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) { in cpm_uart_initbd()
742 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); in cpm_uart_initbd()
743 out_be16(&bdp->cbd_sc, BD_SC_INTRPT); in cpm_uart_initbd()
744 mem_addr += pinfo->tx_fifosize; in cpm_uart_initbd()
747 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); in cpm_uart_initbd()
748 out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_INTRPT); in cpm_uart_initbd()
756 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line); in cpm_uart_init_scc()
758 scp = pinfo->sccp; in cpm_uart_init_scc()
759 sup = pinfo->sccup; in cpm_uart_init_scc()
762 out_be16(&pinfo->sccup->scc_genscc.scc_rbase, in cpm_uart_init_scc()
763 (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); in cpm_uart_init_scc()
764 out_be16(&pinfo->sccup->scc_genscc.scc_tbase, in cpm_uart_init_scc()
765 (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); in cpm_uart_init_scc()
771 out_8(&sup->scc_genscc.scc_rfcr, CPMFCR_GBL | CPMFCR_EB); in cpm_uart_init_scc()
772 out_8(&sup->scc_genscc.scc_tfcr, CPMFCR_GBL | CPMFCR_EB); in cpm_uart_init_scc()
774 out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); in cpm_uart_init_scc()
775 out_be16(&sup->scc_maxidl, 0x10); in cpm_uart_init_scc()
776 out_be16(&sup->scc_brkcr, 1); in cpm_uart_init_scc()
777 out_be16(&sup->scc_parec, 0); in cpm_uart_init_scc()
778 out_be16(&sup->scc_frmec, 0); in cpm_uart_init_scc()
779 out_be16(&sup->scc_nosec, 0); in cpm_uart_init_scc()
780 out_be16(&sup->scc_brkec, 0); in cpm_uart_init_scc()
781 out_be16(&sup->scc_uaddr1, 0); in cpm_uart_init_scc()
782 out_be16(&sup->scc_uaddr2, 0); in cpm_uart_init_scc()
783 out_be16(&sup->scc_toseq, 0); in cpm_uart_init_scc()
784 out_be16(&sup->scc_char1, 0x8000); in cpm_uart_init_scc()
785 out_be16(&sup->scc_char2, 0x8000); in cpm_uart_init_scc()
786 out_be16(&sup->scc_char3, 0x8000); in cpm_uart_init_scc()
787 out_be16(&sup->scc_char4, 0x8000); in cpm_uart_init_scc()
788 out_be16(&sup->scc_char5, 0x8000); in cpm_uart_init_scc()
789 out_be16(&sup->scc_char6, 0x8000); in cpm_uart_init_scc()
790 out_be16(&sup->scc_char7, 0x8000); in cpm_uart_init_scc()
791 out_be16(&sup->scc_char8, 0x8000); in cpm_uart_init_scc()
792 out_be16(&sup->scc_rccm, 0xc0ff); in cpm_uart_init_scc()
801 out_be32(&scp->scc_gsmrh, 0); in cpm_uart_init_scc()
802 out_be32(&scp->scc_gsmrl, in cpm_uart_init_scc()
806 out_be16(&scp->scc_sccm, 0); in cpm_uart_init_scc()
807 out_be16(&scp->scc_scce, 0xffff); in cpm_uart_init_scc()
808 out_be16(&scp->scc_dsr, 0x7e7e); in cpm_uart_init_scc()
809 out_be16(&scp->scc_psmr, 0x3000); in cpm_uart_init_scc()
811 setbits32(&scp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); in cpm_uart_init_scc()
819 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line); in cpm_uart_init_smc()
821 sp = pinfo->smcp; in cpm_uart_init_smc()
822 up = pinfo->smcup; in cpm_uart_init_smc()
825 out_be16(&pinfo->smcup->smc_rbase, in cpm_uart_init_smc()
826 (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); in cpm_uart_init_smc()
827 out_be16(&pinfo->smcup->smc_tbase, in cpm_uart_init_smc()
828 (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); in cpm_uart_init_smc()
833 out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase)); in cpm_uart_init_smc()
834 out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase)); in cpm_uart_init_smc()
835 out_be32(&up->smc_rstate, 0); in cpm_uart_init_smc()
836 out_be32(&up->smc_tstate, 0); in cpm_uart_init_smc()
837 out_be16(&up->smc_brkcr, 1); /* number of break chars */ in cpm_uart_init_smc()
838 out_be16(&up->smc_brkec, 0); in cpm_uart_init_smc()
843 out_8(&up->smc_rfcr, CPMFCR_GBL | CPMFCR_EB); in cpm_uart_init_smc()
844 out_8(&up->smc_tfcr, CPMFCR_GBL | CPMFCR_EB); in cpm_uart_init_smc()
847 out_be16(&up->smc_mrblr, pinfo->rx_fifosize); in cpm_uart_init_smc()
848 out_be16(&up->smc_maxidl, 0x10); in cpm_uart_init_smc()
849 out_be16(&up->smc_brklen, 0); in cpm_uart_init_smc()
850 out_be16(&up->smc_brkec, 0); in cpm_uart_init_smc()
851 out_be16(&up->smc_brkcr, 1); in cpm_uart_init_smc()
856 out_be16(&sp->smc_smcmr, smcr_mk_clen(9) | SMCMR_SM_UART); in cpm_uart_init_smc()
859 out_8(&sp->smc_smcm, 0); in cpm_uart_init_smc()
860 out_8(&sp->smc_smce, 0xff); in cpm_uart_init_smc()
862 setbits16(&sp->smc_smcmr, SMCMR_REN | SMCMR_TEN); in cpm_uart_init_smc()
866 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
879 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line); in cpm_uart_allocbuf()
881 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos); in cpm_uart_allocbuf()
885 return -ENOMEM; in cpm_uart_allocbuf()
890 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) + in cpm_uart_allocbuf()
891 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize); in cpm_uart_allocbuf()
901 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr, in cpm_uart_allocbuf()
908 return -ENOMEM; in cpm_uart_allocbuf()
911 pinfo->dp_addr = dp_offset; in cpm_uart_allocbuf()
912 pinfo->mem_addr = mem_addr; in cpm_uart_allocbuf()
913 pinfo->dma_addr = dma_addr; in cpm_uart_allocbuf()
914 pinfo->mem_size = memsz; in cpm_uart_allocbuf()
916 pinfo->rx_buf = mem_addr; in cpm_uart_allocbuf()
917 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos in cpm_uart_allocbuf()
918 * pinfo->rx_fifosize); in cpm_uart_allocbuf()
920 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem; in cpm_uart_allocbuf()
921 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos; in cpm_uart_allocbuf()
928 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos * in cpm_uart_freebuf()
929 pinfo->rx_fifosize) + in cpm_uart_freebuf()
930 L1_CACHE_ALIGN(pinfo->tx_nrfifos * in cpm_uart_freebuf()
931 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr, in cpm_uart_freebuf()
932 pinfo->dma_addr); in cpm_uart_freebuf()
934 cpm_muram_free(pinfo->dp_addr); in cpm_uart_freebuf()
947 pr_debug("CPM uart[%d]:request port\n", port->line); in cpm_uart_request_port()
949 if (pinfo->flags & FLAG_CONSOLE) in cpm_uart_request_port()
953 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); in cpm_uart_request_port()
954 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); in cpm_uart_request_port()
956 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); in cpm_uart_request_port()
957 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); in cpm_uart_request_port()
979 if (!(pinfo->flags & FLAG_CONSOLE)) in cpm_uart_release_port()
988 pr_debug("CPM uart[%d]:config_port\n", port->line); in cpm_uart_config_port()
991 port->type = PORT_CPM; in cpm_uart_config_port()
1010 bdp = pinfo->tx_cur; in cpm_uart_early_write()
1011 bdbase = pinfo->tx_bd_base; in cpm_uart_early_write()
1024 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) in cpm_uart_early_write()
1031 cpm_outp_addr = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), in cpm_uart_early_write()
1035 out_be16(&bdp->cbd_datlen, 1); in cpm_uart_early_write()
1036 setbits16(&bdp->cbd_sc, BD_SC_READY); in cpm_uart_early_write()
1038 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) in cpm_uart_early_write()
1045 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) in cpm_uart_early_write()
1048 cpm_outp_addr = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), in cpm_uart_early_write()
1052 out_be16(&bdp->cbd_datlen, 1); in cpm_uart_early_write()
1053 setbits16(&bdp->cbd_sc, BD_SC_READY); in cpm_uart_early_write()
1055 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) in cpm_uart_early_write()
1066 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) in cpm_uart_early_write()
1069 pinfo->tx_cur = bdp; in cpm_uart_early_write()
1092 bdp = pinfo->rx_cur; in poll_wait_key()
1093 if (bdp->cbd_sc & BD_SC_EMPTY) in poll_wait_key()
1099 cp = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); in poll_wait_key()
1102 i = c = bdp->cbd_datlen; in poll_wait_key()
1103 while (i-- > 0) in poll_wait_key()
1107 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV | BD_SC_ID); in poll_wait_key()
1108 bdp->cbd_sc |= BD_SC_EMPTY; in poll_wait_key()
1110 if (bdp->cbd_sc & BD_SC_WRAP) in poll_wait_key()
1111 bdp = pinfo->rx_bd_base; in poll_wait_key()
1114 pinfo->rx_cur = (cbd_t *)bdp; in poll_wait_key()
1136 poll_chars--; in cpm_get_poll_char()
1165 return c == NO_POLL_CHAR ? -1 : c; in udbg_cpm_getc_poll()
1172 while ((c = udbg_cpm_getc_poll()) == -1) in udbg_cpm_getc()
1215 if (IS_SMC(port) && port->smcup) in cpm_uart_map_pram()
1216 return port->smcup; in cpm_uart_map_pram()
1217 else if (!IS_SMC(port) && port->sccup) in cpm_uart_map_pram()
1218 return port->sccup; in cpm_uart_map_pram()
1236 port->port.line); in cpm_uart_map_pram()
1257 struct device *dev = pinfo->port.dev; in cpm_uart_init_port()
1266 pinfo->clk = clk; in cpm_uart_init_port()
1268 if (!pinfo->clk) { in cpm_uart_init_port()
1269 data = of_get_property(np, "fsl,cpm-brg", &len); in cpm_uart_init_port()
1272 "fsl,cpm-brg property.\n", np); in cpm_uart_init_port()
1273 return -EINVAL; in cpm_uart_init_port()
1275 pinfo->brg = *data; in cpm_uart_init_port()
1278 data = of_get_property(np, "fsl,cpm-command", &len); in cpm_uart_init_port()
1281 "fsl,cpm-command property.\n", np); in cpm_uart_init_port()
1282 return -EINVAL; in cpm_uart_init_port()
1284 pinfo->command = *data; in cpm_uart_init_port()
1288 return -ENOMEM; in cpm_uart_init_port()
1290 if (of_device_is_compatible(np, "fsl,cpm1-scc-uart") || in cpm_uart_init_port()
1291 of_device_is_compatible(np, "fsl,cpm2-scc-uart")) { in cpm_uart_init_port()
1292 pinfo->sccp = mem; in cpm_uart_init_port()
1293 pinfo->sccup = pram = cpm_uart_map_pram(pinfo, np); in cpm_uart_init_port()
1294 } else if (of_device_is_compatible(np, "fsl,cpm1-smc-uart") || in cpm_uart_init_port()
1295 of_device_is_compatible(np, "fsl,cpm2-smc-uart")) { in cpm_uart_init_port()
1296 pinfo->flags |= FLAG_SMC; in cpm_uart_init_port()
1297 pinfo->smcp = mem; in cpm_uart_init_port()
1298 pinfo->smcup = pram = cpm_uart_map_pram(pinfo, np); in cpm_uart_init_port()
1300 ret = -ENODEV; in cpm_uart_init_port()
1305 ret = -ENOMEM; in cpm_uart_init_port()
1309 pinfo->tx_nrfifos = TX_NUM_FIFO; in cpm_uart_init_port()
1310 pinfo->tx_fifosize = TX_BUF_SIZE; in cpm_uart_init_port()
1311 pinfo->rx_nrfifos = RX_NUM_FIFO; in cpm_uart_init_port()
1312 pinfo->rx_fifosize = RX_BUF_SIZE; in cpm_uart_init_port()
1314 pinfo->port.uartclk = ppc_proc_freq; in cpm_uart_init_port()
1315 pinfo->port.mapbase = (unsigned long)mem; in cpm_uart_init_port()
1316 pinfo->port.type = PORT_CPM; in cpm_uart_init_port()
1317 pinfo->port.ops = &cpm_uart_pops; in cpm_uart_init_port()
1318 pinfo->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CPM_CONSOLE); in cpm_uart_init_port()
1319 pinfo->port.iotype = UPIO_MEM; in cpm_uart_init_port()
1320 pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize; in cpm_uart_init_port()
1321 spin_lock_init(&pinfo->port.lock); in cpm_uart_init_port()
1326 pinfo->gpios[i] = NULL; in cpm_uart_init_port()
1345 pinfo->gpios[i] = gpiod; in cpm_uart_init_port()
1356 return cpm_uart_request_port(&pinfo->port); in cpm_uart_init_port()
1375 struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index]; in cpm_uart_console_write()
1383 uart_port_lock_irqsave(&pinfo->port, &flags); in cpm_uart_console_write()
1385 uart_port_unlock_irqrestore(&pinfo->port, flags); in cpm_uart_console_write()
1403 if (co->index >= UART_NR) { in cpm_uart_console_setup()
1405 co->index); in cpm_uart_console_setup()
1406 return -ENODEV; in cpm_uart_console_setup()
1410 if (!of_device_is_compatible(np, "fsl,cpm1-smc-uart") && in cpm_uart_console_setup()
1411 !of_device_is_compatible(np, "fsl,cpm1-scc-uart") && in cpm_uart_console_setup()
1412 !of_device_is_compatible(np, "fsl,cpm2-smc-uart") && in cpm_uart_console_setup()
1413 !of_device_is_compatible(np, "fsl,cpm2-scc-uart")) in cpm_uart_console_setup()
1416 if (i++ == co->index) in cpm_uart_console_setup()
1421 return -ENODEV; in cpm_uart_console_setup()
1423 pinfo = &cpm_uart_ports[co->index]; in cpm_uart_console_setup()
1425 pinfo->flags |= FLAG_CONSOLE; in cpm_uart_console_setup()
1426 port = &pinfo->port; in cpm_uart_console_setup()
1437 if (baud == -1) in cpm_uart_console_setup()
1442 out_be16(&pinfo->smcup->smc_brkcr, 0); in cpm_uart_console_setup()
1444 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); in cpm_uart_console_setup()
1445 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); in cpm_uart_console_setup()
1447 out_be16(&pinfo->sccup->scc_brkcr, 0); in cpm_uart_console_setup()
1449 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); in cpm_uart_console_setup()
1450 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); in cpm_uart_console_setup()
1470 udbg_port = &pinfo->port; in cpm_uart_console_setup()
1487 .index = -1,
1523 pinfo->port.line = index; in cpm_uart_probe()
1526 return -ENODEV; in cpm_uart_probe()
1531 pinfo->port.dev = &ofdev->dev; in cpm_uart_probe()
1533 pinfo->port.irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); in cpm_uart_probe()
1534 if (!pinfo->port.irq) in cpm_uart_probe()
1535 return -EINVAL; in cpm_uart_probe()
1537 ret = cpm_uart_init_port(ofdev->dev.of_node, pinfo); in cpm_uart_probe()
1539 return uart_add_one_port(&cpm_reg, &pinfo->port); in cpm_uart_probe()
1541 irq_dispose_mapping(pinfo->port.irq); in cpm_uart_probe()
1550 uart_remove_one_port(&cpm_reg, &pinfo->port); in cpm_uart_remove()
1555 .compatible = "fsl,cpm1-smc-uart",
1558 .compatible = "fsl,cpm1-scc-uart",
1561 .compatible = "fsl,cpm2-smc-uart",
1564 .compatible = "fsl,cpm2-scc-uart",