Lines Matching +full:up +full:-
1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 1998-1999 Pete Zaitcev (zaitcev@yahoo.com)
13 * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
16 * David S. Miller (davem@davemloft.net), 2002-Jul-29
104 static unsigned int serial_in(struct uart_sunsu_port *up, int offset) in serial_in() argument
106 offset <<= up->port.regshift; in serial_in()
108 switch (up->port.iotype) { in serial_in()
110 outb(up->port.hub6 - 1 + offset, up->port.iobase); in serial_in()
111 return inb(up->port.iobase + 1); in serial_in()
114 return readb(up->port.membase + offset); in serial_in()
117 return inb(up->port.iobase + offset); in serial_in()
121 static void serial_out(struct uart_sunsu_port *up, int offset, int value) in serial_out() argument
135 offset <<= up->port.regshift; in serial_out()
137 switch (up->port.iotype) { in serial_out()
139 outb(up->port.hub6 - 1 + offset, up->port.iobase); in serial_out()
140 outb(value, up->port.iobase + 1); in serial_out()
144 writeb(value, up->port.membase + offset); in serial_out()
148 outb(value, up->port.iobase + offset); in serial_out()
158 #define serial_inp(up, offset) serial_in(up, offset) argument
159 #define serial_outp(up, offset, value) serial_out(up, offset, value) argument
165 static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value) in serial_icr_write() argument
167 serial_out(up, UART_SCR, offset); in serial_icr_write()
168 serial_out(up, UART_ICR, value); in serial_icr_write()
172 static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset)
176 serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
177 serial_out(up, UART_SCR, offset);
178 value = serial_in(up, UART_ICR);
179 serial_icr_write(up, UART_ACR, up->acr);
190 static int __enable_rsa(struct uart_sunsu_port *up) in __enable_rsa() argument
195 mode = serial_inp(up, UART_RSA_MSR); in __enable_rsa()
199 serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); in __enable_rsa()
200 mode = serial_inp(up, UART_RSA_MSR); in __enable_rsa()
205 up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; in __enable_rsa()
210 static void enable_rsa(struct uart_sunsu_port *up) in enable_rsa() argument
212 if (up->port.type == PORT_RSA) { in enable_rsa()
213 if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { in enable_rsa()
214 spin_lock_irq(&up->port.lock); in enable_rsa()
215 __enable_rsa(up); in enable_rsa()
216 spin_unlock_irq(&up->port.lock); in enable_rsa()
218 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) in enable_rsa()
219 serial_outp(up, UART_RSA_FRR, 0); in enable_rsa()
229 static void disable_rsa(struct uart_sunsu_port *up) in disable_rsa() argument
234 if (up->port.type == PORT_RSA && in disable_rsa()
235 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { in disable_rsa()
236 spin_lock_irq(&up->port.lock); in disable_rsa()
238 mode = serial_inp(up, UART_RSA_MSR); in disable_rsa()
242 serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); in disable_rsa()
243 mode = serial_inp(up, UART_RSA_MSR); in disable_rsa()
248 up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; in disable_rsa()
249 spin_unlock_irq(&up->port.lock); in disable_rsa()
256 if (p->ier & UART_IER_THRI) { in __stop_tx()
257 p->ier &= ~UART_IER_THRI; in __stop_tx()
258 serial_out(p, UART_IER, p->ier); in __stop_tx()
264 struct uart_sunsu_port *up = in sunsu_stop_tx() local
267 __stop_tx(up); in sunsu_stop_tx()
272 if (up->port.type == PORT_16C950) { in sunsu_stop_tx()
273 up->acr |= UART_ACR_TXDIS; in sunsu_stop_tx()
274 serial_icr_write(up, UART_ACR, up->acr); in sunsu_stop_tx()
280 struct uart_sunsu_port *up = in sunsu_start_tx() local
283 if (!(up->ier & UART_IER_THRI)) { in sunsu_start_tx()
284 up->ier |= UART_IER_THRI; in sunsu_start_tx()
285 serial_out(up, UART_IER, up->ier); in sunsu_start_tx()
289 * Re-enable the transmitter if we disabled it. in sunsu_start_tx()
291 if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { in sunsu_start_tx()
292 up->acr &= ~UART_ACR_TXDIS; in sunsu_start_tx()
293 serial_icr_write(up, UART_ACR, up->acr); in sunsu_start_tx()
299 struct uart_sunsu_port *up = in sunsu_stop_rx() local
302 up->ier &= ~UART_IER_RLSI; in sunsu_stop_rx()
303 up->port.read_status_mask &= ~UART_LSR_DR; in sunsu_stop_rx()
304 serial_out(up, UART_IER, up->ier); in sunsu_stop_rx()
309 struct uart_sunsu_port *up = in sunsu_enable_ms() local
313 spin_lock_irqsave(&up->port.lock, flags); in sunsu_enable_ms()
314 up->ier |= UART_IER_MSI; in sunsu_enable_ms()
315 serial_out(up, UART_IER, up->ier); in sunsu_enable_ms()
316 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_enable_ms()
320 receive_chars(struct uart_sunsu_port *up, unsigned char *status) in receive_chars() argument
322 struct tty_port *port = &up->port.state->port; in receive_chars()
328 ch = serial_inp(up, UART_RX); in receive_chars()
330 up->port.icount.rx++; in receive_chars()
339 up->port.icount.brk++; in receive_chars()
340 if (up->port.cons != NULL && in receive_chars()
341 up->port.line == up->port.cons->index) in receive_chars()
349 if (uart_handle_break(&up->port)) in receive_chars()
352 up->port.icount.parity++; in receive_chars()
354 up->port.icount.frame++; in receive_chars()
356 up->port.icount.overrun++; in receive_chars()
361 *status &= up->port.read_status_mask; in receive_chars()
363 if (up->port.cons != NULL && in receive_chars()
364 up->port.line == up->port.cons->index) { in receive_chars()
366 *status |= up->lsr_break_flag; in receive_chars()
367 up->lsr_break_flag = 0; in receive_chars()
377 if (uart_handle_sysrq_char(&up->port, ch)) in receive_chars()
379 if ((*status & up->port.ignore_status_mask) == 0) in receive_chars()
389 *status = serial_inp(up, UART_LSR); in receive_chars()
390 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); in receive_chars()
396 static void transmit_chars(struct uart_sunsu_port *up) in transmit_chars() argument
398 struct circ_buf *xmit = &up->port.state->xmit; in transmit_chars()
401 if (up->port.x_char) { in transmit_chars()
402 serial_outp(up, UART_TX, up->port.x_char); in transmit_chars()
403 up->port.icount.tx++; in transmit_chars()
404 up->port.x_char = 0; in transmit_chars()
407 if (uart_tx_stopped(&up->port)) { in transmit_chars()
408 sunsu_stop_tx(&up->port); in transmit_chars()
412 __stop_tx(up); in transmit_chars()
416 count = up->port.fifosize; in transmit_chars()
418 serial_out(up, UART_TX, xmit->buf[xmit->tail]); in transmit_chars()
419 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in transmit_chars()
420 up->port.icount.tx++; in transmit_chars()
423 } while (--count > 0); in transmit_chars()
426 uart_write_wakeup(&up->port); in transmit_chars()
429 __stop_tx(up); in transmit_chars()
432 static void check_modem_status(struct uart_sunsu_port *up) in check_modem_status() argument
436 status = serial_in(up, UART_MSR); in check_modem_status()
442 up->port.icount.rng++; in check_modem_status()
444 up->port.icount.dsr++; in check_modem_status()
446 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); in check_modem_status()
448 uart_handle_cts_change(&up->port, status & UART_MSR_CTS); in check_modem_status()
450 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_modem_status()
455 struct uart_sunsu_port *up = dev_id; in sunsu_serial_interrupt() local
459 spin_lock_irqsave(&up->port.lock, flags); in sunsu_serial_interrupt()
462 status = serial_inp(up, UART_LSR); in sunsu_serial_interrupt()
464 receive_chars(up, &status); in sunsu_serial_interrupt()
465 check_modem_status(up); in sunsu_serial_interrupt()
467 transmit_chars(up); in sunsu_serial_interrupt()
469 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_serial_interrupt()
471 tty_flip_buffer_push(&up->port.state->port); in sunsu_serial_interrupt()
473 spin_lock_irqsave(&up->port.lock, flags); in sunsu_serial_interrupt()
475 } while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)); in sunsu_serial_interrupt()
477 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_serial_interrupt()
488 static void sunsu_change_mouse_baud(struct uart_sunsu_port *up) in sunsu_change_mouse_baud() argument
490 unsigned int cur_cflag = up->cflag; in sunsu_change_mouse_baud()
493 up->cflag &= ~CBAUD; in sunsu_change_mouse_baud()
494 up->cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud); in sunsu_change_mouse_baud()
496 quot = up->port.uartclk / (16 * new_baud); in sunsu_change_mouse_baud()
498 sunsu_change_speed(&up->port, up->cflag, 0, quot); in sunsu_change_mouse_baud()
501 static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break) in receive_kbd_ms_chars() argument
504 unsigned char ch = serial_inp(up, UART_RX); in receive_kbd_ms_chars()
506 /* Stop-A is handled by drivers/char/keyboard.c now. */ in receive_kbd_ms_chars()
507 if (up->su_type == SU_PORT_KBD) { in receive_kbd_ms_chars()
509 serio_interrupt(&up->serio, ch, 0); in receive_kbd_ms_chars()
511 } else if (up->su_type == SU_PORT_MS) { in receive_kbd_ms_chars()
516 sunsu_change_mouse_baud(up); in receive_kbd_ms_chars()
523 serio_interrupt(&up->serio, ch, 0); in receive_kbd_ms_chars()
528 } while (serial_in(up, UART_LSR) & UART_LSR_DR); in receive_kbd_ms_chars()
533 struct uart_sunsu_port *up = dev_id; in sunsu_kbd_ms_interrupt() local
535 if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) { in sunsu_kbd_ms_interrupt()
536 unsigned char status = serial_inp(up, UART_LSR); in sunsu_kbd_ms_interrupt()
539 receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0); in sunsu_kbd_ms_interrupt()
547 struct uart_sunsu_port *up = in sunsu_tx_empty() local
552 spin_lock_irqsave(&up->port.lock, flags); in sunsu_tx_empty()
553 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; in sunsu_tx_empty()
554 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_tx_empty()
561 struct uart_sunsu_port *up = in sunsu_get_mctrl() local
566 status = serial_in(up, UART_MSR); in sunsu_get_mctrl()
582 struct uart_sunsu_port *up = in sunsu_set_mctrl() local
597 serial_out(up, UART_MCR, mcr); in sunsu_set_mctrl()
602 struct uart_sunsu_port *up = in sunsu_break_ctl() local
606 spin_lock_irqsave(&up->port.lock, flags); in sunsu_break_ctl()
607 if (break_state == -1) in sunsu_break_ctl()
608 up->lcr |= UART_LCR_SBC; in sunsu_break_ctl()
610 up->lcr &= ~UART_LCR_SBC; in sunsu_break_ctl()
611 serial_out(up, UART_LCR, up->lcr); in sunsu_break_ctl()
612 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_break_ctl()
617 struct uart_sunsu_port *up = in sunsu_startup() local
622 if (up->port.type == PORT_16C950) { in sunsu_startup()
623 /* Wake up and initialize UART */ in sunsu_startup()
624 up->acr = 0; in sunsu_startup()
625 serial_outp(up, UART_LCR, 0xBF); in sunsu_startup()
626 serial_outp(up, UART_EFR, UART_EFR_ECB); in sunsu_startup()
627 serial_outp(up, UART_IER, 0); in sunsu_startup()
628 serial_outp(up, UART_LCR, 0); in sunsu_startup()
629 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ in sunsu_startup()
630 serial_outp(up, UART_LCR, 0xBF); in sunsu_startup()
631 serial_outp(up, UART_EFR, UART_EFR_ECB); in sunsu_startup()
632 serial_outp(up, UART_LCR, 0); in sunsu_startup()
637 * If this is an RSA port, see if we can kick it up to the in sunsu_startup()
640 enable_rsa(up); in sunsu_startup()
647 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) { in sunsu_startup()
648 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); in sunsu_startup()
649 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | in sunsu_startup()
651 serial_outp(up, UART_FCR, 0); in sunsu_startup()
657 (void) serial_inp(up, UART_LSR); in sunsu_startup()
658 (void) serial_inp(up, UART_RX); in sunsu_startup()
659 (void) serial_inp(up, UART_IIR); in sunsu_startup()
660 (void) serial_inp(up, UART_MSR); in sunsu_startup()
667 if (!(up->port.flags & UPF_BUGGY_UART) && in sunsu_startup()
668 (serial_inp(up, UART_LSR) == 0xff)) { in sunsu_startup()
669 printk("ttyS%d: LSR safety check engaged!\n", up->port.line); in sunsu_startup()
670 return -ENODEV; in sunsu_startup()
673 if (up->su_type != SU_PORT_PORT) { in sunsu_startup()
674 retval = request_irq(up->port.irq, sunsu_kbd_ms_interrupt, in sunsu_startup()
675 IRQF_SHARED, su_typev[up->su_type], up); in sunsu_startup()
677 retval = request_irq(up->port.irq, sunsu_serial_interrupt, in sunsu_startup()
678 IRQF_SHARED, su_typev[up->su_type], up); in sunsu_startup()
681 printk("su: Cannot register IRQ %d\n", up->port.irq); in sunsu_startup()
688 serial_outp(up, UART_LCR, UART_LCR_WLEN8); in sunsu_startup()
690 spin_lock_irqsave(&up->port.lock, flags); in sunsu_startup()
692 up->port.mctrl |= TIOCM_OUT2; in sunsu_startup()
694 sunsu_set_mctrl(&up->port, up->port.mctrl); in sunsu_startup()
695 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_startup()
702 up->ier = UART_IER_RLSI | UART_IER_RDI; in sunsu_startup()
703 serial_outp(up, UART_IER, up->ier); in sunsu_startup()
705 if (up->port.flags & UPF_FOURPORT) { in sunsu_startup()
710 icp = (up->port.iobase & 0xfe0) | 0x01f; in sunsu_startup()
718 (void) serial_inp(up, UART_LSR); in sunsu_startup()
719 (void) serial_inp(up, UART_RX); in sunsu_startup()
720 (void) serial_inp(up, UART_IIR); in sunsu_startup()
721 (void) serial_inp(up, UART_MSR); in sunsu_startup()
728 struct uart_sunsu_port *up = in sunsu_shutdown() local
735 up->ier = 0; in sunsu_shutdown()
736 serial_outp(up, UART_IER, 0); in sunsu_shutdown()
738 spin_lock_irqsave(&up->port.lock, flags); in sunsu_shutdown()
739 if (up->port.flags & UPF_FOURPORT) { in sunsu_shutdown()
741 inb((up->port.iobase & 0xfe0) | 0x1f); in sunsu_shutdown()
742 up->port.mctrl |= TIOCM_OUT1; in sunsu_shutdown()
744 up->port.mctrl &= ~TIOCM_OUT2; in sunsu_shutdown()
746 sunsu_set_mctrl(&up->port, up->port.mctrl); in sunsu_shutdown()
747 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_shutdown()
752 serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); in sunsu_shutdown()
753 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | in sunsu_shutdown()
756 serial_outp(up, UART_FCR, 0); in sunsu_shutdown()
762 disable_rsa(up); in sunsu_shutdown()
768 (void) serial_in(up, UART_RX); in sunsu_shutdown()
770 free_irq(up->port.irq, up); in sunsu_shutdown()
777 struct uart_sunsu_port *up = in sunsu_change_speed() local
814 if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 && in sunsu_change_speed()
815 up->rev == 0x5201) in sunsu_change_speed()
818 if (uart_config[up->port.type].flags & UART_USE_FIFO) { in sunsu_change_speed()
819 if ((up->port.uartclk / quot) < (2400 * 16)) in sunsu_change_speed()
822 else if (up->port.type == PORT_RSA) in sunsu_change_speed()
828 if (up->port.type == PORT_16750) in sunsu_change_speed()
835 spin_lock_irqsave(&up->port.lock, flags); in sunsu_change_speed()
838 * Update the per-port timeout. in sunsu_change_speed()
840 uart_update_timeout(port, cflag, (port->uartclk / (16 * quot))); in sunsu_change_speed()
842 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in sunsu_change_speed()
844 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; in sunsu_change_speed()
846 up->port.read_status_mask |= UART_LSR_BI; in sunsu_change_speed()
851 up->port.ignore_status_mask = 0; in sunsu_change_speed()
853 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in sunsu_change_speed()
855 up->port.ignore_status_mask |= UART_LSR_BI; in sunsu_change_speed()
861 up->port.ignore_status_mask |= UART_LSR_OE; in sunsu_change_speed()
868 up->port.ignore_status_mask |= UART_LSR_DR; in sunsu_change_speed()
873 up->ier &= ~UART_IER_MSI; in sunsu_change_speed()
874 if (UART_ENABLE_MS(&up->port, cflag)) in sunsu_change_speed()
875 up->ier |= UART_IER_MSI; in sunsu_change_speed()
877 serial_out(up, UART_IER, up->ier); in sunsu_change_speed()
879 if (uart_config[up->port.type].flags & UART_STARTECH) { in sunsu_change_speed()
880 serial_outp(up, UART_LCR, 0xBF); in sunsu_change_speed()
881 serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0); in sunsu_change_speed()
883 serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ in sunsu_change_speed()
884 serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */ in sunsu_change_speed()
885 serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */ in sunsu_change_speed()
886 if (up->port.type == PORT_16750) in sunsu_change_speed()
887 serial_outp(up, UART_FCR, fcr); /* set fcr */ in sunsu_change_speed()
888 serial_outp(up, UART_LCR, cval); /* reset DLAB */ in sunsu_change_speed()
889 up->lcr = cval; /* Save LCR */ in sunsu_change_speed()
890 if (up->port.type != PORT_16750) { in sunsu_change_speed()
893 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); in sunsu_change_speed()
895 serial_outp(up, UART_FCR, fcr); /* set fcr */ in sunsu_change_speed()
898 up->cflag = cflag; in sunsu_change_speed()
900 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_change_speed()
912 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); in sunsu_set_termios()
915 sunsu_change_speed(port, termios->c_cflag, termios->c_iflag, quot); in sunsu_set_termios()
929 struct uart_sunsu_port *up = in sunsu_config_port() local
938 port->type = up->type_probed; /* XXX */ in sunsu_config_port()
945 return -EINVAL; in sunsu_verify_port()
951 int type = port->type; in sunsu_type()
988 struct uart_sunsu_port *up = serio->port_data; in sunsu_serio_write() local
995 lsr = serial_in(up, UART_LSR); in sunsu_serio_write()
999 serial_out(up, UART_TX, ch); in sunsu_serio_write()
1008 struct uart_sunsu_port *up = serio->port_data; in sunsu_serio_open() local
1013 if (!up->serio_open) { in sunsu_serio_open()
1014 up->serio_open = 1; in sunsu_serio_open()
1017 ret = -EBUSY; in sunsu_serio_open()
1025 struct uart_sunsu_port *up = serio->port_data; in sunsu_serio_close() local
1029 up->serio_open = 0; in sunsu_serio_close()
1035 static void sunsu_autoconfig(struct uart_sunsu_port *up) in sunsu_autoconfig() argument
1041 if (up->su_type == SU_PORT_NONE) in sunsu_autoconfig()
1044 up->type_probed = PORT_UNKNOWN; in sunsu_autoconfig()
1045 up->port.iotype = UPIO_MEM; in sunsu_autoconfig()
1047 spin_lock_irqsave(&up->port.lock, flags); in sunsu_autoconfig()
1049 if (!(up->port.flags & UPF_BUGGY_UART)) { in sunsu_autoconfig()
1056 * 0x80 is a non-existent port; which should be safe since in sunsu_autoconfig()
1059 scratch = serial_inp(up, UART_IER); in sunsu_autoconfig()
1060 serial_outp(up, UART_IER, 0); in sunsu_autoconfig()
1064 scratch2 = serial_inp(up, UART_IER); in sunsu_autoconfig()
1065 serial_outp(up, UART_IER, 0x0f); in sunsu_autoconfig()
1069 scratch3 = serial_inp(up, UART_IER); in sunsu_autoconfig()
1070 serial_outp(up, UART_IER, scratch); in sunsu_autoconfig()
1075 save_mcr = serial_in(up, UART_MCR); in sunsu_autoconfig()
1076 save_lcr = serial_in(up, UART_LCR); in sunsu_autoconfig()
1085 * that conflicts with COM 1-4 --- we hope! in sunsu_autoconfig()
1087 if (!(up->port.flags & UPF_SKIP_TEST)) { in sunsu_autoconfig()
1088 serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); in sunsu_autoconfig()
1089 status1 = serial_inp(up, UART_MSR) & 0xF0; in sunsu_autoconfig()
1090 serial_outp(up, UART_MCR, save_mcr); in sunsu_autoconfig()
1094 serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */ in sunsu_autoconfig()
1095 serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */ in sunsu_autoconfig()
1096 serial_outp(up, UART_LCR, 0); in sunsu_autoconfig()
1097 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); in sunsu_autoconfig()
1098 scratch = serial_in(up, UART_IIR) >> 6; in sunsu_autoconfig()
1101 up->port.type = PORT_16450; in sunsu_autoconfig()
1104 up->port.type = PORT_UNKNOWN; in sunsu_autoconfig()
1107 up->port.type = PORT_16550; in sunsu_autoconfig()
1110 up->port.type = PORT_16550A; in sunsu_autoconfig()
1113 if (up->port.type == PORT_16550A) { in sunsu_autoconfig()
1115 serial_outp(up, UART_LCR, UART_LCR_DLAB); in sunsu_autoconfig()
1116 if (serial_in(up, UART_EFR) == 0) { in sunsu_autoconfig()
1117 up->port.type = PORT_16650; in sunsu_autoconfig()
1119 serial_outp(up, UART_LCR, 0xBF); in sunsu_autoconfig()
1120 if (serial_in(up, UART_EFR) == 0) in sunsu_autoconfig()
1121 up->port.type = PORT_16650V2; in sunsu_autoconfig()
1124 if (up->port.type == PORT_16550A) { in sunsu_autoconfig()
1126 serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB); in sunsu_autoconfig()
1127 serial_outp(up, UART_FCR, in sunsu_autoconfig()
1129 scratch = serial_in(up, UART_IIR) >> 5; in sunsu_autoconfig()
1137 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); in sunsu_autoconfig()
1138 serial_outp(up, UART_LCR, 0); in sunsu_autoconfig()
1139 serial_outp(up, UART_FCR, in sunsu_autoconfig()
1141 scratch = serial_in(up, UART_IIR) >> 5; in sunsu_autoconfig()
1143 up->port.type = PORT_16750; in sunsu_autoconfig()
1145 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); in sunsu_autoconfig()
1147 serial_outp(up, UART_LCR, save_lcr); in sunsu_autoconfig()
1148 if (up->port.type == PORT_16450) { in sunsu_autoconfig()
1149 scratch = serial_in(up, UART_SCR); in sunsu_autoconfig()
1150 serial_outp(up, UART_SCR, 0xa5); in sunsu_autoconfig()
1151 status1 = serial_in(up, UART_SCR); in sunsu_autoconfig()
1152 serial_outp(up, UART_SCR, 0x5a); in sunsu_autoconfig()
1153 status2 = serial_in(up, UART_SCR); in sunsu_autoconfig()
1154 serial_outp(up, UART_SCR, scratch); in sunsu_autoconfig()
1157 up->port.type = PORT_8250; in sunsu_autoconfig()
1160 up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size; in sunsu_autoconfig()
1162 if (up->port.type == PORT_UNKNOWN) in sunsu_autoconfig()
1164 up->type_probed = up->port.type; /* XXX */ in sunsu_autoconfig()
1170 if (up->port.type == PORT_RSA) in sunsu_autoconfig()
1171 serial_outp(up, UART_RSA_FRR, 0); in sunsu_autoconfig()
1173 serial_outp(up, UART_MCR, save_mcr); in sunsu_autoconfig()
1174 serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO | in sunsu_autoconfig()
1177 serial_outp(up, UART_FCR, 0); in sunsu_autoconfig()
1178 (void)serial_in(up, UART_RX); in sunsu_autoconfig()
1179 serial_outp(up, UART_IER, 0); in sunsu_autoconfig()
1182 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_autoconfig()
1192 static int sunsu_kbd_ms_init(struct uart_sunsu_port *up) in sunsu_kbd_ms_init() argument
1199 if (up->su_type == SU_PORT_KBD) { in sunsu_kbd_ms_init()
1200 up->cflag = B1200 | CS8 | CLOCAL | CREAD; in sunsu_kbd_ms_init()
1203 up->cflag = B4800 | CS8 | CLOCAL | CREAD; in sunsu_kbd_ms_init()
1206 quot = up->port.uartclk / (16 * baud); in sunsu_kbd_ms_init()
1208 sunsu_autoconfig(up); in sunsu_kbd_ms_init()
1209 if (up->port.type == PORT_UNKNOWN) in sunsu_kbd_ms_init()
1210 return -ENODEV; in sunsu_kbd_ms_init()
1213 up->port.dev->of_node, in sunsu_kbd_ms_init()
1214 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse", in sunsu_kbd_ms_init()
1215 (unsigned long long) up->port.mapbase, in sunsu_kbd_ms_init()
1216 up->port.irq); in sunsu_kbd_ms_init()
1219 serio = &up->serio; in sunsu_kbd_ms_init()
1220 serio->port_data = up; in sunsu_kbd_ms_init()
1222 serio->id.type = SERIO_RS232; in sunsu_kbd_ms_init()
1223 if (up->su_type == SU_PORT_KBD) { in sunsu_kbd_ms_init()
1224 serio->id.proto = SERIO_SUNKBD; in sunsu_kbd_ms_init()
1225 strlcpy(serio->name, "sukbd", sizeof(serio->name)); in sunsu_kbd_ms_init()
1227 serio->id.proto = SERIO_SUN; in sunsu_kbd_ms_init()
1228 serio->id.extra = 1; in sunsu_kbd_ms_init()
1229 strlcpy(serio->name, "sums", sizeof(serio->name)); in sunsu_kbd_ms_init()
1231 strlcpy(serio->phys, in sunsu_kbd_ms_init()
1232 (!(up->port.line & 1) ? "su/serio0" : "su/serio1"), in sunsu_kbd_ms_init()
1233 sizeof(serio->phys)); in sunsu_kbd_ms_init()
1235 serio->write = sunsu_serio_write; in sunsu_kbd_ms_init()
1236 serio->open = sunsu_serio_open; in sunsu_kbd_ms_init()
1237 serio->close = sunsu_serio_close; in sunsu_kbd_ms_init()
1238 serio->dev.parent = up->port.dev; in sunsu_kbd_ms_init()
1243 sunsu_change_speed(&up->port, up->cflag, 0, quot); in sunsu_kbd_ms_init()
1245 sunsu_startup(&up->port); in sunsu_kbd_ms_init()
1250 * ------------------------------------------------------------
1252 * ------------------------------------------------------------
1262 static void wait_for_xmitr(struct uart_sunsu_port *up) in wait_for_xmitr() argument
1266 /* Wait up to 10ms for the character(s) to be sent. */ in wait_for_xmitr()
1268 status = serial_in(up, UART_LSR); in wait_for_xmitr()
1271 up->lsr_break_flag = UART_LSR_BI; in wait_for_xmitr()
1273 if (--tmout == 0) in wait_for_xmitr()
1278 /* Wait up to 1s for flow control if necessary */ in wait_for_xmitr()
1279 if (up->port.flags & UPF_CONS_FLOW) { in wait_for_xmitr()
1281 while (--tmout && in wait_for_xmitr()
1282 ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) in wait_for_xmitr()
1289 struct uart_sunsu_port *up = in sunsu_console_putchar() local
1292 wait_for_xmitr(up); in sunsu_console_putchar()
1293 serial_out(up, UART_TX, ch); in sunsu_console_putchar()
1303 struct uart_sunsu_port *up = &sunsu_ports[co->index]; in sunsu_console_write() local
1308 if (up->port.sysrq || oops_in_progress) in sunsu_console_write()
1309 locked = spin_trylock_irqsave(&up->port.lock, flags); in sunsu_console_write()
1311 spin_lock_irqsave(&up->port.lock, flags); in sunsu_console_write()
1316 ier = serial_in(up, UART_IER); in sunsu_console_write()
1317 serial_out(up, UART_IER, 0); in sunsu_console_write()
1319 uart_console_write(&up->port, s, count, sunsu_console_putchar); in sunsu_console_write()
1325 wait_for_xmitr(up); in sunsu_console_write()
1326 serial_out(up, UART_IER, ier); in sunsu_console_write()
1329 spin_unlock_irqrestore(&up->port.lock, flags); in sunsu_console_write()
1334 * - construct a cflag setting for the first su_open()
1335 * - initialize the serial port
1336 * Return non-zero if we didn't find a serial port.
1345 (sunsu_reg.minor - 64) + co->index); in sunsu_console_setup()
1347 if (co->index > nr_inst) in sunsu_console_setup()
1348 return -ENODEV; in sunsu_console_setup()
1349 port = &sunsu_ports[co->index].port; in sunsu_console_setup()
1354 spin_lock_init(&port->lock); in sunsu_console_setup()
1357 sunserial_console_termios(co, port->dev->of_node); in sunsu_console_setup()
1360 termios.c_cflag = co->cflag; in sunsu_console_setup()
1361 port->mctrl |= TIOCM_DTR; in sunsu_console_setup()
1362 port->ops->set_termios(port, &termios, &dummy); in sunsu_console_setup()
1373 .index = -1,
1434 struct device_node *dp = op->dev.of_node; in su_probe()
1435 struct uart_sunsu_port *up; in su_probe() local
1444 return -EINVAL; in su_probe()
1445 up = &sunsu_ports[nr_inst]; in su_probe()
1447 up = kzalloc(sizeof(*up), GFP_KERNEL); in su_probe()
1448 if (!up) in su_probe()
1449 return -ENOMEM; in su_probe()
1452 up->port.line = nr_inst; in su_probe()
1454 spin_lock_init(&up->port.lock); in su_probe()
1456 up->su_type = type; in su_probe()
1458 rp = &op->resource[0]; in su_probe()
1459 up->port.mapbase = rp->start; in su_probe()
1460 up->reg_size = resource_size(rp); in su_probe()
1461 up->port.membase = of_ioremap(rp, 0, up->reg_size, "su"); in su_probe()
1462 if (!up->port.membase) { in su_probe()
1464 kfree(up); in su_probe()
1465 return -ENOMEM; in su_probe()
1468 up->port.irq = op->archdata.irqs[0]; in su_probe()
1470 up->port.dev = &op->dev; in su_probe()
1472 up->port.type = PORT_UNKNOWN; in su_probe()
1473 up->port.uartclk = (SU_BASE_BAUD * 16); in su_probe()
1474 up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSU_CONSOLE); in su_probe()
1477 if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) { in su_probe()
1478 err = sunsu_kbd_ms_init(up); in su_probe()
1480 of_iounmap(&op->resource[0], in su_probe()
1481 up->port.membase, up->reg_size); in su_probe()
1482 kfree(up); in su_probe()
1485 platform_set_drvdata(op, up); in su_probe()
1492 up->port.flags |= UPF_BOOT_AUTOCONF; in su_probe()
1494 sunsu_autoconfig(up); in su_probe()
1496 err = -ENODEV; in su_probe()
1497 if (up->port.type == PORT_UNKNOWN) in su_probe()
1500 up->port.ops = &sunsu_pops; in su_probe()
1503 if (of_node_name_eq(dp, "rsc-console") || in su_probe()
1504 of_node_name_eq(dp, "lom-console")) in su_probe()
1508 &sunsu_reg, up->port.line, in su_probe()
1510 err = uart_add_one_port(&sunsu_reg, &up->port); in su_probe()
1514 platform_set_drvdata(op, up); in su_probe()
1521 of_iounmap(&op->resource[0], up->port.membase, up->reg_size); in su_probe()
1522 kfree(up); in su_probe()
1528 struct uart_sunsu_port *up = platform_get_drvdata(op); in su_remove() local
1531 if (up->su_type == SU_PORT_MS || in su_remove()
1532 up->su_type == SU_PORT_KBD) in su_remove()
1537 serio_unregister_port(&up->serio); in su_remove()
1539 } else if (up->port.type != PORT_UNKNOWN) in su_remove()
1540 uart_remove_one_port(&sunsu_reg, &up->port); in su_remove()
1542 if (up->port.membase) in su_remove()
1543 of_iounmap(&op->resource[0], up->port.membase, up->reg_size); in su_remove()
1546 kfree(up); in su_remove()