at91_udc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (C) 2004 by Thomas Rathbone, HP Labs
  3. * Copyright (C) 2005 by Ivan Kokshaysky
  4. * Copyright (C) 2006 by SAN People
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef AT91_UDC_H
  12. #define AT91_UDC_H
  13. /*
  14. * USB Device Port (UDP) registers.
  15. * Based on AT91RM9200 datasheet revision E.
  16. */
  17. #define AT91_UDP_FRM_NUM 0x00 /* Frame Number Register */
  18. #define AT91_UDP_NUM (0x7ff << 0) /* Frame Number */
  19. #define AT91_UDP_FRM_ERR (1 << 16) /* Frame Error */
  20. #define AT91_UDP_FRM_OK (1 << 17) /* Frame OK */
  21. #define AT91_UDP_GLB_STAT 0x04 /* Global State Register */
  22. #define AT91_UDP_FADDEN (1 << 0) /* Function Address Enable */
  23. #define AT91_UDP_CONFG (1 << 1) /* Configured */
  24. #define AT91_UDP_ESR (1 << 2) /* Enable Send Resume */
  25. #define AT91_UDP_RSMINPR (1 << 3) /* Resume has been sent */
  26. #define AT91_UDP_RMWUPE (1 << 4) /* Remote Wake Up Enable */
  27. #define AT91_UDP_FADDR 0x08 /* Function Address Register */
  28. #define AT91_UDP_FADD (0x7f << 0) /* Function Address Value */
  29. #define AT91_UDP_FEN (1 << 8) /* Function Enable */
  30. #define AT91_UDP_IER 0x10 /* Interrupt Enable Register */
  31. #define AT91_UDP_IDR 0x14 /* Interrupt Disable Register */
  32. #define AT91_UDP_IMR 0x18 /* Interrupt Mask Register */
  33. #define AT91_UDP_ISR 0x1c /* Interrupt Status Register */
  34. #define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */
  35. #define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */
  36. #define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */
  37. #define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */
  38. #define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */
  39. #define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrupt Status */
  40. #define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */
  41. #define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */
  42. #define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */
  43. #define AT91_UDP_CSR(n) (0x30+((n)*4)) /* Endpoint Control/Status Registers 0-7 */
  44. #define AT91_UDP_TXCOMP (1 << 0) /* Generates IN packet with data previously written in DPR */
  45. #define AT91_UDP_RX_DATA_BK0 (1 << 1) /* Receive Data Bank 0 */
  46. #define AT91_UDP_RXSETUP (1 << 2) /* Send STALL to the host */
  47. #define AT91_UDP_STALLSENT (1 << 3) /* Stall Sent / Isochronous error (Isochronous endpoints) */
  48. #define AT91_UDP_TXPKTRDY (1 << 4) /* Transmit Packet Ready */
  49. #define AT91_UDP_FORCESTALL (1 << 5) /* Force Stall */
  50. #define AT91_UDP_RX_DATA_BK1 (1 << 6) /* Receive Data Bank 1 */
  51. #define AT91_UDP_DIR (1 << 7) /* Transfer Direction */
  52. #define AT91_UDP_EPTYPE (7 << 8) /* Endpoint Type */
  53. #define AT91_UDP_EPTYPE_CTRL (0 << 8)
  54. #define AT91_UDP_EPTYPE_ISO_OUT (1 << 8)
  55. #define AT91_UDP_EPTYPE_BULK_OUT (2 << 8)
  56. #define AT91_UDP_EPTYPE_INT_OUT (3 << 8)
  57. #define AT91_UDP_EPTYPE_ISO_IN (5 << 8)
  58. #define AT91_UDP_EPTYPE_BULK_IN (6 << 8)
  59. #define AT91_UDP_EPTYPE_INT_IN (7 << 8)
  60. #define AT91_UDP_DTGLE (1 << 11) /* Data Toggle */
  61. #define AT91_UDP_EPEDS (1 << 15) /* Endpoint Enable/Disable */
  62. #define AT91_UDP_RXBYTECNT (0x7ff << 16) /* Number of bytes in FIFO */
  63. #define AT91_UDP_FDR(n) (0x50+((n)*4)) /* Endpoint FIFO Data Registers 0-7 */
  64. #define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */
  65. #define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */
  66. #define AT91_UDP_TXVC_PUON (1 << 9) /* PullUp On [AT91SAM9260 only] */
  67. /*-------------------------------------------------------------------------*/
  68. /*
  69. * controller driver data structures
  70. */
  71. #define NUM_ENDPOINTS 6
  72. /*
  73. * hardware won't disable bus reset, or resume while the controller
  74. * is suspended ... watching suspend helps keep the logic symmetric.
  75. */
  76. #define MINIMUS_INTERRUPTUS \
  77. (AT91_UDP_ENDBUSRES | AT91_UDP_RXRSM | AT91_UDP_RXSUSP)
  78. struct at91_ep {
  79. struct usb_ep ep;
  80. struct list_head queue;
  81. struct at91_udc *udc;
  82. void __iomem *creg;
  83. unsigned maxpacket:16;
  84. u8 int_mask;
  85. unsigned is_pingpong:1;
  86. unsigned stopped:1;
  87. unsigned is_in:1;
  88. unsigned is_iso:1;
  89. unsigned fifo_bank:1;
  90. };
  91. struct at91_udc_caps {
  92. int (*init)(struct at91_udc *udc);
  93. void (*pullup)(struct at91_udc *udc, int is_on);
  94. };
  95. struct at91_udc_data {
  96. int vbus_pin; /* high == host powering us */
  97. u8 vbus_active_low; /* vbus polarity */
  98. u8 vbus_polled; /* Use polling, not interrupt */
  99. int pullup_pin; /* active == D+ pulled up */
  100. u8 pullup_active_low; /* true == pullup_pin is active low */
  101. };
  102. /*
  103. * driver is non-SMP, and just blocks IRQs whenever it needs
  104. * access protection for chip registers or driver state
  105. */
  106. struct at91_udc {
  107. struct usb_gadget gadget;
  108. struct at91_ep ep[NUM_ENDPOINTS];
  109. struct usb_gadget_driver *driver;
  110. const struct at91_udc_caps *caps;
  111. unsigned vbus:1;
  112. unsigned enabled:1;
  113. unsigned clocked:1;
  114. unsigned suspended:1;
  115. unsigned req_pending:1;
  116. unsigned wait_for_addr_ack:1;
  117. unsigned wait_for_config_ack:1;
  118. unsigned active_suspend:1;
  119. u8 addr;
  120. struct at91_udc_data board;
  121. struct clk *iclk, *fclk;
  122. struct platform_device *pdev;
  123. struct proc_dir_entry *pde;
  124. void __iomem *udp_baseaddr;
  125. int udp_irq;
  126. spinlock_t lock;
  127. struct timer_list vbus_timer;
  128. struct work_struct vbus_timer_work;
  129. struct regmap *matrix;
  130. };
  131. static inline struct at91_udc *to_udc(struct usb_gadget *g)
  132. {
  133. return container_of(g, struct at91_udc, gadget);
  134. }
  135. struct at91_request {
  136. struct usb_request req;
  137. struct list_head queue;
  138. };
  139. /*-------------------------------------------------------------------------*/
  140. #ifdef VERBOSE_DEBUG
  141. # define VDBG DBG
  142. #else
  143. # define VDBG(stuff...) do{}while(0)
  144. #endif
  145. #ifdef PACKET_TRACE
  146. # define PACKET VDBG
  147. #else
  148. # define PACKET(stuff...) do{}while(0)
  149. #endif
  150. #define ERR(stuff...) pr_err("udc: " stuff)
  151. #define WARNING(stuff...) pr_warning("udc: " stuff)
  152. #define INFO(stuff...) pr_info("udc: " stuff)
  153. #define DBG(stuff...) pr_debug("udc: " stuff)
  154. #endif