1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * u_serial.h - interface to USB gadget "serial port"/TTY utilities
4  *
5  * Copyright (C) 2008 David Brownell
6  * Copyright (C) 2008 by Nokia Corporation
7  *
8  * This software is distributed under the terms of the GNU General
9  * Public License ("GPL") as published by the Free Software Foundation,
10  * either version 2 of that License or (at your option) any later version.
11  */
12 
13 #ifndef __U_SERIAL_H
14 #define __U_SERIAL_H
15 
16 #include <linux/usb/composite.h>
17 #include <linux/usb/cdc.h>
18 
19 #define MAX_U_SERIAL_PORTS	4
20 
21 struct f_serial_opts {
22 	struct usb_function_instance func_inst;
23 	u8 port_num;
24 };
25 
26 /*
27  * One non-multiplexed "serial" I/O port ... there can be several of these
28  * on any given USB peripheral device, if it provides enough endpoints.
29  *
30  * The "u_serial" utility component exists to do one thing:  manage TTY
31  * style I/O using the USB peripheral endpoints listed here, including
32  * hookups to sysfs and /dev for each logical "tty" device.
33  *
34  * REVISIT at least ACM could support tiocmget() if needed.
35  *
36  * REVISIT someday, allow multiplexing several TTYs over these endpoints.
37  */
38 struct gserial {
39 	struct usb_function		func;
40 
41 	/* port is managed by gserial_{connect,disconnect} */
42 	struct gs_port			*ioport;
43 
44 	struct usb_ep			*in;
45 	struct usb_ep			*out;
46 
47 	/* REVISIT avoid this CDC-ACM support harder ... */
48 	struct usb_cdc_line_coding port_line_coding;	/* 9600-8-N-1 etc */
49 
50 	/* notification callbacks */
51 	void (*connect)(struct gserial *p);
52 	void (*disconnect)(struct gserial *p);
53 	int (*send_break)(struct gserial *p, int duration);
54 };
55 
56 /* utilities to allocate/free request and buffer */
57 struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
58 void gs_free_req(struct usb_ep *, struct usb_request *req);
59 
60 /* management of individual TTY ports */
61 int gserial_alloc_line(unsigned char *port_line);
62 void gserial_free_line(unsigned char port_line);
63 
64 /* connect/disconnect is handled by individual functions */
65 int gserial_connect(struct gserial *, u8 port_num);
66 void gserial_disconnect(struct gserial *);
67 
68 /* functions are bound to configurations by a config or gadget driver */
69 int gser_bind_config(struct usb_configuration *c, u8 port_num);
70 int obex_bind_config(struct usb_configuration *c, u8 port_num);
71 
72 #endif /* __U_SERIAL_H */
73