aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2014-05-15 08:28:46 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-05-27 19:02:03 -0400
commitc4128cac3557ddd5fa972cb6511c426cd94a7ccd (patch)
tree091a9630f81e35f8f51b32f0e63df4c69f269935
parent849b1333153c989b3618e05981fd23f61fcfdee4 (diff)
usb: gadget: net2280: Add support for PLX USB338X
This patch adds support for the PLX USB3380 and USB3382. This driver is based on the driver from the manufacturer. Since USB338X is register compatible with NET2280, I thought that it would be better to include this hardware into net2280 driver. Manufacturer's driver only supported the USB33X, did not follow the Kernel Style and contain some trivial errors. This patch has tried to address this issues. This patch has only been tested on USB338x hardware, but the merge has been done trying to not affect the behaviour of NET2280. Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Tested-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/gadget/Kconfig10
-rw-r--r--drivers/usb/gadget/net2280.c1115
-rw-r--r--drivers/usb/gadget/net2280.h97
-rw-r--r--include/linux/usb/usb338x.h199
4 files changed, 1330 insertions, 91 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index ba18e9c110cc..49e434ec527d 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -409,7 +409,7 @@ config USB_NET2272_DMA
409 If unsure, say "N" here. The driver works fine in PIO mode. 409 If unsure, say "N" here. The driver works fine in PIO mode.
410 410
411config USB_NET2280 411config USB_NET2280
412 tristate "NetChip 228x" 412 tristate "NetChip 228x / PLX USB338x"
413 depends on PCI 413 depends on PCI
414 help 414 help
415 NetChip 2280 / 2282 is a PCI based USB peripheral controller which 415 NetChip 2280 / 2282 is a PCI based USB peripheral controller which
@@ -419,6 +419,14 @@ config USB_NET2280
419 (for control transfers) and several endpoints with dedicated 419 (for control transfers) and several endpoints with dedicated
420 functions. 420 functions.
421 421
422 PLX 3380 / 3382 is a PCIe based USB peripheral controller which
423 supports full, high speed USB 2.0 and super speed USB 3.0
424 data transfers.
425
426 It has eight configurable endpoints, as well as endpoint zero
427 (for control transfers) and several endpoints with dedicated
428 functions.
429
422 Say "y" to link the driver statically, or "m" to build a 430 Say "y" to link the driver statically, or "m" to build a
423 dynamically linked module called "net2280" and force all 431 dynamically linked module called "net2280" and force all
424 gadget drivers to also be dynamically linked. 432 gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 300b3a71383b..87789c9bf7fe 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -18,6 +18,9 @@
18 * hint to completely eliminate some IRQs, if a later IRQ is guaranteed 18 * hint to completely eliminate some IRQs, if a later IRQ is guaranteed
19 * and DMA chaining is enabled. 19 * and DMA chaining is enabled.
20 * 20 *
21 * MSI is enabled by default. The legacy IRQ is used if MSI couldn't
22 * be enabled.
23 *
21 * Note that almost all the errata workarounds here are only needed for 24 * Note that almost all the errata workarounds here are only needed for
22 * rev1 chips. Rev1a silicon (0110) fixes almost all of them. 25 * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
23 */ 26 */
@@ -25,10 +28,14 @@
25/* 28/*
26 * Copyright (C) 2003 David Brownell 29 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc. 30 * Copyright (C) 2003-2005 PLX Technology, Inc.
31 * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
28 * 32 *
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility 33 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
30 * with 2282 chip 34 * with 2282 chip
31 * 35 *
36 * Modified Ricardo Ribalda Qtechnology AS to provide compatibility
37 * with usb 338x chip. Based on PLX driver
38 *
32 * This program is free software; you can redistribute it and/or modify 39 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by 40 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or 41 * the Free Software Foundation; either version 2 of the License, or
@@ -61,9 +68,8 @@
61#include <asm/irq.h> 68#include <asm/irq.h>
62#include <asm/unaligned.h> 69#include <asm/unaligned.h>
63 70
64 71#define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller"
65#define DRIVER_DESC "PLX NET228x USB Peripheral Controller" 72#define DRIVER_VERSION "2005 Sept 27/v3.0"
66#define DRIVER_VERSION "2005 Sept 27"
67 73
68#define EP_DONTUSE 13 /* nonzero */ 74#define EP_DONTUSE 13 /* nonzero */
69 75
@@ -73,11 +79,12 @@
73static const char driver_name [] = "net2280"; 79static const char driver_name [] = "net2280";
74static const char driver_desc [] = DRIVER_DESC; 80static const char driver_desc [] = DRIVER_DESC;
75 81
82static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
76static const char ep0name [] = "ep0"; 83static const char ep0name [] = "ep0";
77static const char *const ep_name [] = { 84static const char *const ep_name [] = {
78 ep0name, 85 ep0name,
79 "ep-a", "ep-b", "ep-c", "ep-d", 86 "ep-a", "ep-b", "ep-c", "ep-d",
80 "ep-e", "ep-f", 87 "ep-e", "ep-f", "ep-g", "ep-h",
81}; 88};
82 89
83/* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO) 90/* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
@@ -90,11 +97,12 @@ static const char *const ep_name [] = {
90 */ 97 */
91static bool use_dma = 1; 98static bool use_dma = 1;
92static bool use_dma_chaining = 0; 99static bool use_dma_chaining = 0;
100static bool use_msi = 1;
93 101
94/* "modprobe net2280 use_dma=n" etc */ 102/* "modprobe net2280 use_dma=n" etc */
95module_param (use_dma, bool, S_IRUGO); 103module_param (use_dma, bool, S_IRUGO);
96module_param (use_dma_chaining, bool, S_IRUGO); 104module_param (use_dma_chaining, bool, S_IRUGO);
97 105module_param(use_msi, bool, S_IRUGO);
98 106
99/* mode 0 == ep-{a,b,c,d} 1K fifo each 107/* mode 0 == ep-{a,b,c,d} 1K fifo each
100 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable 108 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
@@ -148,6 +156,9 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
148 struct net2280_ep *ep; 156 struct net2280_ep *ep;
149 u32 max, tmp; 157 u32 max, tmp;
150 unsigned long flags; 158 unsigned long flags;
159 static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 };
160 static const u32 ep_enhanced[9] = { 0x10, 0x60, 0x30, 0x80,
161 0x50, 0x20, 0x70, 0x40, 0x90 };
151 162
152 ep = container_of (_ep, struct net2280_ep, ep); 163 ep = container_of (_ep, struct net2280_ep, ep);
153 if (!_ep || !desc || ep->desc || _ep->name == ep0name 164 if (!_ep || !desc || ep->desc || _ep->name == ep0name
@@ -161,11 +172,20 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
161 if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) 172 if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE)
162 return -EDOM; 173 return -EDOM;
163 174
175 if (dev->pdev->vendor == 0x10b5) {
176 if ((desc->bEndpointAddress & 0x0f) >= 0x0c)
177 return -EDOM;
178 ep->is_in = !!usb_endpoint_dir_in(desc);
179 if (dev->enhanced_mode && ep->is_in && ep_key[ep->num])
180 return -EINVAL;
181 }
182
164 /* sanity check ep-e/ep-f since their fifos are small */ 183 /* sanity check ep-e/ep-f since their fifos are small */
165 max = usb_endpoint_maxp (desc) & 0x1fff; 184 max = usb_endpoint_maxp (desc) & 0x1fff;
166 if (ep->num > 4 && max > 64) 185 if (ep->num > 4 && max > 64 && (dev->pdev->vendor == 0x17cc))
167 return -ERANGE; 186 return -ERANGE;
168 187
188
169 spin_lock_irqsave (&dev->lock, flags); 189 spin_lock_irqsave (&dev->lock, flags);
170 _ep->maxpacket = max & 0x7ff; 190 _ep->maxpacket = max & 0x7ff;
171 ep->desc = desc; 191 ep->desc = desc;
@@ -176,7 +196,8 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
176 ep->out_overflow = 0; 196 ep->out_overflow = 0;
177 197
178 /* set speed-dependent max packet; may kick in high bandwidth */ 198 /* set speed-dependent max packet; may kick in high bandwidth */
179 set_idx_reg (dev->regs, REG_EP_MAXPKT (dev, ep->num), max); 199 set_idx_reg(dev->regs, (dev->enhanced_mode) ? ep_enhanced[ep->num]
200 : REG_EP_MAXPKT(dev, ep->num), max);
180 201
181 /* FIFO lines can't go to different packets. PIO is ok, so 202 /* FIFO lines can't go to different packets. PIO is ok, so
182 * use it instead of troublesome (non-bulk) multi-packet DMA. 203 * use it instead of troublesome (non-bulk) multi-packet DMA.
@@ -199,23 +220,43 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
199 &ep->regs->ep_rsp); 220 &ep->regs->ep_rsp);
200 } else if (tmp == USB_ENDPOINT_XFER_BULK) { 221 } else if (tmp == USB_ENDPOINT_XFER_BULK) {
201 /* catch some particularly blatant driver bugs */ 222 /* catch some particularly blatant driver bugs */
202 if ((dev->gadget.speed == USB_SPEED_HIGH 223 if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) ||
203 && max != 512) 224 (dev->gadget.speed == USB_SPEED_HIGH && max != 512) ||
204 || (dev->gadget.speed == USB_SPEED_FULL 225 (dev->gadget.speed == USB_SPEED_FULL && max > 64)) {
205 && max > 64)) { 226 spin_unlock_irqrestore(&dev->lock, flags);
206 spin_unlock_irqrestore (&dev->lock, flags);
207 return -ERANGE; 227 return -ERANGE;
208 } 228 }
209 } 229 }
210 ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0; 230 ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0;
211 tmp <<= ENDPOINT_TYPE; 231 /* Enable this endpoint */
212 tmp |= desc->bEndpointAddress; 232 if (dev->pdev->vendor == 0x17cc) {
213 tmp |= (4 << ENDPOINT_BYTE_COUNT); /* default full fifo lines */ 233 tmp <<= ENDPOINT_TYPE;
214 tmp |= 1 << ENDPOINT_ENABLE; 234 tmp |= desc->bEndpointAddress;
215 wmb (); 235 /* default full fifo lines */
236 tmp |= (4 << ENDPOINT_BYTE_COUNT);
237 tmp |= 1 << ENDPOINT_ENABLE;
238 ep->is_in = (tmp & USB_DIR_IN) != 0;
239 } else {
240 /* In Legacy mode, only OUT endpoints are used */
241 if (dev->enhanced_mode && ep->is_in) {
242 tmp <<= IN_ENDPOINT_TYPE;
243 tmp |= (1 << IN_ENDPOINT_ENABLE);
244 /* Not applicable to Legacy */
245 tmp |= (1 << ENDPOINT_DIRECTION);
246 } else {
247 tmp <<= OUT_ENDPOINT_TYPE;
248 tmp |= (1 << OUT_ENDPOINT_ENABLE);
249 tmp |= (ep->is_in << ENDPOINT_DIRECTION);
250 }
251
252 tmp |= usb_endpoint_num(desc);
253 tmp |= (ep->ep.maxburst << MAX_BURST_SIZE);
254 }
255
256 /* Make sure all the registers are written before ep_rsp*/
257 wmb();
216 258
217 /* for OUT transfers, block the rx fifo until a read is posted */ 259 /* for OUT transfers, block the rx fifo until a read is posted */
218 ep->is_in = (tmp & USB_DIR_IN) != 0;
219 if (!ep->is_in) 260 if (!ep->is_in)
220 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); 261 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
221 else if (dev->pdev->device != 0x2280) { 262 else if (dev->pdev->device != 0x2280) {
@@ -226,11 +267,13 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
226 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); 267 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
227 } 268 }
228 269
229 writel (tmp, &ep->regs->ep_cfg); 270 writel(tmp, &ep->cfg->ep_cfg);
230 271
231 /* enable irqs */ 272 /* enable irqs */
232 if (!ep->dma) { /* pio, per-packet */ 273 if (!ep->dma) { /* pio, per-packet */
233 tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0); 274 tmp = (dev->pdev->vendor == 0x17cc)?(1 << ep->num)
275 : (1 << ep_bit[ep->num]);
276 tmp |= readl(&dev->regs->pciirqenb0);
234 writel (tmp, &dev->regs->pciirqenb0); 277 writel (tmp, &dev->regs->pciirqenb0);
235 278
236 tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) 279 tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
@@ -251,8 +294,10 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
251 tmp = (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE); 294 tmp = (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
252 writel (tmp, &ep->regs->ep_irqenb); 295 writel (tmp, &ep->regs->ep_irqenb);
253 296
254 tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0); 297 tmp = (dev->pdev->vendor == 0x17cc)?(1 << ep->num)
255 writel (tmp, &dev->regs->pciirqenb0); 298 : (1 << ep_bit[ep->num]);
299 tmp |= readl(&dev->regs->pciirqenb0);
300 writel(tmp, &dev->regs->pciirqenb0);
256 } 301 }
257 } 302 }
258 303
@@ -286,7 +331,8 @@ static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec)
286 331
287static const struct usb_ep_ops net2280_ep_ops; 332static const struct usb_ep_ops net2280_ep_ops;
288 333
289static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) 334static void ep_reset_228x(struct net2280_regs __iomem *regs,
335 struct net2280_ep *ep)
290{ 336{
291 u32 tmp; 337 u32 tmp;
292 338
@@ -361,6 +407,55 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
361 /* fifo size is handled separately */ 407 /* fifo size is handled separately */
362} 408}
363 409
410static void ep_reset_338x(struct net2280_regs __iomem *regs,
411 struct net2280_ep *ep)
412{
413 u32 tmp, dmastat;
414
415 ep->desc = NULL;
416 INIT_LIST_HEAD(&ep->queue);
417
418 usb_ep_set_maxpacket_limit(&ep->ep, ~0);
419 ep->ep.ops = &net2280_ep_ops;
420
421 /* disable the dma, irqs, endpoint... */
422 if (ep->dma) {
423 writel(0, &ep->dma->dmactl);
424 writel((1 << DMA_ABORT_DONE_INTERRUPT) |
425 (1 << DMA_PAUSE_DONE_INTERRUPT) |
426 (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT) |
427 (1 << DMA_TRANSACTION_DONE_INTERRUPT)
428 /* | (1 << DMA_ABORT) */
429 , &ep->dma->dmastat);
430
431 dmastat = readl(&ep->dma->dmastat);
432 if (dmastat == 0x5002) {
433 WARNING(ep->dev, "The dmastat return = %x!!\n",
434 dmastat);
435 writel(0x5a, &ep->dma->dmastat);
436 }
437
438 tmp = readl(&regs->pciirqenb0);
439 tmp &= ~(1 << ep_bit[ep->num]);
440 writel(tmp, &regs->pciirqenb0);
441 } else {
442 if (ep->num < 5) {
443 tmp = readl(&regs->pciirqenb1);
444 tmp &= ~(1 << (8 + ep->num)); /* completion */
445 writel(tmp, &regs->pciirqenb1);
446 }
447 }
448 writel(0, &ep->regs->ep_irqenb);
449
450 writel((1 << SHORT_PACKET_OUT_DONE_INTERRUPT) |
451 (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) |
452 (1 << FIFO_OVERFLOW) |
453 (1 << DATA_PACKET_RECEIVED_INTERRUPT) |
454 (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) |
455 (1 << DATA_OUT_PING_TOKEN_INTERRUPT) |
456 (1 << DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat);
457}
458
364static void nuke (struct net2280_ep *); 459static void nuke (struct net2280_ep *);
365 460
366static int net2280_disable (struct usb_ep *_ep) 461static int net2280_disable (struct usb_ep *_ep)
@@ -374,13 +469,17 @@ static int net2280_disable (struct usb_ep *_ep)
374 469
375 spin_lock_irqsave (&ep->dev->lock, flags); 470 spin_lock_irqsave (&ep->dev->lock, flags);
376 nuke (ep); 471 nuke (ep);
377 ep_reset (ep->dev->regs, ep); 472
473 if (ep->dev->pdev->vendor == 0x10b5)
474 ep_reset_338x(ep->dev->regs, ep);
475 else
476 ep_reset_228x(ep->dev->regs, ep);
378 477
379 VDEBUG (ep->dev, "disabled %s %s\n", 478 VDEBUG (ep->dev, "disabled %s %s\n",
380 ep->dma ? "dma" : "pio", _ep->name); 479 ep->dma ? "dma" : "pio", _ep->name);
381 480
382 /* synch memory views with the device */ 481 /* synch memory views with the device */
383 (void) readl (&ep->regs->ep_cfg); 482 (void)readl(&ep->cfg->ep_cfg);
384 483
385 if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4) 484 if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4)
386 ep->dma = &ep->dev->dma [ep->num - 1]; 485 ep->dma = &ep->dev->dma [ep->num - 1];
@@ -698,6 +797,8 @@ static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma)
698 writel (readl (&dma->dmastat), &dma->dmastat); 797 writel (readl (&dma->dmastat), &dma->dmastat);
699 798
700 writel (td_dma, &dma->dmadesc); 799 writel (td_dma, &dma->dmadesc);
800 if (ep->dev->pdev->vendor == 0x10b5)
801 dmactl |= (0x01 << DMA_REQUEST_OUTSTANDING);
701 writel (dmactl, &dma->dmactl); 802 writel (dmactl, &dma->dmactl);
702 803
703 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */ 804 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
@@ -772,6 +873,21 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
772 start_queue (ep, tmp, req->td_dma); 873 start_queue (ep, tmp, req->td_dma);
773} 874}
774 875
876static inline void resume_dma(struct net2280_ep *ep)
877{
878 writel(readl(&ep->dma->dmactl) | (1 << DMA_ENABLE), &ep->dma->dmactl);
879
880 ep->dma_started = true;
881}
882
883static inline void ep_stop_dma(struct net2280_ep *ep)
884{
885 writel(readl(&ep->dma->dmactl) & ~(1 << DMA_ENABLE), &ep->dma->dmactl);
886 spin_stop_dma(ep->dma);
887
888 ep->dma_started = false;
889}
890
775static inline void 891static inline void
776queue_dma (struct net2280_ep *ep, struct net2280_request *req, int valid) 892queue_dma (struct net2280_ep *ep, struct net2280_request *req, int valid)
777{ 893{
@@ -874,8 +990,23 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
874 990
875 /* kickstart this i/o queue? */ 991 /* kickstart this i/o queue? */
876 if (list_empty (&ep->queue) && !ep->stopped) { 992 if (list_empty (&ep->queue) && !ep->stopped) {
993 /* DMA request while EP halted */
994 if (ep->dma &&
995 (readl(&ep->regs->ep_rsp) & (1 << CLEAR_ENDPOINT_HALT)) &&
996 (dev->pdev->vendor == 0x10b5)) {
997 int valid = 1;
998 if (ep->is_in) {
999 int expect;
1000 expect = likely(req->req.zero ||
1001 ((req->req.length %
1002 ep->ep.maxpacket) != 0));
1003 if (expect != ep->in_fifo_validate)
1004 valid = 0;
1005 }
1006 queue_dma(ep, req, valid);
1007 }
877 /* use DMA if the endpoint supports it, else pio */ 1008 /* use DMA if the endpoint supports it, else pio */
878 if (ep->dma) 1009 else if (ep->dma)
879 start_dma (ep, req); 1010 start_dma (ep, req);
880 else { 1011 else {
881 /* maybe there's no control data, just status ack */ 1012 /* maybe there's no control data, just status ack */
@@ -993,6 +1124,8 @@ static void scan_dma_completions (struct net2280_ep *ep)
993 } else if (!ep->is_in 1124 } else if (!ep->is_in
994 && (req->req.length % ep->ep.maxpacket) != 0) { 1125 && (req->req.length % ep->ep.maxpacket) != 0) {
995 tmp = readl (&ep->regs->ep_stat); 1126 tmp = readl (&ep->regs->ep_stat);
1127 if (ep->dev->pdev->vendor == 0x10b5)
1128 return dma_done(ep, req, tmp, 0);
996 1129
997 /* AVOID TROUBLE HERE by not issuing short reads from 1130 /* AVOID TROUBLE HERE by not issuing short reads from
998 * your gadget driver. That helps avoids errata 0121, 1131 * your gadget driver. That helps avoids errata 0121,
@@ -1079,7 +1212,7 @@ static void restart_dma (struct net2280_ep *ep)
1079 start_queue (ep, dmactl, req->td_dma); 1212 start_queue (ep, dmactl, req->td_dma);
1080} 1213}
1081 1214
1082static void abort_dma (struct net2280_ep *ep) 1215static void abort_dma_228x(struct net2280_ep *ep)
1083{ 1216{
1084 /* abort the current transfer */ 1217 /* abort the current transfer */
1085 if (likely (!list_empty (&ep->queue))) { 1218 if (likely (!list_empty (&ep->queue))) {
@@ -1091,6 +1224,19 @@ static void abort_dma (struct net2280_ep *ep)
1091 scan_dma_completions (ep); 1224 scan_dma_completions (ep);
1092} 1225}
1093 1226
1227static void abort_dma_338x(struct net2280_ep *ep)
1228{
1229 writel((1 << DMA_ABORT), &ep->dma->dmastat);
1230 spin_stop_dma(ep->dma);
1231}
1232
1233static void abort_dma(struct net2280_ep *ep)
1234{
1235 if (ep->dev->pdev->vendor == 0x17cc)
1236 return abort_dma_228x(ep);
1237 return abort_dma_338x(ep);
1238}
1239
1094/* dequeue ALL requests */ 1240/* dequeue ALL requests */
1095static void nuke (struct net2280_ep *ep) 1241static void nuke (struct net2280_ep *ep)
1096{ 1242{
@@ -1244,6 +1390,9 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
1244 ep->wedged = 1; 1390 ep->wedged = 1;
1245 } else { 1391 } else {
1246 clear_halt (ep); 1392 clear_halt (ep);
1393 if (ep->dev->pdev->vendor == 0x10b5 &&
1394 !list_empty(&ep->queue) && ep->td_dma)
1395 restart_dma(ep);
1247 ep->wedged = 0; 1396 ep->wedged = 0;
1248 } 1397 }
1249 (void) readl (&ep->regs->ep_rsp); 1398 (void) readl (&ep->regs->ep_rsp);
@@ -1367,10 +1516,13 @@ static int net2280_set_selfpowered (struct usb_gadget *_gadget, int value)
1367 1516
1368 spin_lock_irqsave (&dev->lock, flags); 1517 spin_lock_irqsave (&dev->lock, flags);
1369 tmp = readl (&dev->usb->usbctl); 1518 tmp = readl (&dev->usb->usbctl);
1370 if (value) 1519 if (value) {
1371 tmp |= (1 << SELF_POWERED_STATUS); 1520 tmp |= (1 << SELF_POWERED_STATUS);
1372 else 1521 dev->selfpowered = 1;
1522 } else {
1373 tmp &= ~(1 << SELF_POWERED_STATUS); 1523 tmp &= ~(1 << SELF_POWERED_STATUS);
1524 dev->selfpowered = 0;
1525 }
1374 writel (tmp, &dev->usb->usbctl); 1526 writel (tmp, &dev->usb->usbctl);
1375 spin_unlock_irqrestore (&dev->lock, flags); 1527 spin_unlock_irqrestore (&dev->lock, flags);
1376 1528
@@ -1504,14 +1656,14 @@ static ssize_t registers_show(struct device *_dev,
1504 /* DMA Control Registers */ 1656 /* DMA Control Registers */
1505 1657
1506 /* Configurable EP Control Registers */ 1658 /* Configurable EP Control Registers */
1507 for (i = 0; i < 7; i++) { 1659 for (i = 0; i < dev->n_ep; i++) {
1508 struct net2280_ep *ep; 1660 struct net2280_ep *ep;
1509 1661
1510 ep = &dev->ep [i]; 1662 ep = &dev->ep [i];
1511 if (i && !ep->desc) 1663 if (i && !ep->desc)
1512 continue; 1664 continue;
1513 1665
1514 t1 = readl (&ep->regs->ep_cfg); 1666 t1 = readl(&ep->cfg->ep_cfg);
1515 t2 = readl (&ep->regs->ep_rsp) & 0xff; 1667 t2 = readl (&ep->regs->ep_rsp) & 0xff;
1516 t = scnprintf (next, size, 1668 t = scnprintf (next, size,
1517 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s" 1669 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
@@ -1571,7 +1723,7 @@ static ssize_t registers_show(struct device *_dev,
1571 t = scnprintf (next, size, "\nirqs: "); 1723 t = scnprintf (next, size, "\nirqs: ");
1572 size -= t; 1724 size -= t;
1573 next += t; 1725 next += t;
1574 for (i = 0; i < 7; i++) { 1726 for (i = 0; i < dev->n_ep; i++) {
1575 struct net2280_ep *ep; 1727 struct net2280_ep *ep;
1576 1728
1577 ep = &dev->ep [i]; 1729 ep = &dev->ep [i];
@@ -1606,7 +1758,7 @@ static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1606 size = PAGE_SIZE; 1758 size = PAGE_SIZE;
1607 spin_lock_irqsave (&dev->lock, flags); 1759 spin_lock_irqsave (&dev->lock, flags);
1608 1760
1609 for (i = 0; i < 7; i++) { 1761 for (i = 0; i < dev->n_ep; i++) {
1610 struct net2280_ep *ep = &dev->ep [i]; 1762 struct net2280_ep *ep = &dev->ep [i];
1611 struct net2280_request *req; 1763 struct net2280_request *req;
1612 int t; 1764 int t;
@@ -1735,6 +1887,121 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1735 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1887 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1736} 1888}
1737 1889
1890static void defect7374_disable_data_eps(struct net2280 *dev)
1891{
1892 /*
1893 * For Defect 7374, disable data EPs (and more):
1894 * - This phase undoes the earlier phase of the Defect 7374 workaround,
1895 * returing ep regs back to normal.
1896 */
1897 struct net2280_ep *ep;
1898 int i;
1899 unsigned char ep_sel;
1900 u32 tmp_reg;
1901
1902 for (i = 1; i < 5; i++) {
1903 ep = &dev->ep[i];
1904 writel(0, &ep->cfg->ep_cfg);
1905 }
1906
1907 /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */
1908 for (i = 0; i < 6; i++)
1909 writel(0, &dev->dep[i].dep_cfg);
1910
1911 for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
1912 /* Select an endpoint for subsequent operations: */
1913 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1914 writel(((tmp_reg & ~0x1f) | ep_sel), &dev->plregs->pl_ep_ctrl);
1915
1916 if (ep_sel < 2 || (ep_sel > 9 && ep_sel < 14) ||
1917 ep_sel == 18 || ep_sel == 20)
1918 continue;
1919
1920 /* Change settings on some selected endpoints */
1921 tmp_reg = readl(&dev->plregs->pl_ep_cfg_4);
1922 tmp_reg &= ~(1 << NON_CTRL_IN_TOLERATE_BAD_DIR);
1923 writel(tmp_reg, &dev->plregs->pl_ep_cfg_4);
1924 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1925 tmp_reg |= (1 << EP_INITIALIZED);
1926 writel(tmp_reg, &dev->plregs->pl_ep_ctrl);
1927 }
1928}
1929
1930static void defect7374_enable_data_eps_zero(struct net2280 *dev)
1931{
1932 u32 tmp = 0, tmp_reg;
1933 u32 fsmvalue, scratch;
1934 int i;
1935 unsigned char ep_sel;
1936
1937 scratch = get_idx_reg(dev->regs, SCRATCH);
1938 fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
1939 scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
1940
1941 /*See if firmware needs to set up for workaround*/
1942 if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) {
1943 WARNING(dev, "Operate Defect 7374 workaround soft this time");
1944 WARNING(dev, "It will operate on cold-reboot and SS connect");
1945
1946 /*GPEPs:*/
1947 tmp = ((0 << ENDPOINT_NUMBER) | (1 << ENDPOINT_DIRECTION) |
1948 (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) |
1949 ((dev->enhanced_mode) ?
1950 1 << OUT_ENDPOINT_ENABLE : 1 << ENDPOINT_ENABLE) |
1951 (1 << IN_ENDPOINT_ENABLE));
1952
1953 for (i = 1; i < 5; i++)
1954 writel(tmp, &dev->ep[i].cfg->ep_cfg);
1955
1956 /* CSRIN, PCIIN, STATIN, RCIN*/
1957 tmp = ((0 << ENDPOINT_NUMBER) | (1 << ENDPOINT_ENABLE));
1958 writel(tmp, &dev->dep[1].dep_cfg);
1959 writel(tmp, &dev->dep[3].dep_cfg);
1960 writel(tmp, &dev->dep[4].dep_cfg);
1961 writel(tmp, &dev->dep[5].dep_cfg);
1962
1963 /*Implemented for development and debug.
1964 * Can be refined/tuned later.*/
1965 for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
1966 /* Select an endpoint for subsequent operations: */
1967 tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1968 writel(((tmp_reg & ~0x1f) | ep_sel),
1969 &dev->plregs->pl_ep_ctrl);
1970
1971 if (ep_sel == 1) {
1972 tmp =
1973 (readl(&dev->plregs->pl_ep_ctrl) |
1974 (1 << CLEAR_ACK_ERROR_CODE) | 0);
1975 writel(tmp, &dev->plregs->pl_ep_ctrl);
1976 continue;
1977 }
1978
1979 if (ep_sel == 0 || (ep_sel > 9 && ep_sel < 14) ||
1980 ep_sel == 18 || ep_sel == 20)
1981 continue;
1982
1983 tmp = (readl(&dev->plregs->pl_ep_cfg_4) |
1984 (1 << NON_CTRL_IN_TOLERATE_BAD_DIR) | 0);
1985 writel(tmp, &dev->plregs->pl_ep_cfg_4);
1986
1987 tmp = readl(&dev->plregs->pl_ep_ctrl) &
1988 ~(1 << EP_INITIALIZED);
1989 writel(tmp, &dev->plregs->pl_ep_ctrl);
1990
1991 }
1992
1993 /* Set FSM to focus on the first Control Read:
1994 * - Tip: Connection speed is known upon the first
1995 * setup request.*/
1996 scratch |= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ;
1997 set_idx_reg(dev->regs, SCRATCH, scratch);
1998
1999 } else{
2000 WARNING(dev, "Defect 7374 workaround soft will NOT operate");
2001 WARNING(dev, "It will operate on cold-reboot and SS connect");
2002 }
2003}
2004
1738/* keeping it simple: 2005/* keeping it simple:
1739 * - one bus driver, initted first; 2006 * - one bus driver, initted first;
1740 * - one function driver, initted second 2007 * - one function driver, initted second
@@ -1744,7 +2011,7 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1744 * perhaps to bind specific drivers to specific devices. 2011 * perhaps to bind specific drivers to specific devices.
1745 */ 2012 */
1746 2013
1747static void usb_reset (struct net2280 *dev) 2014static void usb_reset_228x(struct net2280 *dev)
1748{ 2015{
1749 u32 tmp; 2016 u32 tmp;
1750 2017
@@ -1760,11 +2027,11 @@ static void usb_reset (struct net2280 *dev)
1760 2027
1761 /* clear old dma and irq state */ 2028 /* clear old dma and irq state */
1762 for (tmp = 0; tmp < 4; tmp++) { 2029 for (tmp = 0; tmp < 4; tmp++) {
1763 struct net2280_ep *ep = &dev->ep [tmp + 1]; 2030 struct net2280_ep *ep = &dev->ep[tmp + 1];
1764
1765 if (ep->dma) 2031 if (ep->dma)
1766 abort_dma (ep); 2032 abort_dma(ep);
1767 } 2033 }
2034
1768 writel (~0, &dev->regs->irqstat0), 2035 writel (~0, &dev->regs->irqstat0),
1769 writel (~(1 << SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1), 2036 writel (~(1 << SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1),
1770 2037
@@ -1780,7 +2047,67 @@ static void usb_reset (struct net2280 *dev)
1780 set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0); 2047 set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0);
1781} 2048}
1782 2049
1783static void usb_reinit (struct net2280 *dev) 2050static void usb_reset_338x(struct net2280 *dev)
2051{
2052 u32 tmp;
2053 u32 fsmvalue;
2054
2055 dev->gadget.speed = USB_SPEED_UNKNOWN;
2056 (void)readl(&dev->usb->usbctl);
2057
2058 net2280_led_init(dev);
2059
2060 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2061 (0xf << DEFECT7374_FSM_FIELD);
2062
2063 /* See if firmware needs to set up for workaround: */
2064 if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) {
2065 INFO(dev, "%s: Defect 7374 FsmValue 0x%08X\n", __func__,
2066 fsmvalue);
2067 } else {
2068 /* disable automatic responses, and irqs */
2069 writel(0, &dev->usb->stdrsp);
2070 writel(0, &dev->regs->pciirqenb0);
2071 writel(0, &dev->regs->pciirqenb1);
2072 }
2073
2074 /* clear old dma and irq state */
2075 for (tmp = 0; tmp < 4; tmp++) {
2076 struct net2280_ep *ep = &dev->ep[tmp + 1];
2077
2078 if (ep->dma)
2079 abort_dma(ep);
2080 }
2081
2082 writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1);
2083
2084 if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) {
2085 /* reset, and enable pci */
2086 tmp = readl(&dev->regs->devinit) |
2087 (1 << PCI_ENABLE) |
2088 (1 << FIFO_SOFT_RESET) |
2089 (1 << USB_SOFT_RESET) |
2090 (1 << M8051_RESET);
2091
2092 writel(tmp, &dev->regs->devinit);
2093 }
2094
2095 /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */
2096 INIT_LIST_HEAD(&dev->gadget.ep_list);
2097
2098 for (tmp = 1; tmp < dev->n_ep; tmp++)
2099 list_add_tail(&dev->ep[tmp].ep.ep_list, &dev->gadget.ep_list);
2100
2101}
2102
2103static void usb_reset(struct net2280 *dev)
2104{
2105 if (dev->pdev->vendor == 0x17cc)
2106 return usb_reset_228x(dev);
2107 return usb_reset_338x(dev);
2108}
2109
2110static void usb_reinit_228x(struct net2280 *dev)
1784{ 2111{
1785 u32 tmp; 2112 u32 tmp;
1786 int init_dma; 2113 int init_dma;
@@ -1803,7 +2130,8 @@ static void usb_reinit (struct net2280 *dev)
1803 } else 2130 } else
1804 ep->fifo_size = 64; 2131 ep->fifo_size = 64;
1805 ep->regs = &dev->epregs [tmp]; 2132 ep->regs = &dev->epregs [tmp];
1806 ep_reset (dev->regs, ep); 2133 ep->cfg = &dev->epregs[tmp];
2134 ep_reset_228x(dev->regs, ep);
1807 } 2135 }
1808 usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64); 2136 usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64);
1809 usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64); 2137 usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64);
@@ -1820,7 +2148,122 @@ static void usb_reinit (struct net2280 *dev)
1820 writel (EP_DONTUSE, &dev->dep [tmp].dep_cfg); 2148 writel (EP_DONTUSE, &dev->dep [tmp].dep_cfg);
1821} 2149}
1822 2150
1823static void ep0_start (struct net2280 *dev) 2151static void usb_reinit_338x(struct net2280 *dev)
2152{
2153 int init_dma;
2154 int i;
2155 u32 tmp, val;
2156 u32 fsmvalue;
2157 static const u32 ne[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
2158 static const u32 ep_reg_addr[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00,
2159 0x00, 0xC0, 0x00, 0xC0 };
2160
2161 /* use_dma changes are ignored till next device re-init */
2162 init_dma = use_dma;
2163
2164 /* basic endpoint init */
2165 for (i = 0; i < dev->n_ep; i++) {
2166 struct net2280_ep *ep = &dev->ep[i];
2167
2168 ep->ep.name = ep_name[i];
2169 ep->dev = dev;
2170 ep->num = i;
2171
2172 if (i > 0 && i <= 4 && init_dma)
2173 ep->dma = &dev->dma[i - 1];
2174
2175 if (dev->enhanced_mode) {
2176 ep->cfg = &dev->epregs[ne[i]];
2177 ep->regs = (struct net2280_ep_regs __iomem *)
2178 (((void *)&dev->epregs[ne[i]]) +
2179 ep_reg_addr[i]);
2180 ep->fiforegs = &dev->fiforegs[i];
2181 } else {
2182 ep->cfg = &dev->epregs[i];
2183 ep->regs = &dev->epregs[i];
2184 ep->fiforegs = &dev->fiforegs[i];
2185 }
2186
2187 ep->fifo_size = (i != 0) ? 2048 : 512;
2188
2189 ep_reset_338x(dev->regs, ep);
2190 }
2191 usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 512);
2192
2193 dev->gadget.ep0 = &dev->ep[0].ep;
2194 dev->ep[0].stopped = 0;
2195
2196 /* Link layer set up */
2197 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2198 (0xf << DEFECT7374_FSM_FIELD);
2199
2200 /* See if driver needs to set up for workaround: */
2201 if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ)
2202 INFO(dev, "%s: Defect 7374 FsmValue %08x\n",
2203 __func__, fsmvalue);
2204 else {
2205 tmp = readl(&dev->usb_ext->usbctl2) &
2206 ~((1 << U1_ENABLE) | (1 << U2_ENABLE) | (1 << LTM_ENABLE));
2207 writel(tmp, &dev->usb_ext->usbctl2);
2208 }
2209
2210 /* Hardware Defect and Workaround */
2211 val = readl(&dev->ll_lfps_regs->ll_lfps_5);
2212 val &= ~(0xf << TIMER_LFPS_6US);
2213 val |= 0x5 << TIMER_LFPS_6US;
2214 writel(val, &dev->ll_lfps_regs->ll_lfps_5);
2215
2216 val = readl(&dev->ll_lfps_regs->ll_lfps_6);
2217 val &= ~(0xffff << TIMER_LFPS_80US);
2218 val |= 0x0100 << TIMER_LFPS_80US;
2219 writel(val, &dev->ll_lfps_regs->ll_lfps_6);
2220
2221 /*
2222 * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
2223 * Hot Reset Exit Handshake may Fail in Specific Case using
2224 * Default Register Settings. Workaround for Enumeration test.
2225 */
2226 val = readl(&dev->ll_tsn_regs->ll_tsn_counters_2);
2227 val &= ~(0x1f << HOT_TX_NORESET_TS2);
2228 val |= 0x10 << HOT_TX_NORESET_TS2;
2229 writel(val, &dev->ll_tsn_regs->ll_tsn_counters_2);
2230
2231 val = readl(&dev->ll_tsn_regs->ll_tsn_counters_3);
2232 val &= ~(0x1f << HOT_RX_RESET_TS2);
2233 val |= 0x3 << HOT_RX_RESET_TS2;
2234 writel(val, &dev->ll_tsn_regs->ll_tsn_counters_3);
2235
2236 /*
2237 * Set Recovery Idle to Recover bit:
2238 * - On SS connections, setting Recovery Idle to Recover Fmw improves
2239 * link robustness with various hosts and hubs.
2240 * - It is safe to set for all connection speeds; all chip revisions.
2241 * - R-M-W to leave other bits undisturbed.
2242 * - Reference PLX TT-7372
2243 */
2244 val = readl(&dev->ll_chicken_reg->ll_tsn_chicken_bit);
2245 val |= (1 << RECOVERY_IDLE_TO_RECOVER_FMW);
2246 writel(val, &dev->ll_chicken_reg->ll_tsn_chicken_bit);
2247
2248 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2249
2250 /* disable dedicated endpoints */
2251 writel(0x0D, &dev->dep[0].dep_cfg);
2252 writel(0x0D, &dev->dep[1].dep_cfg);
2253 writel(0x0E, &dev->dep[2].dep_cfg);
2254 writel(0x0E, &dev->dep[3].dep_cfg);
2255 writel(0x0F, &dev->dep[4].dep_cfg);
2256 writel(0x0C, &dev->dep[5].dep_cfg);
2257}
2258
2259static void usb_reinit(struct net2280 *dev)
2260{
2261 if (dev->pdev->vendor == 0x17cc)
2262 return usb_reinit_228x(dev);
2263 return usb_reinit_338x(dev);
2264}
2265
2266static void ep0_start_228x(struct net2280 *dev)
1824{ 2267{
1825 writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE) 2268 writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE)
1826 | (1 << CLEAR_NAK_OUT_PACKETS) 2269 | (1 << CLEAR_NAK_OUT_PACKETS)
@@ -1863,6 +2306,61 @@ static void ep0_start (struct net2280 *dev)
1863 (void) readl (&dev->usb->usbctl); 2306 (void) readl (&dev->usb->usbctl);
1864} 2307}
1865 2308
2309static void ep0_start_338x(struct net2280 *dev)
2310{
2311 u32 fsmvalue;
2312
2313 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2314 (0xf << DEFECT7374_FSM_FIELD);
2315
2316 if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ)
2317 INFO(dev, "%s: Defect 7374 FsmValue %08x\n", __func__,
2318 fsmvalue);
2319 else
2320 writel((1 << CLEAR_NAK_OUT_PACKETS_MODE) |
2321 (1 << SET_EP_HIDE_STATUS_PHASE),
2322 &dev->epregs[0].ep_rsp);
2323
2324 /*
2325 * hardware optionally handles a bunch of standard requests
2326 * that the API hides from drivers anyway. have it do so.
2327 * endpoint status/features are handled in software, to
2328 * help pass tests for some dubious behavior.
2329 */
2330 writel((1 << SET_ISOCHRONOUS_DELAY) |
2331 (1 << SET_SEL) |
2332 (1 << SET_TEST_MODE) |
2333 (1 << SET_ADDRESS) |
2334 (1 << GET_INTERFACE_STATUS) |
2335 (1 << GET_DEVICE_STATUS),
2336 &dev->usb->stdrsp);
2337 dev->wakeup_enable = 1;
2338 writel((1 << USB_ROOT_PORT_WAKEUP_ENABLE) |
2339 (dev->softconnect << USB_DETECT_ENABLE) |
2340 (1 << DEVICE_REMOTE_WAKEUP_ENABLE),
2341 &dev->usb->usbctl);
2342
2343 /* enable irqs so we can see ep0 and general operation */
2344 writel((1 << SETUP_PACKET_INTERRUPT_ENABLE) |
2345 (1 << ENDPOINT_0_INTERRUPT_ENABLE)
2346 , &dev->regs->pciirqenb0);
2347 writel((1 << PCI_INTERRUPT_ENABLE) |
2348 (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2349 (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) |
2350 (1 << VBUS_INTERRUPT_ENABLE),
2351 &dev->regs->pciirqenb1);
2352
2353 /* don't leave any writes posted */
2354 (void)readl(&dev->usb->usbctl);
2355}
2356
2357static void ep0_start(struct net2280 *dev)
2358{
2359 if (dev->pdev->vendor == 0x17cc)
2360 return ep0_start_228x(dev);
2361 return ep0_start_338x(dev);
2362}
2363
1866/* when a driver is successfully registered, it will receive 2364/* when a driver is successfully registered, it will receive
1867 * control requests including set_configuration(), which enables 2365 * control requests including set_configuration(), which enables
1868 * non-control requests. then usb traffic follows until a 2366 * non-control requests. then usb traffic follows until a
@@ -1886,7 +2384,7 @@ static int net2280_start(struct usb_gadget *_gadget,
1886 2384
1887 dev = container_of (_gadget, struct net2280, gadget); 2385 dev = container_of (_gadget, struct net2280, gadget);
1888 2386
1889 for (i = 0; i < 7; i++) 2387 for (i = 0; i < dev->n_ep; i++)
1890 dev->ep [i].irqs = 0; 2388 dev->ep [i].irqs = 0;
1891 2389
1892 /* hook up the driver ... */ 2390 /* hook up the driver ... */
@@ -1900,13 +2398,17 @@ static int net2280_start(struct usb_gadget *_gadget,
1900 if (retval) goto err_func; 2398 if (retval) goto err_func;
1901 2399
1902 /* Enable force-full-speed testing mode, if desired */ 2400 /* Enable force-full-speed testing mode, if desired */
1903 if (full_speed) 2401 if (full_speed && dev->pdev->vendor == 0x17cc)
1904 writel(1 << FORCE_FULL_SPEED_MODE, &dev->usb->xcvrdiag); 2402 writel(1 << FORCE_FULL_SPEED_MODE, &dev->usb->xcvrdiag);
1905 2403
1906 /* ... then enable host detection and ep0; and we're ready 2404 /* ... then enable host detection and ep0; and we're ready
1907 * for set_configuration as well as eventual disconnect. 2405 * for set_configuration as well as eventual disconnect.
1908 */ 2406 */
1909 net2280_led_active (dev, 1); 2407 net2280_led_active (dev, 1);
2408
2409 if (dev->pdev->vendor == 0x10b5)
2410 defect7374_enable_data_eps_zero(dev);
2411
1910 ep0_start (dev); 2412 ep0_start (dev);
1911 2413
1912 DEBUG (dev, "%s ready, usbctl %08x stdrsp %08x\n", 2414 DEBUG (dev, "%s ready, usbctl %08x stdrsp %08x\n",
@@ -1937,7 +2439,7 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
1937 * and kill any outstanding requests. 2439 * and kill any outstanding requests.
1938 */ 2440 */
1939 usb_reset (dev); 2441 usb_reset (dev);
1940 for (i = 0; i < 7; i++) 2442 for (i = 0; i < dev->n_ep; i++)
1941 nuke (&dev->ep [i]); 2443 nuke (&dev->ep [i]);
1942 2444
1943 /* report disconnect; the driver is already quiesced */ 2445 /* report disconnect; the driver is already quiesced */
@@ -1967,7 +2469,8 @@ static int net2280_stop(struct usb_gadget *_gadget,
1967 net2280_led_active (dev, 0); 2469 net2280_led_active (dev, 0);
1968 2470
1969 /* Disable full-speed test mode */ 2471 /* Disable full-speed test mode */
1970 writel(0, &dev->usb->xcvrdiag); 2472 if (dev->pdev->vendor == 0x17cc)
2473 writel(0, &dev->usb->xcvrdiag);
1971 2474
1972 device_remove_file (&dev->pdev->dev, &dev_attr_function); 2475 device_remove_file (&dev->pdev->dev, &dev_attr_function);
1973 device_remove_file (&dev->pdev->dev, &dev_attr_queues); 2476 device_remove_file (&dev->pdev->dev, &dev_attr_queues);
@@ -2219,6 +2722,350 @@ get_ep_by_addr (struct net2280 *dev, u16 wIndex)
2219 return NULL; 2722 return NULL;
2220} 2723}
2221 2724
2725static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r)
2726{
2727 u32 scratch, fsmvalue;
2728 u32 ack_wait_timeout, state;
2729
2730 /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */
2731 scratch = get_idx_reg(dev->regs, SCRATCH);
2732 fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
2733 scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
2734
2735 if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) &&
2736 (r.bRequestType & USB_DIR_IN)))
2737 return;
2738
2739 /* This is the first Control Read for this connection: */
2740 if (!(readl(&dev->usb->usbstat) & (1 << SUPER_SPEED_MODE))) {
2741 /*
2742 * Connection is NOT SS:
2743 * - Connection must be FS or HS.
2744 * - This FSM state should allow workaround software to
2745 * run after the next USB connection.
2746 */
2747 scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ;
2748 goto restore_data_eps;
2749 }
2750
2751 /* Connection is SS: */
2752 for (ack_wait_timeout = 0;
2753 ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS;
2754 ack_wait_timeout++) {
2755
2756 state = readl(&dev->plregs->pl_ep_status_1)
2757 & (0xff << STATE);
2758 if ((state >= (ACK_GOOD_NORMAL << STATE)) &&
2759 (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) {
2760 scratch |= DEFECT7374_FSM_SS_CONTROL_READ;
2761 break;
2762 }
2763
2764 /*
2765 * We have not yet received host's Data Phase ACK
2766 * - Wait and try again.
2767 */
2768 udelay(DEFECT_7374_PROCESSOR_WAIT_TIME);
2769
2770 continue;
2771 }
2772
2773
2774 if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) {
2775 ERROR(dev, "FAIL: Defect 7374 workaround waited but failed");
2776 ERROR(dev, "to detect SS host's data phase ACK.");
2777 ERROR(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16");
2778 ERROR(dev, "got 0x%2.2x.\n", state >> STATE);
2779 } else {
2780 WARNING(dev, "INFO: Defect 7374 workaround waited about\n");
2781 WARNING(dev, "%duSec for Control Read Data Phase ACK\n",
2782 DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout);
2783 }
2784
2785restore_data_eps:
2786 /*
2787 * Restore data EPs to their pre-workaround settings (disabled,
2788 * initialized, and other details).
2789 */
2790 defect7374_disable_data_eps(dev);
2791
2792 set_idx_reg(dev->regs, SCRATCH, scratch);
2793
2794 return;
2795}
2796
2797static void ep_stall(struct net2280_ep *ep, int stall)
2798{
2799 struct net2280 *dev = ep->dev;
2800 u32 val;
2801 static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 };
2802
2803 if (stall) {
2804 writel((1 << SET_ENDPOINT_HALT) |
2805 /* (1 << SET_NAK_PACKETS) | */
2806 (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE),
2807 &ep->regs->ep_rsp);
2808 ep->is_halt = 1;
2809 } else {
2810 if (dev->gadget.speed == USB_SPEED_SUPER) {
2811 /*
2812 * Workaround for SS SeqNum not cleared via
2813 * Endpoint Halt (Clear) bit. select endpoint
2814 */
2815 val = readl(&dev->plregs->pl_ep_ctrl);
2816 val = (val & ~0x1f) | ep_pl[ep->num];
2817 writel(val, &dev->plregs->pl_ep_ctrl);
2818
2819 val |= (1 << SEQUENCE_NUMBER_RESET);
2820 writel(val, &dev->plregs->pl_ep_ctrl);
2821 }
2822 val = readl(&ep->regs->ep_rsp);
2823 val |= (1 << CLEAR_ENDPOINT_HALT) |
2824 (1 << CLEAR_ENDPOINT_TOGGLE);
2825 writel(val
2826 /* | (1 << CLEAR_NAK_PACKETS)*/
2827 , &ep->regs->ep_rsp);
2828 ep->is_halt = 0;
2829 val = readl(&ep->regs->ep_rsp);
2830 }
2831}
2832
2833static void ep_stdrsp(struct net2280_ep *ep, int value, int wedged)
2834{
2835 /* set/clear, then synch memory views with the device */
2836 if (value) {
2837 ep->stopped = 1;
2838 if (ep->num == 0)
2839 ep->dev->protocol_stall = 1;
2840 else {
2841 if (ep->dma)
2842 ep_stop_dma(ep);
2843 ep_stall(ep, true);
2844 }
2845
2846 if (wedged)
2847 ep->wedged = 1;
2848 } else {
2849 ep->stopped = 0;
2850 ep->wedged = 0;
2851
2852 ep_stall(ep, false);
2853
2854 /* Flush the queue */
2855 if (!list_empty(&ep->queue)) {
2856 struct net2280_request *req =
2857 list_entry(ep->queue.next, struct net2280_request,
2858 queue);
2859 if (ep->dma)
2860 resume_dma(ep);
2861 else {
2862 if (ep->is_in)
2863 write_fifo(ep, &req->req);
2864 else {
2865 if (read_fifo(ep, req))
2866 done(ep, req, 0);
2867 }
2868 }
2869 }
2870 }
2871}
2872
2873static void handle_stat0_irqs_superspeed(struct net2280 *dev,
2874 struct net2280_ep *ep, struct usb_ctrlrequest r)
2875{
2876 int tmp = 0;
2877
2878#define w_value le16_to_cpu(r.wValue)
2879#define w_index le16_to_cpu(r.wIndex)
2880#define w_length le16_to_cpu(r.wLength)
2881
2882 switch (r.bRequest) {
2883 struct net2280_ep *e;
2884 u16 status;
2885
2886 case USB_REQ_SET_CONFIGURATION:
2887 dev->addressed_state = !w_value;
2888 goto usb3_delegate;
2889
2890 case USB_REQ_GET_STATUS:
2891 switch (r.bRequestType) {
2892 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2893 status = dev->wakeup_enable ? 0x02 : 0x00;
2894 if (dev->selfpowered)
2895 status |= 1 << 0;
2896 status |= (dev->u1_enable << 2 | dev->u2_enable << 3 |
2897 dev->ltm_enable << 4);
2898 writel(0, &dev->epregs[0].ep_irqenb);
2899 set_fifo_bytecount(ep, sizeof(status));
2900 writel((__force u32) status, &dev->epregs[0].ep_data);
2901 allow_status_338x(ep);
2902 break;
2903
2904 case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2905 e = get_ep_by_addr(dev, w_index);
2906 if (!e)
2907 goto do_stall3;
2908 status = readl(&e->regs->ep_rsp) &
2909 (1 << CLEAR_ENDPOINT_HALT);
2910 writel(0, &dev->epregs[0].ep_irqenb);
2911 set_fifo_bytecount(ep, sizeof(status));
2912 writel((__force u32) status, &dev->epregs[0].ep_data);
2913 allow_status_338x(ep);
2914 break;
2915
2916 default:
2917 goto usb3_delegate;
2918 }
2919 break;
2920
2921 case USB_REQ_CLEAR_FEATURE:
2922 switch (r.bRequestType) {
2923 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2924 if (!dev->addressed_state) {
2925 switch (w_value) {
2926 case USB_DEVICE_U1_ENABLE:
2927 dev->u1_enable = 0;
2928 writel(readl(&dev->usb_ext->usbctl2) &
2929 ~(1 << U1_ENABLE),
2930 &dev->usb_ext->usbctl2);
2931 allow_status_338x(ep);
2932 goto next_endpoints3;
2933
2934 case USB_DEVICE_U2_ENABLE:
2935 dev->u2_enable = 0;
2936 writel(readl(&dev->usb_ext->usbctl2) &
2937 ~(1 << U2_ENABLE),
2938 &dev->usb_ext->usbctl2);
2939 allow_status_338x(ep);
2940 goto next_endpoints3;
2941
2942 case USB_DEVICE_LTM_ENABLE:
2943 dev->ltm_enable = 0;
2944 writel(readl(&dev->usb_ext->usbctl2) &
2945 ~(1 << LTM_ENABLE),
2946 &dev->usb_ext->usbctl2);
2947 allow_status_338x(ep);
2948 goto next_endpoints3;
2949
2950 default:
2951 break;
2952 }
2953 }
2954 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
2955 dev->wakeup_enable = 0;
2956 writel(readl(&dev->usb->usbctl) &
2957 ~(1 << DEVICE_REMOTE_WAKEUP_ENABLE),
2958 &dev->usb->usbctl);
2959 allow_status_338x(ep);
2960 break;
2961 }
2962 goto usb3_delegate;
2963
2964 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2965 e = get_ep_by_addr(dev, w_index);
2966 if (!e)
2967 goto do_stall3;
2968 if (w_value != USB_ENDPOINT_HALT)
2969 goto do_stall3;
2970 VDEBUG(dev, "%s clear halt\n", e->ep.name);
2971 ep_stall(e, false);
2972 if (!list_empty(&e->queue) && e->td_dma)
2973 restart_dma(e);
2974 allow_status(ep);
2975 ep->stopped = 1;
2976 break;
2977
2978 default:
2979 goto usb3_delegate;
2980 }
2981 break;
2982 case USB_REQ_SET_FEATURE:
2983 switch (r.bRequestType) {
2984 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2985 if (!dev->addressed_state) {
2986 switch (w_value) {
2987 case USB_DEVICE_U1_ENABLE:
2988 dev->u1_enable = 1;
2989 writel(readl(&dev->usb_ext->usbctl2) |
2990 (1 << U1_ENABLE),
2991 &dev->usb_ext->usbctl2);
2992 allow_status_338x(ep);
2993 goto next_endpoints3;
2994
2995 case USB_DEVICE_U2_ENABLE:
2996 dev->u2_enable = 1;
2997 writel(readl(&dev->usb_ext->usbctl2) |
2998 (1 << U2_ENABLE),
2999 &dev->usb_ext->usbctl2);
3000 allow_status_338x(ep);
3001 goto next_endpoints3;
3002
3003 case USB_DEVICE_LTM_ENABLE:
3004 dev->ltm_enable = 1;
3005 writel(readl(&dev->usb_ext->usbctl2) |
3006 (1 << LTM_ENABLE),
3007 &dev->usb_ext->usbctl2);
3008 allow_status_338x(ep);
3009 goto next_endpoints3;
3010 default:
3011 break;
3012 }
3013 }
3014
3015 if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
3016 dev->wakeup_enable = 1;
3017 writel(readl(&dev->usb->usbctl) |
3018 (1 << DEVICE_REMOTE_WAKEUP_ENABLE),
3019 &dev->usb->usbctl);
3020 allow_status_338x(ep);
3021 break;
3022 }
3023 goto usb3_delegate;
3024
3025 case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
3026 e = get_ep_by_addr(dev, w_index);
3027 if (!e || (w_value != USB_ENDPOINT_HALT))
3028 goto do_stall3;
3029 ep_stdrsp(e, true, false);
3030 allow_status_338x(ep);
3031 break;
3032
3033 default:
3034 goto usb3_delegate;
3035 }
3036
3037 break;
3038 default:
3039
3040usb3_delegate:
3041 VDEBUG(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n",
3042 r.bRequestType, r.bRequest,
3043 w_value, w_index, w_length,
3044 readl(&ep->cfg->ep_cfg));
3045
3046 ep->responded = 0;
3047 spin_unlock(&dev->lock);
3048 tmp = dev->driver->setup(&dev->gadget, &r);
3049 spin_lock(&dev->lock);
3050 }
3051do_stall3:
3052 if (tmp < 0) {
3053 VDEBUG(dev, "req %02x.%02x protocol STALL; stat %d\n",
3054 r.bRequestType, r.bRequest, tmp);
3055 dev->protocol_stall = 1;
3056 /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */
3057 ep_stall(ep, true);
3058 }
3059
3060next_endpoints3:
3061
3062#undef w_value
3063#undef w_index
3064#undef w_length
3065
3066 return;
3067}
3068
2222static void handle_stat0_irqs (struct net2280 *dev, u32 stat) 3069static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2223{ 3070{
2224 struct net2280_ep *ep; 3071 struct net2280_ep *ep;
@@ -2240,10 +3087,20 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2240 struct net2280_request *req; 3087 struct net2280_request *req;
2241 3088
2242 if (dev->gadget.speed == USB_SPEED_UNKNOWN) { 3089 if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
2243 if (readl (&dev->usb->usbstat) & (1 << HIGH_SPEED)) 3090 u32 val = readl(&dev->usb->usbstat);
3091 if (val & (1 << SUPER_SPEED)) {
3092 dev->gadget.speed = USB_SPEED_SUPER;
3093 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3094 EP0_SS_MAX_PACKET_SIZE);
3095 } else if (val & (1 << HIGH_SPEED)) {
2244 dev->gadget.speed = USB_SPEED_HIGH; 3096 dev->gadget.speed = USB_SPEED_HIGH;
2245 else 3097 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3098 EP0_HS_MAX_PACKET_SIZE);
3099 } else {
2246 dev->gadget.speed = USB_SPEED_FULL; 3100 dev->gadget.speed = USB_SPEED_FULL;
3101 usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3102 EP0_HS_MAX_PACKET_SIZE);
3103 }
2247 net2280_led_speed (dev, dev->gadget.speed); 3104 net2280_led_speed (dev, dev->gadget.speed);
2248 DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed)); 3105 DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed));
2249 } 3106 }
@@ -2261,32 +3118,38 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2261 } 3118 }
2262 ep->stopped = 0; 3119 ep->stopped = 0;
2263 dev->protocol_stall = 0; 3120 dev->protocol_stall = 0;
2264 3121 if (dev->pdev->vendor == 0x10b5)
2265 if (ep->dev->pdev->device == 0x2280) 3122 ep->is_halt = 0;
2266 tmp = (1 << FIFO_OVERFLOW) 3123 else{
2267 | (1 << FIFO_UNDERFLOW); 3124 if (ep->dev->pdev->device == 0x2280)
2268 else 3125 tmp = (1 << FIFO_OVERFLOW) |
2269 tmp = 0; 3126 (1 << FIFO_UNDERFLOW);
2270 3127 else
2271 writel (tmp | (1 << TIMEOUT) 3128 tmp = 0;
2272 | (1 << USB_STALL_SENT) 3129
2273 | (1 << USB_IN_NAK_SENT) 3130 writel(tmp | (1 << TIMEOUT) |
2274 | (1 << USB_IN_ACK_RCVD) 3131 (1 << USB_STALL_SENT) |
2275 | (1 << USB_OUT_PING_NAK_SENT) 3132 (1 << USB_IN_NAK_SENT) |
2276 | (1 << USB_OUT_ACK_SENT) 3133 (1 << USB_IN_ACK_RCVD) |
2277 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) 3134 (1 << USB_OUT_PING_NAK_SENT) |
2278 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) 3135 (1 << USB_OUT_ACK_SENT) |
2279 | (1 << DATA_PACKET_RECEIVED_INTERRUPT) 3136 (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) |
2280 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) 3137 (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) |
2281 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT) 3138 (1 << DATA_PACKET_RECEIVED_INTERRUPT) |
2282 | (1 << DATA_IN_TOKEN_INTERRUPT) 3139 (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) |
2283 , &ep->regs->ep_stat); 3140 (1 << DATA_OUT_PING_TOKEN_INTERRUPT) |
2284 u.raw [0] = readl (&dev->usb->setup0123); 3141 (1 << DATA_IN_TOKEN_INTERRUPT)
2285 u.raw [1] = readl (&dev->usb->setup4567); 3142 , &ep->regs->ep_stat);
3143 }
3144 u.raw[0] = readl(&dev->usb->setup0123);
3145 u.raw[1] = readl(&dev->usb->setup4567);
2286 3146
2287 cpu_to_le32s (&u.raw [0]); 3147 cpu_to_le32s (&u.raw [0]);
2288 cpu_to_le32s (&u.raw [1]); 3148 cpu_to_le32s (&u.raw [1]);
2289 3149
3150 if (dev->pdev->vendor == 0x10b5)
3151 defect7374_workaround(dev, u.r);
3152
2290 tmp = 0; 3153 tmp = 0;
2291 3154
2292#define w_value le16_to_cpu(u.r.wValue) 3155#define w_value le16_to_cpu(u.r.wValue)
@@ -2318,6 +3181,12 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2318 * everything else goes uplevel to the gadget code. 3181 * everything else goes uplevel to the gadget code.
2319 */ 3182 */
2320 ep->responded = 1; 3183 ep->responded = 1;
3184
3185 if (dev->gadget.speed == USB_SPEED_SUPER) {
3186 handle_stat0_irqs_superspeed(dev, ep, u.r);
3187 goto next_endpoints;
3188 }
3189
2321 switch (u.r.bRequest) { 3190 switch (u.r.bRequest) {
2322 case USB_REQ_GET_STATUS: { 3191 case USB_REQ_GET_STATUS: {
2323 struct net2280_ep *e; 3192 struct net2280_ep *e;
@@ -2360,8 +3229,11 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2360 VDEBUG(dev, "%s wedged, halt not cleared\n", 3229 VDEBUG(dev, "%s wedged, halt not cleared\n",
2361 ep->ep.name); 3230 ep->ep.name);
2362 } else { 3231 } else {
2363 VDEBUG(dev, "%s clear halt\n", ep->ep.name); 3232 VDEBUG(dev, "%s clear halt\n", e->ep.name);
2364 clear_halt(e); 3233 clear_halt(e);
3234 if (ep->dev->pdev->vendor == 0x10b5 &&
3235 !list_empty(&e->queue) && e->td_dma)
3236 restart_dma(e);
2365 } 3237 }
2366 allow_status (ep); 3238 allow_status (ep);
2367 goto next_endpoints; 3239 goto next_endpoints;
@@ -2381,6 +3253,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2381 if (e->ep.name == ep0name) 3253 if (e->ep.name == ep0name)
2382 goto do_stall; 3254 goto do_stall;
2383 set_halt (e); 3255 set_halt (e);
3256 if (dev->pdev->vendor == 0x10b5 && e->dma)
3257 abort_dma(e);
2384 allow_status (ep); 3258 allow_status (ep);
2385 VDEBUG (dev, "%s set halt\n", ep->ep.name); 3259 VDEBUG (dev, "%s set halt\n", ep->ep.name);
2386 goto next_endpoints; 3260 goto next_endpoints;
@@ -2392,7 +3266,7 @@ delegate:
2392 "ep_cfg %08x\n", 3266 "ep_cfg %08x\n",
2393 u.r.bRequestType, u.r.bRequest, 3267 u.r.bRequestType, u.r.bRequest,
2394 w_value, w_index, w_length, 3268 w_value, w_index, w_length,
2395 readl (&ep->regs->ep_cfg)); 3269 readl(&ep->cfg->ep_cfg));
2396 ep->responded = 0; 3270 ep->responded = 0;
2397 spin_unlock (&dev->lock); 3271 spin_unlock (&dev->lock);
2398 tmp = dev->driver->setup (&dev->gadget, &u.r); 3272 tmp = dev->driver->setup (&dev->gadget, &u.r);
@@ -2455,7 +3329,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2455 3329
2456 /* after disconnect there's nothing else to do! */ 3330 /* after disconnect there's nothing else to do! */
2457 tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT); 3331 tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT);
2458 mask = (1 << HIGH_SPEED) | (1 << FULL_SPEED); 3332 mask = (1 << SUPER_SPEED) | (1 << HIGH_SPEED) | (1 << FULL_SPEED);
2459 3333
2460 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. 3334 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2461 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and 3335 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
@@ -2546,12 +3420,19 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2546 tmp = readl (&dma->dmastat); 3420 tmp = readl (&dma->dmastat);
2547 writel (tmp, &dma->dmastat); 3421 writel (tmp, &dma->dmastat);
2548 3422
3423 /* dma sync*/
3424 if (dev->pdev->vendor == 0x10b5) {
3425 u32 r_dmacount = readl(&dma->dmacount);
3426 if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
3427 (tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT)))
3428 continue;
3429 }
3430
2549 /* chaining should stop on abort, short OUT from fifo, 3431 /* chaining should stop on abort, short OUT from fifo,
2550 * or (stat0 codepath) short OUT transfer. 3432 * or (stat0 codepath) short OUT transfer.
2551 */ 3433 */
2552 if (!use_dma_chaining) { 3434 if (!use_dma_chaining) {
2553 if ((tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT)) 3435 if (!(tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT))) {
2554 == 0) {
2555 DEBUG (ep->dev, "%s no xact done? %08x\n", 3436 DEBUG (ep->dev, "%s no xact done? %08x\n",
2556 ep->ep.name, tmp); 3437 ep->ep.name, tmp);
2557 continue; 3438 continue;
@@ -2625,7 +3506,8 @@ static irqreturn_t net2280_irq (int irq, void *_dev)
2625 struct net2280 *dev = _dev; 3506 struct net2280 *dev = _dev;
2626 3507
2627 /* shared interrupt, not ours */ 3508 /* shared interrupt, not ours */
2628 if (!(readl(&dev->regs->irqstat0) & (1 << INTA_ASSERTED))) 3509 if (dev->pdev->vendor == 0x17cc &&
3510 (!(readl(&dev->regs->irqstat0) & (1 << INTA_ASSERTED))))
2629 return IRQ_NONE; 3511 return IRQ_NONE;
2630 3512
2631 spin_lock (&dev->lock); 3513 spin_lock (&dev->lock);
@@ -2636,6 +3518,13 @@ static irqreturn_t net2280_irq (int irq, void *_dev)
2636 /* control requests and PIO */ 3518 /* control requests and PIO */
2637 handle_stat0_irqs (dev, readl (&dev->regs->irqstat0)); 3519 handle_stat0_irqs (dev, readl (&dev->regs->irqstat0));
2638 3520
3521 if (dev->pdev->vendor == 0x10b5) {
3522 /* re-enable interrupt to trigger any possible new interrupt */
3523 u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
3524 writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
3525 writel(pciirqenb1, &dev->regs->pciirqenb1);
3526 }
3527
2639 spin_unlock (&dev->lock); 3528 spin_unlock (&dev->lock);
2640 3529
2641 return IRQ_HANDLED; 3530 return IRQ_HANDLED;
@@ -2674,6 +3563,8 @@ static void net2280_remove (struct pci_dev *pdev)
2674 } 3563 }
2675 if (dev->got_irq) 3564 if (dev->got_irq)
2676 free_irq (pdev->irq, dev); 3565 free_irq (pdev->irq, dev);
3566 if (use_msi && dev->pdev->vendor == 0x10b5)
3567 pci_disable_msi(pdev);
2677 if (dev->regs) 3568 if (dev->regs)
2678 iounmap (dev->regs); 3569 iounmap (dev->regs);
2679 if (dev->region) 3570 if (dev->region)
@@ -2708,7 +3599,8 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2708 spin_lock_init (&dev->lock); 3599 spin_lock_init (&dev->lock);
2709 dev->pdev = pdev; 3600 dev->pdev = pdev;
2710 dev->gadget.ops = &net2280_ops; 3601 dev->gadget.ops = &net2280_ops;
2711 dev->gadget.max_speed = USB_SPEED_HIGH; 3602 dev->gadget.max_speed = (dev->pdev->vendor == 0x10b5) ?
3603 USB_SPEED_SUPER : USB_SPEED_HIGH;
2712 3604
2713 /* the "gadget" abstracts/virtualizes the controller */ 3605 /* the "gadget" abstracts/virtualizes the controller */
2714 dev->gadget.name = driver_name; 3606 dev->gadget.name = driver_name;
@@ -2750,8 +3642,39 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2750 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200); 3642 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
2751 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300); 3643 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
2752 3644
2753 /* put into initial config, link up all endpoints */ 3645 if (dev->pdev->vendor == 0x10b5) {
2754 writel (0, &dev->usb->usbctl); 3646 u32 fsmvalue;
3647 u32 usbstat;
3648 dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
3649 (base + 0x00b4);
3650 dev->fiforegs = (struct usb338x_fifo_regs __iomem *)
3651 (base + 0x0500);
3652 dev->llregs = (struct usb338x_ll_regs __iomem *)
3653 (base + 0x0700);
3654 dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *)
3655 (base + 0x0748);
3656 dev->ll_tsn_regs = (struct usb338x_ll_tsn_regs __iomem *)
3657 (base + 0x077c);
3658 dev->ll_chicken_reg = (struct usb338x_ll_chi_regs __iomem *)
3659 (base + 0x079c);
3660 dev->plregs = (struct usb338x_pl_regs __iomem *)
3661 (base + 0x0800);
3662 usbstat = readl(&dev->usb->usbstat);
3663 dev->enhanced_mode = (usbstat & (1 << 11)) ? 1 : 0;
3664 dev->n_ep = (dev->enhanced_mode) ? 9 : 5;
3665 /* put into initial config, link up all endpoints */
3666 fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
3667 (0xf << DEFECT7374_FSM_FIELD);
3668 /* See if firmware needs to set up for workaround: */
3669 if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ)
3670 writel(0, &dev->usb->usbctl);
3671 } else{
3672 dev->enhanced_mode = 0;
3673 dev->n_ep = 7;
3674 /* put into initial config, link up all endpoints */
3675 writel(0, &dev->usb->usbctl);
3676 }
3677
2755 usb_reset (dev); 3678 usb_reset (dev);
2756 usb_reinit (dev); 3679 usb_reinit (dev);
2757 3680
@@ -2762,6 +3685,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2762 goto done; 3685 goto done;
2763 } 3686 }
2764 3687
3688 if (use_msi && dev->pdev->vendor == 0x10b5)
3689 if (pci_enable_msi(pdev))
3690 ERROR(dev, "Failed to enable MSI mode\n");
3691
2765 if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev) 3692 if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev)
2766 != 0) { 3693 != 0) {
2767 ERROR (dev, "request interrupt %d failed\n", pdev->irq); 3694 ERROR (dev, "request interrupt %d failed\n", pdev->irq);
@@ -2797,7 +3724,8 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2797 } 3724 }
2798 3725
2799 /* enable lower-overhead pci memory bursts during DMA */ 3726 /* enable lower-overhead pci memory bursts during DMA */
2800 writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) 3727 if (dev->pdev->vendor == 0x17cc)
3728 writel((1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE)
2801 // 256 write retries may not be enough... 3729 // 256 write retries may not be enough...
2802 // | (1 << PCI_RETRY_ABORT_ENABLE) 3730 // | (1 << PCI_RETRY_ABORT_ENABLE)
2803 | (1 << DMA_READ_MULTIPLE_ENABLE) 3731 | (1 << DMA_READ_MULTIPLE_ENABLE)
@@ -2814,10 +3742,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2814 INFO (dev, "%s\n", driver_desc); 3742 INFO (dev, "%s\n", driver_desc);
2815 INFO (dev, "irq %d, pci mem %p, chip rev %04x\n", 3743 INFO (dev, "irq %d, pci mem %p, chip rev %04x\n",
2816 pdev->irq, base, dev->chiprev); 3744 pdev->irq, base, dev->chiprev);
2817 INFO (dev, "version: " DRIVER_VERSION "; dma %s\n", 3745 INFO(dev, "version: " DRIVER_VERSION "; dma %s %s\n",
2818 use_dma 3746 use_dma ? (use_dma_chaining ? "chaining" : "enabled")
2819 ? (use_dma_chaining ? "chaining" : "enabled") 3747 : "disabled",
2820 : "disabled"); 3748 dev->enhanced_mode ? "enhanced mode" : "legacy mode");
2821 retval = device_create_file (&pdev->dev, &dev_attr_registers); 3749 retval = device_create_file (&pdev->dev, &dev_attr_registers);
2822 if (retval) goto done; 3750 if (retval) goto done;
2823 3751
@@ -2849,7 +3777,8 @@ static void net2280_shutdown (struct pci_dev *pdev)
2849 writel (0, &dev->usb->usbctl); 3777 writel (0, &dev->usb->usbctl);
2850 3778
2851 /* Disable full-speed test mode */ 3779 /* Disable full-speed test mode */
2852 writel(0, &dev->usb->xcvrdiag); 3780 if (dev->pdev->vendor == 0x17cc)
3781 writel(0, &dev->usb->xcvrdiag);
2853} 3782}
2854 3783
2855 3784
@@ -2869,8 +3798,24 @@ static const struct pci_device_id pci_ids [] = { {
2869 .device = 0x2282, 3798 .device = 0x2282,
2870 .subvendor = PCI_ANY_ID, 3799 .subvendor = PCI_ANY_ID,
2871 .subdevice = PCI_ANY_ID, 3800 .subdevice = PCI_ANY_ID,
2872 3801},
2873}, { /* end: all zeroes */ } 3802 {
3803 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3804 .class_mask = ~0,
3805 .vendor = 0x10b5,
3806 .device = 0x3380,
3807 .subvendor = PCI_ANY_ID,
3808 .subdevice = PCI_ANY_ID,
3809 },
3810 {
3811 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3812 .class_mask = ~0,
3813 .vendor = 0x10b5,
3814 .device = 0x3382,
3815 .subvendor = PCI_ANY_ID,
3816 .subdevice = PCI_ANY_ID,
3817 },
3818{ /* end: all zeroes */ }
2874}; 3819};
2875MODULE_DEVICE_TABLE (pci, pci_ids); 3820MODULE_DEVICE_TABLE (pci, pci_ids);
2876 3821
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h
index a844be0d683a..f32c2746b6ae 100644
--- a/drivers/usb/gadget/net2280.h
+++ b/drivers/usb/gadget/net2280.h
@@ -6,6 +6,7 @@
6/* 6/*
7 * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com) 7 * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
8 * Copyright (C) 2003 David Brownell 8 * Copyright (C) 2003 David Brownell
9 * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
@@ -14,6 +15,7 @@
14 */ 15 */
15 16
16#include <linux/usb/net2280.h> 17#include <linux/usb/net2280.h>
18#include <linux/usb/usb338x.h>
17 19
18/*-------------------------------------------------------------------------*/ 20/*-------------------------------------------------------------------------*/
19 21
@@ -59,6 +61,13 @@ set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
59#define CHIPREV_1 0x0100 61#define CHIPREV_1 0x0100
60#define CHIPREV_1A 0x0110 62#define CHIPREV_1A 0x0110
61 63
64/* DEFECT 7374 */
65#define DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS 200
66#define DEFECT_7374_PROCESSOR_WAIT_TIME 10
67
68/* ep0 max packet size */
69#define EP0_SS_MAX_PACKET_SIZE 0x200
70#define EP0_HS_MAX_PACKET_SIZE 0x40
62#ifdef __KERNEL__ 71#ifdef __KERNEL__
63 72
64/* ep a-f highspeed and fullspeed maxpacket, addresses 73/* ep a-f highspeed and fullspeed maxpacket, addresses
@@ -85,12 +94,15 @@ struct net2280_dma {
85 94
86struct net2280_ep { 95struct net2280_ep {
87 struct usb_ep ep; 96 struct usb_ep ep;
97 struct net2280_ep_regs __iomem *cfg;
88 struct net2280_ep_regs __iomem *regs; 98 struct net2280_ep_regs __iomem *regs;
89 struct net2280_dma_regs __iomem *dma; 99 struct net2280_dma_regs __iomem *dma;
90 struct net2280_dma *dummy; 100 struct net2280_dma *dummy;
101 struct usb338x_fifo_regs __iomem *fiforegs;
91 dma_addr_t td_dma; /* of dummy */ 102 dma_addr_t td_dma; /* of dummy */
92 struct net2280 *dev; 103 struct net2280 *dev;
93 unsigned long irqs; 104 unsigned long irqs;
105 unsigned is_halt:1, dma_started:1;
94 106
95 /* analogous to a host-side qh */ 107 /* analogous to a host-side qh */
96 struct list_head queue; 108 struct list_head queue;
@@ -116,10 +128,19 @@ static inline void allow_status (struct net2280_ep *ep)
116 ep->stopped = 1; 128 ep->stopped = 1;
117} 129}
118 130
119/* count (<= 4) bytes in the next fifo write will be valid */ 131static void allow_status_338x(struct net2280_ep *ep)
120static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
121{ 132{
122 writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg); 133 /*
134 * Control Status Phase Handshake was set by the chip when the setup
135 * packet arrived. While set, the chip automatically NAKs the host's
136 * Status Phase tokens.
137 */
138 writel(1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE, &ep->regs->ep_rsp);
139
140 ep->stopped = 1;
141
142 /* TD 9.9 Halt Endpoint test. TD 9.22 set feature test. */
143 ep->responded = 0;
123} 144}
124 145
125struct net2280_request { 146struct net2280_request {
@@ -135,23 +156,38 @@ struct net2280 {
135 /* each pci device provides one gadget, several endpoints */ 156 /* each pci device provides one gadget, several endpoints */
136 struct usb_gadget gadget; 157 struct usb_gadget gadget;
137 spinlock_t lock; 158 spinlock_t lock;
138 struct net2280_ep ep [7]; 159 struct net2280_ep ep[9];
139 struct usb_gadget_driver *driver; 160 struct usb_gadget_driver *driver;
140 unsigned enabled : 1, 161 unsigned enabled : 1,
141 protocol_stall : 1, 162 protocol_stall : 1,
142 softconnect : 1, 163 softconnect : 1,
143 got_irq : 1, 164 got_irq : 1,
144 region : 1; 165 region:1,
166 u1_enable:1,
167 u2_enable:1,
168 ltm_enable:1,
169 wakeup_enable:1,
170 selfpowered:1,
171 addressed_state:1;
145 u16 chiprev; 172 u16 chiprev;
173 int enhanced_mode;
174 int n_ep;
146 175
147 /* pci state used to access those endpoints */ 176 /* pci state used to access those endpoints */
148 struct pci_dev *pdev; 177 struct pci_dev *pdev;
149 struct net2280_regs __iomem *regs; 178 struct net2280_regs __iomem *regs;
150 struct net2280_usb_regs __iomem *usb; 179 struct net2280_usb_regs __iomem *usb;
180 struct usb338x_usb_ext_regs __iomem *usb_ext;
151 struct net2280_pci_regs __iomem *pci; 181 struct net2280_pci_regs __iomem *pci;
152 struct net2280_dma_regs __iomem *dma; 182 struct net2280_dma_regs __iomem *dma;
153 struct net2280_dep_regs __iomem *dep; 183 struct net2280_dep_regs __iomem *dep;
154 struct net2280_ep_regs __iomem *epregs; 184 struct net2280_ep_regs __iomem *epregs;
185 struct usb338x_fifo_regs __iomem *fiforegs;
186 struct usb338x_ll_regs __iomem *llregs;
187 struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs;
188 struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs;
189 struct usb338x_ll_chi_regs __iomem *ll_chicken_reg;
190 struct usb338x_pl_regs __iomem *plregs;
155 191
156 struct pci_pool *requests; 192 struct pci_pool *requests;
157 // statistics... 193 // statistics...
@@ -179,6 +215,43 @@ static inline void clear_halt (struct net2280_ep *ep)
179 , &ep->regs->ep_rsp); 215 , &ep->regs->ep_rsp);
180} 216}
181 217
218/*
219 * FSM value for Defect 7374 (U1U2 Test) is managed in
220 * chip's SCRATCH register:
221 */
222#define DEFECT7374_FSM_FIELD 28
223
224/* Waiting for Control Read:
225 * - A transition to this state indicates a fresh USB connection,
226 * before the first Setup Packet. The connection speed is not
227 * known. Firmware is waiting for the first Control Read.
228 * - Starting state: This state can be thought of as the FSM's typical
229 * starting state.
230 * - Tip: Upon the first SS Control Read the FSM never
231 * returns to this state.
232 */
233#define DEFECT7374_FSM_WAITING_FOR_CONTROL_READ (1 << DEFECT7374_FSM_FIELD)
234
235/* Non-SS Control Read:
236 * - A transition to this state indicates detection of the first HS
237 * or FS Control Read.
238 * - Tip: Upon the first SS Control Read the FSM never
239 * returns to this state.
240 */
241#define DEFECT7374_FSM_NON_SS_CONTROL_READ (2 << DEFECT7374_FSM_FIELD)
242
243/* SS Control Read:
244 * - A transition to this state indicates detection of the
245 * first SS Control Read.
246 * - This state indicates workaround completion. Workarounds no longer
247 * need to be applied (as long as the chip remains powered up).
248 * - Tip: Once in this state the FSM state does not change (until
249 * the chip's power is lost and restored).
250 * - This can be thought of as the final state of the FSM;
251 * the FSM 'locks-up' in this state until the chip loses power.
252 */
253#define DEFECT7374_FSM_SS_CONTROL_READ (3 << DEFECT7374_FSM_FIELD)
254
182#ifdef USE_RDK_LEDS 255#ifdef USE_RDK_LEDS
183 256
184static inline void net2280_led_init (struct net2280 *dev) 257static inline void net2280_led_init (struct net2280 *dev)
@@ -198,6 +271,9 @@ void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
198{ 271{
199 u32 val = readl (&dev->regs->gpioctl); 272 u32 val = readl (&dev->regs->gpioctl);
200 switch (speed) { 273 switch (speed) {
274 case USB_SPEED_SUPER: /* green + red */
275 val |= (1 << GPIO0_DATA) | (1 << GPIO1_DATA);
276 break;
201 case USB_SPEED_HIGH: /* green */ 277 case USB_SPEED_HIGH: /* green */
202 val &= ~(1 << GPIO0_DATA); 278 val &= ~(1 << GPIO0_DATA);
203 val |= (1 << GPIO1_DATA); 279 val |= (1 << GPIO1_DATA);
@@ -271,6 +347,17 @@ static inline void net2280_led_shutdown (struct net2280 *dev)
271 347
272/*-------------------------------------------------------------------------*/ 348/*-------------------------------------------------------------------------*/
273 349
350static inline void set_fifo_bytecount(struct net2280_ep *ep, unsigned count)
351{
352 if (ep->dev->pdev->vendor == 0x17cc)
353 writeb(count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
354 else{
355 u32 tmp = readl(&ep->cfg->ep_cfg) &
356 (~(0x07 << EP_FIFO_BYTE_COUNT));
357 writel(tmp | (count << EP_FIFO_BYTE_COUNT), &ep->cfg->ep_cfg);
358 }
359}
360
274static inline void start_out_naking (struct net2280_ep *ep) 361static inline void start_out_naking (struct net2280_ep *ep)
275{ 362{
276 /* NOTE: hardware races lurk here, and PING protocol issues */ 363 /* NOTE: hardware races lurk here, and PING protocol issues */
diff --git a/include/linux/usb/usb338x.h b/include/linux/usb/usb338x.h
new file mode 100644
index 000000000000..f92eb635b9d3
--- /dev/null
+++ b/include/linux/usb/usb338x.h
@@ -0,0 +1,199 @@
1/*
2 * USB 338x super/high/full speed USB device controller.
3 * Unlike many such controllers, this one talks PCI.
4 *
5 * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
6 * Copyright (C) 2003 David Brownell
7 * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#ifndef __LINUX_USB_USB338X_H
22#define __LINUX_USB_USB338X_H
23
24#include <linux/usb/net2280.h>
25
26/*
27 * Extra defined bits for net2280 registers
28 */
29#define SCRATCH 0x0b
30
31#define DEFECT7374_FSM_FIELD 28
32#define SUPER_SPEED 8
33#define DMA_REQUEST_OUTSTANDING 5
34#define DMA_PAUSE_DONE_INTERRUPT 26
35#define SET_ISOCHRONOUS_DELAY 24
36#define SET_SEL 22
37#define SUPER_SPEED_MODE 8
38
39/*ep_cfg*/
40#define MAX_BURST_SIZE 24
41#define EP_FIFO_BYTE_COUNT 16
42#define IN_ENDPOINT_ENABLE 14
43#define IN_ENDPOINT_TYPE 12
44#define OUT_ENDPOINT_ENABLE 10
45#define OUT_ENDPOINT_TYPE 8
46
47struct usb338x_usb_ext_regs {
48 u32 usbclass;
49#define DEVICE_PROTOCOL 16
50#define DEVICE_SUB_CLASS 8
51#define DEVICE_CLASS 0
52 u32 ss_sel;
53#define U2_SYSTEM_EXIT_LATENCY 8
54#define U1_SYSTEM_EXIT_LATENCY 0
55 u32 ss_del;
56#define U2_DEVICE_EXIT_LATENCY 8
57#define U1_DEVICE_EXIT_LATENCY 0
58 u32 usb2lpm;
59#define USB_L1_LPM_HIRD 2
60#define USB_L1_LPM_REMOTE_WAKE 1
61#define USB_L1_LPM_SUPPORT 0
62 u32 usb3belt;
63#define BELT_MULTIPLIER 10
64#define BEST_EFFORT_LATENCY_TOLERANCE 0
65 u32 usbctl2;
66#define LTM_ENABLE 7
67#define U2_ENABLE 6
68#define U1_ENABLE 5
69#define FUNCTION_SUSPEND 4
70#define USB3_CORE_ENABLE 3
71#define USB2_CORE_ENABLE 2
72#define SERIAL_NUMBER_STRING_ENABLE 0
73 u32 in_timeout;
74#define GPEP3_TIMEOUT 19
75#define GPEP2_TIMEOUT 18
76#define GPEP1_TIMEOUT 17
77#define GPEP0_TIMEOUT 16
78#define GPEP3_TIMEOUT_VALUE 13
79#define GPEP3_TIMEOUT_ENABLE 12
80#define GPEP2_TIMEOUT_VALUE 9
81#define GPEP2_TIMEOUT_ENABLE 8
82#define GPEP1_TIMEOUT_VALUE 5
83#define GPEP1_TIMEOUT_ENABLE 4
84#define GPEP0_TIMEOUT_VALUE 1
85#define GPEP0_TIMEOUT_ENABLE 0
86 u32 isodelay;
87#define ISOCHRONOUS_DELAY 0
88} __packed;
89
90struct usb338x_fifo_regs {
91 /* offset 0x0500, 0x0520, 0x0540, 0x0560, 0x0580 */
92 u32 ep_fifo_size_base;
93#define IN_FIFO_BASE_ADDRESS 22
94#define IN_FIFO_SIZE 16
95#define OUT_FIFO_BASE_ADDRESS 6
96#define OUT_FIFO_SIZE 0
97 u32 ep_fifo_out_wrptr;
98 u32 ep_fifo_out_rdptr;
99 u32 ep_fifo_in_wrptr;
100 u32 ep_fifo_in_rdptr;
101 u32 unused[3];
102} __packed;
103
104
105/* Link layer */
106struct usb338x_ll_regs {
107 /* offset 0x700 */
108 u32 ll_ltssm_ctrl1;
109 u32 ll_ltssm_ctrl2;
110 u32 ll_ltssm_ctrl3;
111 u32 unused[2];
112 u32 ll_general_ctrl0;
113 u32 ll_general_ctrl1;
114#define PM_U3_AUTO_EXIT 29
115#define PM_U2_AUTO_EXIT 28
116#define PM_U1_AUTO_EXIT 27
117#define PM_FORCE_U2_ENTRY 26
118#define PM_FORCE_U1_ENTRY 25
119#define PM_LGO_COLLISION_SEND_LAU 24
120#define PM_DIR_LINK_REJECT 23
121#define PM_FORCE_LINK_ACCEPT 22
122#define PM_DIR_ENTRY_U3 20
123#define PM_DIR_ENTRY_U2 19
124#define PM_DIR_ENTRY_U1 18
125#define PM_U2_ENABLE 17
126#define PM_U1_ENABLE 16
127#define SKP_THRESHOLD_ADJUST_FMW 8
128#define RESEND_DPP_ON_LRTY_FMW 7
129#define DL_BIT_VALUE_FMW 6
130#define FORCE_DL_BIT 5
131 u32 ll_general_ctrl2;
132#define SELECT_INVERT_LANE_POLARITY 7
133#define FORCE_INVERT_LANE_POLARITY 6
134 u32 ll_general_ctrl3;
135 u32 ll_general_ctrl4;
136 u32 ll_error_gen;
137} __packed;
138
139struct usb338x_ll_lfps_regs {
140 /* offset 0x748 */
141 u32 ll_lfps_5;
142#define TIMER_LFPS_6US 16
143 u32 ll_lfps_6;
144#define TIMER_LFPS_80US 0
145} __packed;
146
147struct usb338x_ll_tsn_regs {
148 /* offset 0x77C */
149 u32 ll_tsn_counters_2;
150#define HOT_TX_NORESET_TS2 24
151 u32 ll_tsn_counters_3;
152#define HOT_RX_RESET_TS2 0
153} __packed;
154
155struct usb338x_ll_chi_regs {
156 /* offset 0x79C */
157 u32 ll_tsn_chicken_bit;
158#define RECOVERY_IDLE_TO_RECOVER_FMW 3
159} __packed;
160
161/* protocol layer */
162struct usb338x_pl_regs {
163 /* offset 0x800 */
164 u32 pl_reg_1;
165 u32 pl_reg_2;
166 u32 pl_reg_3;
167 u32 pl_reg_4;
168 u32 pl_ep_ctrl;
169 /* Protocol Layer Endpoint Control*/
170#define PL_EP_CTRL 0x810
171#define ENDPOINT_SELECT 0
172 /* [4:0] */
173#define EP_INITIALIZED 16
174#define SEQUENCE_NUMBER_RESET 17
175#define CLEAR_ACK_ERROR_CODE 20
176 u32 pl_reg_6;
177 u32 pl_reg_7;
178 u32 pl_reg_8;
179 u32 pl_ep_status_1;
180 /* Protocol Layer Endpoint Status 1*/
181#define PL_EP_STATUS_1 0x820
182#define STATE 16
183#define ACK_GOOD_NORMAL 0x11
184#define ACK_GOOD_MORE_ACKS_TO_COME 0x16
185 u32 pl_ep_status_2;
186 u32 pl_ep_status_3;
187 /* Protocol Layer Endpoint Status 3*/
188#define PL_EP_STATUS_3 0x828
189#define SEQUENCE_NUMBER 0
190 u32 pl_ep_status_4;
191 /* Protocol Layer Endpoint Status 4*/
192#define PL_EP_STATUS_4 0x82c
193 u32 pl_ep_cfg_4;
194 /* Protocol Layer Endpoint Configuration 4*/
195#define PL_EP_CFG_4 0x830
196#define NON_CTRL_IN_TOLERATE_BAD_DIR 6
197} __packed;
198
199#endif /* __LINUX_USB_USB338X_H */