Lines Matching refs:port
65 struct tty_port port; member
87 static int sdio_uart_add_port(struct sdio_uart_port *port) in sdio_uart_add_port() argument
91 mutex_init(&port->func_lock); in sdio_uart_add_port()
92 spin_lock_init(&port->write_lock); in sdio_uart_add_port()
93 if (kfifo_alloc(&port->xmit_fifo, FIFO_SIZE, GFP_KERNEL)) in sdio_uart_add_port()
99 port->index = index; in sdio_uart_add_port()
100 sdio_uart_table[index] = port; in sdio_uart_add_port()
112 struct sdio_uart_port *port; in sdio_uart_port_get() local
118 port = sdio_uart_table[index]; in sdio_uart_port_get()
119 if (port) in sdio_uart_port_get()
120 tty_port_get(&port->port); in sdio_uart_port_get()
123 return port; in sdio_uart_port_get()
126 static void sdio_uart_port_put(struct sdio_uart_port *port) in sdio_uart_port_put() argument
128 tty_port_put(&port->port); in sdio_uart_port_put()
131 static void sdio_uart_port_remove(struct sdio_uart_port *port) in sdio_uart_port_remove() argument
136 sdio_uart_table[port->index] = NULL; in sdio_uart_port_remove()
146 mutex_lock(&port->port.mutex); in sdio_uart_port_remove()
147 mutex_lock(&port->func_lock); in sdio_uart_port_remove()
148 func = port->func; in sdio_uart_port_remove()
150 port->func = NULL; in sdio_uart_port_remove()
151 mutex_unlock(&port->func_lock); in sdio_uart_port_remove()
153 tty_port_tty_hangup(&port->port, false); in sdio_uart_port_remove()
154 mutex_unlock(&port->port.mutex); in sdio_uart_port_remove()
159 sdio_uart_port_put(port); in sdio_uart_port_remove()
162 static int sdio_uart_claim_func(struct sdio_uart_port *port) in sdio_uart_claim_func() argument
164 mutex_lock(&port->func_lock); in sdio_uart_claim_func()
165 if (unlikely(!port->func)) { in sdio_uart_claim_func()
166 mutex_unlock(&port->func_lock); in sdio_uart_claim_func()
169 if (likely(port->in_sdio_uart_irq != current)) in sdio_uart_claim_func()
170 sdio_claim_host(port->func); in sdio_uart_claim_func()
171 mutex_unlock(&port->func_lock); in sdio_uart_claim_func()
175 static inline void sdio_uart_release_func(struct sdio_uart_port *port) in sdio_uart_release_func() argument
177 if (likely(port->in_sdio_uart_irq != current)) in sdio_uart_release_func()
178 sdio_release_host(port->func); in sdio_uart_release_func()
181 static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset) in sdio_in() argument
184 c = sdio_readb(port->func, port->regs_offset + offset, NULL); in sdio_in()
188 static inline void sdio_out(struct sdio_uart_port *port, int offset, int value) in sdio_out() argument
190 sdio_writeb(port->func, value, port->regs_offset + offset, NULL); in sdio_out()
193 static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port) in sdio_uart_get_mctrl() argument
200 status = sdio_in(port, UART_MSR); in sdio_uart_get_mctrl()
214 static void sdio_uart_write_mctrl(struct sdio_uart_port *port, in sdio_uart_write_mctrl() argument
230 sdio_out(port, UART_MCR, mcr); in sdio_uart_write_mctrl()
233 static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port, in sdio_uart_update_mctrl() argument
238 old = port->mctrl; in sdio_uart_update_mctrl()
239 port->mctrl = (old & ~clear) | set; in sdio_uart_update_mctrl()
240 if (old != port->mctrl) in sdio_uart_update_mctrl()
241 sdio_uart_write_mctrl(port, port->mctrl); in sdio_uart_update_mctrl()
244 #define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0) argument
245 #define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x) argument
247 static void sdio_uart_change_speed(struct sdio_uart_port *port, in sdio_uart_change_speed() argument
267 if (baud <= port->uartclk) in sdio_uart_change_speed()
280 quot = (2 * port->uartclk + baud) / (2 * baud); in sdio_uart_change_speed()
287 port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in sdio_uart_change_speed()
289 port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; in sdio_uart_change_speed()
291 port->read_status_mask |= UART_LSR_BI; in sdio_uart_change_speed()
296 port->ignore_status_mask = 0; in sdio_uart_change_speed()
298 port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in sdio_uart_change_speed()
300 port->ignore_status_mask |= UART_LSR_BI; in sdio_uart_change_speed()
306 port->ignore_status_mask |= UART_LSR_OE; in sdio_uart_change_speed()
313 port->ignore_status_mask |= UART_LSR_DR; in sdio_uart_change_speed()
318 port->ier &= ~UART_IER_MSI; in sdio_uart_change_speed()
320 port->ier |= UART_IER_MSI; in sdio_uart_change_speed()
322 port->lcr = cval; in sdio_uart_change_speed()
324 sdio_out(port, UART_IER, port->ier); in sdio_uart_change_speed()
325 sdio_out(port, UART_LCR, cval | UART_LCR_DLAB); in sdio_uart_change_speed()
326 sdio_out(port, UART_DLL, quot & 0xff); in sdio_uart_change_speed()
327 sdio_out(port, UART_DLM, quot >> 8); in sdio_uart_change_speed()
328 sdio_out(port, UART_LCR, cval); in sdio_uart_change_speed()
329 sdio_out(port, UART_FCR, fcr); in sdio_uart_change_speed()
331 sdio_uart_write_mctrl(port, port->mctrl); in sdio_uart_change_speed()
334 static void sdio_uart_start_tx(struct sdio_uart_port *port) in sdio_uart_start_tx() argument
336 if (!(port->ier & UART_IER_THRI)) { in sdio_uart_start_tx()
337 port->ier |= UART_IER_THRI; in sdio_uart_start_tx()
338 sdio_out(port, UART_IER, port->ier); in sdio_uart_start_tx()
342 static void sdio_uart_stop_tx(struct sdio_uart_port *port) in sdio_uart_stop_tx() argument
344 if (port->ier & UART_IER_THRI) { in sdio_uart_stop_tx()
345 port->ier &= ~UART_IER_THRI; in sdio_uart_stop_tx()
346 sdio_out(port, UART_IER, port->ier); in sdio_uart_stop_tx()
350 static void sdio_uart_stop_rx(struct sdio_uart_port *port) in sdio_uart_stop_rx() argument
352 port->ier &= ~UART_IER_RLSI; in sdio_uart_stop_rx()
353 port->read_status_mask &= ~UART_LSR_DR; in sdio_uart_stop_rx()
354 sdio_out(port, UART_IER, port->ier); in sdio_uart_stop_rx()
357 static void sdio_uart_receive_chars(struct sdio_uart_port *port, in sdio_uart_receive_chars() argument
364 ch = sdio_in(port, UART_RX); in sdio_uart_receive_chars()
366 port->icount.rx++; in sdio_uart_receive_chars()
375 port->icount.brk++; in sdio_uart_receive_chars()
377 port->icount.parity++; in sdio_uart_receive_chars()
379 port->icount.frame++; in sdio_uart_receive_chars()
381 port->icount.overrun++; in sdio_uart_receive_chars()
386 *status &= port->read_status_mask; in sdio_uart_receive_chars()
395 if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0) in sdio_uart_receive_chars()
396 tty_insert_flip_char(&port->port, ch, flag); in sdio_uart_receive_chars()
402 if (*status & ~port->ignore_status_mask & UART_LSR_OE) in sdio_uart_receive_chars()
403 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); in sdio_uart_receive_chars()
405 *status = sdio_in(port, UART_LSR); in sdio_uart_receive_chars()
408 tty_flip_buffer_push(&port->port); in sdio_uart_receive_chars()
411 static void sdio_uart_transmit_chars(struct sdio_uart_port *port) in sdio_uart_transmit_chars() argument
413 struct kfifo *xmit = &port->xmit_fifo; in sdio_uart_transmit_chars()
419 if (port->x_char) { in sdio_uart_transmit_chars()
420 sdio_out(port, UART_TX, port->x_char); in sdio_uart_transmit_chars()
421 port->icount.tx++; in sdio_uart_transmit_chars()
422 port->x_char = 0; in sdio_uart_transmit_chars()
426 tty = tty_port_tty_get(&port->port); in sdio_uart_transmit_chars()
430 sdio_uart_stop_tx(port); in sdio_uart_transmit_chars()
435 len = kfifo_out_locked(xmit, iobuf, 16, &port->write_lock); in sdio_uart_transmit_chars()
437 sdio_out(port, UART_TX, iobuf[count]); in sdio_uart_transmit_chars()
438 port->icount.tx++; in sdio_uart_transmit_chars()
445 sdio_uart_stop_tx(port); in sdio_uart_transmit_chars()
450 static void sdio_uart_check_modem_status(struct sdio_uart_port *port) in sdio_uart_check_modem_status() argument
455 status = sdio_in(port, UART_MSR); in sdio_uart_check_modem_status()
461 port->icount.rng++; in sdio_uart_check_modem_status()
463 port->icount.dsr++; in sdio_uart_check_modem_status()
465 port->icount.dcd++; in sdio_uart_check_modem_status()
468 wake_up_interruptible(&port->port.open_wait); in sdio_uart_check_modem_status()
471 tty_port_tty_hangup(&port->port, false); in sdio_uart_check_modem_status()
475 port->icount.cts++; in sdio_uart_check_modem_status()
476 tty = tty_port_tty_get(&port->port); in sdio_uart_check_modem_status()
482 sdio_uart_start_tx(port); in sdio_uart_check_modem_status()
488 sdio_uart_stop_tx(port); in sdio_uart_check_modem_status()
501 struct sdio_uart_port *port = sdio_get_drvdata(func); in sdio_uart_irq() local
512 if (unlikely(port->in_sdio_uart_irq == current)) in sdio_uart_irq()
515 iir = sdio_in(port, UART_IIR); in sdio_uart_irq()
519 port->in_sdio_uart_irq = current; in sdio_uart_irq()
520 lsr = sdio_in(port, UART_LSR); in sdio_uart_irq()
522 sdio_uart_receive_chars(port, &lsr); in sdio_uart_irq()
523 sdio_uart_check_modem_status(port); in sdio_uart_irq()
525 sdio_uart_transmit_chars(port); in sdio_uart_irq()
526 port->in_sdio_uart_irq = NULL; in sdio_uart_irq()
531 struct sdio_uart_port *port = in uart_carrier_raised() local
532 container_of(tport, struct sdio_uart_port, port); in uart_carrier_raised()
533 unsigned int ret = sdio_uart_claim_func(port); in uart_carrier_raised()
536 ret = sdio_uart_get_mctrl(port); in uart_carrier_raised()
537 sdio_uart_release_func(port); in uart_carrier_raised()
553 struct sdio_uart_port *port = in uart_dtr_rts() local
554 container_of(tport, struct sdio_uart_port, port); in uart_dtr_rts()
555 int ret = sdio_uart_claim_func(port); in uart_dtr_rts()
559 sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); in uart_dtr_rts()
561 sdio_uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS); in uart_dtr_rts()
562 sdio_uart_release_func(port); in uart_dtr_rts()
582 struct sdio_uart_port *port = in sdio_uart_activate() local
583 container_of(tport, struct sdio_uart_port, port); in sdio_uart_activate()
592 kfifo_reset(&port->xmit_fifo); in sdio_uart_activate()
594 ret = sdio_uart_claim_func(port); in sdio_uart_activate()
597 ret = sdio_enable_func(port->func); in sdio_uart_activate()
600 ret = sdio_claim_irq(port->func, sdio_uart_irq); in sdio_uart_activate()
608 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); in sdio_uart_activate()
609 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | in sdio_uart_activate()
611 sdio_out(port, UART_FCR, 0); in sdio_uart_activate()
616 (void) sdio_in(port, UART_LSR); in sdio_uart_activate()
617 (void) sdio_in(port, UART_RX); in sdio_uart_activate()
618 (void) sdio_in(port, UART_IIR); in sdio_uart_activate()
619 (void) sdio_in(port, UART_MSR); in sdio_uart_activate()
624 sdio_out(port, UART_LCR, UART_LCR_WLEN8); in sdio_uart_activate()
626 port->ier = UART_IER_RLSI|UART_IER_RDI|UART_IER_RTOIE|UART_IER_UUE; in sdio_uart_activate()
627 port->mctrl = TIOCM_OUT2; in sdio_uart_activate()
629 sdio_uart_change_speed(port, &tty->termios, NULL); in sdio_uart_activate()
632 sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); in sdio_uart_activate()
635 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) in sdio_uart_activate()
641 sdio_uart_irq(port->func); in sdio_uart_activate()
643 sdio_uart_release_func(port); in sdio_uart_activate()
647 sdio_disable_func(port->func); in sdio_uart_activate()
649 sdio_uart_release_func(port); in sdio_uart_activate()
665 struct sdio_uart_port *port = in sdio_uart_shutdown() local
666 container_of(tport, struct sdio_uart_port, port); in sdio_uart_shutdown()
669 ret = sdio_uart_claim_func(port); in sdio_uart_shutdown()
673 sdio_uart_stop_rx(port); in sdio_uart_shutdown()
676 sdio_release_irq(port->func); in sdio_uart_shutdown()
677 port->ier = 0; in sdio_uart_shutdown()
678 sdio_out(port, UART_IER, 0); in sdio_uart_shutdown()
680 sdio_uart_clear_mctrl(port, TIOCM_OUT2); in sdio_uart_shutdown()
683 port->lcr &= ~UART_LCR_SBC; in sdio_uart_shutdown()
684 sdio_out(port, UART_LCR, port->lcr); in sdio_uart_shutdown()
685 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | in sdio_uart_shutdown()
688 sdio_out(port, UART_FCR, 0); in sdio_uart_shutdown()
690 sdio_disable_func(port->func); in sdio_uart_shutdown()
692 sdio_uart_release_func(port); in sdio_uart_shutdown()
697 struct sdio_uart_port *port = in sdio_uart_port_destroy() local
698 container_of(tport, struct sdio_uart_port, port); in sdio_uart_port_destroy()
699 kfifo_free(&port->xmit_fifo); in sdio_uart_port_destroy()
700 kfree(port); in sdio_uart_port_destroy()
715 struct sdio_uart_port *port = sdio_uart_port_get(idx); in sdio_uart_install() local
720 tty->driver_data = port; in sdio_uart_install()
722 sdio_uart_port_put(port); in sdio_uart_install()
736 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_cleanup() local
738 sdio_uart_port_put(port); in sdio_uart_cleanup()
747 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_open() local
748 return tty_port_open(&port->port, tty, filp); in sdio_uart_open()
753 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_close() local
754 tty_port_close(&port->port, tty, filp); in sdio_uart_close()
759 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_hangup() local
760 tty_port_hangup(&port->port); in sdio_uart_hangup()
766 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_write() local
769 if (!port->func) in sdio_uart_write()
772 ret = kfifo_in_locked(&port->xmit_fifo, buf, count, &port->write_lock); in sdio_uart_write()
773 if (!(port->ier & UART_IER_THRI)) { in sdio_uart_write()
774 int err = sdio_uart_claim_func(port); in sdio_uart_write()
776 sdio_uart_start_tx(port); in sdio_uart_write()
777 sdio_uart_irq(port->func); in sdio_uart_write()
778 sdio_uart_release_func(port); in sdio_uart_write()
788 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_write_room() local
789 return FIFO_SIZE - kfifo_len(&port->xmit_fifo); in sdio_uart_write_room()
794 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_chars_in_buffer() local
795 return kfifo_len(&port->xmit_fifo); in sdio_uart_chars_in_buffer()
800 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_send_xchar() local
802 port->x_char = ch; in sdio_uart_send_xchar()
803 if (ch && !(port->ier & UART_IER_THRI)) { in sdio_uart_send_xchar()
804 if (sdio_uart_claim_func(port) != 0) in sdio_uart_send_xchar()
806 sdio_uart_start_tx(port); in sdio_uart_send_xchar()
807 sdio_uart_irq(port->func); in sdio_uart_send_xchar()
808 sdio_uart_release_func(port); in sdio_uart_send_xchar()
814 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_throttle() local
819 if (sdio_uart_claim_func(port) != 0) in sdio_uart_throttle()
823 port->x_char = STOP_CHAR(tty); in sdio_uart_throttle()
824 sdio_uart_start_tx(port); in sdio_uart_throttle()
828 sdio_uart_clear_mctrl(port, TIOCM_RTS); in sdio_uart_throttle()
830 sdio_uart_irq(port->func); in sdio_uart_throttle()
831 sdio_uart_release_func(port); in sdio_uart_throttle()
836 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_unthrottle() local
841 if (sdio_uart_claim_func(port) != 0) in sdio_uart_unthrottle()
845 if (port->x_char) { in sdio_uart_unthrottle()
846 port->x_char = 0; in sdio_uart_unthrottle()
848 port->x_char = START_CHAR(tty); in sdio_uart_unthrottle()
849 sdio_uart_start_tx(port); in sdio_uart_unthrottle()
854 sdio_uart_set_mctrl(port, TIOCM_RTS); in sdio_uart_unthrottle()
856 sdio_uart_irq(port->func); in sdio_uart_unthrottle()
857 sdio_uart_release_func(port); in sdio_uart_unthrottle()
863 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_set_termios() local
866 if (sdio_uart_claim_func(port) != 0) in sdio_uart_set_termios()
869 sdio_uart_change_speed(port, &tty->termios, old_termios); in sdio_uart_set_termios()
873 sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR); in sdio_uart_set_termios()
880 sdio_uart_set_mctrl(port, mask); in sdio_uart_set_termios()
886 sdio_uart_start_tx(port); in sdio_uart_set_termios()
891 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) { in sdio_uart_set_termios()
893 sdio_uart_stop_tx(port); in sdio_uart_set_termios()
897 sdio_uart_release_func(port); in sdio_uart_set_termios()
902 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_break_ctl() local
905 result = sdio_uart_claim_func(port); in sdio_uart_break_ctl()
910 port->lcr |= UART_LCR_SBC; in sdio_uart_break_ctl()
912 port->lcr &= ~UART_LCR_SBC; in sdio_uart_break_ctl()
913 sdio_out(port, UART_LCR, port->lcr); in sdio_uart_break_ctl()
915 sdio_uart_release_func(port); in sdio_uart_break_ctl()
921 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_tiocmget() local
924 result = sdio_uart_claim_func(port); in sdio_uart_tiocmget()
926 result = port->mctrl | sdio_uart_get_mctrl(port); in sdio_uart_tiocmget()
927 sdio_uart_release_func(port); in sdio_uart_tiocmget()
936 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_tiocmset() local
939 result = sdio_uart_claim_func(port); in sdio_uart_tiocmset()
941 sdio_uart_update_mctrl(port, set, clear); in sdio_uart_tiocmset()
942 sdio_uart_release_func(port); in sdio_uart_tiocmset()
955 struct sdio_uart_port *port = sdio_uart_port_get(i); in sdio_uart_proc_show() local
956 if (port) { in sdio_uart_proc_show()
960 port->icount.tx, port->icount.rx); in sdio_uart_proc_show()
961 if (port->icount.frame) in sdio_uart_proc_show()
963 port->icount.frame); in sdio_uart_proc_show()
964 if (port->icount.parity) in sdio_uart_proc_show()
966 port->icount.parity); in sdio_uart_proc_show()
967 if (port->icount.brk) in sdio_uart_proc_show()
969 port->icount.brk); in sdio_uart_proc_show()
970 if (port->icount.overrun) in sdio_uart_proc_show()
972 port->icount.overrun); in sdio_uart_proc_show()
973 if (port->icount.cts) in sdio_uart_proc_show()
975 port->icount.cts); in sdio_uart_proc_show()
976 if (port->icount.dsr) in sdio_uart_proc_show()
978 port->icount.dsr); in sdio_uart_proc_show()
979 if (port->icount.rng) in sdio_uart_proc_show()
981 port->icount.rng); in sdio_uart_proc_show()
982 if (port->icount.dcd) in sdio_uart_proc_show()
984 port->icount.dcd); in sdio_uart_proc_show()
986 sdio_uart_port_put(port); in sdio_uart_proc_show()
1025 struct sdio_uart_port *port; in sdio_uart_probe() local
1028 port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL); in sdio_uart_probe()
1029 if (!port) in sdio_uart_probe()
1035 kfree(port); in sdio_uart_probe()
1054 kfree(port); in sdio_uart_probe()
1059 port->regs_offset = (tpl->data[4] << 0) | in sdio_uart_probe()
1063 sdio_func_id(func), port->regs_offset); in sdio_uart_probe()
1064 port->uartclk = tpl->data[7] * 115200; in sdio_uart_probe()
1065 if (port->uartclk == 0) in sdio_uart_probe()
1066 port->uartclk = 115200; in sdio_uart_probe()
1068 sdio_func_id(func), port->uartclk, in sdio_uart_probe()
1071 kfree(port); in sdio_uart_probe()
1075 port->func = func; in sdio_uart_probe()
1076 sdio_set_drvdata(func, port); in sdio_uart_probe()
1077 tty_port_init(&port->port); in sdio_uart_probe()
1078 port->port.ops = &sdio_uart_port_ops; in sdio_uart_probe()
1080 ret = sdio_uart_add_port(port); in sdio_uart_probe()
1082 kfree(port); in sdio_uart_probe()
1085 dev = tty_port_register_device(&port->port, in sdio_uart_probe()
1086 sdio_uart_tty_driver, port->index, &func->dev); in sdio_uart_probe()
1088 sdio_uart_port_remove(port); in sdio_uart_probe()
1098 struct sdio_uart_port *port = sdio_get_drvdata(func); in sdio_uart_remove() local
1100 tty_unregister_device(sdio_uart_tty_driver, port->index); in sdio_uart_remove()
1101 sdio_uart_port_remove(port); in sdio_uart_remove()