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