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 circ_buf *xmit = &up->port.state->xmit; 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 (uart_circ_empty(xmit) || 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()
269 &up->regs->w.xfifo[i]); in transmit_chars()
270 uart_xmit_advance(&up->port, 1); in transmit_chars()
276 sunsab_cec_wait(up); in transmit_chars()
277 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in transmit_chars()
280 uart_write_wakeup(&up->port); in transmit_chars()
283 sunsab_stop_tx(&up->port); in transmit_chars()
286 static void check_status(struct uart_sunsab_port *up, in check_status() argument
290 uart_handle_dcd_change(&up->port, in check_status()
291 !(readb(&up->regs->r.vstr) & SAB82532_VSTR_CD)); in check_status()
294 uart_handle_cts_change(&up->port, in check_status()
295 (readb(&up->regs->r.star) & SAB82532_STAR_CTS)); in check_status()
297 if ((readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ^ up->dsr) { in check_status()
298 up->dsr = (readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ? 0 : 1; in check_status()
299 up->port.icount.dsr++; in check_status()
302 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_status()
307 struct uart_sunsab_port *up = dev_id; in sunsab_interrupt() local
313 spin_lock_irqsave(&up->port.lock, flags); in sunsab_interrupt()
316 gis = readb(&up->regs->r.gis) >> up->gis_shift; in sunsab_interrupt()
318 status.sreg.isr0 = readb(&up->regs->r.isr0); in sunsab_interrupt()
320 status.sreg.isr1 = readb(&up->regs->r.isr1); in sunsab_interrupt()
326 port = receive_chars(up, &status); in sunsab_interrupt()
329 check_status(up, &status); in sunsab_interrupt()
331 transmit_chars(up, &status); in sunsab_interrupt()
334 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_interrupt()
345 struct uart_sunsab_port *up = in sunsab_tx_empty() local
350 if (test_bit(SAB82532_ALLS, &up->irqflags)) in sunsab_tx_empty()
361 struct uart_sunsab_port *up = in sunsab_set_mctrl() local
365 up->cached_mode &= ~SAB82532_MODE_FRTS; in sunsab_set_mctrl()
366 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_set_mctrl()
368 up->cached_mode |= (SAB82532_MODE_FRTS | in sunsab_set_mctrl()
372 up->cached_pvr &= ~(up->pvr_dtr_bit); in sunsab_set_mctrl()
374 up->cached_pvr |= up->pvr_dtr_bit; in sunsab_set_mctrl()
377 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_set_mctrl()
378 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_set_mctrl()
379 sunsab_tx_idle(up); in sunsab_set_mctrl()
385 struct uart_sunsab_port *up = in sunsab_get_mctrl() local
392 val = readb(&up->regs->r.pvr); in sunsab_get_mctrl()
393 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR; in sunsab_get_mctrl()
395 val = readb(&up->regs->r.vstr); in sunsab_get_mctrl()
398 val = readb(&up->regs->r.star); in sunsab_get_mctrl()
407 struct uart_sunsab_port *up = in sunsab_stop_tx() local
410 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in sunsab_stop_tx()
411 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_stop_tx()
415 static void sunsab_tx_idle(struct uart_sunsab_port *up) in sunsab_tx_idle() argument
417 if (test_bit(SAB82532_REGS_PENDING, &up->irqflags)) { in sunsab_tx_idle()
420 clear_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_tx_idle()
421 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_tx_idle()
422 writeb(up->cached_pvr, &up->regs->rw.pvr); in sunsab_tx_idle()
423 writeb(up->cached_dafo, &up->regs->w.dafo); in sunsab_tx_idle()
425 writeb(up->cached_ebrg & 0xff, &up->regs->w.bgr); in sunsab_tx_idle()
426 tmp = readb(&up->regs->rw.ccr2); in sunsab_tx_idle()
428 tmp |= (up->cached_ebrg >> 2) & 0xc0; in sunsab_tx_idle()
429 writeb(tmp, &up->regs->rw.ccr2); in sunsab_tx_idle()
436 struct uart_sunsab_port *up = in sunsab_start_tx() local
438 struct circ_buf *xmit = &up->port.state->xmit; in sunsab_start_tx()
444 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in sunsab_start_tx()
445 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_start_tx()
447 if (!test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_start_tx()
450 clear_bit(SAB82532_ALLS, &up->irqflags); in sunsab_start_tx()
451 clear_bit(SAB82532_XPR, &up->irqflags); in sunsab_start_tx()
453 for (i = 0; i < up->port.fifosize; i++) { in sunsab_start_tx()
455 &up->regs->w.xfifo[i]); in sunsab_start_tx()
456 uart_xmit_advance(&up->port, 1); in sunsab_start_tx()
462 sunsab_cec_wait(up); in sunsab_start_tx()
463 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in sunsab_start_tx()
469 struct uart_sunsab_port *up = in sunsab_send_xchar() local
476 spin_lock_irqsave(&up->port.lock, flags); in sunsab_send_xchar()
478 sunsab_tec_wait(up); in sunsab_send_xchar()
479 writeb(ch, &up->regs->w.tic); in sunsab_send_xchar()
481 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_send_xchar()
487 struct uart_sunsab_port *up = in sunsab_stop_rx() local
490 up->interrupt_mask0 |= SAB82532_IMR0_TCD; in sunsab_stop_rx()
491 writeb(up->interrupt_mask1, &up->regs->w.imr0); in sunsab_stop_rx()
497 struct uart_sunsab_port *up = in sunsab_break_ctl() local
502 spin_lock_irqsave(&up->port.lock, flags); in sunsab_break_ctl()
504 val = up->cached_dafo; in sunsab_break_ctl()
509 up->cached_dafo = val; in sunsab_break_ctl()
511 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_break_ctl()
512 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_break_ctl()
513 sunsab_tx_idle(up); in sunsab_break_ctl()
515 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_break_ctl()
521 struct uart_sunsab_port *up = in sunsab_startup() local
525 int err = request_irq(up->port.irq, sunsab_interrupt, in sunsab_startup()
526 IRQF_SHARED, "sab", up); in sunsab_startup()
530 spin_lock_irqsave(&up->port.lock, flags); in sunsab_startup()
535 sunsab_cec_wait(up); in sunsab_startup()
536 sunsab_tec_wait(up); in sunsab_startup()
541 writeb(SAB82532_CMDR_RRES, &up->regs->w.cmdr); in sunsab_startup()
542 sunsab_cec_wait(up); in sunsab_startup()
543 writeb(SAB82532_CMDR_XRES, &up->regs->w.cmdr); in sunsab_startup()
548 (void) readb(&up->regs->r.isr0); in sunsab_startup()
549 (void) readb(&up->regs->r.isr1); in sunsab_startup()
554 writeb(0, &up->regs->w.ccr0); /* power-down */ in sunsab_startup()
556 SAB82532_CCR0_SM_ASYNC, &up->regs->w.ccr0); in sunsab_startup()
557 writeb(SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7, &up->regs->w.ccr1); in sunsab_startup()
559 SAB82532_CCR2_TOE, &up->regs->w.ccr2); in sunsab_startup()
560 writeb(0, &up->regs->w.ccr3); in sunsab_startup()
561 writeb(SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG, &up->regs->w.ccr4); in sunsab_startup()
562 up->cached_mode = (SAB82532_MODE_RTS | SAB82532_MODE_FCTS | in sunsab_startup()
564 writeb(up->cached_mode, &up->regs->w.mode); in sunsab_startup()
565 writeb(SAB82532_RFC_DPS|SAB82532_RFC_RFTH_32, &up->regs->w.rfc); in sunsab_startup()
567 tmp = readb(&up->regs->rw.ccr0); in sunsab_startup()
568 tmp |= SAB82532_CCR0_PU; /* power-up */ in sunsab_startup()
569 writeb(tmp, &up->regs->rw.ccr0); in sunsab_startup()
574 up->interrupt_mask0 = (SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_startup()
576 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_startup()
577 up->interrupt_mask1 = (SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_startup()
581 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_startup()
582 set_bit(SAB82532_ALLS, &up->irqflags); in sunsab_startup()
583 set_bit(SAB82532_XPR, &up->irqflags); in sunsab_startup()
585 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_startup()
593 struct uart_sunsab_port *up = in sunsab_shutdown() local
597 spin_lock_irqsave(&up->port.lock, flags); in sunsab_shutdown()
600 up->interrupt_mask0 = 0xff; in sunsab_shutdown()
601 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_shutdown()
602 up->interrupt_mask1 = 0xff; in sunsab_shutdown()
603 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_shutdown()
606 up->cached_dafo = readb(&up->regs->rw.dafo); in sunsab_shutdown()
607 up->cached_dafo &= ~SAB82532_DAFO_XBRK; in sunsab_shutdown()
608 writeb(up->cached_dafo, &up->regs->rw.dafo); in sunsab_shutdown()
611 up->cached_mode &= ~SAB82532_MODE_RAC; in sunsab_shutdown()
612 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_shutdown()
626 tmp = readb(&up->regs->rw.ccr0); in sunsab_shutdown()
628 writeb(tmp, &up->regs->rw.ccr0); in sunsab_shutdown()
631 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_shutdown()
632 free_irq(up->port.irq, up); in sunsab_shutdown()
678 static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cflag, in sunsab_convert_to_sab() argument
706 up->cached_dafo = dafo; in sunsab_convert_to_sab()
710 up->cached_ebrg = n | (m << 6); in sunsab_convert_to_sab()
712 up->tec_timeout = (10 * 1000000) / baud; in sunsab_convert_to_sab()
713 up->cec_timeout = up->tec_timeout >> 2; in sunsab_convert_to_sab()
724 up->port.read_status_mask = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME | in sunsab_convert_to_sab()
727 up->port.read_status_mask |= (SAB82532_ISR1_CSC | in sunsab_convert_to_sab()
731 up->port.read_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
734 up->port.read_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
739 up->port.ignore_status_mask = 0; in sunsab_convert_to_sab()
741 up->port.ignore_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
744 up->port.ignore_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
750 up->port.ignore_status_mask |= SAB82532_ISR0_RFO; in sunsab_convert_to_sab()
757 up->port.ignore_status_mask |= (SAB82532_ISR0_RPF | in sunsab_convert_to_sab()
760 uart_update_timeout(&up->port, cflag, in sunsab_convert_to_sab()
761 (up->port.uartclk / (16 * quot))); in sunsab_convert_to_sab()
766 up->cached_mode |= SAB82532_MODE_RAC; in sunsab_convert_to_sab()
767 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_convert_to_sab()
768 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_convert_to_sab()
769 sunsab_tx_idle(up); in sunsab_convert_to_sab()
776 struct uart_sunsab_port *up = in sunsab_set_termios() local
782 spin_lock_irqsave(&up->port.lock, flags); in sunsab_set_termios()
783 sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot); in sunsab_set_termios()
784 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_set_termios()
789 struct uart_sunsab_port *up = (void *)port; in sunsab_type() local
792 sprintf(buf, "SAB82532 %s", sab82532_version[up->type]); in sunsab_type()
846 struct uart_sunsab_port *up = in sunsab_console_putchar() local
849 sunsab_tec_wait(up); in sunsab_console_putchar()
850 writeb(c, &up->regs->w.tic); in sunsab_console_putchar()
855 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_write() local
859 if (up->port.sysrq || oops_in_progress) in sunsab_console_write()
860 locked = spin_trylock_irqsave(&up->port.lock, flags); in sunsab_console_write()
862 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_write()
864 uart_console_write(&up->port, s, n, sunsab_console_putchar); in sunsab_console_write()
865 sunsab_tec_wait(up); in sunsab_console_write()
868 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_write()
873 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_setup() local
883 if (up->port.type != PORT_SUNSAB) in sunsab_console_setup()
889 sunserial_console_termios(con, up->port.dev->of_node); in sunsab_console_setup()
910 spin_lock_init(&up->port.lock); in sunsab_console_setup()
915 sunsab_startup(&up->port); in sunsab_console_setup()
917 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_setup()
922 up->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_console_setup()
924 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_console_setup()
925 up->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_console_setup()
929 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_console_setup()
931 quot = uart_get_divisor(&up->port, baud); in sunsab_console_setup()
932 sunsab_convert_to_sab(up, con->cflag, 0, baud, quot); in sunsab_console_setup()
933 sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); in sunsab_console_setup()
935 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_setup()
959 static int sunsab_init_one(struct uart_sunsab_port *up, in sunsab_init_one() argument
964 up->port.line = line; in sunsab_init_one()
965 up->port.dev = &op->dev; in sunsab_init_one()
967 up->port.mapbase = op->resource[0].start + offset; in sunsab_init_one()
968 up->port.membase = of_ioremap(&op->resource[0], offset, in sunsab_init_one()
971 if (!up->port.membase) in sunsab_init_one()
973 up->regs = (union sab82532_async_regs __iomem *) up->port.membase; in sunsab_init_one()
975 up->port.irq = op->archdata.irqs[0]; in sunsab_init_one()
977 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; in sunsab_init_one()
978 up->port.iotype = UPIO_MEM; in sunsab_init_one()
979 up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSAB_CONSOLE); in sunsab_init_one()
981 writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc); in sunsab_init_one()
983 up->port.ops = &sunsab_pops; in sunsab_init_one()
984 up->port.type = PORT_SUNSAB; in sunsab_init_one()
985 up->port.uartclk = SAB_BASE_BAUD; in sunsab_init_one()
987 up->type = readb(&up->regs->r.vstr) & 0x0f; in sunsab_init_one()
988 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->regs->w.pcr); in sunsab_init_one()
989 writeb(0xff, &up->regs->w.pim); in sunsab_init_one()
990 if ((up->port.line & 0x1) == 0) { in sunsab_init_one()
991 up->pvr_dsr_bit = (1 << 0); in sunsab_init_one()
992 up->pvr_dtr_bit = (1 << 1); in sunsab_init_one()
993 up->gis_shift = 2; in sunsab_init_one()
995 up->pvr_dsr_bit = (1 << 3); in sunsab_init_one()
996 up->pvr_dtr_bit = (1 << 2); in sunsab_init_one()
997 up->gis_shift = 0; in sunsab_init_one()
999 up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4); in sunsab_init_one()
1000 writeb(up->cached_pvr, &up->regs->w.pvr); in sunsab_init_one()
1001 up->cached_mode = readb(&up->regs->rw.mode); in sunsab_init_one()
1002 up->cached_mode |= SAB82532_MODE_FRTS; in sunsab_init_one()
1003 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1004 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_init_one()
1005 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1007 up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT; in sunsab_init_one()
1008 up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT; in sunsab_init_one()
1016 struct uart_sunsab_port *up; in sab_probe() local
1019 up = &sunsab_ports[inst * 2]; in sab_probe()
1021 err = sunsab_init_one(&up[0], op, in sab_probe()
1027 err = sunsab_init_one(&up[1], op, in sab_probe()
1034 &sunsab_reg, up[0].port.line, in sab_probe()
1038 &sunsab_reg, up[1].port.line, in sab_probe()
1041 err = uart_add_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1045 err = uart_add_one_port(&sunsab_reg, &up[1].port); in sab_probe()
1049 platform_set_drvdata(op, &up[0]); in sab_probe()
1056 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1059 up[1].port.membase, in sab_probe()
1063 up[0].port.membase, in sab_probe()
1071 struct uart_sunsab_port *up = platform_get_drvdata(op); in sab_remove() local
1073 uart_remove_one_port(&sunsab_reg, &up[1].port); in sab_remove()
1074 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_remove()
1076 up[1].port.membase, in sab_remove()
1079 up[0].port.membase, in sab_remove()