u_serial.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  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
  7. */
  8. #ifndef __U_SERIAL_H
  9. #define __U_SERIAL_H
  10. #include <linux/usb/composite.h>
  11. #include <linux/usb/cdc.h>
  12. #define MAX_U_SERIAL_PORTS 8
  13. struct f_serial_opts {
  14. struct usb_function_instance func_inst;
  15. u8 port_num;
  16. };
  17. /*
  18. * One non-multiplexed "serial" I/O port ... there can be several of these
  19. * on any given USB peripheral device, if it provides enough endpoints.
  20. *
  21. * The "u_serial" utility component exists to do one thing: manage TTY
  22. * style I/O using the USB peripheral endpoints listed here, including
  23. * hookups to sysfs and /dev for each logical "tty" device.
  24. *
  25. * REVISIT at least ACM could support tiocmget() if needed.
  26. *
  27. * REVISIT someday, allow multiplexing several TTYs over these endpoints.
  28. */
  29. struct gserial {
  30. struct usb_function func;
  31. /* port is managed by gserial_{connect,disconnect} */
  32. struct gs_port *ioport;
  33. struct usb_ep *in;
  34. struct usb_ep *out;
  35. /* REVISIT avoid this CDC-ACM support harder ... */
  36. struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */
  37. /* notification callbacks */
  38. void (*connect)(struct gserial *p);
  39. void (*disconnect)(struct gserial *p);
  40. int (*send_break)(struct gserial *p, int duration);
  41. };
  42. /* utilities to allocate/free request and buffer */
  43. struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
  44. void gs_free_req(struct usb_ep *, struct usb_request *req);
  45. /* management of individual TTY ports */
  46. int gserial_alloc_line_no_console(unsigned char *port_line);
  47. int gserial_alloc_line(unsigned char *port_line);
  48. void gserial_free_line(unsigned char port_line);
  49. #ifdef CONFIG_U_SERIAL_CONSOLE
  50. ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count);
  51. ssize_t gserial_get_console(unsigned char port_num, char *page);
  52. #endif /* CONFIG_U_SERIAL_CONSOLE */
  53. /* connect/disconnect is handled by individual functions */
  54. int gserial_connect(struct gserial *, u8 port_num);
  55. void gserial_disconnect(struct gserial *);
  56. void gserial_suspend(struct gserial *p);
  57. void gserial_resume(struct gserial *p);
  58. #endif /* __U_SERIAL_H */