Commit Graph

1002 Commits

Author SHA1 Message Date
Felipe Balbi c5ac6116db usb: dwc3: core: add dwc3_get_properties()
This helper will be responsible for reading and
parsing our properties. No functional changes in
this patch, cleanup only.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:35 +02:00
Felipe Balbi 3b2733227f usb: dwc3: core: remove unnecessary alignment
Kernel will give us page aligned memory anyway.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:34 +02:00
Felipe Balbi 941f918ecf usb: dwc3: core: introduce dwc3_core_setup_global_control()
This little helper will be used to setup anything
related to GCTL register. There are no functional
changes, this is a cleanup only patch.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:34 +02:00
Felipe Balbi 0759956f8a usb: dwc3: core: introduce dwc3_core_is_valid()
This little helper will be used to make sure we're
dealing with a valid Synopsys DWC3 or DWC3.1 core.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:34 +02:00
John Youn 0bb39ca1ad usb: dwc3: Add support for device L1 exit
For the usb31 IP and from version 2.90a of the usb3 IP, the core
supports HW exit from L1 in HS. Enable it, otherwise the controller may
never exit from LPM to do a transfer.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:33 +02:00
Lu Baolu f9d2f9228c usb: dwc3: remove unused struct member dwc3->mem
Member @mem in struct dwc3 is not used in any places. Clean up it.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:33 +02:00
Felipe Balbi 0a695d4c75 usb: dwc3: gadget: never ever kill the machine
We should never kill the machine just because some
USB endpoint type is wrong. WARN about it and move
on.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:32 +02:00
Felipe Balbi c9508c8c50 usb: dwc3: gadget: only interrupt on short if short_not_ok is set
We don't need to know about short packets unless
gadget driver told us it's not ok to see them on the
bus. In the normal situation we can continue
processing the list of requests if we get a Short
packet.

Also, note that we're making sure ISP is only set
for OUT endpoints, where that setting is valid.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:32 +02:00
Felipe Balbi 58f29034b4 usb: dwc3: gadget: CSP is only valid for OUT endpoints
CSP bit is only valid for OUT endpoints. Synopsys
databook is unclear if HW ignores CSP for IN
endpoints (chances are, it does) but to avoid
problems, let's make sure to set CSP only when valid
to do so.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:32 +02:00
Felipe Balbi b9bd138e06 usb: dwc3: gadget: remove unused 'first_trb_index'
Recent changes have turned this field obsolete. Remove it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:31 +02:00
Felipe Balbi 39e07ffb1c usb: dwc3: ep0: simplify dwc3_ep0_handle_feature()
By extracting smaller functions from
dwc3_ep0_handle_feature(), it becomes far easier to
understand what's going on. Cleanup only, no
functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:31 +02:00
Felipe Balbi 6d729a55cc usb: dwc3: host: extract dwc3_host_get_irq()
Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:31 +02:00
Felipe Balbi 6db3812e09 usb: dwc3: gadget: extract dwc3_gadget_get_irq()
Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:30 +02:00
Felipe Balbi 4dd5a69e49 usb: dwc3: trace: add a proper tracepoint for reg accessors
We want to reduce the usage of dwc3_trace() in favor
of proper tracepoints which can be enabled/disabled
by the user. Let's start with our register
accessors.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:30 +02:00
Felipe Balbi ba1773fb7d usb: dwc3: Kconfig: allow all glues to build if COMPILE_TEST
We shouldn't have any glue layer which doesn't
compile everywhere. In order to make sure this is
always the case, make sure COMPILE_TEST is properly
added at dependency list of a config entry.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:30 +02:00
Felipe Balbi 57b14da562 usb: dwc3: don't compile dwc3_trace() unless CONFIG_FTRACE=y
We don't need dwc3_trace() unless we're building a
kernel with CONFIG_FTRACE. This patch reduces
dwc3.ko text size a bit while also removing overhead
of dwc3_trace() calls.

   text    data     bss     dec     hex filename
  50796     581       0   51377    c8b1 drivers/usb/dwc3/dwc3.o
  43961     581       0   44542    adfe drivers/usb/dwc3/dwc3.o.patched

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:29 +02:00
Felipe Balbi a97ea99460 usb: dwc3: gadget: offset Start Transfer latency for bulk EPs
We can offset the latency of a full Start Transfer
command - where we _must_ poll for its completion -
to usb_ep_enable() time. This means that once
requests start showing up from the gadget driver, we
can rely on No Response Update Transfer command -
where we don't need to poll for completion.

This patch, starts implementing this method for Bulk
endpoints, even though, technically, we could extend
it to all other endpoints in future commits.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:29 +02:00
Felipe Balbi fa8d965d73 usb: dwc3: trace: pretty print high-bandwidth transfers too
In case of periodic transfers, let's pretty print
the size field as a multiplier followed by length,
such as :

	3x 1024

instead of:

	33555456

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:28 +02:00
Felipe Balbi 43c96be1c4 usb: dwc3: trace: print out ep0state also from XferComplete
With this extra piece of information, it will be
easier to find mismatches between driver and HW.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:17:34 +02:00
Felipe Balbi cdd72ac20b usb: dwc3: debug: move dwc3_ep0_state_string() to debug.h
We will be using dwc3_ep0_state_string() from within
our tracepoints, so we need to move that helper to
debug.h in order for it to be accessible.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:17:34 +02:00
Felipe Balbi 8566cd1adf usb: dwc3: gadget: remove redundant trace prints
Removing some trace prints which were made redundant
when we started decoding events and TRBs completely
within their respective trace points.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:36 +02:00
Felipe Balbi 45a2af2f2b usb: dwc3: debug: decode control endpoint phase too
DWC3 can tell us which phase of a setup transfer
we're getting into. Let's decode it from the event
to make it easier to debug.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:36 +02:00
Felipe Balbi 799e9dc829 usb: dwc3: gadget: conditionally disable Link State change events
Link State Change events are only needed for
debugging and to apply certain workarounds on known
errata. Let's save a few cycles by disabling these
events completely on working revisions of the core.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:35 +02:00
Felipe Balbi 15b8d9332b usb: dwc3: gadget: giveback request if we can't kick it
There might be situations where a Start Transfer
command might fail, if that ever happens, instead of
simply removing the request from our list, we should
give the request back to the gadget driver,
otherwise we might eventually starve it from requests.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:35 +02:00
Felipe Balbi 8897a761c3 usb: dwc3: gadget: make use of No Response Update Transfer
No Response Update Transfer is a special type of
Update Transfer command which can be used whenever
we're not relying on XferNotReady to prepare
transfers. With this, we don't need to wait for
CMDACT to be cleared and issue further commands to
the endpoint straight away.

Let's start using this version to skip the long-ish
wait.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:34 +02:00
Felipe Balbi 5999914f22 usb: dwc3: gadget: properly check ep cmd
The cmd argument we pass to
dwc3_send_gadget_ep_cmd() could contain extra
arguments embedded. When checking for StartTransfer
command, we need to make sure to match only lower 4
bits which contain the actual command and ignore the
rest.

Reported-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:34 +02:00
Felipe Balbi 6b9018d4c1 usb: dwc3: gadget: set PCM1 field of isochronous-first TRBs
In case of High-Speed, High-Bandwidth endpoints, we
need to tell DWC3 that we have more than one packet
per interval. We do that by setting PCM1 field of
Isochronous-First TRB.

Cc: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:15:34 +02:00
Felipe Balbi 4accb8a1ee usb: dwc3: st: add missing <linux/pinctrl/consumer.h> include
dwc3-st uses pinctrl_pm_select_*_state() however it
doesn't include the necessary header. Fix the build
break caused by that, by simply including the
missing header.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:14:27 +02:00
Vivek Gautam 9b9d7cdd0a usb: dwc3: Fix error handling for core init
Fixing the sequence of events in dwc3_core_init() error exit path.
dwc3_core_exit() call is also removed from the error path since,
whatever it's doing is already done.

Fixes: c499ff7 usb: dwc3: core: re-factor init and exit paths

Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Stable <stable@vger.kernel.org> # 4.8+
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-31 11:14:27 +02:00
Christophe JAILLET 51fbc7c06c usb: dwc3: Fix size used in dma_free_coherent()
In commit 2abd9d5fa6 ("usb: dwc3: ep0: Add chained TRB support"), the
size of the memory allocated with 'dma_alloc_coherent()' has been modified
but the corresponding calls to 'dma_free_coherent()' have not been updated
accordingly.

This has been spotted with coccinelle, using the following script:
////////////////////
@r@
expression x0, x1, y0, y1, z0, z1, t0, t1, ret;
@@

*   ret = dma_alloc_coherent(x0, y0, z0, t0);
    ...
*   dma_free_coherent(x1, y1, ret, t1);

@script:python@
y0 << r.y0;
y1 << r.y1;

@@
if y1.find(y0) == -1:
 print "WARNING: sizes look different:  '%s'   vs   '%s'" % (y0, y1)
////////////////////

Fixes: 2abd9d5fa6 ("usb: dwc3: ep0: Add chained TRB support")

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-17 12:35:48 +03:00
Felipe Balbi d889c23ce4 usb: dwc3: gadget: never pre-start Isochronous endpoints
We cannot pre-start isochronous endpoints because we
rely on the micro-frame number passed via
XferNotReady command for proper Isochronous
scheduling.

Fixes: 08a36b5438 ("usb: dwc3: gadget: simplify __dwc3_gadget_ep_queue()")
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-17 11:14:00 +03:00
Felipe Balbi a9c3ca5fae usb: dwc3: gadget: properly account queued requests
Some requests could be accounted for multiple
times. Let's fix that so each and every requests is
accounted for only once.

