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