Lines Matching full:up
92 static __inline__ void sunsab_tec_wait(struct uart_sunsab_port *up) in sunsab_tec_wait() argument
94 int timeout = up->tec_timeout; in sunsab_tec_wait()
96 while ((readb(&up->regs->r.star) & SAB82532_STAR_TEC) && --timeout) in sunsab_tec_wait()
100 static __inline__ void sunsab_cec_wait(struct uart_sunsab_port *up) in sunsab_cec_wait() argument
102 int timeout = up->cec_timeout; in sunsab_cec_wait()
104 while ((readb(&up->regs->r.star) & SAB82532_STAR_CEC) && --timeout) in sunsab_cec_wait()
109 receive_chars(struct uart_sunsab_port *up, in receive_chars() argument
119 if (up->port.state != NULL) /* Unopened serial console */ in receive_chars()
120 port = &up->port.state->port; in receive_chars()
129 count = readb(&up->regs->r.rbcl) & (SAB82532_RECV_FIFO_SIZE - 1); in receive_chars()
135 sunsab_cec_wait(up); in receive_chars()
136 writeb(SAB82532_CMDR_RFRD, &up->regs->w.cmdr); in receive_chars()
145 buf[i] = readb(&up->regs->r.rfifo[i]); in receive_chars()
149 sunsab_cec_wait(up); in receive_chars()
150 writeb(SAB82532_CMDR_RMC, &up->regs->w.cmdr); in receive_chars()
155 (up->port.line == up->port.cons->index)) in receive_chars()
162 up->port.icount.brk++; in receive_chars()
163 uart_handle_break(&up->port); in receive_chars()
171 up->port.icount.rx++; in receive_chars()
183 up->port.icount.brk++; in receive_chars()
190 if (uart_handle_break(&up->port)) in receive_chars()
193 up->port.icount.parity++; in receive_chars()
195 up->port.icount.frame++; in receive_chars()
197 up->port.icount.overrun++; in receive_chars()
202 stat->sreg.isr0 &= (up->port.read_status_mask & 0xff); in receive_chars()
203 stat->sreg.isr1 &= ((up->port.read_status_mask >> 8) & 0xff); in receive_chars()
213 if (uart_handle_sysrq_char(&up->port, ch) || !port) in receive_chars()
216 if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 && in receive_chars()
217 (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0) in receive_chars()
232 static void transmit_chars(struct uart_sunsab_port *up, in transmit_chars() argument
235 struct tty_port *tport = &up->port.state->port; in transmit_chars()
239 up->interrupt_mask1 |= SAB82532_IMR1_ALLS; in transmit_chars()
240 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
241 set_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
249 if (!(readb(&up->regs->r.star) & SAB82532_STAR_XFW)) in transmit_chars()
252 set_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
253 sunsab_tx_idle(up); in transmit_chars()
255 if (kfifo_is_empty(&tport->xmit_fifo) || uart_tx_stopped(&up->port)) { in transmit_chars()
256 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in transmit_chars()
257 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
261 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in transmit_chars()
262 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
263 clear_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
266 clear_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
267 for (i = 0; i < up->port.fifosize; i++) { in transmit_chars()
270 if (!uart_fifo_get(&up->port, &ch)) in transmit_chars()
273 writeb(ch, &up->regs->w.xfifo[i]); in transmit_chars()
277 sunsab_cec_wait(up); in transmit_chars()
278 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in transmit_chars()
281 uart_write_wakeup(&up->port); in transmit_chars()
284 sunsab_stop_tx(&up->port); in transmit_chars()
287 static void check_status(struct uart_sunsab_port *up, in check_status() argument
291 uart_handle_dcd_change(&up->port, in check_status()
292 !(readb(&up->regs->r.vstr) & SAB82532_VSTR_CD)); in check_status()
295 uart_handle_cts_change(&up->port, in check_status()
296 (readb(&up->regs->r.star) & SAB82532_STAR_CTS)); in check_status()
298 if ((readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ^ up->dsr) { in check_status()
299 up->dsr = (readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ? 0 : 1; in check_status()
300 up->port.icount.dsr++; in check_status()
303 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_status()
308 struct uart_sunsab_port *up = dev_id; in sunsab_interrupt() local
314 uart_port_lock_irqsave(&up->port, &flags); in sunsab_interrupt()
317 gis = readb(&up->regs->r.gis) >> up->gis_shift; in sunsab_interrupt()
319 status.sreg.isr0 = readb(&up->regs->r.isr0); in sunsab_interrupt()
321 status.sreg.isr1 = readb(&up->regs->r.isr1); in sunsab_interrupt()
327 port = receive_chars(up, &status); in sunsab_interrupt()
330 check_status(up, &status); in sunsab_interrupt()
332 transmit_chars(up, &status); in sunsab_interrupt()
335 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_interrupt()
346 struct uart_sunsab_port *up = in sunsab_tx_empty() local
351 if (test_bit(SAB82532_ALLS, &up->irqflags)) in sunsab_tx_empty()
362 struct uart_sunsab_port *up = in sunsab_set_mctrl() local
366 up->cached_mode &= ~SAB82532_MODE_FRTS; in sunsab_set_mctrl()
367 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_set_mctrl()
369 up->cached_mode |= (SAB82532_MODE_FRTS | in sunsab_set_mctrl()
373 up->cached_pvr &= ~(up->pvr_dtr_bit); in sunsab_set_mctrl()
375 up->cached_pvr |= up->pvr_dtr_bit; in sunsab_set_mctrl()
378 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_set_mctrl()
379 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_set_mctrl()
380 sunsab_tx_idle(up); in sunsab_set_mctrl()
386 struct uart_sunsab_port *up = in sunsab_get_mctrl() local
393 val = readb(&up->regs->r.pvr); in sunsab_get_mctrl()
394 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR; in sunsab_get_mctrl()
396 val = readb(&up->regs->r.vstr); in sunsab_get_mctrl()
399 val = readb(&up->regs->r.star); in sunsab_get_mctrl()
408 struct uart_sunsab_port *up = in sunsab_stop_tx() local
411 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in sunsab_stop_tx()
412 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_stop_tx()
416 static void sunsab_tx_idle(struct uart_sunsab_port *up) in sunsab_tx_idle() argument
418 if (test_bit(SAB82532_REGS_PENDING, &up->irqflags)) { in sunsab_tx_idle()
421 clear_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_tx_idle()
422 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_tx_idle()
423 writeb(up->cached_pvr, &up->regs->rw.pvr); in sunsab_tx_idle()
424 writeb(up->cached_dafo, &up->regs->w.dafo); in sunsab_tx_idle()
426 writeb(up->cached_ebrg & 0xff, &up->regs->w.bgr); in sunsab_tx_idle()
427 tmp = readb(&up->regs->rw.ccr2); in sunsab_tx_idle()
429 tmp |= (up->cached_ebrg >> 2) & 0xc0; in sunsab_tx_idle()
430 writeb(tmp, &up->regs->rw.ccr2); in sunsab_tx_idle()
437 struct uart_sunsab_port *up = in sunsab_start_tx() local
439 struct tty_port *tport = &up->port.state->port; in sunsab_start_tx()
445 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in sunsab_start_tx()
446 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_start_tx()
448 if (!test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_start_tx()
451 clear_bit(SAB82532_ALLS, &up->irqflags); in sunsab_start_tx()
452 clear_bit(SAB82532_XPR, &up->irqflags); in sunsab_start_tx()
454 for (i = 0; i < up->port.fifosize; i++) { in sunsab_start_tx()
457 if (!uart_fifo_get(&up->port, &ch)) in sunsab_start_tx()
460 writeb(ch, &up->regs->w.xfifo[i]); in sunsab_start_tx()
464 sunsab_cec_wait(up); in sunsab_start_tx()
465 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in sunsab_start_tx()
471 struct uart_sunsab_port *up = in sunsab_send_xchar() local
478 uart_port_lock_irqsave(&up->port, &flags); in sunsab_send_xchar()
480 sunsab_tec_wait(up); in sunsab_send_xchar()
481 writeb(ch, &up->regs->w.tic); in sunsab_send_xchar()
483 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_send_xchar()
489 struct uart_sunsab_port *up = in sunsab_stop_rx() local
492 up->interrupt_mask0 |= SAB82532_IMR0_TCD; in sunsab_stop_rx()
493 writeb(up->interrupt_mask1, &up->regs->w.imr0); in sunsab_stop_rx()
499 struct uart_sunsab_port *up = in sunsab_break_ctl() local
504 uart_port_lock_irqsave(&up->port, &flags); in sunsab_break_ctl()
506 val = up->cached_dafo; in sunsab_break_ctl()
511 up->cached_dafo = val; in sunsab_break_ctl()
513 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_break_ctl()
514 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_break_ctl()
515 sunsab_tx_idle(up); in sunsab_break_ctl()
517 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_break_ctl()
523 struct uart_sunsab_port *up = in sunsab_startup() local
527 int err = request_irq(up->port.irq, sunsab_interrupt, in sunsab_startup()
528 IRQF_SHARED, "sab", up); in sunsab_startup()
532 uart_port_lock_irqsave(&up->port, &flags); in sunsab_startup()
537 sunsab_cec_wait(up); in sunsab_startup()
538 sunsab_tec_wait(up); in sunsab_startup()
543 writeb(SAB82532_CMDR_RRES, &up->regs->w.cmdr); in sunsab_startup()
544 sunsab_cec_wait(up); in sunsab_startup()
545 writeb(SAB82532_CMDR_XRES, &up->regs->w.cmdr); in sunsab_startup()
550 (void) readb(&up->regs->r.isr0); in sunsab_startup()
551 (void) readb(&up->regs->r.isr1); in sunsab_startup()
556 writeb(0, &up->regs->w.ccr0); /* power-down */ in sunsab_startup()
558 SAB82532_CCR0_SM_ASYNC, &up->regs->w.ccr0); in sunsab_startup()
559 writeb(SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7, &up->regs->w.ccr1); in sunsab_startup()
561 SAB82532_CCR2_TOE, &up->regs->w.ccr2); in sunsab_startup()
562 writeb(0, &up->regs->w.ccr3); in sunsab_startup()
563 writeb(SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG, &up->regs->w.ccr4); in sunsab_startup()
564 up->cached_mode = (SAB82532_MODE_RTS | SAB82532_MODE_FCTS | in sunsab_startup()
566 writeb(up->cached_mode, &up->regs->w.mode); in sunsab_startup()
567 writeb(SAB82532_RFC_DPS|SAB82532_RFC_RFTH_32, &up->regs->w.rfc); in sunsab_startup()
569 tmp = readb(&up->regs->rw.ccr0); in sunsab_startup()
570 tmp |= SAB82532_CCR0_PU; /* power-up */ in sunsab_startup()
571 writeb(tmp, &up->regs->rw.ccr0); in sunsab_startup()
576 up->interrupt_mask0 = (SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_startup()
578 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_startup()
579 up->interrupt_mask1 = (SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_startup()
583 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_startup()
584 set_bit(SAB82532_ALLS, &up->irqflags); in sunsab_startup()
585 set_bit(SAB82532_XPR, &up->irqflags); in sunsab_startup()
587 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_startup()
595 struct uart_sunsab_port *up = in sunsab_shutdown() local
599 uart_port_lock_irqsave(&up->port, &flags); in sunsab_shutdown()
602 up->interrupt_mask0 = 0xff; in sunsab_shutdown()
603 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_shutdown()
604 up->interrupt_mask1 = 0xff; in sunsab_shutdown()
605 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_shutdown()
608 up->cached_dafo = readb(&up->regs->rw.dafo); in sunsab_shutdown()
609 up->cached_dafo &= ~SAB82532_DAFO_XBRK; in sunsab_shutdown()
610 writeb(up->cached_dafo, &up->regs->rw.dafo); in sunsab_shutdown()
613 up->cached_mode &= ~SAB82532_MODE_RAC; in sunsab_shutdown()
614 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_shutdown()
628 tmp = readb(&up->regs->rw.ccr0); in sunsab_shutdown()
630 writeb(tmp, &up->regs->rw.ccr0); in sunsab_shutdown()
633 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_shutdown()
634 free_irq(up->port.irq, up); in sunsab_shutdown()
680 static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cflag, in sunsab_convert_to_sab() argument
708 up->cached_dafo = dafo; in sunsab_convert_to_sab()
712 up->cached_ebrg = n | (m << 6); in sunsab_convert_to_sab()
714 up->tec_timeout = (10 * 1000000) / baud; in sunsab_convert_to_sab()
715 up->cec_timeout = up->tec_timeout >> 2; in sunsab_convert_to_sab()
726 up->port.read_status_mask = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME | in sunsab_convert_to_sab()
729 up->port.read_status_mask |= (SAB82532_ISR1_CSC | in sunsab_convert_to_sab()
733 up->port.read_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
736 up->port.read_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
741 up->port.ignore_status_mask = 0; in sunsab_convert_to_sab()
743 up->port.ignore_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
746 up->port.ignore_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
752 up->port.ignore_status_mask |= SAB82532_ISR0_RFO; in sunsab_convert_to_sab()
759 up->port.ignore_status_mask |= (SAB82532_ISR0_RPF | in sunsab_convert_to_sab()
762 uart_update_timeout(&up->port, cflag, in sunsab_convert_to_sab()
763 (up->port.uartclk / (16 * quot))); in sunsab_convert_to_sab()
768 up->cached_mode |= SAB82532_MODE_RAC; in sunsab_convert_to_sab()
769 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_convert_to_sab()
770 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_convert_to_sab()
771 sunsab_tx_idle(up); in sunsab_convert_to_sab()
778 struct uart_sunsab_port *up = in sunsab_set_termios() local
784 uart_port_lock_irqsave(&up->port, &flags); in sunsab_set_termios()
785 sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot); in sunsab_set_termios()
786 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_set_termios()
791 struct uart_sunsab_port *up = (void *)port; in sunsab_type() local
794 sprintf(buf, "SAB82532 %s", sab82532_version[up->type]); in sunsab_type()
848 struct uart_sunsab_port *up = in sunsab_console_putchar() local
851 sunsab_tec_wait(up); in sunsab_console_putchar()
852 writeb(c, &up->regs->w.tic); in sunsab_console_putchar()
857 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_write() local
861 if (up->port.sysrq || oops_in_progress) in sunsab_console_write()
862 locked = uart_port_trylock_irqsave(&up->port, &flags); in sunsab_console_write()
864 uart_port_lock_irqsave(&up->port, &flags); in sunsab_console_write()
866 uart_console_write(&up->port, s, n, sunsab_console_putchar); in sunsab_console_write()
867 sunsab_tec_wait(up); in sunsab_console_write()
870 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_console_write()
875 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_setup() local
885 if (up->port.type != PORT_SUNSAB) in sunsab_console_setup()
891 sunserial_console_termios(con, up->port.dev->of_node); in sunsab_console_setup()
912 spin_lock_init(&up->port.lock); in sunsab_console_setup()
917 sunsab_startup(&up->port); in sunsab_console_setup()
919 uart_port_lock_irqsave(&up->port, &flags); in sunsab_console_setup()
924 up->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_console_setup()
926 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_console_setup()
927 up->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_console_setup()
931 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_console_setup()
933 quot = uart_get_divisor(&up->port, baud); in sunsab_console_setup()
934 sunsab_convert_to_sab(up, con->cflag, 0, baud, quot); in sunsab_console_setup()
935 sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); in sunsab_console_setup()
937 uart_port_unlock_irqrestore(&up->port, flags); in sunsab_console_setup()
961 static int sunsab_init_one(struct uart_sunsab_port *up, in sunsab_init_one() argument
966 up->port.line = line; in sunsab_init_one()
967 up->port.dev = &op->dev; in sunsab_init_one()
969 up->port.mapbase = op->resource[0].start + offset; in sunsab_init_one()
970 up->port.membase = of_ioremap(&op->resource[0], offset, in sunsab_init_one()
973 if (!up->port.membase) in sunsab_init_one()
975 up->regs = (union sab82532_async_regs __iomem *) up->port.membase; in sunsab_init_one()
977 up->port.irq = op->archdata.irqs[0]; in sunsab_init_one()
979 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; in sunsab_init_one()
980 up->port.iotype = UPIO_MEM; in sunsab_init_one()
981 up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSAB_CONSOLE); in sunsab_init_one()
983 writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc); in sunsab_init_one()
985 up->port.ops = &sunsab_pops; in sunsab_init_one()
986 up->port.type = PORT_SUNSAB; in sunsab_init_one()
987 up->port.uartclk = SAB_BASE_BAUD; in sunsab_init_one()
989 up->type = readb(&up->regs->r.vstr) & 0x0f; in sunsab_init_one()
990 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->regs->w.pcr); in sunsab_init_one()
991 writeb(0xff, &up->regs->w.pim); in sunsab_init_one()
992 if ((up->port.line & 0x1) == 0) { in sunsab_init_one()
993 up->pvr_dsr_bit = (1 << 0); in sunsab_init_one()
994 up->pvr_dtr_bit = (1 << 1); in sunsab_init_one()
995 up->gis_shift = 2; in sunsab_init_one()
997 up->pvr_dsr_bit = (1 << 3); in sunsab_init_one()
998 up->pvr_dtr_bit = (1 << 2); in sunsab_init_one()
999 up->gis_shift = 0; in sunsab_init_one()
1001 up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4); in sunsab_init_one()
1002 writeb(up->cached_pvr, &up->regs->w.pvr); in sunsab_init_one()
1003 up->cached_mode = readb(&up->regs->rw.mode); in sunsab_init_one()
1004 up->cached_mode |= SAB82532_MODE_FRTS; in sunsab_init_one()
1005 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1006 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_init_one()
1007 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1009 up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT; in sunsab_init_one()
1010 up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT; in sunsab_init_one()
1018 struct uart_sunsab_port *up; in sab_probe() local
1021 up = &sunsab_ports[inst * 2]; in sab_probe()
1023 err = sunsab_init_one(&up[0], op, in sab_probe()
1029 err = sunsab_init_one(&up[1], op, in sab_probe()
1036 &sunsab_reg, up[0].port.line, in sab_probe()
1040 &sunsab_reg, up[1].port.line, in sab_probe()
1043 err = uart_add_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1047 err = uart_add_one_port(&sunsab_reg, &up[1].port); in sab_probe()
1051 platform_set_drvdata(op, &up[0]); in sab_probe()
1058 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1061 up[1].port.membase, in sab_probe()
1065 up[0].port.membase, in sab_probe()
1073 struct uart_sunsab_port *up = platform_get_drvdata(op); in sab_remove() local
1075 uart_remove_one_port(&sunsab_reg, &up[1].port); in sab_remove()
1076 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_remove()
1078 up[1].port.membase, in sab_remove()
1081 up[0].port.membase, in sab_remove()