u_serial.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 4
  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(unsigned char *port_line);
  47. void gserial_free_line(unsigned char port_line);
  48. /* connect/disconnect is handled by individual functions */
  49. int gserial_connect(struct gserial *, u8 port_num);
  50. void gserial_disconnect(struct gserial *);
  51. /* functions are bound to configurations by a config or gadget driver */
  52. int gser_bind_config(struct usb_configuration *c, u8 port_num);
  53. int obex_bind_config(struct usb_configuration *c, u8 port_num);
  54. #endif /* __U_SERIAL_H */