u_serial.h 2.3 KB

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