Cc: <stable@vger.kernel.org> # v4.8
Fixes: 55a0237f8f ("usb: dwc3: gadget: use allocated/queued reqs for LST bit")
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-10-17 11:14:00 +03:00
Greg Kroah-Hartman 8152263748 usb: patches for v4.9 merge window
This time around we have 92 non-merge commits. Most
 of the changes are in drivers/usb/gadget (40.3%)
 with drivers/usb/gadget/function being the most
 active directory (27.2%).
 
 As for UDC drivers, only dwc3 (26.5%) and dwc2
 (12.7%) have really been active.
 
 The most important changes for dwc3 are better
 support for scatterlist and, again, throughput
 improvements. While on dwc2 got some minor stability
 fixes related to soft reset and FIFO usage.
 
 Felipe Tonello has done some good work fixing up our
 f_midi gadget and Tal Shorer has implemented a nice
 API change for our ULPI bus.
 
 Apart from these, we have our usual set of
 non-critical fixes, spelling fixes, build warning
 fixes, etc.
 -----BEGIN PGP SIGNATURE-----
 
 iQI6BAABCAAkBQJX2TpXHRxmZWxpcGUuYmFsYmlAbGludXguaW50ZWwuY29tAAoJ
 EMy+uJnhGpkGxX0QAIOavB96wkAP4msMzCMIKyKX8NBVWEYzLy7Ou6IrPKiGOR28
 CjDi1C5qW7838H4neA6Gfw896rfTiAODhoiOY/RTXI7p2hTUUXHQuJ81Bad75gHD
 744BUMPy37YJnvgHTasYn0GxAvP73YmV+omRxo76poetYZ9eH8dGECvC9q6m+jRU
 XaubWEq1JMvzHvlyO7BIrndGY4ByRbBoG0XPiZF07e5YDkKWQmv56tgAAN7fEkeh
 8HIg8lG2xvgf+w6cDbrQ2c8fp055OvrOq40R2pSXwQgYYKXPJ+vFiNzriQ6Rfxai
 gIYrB+mrKZcY6mi6OhoulGfNxT65VqMqnUfwVbbwlJQbDe5EkV6o/1WYdaBvdO2s
 qTT9A5alabFzbQ8ZtjzsIHtV62LwmZlMWk7gxZlcvLFNjf/P2CMqqnJi30/JlrsE
 iqhwIGRDhMq4QZZbiiEiJEaEn6vh2zseRdmCy3uMFearXKBP/I2177QOTDG7ZMKf
 fZR4ROlv6c5tIpBCOsTV0+7c/fnnnOTHU4+vJiUzU0krkPzaLcL8iMT1tn+uGchX
 4d2XLuT6AbVxQR4N8YF4FwRzB/PbEb+ZWWGu1mOVSd9/dsA43K50zNdc061dgz8K
 q8lau6bmtfUXdbeWa3WMEaAZIuSBmFarJY0tPZV6W7cXUAgKitThRD6fp4E0
 =vTFa
 -----END PGP SIGNATURE-----

Merge tag 'usb-for-v4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: patches for v4.9 merge window

This time around we have 92 non-merge commits. Most
of the changes are in drivers/usb/gadget (40.3%)
with drivers/usb/gadget/function being the most
active directory (27.2%).

As for UDC drivers, only dwc3 (26.5%) and dwc2
(12.7%) have really been active.

The most important changes for dwc3 are better
support for scatterlist and, again, throughput
improvements. While on dwc2 got some minor stability
fixes related to soft reset and FIFO usage.

Felipe Tonello has done some good work fixing up our
f_midi gadget and Tal Shorer has implemented a nice
API change for our ULPI bus.

Apart from these, we have our usual set of
non-critical fixes, spelling fixes, build warning
fixes, etc.
2016-09-14 20:37:50 +02:00
Felipe Balbi b281dc630b usb: dwc3: of-simple: add compatible for Cavium
Add necessary compatible flag for Cavium's DWC3 so
dwc3-of-simple will probe.

Tested-by: Steven J. Hill <Steven.Hill@cavium.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-13 09:28:59 +03:00
Felipe Balbi 26c9cac402 usb: dwc3: of-simple: allow glues without clocks
Instead of erroring out when we don't have clocks,
let's just avoid any calls to the clk API.

Tested-by: Steven J. Hill <Steven.Hill@cavium.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-13 08:40:40 +03:00
Greg Kroah-Hartman fc9104d5d7 Merge 4.8-rc6 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-12 09:15:26 +02:00
Anurag Kumar Vulisha 8d53e62675 usb: dwc3: of-simple: Fix warning during unbind
In dwc3_of_simple_remove() we are using clk_unprepare() before doing
any clk_disable(). If we enable Common CLK framework (CCF) and try to
unbind dwc3-of-simple driver, we see kernel WARN messages.

