Skip to content

Commit 4e33059

Browse files
mwallegregkh
authored andcommitted
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>
1 parent acabfb1 commit 4e33059

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/usb/gadget/function/u_serial.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/kthread.h>
2929
#include <linux/workqueue.h>
3030
#include <linux/kfifo.h>
31+
#include <linux/serial.h>
3132

3233
#include "u_serial.h"
3334

@@ -126,6 +127,7 @@ struct gs_port {
126127
wait_queue_head_t close_wait;
127128
bool suspended; /* port suspended */
128129
bool start_delayed; /* delay start when suspended */
130+
struct async_icount icount;
129131

130132
/* REVISIT this state ... */
131133
struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
@@ -257,6 +259,7 @@ __acquires(&port->port_lock)
257259
break;
258260
}
259261
do_tty_wake = true;
262+
port->icount.tx += len;
260263

261264
req->length = len;
262265
list_del(&req->list);
@@ -408,6 +411,7 @@ static void gs_rx_push(struct work_struct *work)
408411
size -= n;
409412
}
410413

414+
port->icount.rx += size;
411415
count = tty_insert_flip_string(&port->port, packet,
412416
size);
413417
if (count)
@@ -851,6 +855,23 @@ static int gs_break_ctl(struct tty_struct *tty, int duration)
851855
return status;
852856
}
853857

858+
static int gs_get_icount(struct tty_struct *tty,
859+
struct serial_icounter_struct *icount)
860+
{
861+
struct gs_port *port = tty->driver_data;
862+
struct async_icount cnow;
863+
unsigned long flags;
864+
865+
spin_lock_irqsave(&port->port_lock, flags);
866+
cnow = port->icount;
867+
spin_unlock_irqrestore(&port->port_lock, flags);
868+
869+
icount->rx = cnow.rx;
870+
icount->tx = cnow.tx;
871+
872+
return 0;
873+
}
874+
854875
static const struct tty_operations gs_tty_ops = {
855876
.open = gs_open,
856877
.close = gs_close,
@@ -861,6 +882,7 @@ static const struct tty_operations gs_tty_ops = {
861882
.chars_in_buffer = gs_chars_in_buffer,
862883
.unthrottle = gs_unthrottle,
863884
.break_ctl = gs_break_ctl,
885+
.get_icount = gs_get_icount,
864886
};
865887

866888
/*-------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)