From patchwork Tue Jul 30 19:38:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 815614 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB52018CC09; Tue, 30 Jul 2024 19:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722368335; cv=none; b=NDfpU883s2xz2CtEjdNW+gQ7KDbemG73NZ/kqTGxg5ZYPf0yCjrEPZcurZWNwMt0LptXYMph+JPk6F1BRHKGAZ+1Xfk8maIz9vNmaOGhv3KYJL18LS6qr/J7bwc5pzECK6wVevKmSMjugEfJmDRLlXnjkGI0oa8UrqAwgcYMJmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722368335; c=relaxed/simple; bh=5lpKaUgX4LewI+2gJzXQuBzlVZD7Vurrl6h6fEr9DDs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=UHtdDjcXYz4d+X4juCIykxv404jwXCK0adGJdF6sbGBs06QyogR9z75h8sS2MGeo7Em7hWXYaikcIkbCOKv/n2WPk/EMDCRgVvrNq3TG5QcWNBRVXnqmXJ3a0xI48PXfp49yjiLgs3qC7WHJel1w1j/xaY6odHSJlZmn9/xK8Iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MDJ0cQxz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MDJ0cQxz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50248C4AF0F; Tue, 30 Jul 2024 19:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722368335; bh=5lpKaUgX4LewI+2gJzXQuBzlVZD7Vurrl6h6fEr9DDs=; h=From:To:Cc:Subject:Date:From; b=MDJ0cQxz//BRJPcyL0nrwk9o6pH0odNZ2Bz/RvGfk8pwZq4b91O3Q2DOZ8B5tJ9Ve YIUFkbUBz44fXGfe9cSNX7638tkrsmZ0UUV/Fx+UG2JAY3AJ0JTjdp2k+hezcnNTh8 nuXiGUbgaXRAqNqCW3LAsg8tX7TuEgKNQVRdPpUmEG59hDLTUssTws7Zr7wvSzSor9 R/ha4if0Z0Xi14R9Wyn1jVptQyAczsc5fsGZYOMa1RI5sSn9/kwwJGJFM9VrWCpKk8 nUBSpcb0H1TMd7uo0w+S2AXuYa+cP7J6ovgyufMqZ55WjMGF+FDPE1iMVY2QD8B6g4 Q/kjMuNSYpXxw== From: Michael Walle To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Walle Subject: [PATCH] usb: gadget: u_serial: add .get_icount() support Date: Tue, 30 Jul 2024 21:38:40 +0200 Message-Id: <20240730193840.2580358-1-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- drivers/usb/gadget/function/u_serial.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index eec7f7a2e40f..bbc5f7617a13 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "u_serial.h" @@ -126,6 +127,7 @@ struct gs_port { wait_queue_head_t close_wait; bool suspended; /* port suspended */ bool start_delayed; /* delay start when suspended */ + struct async_icount icount; /* REVISIT this state ... */ struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ @@ -257,6 +259,7 @@ __acquires(&port->port_lock) break; } do_tty_wake = true; + port->icount.tx += len; req->length = len; list_del(&req->list); @@ -408,6 +411,7 @@ static void gs_rx_push(struct work_struct *work) size -= n; } + port->icount.rx += size; count = tty_insert_flip_string(&port->port, packet, size); if (count) @@ -851,6 +855,23 @@ static int gs_break_ctl(struct tty_struct *tty, int duration) return status; } +static int gs_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) +{ + struct gs_port *port = tty->driver_data; + struct async_icount cnow; + unsigned long flags; + + spin_lock_irqsave(&port->port_lock, flags); + cnow = port->icount; + spin_unlock_irqrestore(&port->port_lock, flags); + + icount->rx = cnow.rx; + icount->tx = cnow.tx; + + return 0; +} + static const struct tty_operations gs_tty_ops = { .open = gs_open, .close = gs_close, @@ -861,6 +882,7 @@ static const struct tty_operations gs_tty_ops = { .chars_in_buffer = gs_chars_in_buffer, .unthrottle = gs_unthrottle, .break_ctl = gs_break_ctl, + .get_icount = gs_get_icount, }; /*-------------------------------------------------------------------------*/