This patch fixes this kernel warning by using clk_disable_unprepare()
instead of clk_unprepare().

Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-12 10:07:24 +03:00
Lu Baolu 5e6c88d28c usb: dwc3: fix Clear Stall EP command failure
Commit 50c763f8c1 ("usb: dwc3: Set the ClearPendIN bit on Clear
Stall EP command") sets ClearPendIN bit for all IN endpoints of
v2.60a+ cores. This causes ClearStall command fails on 2.60+ cores
operating in HighSpeed mode.

In page 539 of 2.60a specification:

"When issuing Clear Stall command for IN endpoints in SuperSpeed
mode, the software must set the "ClearPendIN" bit to '1' to
clear any pending IN transcations, so that the device does not
expect any ACK TP from the host for the data sent earlier."

It's obvious that we only need to apply this rule to those IN
endpoints that currently operating in SuperSpeed mode.

Fixes: 50c763f8c1 ("usb: dwc3: Set the ClearPendIN bit on Clear Stall EP command")
Cc: <stable@vger.kernel.org> # v4.7+
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-12 10:05:55 +03:00
Arnd Bergmann d6e10bf2ba usb: dwc3: avoid -Wmaybe-uninitialized warning
Cleaning up the loop in dwc3_cleanup_done_reqs() introduced a
gcc warning if built with "-Wmaybe-uninitialized":

drivers/usb/dwc3/gadget.c: In function 'dwc3_endpoint_transfer_complete':
drivers/usb/dwc3/gadget.c:2015:9: 'trb' may be used uninitialized in this function [-Wmaybe-uninitialized]

I believe it is a false positive and we always have a valid 'trb'
pointer at the end of the function, but neither I nor the compiler
are able to prove that.

This works around the warning by computing a flag earlier in the function
when it's guaranteed to be valid, which tells the compiler that it's
safe and makes it easier to understand to me.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 31162af447 ("usb: dwc3: gadget: avoid while (1) loop on completion")
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-09 14:56:06 +03:00
Felipe Balbi 696118c016 usb: dwc3: pci: fix build warning on !PM_SLEEP
When building a kernel with CONFIG_PM_SLEEP=n, we
get the following warning:

drivers/usb/dwc3/dwc3-pci.c:253:12: warning: 'dwc3_pci_pm_dummy' defined but not used

In order to fix this, we should only define
dwc3_pci_pm_dummy() when CONFIG_PM_SLEEP is defined.

Fixes: f6c274e11e ("usb: dwc3: pci: runtime_resume child device")
Reported-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-07 15:37:36 +03:00
Thinh Nguyen 9d6173e125 usb: dwc3: Fix dr_mode validation
This patch follows the similar fix in dwc2. See
commit 5268ed9d2e ("usb: dwc2: Fix dr_mode validation")

Currently, the dr_mode is only checked against the module configuration.
It also needs to be checked against the hardware capablities.

The driver now checks if both the module configuration and hardware are
capable of the dr_mode value. If not, then it will issue a warning and
fall back to a supported value. If it is unable to fall back to a
suitable value, then the probe will fail.

Behavior summary:

      module          :  actual
 HW   config  dr_mode :  dr_mode
---------------------------------
 host  host   any     :  host
 host  dev    any     :  INVALID
 host  otg    any     :  host

 dev   host   any     :  INVALID
 dev   dev    any     :  dev
 dev   otg    any     :  dev

 otg   host   any     :  host
 otg   dev    any     :  dev
 otg   otg    any     :  dr_mode

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-07 13:29:20 +03:00
Tal Shorer 073c47aca7 usb: dwc3: ulpi: make dwc3_ulpi_ops constant
ulpi_register_interface() accepts a const struct ulpi_ops and dwc3
doesn't perform any changes to this struct at runtime, so there's no
reason it shouldn't be constant.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-06 10:47:26 +03:00
Tal Shorer e6f7484978 usb: ulpi: rename operations {read|write}_dev to simply {read|write}
With the removal of the old {read|write} operations, we can now safely
rename the new api operations {read|write}_dev to use the shorter and
clearer names {read|write}, respectively.

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-06 10:47:24 +03:00
Tal Shorer b7cf1dc341 usb: dwc3: ulpi: use new api
The old read, write callbacks in struct ulpi_ops have been deprecated
in favor of new callbacks that pass the parent device directly.
Replace the used callbacks in dwc3's ulpi component with the new api.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-06 10:47:24 +03:00
John Youn 9d7aba7786 Revert "usb: dwc3: gadget: always decrement by 1"
This reverts commit 6f8245b4e3 ("usb: dwc3: gadget: always decrement
by 1").

We can't always decrement this value.

We should decrement only if the calculation of free slots results in a
LINK TRB being among one of the free slots (dequeue < enqueue).

Otherwise, if the LINK TRB is not among the free slots then it should
not be decremented.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-09-05 13:39:23 +03:00
Greg Kroah-Hartman 9b0dd49e35 Merge 4.8-rc5 into usb-testing
We want the USB fixes in here for testing and merge issues.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-05 08:07:58 +02:00
Felipe Balbi 6f8245b4e3 usb: dwc3: gadget: always decrement by 1
We need to decrement in both cases (enq > deq and
enq < deq)

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:30:27 +03:00
Felipe Balbi 594e121f25 usb: dwc3: gadget: stop kicking if we run out of space
In case our TRB ring is full, we can avoid trying to
kick transfers which won't start and just add requests
to the queue.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:21 +03:00
Felipe Balbi 7ae7df4982 usb: dwc3: gadget: abolish trbs_left
Instead, we can always rely on dwc3_calc_trbs_left()
directly.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:20 +03:00
John Youn 06281d460f usb: dwc3: Add ENDXFER command polling
ENDXFER polling is available on version 3.10a and later of the
DWC_usb3 (USB 3.0) controller. With this feature, the software can poll
the CMDACT bit in the DEPCMD register after issuing an ENDXFER command.
This feature is enabled by writing GUCTL2[14].

This feature is NOT available on the DWC_usb31 (USB 3.1) IP.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:19 +03:00
John Youn 512e47572f usb: dwc3: Add revision numbers for the USB 3.0 IP
Add revision number constants for the 3.00a and 3.10a releases.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:18 +03:00
Baolin Wang 00af62330c usb: dwc3: core: Move the mode setting to the right place
When dwc3 core enters into suspend mode, the system (especially for mobile
device) may power off the dwc3 controller for power saving, that will cause
dwc3 controller lost the mode operation when resuming dwc3 core.

Thus we can move the mode setting into dwc3_core_init() function to avoid this
issue.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:16 +03:00
William Wu f652191be3 usb: dwc3: of-simple: add compatible for rockchip rk3399
Rockchip platform merely enable usb3 clocks and
populate its children. So we can use this generic
glue layer to support Rockchip dwc3.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:12 +03:00
William Wu 00fe081dc3 usb: dwc3: add dis_del_phy_power_chg_quirk
Add a quirk to clear the GUSB3PIPECTL.DELAYP1TRANS bit,
which specifies whether disable delay PHY power change
from P0 to P1/P2/P3 when link state changing from U0
to U1/U2/U3 respectively.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:11 +03:00
William Wu 32f2ed864d usb: dwc3: make usb2 phy utmi interface configurable
Support to configure the UTMI+ PHY with an 8- or 16-bit
interface via DT. The UTMI+ PHY interface is a hardware
capability, and it's platform dependent. Normally, the
PHYIF can be configured during coreconsultant.

But for some specific USB cores(e.g. rk3399 SoC DWC3),
the default PHYIF configuration value is false, so we
need to reconfigure it by software.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:11 +03:00
William Wu 16199f3389 usb: dwc3: add dis_u2_freeclk_exists_quirk
Add a quirk to clear the GUSB2PHYCFG.U2_FREECLK_EXISTS bit,
which specifies whether the USB2.0 PHY provides a free-running
PHY clock, which is active when the clock control input is active.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:11 +03:00
Felipe Balbi dc55c67e9c usb: dwc3: gadget: improve increment request->actual
No functional changes, just a slight cosmetic
change.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:06 +03:00
Felipe Balbi f99f53f24d usb: dwc3: gadget: remove condition that never happens
We don't use LST bit anymore, so this condition will
never trigger.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:13:06 +03:00
Felipe Balbi 1f512119a0 usb: dwc3: gadget: add remaining sg entries to ring
Upon transfer completion after a full ring, let's
add more TRBs to our ring in order to complete our
request successfully.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 12:12:58 +03:00
Felipe Balbi 696fe69d7e usb: dwc3: debug: fix ep name on trace output
There was a typo when generating endpoint name which
would be very confusing when debugging. Fix it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-25 10:36:25 +03:00
Felipe Balbi 2c78c0295f usb: dwc3: gadget: interrupt on ring full too
If the ring is full and we are processing a big
sglist, then let's interrupt so we can, later, add
more TRBs to the ring.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 0b3e4af3c7 usb: dwc3: gadget: add sg and num_pending_sgs to dwc3_request
These two fields will be used in a follow-up patch
to track how many entries of request's sglist we
have already processed. The reason is that if a
gadget driver sends an sglist with more entries then
we can fit in the ring, we will have to continue
processing remaining afterwards.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 31162af447 usb: dwc3: gadget: avoid while (1) loop on completion
We know that we have to iterate over the list of
started requests. Instead of looping forever, we can
rely on list_for_each_entry(). Likewise, instead of
a do {} while loop over all, maybe available,
scatterlist entries, we can detect if $this request
uses scatterlist and rely on for_each_sg().

This makes the code easier to follow while making
sure that we will *always* break out of the loop.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 08a36b5438 usb: dwc3: gadget: simplify __dwc3_gadget_ep_queue()
Many of the comments in that function are really
outdated and don't match what the driver is
doing. Moreover, recent patches combined programming
model for all non-control endpoints, this gives us
an opportunity to get rid of our special cases in
__dwc3_gadget_ep_queue().

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 45438a0cd9 usb: dwc3: gadget: simplify dwc3_ep_prev_trb()
We always need to decrement our index by at least
one. Simplify the implementation by using a
temporary local variable and making sure that we
will always decrement one extra if tmp == 0.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 737f1ae255 usb: dwc3: gadget: increment dequeue pointer on completion
Instead of waiting until giveback before
incrementing the dequeue pointer, we can increment
it from dwc3_cleanup_done_reqs(), that way we avoid
an extra loop over all TRBs during giveback.

While at that, also avoid using req->first_trb_index
as that's completely unnecessary. A follow-up patch
will clean up further uses of that and remove the
field altogether.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Felipe Balbi 4bc48c9747 usb: dwc3: gadget: retire LST bit completely
The only endpoint which actually requires LST bit
and XferComplete is ep0/1. Let's save some time by
completely removing LST bit support and
XferComplete.

This simplifies and consolidates endpoint handling
for all other 3 transfer types while also avoiding
extra interrupts.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:37 +03:00
Nicolas Saenz Julienne d6011f6fc2 usb: dwc3: gadget: don't rely on jiffies while holding spinlock
__dwc3_gadget_wakeup() is called while holding a spinlock, then depends on
jiffies in order to timeout while polling the USB core for a link state
update. In the case the wakeup failed, the timeout will never happen and
will also cause the cpu to stall until rcu_preempt kicks in.

This switches to a "decrement variable and wait" timeout scheme.

Signed-off-by: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:13 +03:00
Felipe Balbi b74c2d875b usb: dwc3: core: allow device to runtime_suspend several times
After going through runtime_suspend/runtime_resume
cycle once we would be left with an unbalanced
pm_runtime_get() call. Fix that by making sure that
we try to suspend right after resuming so things are
balanced and device can runtime_suspend again.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:11 +03:00
Felipe Balbi f6c274e11e usb: dwc3: pci: runtime_resume child device
During runtime_resume of dwc3-pci.c, we need to
runtime suspend our child device (which is dwc3
proper) otherwise nothing will happen.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-22 10:45:10 +03:00
Greg Kroah-Hartman 1aaaa9acae Merge 4.8-rc3 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-21 21:33:17 -04:00
Felipe Balbi a0ad85ae86 usb: dwc3: gadget: stop processing on HWO set
stop consuming TRBs when we reach one with HWO bit
already set. This will prevent us from prematurely
retiring a TRB.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-11 15:09:48 +03:00
Janusz Dziedzic 79d17482a4 usb: dwc3: don't set last bit for ISOC endpoints
According to Synopsys Databook 2.60a, section 8.3.4,
it's stated that:

	The LST bit should be set to 0 (isochronous
	transfers normally continue until the
	endpoint is removed entirely, at which time
	an End Transfer command is used to stop the
	transfer).

This patch makes sure that detail is observed and
fixes a regression with Android Audio playback
caused by recent changes to DWC3 gadget.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-11 15:09:48 +03:00
Wei Yongjun 4c4f106c03 usb: dwc3: fix missing platform_set_drvdata() in dwc3_of_simple_probe()
Add missing platform_set_drvdata() in dwc3_of_simple_probe(), otherwise
calling platform_get_drvdata() in remove returns NULL.

This is detected by Coccinelle semantic patch.

Signed-off-by: Wei Yongjun <weiyj.lk@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-11 15:09:45 +03:00
Heikki Krogerus 4491ed5042 usb: dwc3: pci: add Intel Kabylake PCI ID
Intel Kabylake PCH has the same DWC3 than Intel
Sunrisepoint. Add the new ID to the supported devices.

Cc: <stable@vger.kernel.org>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-10 14:15:58 +03:00
Felipe Balbi 7c705dfe2e usb: dwc3: gadget: always cleanup all TRBs
If we stop earlier due to short packet, we will
not be able to giveback all TRBs.

Cc: <stable@vger.kernel.org>
Cc: Brian E Rogers <brian.e.rogers@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-10 14:15:57 +03:00
Felipe Balbi e5b36ae2f8 usb: dwc3: gadget: fix for short pkts during chained xfers
DWC3 has one interesting peculiarity with chained
transfers. If we setup N chained transfers and we
get a short packet before processing all N TRBs,
DWC3 will (conditionally) issue a XferComplete or
XferInProgress event and retire all TRBs from the
one which got a short packet to the last without
clearing their HWO bits.

This means SW must clear HWO bit manually, which
this patch is doing.

Cc: <stable@vger.kernel.org>
Cc: Brian E Rogers <brian.e.rogers@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-10 14:15:57 +03:00
Felipe Balbi c7de573471 usb: dwc3: gadget: increment request->actual once
When using SG lists, we would end up setting
request->actual to:

	num_mapped_sgs * (request->length - count)

Let's fix that up by incrementing request->actual
only once.

Cc: <stable@vger.kernel.org>
Reported-by: Brian E Rogers <brian.e.rogers@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-08-10 14:15:57 +03:00
Masahiro Yamada a26a142275 usb: remove redundant dependency on USB_SUPPORT
The whole Kconfig entries of the USB subsystem are surrounded with
"if USB_SUPPORT" ... "endif", so CONFIG_USB_SUPPORT=y is surely met
when these two Kconfig options are visible.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-09 16:15:44 +02:00
Greg Kroah-Hartman c318a821b9 Merge 4.7-rc6 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-07-04 08:19:21 -07:00
Linus Torvalds 0d064a7b9c - Final patches fixing Reset API change
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJXdkJCAAoJEFGvii+H/Hdh4fIP/0U47cICszk6AkV2P3q3yRc6
 RyIfjBddVxAnNnUQoJAkyDnZmZnCH33wMa3NG8BlXCrtPUSMoUkG78RIN6mWjgp6
 pooaXBylqIiU4ZoyQVXvxTQZhM7u/ox+2InrXOeZXirkJvRY4GzwsNWtdhzclHq2
 iM86K1cfaIPdJ4d3y7WF6/5DOsdMiYQUvmtxLEYTKgJgGvkgM/9I7Ws8vk3R0lXk
 wO8EItxIZecAIEwfwI8HgYCoyPctevMSnXMTWAJTF+5m3Wprhhv0lEjCTEBHbmJb
 kkrAr86tNj4nNVG9pQCDYL/XX0Zpub0vTA4+mPL5/WTrVpI/RRYlJXKIlR25vvlN
 wlYRrY4mE4gKFJh7t6DhQiHdrrQcoWPymKZ7CSF2GZvc65xwBa0u3ZkeLhurgj0N
 C8Zj7QRIqHfP4O8JDMRvuToWJWtc8sfSvh2Y9szkevwNjZjO9INSM/hStfJZ1S0E
 EnZIcHSKehjdiLHiMgyWGRB3Fq24u41u8aVAGvCfCsSe7CZKYKzyAHEQSC7solSJ
 GmbJ6F2gB65v62rNReZeP9NCc25fex7ZkdYMr6XYqrSh7GoxtF+9VPHEvYXs5BVK
 +rVVCOvuvqSy4+oQ+N/0grLHIThqSVbAusXBSLFPykHO7R4Z30f3wIiSPTq8m2VW
 c5qwGR4ceOBRrX8fQw0c
 =PpU9
 -----END PGP SIGNATURE-----

Merge tag 'mfd-fixes-4.7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd

Pull more MFD fixes from Lee Jones:
 "Apologies for missing these from the first pull request.

  Final patches fixing Reset API change"

* tag 'mfd-fixes-4.7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd:
  usb: dwc3: st: Use explicit reset_control_get_exclusive() API
  phy: phy-stih407-usb: Use explicit reset_control_get_exclusive() API
  phy: miphy28lp: Inform the reset framework that our reset line may be shared
2016-07-01 15:17:16 -07:00
Roger Quadros 322832f2f1 usb: dwc3: host: Fix broken XHCI host
Looks like we lost all changes related to
commit 9522def400 ("usb: dwc3: core: cleanup IRQ resources") in host.c
when Felipe's next branch was merged into Greg's next branch.

Fixes 215db94818 ("Merge tag 'usb-for-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next")
Signed-off-by: Roger Quadros <rogerq@ti.com>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-07-01 08:59:44 -07:00
Lee Jones 5baaf3b9ef usb: dwc3: st: Use explicit reset_control_get_exclusive() API
We're making all reset line users specify whether their lines are
shared with other IP or they operate them exclusively.  In this case
the line is exclusively used only by this IP, so use the *_exclusive()
API accordingly.

Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2016-07-01 10:52:16 +01:00
Linus Torvalds 4aa34ce3c1 - Bug Fixes
- Use new reset_*_get_shared() variant to prevent reset line obtainment failure
     - Fixes: 0b52297 ("reset: Add support for shared reset controls")
   - Fix unintentional switch() fall-through into error path
   - Fix uninitialised variable compiler warning
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJXdMAeAAoJEFGvii+H/Hdh2JsQAJ5ez/+WlfVY5enmZTCPTfjv
 YAZOhGuKyK1RcNKVmhRTXKDDlEQtbzX01AG73UOsMuR6Gjfq4q+lsK88ybE6Y3MS
 YuIBa0TXicyywbLhAh4bCqbImFQZ2MhU07mJWn5n6qX1LwrxncKN5MdRj2DKzldv
 s9AG1EKUKf/83k6kuODaP8dXutvWPEGKYKXnq9MQPBliU2j7DT7mfEp3jLGlJvXy
 UkW2uq1RAhu27fe7TKVefatXLIyqo74fi3fuHVZpWfPsoUTFlQd3RzeFL7Q/orWH
 JqiUk55xAbsmtkEeKNbpph1gPyR1pzKKHiNvSfRt/yIjsxOVPGZQZA2y4OpIcOKV
 mbxPUrurhcdI+sK2+7JpcbjKYJpCsGgCXtwbLubLcgler+RatmFWOB8+ayH32eVC
 DELYFtc80YBaDS+2KrgY4la1Mk1agbfDpyhq4Vp5uiRZFhQyldd1XrPPQssMJNc+
 Zme+LRu+EQiullbHDRb6cb0dnV2Tcek4IjI1CsNA6UMAMLcVb8IZ1gX39vWr+BNt
 ZWxxoBOcskPJ/t3h4ddPbuMzSA0ctBkJct9bdjg+bpZeA0aJ46lTQCJk4fZfjViu
 YcDgO8/ZVaDLz5f4f44xJ+Hwnzxr2fezBUirD3UtPvs57BSVnFbHMBXUdy0NCBHk
 mZi1lFOjy7eKuW1+kbrx
 =mo7m
 -----END PGP SIGNATURE-----

Merge tag 'mfd-fixes-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd

Pull MFD fixes from Lee Jones:
 "Contained are some standard fixes and unusually an extension to the
  Reset API.  Some of those changes are required to fix a bug introduced
  in -rc1, which introduces extra 'reset line checks' i.e. whether the
  line is shared or not.  If a line is shared and the new *_shared() API
  is not used, the request fails with an error.  This breaks USB in v4.7
  for ST's platforms.

  Admittedly, there are some patches contained in our (MFD/Reset)
  immutable branch which are not true -fixes, but there isn't anything I
  can do about that.  Rest assured though, there aren't any API
  'changes'.  Everything is the same from the consumer's perspective.

   - Use new reset_*_get_shared() variant to prevent reset line
     obtainment failure (Fixes commit 0b52297f2288: "reset: Add support
     for shared reset controls")

   - Fix unintentional switch() fall-through into error path

   - Fix uninitialised variable compiler warning"

* tag 'mfd-fixes-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd:
  mfd: da9053: Fix compiler warning message for uninitialised variable
  mfd: max77620: Fix FPS switch statements
  phy: phy-stih407-usb: Inform the reset framework that our reset line may be shared
  usb: dwc3: st: Inform the reset framework that our reset line may be shared
  usb: host: ehci-st: Inform the reset framework that our reset line may be shared
  usb: host: ohci-st: Inform the reset framework that our reset line may be shared
  reset: TRIVIAL: Add line break at same place for similar APIs
  reset: Supply *_shared variant calls when using *_optional APIs
  reset: Supply *_shared variant calls when using of_* API
  reset: Ensure drivers are explicit when requesting reset lines
  reset: Reorder inline reset_control_get*() wrappers
2016-06-30 09:44:34 -07:00
Lee Jones 002f17bc54 usb: dwc3: st: Inform the reset framework that our reset line may be shared
On the STiH410 B2120 development board the MiPHY28lp shares its reset
line with the Synopsys DWC3 SuperSpeed (SS) USB 3.0 Dual-Role-Device
(DRD).  New functionality in the reset subsystems forces consumers to
be explicit when requesting shared/exclusive reset lines.

Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2016-06-30 07:44:21 +01:00
Greg Kroah-Hartman 215db94818 usb: patches for v4.8 merge window
Here's the big pull request for Peripheral stack and
 all related drivers.
 
 This time around with 109 non-merge commits mostly
 concentrated on drivers/usb/gadget/udc (41.5%) and
 drivers/usb/dwc3 (28.1%).
 
 There's a big rework on dwc3's transfer handling
 which gave us almost 3x faster USB3 speeds with Mass
 Storage on a particular test scenario I measured. We
 are also removing platform_data from dwc3 after
 converting all users to built-in properties instead.
 
 For the Gadget API, we're just adding tracepoints to
 aid debugging activities.
 
 Other than these, there's the usual set of spelling
 fixes, minor bug fixes and sparse warnings cleanups.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJXc7hvAAoJEIaOsuA1yqREgCoP/3/xfIoJfDTLbTG9V898Ma07
 jSHVmaAu4FSktbYv6ndfcdn5tQxpADurc1cphCV1sT24Fdr56YsQdOxagqu892oo
 oW/WMka1bo7OlvzHqZYmy60hAEeWsAaVxqtEtpyb35Q/tH/33bxTlO+MeKmEKpIM
 HVQzMNuzXy6NxytVGu/BnSZRGtDLHZMdaRNEpn465Ll9mP6zm7ebdWnkIGniGRZ+
 YeK1CfvnUcSxmaB83Gr5kthFJUhi5rpX421301FdtkY4cUtZad+FlN0UW3fd8ztC
 hGr2fr+CZO7zVJ/KmEvarTLvYN0ScSjyS0VX9TT/voxJbjqZaIew0mkUWLpdxpYW
 J4i921j5pSVuK9VRbnhObxenLsW66zoqFtHeQ7pRDm3sX2fJGAX5qB6Votw4ziar
 puwE3cQ4Divk6CGEcnUmZ26KvYE/sW7W8WoKAeMMjIinJN46geLjAiqA5dpYxYuH
 ipCe1YdbjpG4GOnTjajZodGUXlmCPbs2VmcgIH36jbQ8S1m1Q3wuO9ClAO8MvGmr
 Y5HzbUeEDyJe4ZKzT9iOWtj0PAa1YEvpSRLwpZaehycQLKvbd0rRDIQ4p+oq7QDK
 gAN+kWCnkNup7qzAD6aE0FrJtYt5u5qVmPfp1H9z8+/AfmG8QZpy2d+VQsAhIwI+
 9d2bok3rsfi87lEFVRWg
 =PT1e
 -----END PGP SIGNATURE-----

Merge tag 'usb-for-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: patches for v4.8 merge window

Here's the big pull request for Peripheral stack and
all related drivers.

This time around with 109 non-merge commits mostly
concentrated on drivers/usb/gadget/udc (41.5%) and
drivers/usb/dwc3 (28.1%).

There's a big rework on dwc3's transfer handling
which gave us almost 3x faster USB3 speeds with Mass
Storage on a particular test scenario I measured. We
are also removing platform_data from dwc3 after
converting all users to built-in properties instead.

For the Gadget API, we're just adding tracepoints to
aid debugging activities.

Other than these, there's the usual set of spelling
fixes, minor bug fixes and sparse warnings cleanups.
2016-06-29 09:51:48 -07:00
Heikki Krogerus 95b57df450 usb: dwc3: host: use build-in property instead of platform data
This should allow xhci to remove handling of platform data.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-06-26 11:43:39 -07:00
Baolin Wang 72704f876f dwc3: gadget: Implement the suspend entry event handler
It had changed to be suspend event for BIT6 in DEVT register from
version 2.30a and above. Thus this patch introduces one suspend
event handler to handle the suspend event.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 11:16:01 +03:00
Roger Quadros 9522def400 usb: dwc3: core: cleanup IRQ resources
Implementations might use different IRQs for
host, gadget so use named interrupt resources
to allow device tree to specify the interrupts.

Following are the interrupt names

Peripheral Interrupt - peripheral
HOST Interrupt - host

Maintain backward compatibility for a single named
interrupt ("dwc3_usb3") for all interrupts as well as
unnamed interrupt at index 0 for all interrupts.

As platform_get_irq() variants are used, tackle
the -EPROBE_DEFER case as well.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:53:22 +03:00
Baolin Wang da1410be21 usb: dwc3: gadget: Add the suspend state checking when stopping gadget
It will be crash to stop gadget when the dwc3 device had been into suspend
state, thus we need to check if the dwc3 device had been into suspend state
when UDC try to stop gadget.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:44:37 +03:00
Felipe Balbi 0e146028ee usb: dwc3: gadget: issue ENDTRANSFER conditional on resource_index
Because of recent changes to transfer handling on
DWC3, we will not get XferComplete unless we
completely fill up our TRB ring. This means that we
might get a Reset or Disconnect without getting a
XferComplete first.

In order to correctly release our allocated Transfer
Resource, we must issue ENDTRANSFER command whenever
dep->resource_index is valid.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:44 +03:00
Roger Quadros 328082376a usb: dwc3: fix runtime PM in error path
If there is a failure after pm_runtime_enable/get_sync()
we need to call pm_runtime_disable/put_sync().

Otherwise it will lead to an unbalanced pm_runtime_enable() on the
subsequent probe if the earlier probe bailed out due to -EPROBE_DEFER.

pm_runtime_get_sync() can fail as well so deal with that case too.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:43 +03:00
Felipe Balbi b6d4e16e83 usb: dwc3: gadget: simplify run_stop() break condition
it's clear now that when is_on=true, we must loop
until DWC3_DSTS_DEVCTRLHLT clears; while when
is_on=false we must loop until DWC3_DSTS_DEVCTRLHLT
gets set.

Instead of adding actual if() statements, we can
rely on XOR operation to evaluate to true only when
the above conditions apply. Then, we can move the
break condition back to the while() statement
together with our timeout check and the resulting
code is very compact and simpler to read.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:43 +03:00
Felipe Balbi f2df679b6c usb: dwc3: gadget: avoid while(1) in run_stop()
instead of looping forever and forcing a return if
timeout reaches zero, we can just use timeout and
loop's break condition directly.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:43 +03:00
Felipe Balbi d807bdd028 usb: dwc3: gadget: remove udelay() from run_stop()
testing shows that udelay() is unnecessary as
controller reaches Halted state almost
instantenously as can be seen by our timeout
variable never actually decrementing.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:42 +03:00
Felipe Balbi 5f82279a0c usb: dwc3: core: fixup dr_mode fallback selection
We shouldn't change a host-only dwc3 to gadget-only
if driver is built as gadget-only. Fix that up here.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:42 +03:00
Felipe Balbi e6fe66fe08 usb: dwc3: pci: add dr-mode for Intel dwc3
It's know that Intel's SoCs' dwc3 integration is
peripheral-only since Intel implements its own
portmux for role-swapping. In order to prevent dwc3
from ever registering and XHCI platform_device,
let's just set dr-mode to peripheral-only on Intel
SoCs.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:42 +03:00
Felipe Balbi 21e64bf20d usb: dwc3: gadget: rename 'ignore' argument to 'modify'
'modify' is what the current action is called. Let's
rename it so it matches databook. While at that,
also make sure to add support 'init' action too.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-21 10:38:41 +03:00
Felipe Balbi d6dc2e76a8 usb: dwc3: gadget: decrement trbs_left for each sg entry
If we don't, we will overwrite valid TRBs.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:51 +03:00
Felipe Balbi ba62c09d5c usb: dwc3: gadget: start Bulk endpoints more frequently
Now we can try to issue Update Transfer every time
gadget driver queues a new request. This will make
sure we keep controller's queue busy for as long as
possible.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:51 +03:00
Felipe Balbi 13fa2e69b1 usb: dwc3: gadget: disable XFER_NOT_READY
We don't need this IRQ anymore for interrupt or bulk
endpoints.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:50 +03:00
Felipe Balbi 55a0237f8f usb: dwc3: gadget: use allocated/queued reqs for LST bit
Let's only set LST bit when we run out of space in
our TRB ring. For all other cases, we keep LST bit
unset which will prevent constant allocation and
deallocation of endpoint transfer resources.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:50 +03:00
Felipe Balbi 69450c4dc1 usb: dwc3: gadget: halt and stop based HWO bit
Instead of relying on empty list of queued requests,
let's rely on the fact that we have a TRB being
processed right now.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:50 +03:00
Felipe Balbi 68d34c8a74 usb: dwc3: gadget: keep track of allocated and queued reqs
We will be using this information to change how we
figure out when we need LST bit. For now, just
update our counters.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:49 +03:00
Felipe Balbi b6b1c6db4c usb: dwc3: gadget: update transfer needs transfer resource
According to SNPS databook, we need to pass transfer
resource on update transfer command, let's do it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:49 +03:00
Heikki Krogerus d18e65470a usb: dwc3: remove handling of platform data
No more users for it.

Tested-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:48 +03:00
Heikki Krogerus cf48305de0 usb: dwc3: pci: use build-in properties instead of platform data
This should allow the core driver to drop handling of
platform data and expect the platform specific details to
always come from properties.

Tested-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Huang Rui <ray.huang@amd.com>
CC: John Youn <John.Youn@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:48 +03:00
Felipe Balbi 60cfb37ac9 usb: dwc3: remove trailing newline from dwc3_trace
when passing strings to trace, we don't need the
trailing newline character. Trace already appends a
newline character automatically.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:48 +03:00
Roger Quadros d2728fb3e0 usb: dwc3: omap: Pass VBUS and ID events transparently
Don't make any decisions regarding VBUS session based on ID
status. That is best left to the OTG core.

Pass ID and VBUS events independent of each other so that OTG
core knows exactly what to do.

This makes dual-role with extcon work with OTG irq on OMAP platforms.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:47 +03:00
Roger Quadros 9ab330bf4d usb: dwc3: omap: Don't set POWERPRESENT
TRM [1] recommends that POWERPRESENT bit must not be
set and left at it's default value of 0.

[1] OMAP542x TRM - http://www.ti.com/lit/pdf/swpu249
Section 23.11.4.5.1 Mailbox VBUS/ID Management

"Because PIPE powerpresent has a different meaning in host and in device mode,
and because of the redundancy with the UTMI signals, the controller ORes
together the appropriate PIPE and UTMI inputs to create its internal
VBUS status. For that reason, it is recommended to leave field
USBOTGSS_UTMI_OTG_STATUS[9] POWERPRESENT at its default value (=0), and only to
fill in the USB2 VBUS status fields in the same register."

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:47 +03:00
Roger Quadros 12da8eae20 usb: dwc3: omap: Mark the interrupt handler as shared
On OMAPs, OTG events come on the same IRQ so we need to share
this IRQ with the OTG device driver.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:47 +03:00
Roger Quadros 3f586c92d8 usb: dwc3: omap: use request_threaded_irq()
We intend to share this interrupt with the OTG driver an to ensure
that irqflags match for the shared interrupt handlers we use
request_threaded_irq()

If we don't use request_treaded_irq() then forced threaded irq will
set IRQF_ONESHOT and this won't match with the OTG IRQ handler's
IRQ flags.

NOTE: OTG IRQ handler is yet to be added. This is a preparatory step.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:46 +03:00
William Wu 475c8beb35 usb: dwc3: add DWC3_GUCTL1 reg for debug
GUCTL1 reg has some useful functions which can be
written by user. For rockchip platform, we set
GUCTL1.DEV_FORCE_20_CLK_FOR_30_CLK (bit26, applicable
for the core is programmed to operate in 2.0 device
only) to 1 in bootrom, and after start the kernel,
we want to check whether this bit can be reset to
default 0 after the core reset. Dump GUCTL1 reg from
debugfs is more convenient for us.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:46 +03:00
John Youn e77c561432 usb: dwc3: Fix DWC3_USB31_REVISION_110A definition
The DWC3_USB31_REVISION_110A macro uses an invalid constant name in its
definition. This is currently not used.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:46 +03:00
John Youn 2da9ad761e usb: dwc3: Use the correct speed macros for DSTS/DCFG
Correct the use of the DWC3_DSTS_XXX_SPEED and DWC3_DCFG_XXX_SPEED
macros. The wrong set of macros were being used in a few places.

This is only a cosmetic change as the values for both sets are
identical.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:45 +03:00
John Youn 3de2685f0c usb: dwc3: gadget: Fix truncated cast issue
From sparse:
warning: cast truncates bits from constant value (100 becomes 0)

The DWC3_TRB_NUM constant is too big for u8. Do the calculation a
slightly different way that should still be optimized out for the case
where DWC3_TRB_NUM == 256.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:45 +03:00
John Youn 361572b5f7 usb: dwc3: gadget: Handle TRB index 0 when full or empty
If the trb->enqueue == trb->dequeue, then it could be full or empty.
This could also happen at TRB index 0, so modify the check to handle
that condition. At index 0, the previous TRB is the one just before the
link TRB.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:45 +03:00
John Youn 7d0a038b13 usb: dwc3: gadget: Account for link TRB in TRBs left
The TRBs left calculation didn't account for the link TRB taking up one
spot.

If the trb_dequeue < trb_enqueue, then the result includes the link
TRB slot so it must be adjusted.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:44 +03:00
John Youn 32db3d9437 usb: dwc3: gadget: Account for max size in TRB space
The current calculation takes dep->trb_dequeue - dep->trb_enqueue to
find the TRB space left.

If you enqueue 1, that results in:
(u8) 0 - (u8) 1 = 0xff = 255 TRBs left.

This is correct if DWC3_TRB_NUM == 256.

If DWC3_TRB_NUM is less than 256 (but still a power of 2) you need to
mod the result by DWC3_TRB_NUM.

For example the same calculation with DWC3_TRB_NUM = 8, results in:
255 % 6 = 7 TRBs left.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:44 +03:00
John Youn 89bc856e5a usb: dwc3: gadget: Don't prepare TRBs if no space
If trbs_left == 0, we don't have any space left in the TRB ring so don't
prepare anything.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:44 +03:00
John Youn 0d25744ad1 usb: dwc3: gadget: Initialize the TRB ring
Clears out all the TRBs in the ring to clean up any stale data that
might be in them from the previous time the endpoint was enabled.

Also removed the existing clear of the LINK trb since the entire ring is
cleard just before.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:43 +03:00
John Youn dca0119c3a usb: dwc3: gadget: Simplify skipping of link TRBs
Make the skipping of the link TRBS built-in to the increment operation.
This simplifies the code wherever we increment the trb index and ensures
that we never end up pointing to a link trb.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:43 +03:00
John Youn 96bedb637a usb: dwc3: Endianness issue on dwc3_log_ctrl
Sparse complains even though it looks ok. Probably it cannot detect that
the wValue, wIndex, and wLength are declared __le16 due to the macro
magic.

Redeclare them as CPU endianness and make the conversion on assignment.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:43 +03:00
John Youn d07fa665c7 usb: dwc3: gadget: Fix usage of bitwise operator
Cleans up the sparse warning:
warning: dubious: x | !y

Since we do want a bitwise OR here, don't use a logical (true/false)
value. Probably is not a real issue but it cleans up the warning.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:42 +03:00
John Youn 501058edeb usb: dwc3: ep0: Use the correct type for SET_SEL data
u2sel and u2pel should be __le16. Doesn't fix any issue.

Found with sparse.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:42 +03:00
John Youn 958b9fa7f8 usb: dwc3: ep0: Fix endianness of wIndex passed to dwc3_wIndex_to_dep
The wIndex passed in here is CPU endianness, but the function expects
little endian.

Found with sparse.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:42 +03:00
Felipe Balbi 71f7e70270 usb: dwc3: gadget: improve gcmd trace
Just like we did for endpoint commands, let's have a
single trace output for the command and its
status. This will improve trace readability

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:41 +03:00
Felipe Balbi 88811f7b72 usb: dwc3: gadget: remove udelay() from generic cmd
We want commands to finish ASAP, so let's remove
that udelay() call.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:41 +03:00
Felipe Balbi 0fe886cdb0 usb: dwc3: gadget: single return point on generic commands
Just like we did for endpoint commands, let's use a
single return point for generic commands as
well. This aids readability.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:41 +03:00
Felipe Balbi 0933df159c usb: dwc3: trace: print ep cmd status with a single trace
Instead of printing command's status with a separate
trace printout, let's print it within a single call.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:40 +03:00
Felipe Balbi f6bb225bb3 usb: dwc3: gadget: loop while (timeout)
instead of having infinite loop and always checking
timeout value as a break condition, we can just
decrement timeout inside while's condition.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:40 +03:00
Felipe Balbi ba1598410e usb: dwc3: gadget: fix trace output when command fails
We don't need the extra %s when command fails.
Let's remove it

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:40 +03:00
Felipe Balbi f75cacc468 usb: dwc3: trace: fully decode IRQ events
This will make it more human-friendly to read trace
output from dwc3.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:39 +03:00
Felipe Balbi 7ab373aadb usb: dwc3: gadget: no more tracking endpoint type with its name
I really thought this would be useful, but as it
turns out, it creates more problems than fixes. The
amount of times we had to fix this because some
other commit shuffled things around and ended up
regressing this tiny little string manupulation...

Might as well remove it, since it has a negligible
added benefit.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:39 +03:00
Janusz Dziedzic 22f2c619a1 usb: dwc3: trace: pretty-print TRB's ctrl field
Improve trb tracing by showing trb flags, interrupts
trb type.

trb flags:
- h - hardware owner of descriptor
- l - last TRB
- c - chain buffers
- s - continue on short packet

interrupt flags:
- s - interrupt on short packet
- c - interrupt on complete

Capital letter means that bit is set, while
lowercase letter means bit is cleared.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:39 +03:00
Felipe Balbi 74674cbf85 usb: dwc3: gadget: add a per-endpoint request queue lock
This will allow us to process several endpoints at a
time by making sure that we lock only shared
resources.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:38 +03:00
Felipe Balbi e9af922909 usb: dwc3: pci: add Power Management dummy hooks
Allow for dwc3-pci to reach D3 and enable pm_runtime
by providing dummy PM hooks. Without them, PCI
subsystem won't put device to D3.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:38 +03:00
Felipe Balbi fc8bb91bc8 usb: dwc3: implement runtime PM
this patch implements the most basic pm_runtime
support for dwc3. Whenever USB cable is dettached,
then we will allow core to runtime_suspend.

Runtime suspending will involve completely tearing
down event buffers and require a full soft-reset of
the IP.

Note that a further optimization could be
implemented once we decide to support hibernation,
which is to allow runtime_suspend with cable
connected when bus is in U3. That's subject to a
separate patch, however.

Tested-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:38 +03:00
Felipe Balbi 4cb4221764 usb: dwc3: gadget: fix for possible endpoint disable race
when we call dwc3_gadget_giveback(), we end up
releasing our controller's lock. Another thread
could get scheduled and disable the endpoint,
subsequently setting dep->endpoint.desc to NULL.

In that case, we would end up dereferencing a NULL
pointer which would result in a Kernel Oops. Let's
avoid the problem by simply returning early if we
have a NULL descriptor.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:37 +03:00
Konrad Leszczynski 9cad39fe4e usb: dwc3: fix for the isoc transfer EP_BUSY flag
commit f3af36511e ("usb: dwc3: gadget: always
enable IOC on bulk/interrupt transfers") ended up
regressing Isochronous endpoints by clearing
DWC3_EP_BUSY flag too early, which resulted in
choppy audio playback over USB.

Fix that by partially reverting original commit and
making sure that we check for isochronous endpoints.

Fixes: f3af36511e ("usb: dwc3: gadget: always enable IOC
		on bulk/interrupt transfers")
Cc: <stable@vger.kernel.org>
Signed-off-by: Konrad Leszczynski <konrad.leszczynski@intel.com>
Signed-off-by: Rafal Redzimski <rafal.f.redzimski@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:37 +03:00
Felipe Balbi ab2a92e7a6 usb: dwc3: gadget: only resume USB2 PHY in <=HIGHSPEED
As a micro-power optimization, let's only resume the
USB2 PHY if we're working on <=HIGHSPEED. If we're
gonna work on SUPERSPEED or SUPERSPEED+, there's no
point in resuming the USB2 PHY.

Fixes: 2b0f11df84 ("usb: dwc3: gadget: clear SUSPHY bit before ep cmds")
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:37 +03:00
Felipe Balbi 3f308d17d7 usb: dwc3: gadget: hold gadget IRQ in dwc->irq_gadget
by holding gadget's IRQ number in dwc->irq_gadget,
it'll be simpler to free_irq() and disable the IRQ
in case an IRQ fires while we are runtime suspended.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:36 +03:00
Felipe Balbi 51f5d49ad6 usb: dwc3: core: simplify suspend/resume operations
now that we have re-factored dwc3_core_init() and
dwc3_core_exit() we can use them for suspend/resume
operations.

This will help us avoid some common mistakes when
patching code when we have duplicated pieces of code
doing the same thing.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:36 +03:00
Felipe Balbi c499ff71ff usb: dwc3: core: re-factor init and exit paths
The idea of this patch is for dwc3_core_init() to
abstract all the details about how to initialize
dwc3 and dwc3_core_exit() to do the same for
teardown.

With this, we can simplify suspend/resume operations
by a large margin and always know that we're going
to start dwc3 from a known starting point.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:36 +03:00
Felipe Balbi bcdb3272e8 usb: dwc3: core: move fladj to dwc3 structure
this patch is in preparation for some further
re-factoring in dwc3 initialization. No functional
changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:35 +03:00
Felipe Balbi 2eb8801650 usb: dwc3: gadget: add a pointer to endpoint registers
By adding a pointer to endpoint registers' base
address, we can avoid using our controller-wide
struct dwc3 pointer for everything. At some point
this will allow us to have per-endpoint locks which
will, in turn, let us queue requests to separate
endpoints in parallel.

Because of this change our debugfs interface and io
accessors need to be changed accordingly.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:35 +03:00
Felipe Balbi 2cd4718d0b usb: dwc3: gadget: pass dep as argument to endpoint command
In all call sites of dwc3_send_gadget_ep_cmd() we
already had a valid dep pointer, so instead of
passing dwc and dep->number, which would be used to
fetch the same pointer we already had, just pass dep
directly.

In other words, we're changing:

	struct dwc3_ep *dep = dwc[dep->number];

to just passing struct dwc3_ep *dep as argument.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:32:31 +03:00
Felipe Balbi 4e99472bc1 usb: dwc3: gadget: initialize NUMP based on RxFIFO Size
Instead of using burst size to configure NUMP, we
should be using RxFIFO Size instead. DWC3 is smart
enough to know that it shouldn't burst in case burst
size is 0.

Reported-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:07 +03:00
Felipe Balbi 5ee85d890f usb: dwc3: gadget: split __dwc3_gadget_kick_transfer()
To aid code readability, we're gonna split
__dwc3_gadget_kick_transfer() into its constituent
parts: scatter gather and linear buffers.

That way, it's easier to follow the code and focus
debug effort when one or the other fails.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:06 +03:00
Felipe Balbi 6b74289937 usb: dwc3: gadget: return 0 if we try to Wakeup in superspeed
Instead of returning -EINVAL when someone calls
__dwc3_gadget_wakeup() in speeds > highspeed, let's
return 0. There are no problems for the driver for
calling it in superspeed as we cleanly just return.

This avoids an annoying WARN_ONCE() always
triggering during superspeed enumeration with LPM
enabled.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:06 +03:00
Felipe Balbi b43bba96b9 usb: dwc3: gadget: remove udelay(1) when sending ep cmds
When we send an endpoint command, we want that to
complete as soon as possible, so let's remove the
unnecessary udelay(1) call.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:06 +03:00
Felipe Balbi 6aff483295 usb: dwc3: gadget: rely on sg_is_last() and list_is_last()
sg_is_last() and list_is_last() will encode the
required information for the driver to make
decisions WRT CHN and LST bits.

While at that, also replace '1' with 'true' for
consistency.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:05 +03:00
Felipe Balbi 4fae2e3e15 usb: dwc3: gadget: simplify __dwc3_gadget_kick_transfer()
as it turns out, we don't need the extra 'start_new'
argument as that can be inferred from DWC3_EP_BUSY
flag.

Because of that, we can simplify
__dwc3_gadget_kick_transfer() by quite a bit, even
allowing us to prepare more TRBs unconditionally.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:05 +03:00
Felipe Balbi c4233573f6 usb: dwc3: gadget: prepare TRBs on update transfers too
If we're updating transfers, we can also prepare as
many TRBs as we can fit in the ring. Let's start
doing that.

This patch 'solves' a limitation of how many TRBs we
can prepare when we're getting close the end of the
ring. Instead driver to prepare only up to end of
the ring, we check if we have space to wrap around
the ring properly.

Note that this only happens when our enqueue and
dequeue pointers are equal (which is the case for
bulk endpoints after an XferComplete event).

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:05 +03:00
Felipe Balbi 7f370ed0cf usb: dwc3: core: get rid of DWC3_PM_OPS macro
that macro is unnecessary and just adds pointless
obfuscation. Let's remove it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:04 +03:00
Felipe Balbi 9f8a67b65a usb: dwc3: gadget: fix gadget suspend/resume
Instead of trying hard to stay connected to the
host, it's best (and far easier) to disconnect from
the host already.

Anything relying on KEEP_CONNECT will just have that
ignored, but we don't have proper hibernation
implementation yet, so there are no regressions.

In any case, hibernation is only useful for runtime
PM, not system sleep.

While at that, also remove dwc3.dcfg which has been
rendered unnecessary.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:04 +03:00
Felipe Balbi d7be295243 usb: dwc3: gadget: re-factor ->udc_start and ->udc_stop
we will be re-using it for suspend/resume, so
instead of duplicating code, let's just re-factor
the functions so they can be re-used.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-20 12:30:04 +03:00
John Youn 50c763f8c1 usb: dwc3: Set the ClearPendIN bit on Clear Stall EP command
As of core revision 2.60a the recommended programming model is to set
the ClearPendIN bit when issuing a Clear Stall EP command for IN
endpoints. This is to prevent an issue where some (non-compliant) hosts
may not send ACK TPs for pending IN transfers due to a mishandled error
condition. Synopsys STAR 9000614252.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-06-01 09:53:42 +03:00
Peter Griffin 27a0faafdc usb: dwc3: st: Fix USB_DR_MODE_PERIPHERAL configuration.
Set USB3_FORCE_VBUSVALID when configured for USB_DR_MODE_PERIPHERAL
mode, as it is required to have a working setup.

This worked on the internal driver by relying on the reset
value of the syscfg register as the bits aren't explicity cleared
and set like the upstream driver.

Also add a comment about what setting this bit means.

Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-05-31 11:24:31 +03:00
Steinar H. Gunderson 4879efb34f usb: dwc3: exynos: Fix deferred probing storm.
dwc3-exynos has two problems during init if the regulators are slow
to come up (for instance if the I2C bus driver is not on the initramfs)
and return probe deferral. First, every time this happens, the driver
leaks the USB phys created; they need to be deallocated on error.

Second, since the phy devices are created before the regulators fail,
this means that there's a new device to re-trigger deferred probing,
which causes it to essentially go into a busy loop of re-probing the
device until the regulators come up.

Move the phy creation to after the regulators have succeeded, and also
fix cleanup on failure. On my ODROID XU4 system (with Debian's initramfs
which doesn't contain the I2C driver), this reduces the number of probe
attempts (for each of the two controllers) from more than 2000 to eight.

Signed-off-by: Steinar H. Gunderson <sesse@google.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Reviewed-by: Vivek Gautam <gautam.vivek@samsung.com>
Fixes: d720f057fd ("usb: dwc3: exynos: add nop transceiver support")
Cc: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-05-31 11:12:42 +03:00
Dan Carpenter 973986126a usb: dwc3: gadget: fix mask and shift order in DWC3_DCFG_NUMP()
In the original DWC3_DCFG_NUMP() was always zero.  It looks like the
intent was to shift first and then do the mask.

Fixes: 2a58f9c12b ('usb: dwc3: gadget: disable automatic calculation of ACK TP NUMP')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-05-03 14:32:07 -07:00
Greg Kroah-Hartman ce15bda101 usb: changes for v4.7 merge window
Here's the big USB Gadget pull request. This time
 not as large as usual with only 57 non-merge
 commits.
 
 The most important part here is, again, all the work
 on dwc3. This time around we're treating all
 endpoints (except for control endpoint) exactly the
 same. They all have the same amount of TRBs on the
 ring, they all treat the ring as an actual ring with
 a link TRB pointing to the head, etc.
 
 We're also helping the host side burst (on
 SuperSpeed GEN1 or GEN2 at least) for as long as
 possible until the endpoint returns NRDY.
 
 Other than this big TRB ring rework on dwc3, we also
 have a dwc3-omap DMA initialization fix, some extra
 debugfs files to aid in some odd debug sessions and
 a complete removal of our FIFO resizing logic.
 
 We have a new quirk for some dwc3 P3 quirk in some
 implementations.
 
 The rest is basically non-critical fixes and the
 usual cleanups.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJXIek2AAoJEIaOsuA1yqRE2+cP/iZzzRshn6atj4b0BaRzyk6k
 acK6YNs8pBgJMt9FaVWhDOlCfa/8hg5W+6Z5Ovpx4WPyJdZbYkoxJ0ZJGKYjYZ/y
 U8hUxpTJ2s2wZKXRKchzT90hQvNlHdg3u2okP2GK0Oa17/idcQf2w1+0Cscm/dqN
 Ur5HgukLe31/MrcPr49OuLkahSPfHUQlOn8i4AZyBTh9L8ouzKDCvzUt2ABoCRLE
 wPcMegJhks7FQ5fksXtLsfqhqAoHpYHlsZQcH35iV8wPdtSueAtZ8tS6t445XbX9
 vEsFq1ovpBMYfl/dwV6RBZiQTjZiGWaIdjOZMUcpbD03yXE2IC6l+mtE/wuhlnHu
 J0Rr4YmfS4g++J1+380NQGoreOBZ2u7pujQ4TAy399zsLD8LR3zOQK5IErILSfpO
 m6p3ElkGuAyHJKmo4CysSspXnnNGBp/fuTkYdPM9IJRJCe0YwnF/zsQd0OrNZ/Pm
 39f6woE2aBQaEzdn+3Nya9B2IWYi6SIheQXPg0HETX/hujZHJv1x758VO6+c7aeq
 nlhRlxSe8u8DKryBG43+F+myHaIz1p0Y2O3MzIlvRv0yw87QevJ4pAWptdMITaMh
 YpgSjDPw5y2z91AhK/Fv+AXswKaoWBc6EEzBirW6hQWllSp+7qWloA6vYXkdHDr7
 QajUBeXzNgXF8JfIos5H
 =7szP
 -----END PGP SIGNATURE-----

Merge tag 'usb-for-v4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: changes for v4.7 merge window

Here's the big USB Gadget pull request. This time
not as large as usual with only 57 non-merge
commits.

The most important part here is, again, all the work
on dwc3. This time around we're treating all
endpoints (except for control endpoint) exactly the
same. They all have the same amount of TRBs on the
ring, they all treat the ring as an actual ring with
a link TRB pointing to the head, etc.

We're also helping the host side burst (on
SuperSpeed GEN1 or GEN2 at least) for as long as
possible until the endpoint returns NRDY.

Other than this big TRB ring rework on dwc3, we also
have a dwc3-omap DMA initialization fix, some extra
debugfs files to aid in some odd debug sessions and
a complete removal of our FIFO resizing logic.

We have a new quirk for some dwc3 P3 quirk in some
implementations.

The rest is basically non-critical fixes and the
usual cleanups.
2016-04-28 09:32:39 -07:00
Felipe Balbi 2a58f9c12b usb: dwc3: gadget: disable automatic calculation of ACK TP NUMP
Now that we calculate DCFG.NUMP, we can disable
dwc3's automatic calculation so we maximize our
chances of very high throughtput through the use of
bursts.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 10:56:28 +03:00
Felipe Balbi 676e349744 usb: dwc3: gadget: update DCFG.NumP to max burst size
NumP field of DCFG register is used on NumP field of
ACK TP header and it tells the host how many packets
an endpoint can receive before waiting for
synchronization.

Documentation says it should be set to anything
<=bMaxBurst. Interestingly, however, this setting is
not per-endpoint how it should be (different
endpoints could have different burst sizes), but
things seem to work okay right now.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 10:47:29 +03:00
Konrad Leszczynski 7b9cc7a2b1 usb: dwc3: gadget: give better command return code
if Start Transfer command fails, let's try a little
harder to figure out why the command failed and give
slightly better return codes. This will be usefulf
or isochronous endpoints, at least, which could
decide to retry a given request.

Signed-off-by: Konrad Leszczynski <konrad.leszczynski@intel.com>
Signed-off-by: Rafal Redzimski <rafal.f.redzimski@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 09:02:00 +03:00
Heikki Krogerus ce046d323d usb: dwc3: pci: pass the platform device as a parameter to dwc3_pci_quirks()
For convenience, passing the dwc3 platform device as a
parameter to dwc3_pci_quirks() function.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 09:01:59 +03:00
Heikki Krogerus 474799f073 usb: dwc3: pci: make build-in device properties available
Setting the ACPI companion before calling dwc3_pci_quirks.
The ACPI companion will be set unconditionally as the
primary fwnode, overriding any previously set primary
fwnode. This will make sure that any build-in properties
added to the platform device will be added as the secondary
fwnode in cases where also ACPI companion exists.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 09:01:59 +03:00
Fei Yang ae41141376 usb: dwc3: ep0: sanity check test mode selector
In case host sends us an unsupported test mode, we
*must* stall this request. This will tell the host
that the selector is invalid and we won't put the
controller in unsupported test modes which could
have undetermined side-effects.

Signed-off-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-28 09:01:34 +03:00
Felipe Balbi 818ec3aba8 usb: dwc3: debugfs: dump out endpoint details
There's a bunch of information in the debug register
set from dwc3 which is useful in some debugging
scenarios. Let's dump them out in endpoint-specific
directories and designated files.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:57 +03:00
Felipe Balbi b058f3e8a3 usb: dwc3: core: add helper to extract trb type
This helper will be used later to convert trb type
into a human-readable string for debugfs.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:57 +03:00
Felipe Balbi cf6d867d3b usb: dwc3: core: add fifo space helper
this helper will be used, initially, to dump space
of different queues and fifos in dwc3 to
debugfs. Later, it'll be used to issue remote wakeup
when we want to start a transfer and there's
something in a TX FIFO.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:57 +03:00
Du, Changbin 4e9f311833 usb: dwc3: make dwc3_debugfs_init return value be void
Debugfs init failure is not so important. We can continue our job on
this failure. Also no break need for debugfs_create_file call failure.

Signed-off-by: Du, Changbin <changbin.du@intel.com>

[felipe.balbi@linux.intel.com :
	- remove out-of-memory message, we get that from OOM.
	- switch dev_err() to dev_dbg() ]

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:53 +03:00
Roger Quadros af566a0be6 usb: dwc3: omap: get rid of dma_status
dma_status bit flag is set but never really used
so get rid of it.

Reported-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:53 +03:00
Felipe Balbi 8e7046b71d usb: dwc3: gadget: don't interrupt when chained
It makes no sense to interrupt in the middle of
chained transfer. This patch just makes sure we
don't do that.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:52 +03:00
Felipe Balbi 052ba52efa usb: dwc3: gadget: remove newline from trace
trace already adds a newline character for us, we
don't need to do it ourselves.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:52 +03:00
Felipe Balbi 36b68aae8e usb: dwc3: gadget: use link TRB for all endpoint types
instead of limiting link TRB only to Isoc endpoints,
let's use it for all endpoint types, this way we are
more likely to transfer more data before a
XferComplete event.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:52 +03:00
Felipe Balbi 4faf75504a usb: dwc3: gadget: move % operation to increment helpers
By moving our % DWC3_NUM_TRB operation to the
increment helpers, the rest of the driver can be
simplified.

It's also a good practice to make sure we will have
a single place dealing with details about how to
increment our enqueue and dequeue pointers.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:51 +03:00
Felipe Balbi ef966b9d33 usb: dwc3: gadget: add trb enqueue/dequeue helpers
Add three little helpers which will aid in making
the code slightly easier to read. One helper
increments enqueue pointer, another increments
dequeue pointer and the last one tests if we're
dealing with the last TRB.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:11:46 +03:00
Felipe Balbi 70fdb273db usb: dwc3: get rid of DWC3_TRB_MASK
instead of using a bitwise and, let's rely on the %
operator since that's a lot more clear. Also, GCC
will optimize % 256 to nothing anyway.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-19 11:10:45 +03:00
Felipe Balbi c28f82595d usb: dwc3: switch trb enqueue/dequeue and first_trb_index to u8
We *know* that we have 1 PAGE (4096 bytes) for our
TRB poll. We also know the size of each TRB and know
that we can fit 256 of them in one PAGE. By using a
u8 type we can make sure that:

	enqueue++ % 256;

gets optimized to an increment only.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:49 +03:00
Felipe Balbi 5ef68c56e1 usb: dwc3: core: document struct dwc3_request
No functional changes. Merely adding useful
documentation for future readers.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:48 +03:00
Felipe Balbi 53fd88189e usb: dwc3: gadget: rename busy/free_slot to trb_enqueue/dequeue
This makes it clear that we're dealing with a queue
of TRBs. No functional changes. While at that, also
rename start_slot to first_trb_index for similar
reasons.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:46 +03:00
Grygorii Strashko 495dd5f781 usb: dwc3: omap: drop dma_mask configuration
The DWC3 OMAP driver supports DT-boot only, as result dma_mask will be
always configured properly from DT -
of_platform_device_create_pdata()->of_dma_configure(). More over,
dwc3-omap.c can be built as module and in this case it's unsafe to
assign local variable as dma_mask.

Hence, remove dma_mask configuration code.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:45 +03:00
Rajesh Bhagat e58dd35774 usb: dwc3: add disable receiver detection in P3 quirk
Some freescale QorIQ platforms require to disable receiver detection
in P3 for correct detection of USB devices. If GUSB3PIPECTL(DISRXDETINP3)
is set, Core will change PHY power state to P2 and then perform receiver
detection. After receiver detection, Core will change PHY power state to
P3. Same quirk would be added in dts file in future patches.

Signed-off-by: Sriram Dash <sriram.dash@nxp.com>
Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:44 +03:00
Felipe Balbi c36d8e947a usb: dwc3: gadget: put link to U0 before Start Transfer
Synopsys Databook says we should move link to U0
before issuing a Start Transfer command. We could
require the gadget driver to call
usb_gadget_wakeup() however I feel that changing all
gadget drivers to keep track of Link State and
conditionally call usb_gadget_wakeup() would be far
too much work. For now we will handle this at the
UDC level, but at some point composite.c should be
one handling this.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:42 +03:00
Felipe Balbi 218ef7b647 usb: dwc3: gadget: extract unlocked dwc3_gadget_wakeup()
we will need this from StartTransfer to make sure
link is in U0 before starting a transfer.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:41 +03:00
Felipe Balbi 2b0f11df84 usb: dwc3: gadget: clear SUSPHY bit before ep cmds
Synopsys Databook 2.60a has a note that if we're
sending an endpoint command we _must_ make sure that
DWC3_GUSB2PHY(n).SUSPHY bit is cleared.

This patch implements that particular detail.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:41 +03:00
Felipe Balbi c0ca324d09 usb: dwc3: gadget: combine return points into a single one
dwc3_send_gadget_ep_cmd() had three return
points. That becomes a pain to track when we need to
debug something or if we need to add more code
before returning.

Let's combine all three return points into a single
one just by introducing a local 'ret' variable.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:39 +03:00
Felipe Balbi dea520a4a2 usb: dwc3: gadget: pass ev_buff as cookie to irq handler
we don't plan on using multiple event buffers, but
if we find a good use case for it, this little trick
will help us avoid a loop in hardirq handler looping
for each and every event buffer.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 15:23:30 +03:00
Roger Quadros 9772b47a4c usb: dwc3: gadget: Fix suspend/resume during device mode
Gadget controller might not be always active during system
suspend/resume as gadget driver might not have yet been loaded or
might have been unloaded prior to system suspend.

Check if we're active and only then perform
necessary actions during suspend/resume.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 12:35:18 +03:00
Du, Changbin e6bdf8195b usb: dwc3: fix memory leak of dwc->regset
dwc->regset is allocated on dwc3_debugfs_init, and should
be released on init failure or dwc3_debugfs_exit. Btw,
The line "dwc->root = NULL" is unnecessary, so remove it.

Signed-off-by: Du, Changbin <changbin.du@intel.com>

[ felipe.balbi@linux.intel.com : add another err label for the new
	error condition ]

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 12:35:18 +03:00
Felipe Balbi 5c4ad318de usb: dwc3: core: fix PHY handling during suspend
we need to power off the PHY during suspend and
power it back on during resume.

Signed-off-by: Felipe Balbi <balbi@kernel.org>
[nsekhar@ti.com: fix call to usb_phy_set_suspend() in dwc3_suspend()]
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 12:35:17 +03:00
Felipe Balbi 45d49cb706 usb: dwc3: omap: fix up error path on probe()
Even if pm_runtime_get*() fails, we *MUST* call
pm_runtime_put_sync() before disabling PM.

While at it, remove superfluous dwc3_omap_disable_irqs()
in error path.

Signed-off-by: Felipe Balbi <balbi@kernel.org>
[nsekhar@ti.com: patch description updates]
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-18 12:35:17 +03:00
Felipe Balbi 696c8b1282 usb: dwc3: drop ev_buffs array
we will be using a single event buffer and that
renders ev_buffs array unnecessary. Let's remove it
in favor of a single pointer to a single event
buffer.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:39 +03:00
Felipe Balbi 660e9bde74 usb: dwc3: remove num_event_buffers
We never, ever route any of the other event buffers
so we might as well drop support for them.

Until someone has a real, proper benefit for
multiple event buffers, we will rely on a single
one. This also helps reduce memory footprint of
dwc3.ko which won't allocate memory for the extra
event buffers.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:39 +03:00
Felipe Balbi aa3342c8bb usb: dwc3: better name for our request management lists
request_list and req_queued were, well, weird naming
choices.

Let's give those better names and call them,
respectively, pending_list and started_list. These
new names better reflect what these lists are
supposed to do.

While at that also rename req->queued to req->started.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:38 +03:00
Felipe Balbi 8495036e98 usb: dwc3: increase maximum number of TRBs per endpoint
previously we were using a maximum of 32 TRBs per
endpoint. With each TRB being 16 bytes long, we were
using 512 bytes of memory for each endpoint.

However, SLAB/SLUB will always allocate PAGE_SIZE
chunks. In order to better utilize the memory we
allocate and to allow deeper queues for gadgets
which would benefit from it (g_ether comes to mind),
let's increase the maximum to 256 TRBs which rounds
up to 4096 bytes for each endpoint.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:37 +03:00
Felipe Balbi ca4d44ea2a usb: dwc3: gadget: always enable CSP
CSP bit of TRB Control is useful for protocols such
CDC EEM/ECM/NCM where we're transferring in blocks
of MTU-sized requests (usually MTU is 1500 bytes).

We know we will always have a short packet after two
(for HS) wMaxPacketSize packets and, usually, we
will have a long(-ish) queue of requests (for our
g_ether gadget, we have at least 10
requests).

Instead of always stopping the queue processing to
interrupt, giveback and restart, let's tell dwc3 to
interrupt but continue processing following request
if we have anything already pending in the queue.

This gave me a considerable improvement of 40% on my
test setup.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:37 +03:00
Felipe Balbi bc5081617f usb: dwc3: drop FIFO resizing logic
That FIFO resizing logic was added to support OMAP5
ES1.0 which had a bogus default FIFO size. I can't
remember the exact size of default FIFO, but it was
less than one bulk superspeed packet (<1024) which
would prevent USB3 from ever working on OMAP5 ES1.0.

However, OMAP5 ES1.0 support has been dropped by
commit aa2f4b16f8 ("ARM: OMAP5: id: Remove ES1.0
support") which renders FIFO resizing unnecessary.

Tested-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-14 09:24:37 +03:00
Grygorii Strashko adf9a3ab90 usb: dwc3: keystone: drop dma_mask configuration
The Keystone 2 supports DT-boot only, as result dma_mask will be
always configured properly from DT -
of_platform_device_create_pdata()->of_dma_configure(). More over,
dwc3-keystone.c can be built as module and in this case it's unsafe to
assign local variable as dma_mask.

Hence, remove dma_mask configuration code.

Cc: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-04-06 16:36:01 +03:00