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
6 The PLX USB2380 is a PCIe version of the NET2280 and behaves more like the
7 USB338x but without the USB3.0 superspeed support.
9 This was tested with g_ether, g_serial, g_mass_storage on a Gateworks
12 Cc: Justin DeFields <justindefields@gmail.com>
13 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
14 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
16 drivers/usb/gadget/udc/Kconfig | 4 +++-
17 drivers/usb/gadget/udc/net2280.c | 51 +++++++++++++++++++++++-----------------
18 drivers/usb/gadget/udc/net2280.h | 1 +
19 3 files changed, 34 insertions(+), 22 deletions(-)
21 diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
22 index 7c28941..658b8da 100644
23 --- a/drivers/usb/gadget/udc/Kconfig
24 +++ b/drivers/usb/gadget/udc/Kconfig
25 @@ -312,7 +312,7 @@ config USB_NET2272_DMA
26 If unsure, say "N" here. The driver works fine in PIO mode.
29 - tristate "NetChip 228x / PLX USB338x"
30 + tristate "NetChip NET228x / PLX USB3x8x"
33 NetChip 2280 / 2282 is a PCI based USB peripheral controller which
34 @@ -322,6 +322,8 @@ config USB_NET2280
35 (for control transfers) and several endpoints with dedicated
38 + PLX 2380 is a PCIe version of the PLX 2380.
40 PLX 3380 / 3382 is a PCIe based USB peripheral controller which
41 supports full, high speed USB 2.0 and super speed USB 3.0
43 diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
44 index c894b94..614ab951 100644
45 --- a/drivers/usb/gadget/udc/net2280.c
46 +++ b/drivers/usb/gadget/udc/net2280.c
47 @@ -211,7 +211,7 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
51 - if (dev->quirks & PLX_SUPERSPEED) {
52 + if (dev->quirks & PLX_PCIE) {
53 if ((desc->bEndpointAddress & 0x0f) >= 0x0c) {
56 @@ -245,7 +245,7 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
57 /* set type, direction, address; reset fifo counters */
58 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
60 - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) {
61 + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
62 tmp = readl(&ep->cfg->ep_cfg);
63 /* If USB ep number doesn't match hardware ep number */
64 if ((tmp & 0xf) != usb_endpoint_num(desc)) {
65 @@ -316,7 +316,7 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
66 BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
69 - if (dev->quirks & PLX_SUPERSPEED)
70 + if (dev->quirks & PLX_PCIE)
72 writel(tmp, &ep->cfg->ep_cfg);
74 @@ -527,7 +527,7 @@ static int net2280_disable(struct usb_ep *_ep)
75 spin_lock_irqsave(&ep->dev->lock, flags);
78 - if (ep->dev->quirks & PLX_SUPERSPEED)
79 + if (ep->dev->quirks & PLX_PCIE)
80 ep_reset_338x(ep->dev->regs, ep);
82 ep_reset_228x(ep->dev->regs, ep);
83 @@ -862,7 +862,7 @@ static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma)
84 writel(readl(&dma->dmastat), &dma->dmastat);
86 writel(td_dma, &dma->dmadesc);
87 - if (ep->dev->quirks & PLX_SUPERSPEED)
88 + if (ep->dev->quirks & PLX_PCIE)
89 dmactl |= BIT(DMA_REQUEST_OUTSTANDING);
90 writel(dmactl, &dma->dmactl);
92 @@ -1046,7 +1046,7 @@ net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
94 /* kickstart this i/o queue? */
95 if (list_empty(&ep->queue) && !ep->stopped &&
96 - !((dev->quirks & PLX_SUPERSPEED) && ep->dma &&
97 + !((dev->quirks & PLX_PCIE) && ep->dma &&
98 (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) {
100 /* use DMA if the endpoint supports it, else pio */
101 @@ -1169,7 +1169,7 @@ static void scan_dma_completions(struct net2280_ep *ep)
103 } else if (!ep->is_in &&
104 (req->req.length % ep->ep.maxpacket) &&
105 - !(ep->dev->quirks & PLX_SUPERSPEED)) {
106 + !(ep->dev->quirks & PLX_PCIE)) {
108 tmp = readl(&ep->regs->ep_stat);
109 /* AVOID TROUBLE HERE by not issuing short reads from
110 @@ -1367,7 +1367,7 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
114 - if (ep->dev->quirks & PLX_SUPERSPEED &&
115 + if (ep->dev->quirks & PLX_PCIE &&
116 !list_empty(&ep->queue) && ep->td_dma)
119 @@ -2394,7 +2394,7 @@ static int net2280_start(struct usb_gadget *_gadget,
121 net2280_led_active(dev, 1);
123 - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched)
124 + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
125 defect7374_enable_data_eps_zero(dev);
128 @@ -3063,7 +3063,7 @@ static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
131 dev->protocol_stall = 0;
132 - if (!(dev->quirks & PLX_SUPERSPEED)) {
133 + if (!(dev->quirks & PLX_PCIE)) {
134 if (ep->dev->quirks & PLX_2280)
135 tmp = BIT(FIFO_OVERFLOW) |
137 @@ -3090,7 +3090,7 @@ static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
138 cpu_to_le32s(&u.raw[0]);
139 cpu_to_le32s(&u.raw[1]);
141 - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched)
142 + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched)
143 defect7374_workaround(dev, u.r);
146 @@ -3173,7 +3173,7 @@ static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
148 ep_vdbg(dev, "%s clear halt\n", e->ep.name);
150 - if ((ep->dev->quirks & PLX_SUPERSPEED) &&
151 + if ((ep->dev->quirks & PLX_PCIE) &&
152 !list_empty(&e->queue) && e->td_dma)
155 @@ -3195,7 +3195,7 @@ static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
156 if (e->ep.name == ep0name)
159 - if ((dev->quirks & PLX_SUPERSPEED) && e->dma)
160 + if ((dev->quirks & PLX_PCIE) && e->dma)
163 ep_vdbg(dev, "%s set halt\n", ep->ep.name);
164 @@ -3234,7 +3234,7 @@ do_stall:
168 - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) {
169 + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) {
170 u32 mask = (BIT(ENDPOINT_0_INTERRUPT) |
171 USB3380_IRQSTAT0_EP_INTR_MASK_IN |
172 USB3380_IRQSTAT0_EP_INTR_MASK_OUT);
173 @@ -3399,7 +3399,7 @@ __acquires(dev->lock)
174 writel(tmp, &dma->dmastat);
177 - if (dev->quirks & PLX_SUPERSPEED) {
178 + if (dev->quirks & PLX_PCIE) {
179 u32 r_dmacount = readl(&dma->dmacount);
180 if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
181 (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT)))
182 @@ -3468,7 +3468,7 @@ static irqreturn_t net2280_irq(int irq, void *_dev)
183 /* control requests and PIO */
184 handle_stat0_irqs(dev, readl(&dev->regs->irqstat0));
186 - if (dev->quirks & PLX_SUPERSPEED) {
187 + if (dev->quirks & PLX_PCIE) {
188 /* re-enable interrupt to trigger any possible new interrupt */
189 u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
190 writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
191 @@ -3513,7 +3513,7 @@ static void net2280_remove(struct pci_dev *pdev)
194 free_irq(pdev->irq, dev);
195 - if (dev->quirks & PLX_SUPERSPEED)
196 + if (dev->quirks & PLX_PCIE)
197 pci_disable_msi(pdev);
200 @@ -3593,7 +3593,7 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
201 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
202 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
204 - if (dev->quirks & PLX_SUPERSPEED) {
205 + if (dev->quirks & PLX_PCIE) {
208 dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
209 @@ -3637,7 +3637,7 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
213 - if (dev->quirks & PLX_SUPERSPEED)
214 + if (dev->quirks & PLX_PCIE)
215 if (pci_enable_msi(pdev))
216 ep_err(dev, "Failed to enable MSI mode\n");
218 @@ -3755,10 +3755,19 @@ static const struct pci_device_id pci_ids[] = { {
219 .class = PCI_CLASS_SERIAL_USB_DEVICE,
221 .vendor = PCI_VENDOR_ID_PLX,
223 + .subvendor = PCI_ANY_ID,
224 + .subdevice = PCI_ANY_ID,
225 + .driver_data = PLX_PCIE,
228 + .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
230 + .vendor = PCI_VENDOR_ID_PLX,
232 .subvendor = PCI_ANY_ID,
233 .subdevice = PCI_ANY_ID,
234 - .driver_data = PLX_SUPERSPEED,
235 + .driver_data = PLX_PCIE | PLX_SUPERSPEED,
238 .class = PCI_CLASS_SERIAL_USB_DEVICE,
239 @@ -3767,7 +3776,7 @@ static const struct pci_device_id pci_ids[] = { {
241 .subvendor = PCI_ANY_ID,
242 .subdevice = PCI_ANY_ID,
243 - .driver_data = PLX_SUPERSPEED,
244 + .driver_data = PLX_PCIE | PLX_SUPERSPEED,
246 { /* end: all zeroes */ }
248 diff --git a/drivers/usb/gadget/udc/net2280.h b/drivers/usb/gadget/udc/net2280.h
249 index 0d32052..2736a95 100644
250 --- a/drivers/usb/gadget/udc/net2280.h
251 +++ b/drivers/usb/gadget/udc/net2280.h
252 @@ -47,6 +47,7 @@ set_idx_reg(struct net2280_regs __iomem *regs, u32 index, u32 value)
253 #define PLX_LEGACY BIT(0)
254 #define PLX_2280 BIT(1)
255 #define PLX_SUPERSPEED BIT(2)
256 +#define PLX_PCIE BIT(3)
259 #define RETRY_COUNTER 16