Lines Matching refs:up

95 static __inline__ void sunsab_tec_wait(struct uart_sunsab_port *up)  in sunsab_tec_wait()  argument
97 int timeout = up->tec_timeout; in sunsab_tec_wait()
99 while ((readb(&up->regs->r.star) & SAB82532_STAR_TEC) && --timeout) in sunsab_tec_wait()
103 static __inline__ void sunsab_cec_wait(struct uart_sunsab_port *up) in sunsab_cec_wait() argument
105 int timeout = up->cec_timeout; in sunsab_cec_wait()
107 while ((readb(&up->regs->r.star) & SAB82532_STAR_CEC) && --timeout) in sunsab_cec_wait()
112 receive_chars(struct uart_sunsab_port *up, in receive_chars() argument
122 if (up->port.state != NULL) /* Unopened serial console */ in receive_chars()
123 port = &up->port.state->port; in receive_chars()
132 count = readb(&up->regs->r.rbcl) & (SAB82532_RECV_FIFO_SIZE - 1); in receive_chars()
138 sunsab_cec_wait(up); in receive_chars()
139 writeb(SAB82532_CMDR_RFRD, &up->regs->w.cmdr); in receive_chars()
148 buf[i] = readb(&up->regs->r.rfifo[i]); in receive_chars()
152 sunsab_cec_wait(up); in receive_chars()
153 writeb(SAB82532_CMDR_RMC, &up->regs->w.cmdr); in receive_chars()
158 (up->port.line == up->port.cons->index)) in receive_chars()
165 up->port.icount.brk++; in receive_chars()
166 uart_handle_break(&up->port); in receive_chars()
174 up->port.icount.rx++; in receive_chars()
186 up->port.icount.brk++; in receive_chars()
193 if (uart_handle_break(&up->port)) in receive_chars()
196 up->port.icount.parity++; in receive_chars()
198 up->port.icount.frame++; in receive_chars()
200 up->port.icount.overrun++; in receive_chars()
205 stat->sreg.isr0 &= (up->port.read_status_mask & 0xff); in receive_chars()
206 stat->sreg.isr1 &= ((up->port.read_status_mask >> 8) & 0xff); in receive_chars()
216 if (uart_handle_sysrq_char(&up->port, ch) || !port) in receive_chars()
219 if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 && in receive_chars()
220 (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0) in receive_chars()
235 static void transmit_chars(struct uart_sunsab_port *up, in transmit_chars() argument
238 struct circ_buf *xmit = &up->port.state->xmit; in transmit_chars()
242 up->interrupt_mask1 |= SAB82532_IMR1_ALLS; in transmit_chars()
243 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
244 set_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
252 if (!(readb(&up->regs->r.star) & SAB82532_STAR_XFW)) in transmit_chars()
255 set_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
256 sunsab_tx_idle(up); in transmit_chars()
258 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { in transmit_chars()
259 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in transmit_chars()
260 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
264 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in transmit_chars()
265 writeb(up->interrupt_mask1, &up->regs->w.imr1); in transmit_chars()
266 clear_bit(SAB82532_ALLS, &up->irqflags); in transmit_chars()
269 clear_bit(SAB82532_XPR, &up->irqflags); in transmit_chars()
270 for (i = 0; i < up->port.fifosize; i++) { in transmit_chars()
272 &up->regs->w.xfifo[i]); in transmit_chars()
274 up->port.icount.tx++; in transmit_chars()
280 sunsab_cec_wait(up); in transmit_chars()
281 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in transmit_chars()
284 uart_write_wakeup(&up->port); in transmit_chars()
287 sunsab_stop_tx(&up->port); in transmit_chars()
290 static void check_status(struct uart_sunsab_port *up, in check_status() argument
294 uart_handle_dcd_change(&up->port, in check_status()
295 !(readb(&up->regs->r.vstr) & SAB82532_VSTR_CD)); in check_status()
298 uart_handle_cts_change(&up->port, in check_status()
299 (readb(&up->regs->r.star) & SAB82532_STAR_CTS)); in check_status()
301 if ((readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ^ up->dsr) { in check_status()
302 up->dsr = (readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ? 0 : 1; in check_status()
303 up->port.icount.dsr++; in check_status()
306 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_status()
311 struct uart_sunsab_port *up = dev_id; in sunsab_interrupt() local
317 spin_lock_irqsave(&up->port.lock, flags); in sunsab_interrupt()
320 gis = readb(&up->regs->r.gis) >> up->gis_shift; in sunsab_interrupt()
322 status.sreg.isr0 = readb(&up->regs->r.isr0); in sunsab_interrupt()
324 status.sreg.isr1 = readb(&up->regs->r.isr1); in sunsab_interrupt()
330 port = receive_chars(up, &status); in sunsab_interrupt()
333 check_status(up, &status); in sunsab_interrupt()
335 transmit_chars(up, &status); in sunsab_interrupt()
338 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_interrupt()
349 struct uart_sunsab_port *up = in sunsab_tx_empty() local
354 if (test_bit(SAB82532_ALLS, &up->irqflags)) in sunsab_tx_empty()
365 struct uart_sunsab_port *up = in sunsab_set_mctrl() local
369 up->cached_mode &= ~SAB82532_MODE_FRTS; in sunsab_set_mctrl()
370 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_set_mctrl()
372 up->cached_mode |= (SAB82532_MODE_FRTS | in sunsab_set_mctrl()
376 up->cached_pvr &= ~(up->pvr_dtr_bit); in sunsab_set_mctrl()
378 up->cached_pvr |= up->pvr_dtr_bit; in sunsab_set_mctrl()
381 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_set_mctrl()
382 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_set_mctrl()
383 sunsab_tx_idle(up); in sunsab_set_mctrl()
389 struct uart_sunsab_port *up = in sunsab_get_mctrl() local
396 val = readb(&up->regs->r.pvr); in sunsab_get_mctrl()
397 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR; in sunsab_get_mctrl()
399 val = readb(&up->regs->r.vstr); in sunsab_get_mctrl()
402 val = readb(&up->regs->r.star); in sunsab_get_mctrl()
411 struct uart_sunsab_port *up = in sunsab_stop_tx() local
414 up->interrupt_mask1 |= SAB82532_IMR1_XPR; in sunsab_stop_tx()
415 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_stop_tx()
419 static void sunsab_tx_idle(struct uart_sunsab_port *up) in sunsab_tx_idle() argument
421 if (test_bit(SAB82532_REGS_PENDING, &up->irqflags)) { in sunsab_tx_idle()
424 clear_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_tx_idle()
425 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_tx_idle()
426 writeb(up->cached_pvr, &up->regs->rw.pvr); in sunsab_tx_idle()
427 writeb(up->cached_dafo, &up->regs->w.dafo); in sunsab_tx_idle()
429 writeb(up->cached_ebrg & 0xff, &up->regs->w.bgr); in sunsab_tx_idle()
430 tmp = readb(&up->regs->rw.ccr2); in sunsab_tx_idle()
432 tmp |= (up->cached_ebrg >> 2) & 0xc0; in sunsab_tx_idle()
433 writeb(tmp, &up->regs->rw.ccr2); in sunsab_tx_idle()
440 struct uart_sunsab_port *up = in sunsab_start_tx() local
442 struct circ_buf *xmit = &up->port.state->xmit; in sunsab_start_tx()
448 up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR); in sunsab_start_tx()
449 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_start_tx()
451 if (!test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_start_tx()
454 clear_bit(SAB82532_ALLS, &up->irqflags); in sunsab_start_tx()
455 clear_bit(SAB82532_XPR, &up->irqflags); in sunsab_start_tx()
457 for (i = 0; i < up->port.fifosize; i++) { in sunsab_start_tx()
459 &up->regs->w.xfifo[i]); in sunsab_start_tx()
461 up->port.icount.tx++; in sunsab_start_tx()
467 sunsab_cec_wait(up); in sunsab_start_tx()
468 writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr); in sunsab_start_tx()
474 struct uart_sunsab_port *up = in sunsab_send_xchar() local
481 spin_lock_irqsave(&up->port.lock, flags); in sunsab_send_xchar()
483 sunsab_tec_wait(up); in sunsab_send_xchar()
484 writeb(ch, &up->regs->w.tic); in sunsab_send_xchar()
486 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_send_xchar()
492 struct uart_sunsab_port *up = in sunsab_stop_rx() local
495 up->interrupt_mask0 |= SAB82532_IMR0_TCD; in sunsab_stop_rx()
496 writeb(up->interrupt_mask1, &up->regs->w.imr0); in sunsab_stop_rx()
502 struct uart_sunsab_port *up = in sunsab_break_ctl() local
507 spin_lock_irqsave(&up->port.lock, flags); in sunsab_break_ctl()
509 val = up->cached_dafo; in sunsab_break_ctl()
514 up->cached_dafo = val; in sunsab_break_ctl()
516 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_break_ctl()
517 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_break_ctl()
518 sunsab_tx_idle(up); in sunsab_break_ctl()
520 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_break_ctl()
526 struct uart_sunsab_port *up = in sunsab_startup() local
530 int err = request_irq(up->port.irq, sunsab_interrupt, in sunsab_startup()
531 IRQF_SHARED, "sab", up); in sunsab_startup()
535 spin_lock_irqsave(&up->port.lock, flags); in sunsab_startup()
540 sunsab_cec_wait(up); in sunsab_startup()
541 sunsab_tec_wait(up); in sunsab_startup()
546 writeb(SAB82532_CMDR_RRES, &up->regs->w.cmdr); in sunsab_startup()
547 sunsab_cec_wait(up); in sunsab_startup()
548 writeb(SAB82532_CMDR_XRES, &up->regs->w.cmdr); in sunsab_startup()
553 (void) readb(&up->regs->r.isr0); in sunsab_startup()
554 (void) readb(&up->regs->r.isr1); in sunsab_startup()
559 writeb(0, &up->regs->w.ccr0); /* power-down */ in sunsab_startup()
561 SAB82532_CCR0_SM_ASYNC, &up->regs->w.ccr0); in sunsab_startup()
562 writeb(SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7, &up->regs->w.ccr1); in sunsab_startup()
564 SAB82532_CCR2_TOE, &up->regs->w.ccr2); in sunsab_startup()
565 writeb(0, &up->regs->w.ccr3); in sunsab_startup()
566 writeb(SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG, &up->regs->w.ccr4); in sunsab_startup()
567 up->cached_mode = (SAB82532_MODE_RTS | SAB82532_MODE_FCTS | in sunsab_startup()
569 writeb(up->cached_mode, &up->regs->w.mode); in sunsab_startup()
570 writeb(SAB82532_RFC_DPS|SAB82532_RFC_RFTH_32, &up->regs->w.rfc); in sunsab_startup()
572 tmp = readb(&up->regs->rw.ccr0); in sunsab_startup()
574 writeb(tmp, &up->regs->rw.ccr0); in sunsab_startup()
579 up->interrupt_mask0 = (SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_startup()
581 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_startup()
582 up->interrupt_mask1 = (SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_startup()
586 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_startup()
587 set_bit(SAB82532_ALLS, &up->irqflags); in sunsab_startup()
588 set_bit(SAB82532_XPR, &up->irqflags); in sunsab_startup()
590 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_startup()
598 struct uart_sunsab_port *up = in sunsab_shutdown() local
602 spin_lock_irqsave(&up->port.lock, flags); in sunsab_shutdown()
605 up->interrupt_mask0 = 0xff; in sunsab_shutdown()
606 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_shutdown()
607 up->interrupt_mask1 = 0xff; in sunsab_shutdown()
608 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_shutdown()
611 up->cached_dafo = readb(&up->regs->rw.dafo); in sunsab_shutdown()
612 up->cached_dafo &= ~SAB82532_DAFO_XBRK; in sunsab_shutdown()
613 writeb(up->cached_dafo, &up->regs->rw.dafo); in sunsab_shutdown()
616 up->cached_mode &= ~SAB82532_MODE_RAC; in sunsab_shutdown()
617 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_shutdown()
631 tmp = readb(&up->regs->rw.ccr0); in sunsab_shutdown()
633 writeb(tmp, &up->regs->rw.ccr0); in sunsab_shutdown()
636 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_shutdown()
637 free_irq(up->port.irq, up); in sunsab_shutdown()
683 static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cflag, in sunsab_convert_to_sab() argument
715 up->cached_dafo = dafo; in sunsab_convert_to_sab()
719 up->cached_ebrg = n | (m << 6); in sunsab_convert_to_sab()
721 up->tec_timeout = (10 * 1000000) / baud; in sunsab_convert_to_sab()
722 up->cec_timeout = up->tec_timeout >> 2; in sunsab_convert_to_sab()
733 up->port.read_status_mask = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME | in sunsab_convert_to_sab()
736 up->port.read_status_mask |= (SAB82532_ISR1_CSC | in sunsab_convert_to_sab()
740 up->port.read_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
743 up->port.read_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
748 up->port.ignore_status_mask = 0; in sunsab_convert_to_sab()
750 up->port.ignore_status_mask |= (SAB82532_ISR0_PERR | in sunsab_convert_to_sab()
753 up->port.ignore_status_mask |= (SAB82532_ISR1_BRK << 8); in sunsab_convert_to_sab()
759 up->port.ignore_status_mask |= SAB82532_ISR0_RFO; in sunsab_convert_to_sab()
766 up->port.ignore_status_mask |= (SAB82532_ISR0_RPF | in sunsab_convert_to_sab()
769 uart_update_timeout(&up->port, cflag, in sunsab_convert_to_sab()
770 (up->port.uartclk / (16 * quot))); in sunsab_convert_to_sab()
775 up->cached_mode |= SAB82532_MODE_RAC; in sunsab_convert_to_sab()
776 set_bit(SAB82532_REGS_PENDING, &up->irqflags); in sunsab_convert_to_sab()
777 if (test_bit(SAB82532_XPR, &up->irqflags)) in sunsab_convert_to_sab()
778 sunsab_tx_idle(up); in sunsab_convert_to_sab()
785 struct uart_sunsab_port *up = in sunsab_set_termios() local
791 spin_lock_irqsave(&up->port.lock, flags); in sunsab_set_termios()
792 sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot); in sunsab_set_termios()
793 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_set_termios()
798 struct uart_sunsab_port *up = (void *)port; in sunsab_type() local
801 sprintf(buf, "SAB82532 %s", sab82532_version[up->type]); in sunsab_type()
855 struct uart_sunsab_port *up = in sunsab_console_putchar() local
858 sunsab_tec_wait(up); in sunsab_console_putchar()
859 writeb(c, &up->regs->w.tic); in sunsab_console_putchar()
864 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_write() local
868 if (up->port.sysrq || oops_in_progress) in sunsab_console_write()
869 locked = spin_trylock_irqsave(&up->port.lock, flags); in sunsab_console_write()
871 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_write()
873 uart_console_write(&up->port, s, n, sunsab_console_putchar); in sunsab_console_write()
874 sunsab_tec_wait(up); in sunsab_console_write()
877 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_write()
882 struct uart_sunsab_port *up = &sunsab_ports[con->index]; in sunsab_console_setup() local
892 if (up->port.type != PORT_SUNSAB) in sunsab_console_setup()
898 sunserial_console_termios(con, up->port.dev->of_node); in sunsab_console_setup()
919 spin_lock_init(&up->port.lock); in sunsab_console_setup()
924 sunsab_startup(&up->port); in sunsab_console_setup()
926 spin_lock_irqsave(&up->port.lock, flags); in sunsab_console_setup()
931 up->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR | in sunsab_console_setup()
933 writeb(up->interrupt_mask0, &up->regs->w.imr0); in sunsab_console_setup()
934 up->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS | in sunsab_console_setup()
938 writeb(up->interrupt_mask1, &up->regs->w.imr1); in sunsab_console_setup()
940 quot = uart_get_divisor(&up->port, baud); in sunsab_console_setup()
941 sunsab_convert_to_sab(up, con->cflag, 0, baud, quot); in sunsab_console_setup()
942 sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); in sunsab_console_setup()
944 spin_unlock_irqrestore(&up->port.lock, flags); in sunsab_console_setup()
968 static int sunsab_init_one(struct uart_sunsab_port *up, in sunsab_init_one() argument
973 up->port.line = line; in sunsab_init_one()
974 up->port.dev = &op->dev; in sunsab_init_one()
976 up->port.mapbase = op->resource[0].start + offset; in sunsab_init_one()
977 up->port.membase = of_ioremap(&op->resource[0], offset, in sunsab_init_one()
980 if (!up->port.membase) in sunsab_init_one()
982 up->regs = (union sab82532_async_regs __iomem *) up->port.membase; in sunsab_init_one()
984 up->port.irq = op->archdata.irqs[0]; in sunsab_init_one()
986 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; in sunsab_init_one()
987 up->port.iotype = UPIO_MEM; in sunsab_init_one()
989 writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc); in sunsab_init_one()
991 up->port.ops = &sunsab_pops; in sunsab_init_one()
992 up->port.type = PORT_SUNSAB; in sunsab_init_one()
993 up->port.uartclk = SAB_BASE_BAUD; in sunsab_init_one()
995 up->type = readb(&up->regs->r.vstr) & 0x0f; in sunsab_init_one()
996 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->regs->w.pcr); in sunsab_init_one()
997 writeb(0xff, &up->regs->w.pim); in sunsab_init_one()
998 if ((up->port.line & 0x1) == 0) { in sunsab_init_one()
999 up->pvr_dsr_bit = (1 << 0); in sunsab_init_one()
1000 up->pvr_dtr_bit = (1 << 1); in sunsab_init_one()
1001 up->gis_shift = 2; in sunsab_init_one()
1003 up->pvr_dsr_bit = (1 << 3); in sunsab_init_one()
1004 up->pvr_dtr_bit = (1 << 2); in sunsab_init_one()
1005 up->gis_shift = 0; in sunsab_init_one()
1007 up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4); in sunsab_init_one()
1008 writeb(up->cached_pvr, &up->regs->w.pvr); in sunsab_init_one()
1009 up->cached_mode = readb(&up->regs->rw.mode); in sunsab_init_one()
1010 up->cached_mode |= SAB82532_MODE_FRTS; in sunsab_init_one()
1011 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1012 up->cached_mode |= SAB82532_MODE_RTS; in sunsab_init_one()
1013 writeb(up->cached_mode, &up->regs->rw.mode); in sunsab_init_one()
1015 up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT; in sunsab_init_one()
1016 up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT; in sunsab_init_one()
1024 struct uart_sunsab_port *up; in sab_probe() local
1027 up = &sunsab_ports[inst * 2]; in sab_probe()
1029 err = sunsab_init_one(&up[0], op, in sab_probe()
1035 err = sunsab_init_one(&up[1], op, in sab_probe()
1042 &sunsab_reg, up[0].port.line, in sab_probe()
1046 &sunsab_reg, up[1].port.line, in sab_probe()
1049 err = uart_add_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1053 err = uart_add_one_port(&sunsab_reg, &up[1].port); in sab_probe()
1057 platform_set_drvdata(op, &up[0]); in sab_probe()
1064 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_probe()
1067 up[1].port.membase, in sab_probe()
1071 up[0].port.membase, in sab_probe()
1079 struct uart_sunsab_port *up = platform_get_drvdata(op); in sab_remove() local
1081 uart_remove_one_port(&sunsab_reg, &up[1].port); in sab_remove()
1082 uart_remove_one_port(&sunsab_reg, &up[0].port); in sab_remove()
1084 up[1].port.membase, in sab_remove()
1087 up[0].port.membase, in sab_remove()