u_serial.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * u_serial.h - interface to USB gadget "serial port"/TTY utilities
  3. *
  4. * Copyright (C) 2008 David Brownell
  5. * Copyright (C) 2008 by Nokia Corporation
  6. *
  7. * This software is distributed under the terms of the GNU General
  8. * Public License ("GPL") as published by the Free Software Foundation,
  9. * either version 2 of that License or (at your option) any later version.
  10. */
  11. #ifndef __U_SERIAL_H
  12. #define __U_SERIAL_H
  13. #include <linux/usb/composite.h>
  14. #include <linux/usb/cdc.h>
  15. #define MAX_U_SERIAL_PORTS 4
  16. struct f_serial_opts {
  17. struct usb_function_instance func_inst;
  18. u8 port_num;
  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(unsigned char *port_line);
  50. void gserial_free_line(unsigned char port_line);
  51. /* connect/disconnect is handled by individual functions */
  52. int gserial_connect(struct gserial *, u8 port_num);
  53. void gserial_disconnect(struct gserial *);
  54. /* functions are bound to configurations by a config or gadget driver */
  55. int gser_bind_config(struct usb_configuration *c, u8 port_num);
  56. int obex_bind_config(struct usb_configuration *c, u8 port_num);
  57. #endif /* __U_SERIAL_H */