xref: /linux/drivers/usb/gadget/function/u_serial.h (revision aba3a8d01d623a5efef48ab8e78752d58d4c90c3)
12e759738SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */
200a2430fSAndrzej Pietrasiewicz /*
300a2430fSAndrzej Pietrasiewicz  * u_serial.h - interface to USB gadget "serial port"/TTY utilities
400a2430fSAndrzej Pietrasiewicz  *
500a2430fSAndrzej Pietrasiewicz  * Copyright (C) 2008 David Brownell
600a2430fSAndrzej Pietrasiewicz  * Copyright (C) 2008 by Nokia Corporation
700a2430fSAndrzej Pietrasiewicz  */
800a2430fSAndrzej Pietrasiewicz 
900a2430fSAndrzej Pietrasiewicz #ifndef __U_SERIAL_H
1000a2430fSAndrzej Pietrasiewicz #define __U_SERIAL_H
1100a2430fSAndrzej Pietrasiewicz 
1200a2430fSAndrzej Pietrasiewicz #include <linux/usb/composite.h>
1300a2430fSAndrzej Pietrasiewicz #include <linux/usb/cdc.h>
1400a2430fSAndrzej Pietrasiewicz 
1500a2430fSAndrzej Pietrasiewicz #define MAX_U_SERIAL_PORTS	4
1600a2430fSAndrzej Pietrasiewicz 
1700a2430fSAndrzej Pietrasiewicz struct f_serial_opts {
1800a2430fSAndrzej Pietrasiewicz 	struct usb_function_instance func_inst;
1900a2430fSAndrzej Pietrasiewicz 	u8 port_num;
2000a2430fSAndrzej Pietrasiewicz };
2100a2430fSAndrzej Pietrasiewicz 
2200a2430fSAndrzej Pietrasiewicz /*
2300a2430fSAndrzej Pietrasiewicz  * One non-multiplexed "serial" I/O port ... there can be several of these
2400a2430fSAndrzej Pietrasiewicz  * on any given USB peripheral device, if it provides enough endpoints.
2500a2430fSAndrzej Pietrasiewicz  *
2600a2430fSAndrzej Pietrasiewicz  * The "u_serial" utility component exists to do one thing:  manage TTY
2700a2430fSAndrzej Pietrasiewicz  * style I/O using the USB peripheral endpoints listed here, including
2800a2430fSAndrzej Pietrasiewicz  * hookups to sysfs and /dev for each logical "tty" device.
2900a2430fSAndrzej Pietrasiewicz  *
3000a2430fSAndrzej Pietrasiewicz  * REVISIT at least ACM could support tiocmget() if needed.
3100a2430fSAndrzej Pietrasiewicz  *
3200a2430fSAndrzej Pietrasiewicz  * REVISIT someday, allow multiplexing several TTYs over these endpoints.
3300a2430fSAndrzej Pietrasiewicz  */
3400a2430fSAndrzej Pietrasiewicz struct gserial {
3500a2430fSAndrzej Pietrasiewicz 	struct usb_function		func;
3600a2430fSAndrzej Pietrasiewicz 
3700a2430fSAndrzej Pietrasiewicz 	/* port is managed by gserial_{connect,disconnect} */
3800a2430fSAndrzej Pietrasiewicz 	struct gs_port			*ioport;
3900a2430fSAndrzej Pietrasiewicz 
4000a2430fSAndrzej Pietrasiewicz 	struct usb_ep			*in;
4100a2430fSAndrzej Pietrasiewicz 	struct usb_ep			*out;
4200a2430fSAndrzej Pietrasiewicz 
4300a2430fSAndrzej Pietrasiewicz 	/* REVISIT avoid this CDC-ACM support harder ... */
4400a2430fSAndrzej Pietrasiewicz 	struct usb_cdc_line_coding port_line_coding;	/* 9600-8-N-1 etc */
4500a2430fSAndrzej Pietrasiewicz 
4600a2430fSAndrzej Pietrasiewicz 	/* notification callbacks */
4700a2430fSAndrzej Pietrasiewicz 	void (*connect)(struct gserial *p);
4800a2430fSAndrzej Pietrasiewicz 	void (*disconnect)(struct gserial *p);
4900a2430fSAndrzej Pietrasiewicz 	int (*send_break)(struct gserial *p, int duration);
5000a2430fSAndrzej Pietrasiewicz };
5100a2430fSAndrzej Pietrasiewicz 
5200a2430fSAndrzej Pietrasiewicz /* utilities to allocate/free request and buffer */
5300a2430fSAndrzej Pietrasiewicz struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
5400a2430fSAndrzej Pietrasiewicz void gs_free_req(struct usb_ep *, struct usb_request *req);
5500a2430fSAndrzej Pietrasiewicz 
5600a2430fSAndrzej Pietrasiewicz /* management of individual TTY ports */
57b417343cSMichał Mirosław int gserial_alloc_line_no_console(unsigned char *port_line);
5800a2430fSAndrzej Pietrasiewicz int gserial_alloc_line(unsigned char *port_line);
5900a2430fSAndrzej Pietrasiewicz void gserial_free_line(unsigned char port_line);
6000a2430fSAndrzej Pietrasiewicz 
61d7cb8fb7SMichał Mirosław #ifdef CONFIG_U_SERIAL_CONSOLE
62d7cb8fb7SMichał Mirosław 
63d7cb8fb7SMichał Mirosław ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count);
64d7cb8fb7SMichał Mirosław ssize_t gserial_get_console(unsigned char port_num, char *page);
65d7cb8fb7SMichał Mirosław 
66d7cb8fb7SMichał Mirosław #endif /* CONFIG_U_SERIAL_CONSOLE */
67d7cb8fb7SMichał Mirosław 
6800a2430fSAndrzej Pietrasiewicz /* connect/disconnect is handled by individual functions */
6900a2430fSAndrzej Pietrasiewicz int gserial_connect(struct gserial *, u8 port_num);
7000a2430fSAndrzej Pietrasiewicz void gserial_disconnect(struct gserial *);
71*aba3a8d0SFabrice Gasnier void gserial_suspend(struct gserial *p);
72*aba3a8d0SFabrice Gasnier void gserial_resume(struct gserial *p);
7300a2430fSAndrzej Pietrasiewicz 
7400a2430fSAndrzej Pietrasiewicz /* functions are bound to configurations by a config or gadget driver */
7500a2430fSAndrzej Pietrasiewicz int gser_bind_config(struct usb_configuration *c, u8 port_num);
7600a2430fSAndrzej Pietrasiewicz int obex_bind_config(struct usb_configuration *c, u8 port_num);
7700a2430fSAndrzej Pietrasiewicz 
7800a2430fSAndrzej Pietrasiewicz #endif /* __U_SERIAL_H */
79