1
0

160-usb-gadget-udc-net2280-add-usb2380-support.patch 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. From 5185c91385d73cdf79836eb8548e4726e43ae831 Mon Sep 17 00:00:00 2001
  2. From: Tim Harvey <tharvey@gateworks.com>
  3. Date: Mon, 23 May 2016 06:58:41 -0700
  4. Subject: [PATCH] usb: gadget: net2280: add USB2380 support
  5. The PLX USB2380 is a PCIe version of the NET2280 and behaves more like the
  6. USB338x but without the USB3.0 superspeed support.
  7. This was tested with g_ether, g_serial, g_mass_storage on a Gateworks
  8. Ventana GW2383.
  9. Cc: Justin DeFields <justindefields@gmail.com>
  10. Signed-off-by: Tim Harvey <tharvey@gateworks.com>
  11. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  12. ---
  13. drivers/usb/gadget/udc/Kconfig | 4 +++-
  14. drivers/usb/gadget/udc/net2280.c | 51 +++++++++++++++++++++++-----------------
  15. drivers/usb/gadget/udc/net2280.h | 1 +
  16. 3 files changed, 34 insertions(+), 22 deletions(-)
  17. --- a/drivers/usb/gadget/udc/Kconfig
  18. +++ b/drivers/usb/gadget/udc/Kconfig
  19. @@ -298,7 +298,7 @@ config USB_NET2272_DMA
  20. If unsure, say "N" here. The driver works fine in PIO mode.
  21. config USB_NET2280
  22. - tristate "NetChip 228x / PLX USB338x"
  23. + tristate "NetChip NET228x / PLX USB3x8x"
  24. depends on PCI
  25. help
  26. NetChip 2280 / 2282 is a PCI based USB peripheral controller which
  27. @@ -308,6 +308,8 @@ config USB_NET2280
  28. (for control transfers) and several endpoints with dedicated
  29. functions.
  30. + PLX 2380 is a PCIe version of the PLX 2380.
  31. +
  32. PLX 3380 / 3382 is a PCIe based USB peripheral controller which
  33. supports full, high speed USB 2.0 and super speed USB 3.0
  34. data transfers.
  35. --- a/drivers/usb/gadget/udc/net2280.c
  36. +++ b/drivers/usb/gadget/udc/net2280.c
  37. @@ -211,7 +211,7 @@ net2280_enable(struct usb_ep *_ep, const
  38. goto print_err;
  39. }
  40. - if (dev->quirks & PLX_SUPERSPEED) {
  41. + if (dev->quirks & PLX_PCIE) {
  42. if ((desc->bEndpointAddress & 0x0f) >= 0x0c) {
  43. ret = -EDOM;
  44. goto print_err;
  45. @@ -245,7 +245,7 @@ net2280_enable(struct usb_ep *_ep, const
  46. /* set type, direction, address; reset fifo counters */
  47. writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
  48. - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) {
  49. + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
  50. tmp = readl(&ep->cfg->ep_cfg);
  51. /* If USB ep number doesn't match hardware ep number */
  52. if ((tmp & 0xf) != usb_endpoint_num(desc)) {
  53. @@ -316,7 +316,7 @@ net2280_enable(struct usb_ep *_ep, const
  54. BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
  55. }
  56. - if (dev->quirks & PLX_SUPERSPEED)
  57. + if (dev->quirks & PLX_PCIE)
  58. ep_clear_seqnum(ep);
  59. writel(tmp, &ep->cfg->ep_cfg);
  60. @@ -527,7 +527,7 @@ static int net2280_disable(struct usb_ep
  61. spin_lock_irqsave(&ep->dev->lock, flags);
  62. nuke(ep);
  63. - if (ep->dev->quirks & PLX_SUPERSPEED)
  64. + if (ep->dev->quirks & PLX_PCIE)
  65. ep_reset_338x(ep->dev->regs, ep);
  66. else
  67. ep_reset_228x(ep->dev->regs, ep);
  68. @@ -862,7 +862,7 @@ static void start_queue(struct net2280_e
  69. writel(readl(&dma->dmastat), &dma->dmastat);
  70. writel(td_dma, &dma->dmadesc);
  71. - if (ep->dev->quirks & PLX_SUPERSPEED)
  72. + if (ep->dev->quirks & PLX_PCIE)
  73. dmactl |= BIT(DMA_REQUEST_OUTSTANDING);
  74. writel(dmactl, &dma->dmactl);
  75. @@ -1046,7 +1046,7 @@ net2280_queue(struct usb_ep *_ep, struct
  76. /* kickstart this i/o queue? */
  77. if (list_empty(&ep->queue) && !ep->stopped &&
  78. - !((dev->quirks & PLX_SUPERSPEED) && ep->dma &&
  79. + !((dev->quirks & PLX_PCIE) && ep->dma &&
  80. (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) {
  81. /* use DMA if the endpoint supports it, else pio */
  82. @@ -1169,7 +1169,7 @@ static void scan_dma_completions(struct
  83. break;
  84. } else if (!ep->is_in &&
  85. (req->req.length % ep->ep.maxpacket) &&
  86. - !(ep->dev->quirks & PLX_SUPERSPEED)) {
  87. + !(ep->dev->quirks & PLX_PCIE)) {
  88. tmp = readl(&ep->regs->ep_stat);
  89. /* AVOID TROUBLE HERE by not issuing short reads from
  90. @@ -1367,7 +1367,7 @@ net2280_set_halt_and_wedge(struct usb_ep
  91. ep->wedged = 1;
  92. } else {
  93. clear_halt(ep);
  94. - if (ep->dev->quirks & PLX_SUPERSPEED &&
  95. + if (ep->dev->quirks & PLX_PCIE &&
  96. !list_empty(&ep->queue) && ep->td_dma)
  97. restart_dma(ep);
  98. ep->wedged = 0;
  99. @@ -2394,7 +2394,7 @@ static int net2280_start(struct usb_gadg
  100. */
  101. net2280_led_active(dev, 1);
  102. - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched)
  103. + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
  104. defect7374_enable_data_eps_zero(dev);
  105. ep0_start(dev);
  106. @@ -3060,7 +3060,7 @@ static void handle_stat0_irqs(struct net
  107. }
  108. ep->stopped = 0;
  109. dev->protocol_stall = 0;
  110. - if (!(dev->quirks & PLX_SUPERSPEED)) {
  111. + if (!(dev->quirks & PLX_PCIE)) {
  112. if (ep->dev->quirks & PLX_2280)
  113. tmp = BIT(FIFO_OVERFLOW) |
  114. BIT(FIFO_UNDERFLOW);
  115. @@ -3087,7 +3087,7 @@ static void handle_stat0_irqs(struct net
  116. cpu_to_le32s(&u.raw[0]);
  117. cpu_to_le32s(&u.raw[1]);
  118. - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched)
  119. + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
  120. defect7374_workaround(dev, u.r);
  121. tmp = 0;
  122. @@ -3170,7 +3170,7 @@ static void handle_stat0_irqs(struct net
  123. } else {
  124. ep_vdbg(dev, "%s clear halt\n", e->ep.name);
  125. clear_halt(e);
  126. - if ((ep->dev->quirks & PLX_SUPERSPEED) &&
  127. + if ((ep->dev->quirks & PLX_PCIE) &&
  128. !list_empty(&e->queue) && e->td_dma)
  129. restart_dma(e);
  130. }
  131. @@ -3192,7 +3192,7 @@ static void handle_stat0_irqs(struct net
  132. if (e->ep.name == ep0name)
  133. goto do_stall;
  134. set_halt(e);
  135. - if ((dev->quirks & PLX_SUPERSPEED) && e->dma)
  136. + if ((dev->quirks & PLX_PCIE) && e->dma)
  137. abort_dma(e);
  138. allow_status(ep);
  139. ep_vdbg(dev, "%s set halt\n", ep->ep.name);
  140. @@ -3231,7 +3231,7 @@ do_stall:
  141. #undef w_length
  142. next_endpoints:
  143. - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) {
  144. + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
  145. u32 mask = (BIT(ENDPOINT_0_INTERRUPT) |
  146. USB3380_IRQSTAT0_EP_INTR_MASK_IN |
  147. USB3380_IRQSTAT0_EP_INTR_MASK_OUT);
  148. @@ -3392,7 +3392,7 @@ static void handle_stat1_irqs(struct net
  149. writel(tmp, &dma->dmastat);
  150. /* dma sync*/
  151. - if (dev->quirks & PLX_SUPERSPEED) {
  152. + if (dev->quirks & PLX_PCIE) {
  153. u32 r_dmacount = readl(&dma->dmacount);
  154. if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
  155. (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT)))
  156. @@ -3461,7 +3461,7 @@ static irqreturn_t net2280_irq(int irq,
  157. /* control requests and PIO */
  158. handle_stat0_irqs(dev, readl(&dev->regs->irqstat0));
  159. - if (dev->quirks & PLX_SUPERSPEED) {
  160. + if (dev->quirks & PLX_PCIE) {
  161. /* re-enable interrupt to trigger any possible new interrupt */
  162. u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
  163. writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
  164. @@ -3506,7 +3506,7 @@ static void net2280_remove(struct pci_de
  165. }
  166. if (dev->got_irq)
  167. free_irq(pdev->irq, dev);
  168. - if (dev->quirks & PLX_SUPERSPEED)
  169. + if (dev->quirks & PLX_PCIE)
  170. pci_disable_msi(pdev);
  171. if (dev->regs)
  172. iounmap(dev->regs);
  173. @@ -3586,7 +3586,7 @@ static int net2280_probe(struct pci_dev
  174. dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
  175. dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
  176. - if (dev->quirks & PLX_SUPERSPEED) {
  177. + if (dev->quirks & PLX_PCIE) {
  178. u32 fsmvalue;
  179. u32 usbstat;
  180. dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
  181. @@ -3630,7 +3630,7 @@ static int net2280_probe(struct pci_dev
  182. goto done;
  183. }
  184. - if (dev->quirks & PLX_SUPERSPEED)
  185. + if (dev->quirks & PLX_PCIE)
  186. if (pci_enable_msi(pdev))
  187. ep_err(dev, "Failed to enable MSI mode\n");
  188. @@ -3748,10 +3748,19 @@ static const struct pci_device_id pci_id
  189. .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
  190. .class_mask = ~0,
  191. .vendor = PCI_VENDOR_ID_PLX,
  192. + .device = 0x2380,
  193. + .subvendor = PCI_ANY_ID,
  194. + .subdevice = PCI_ANY_ID,
  195. + .driver_data = PLX_PCIE,
  196. + },
  197. + {
  198. + .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
  199. + .class_mask = ~0,
  200. + .vendor = PCI_VENDOR_ID_PLX,
  201. .device = 0x3380,
  202. .subvendor = PCI_ANY_ID,
  203. .subdevice = PCI_ANY_ID,
  204. - .driver_data = PLX_SUPERSPEED,
  205. + .driver_data = PLX_PCIE | PLX_SUPERSPEED,
  206. },
  207. {
  208. .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
  209. @@ -3760,7 +3769,7 @@ static const struct pci_device_id pci_id
  210. .device = 0x3382,
  211. .subvendor = PCI_ANY_ID,
  212. .subdevice = PCI_ANY_ID,
  213. - .driver_data = PLX_SUPERSPEED,
  214. + .driver_data = PLX_PCIE | PLX_SUPERSPEED,
  215. },
  216. { /* end: all zeroes */ }
  217. };
  218. --- a/drivers/usb/gadget/udc/net2280.h
  219. +++ b/drivers/usb/gadget/udc/net2280.h
  220. @@ -47,6 +47,7 @@ set_idx_reg(struct net2280_regs __iomem
  221. #define PLX_LEGACY BIT(0)
  222. #define PLX_2280 BIT(1)
  223. #define PLX_SUPERSPEED BIT(2)
  224. +#define PLX_PCIE BIT(3)
  225. #define REG_DIAG 0x0
  226. #define RETRY_COUNTER 16