isp1760-udc.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Driver for the NXP ISP1761 device controller
  4. *
  5. * Copyright 2021 Linaro, Rui Miguel Silva
  6. * Copyright 2014 Ideas on Board Oy
  7. *
  8. * Contacts:
  9. * Laurent Pinchart <[email protected]>
  10. * Rui Miguel Silva <[email protected]>
  11. */
  12. #ifndef _ISP1760_UDC_H_
  13. #define _ISP1760_UDC_H_
  14. #include <linux/ioport.h>
  15. #include <linux/list.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/timer.h>
  18. #include <linux/usb/gadget.h>
  19. #include "isp1760-regs.h"
  20. struct isp1760_device;
  21. struct isp1760_udc;
  22. enum isp1760_ctrl_state {
  23. ISP1760_CTRL_SETUP, /* Waiting for a SETUP transaction */
  24. ISP1760_CTRL_DATA_IN, /* Setup received, data IN stage */
  25. ISP1760_CTRL_DATA_OUT, /* Setup received, data OUT stage */
  26. ISP1760_CTRL_STATUS, /* 0-length request in status stage */
  27. };
  28. struct isp1760_ep {
  29. struct isp1760_udc *udc;
  30. struct usb_ep ep;
  31. struct list_head queue;
  32. unsigned int addr;
  33. unsigned int maxpacket;
  34. char name[7];
  35. const struct usb_endpoint_descriptor *desc;
  36. bool rx_pending;
  37. bool halted;
  38. bool wedged;
  39. };
  40. /**
  41. * struct isp1760_udc - UDC state information
  42. * irq: IRQ number
  43. * irqname: IRQ name (as passed to request_irq)
  44. * regs: regmap for UDC registers
  45. * driver: Gadget driver
  46. * gadget: Gadget device
  47. * lock: Protects driver, vbus_timer, ep, ep0_*, DC_EPINDEX register
  48. * ep: Array of endpoints
  49. * ep0_state: Control request state for endpoint 0
  50. * ep0_dir: Direction of the current control request
  51. * ep0_length: Length of the current control request
  52. * connected: Tracks gadget driver bus connection state
  53. */
  54. struct isp1760_udc {
  55. struct isp1760_device *isp;
  56. int irq;
  57. char *irqname;
  58. struct regmap *regs;
  59. struct regmap_field *fields[DC_FIELD_MAX];
  60. struct usb_gadget_driver *driver;
  61. struct usb_gadget gadget;
  62. spinlock_t lock;
  63. struct timer_list vbus_timer;
  64. struct isp1760_ep ep[15];
  65. enum isp1760_ctrl_state ep0_state;
  66. u8 ep0_dir;
  67. u16 ep0_length;
  68. bool connected;
  69. bool is_isp1763;
  70. unsigned int devstatus;
  71. };
  72. #ifdef CONFIG_USB_ISP1761_UDC
  73. int isp1760_udc_register(struct isp1760_device *isp, int irq,
  74. unsigned long irqflags);
  75. void isp1760_udc_unregister(struct isp1760_device *isp);
  76. #else
  77. static inline int isp1760_udc_register(struct isp1760_device *isp, int irq,
  78. unsigned long irqflags)
  79. {
  80. return 0;
  81. }
  82. static inline void isp1760_udc_unregister(struct isp1760_device *isp)
  83. {
  84. }
  85. #endif
  86. #endif