xref: /linux/drivers/usb/gadget/function/u_serial.h (revision a17f04d4f26db70a42e52ebf0f04d84da79ebf1e)
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 
159ffcc305SMacpaul Lin #define MAX_U_SERIAL_PORTS	8
1600a2430fSAndrzej Pietrasiewicz 
1700a2430fSAndrzej Pietrasiewicz struct f_serial_opts {
1800a2430fSAndrzej Pietrasiewicz 	struct usb_function_instance func_inst;
1900a2430fSAndrzej Pietrasiewicz 	u8 port_num;
20*a17f04d4SMichael Walle 	u8 protocol;
21*a17f04d4SMichael Walle 
22*a17f04d4SMichael Walle 	struct mutex lock; /* protect instances */
23*a17f04d4SMichael Walle 	int instances;
2400a2430fSAndrzej Pietrasiewicz };
2500a2430fSAndrzej Pietrasiewicz 
2600a2430fSAndrzej Pietrasiewicz /*
2700a2430fSAndrzej Pietrasiewicz  * One non-multiplexed "serial" I/O port ... there can be several of these
2800a2430fSAndrzej Pietrasiewicz  * on any given USB peripheral device, if it provides enough endpoints.
2900a2430fSAndrzej Pietrasiewicz  *
3000a2430fSAndrzej Pietrasiewicz  * The "u_serial" utility component exists to do one thing:  manage TTY
3100a2430fSAndrzej Pietrasiewicz  * style I/O using the USB peripheral endpoints listed here, including
3200a2430fSAndrzej Pietrasiewicz  * hookups to sysfs and /dev for each logical "tty" device.
3300a2430fSAndrzej Pietrasiewicz  *
3400a2430fSAndrzej Pietrasiewicz  * REVISIT at least ACM could support tiocmget() if needed.
3500a2430fSAndrzej Pietrasiewicz  *
3600a2430fSAndrzej Pietrasiewicz  * REVISIT someday, allow multiplexing several TTYs over these endpoints.
3700a2430fSAndrzej Pietrasiewicz  */
3800a2430fSAndrzej Pietrasiewicz struct gserial {
3900a2430fSAndrzej Pietrasiewicz 	struct usb_function		func;
4000a2430fSAndrzej Pietrasiewicz 
4100a2430fSAndrzej Pietrasiewicz 	/* port is managed by gserial_{connect,disconnect} */
4200a2430fSAndrzej Pietrasiewicz 	struct gs_port			*ioport;
4300a2430fSAndrzej Pietrasiewicz 
4400a2430fSAndrzej Pietrasiewicz 	struct usb_ep			*in;
4500a2430fSAndrzej Pietrasiewicz 	struct usb_ep			*out;
4600a2430fSAndrzej Pietrasiewicz 
4700a2430fSAndrzej Pietrasiewicz 	/* REVISIT avoid this CDC-ACM support harder ... */
4800a2430fSAndrzej Pietrasiewicz 	struct usb_cdc_line_coding port_line_coding;	/* 9600-8-N-1 etc */
4900a2430fSAndrzej Pietrasiewicz 
5000a2430fSAndrzej Pietrasiewicz 	/* notification callbacks */
5100a2430fSAndrzej Pietrasiewicz 	void (*connect)(struct gserial *p);
5200a2430fSAndrzej Pietrasiewicz 	void (*disconnect)(struct gserial *p);
5300a2430fSAndrzej Pietrasiewicz 	int (*send_break)(struct gserial *p, int duration);
5400a2430fSAndrzej Pietrasiewicz };
5500a2430fSAndrzej Pietrasiewicz 
5600a2430fSAndrzej Pietrasiewicz /* utilities to allocate/free request and buffer */
5700a2430fSAndrzej Pietrasiewicz struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
5800a2430fSAndrzej Pietrasiewicz void gs_free_req(struct usb_ep *, struct usb_request *req);
5900a2430fSAndrzej Pietrasiewicz 
6000a2430fSAndrzej Pietrasiewicz /* management of individual TTY ports */
61b417343cSMichał Mirosław int gserial_alloc_line_no_console(unsigned char *port_line);
6200a2430fSAndrzej Pietrasiewicz int gserial_alloc_line(unsigned char *port_line);
6300a2430fSAndrzej Pietrasiewicz void gserial_free_line(unsigned char port_line);
6400a2430fSAndrzej Pietrasiewicz 
65d7cb8fb7SMichał Mirosław #ifdef CONFIG_U_SERIAL_CONSOLE
66d7cb8fb7SMichał Mirosław 
67d7cb8fb7SMichał Mirosław ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count);
68d7cb8fb7SMichał Mirosław ssize_t gserial_get_console(unsigned char port_num, char *page);
69d7cb8fb7SMichał Mirosław 
70d7cb8fb7SMichał Mirosław #endif /* CONFIG_U_SERIAL_CONSOLE */
71d7cb8fb7SMichał Mirosław 
7200a2430fSAndrzej Pietrasiewicz /* connect/disconnect is handled by individual functions */
7300a2430fSAndrzej Pietrasiewicz int gserial_connect(struct gserial *, u8 port_num);
7400a2430fSAndrzej Pietrasiewicz void gserial_disconnect(struct gserial *);
75aba3a8d0SFabrice Gasnier void gserial_suspend(struct gserial *p);
76aba3a8d0SFabrice Gasnier void gserial_resume(struct gserial *p);
7700a2430fSAndrzej Pietrasiewicz 
7800a2430fSAndrzej Pietrasiewicz #endif /* __U_SERIAL_H */
79