blob: 102a7323a1fd344e490acdc4440a9fd94c96cdc9 [file] [log] [blame]
Nishad Kamdar2e759732020-03-28 16:41:15 +05301/* SPDX-License-Identifier: GPL-2.0+ */
David Brownellc1dca562008-06-19 17:51:44 -07002/*
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 Brownellc1dca562008-06-19 17:51:44 -07007 */
8
9#ifndef __U_SERIAL_H
10#define __U_SERIAL_H
11
David Brownell4d5a73d2008-06-19 18:18:40 -070012#include <linux/usb/composite.h>
David Brownellc1dca562008-06-19 17:51:44 -070013#include <linux/usb/cdc.h>
14
Macpaul Lin9ffcc302020-06-16 13:56:17 +080015#define MAX_U_SERIAL_PORTS 8
Sebastian Andrzej Siewior19b10a82012-12-23 21:10:06 +010016
Sebastian Andrzej Siewiorff47f592012-12-23 21:10:07 +010017struct f_serial_opts {
18 struct usb_function_instance func_inst;
19 u8 port_num;
20};
21
David Brownellc1dca562008-06-19 17:51:44 -070022/*
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 Brownell1f1ba112008-08-06 18:49:57 -070030 * REVISIT at least ACM could support tiocmget() if needed.
David Brownellc1dca562008-06-19 17:51:44 -070031 *
32 * REVISIT someday, allow multiplexing several TTYs over these endpoints.
33 */
34struct gserial {
David Brownell4d5a73d2008-06-19 18:18:40 -070035 struct usb_function func;
David Brownellc1dca562008-06-19 17:51:44 -070036
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 Brownellc1dca562008-06-19 17:51:44 -070042
43 /* REVISIT avoid this CDC-ACM support harder ... */
44 struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */
David Brownell1f1ba112008-08-06 18:49:57 -070045
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 Brownellc1dca562008-06-19 17:51:44 -070050};
51
David Brownell1f1ba112008-08-06 18:49:57 -070052/* utilities to allocate/free request and buffer */
53struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
54void gs_free_req(struct usb_ep *, struct usb_request *req);
55
Sebastian Andrzej Siewior19b10a82012-12-23 21:10:06 +010056/* management of individual TTY ports */
Michał Mirosławb4173432019-08-10 10:42:50 +020057int gserial_alloc_line_no_console(unsigned char *port_line);
Sebastian Andrzej Siewior19b10a82012-12-23 21:10:06 +010058int gserial_alloc_line(unsigned char *port_line);
59void gserial_free_line(unsigned char port_line);
David Brownellc1dca562008-06-19 17:51:44 -070060
Michał Mirosławd7cb8fb2019-08-10 10:42:51 +020061#ifdef CONFIG_U_SERIAL_CONSOLE
62
63ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count);
64ssize_t gserial_get_console(unsigned char port_num, char *page);
65
66#endif /* CONFIG_U_SERIAL_CONSOLE */
67
David Brownellc1dca562008-06-19 17:51:44 -070068/* connect/disconnect is handled by individual functions */
69int gserial_connect(struct gserial *, u8 port_num);
70void gserial_disconnect(struct gserial *);
Fabrice Gasnieraba3a8d2020-04-23 13:55:54 +020071void gserial_suspend(struct gserial *p);
72void gserial_resume(struct gserial *p);
David Brownellc1dca562008-06-19 17:51:44 -070073
David Brownell4d5a73d2008-06-19 18:18:40 -070074/* functions are bound to configurations by a config or gadget driver */
David Brownell61d8bae2008-06-19 18:18:50 -070075int gser_bind_config(struct usb_configuration *c, u8 port_num);
Felipe Balbi30867752008-08-18 17:39:30 -070076int obex_bind_config(struct usb_configuration *c, u8 port_num);
David Brownell4d5a73d2008-06-19 18:18:40 -070077
David Brownellc1dca562008-06-19 17:51:44 -070078#endif /* __U_SERIAL_H */