Nishad Kamdar | 2e75973 | 2020-03-28 16:41:15 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 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 |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef __U_SERIAL_H |
| 10 | #define __U_SERIAL_H |
| 11 | |
David Brownell | 4d5a73d | 2008-06-19 18:18:40 -0700 | [diff] [blame] | 12 | #include <linux/usb/composite.h> |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 13 | #include <linux/usb/cdc.h> |
| 14 | |
Macpaul Lin | 9ffcc30 | 2020-06-16 13:56:17 +0800 | [diff] [blame] | 15 | #define MAX_U_SERIAL_PORTS 8 |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 16 | |
Sebastian Andrzej Siewior | ff47f59 | 2012-12-23 21:10:07 +0100 | [diff] [blame] | 17 | struct f_serial_opts { |
| 18 | struct usb_function_instance func_inst; |
| 19 | u8 port_num; |
| 20 | }; |
| 21 | |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 22 | /* |
| 23 | * One non-multiplexed "serial" I/O port ... there can be several of these |
| 24 | * on any given USB peripheral device, if it provides enough endpoints. |
| 25 | * |
| 26 | * The "u_serial" utility component exists to do one thing: manage TTY |
| 27 | * style I/O using the USB peripheral endpoints listed here, including |
| 28 | * hookups to sysfs and /dev for each logical "tty" device. |
| 29 | * |
David Brownell | 1f1ba11 | 2008-08-06 18:49:57 -0700 | [diff] [blame] | 30 | * REVISIT at least ACM could support tiocmget() if needed. |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 31 | * |
| 32 | * REVISIT someday, allow multiplexing several TTYs over these endpoints. |
| 33 | */ |
| 34 | struct gserial { |
David Brownell | 4d5a73d | 2008-06-19 18:18:40 -0700 | [diff] [blame] | 35 | struct usb_function func; |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 36 | |
| 37 | /* port is managed by gserial_{connect,disconnect} */ |
| 38 | struct gs_port *ioport; |
| 39 | |
| 40 | struct usb_ep *in; |
| 41 | struct usb_ep *out; |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 42 | |
| 43 | /* REVISIT avoid this CDC-ACM support harder ... */ |
| 44 | struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */ |
David Brownell | 1f1ba11 | 2008-08-06 18:49:57 -0700 | [diff] [blame] | 45 | |
| 46 | /* notification callbacks */ |
| 47 | void (*connect)(struct gserial *p); |
| 48 | void (*disconnect)(struct gserial *p); |
| 49 | int (*send_break)(struct gserial *p, int duration); |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
David Brownell | 1f1ba11 | 2008-08-06 18:49:57 -0700 | [diff] [blame] | 52 | /* utilities to allocate/free request and buffer */ |
| 53 | struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags); |
| 54 | void gs_free_req(struct usb_ep *, struct usb_request *req); |
| 55 | |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 56 | /* management of individual TTY ports */ |
Michał Mirosław | b417343 | 2019-08-10 10:42:50 +0200 | [diff] [blame] | 57 | int gserial_alloc_line_no_console(unsigned char *port_line); |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 58 | int gserial_alloc_line(unsigned char *port_line); |
| 59 | void gserial_free_line(unsigned char port_line); |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 60 | |
Michał Mirosław | d7cb8fb | 2019-08-10 10:42:51 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_U_SERIAL_CONSOLE |
| 62 | |
| 63 | ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count); |
| 64 | ssize_t gserial_get_console(unsigned char port_num, char *page); |
| 65 | |
| 66 | #endif /* CONFIG_U_SERIAL_CONSOLE */ |
| 67 | |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 68 | /* connect/disconnect is handled by individual functions */ |
| 69 | int gserial_connect(struct gserial *, u8 port_num); |
| 70 | void gserial_disconnect(struct gserial *); |
Fabrice Gasnier | aba3a8d | 2020-04-23 13:55:54 +0200 | [diff] [blame] | 71 | void gserial_suspend(struct gserial *p); |
| 72 | void gserial_resume(struct gserial *p); |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 73 | |
David Brownell | 4d5a73d | 2008-06-19 18:18:40 -0700 | [diff] [blame] | 74 | /* functions are bound to configurations by a config or gadget driver */ |
David Brownell | 61d8bae | 2008-06-19 18:18:50 -0700 | [diff] [blame] | 75 | int gser_bind_config(struct usb_configuration *c, u8 port_num); |
Felipe Balbi | 3086775 | 2008-08-18 17:39:30 -0700 | [diff] [blame] | 76 | int obex_bind_config(struct usb_configuration *c, u8 port_num); |
David Brownell | 4d5a73d | 2008-06-19 18:18:40 -0700 | [diff] [blame] | 77 | |
David Brownell | c1dca56 | 2008-06-19 17:51:44 -0700 | [diff] [blame] | 78 | #endif /* __U_SERIAL_H */ |