Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: u_serial: add .get_icount() support

Add icount support for the transmitting and receiving characters. This
will make the tty LED trigger work with the ttyGS devices.

Signed-off-by: Michael Walle <mwalle@kernel.org>
Link: https://lore.kernel.org/r/20240730193840.2580358-1-mwalle@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Michael Walle and committed by
Greg Kroah-Hartman
4e33059e acabfb1b

+22
+22
drivers/usb/gadget/function/u_serial.c
··· 28 28 #include <linux/kthread.h> 29 29 #include <linux/workqueue.h> 30 30 #include <linux/kfifo.h> 31 + #include <linux/serial.h> 31 32 32 33 #include "u_serial.h" 33 34 ··· 127 126 wait_queue_head_t close_wait; 128 127 bool suspended; /* port suspended */ 129 128 bool start_delayed; /* delay start when suspended */ 129 + struct async_icount icount; 130 130 131 131 /* REVISIT this state ... */ 132 132 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ ··· 259 257 break; 260 258 } 261 259 do_tty_wake = true; 260 + port->icount.tx += len; 262 261 263 262 req->length = len; 264 263 list_del(&req->list); ··· 411 408 size -= n; 412 409 } 413 410 411 + port->icount.rx += size; 414 412 count = tty_insert_flip_string(&port->port, packet, 415 413 size); 416 414 if (count) ··· 855 851 return status; 856 852 } 857 853 854 + static int gs_get_icount(struct tty_struct *tty, 855 + struct serial_icounter_struct *icount) 856 + { 857 + struct gs_port *port = tty->driver_data; 858 + struct async_icount cnow; 859 + unsigned long flags; 860 + 861 + spin_lock_irqsave(&port->port_lock, flags); 862 + cnow = port->icount; 863 + spin_unlock_irqrestore(&port->port_lock, flags); 864 + 865 + icount->rx = cnow.rx; 866 + icount->tx = cnow.tx; 867 + 868 + return 0; 869 + } 870 + 858 871 static const struct tty_operations gs_tty_ops = { 859 872 .open = gs_open, 860 873 .close = gs_close, ··· 882 861 .chars_in_buffer = gs_chars_in_buffer, 883 862 .unthrottle = gs_unthrottle, 884 863 .break_ctl = gs_break_ctl, 864 + .get_icount = gs_get_icount, 885 865 }; 886 866 887 867 /*-------------------------------------------------------------------------*/