Lines Matching refs:up
91 static __inline__ void sunsab_tec_wait(struct uart_sunsab_port *up) in sunsab_tec_wait() argument
93 int timeout = up->tec_timeout; in sunsab_tec_wait()
95 while ((readb(&up->regs->r.star) & SAB82532_STAR_TEC) && --timeout) in sunsab_tec_wait()
99 static __inline__ void sunsab_cec_wait(struct uart_sunsab_port *up) in sunsab_cec_wait() argument
101 int timeout = up->cec_timeout; in sunsab_cec_wait()
103 while ((readb(&up->regs->r.star) & SAB82532_STAR_CEC) && --timeout) in sunsab_cec_wait()
108 receive_chars(struct uart_sunsab_port *up, in receive_chars() argument
118 if (up->port.state != NULL) /* Unopened serial console */ in receive_chars()
119 port = &up->port.state->port; in receive_chars()
128 count = readb(&up->regs->r.rbcl) & (SAB82532_RECV_FIFO_SIZE - 1); in receive_chars()
134 sunsab_cec_wait(up); in receive_chars()
135 writeb(SAB82532_CMDR_RFRD, &up->regs->w.cmdr); in receive_chars()
144 buf[i] = readb(&up->regs->r.rfifo[i]); in receive_chars()
148 sunsab_cec_wait(up); in receive_chars()
149 writeb(SAB82532_CMDR_RMC, &up->regs->w.cmdr); in receive_chars()
154 (up->port.line == up->port.cons->index)) in receive_chars()
161 up->port.icount.brk++; in receive_chars()
162 uart_handle_break(&up->port); in receive_chars()
170 up->port.icount.rx++; in receive_chars()
182 up->port.icount.brk++; in receive_chars()
189 if (uart_handle_break(&up->port)) in receive_chars()
192 up->port.icount.parity++; in receive_chars()
194 up->port.icount.frame++; in receive_chars()
196 up->port.icount.overrun++; in receive_chars()
201 stat->sreg.isr0 &= (up->port.read_status_mask & 0xff); in receive_chars()
202 stat->sreg.isr1 &= ((up->port.read_status_mask >> 8) & 0xff); in receive_chars()
212 if (uart_handle_sysrq_char(&up->port, ch) || !port) in receive_chars()
215 if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 && in receive_chars()
216 (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0) in receive_chars()
231 static void transmit_chars(struct uart_sunsab_port *up, in transmit_chars() argument
234 struct circ_buf *xmit = &up->port.state->xmit; in transmit_chars()
238 up->interrupt_mask1 |= SAB82532_IMR1_ALLS; in transmit_chars()
239 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
240 set_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
248 if (!(readb(&up->regs->r.star) & SAB82532_STAR_XFW)) in transmit_chars()
251 set_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
252 sunsab_tx_idle(up); in transmit_chars()
254 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { in transmit_chars()
255 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in transmit_chars()
256 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
260 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in transmit_chars()
261 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
262 clear_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
265 clear_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
266 for (i = 0; i < up->port.fifosize; i++) { in transmit_chars()
268 &up->regs->w.xfifo[i]); in transmit_chars()
270 up->port.icount.tx++; 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()
457 up->port.icount.tx++; in sunsab_start_tx()
463 sunsab_cec_wait(up); in sunsab_start_tx()
464 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in sunsab_start_tx()
470 struct uart_sunsab_port *up = in sunsab_send_xchar() local
477 spin_lock_irqsave(&up->port.lock, flags); in sunsab_send_xchar()
479 sunsab_tec_wait(up); in sunsab_send_xchar()
480 writeb(ch, &up->regs->w.tic); in sunsab_send_xchar()
482 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_send_xchar()
488 struct uart_sunsab_port *up = in sunsab_stop_rx() local
491 up->interrupt_mask0 |= SAB82532_IMR0_TCD; in sunsab_stop_rx()
492 writeb(up->interrupt_mask1, &up->regs->w.imr0); in sunsab_stop_rx()
498 struct uart_sunsab_port *up = in sunsab_break_ctl() local
503 spin_lock_irqsave(&up->port.lock, flags); in sunsab_break_ctl()
505 val = up->cached_dafo; in sunsab_break_ctl()
510 up->cached_dafo = val; in sunsab_break_ctl()
512 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_break_ctl()
513 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_break_ctl()
514 sunsab_tx_idle(up); in sunsab_break_ctl()
516 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_break_ctl()
522 struct uart_sunsab_port *up = in sunsab_startup() local
526 int err = request_irq(up->port.irq, sunsab_interrupt, in sunsab_startup()
527 IRQF_SHARED, "sab", up); in sunsab_startup()
531 spin_lock_irqsave(&up->port.lock, flags); in sunsab_startup()
536 sunsab_cec_wait(up); in sunsab_startup()
537 sunsab_tec_wait(up); in sunsab_startup()
542 writeb(SAB82532_CMDR_RRES, &up->regs->w.cmdr); in sunsab_startup()
543 sunsab_cec_wait(up); in sunsab_startup()
544 writeb(SAB82532_CMDR_XRES, &up->regs->w.cmdr); in sunsab_startup()
549 (void) readb(&up->regs->r.isr0); in sunsab_startup()
550 (void) readb(&up->regs->r.isr1); in sunsab_startup()
555 writeb(0, &up->regs->w.ccr0); /* power-down */ in sunsab_startup()
557 SAB82532_CCR0_SM_ASYNC, &up->regs->w.ccr0); in sunsab_startup()
558 writeb(SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7, &up->regs->w.ccr1); in sunsab_startup()
560 SAB82532_CCR2_TOE, &up->regs->w.ccr2); in sunsab_startup()
561 writeb(0, &up->regs->w.ccr3); in sunsab_startup()
562 writeb(SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG, &up->regs->w.ccr4); in sunsab_startup()
563 up->cached_mode = (SAB82532_MODE_RTS | SAB82532_MODE_FCTS | in sunsab_startup()
565 writeb(up->cached_mode, &up->regs->w.mode); in sunsab_startup()
566 writeb(SAB82532_RFC_DPS|SAB82532_RFC_RFTH_32, &up->regs->w.rfc); in sunsab_startup()
568 tmp = readb(&up->regs->rw.ccr0); in sunsab_startup()
570 writeb(tmp, &up->regs->rw.ccr0); in sunsab_startup()
575 up->interrupt_mask0 = (SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_startup()
577 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_startup()
578 up->interrupt_mask1 = (SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_startup()
582 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_startup()
583 set_bit(SAB82532_ALLS, &up->irqflags); in sunsab_startup()
584 set_bit(SAB82532_XPR, &up->irqflags); in sunsab_startup()
586 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_startup()
594 struct uart_sunsab_port *up = in sunsab_shutdown() local
598 spin_lock_irqsave(&up->port.lock, flags); in sunsab_shutdown()
601 up->interrupt_mask0 = 0xff; in sunsab_shutdown()
602 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_shutdown()
603 up->interrupt_mask1 = 0xff; in sunsab_shutdown()
604 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_shutdown()
607 up->cached_dafo = readb(&up->regs->rw.dafo); in sunsab_shutdown()
608 up->cached_dafo &= ~SAB82532_DAFO_XBRK; in sunsab_shutdown()
609 writeb(up->cached_dafo, &up->regs->rw.dafo); in sunsab_shutdown()
612 up->cached_mode &= ~SAB82532_MODE_RAC; in sunsab_shutdown()
613 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_shutdown()
627 tmp = readb(&up->regs->rw.ccr0); in sunsab_shutdown()
629 writeb(tmp, &up->regs->rw.ccr0); in sunsab_shutdown()
632 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_shutdown()
633 free_irq(up->port.irq, up); in sunsab_shutdown()
679 static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cflag, in sunsab_convert_to_sab() argument
711 up->cached_dafo = dafo; in sunsab_convert_to_sab()
715 up->cached_ebrg = n | (m << 6); in sunsab_convert_to_sab()
717 up->tec_timeout = (10 * 1000000) / baud; in sunsab_convert_to_sab()
718 up->cec_timeout = up->tec_timeout >> 2; in sunsab_convert_to_sab()
729 up->port.read_status_mask = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME | in sunsab_convert_to_sab()
732 up->port.read_status_mask |= (SAB82532_ISR1_CSC | in sunsab_convert_to_sab()
736 up->port.read_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
739 up->port.read_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
744 up->port.ignore_status_mask = 0; in sunsab_convert_to_sab()
746 up->port.ignore_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
749 up->port.ignore_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
755 up->port.ignore_status_mask |= SAB82532_ISR0_RFO; in sunsab_convert_to_sab()
762 up->port.ignore_status_mask |= (SAB82532_ISR0_RPF | in sunsab_convert_to_sab()
765 uart_update_timeout(&up->port, cflag, in sunsab_convert_to_sab()
766 (up->port.uartclk / (16 * quot))); in sunsab_convert_to_sab()
771 up->cached_mode |= SAB82532_MODE_RAC; in sunsab_convert_to_sab()
772 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_convert_to_sab()
773 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_convert_to_sab()
774 sunsab_tx_idle(up); in sunsab_convert_to_sab()
781 struct uart_sunsab_port *up = in sunsab_set_termios() local
787 spin_lock_irqsave(&up->port.lock, flags); in sunsab_set_termios()
788 sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot); in sunsab_set_termios()
789 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_set_termios()
794 struct uart_sunsab_port *up = (void *)port; in sunsab_type() local
797 sprintf(buf, "SAB82532 %s", sab82532_version[up->type]); in sunsab_type()
851 struct uart_sunsab_port *up = in sunsab_console_putchar() local
854 sunsab_tec_wait(up); in sunsab_console_putchar()
855 writeb(c, &up->regs->w.tic); in sunsab_console_putchar()
860 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_write() local
864 if (up->port.sysrq || oops_in_progress) in sunsab_console_write()
865 locked = spin_trylock_irqsave(&up->port.lock, flags); in sunsab_console_write()
867 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_write()
869 uart_console_write(&up->port, s, n, sunsab_console_putchar); in sunsab_console_write()
870 sunsab_tec_wait(up); in sunsab_console_write()
873 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_write()
878 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_setup() local
888 if (up->port.type != PORT_SUNSAB) in sunsab_console_setup()
894 sunserial_console_termios(con, up->port.dev->of_node); in sunsab_console_setup()
915 spin_lock_init(&up->port.lock); in sunsab_console_setup()
920 sunsab_startup(&up->port); in sunsab_console_setup()
922 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_setup()
927 up->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_console_setup()
929 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_console_setup()
930 up->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_console_setup()
934 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_console_setup()
936 quot = uart_get_divisor(&up->port, baud); in sunsab_console_setup()
937 sunsab_convert_to_sab(up, con->cflag, 0, baud, quot); in sunsab_console_setup()
938 sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); in sunsab_console_setup()
940 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_setup()
964 static int sunsab_init_one(struct uart_sunsab_port *up, in sunsab_init_one() argument
969 up->port.line = line; in sunsab_init_one()
970 up->port.dev = &op->dev; in sunsab_init_one()
972 up->port.mapbase = op->resource[0].start + offset; in sunsab_init_one()
973 up->port.membase = of_ioremap(&op->resource[0], offset, in sunsab_init_one()
976 if (!up->port.membase) in sunsab_init_one()
978 up->regs = (union sab82532_async_regs __iomem *) up->port.membase; in sunsab_init_one()
980 up->port.irq = op->archdata.irqs[0]; in sunsab_init_one()
982 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; in sunsab_init_one()
983 up->port.iotype = UPIO_MEM; in sunsab_init_one()
984 up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSAB_CONSOLE); in sunsab_init_one()
986 writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc); in sunsab_init_one()
988 up->port.ops = &sunsab_pops; in sunsab_init_one()
989 up->port.type = PORT_SUNSAB; in sunsab_init_one()
990 up->port.uartclk = SAB_BASE_BAUD; in sunsab_init_one()
992 up->type = readb(&up->regs->r.vstr) & 0x0f; in sunsab_init_one()
993 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->regs->w.pcr); in sunsab_init_one()
994 writeb(0xff, &up->regs->w.pim); in sunsab_init_one()
995 if ((up->port.line & 0x1) == 0) { in sunsab_init_one()
996 up->pvr_dsr_bit = (1 << 0); in sunsab_init_one()
997 up->pvr_dtr_bit = (1 << 1); in sunsab_init_one()
998 up->gis_shift = 2; in sunsab_init_one()
1000 up->pvr_dsr_bit = (1 << 3); in sunsab_init_one()
1001 up->pvr_dtr_bit = (1 << 2); in sunsab_init_one()
1002 up->gis_shift = 0; in sunsab_init_one()
1004 up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4); in sunsab_init_one()
1005 writeb(up->cached_pvr, &up->regs->w.pvr); in sunsab_init_one()
1006 up->cached_mode = readb(&up->regs->rw.mode); in sunsab_init_one()
1007 up->cached_mode |= SAB82532_MODE_FRTS; in sunsab_init_one()
1008 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1009 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_init_one()
1010 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1012 up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT; in sunsab_init_one()
1013 up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT; in sunsab_init_one()
1021 struct uart_sunsab_port *up; in sab_probe() local
1024 up = &sunsab_ports[inst * 2]; in sab_probe()
1026 err = sunsab_init_one(&up[0], op, in sab_probe()
1032 err = sunsab_init_one(&up[1], op, in sab_probe()
1039 &sunsab_reg, up[0].port.line, in sab_probe()
1043 &sunsab_reg, up[1].port.line, in sab_probe()
1046 err = uart_add_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1050 err = uart_add_one_port(&sunsab_reg, &up[1].port); in sab_probe()
1054 platform_set_drvdata(op, &up[0]); in sab_probe()
1061 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1064 up[1].port.membase, in sab_probe()
1068 up[0].port.membase, in sab_probe()
1076 struct uart_sunsab_port *up = platform_get_drvdata(op); in sab_remove() local
1078 uart_remove_one_port(&sunsab_reg, &up[1].port); in sab_remove()
1079 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_remove()
1081 up[1].port.membase, in sab_remove()
1084 up[0].port.membase, in sab_remove()