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 u8 sdio_in(struct sdio_uart_port *port, int offset) in sdio_in() argument
183 return sdio_readb(port->func, port->regs_offset + offset, NULL); in sdio_in()
186 static inline void sdio_out(struct sdio_uart_port *port, int offset, int value) in sdio_out() argument
188 sdio_writeb(port->func, value, port->regs_offset + offset, NULL); in sdio_out()
191 static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port) in sdio_uart_get_mctrl() argument
198 status = sdio_in(port, UART_MSR); in sdio_uart_get_mctrl()
212 static void sdio_uart_write_mctrl(struct sdio_uart_port *port, in sdio_uart_write_mctrl() argument
228 sdio_out(port, UART_MCR, mcr); in sdio_uart_write_mctrl()
231 static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port, in sdio_uart_update_mctrl() argument
236 old = port->mctrl; in sdio_uart_update_mctrl()
237 port->mctrl = (old & ~clear) | set; in sdio_uart_update_mctrl()
238 if (old != port->mctrl) in sdio_uart_update_mctrl()
239 sdio_uart_write_mctrl(port, port->mctrl); in sdio_uart_update_mctrl()
242 #define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0) argument
243 #define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x) argument
245 static void sdio_uart_change_speed(struct sdio_uart_port *port, in sdio_uart_change_speed() argument
265 if (baud <= port->uartclk) in sdio_uart_change_speed()
278 quot = (2 * port->uartclk + baud) / (2 * baud); in sdio_uart_change_speed()
285 port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in sdio_uart_change_speed()
287 port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; in sdio_uart_change_speed()
289 port->read_status_mask |= UART_LSR_BI; in sdio_uart_change_speed()
294 port->ignore_status_mask = 0; in sdio_uart_change_speed()
296 port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in sdio_uart_change_speed()
298 port->ignore_status_mask |= UART_LSR_BI; in sdio_uart_change_speed()
304 port->ignore_status_mask |= UART_LSR_OE; in sdio_uart_change_speed()
311 port->ignore_status_mask |= UART_LSR_DR; in sdio_uart_change_speed()
316 port->ier &= ~UART_IER_MSI; in sdio_uart_change_speed()
318 port->ier |= UART_IER_MSI; in sdio_uart_change_speed()
320 port->lcr = cval; in sdio_uart_change_speed()
322 sdio_out(port, UART_IER, port->ier); in sdio_uart_change_speed()
323 sdio_out(port, UART_LCR, cval | UART_LCR_DLAB); in sdio_uart_change_speed()
324 sdio_out(port, UART_DLL, quot & 0xff); in sdio_uart_change_speed()
325 sdio_out(port, UART_DLM, quot >> 8); in sdio_uart_change_speed()
326 sdio_out(port, UART_LCR, cval); in sdio_uart_change_speed()
327 sdio_out(port, UART_FCR, fcr); in sdio_uart_change_speed()
329 sdio_uart_write_mctrl(port, port->mctrl); in sdio_uart_change_speed()
332 static void sdio_uart_start_tx(struct sdio_uart_port *port) in sdio_uart_start_tx() argument
334 if (!(port->ier & UART_IER_THRI)) { in sdio_uart_start_tx()
335 port->ier |= UART_IER_THRI; in sdio_uart_start_tx()
336 sdio_out(port, UART_IER, port->ier); in sdio_uart_start_tx()
340 static void sdio_uart_stop_tx(struct sdio_uart_port *port) in sdio_uart_stop_tx() argument
342 if (port->ier & UART_IER_THRI) { in sdio_uart_stop_tx()
343 port->ier &= ~UART_IER_THRI; in sdio_uart_stop_tx()
344 sdio_out(port, UART_IER, port->ier); in sdio_uart_stop_tx()
348 static void sdio_uart_stop_rx(struct sdio_uart_port *port) in sdio_uart_stop_rx() argument
350 port->ier &= ~UART_IER_RLSI; in sdio_uart_stop_rx()
351 port->read_status_mask &= ~UART_LSR_DR; in sdio_uart_stop_rx()
352 sdio_out(port, UART_IER, port->ier); in sdio_uart_stop_rx()
355 static void sdio_uart_receive_chars(struct sdio_uart_port *port, u8 *status) in sdio_uart_receive_chars() argument
360 u8 ch = sdio_in(port, UART_RX); in sdio_uart_receive_chars()
362 port->icount.rx++; in sdio_uart_receive_chars()
371 port->icount.brk++; in sdio_uart_receive_chars()
373 port->icount.parity++; in sdio_uart_receive_chars()
375 port->icount.frame++; in sdio_uart_receive_chars()
377 port->icount.overrun++; in sdio_uart_receive_chars()
382 *status &= port->read_status_mask; in sdio_uart_receive_chars()
391 if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0) in sdio_uart_receive_chars()
392 tty_insert_flip_char(&port->port, ch, flag); in sdio_uart_receive_chars()
398 if (*status & ~port->ignore_status_mask & UART_LSR_OE) in sdio_uart_receive_chars()
399 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); in sdio_uart_receive_chars()
401 *status = sdio_in(port, UART_LSR); in sdio_uart_receive_chars()
404 tty_flip_buffer_push(&port->port); in sdio_uart_receive_chars()
407 static void sdio_uart_transmit_chars(struct sdio_uart_port *port) in sdio_uart_transmit_chars() argument
409 struct kfifo *xmit = &port->xmit_fifo; in sdio_uart_transmit_chars()
415 if (port->x_char) { in sdio_uart_transmit_chars()
416 sdio_out(port, UART_TX, port->x_char); in sdio_uart_transmit_chars()
417 port->icount.tx++; in sdio_uart_transmit_chars()
418 port->x_char = 0; in sdio_uart_transmit_chars()
422 tty = tty_port_tty_get(&port->port); in sdio_uart_transmit_chars()
426 sdio_uart_stop_tx(port); in sdio_uart_transmit_chars()
431 len = kfifo_out_locked(xmit, iobuf, 16, &port->write_lock); in sdio_uart_transmit_chars()
433 sdio_out(port, UART_TX, iobuf[count]); in sdio_uart_transmit_chars()
434 port->icount.tx++; in sdio_uart_transmit_chars()
441 sdio_uart_stop_tx(port); in sdio_uart_transmit_chars()
446 static void sdio_uart_check_modem_status(struct sdio_uart_port *port) in sdio_uart_check_modem_status() argument
451 status = sdio_in(port, UART_MSR); in sdio_uart_check_modem_status()
457 port->icount.rng++; in sdio_uart_check_modem_status()
459 port->icount.dsr++; in sdio_uart_check_modem_status()
461 port->icount.dcd++; in sdio_uart_check_modem_status()
464 wake_up_interruptible(&port->port.open_wait); in sdio_uart_check_modem_status()
467 tty_port_tty_hangup(&port->port, false); in sdio_uart_check_modem_status()
471 port->icount.cts++; in sdio_uart_check_modem_status()
472 tty = tty_port_tty_get(&port->port); in sdio_uart_check_modem_status()
478 sdio_uart_start_tx(port); in sdio_uart_check_modem_status()
484 sdio_uart_stop_tx(port); in sdio_uart_check_modem_status()
497 struct sdio_uart_port *port = sdio_get_drvdata(func); in sdio_uart_irq() local
508 if (unlikely(port->in_sdio_uart_irq == current)) in sdio_uart_irq()
511 iir = sdio_in(port, UART_IIR); in sdio_uart_irq()
515 port->in_sdio_uart_irq = current; in sdio_uart_irq()
516 lsr = sdio_in(port, UART_LSR); in sdio_uart_irq()
518 sdio_uart_receive_chars(port, &lsr); in sdio_uart_irq()
519 sdio_uart_check_modem_status(port); in sdio_uart_irq()
521 sdio_uart_transmit_chars(port); in sdio_uart_irq()
522 port->in_sdio_uart_irq = NULL; in sdio_uart_irq()
527 struct sdio_uart_port *port = in uart_carrier_raised() local
528 container_of(tport, struct sdio_uart_port, port); in uart_carrier_raised()
529 unsigned int ret = sdio_uart_claim_func(port); in uart_carrier_raised()
532 ret = sdio_uart_get_mctrl(port); in uart_carrier_raised()
533 sdio_uart_release_func(port); in uart_carrier_raised()
549 struct sdio_uart_port *port = in uart_dtr_rts() local
550 container_of(tport, struct sdio_uart_port, port); in uart_dtr_rts()
551 int ret = sdio_uart_claim_func(port); in uart_dtr_rts()
555 sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); in uart_dtr_rts()
557 sdio_uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS); in uart_dtr_rts()
558 sdio_uart_release_func(port); in uart_dtr_rts()
578 struct sdio_uart_port *port = in sdio_uart_activate() local
579 container_of(tport, struct sdio_uart_port, port); in sdio_uart_activate()
588 kfifo_reset(&port->xmit_fifo); in sdio_uart_activate()
590 ret = sdio_uart_claim_func(port); in sdio_uart_activate()
593 ret = sdio_enable_func(port->func); in sdio_uart_activate()
596 ret = sdio_claim_irq(port->func, sdio_uart_irq); in sdio_uart_activate()
604 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); in sdio_uart_activate()
605 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | in sdio_uart_activate()
607 sdio_out(port, UART_FCR, 0); in sdio_uart_activate()
612 (void) sdio_in(port, UART_LSR); in sdio_uart_activate()
613 (void) sdio_in(port, UART_RX); in sdio_uart_activate()
614 (void) sdio_in(port, UART_IIR); in sdio_uart_activate()
615 (void) sdio_in(port, UART_MSR); in sdio_uart_activate()
620 sdio_out(port, UART_LCR, UART_LCR_WLEN8); in sdio_uart_activate()
622 port->ier = UART_IER_RLSI|UART_IER_RDI|UART_IER_RTOIE|UART_IER_UUE; in sdio_uart_activate()
623 port->mctrl = TIOCM_OUT2; in sdio_uart_activate()
625 sdio_uart_change_speed(port, &tty->termios, NULL); in sdio_uart_activate()
628 sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); in sdio_uart_activate()
631 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) in sdio_uart_activate()
637 sdio_uart_irq(port->func); in sdio_uart_activate()
639 sdio_uart_release_func(port); in sdio_uart_activate()
643 sdio_disable_func(port->func); in sdio_uart_activate()
645 sdio_uart_release_func(port); in sdio_uart_activate()
661 struct sdio_uart_port *port = in sdio_uart_shutdown() local
662 container_of(tport, struct sdio_uart_port, port); in sdio_uart_shutdown()
665 ret = sdio_uart_claim_func(port); in sdio_uart_shutdown()
669 sdio_uart_stop_rx(port); in sdio_uart_shutdown()
672 sdio_release_irq(port->func); in sdio_uart_shutdown()
673 port->ier = 0; in sdio_uart_shutdown()
674 sdio_out(port, UART_IER, 0); in sdio_uart_shutdown()
676 sdio_uart_clear_mctrl(port, TIOCM_OUT2); in sdio_uart_shutdown()
679 port->lcr &= ~UART_LCR_SBC; in sdio_uart_shutdown()
680 sdio_out(port, UART_LCR, port->lcr); in sdio_uart_shutdown()
681 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | in sdio_uart_shutdown()
684 sdio_out(port, UART_FCR, 0); in sdio_uart_shutdown()
686 sdio_disable_func(port->func); in sdio_uart_shutdown()
688 sdio_uart_release_func(port); in sdio_uart_shutdown()
693 struct sdio_uart_port *port = in sdio_uart_port_destroy() local
694 container_of(tport, struct sdio_uart_port, port); in sdio_uart_port_destroy()
695 kfifo_free(&port->xmit_fifo); in sdio_uart_port_destroy()
696 kfree(port); in sdio_uart_port_destroy()
711 struct sdio_uart_port *port = sdio_uart_port_get(idx); in sdio_uart_install() local
716 tty->driver_data = port; in sdio_uart_install()
718 sdio_uart_port_put(port); in sdio_uart_install()
732 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_cleanup() local
734 sdio_uart_port_put(port); in sdio_uart_cleanup()
743 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_open() local
744 return tty_port_open(&port->port, tty, filp); in sdio_uart_open()
749 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_close() local
750 tty_port_close(&port->port, tty, filp); in sdio_uart_close()
755 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_hangup() local
756 tty_port_hangup(&port->port); in sdio_uart_hangup()
762 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_write() local
765 if (!port->func) in sdio_uart_write()
768 ret = kfifo_in_locked(&port->xmit_fifo, buf, count, &port->write_lock); in sdio_uart_write()
769 if (!(port->ier & UART_IER_THRI)) { in sdio_uart_write()
770 int err = sdio_uart_claim_func(port); in sdio_uart_write()
772 sdio_uart_start_tx(port); in sdio_uart_write()
773 sdio_uart_irq(port->func); in sdio_uart_write()
774 sdio_uart_release_func(port); in sdio_uart_write()
784 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_write_room() local
785 return FIFO_SIZE - kfifo_len(&port->xmit_fifo); in sdio_uart_write_room()
790 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_chars_in_buffer() local
791 return kfifo_len(&port->xmit_fifo); in sdio_uart_chars_in_buffer()
796 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_send_xchar() local
798 port->x_char = ch; in sdio_uart_send_xchar()
799 if (ch && !(port->ier & UART_IER_THRI)) { in sdio_uart_send_xchar()
800 if (sdio_uart_claim_func(port) != 0) in sdio_uart_send_xchar()
802 sdio_uart_start_tx(port); in sdio_uart_send_xchar()
803 sdio_uart_irq(port->func); in sdio_uart_send_xchar()
804 sdio_uart_release_func(port); in sdio_uart_send_xchar()
810 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_throttle() local
815 if (sdio_uart_claim_func(port) != 0) in sdio_uart_throttle()
819 port->x_char = STOP_CHAR(tty); in sdio_uart_throttle()
820 sdio_uart_start_tx(port); in sdio_uart_throttle()
824 sdio_uart_clear_mctrl(port, TIOCM_RTS); in sdio_uart_throttle()
826 sdio_uart_irq(port->func); in sdio_uart_throttle()
827 sdio_uart_release_func(port); in sdio_uart_throttle()
832 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_unthrottle() local
837 if (sdio_uart_claim_func(port) != 0) in sdio_uart_unthrottle()
841 if (port->x_char) { in sdio_uart_unthrottle()
842 port->x_char = 0; in sdio_uart_unthrottle()
844 port->x_char = START_CHAR(tty); in sdio_uart_unthrottle()
845 sdio_uart_start_tx(port); in sdio_uart_unthrottle()
850 sdio_uart_set_mctrl(port, TIOCM_RTS); in sdio_uart_unthrottle()
852 sdio_uart_irq(port->func); in sdio_uart_unthrottle()
853 sdio_uart_release_func(port); in sdio_uart_unthrottle()
859 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_set_termios() local
862 if (sdio_uart_claim_func(port) != 0) in sdio_uart_set_termios()
865 sdio_uart_change_speed(port, &tty->termios, old_termios); in sdio_uart_set_termios()
869 sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR); in sdio_uart_set_termios()
876 sdio_uart_set_mctrl(port, mask); in sdio_uart_set_termios()
882 sdio_uart_start_tx(port); in sdio_uart_set_termios()
887 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) { in sdio_uart_set_termios()
889 sdio_uart_stop_tx(port); in sdio_uart_set_termios()
893 sdio_uart_release_func(port); in sdio_uart_set_termios()
898 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_break_ctl() local
901 result = sdio_uart_claim_func(port); in sdio_uart_break_ctl()
906 port->lcr |= UART_LCR_SBC; in sdio_uart_break_ctl()
908 port->lcr &= ~UART_LCR_SBC; in sdio_uart_break_ctl()
909 sdio_out(port, UART_LCR, port->lcr); in sdio_uart_break_ctl()
911 sdio_uart_release_func(port); in sdio_uart_break_ctl()
917 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_tiocmget() local
920 result = sdio_uart_claim_func(port); in sdio_uart_tiocmget()
922 result = port->mctrl | sdio_uart_get_mctrl(port); in sdio_uart_tiocmget()
923 sdio_uart_release_func(port); in sdio_uart_tiocmget()
932 struct sdio_uart_port *port = tty->driver_data; in sdio_uart_tiocmset() local
935 result = sdio_uart_claim_func(port); in sdio_uart_tiocmset()
937 sdio_uart_update_mctrl(port, set, clear); in sdio_uart_tiocmset()
938 sdio_uart_release_func(port); in sdio_uart_tiocmset()
951 struct sdio_uart_port *port = sdio_uart_port_get(i); in sdio_uart_proc_show() local
952 if (port) { in sdio_uart_proc_show()
956 port->icount.tx, port->icount.rx); in sdio_uart_proc_show()
957 if (port->icount.frame) in sdio_uart_proc_show()
959 port->icount.frame); in sdio_uart_proc_show()
960 if (port->icount.parity) in sdio_uart_proc_show()
962 port->icount.parity); in sdio_uart_proc_show()
963 if (port->icount.brk) in sdio_uart_proc_show()
965 port->icount.brk); in sdio_uart_proc_show()
966 if (port->icount.overrun) in sdio_uart_proc_show()
968 port->icount.overrun); in sdio_uart_proc_show()
969 if (port->icount.cts) in sdio_uart_proc_show()
971 port->icount.cts); in sdio_uart_proc_show()
972 if (port->icount.dsr) in sdio_uart_proc_show()
974 port->icount.dsr); in sdio_uart_proc_show()
975 if (port->icount.rng) in sdio_uart_proc_show()
977 port->icount.rng); in sdio_uart_proc_show()
978 if (port->icount.dcd) in sdio_uart_proc_show()
980 port->icount.dcd); in sdio_uart_proc_show()
982 sdio_uart_port_put(port); in sdio_uart_proc_show()
1021 struct sdio_uart_port *port; in sdio_uart_probe() local
1024 port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL); in sdio_uart_probe()
1025 if (!port) in sdio_uart_probe()
1031 kfree(port); in sdio_uart_probe()
1050 kfree(port); in sdio_uart_probe()
1055 port->regs_offset = (tpl->data[4] << 0) | in sdio_uart_probe()
1059 sdio_func_id(func), port->regs_offset); in sdio_uart_probe()
1060 port->uartclk = tpl->data[7] * 115200; in sdio_uart_probe()
1061 if (port->uartclk == 0) in sdio_uart_probe()
1062 port->uartclk = 115200; in sdio_uart_probe()
1064 sdio_func_id(func), port->uartclk, in sdio_uart_probe()
1067 kfree(port); in sdio_uart_probe()
1071 port->func = func; in sdio_uart_probe()
1072 sdio_set_drvdata(func, port); in sdio_uart_probe()
1073 tty_port_init(&port->port); in sdio_uart_probe()
1074 port->port.ops = &sdio_uart_port_ops; in sdio_uart_probe()
1076 ret = sdio_uart_add_port(port); in sdio_uart_probe()
1078 kfree(port); in sdio_uart_probe()
1081 dev = tty_port_register_device(&port->port, in sdio_uart_probe()
1082 sdio_uart_tty_driver, port->index, &func->dev); in sdio_uart_probe()
1084 sdio_uart_port_remove(port); in sdio_uart_probe()
1094 struct sdio_uart_port *port = sdio_get_drvdata(func); in sdio_uart_remove() local
1096 tty_unregister_device(sdio_uart_tty_driver, port->index); in sdio_uart_remove()
1097 sdio_uart_port_remove(port); in sdio_uart_remove()