Commit graph

1415 commits

Author SHA1 Message Date
Felipe Balbi 5c81ababec usb: dwc3: ep0: prevent starting transfers twice on ep0
In case we try to start an invalid test mode, we
will call dwc3_ep0_stall_and_restart() but we will
also call dwc3_ep0_out_start() which will start
a second transfer on ep0.

Let's prevent any problems by returning early in
the error case.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 19:30:49 +03:00
Felipe Balbi 9be2395186 usb: dwc3: gadget: remove duplicated code from __dwc3_gadget_ep_set_halt
whenever we want to stall ep0, we always call
dwc3_ep0_stall_and_restart() which makes sure
to send ep0state properly rendering the code
in __dwc3_gadget_ep_set_halt() duplicated.

Reported-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 17:09:28 +03:00
Felipe Balbi b4996a8631 usb: dwc3: rename res_trans_idx to resource_index
resource_index is more human readable. No
functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 14:00:45 +03:00
Felipe Balbi b511e5e76b usb: dwc3: gadget: split special cases of ep_queue()
It makes it easier to read and also avoids
setting DWC3_EP_PENDING_REQUEST just so the
next branch evaluates true.

No functional changes otherwise.

Cc: Pratyush Anand <pratyush.anand@st.com>
Cc: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 13:59:39 +03:00
Pratyush Anand 3daf74d78d usb: dwc3: remove WARN_ON from dwc_stop_active_transfer
Now we are sure that, if res_trans_idx is zero, then endpoint has been
stopped. So it's safe to just return if endpoint is already stopped. No
need to generate warning anymore.

While doing so, it's better to return when res_trans_idx is zero and
decrease one level of indentation.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>

[ balbi@ti.com: slightly changed commit log ]

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 13:59:26 +03:00
Pratyush Anand 58a0f23fdd USB: DWC3: Issue device soft reset before core soft reset
Synopsys specification clearly states under section "Device Power-On or
Soft Reset" that DCTL.CSftRst=1 should be first step.  So, just follow
what specification says.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-22 13:22:46 +03:00
Pratyush Anand 45627ac6a4 USB: DWC3: Put 100 ms delay for phy to be stable
Before taking core out of reset phy must be stable. So wait for 100ms
after clear phy reset.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-22 13:21:54 +03:00
Sachin Kamat 45c396ce6b usb: dwc3: Remove duplicate header file inclusion
module.h header file was included twice.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-22 13:21:43 +03:00
Pratyush Anand 1591633ed6 usb: dwc3: giveback all queued request when ep disabled or reset received
In case of ep_disable and reset interrupt is received and, still there
was at least one request queued for dma transfer, then endpoint is
stopped first. Once endpoint is stopped, callback for all queued
request must be called.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-15 14:43:44 +03:00
Pratyush Anand e8d4e8be86 usb: dwc3: fix giveback of queued request in ep_dequeue
In case of ep_dequeue , if dequeued request was submitted for dma
transfer, then endpoint is stopped. Once endpoint is stooped, callback
for the dequeued request must be called.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-15 14:42:49 +03:00
Felipe Balbi b785ea7ce6 usb: gadget: composite: fix ep->maxburst initialization
bMaxBurst field on endpoint companion descriptor
is supposed to contain the number of burst minus
1. When passing that to controller drivers, we
should be passing the real number instead (by
incrementing 1).

While doing that, also fix the assumption on
dwc3 that value comes decremented by one.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-12 13:30:25 +03:00
Pratyush Anand dcae3573b9 usb: dwc3: resume phy during gadget initialization on recent cores
It is needed to enumerate recent cores like 2.10a.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 17:37:41 +03:00
Pratyush Anand 7e39b817ee usb: dwc3: Correct DWC3_DCTL_HIRD_THRES definition
The definition of DWC3_DCTL_HIRD_THRES macro is
completely wrong. It will only work for when we
want to read the register's contents for that bitfield.

Change the macro so that it can be used to writing to
the register, and when we need to read, we can add
extra right shift of 24 bits.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>

[ balbi@ti.com: add a commit log ]

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 16:56:10 +03:00
Felipe Balbi 3336abb5b6 usb: dwc3: gadget: ignore endpoint IRQs when endpoint is disabled
By the time we're disabling the endpoint, HW
could already have posted more events to our
event buffer. In that case, we will receive
endpoint events for a disabled endpoint.

In order to protect ourselves from that situation,
we simply ignore endpoint interrupts whenever
the endpoint is disabled.

Tested-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 11:22:32 +03:00
Felipe Balbi 1e2360eada usb: dwc3: gadget: don't call stop_active_transfers() on disconnect
In case we get disconnected, we will call gadget
driver's disconnect method, which should make
sure to disable all endpoints. At that point
we will call stop_active_transfers() to make
sure we didn't leave any pending request on the
controller.

Tested-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 11:22:32 +03:00
Felipe Balbi ea53b8828c usb: dwc3: gadget: don't wait for ep cmd IRQ
That IRQ is causing way too much trouble. We have
a different handling which was agreed with IP
provider and has been tested with FPGA and OMAP5.

Tested-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 11:22:24 +03:00
Felipe Balbi 6dbc10c61d usb: dwc3: gadget: drop useless code
We never set CMDIOC bit for Start Transfer
command, so that code will never be used.

Tested-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-06 11:21:23 +03:00
Pratyush Anand 70b674bfeb usb: dwc3: Fix break from cleanup request loop
If event status says that its last completed TRB but TRB is still owned
by HW then break from the loop, because we are not going to get correct
TRB status from trb control/size register.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-04 18:23:19 +03:00
Pratyush Anand d6d6ec7b88 usb: dwc3: Fix missed isoc IN transaction
If an IN transfer is missed on isoc endpoint, then driver must insure
that next ep_queue is properly handled.
This patch fixes this issue by starting a new transfer for next queued
request.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-04 18:23:04 +03:00
Pratyush Anand d05b81824e USB: DWC3: Correct DWC3_DSTS_SOFFN_MASK definition
SOF Number is bit16:3 of DSTS. Correct the mask accordingly.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-04 18:17:29 +03:00
Pratyush Anand 389f2828bb USB: DWC3: Correct DWC3_TRB_SIZE_TRBSTS definition
Correct  define for DWC3_TRB_SIZE_TRBSTS.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-04 18:17:20 +03:00
Pratyush Anand 206dd69a62 USB: DWC3: Generate interrupt on each TRB as default option
Currently in case of isoc, interrupt is programmed after each
TRB_NUM/4 ie 8th TRB. A TRB is programmed against each submitted
request from gadget. If we do not want to limit the minimum number of
necessary request to be submitted from gadget then we must receive
interrupt on each TRB submission. There can be such situation with a
gadget working with ping-pong buffer.

If a gadget does not want to receive interrupt after each request
completion then it may set no_interrupt flag.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-04 18:17:04 +03:00
Felipe Balbi 85a781019b usb: dwc3: ep0: rename dwc3_ep0_complete_req to dwc3_ep0_complete_status
That's a much more intuitive name as that function
is only called at the completion of a Status Phase.

It also matches dwc3_ep0_complete_data() for
the completion of Data Phase.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:28 +03:00
Felipe Balbi c8cf7af452 usb: dwc3: ep0: be careful with endianness on SetSEL command
USB is always little endian, but this driver
could run on non little endian cpus. Let's
be carefull with that.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:27 +03:00
Felipe Balbi ef21ede65e usb: dwc3: ep0: simplify error handling on dwc3_ep0_inspect_setup
There's no need for returning early. Instead,
we can call dwc3_ep0_stall_and_restart()
conditionally.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:27 +03:00
Gerard CAUVY 5cbe8c220c usb: dwc3: gadget: move AcceptU1Ena and AcceptU2Ena to Reset IRQ
According to the databook, the DWC3 Core will
reset those bits to 0 on USB Bus Reset. This
means we must re-enable those bits on every
reset interrupt.

Because we will always get a Reset interrupt
after loading a gadget driver, we can, instead
of re-enabling something that was just lost,
move the handling of those bits to the Reset
Interrupt.

This patch fixes USB30CV U1/U2 Test.

Signed-off-by: Gerard CAUVY <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:26 +03:00
Felipe Balbi c4430a2694 usb: dwc3: gadget: disable U1/U2 on disconnect
If we get a disconnect IRQ, we should take
the core out of low power mode so we can
reconnect afterwards.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:25 +03:00
Felipe Balbi fcc023c726 usb: dwc3: gadget: prevent DCTL register corruption
If we don't read out the contents of the register
(in order to reinitialize 'reg' variable) we will
be writing unknown contents to the DCTL register
whenever we try to use dwc3_gadget_wakeup() function.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:25 +03:00
Paul Zimmerman 7acd85e0eb usb: dwc3: core: make sure evt->lpos is correctly initialized
The same event buffers will be reused when coming
out of hibernation, so we must reinitialize them
properly to avoid any mistakes.

While at that, also take dwc3_event_buffers_setup()
out of __devinit section.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:24 +03:00
Paul Zimmerman 802fde983e usb: dwc3: support new revisions of DWC3 core
Recent cores (>= 1.94a) have a set of new features,
commands and a slightly different programming model.

This patch aims to support those changes.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:23 +03:00
Paul Zimmerman d7a46a8dfc usb: dwc3: gadget: rename phy_power() to phy_suspend()
those two functions don't power PHYs, they simply
put them in suspend state. Rename to reflect better
what functions actually do.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:23 +03:00
Paul Zimmerman aed430e513 usb: dwc3: gadget: reinitialize retries
retries is used twice without being reinitialized.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:22 +03:00
Paul Zimmerman 2c61a8efce usb: dwc3: add definitions for new registers
This patch adds definitions for some new registers that have been
added to later versions of the controller, up to v2.10a.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:21 +03:00
Felipe Balbi a092532483 usb: dwc3: gadget: remove trailing semicolon
That semicolon doesn't do anything, it's not
needed and should be removed.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:21 +03:00
Felipe Balbi 33b84c2c06 usb: dwc3: ep0: fix a typo in comment
s/has/have. No functional changes, just
a typo fix on a code comment.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:20 +03:00
Felipe Balbi 788a23f496 usb: dwc3: ep0: align on function signature
On our Transfer Not Ready handlers, only
dwc3_ep0_do_control_status() had a different
list of parameters.

Align on the parameters in order to keep consistency.

No functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:19 +03:00
Felipe Balbi c74c6d4a02 usb: dwc3: ep0: switch over to IS_ALIGNED
IS_ALIGNED provides a much faster operation for
checking proper size alignment then a modulo
operation. Let's use it.

Reported-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:19 +03:00
Felipe Balbi a0807881af usb: dwc3: handle pending unaligned Control OUT data phase correctly
When DWC3_EP_PENDING_REQUEST flag is set for a Control OUT Data
phase transfer, we would be missing the proper handling for
unaligned OUT requests, thus hanging a transfer.

Since proper handling is already done on dwc3_ep0_do_control_data(),
we simply re-factor that function so it can be re-used from
__dwc3_gadget_ep0_queue().

Reported-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:18 +03:00
Felipe Balbi 4552a0ca61 usb: dwc3: fix a WARN and a comment
we're now have DWC3_EP0_BOUNCE_SIZE to tell
us the actual size of the bufer. Let's use that
instead of ep0 wMaxPacketSize.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:17 +03:00
joseph daniel b8cacf33f0 usb: dwc3: Fix the dwc3 dependency
The warning shown up when ran with randconfig,

warning: (USB_DWC3) selects USB_XHCI_PLATFORM which has unmet direct dependencies (USB_SUPPORT && USB_XHCI_HCD)

Signed-off-by: joseph daniel <josephdanielwalter@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-05-11 15:17:31 -07:00
Greg Kroah-Hartman 23063b378d usb: dwc3: patches for v3.5 merge window
This pull request contains one workaround for a Silicon
 Issue found on all RTL releases prior to 2.20a, which
 would cause a metastability state on Run/Stop bit.
 
 We also have some patches implementing a few extra Standard
 requests introduced by USB3 spec (Set SEL and Set Isoch Delay),
 as well as one patch, which has been pending for a long time,
 implementing LPM support.
 
 Last, but not least, we are splitting the host address space
 out of the dwc3 core driver otherwise xHCI won't be able to
 request_mem_region() its own address space. This patch is
 only needed because we are (as we should) re-using the xHCI
 driver, which is a completely separate module.
 
 Together with these three big changes, come a few extra preparatory
 patches which most move code around, define macros and so on, as
 well as a fix for Isochronous transfers which hasn't been triggered
 before.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJPo7lXAAoJEIaOsuA1yqRESaIP/AgxZIfOAUbPx0GWLnhub3qr
 SxaUplweFc9q4KXRLn0kGdY9QArPR3bqW9g8KOTiRCBYRtjpACyMjibAUaAht81h
 +vLdPt87Slj2c14t1uguWFvgCUYQOCugkVvDIjRg9PCLIuTahm4cIBFqL3RJOHFf
 9WCd8JjH9ahr85ZtoCBk9B5bDNn71nS+Yh6/8+Ab90AE4vZ6t8Xx3+wLTHy2CBYQ
 UH1o61QZreAJ0J3OiUobjqrVbYwz6TM0dFYMjA6ko+OiPRhVOj8/C8aNl/U1whRm
 +7jjJiWO9aHp+Tu2OAQOBF6ydc3ZLBEiCl9RiE+O9MppmtOykzkTHFm1ZXatCEY7
 UUYOy43VXLNlHoz8nidNw6P25hAwwlSijzlyawpihKbIaE8le2MpE6I00AlciM2q
 BEo4LpluC8Rr6CUUr5W9dPZUexRlzxdAL5nQSJUnJgfEPphpP3x7dWTxUZBaWjq6
 akqjgGqVj1QKwMnqL4GILtRgdqWj6WYrw67fYVLHqj8QQla4cgXQ2sHp9/R0imvT
 nmjiL5ZiuIWWr965DgVHZwqIkdvMpSQb99a1xmptw8lFDGkVJDCssPDdEErbBMwy
 KmOSaqKeg/Yway05i+Pwo/NUKHQSZeiyuguzniMrF7iYFF1/2hVYRgfpH4V+95w/
 Xrnz4uH2YJGQGPddf87P
 =qgf/
 -----END PGP SIGNATURE-----

Merge tag 'dwc3-for-v3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

usb: dwc3: patches for v3.5 merge window

This pull request contains one workaround for a Silicon
Issue found on all RTL releases prior to 2.20a, which
would cause a metastability state on Run/Stop bit.

We also have some patches implementing a few extra Standard
requests introduced by USB3 spec (Set SEL and Set Isoch Delay),
as well as one patch, which has been pending for a long time,
implementing LPM support.

Last, but not least, we are splitting the host address space
out of the dwc3 core driver otherwise xHCI won't be able to
request_mem_region() its own address space. This patch is
only needed because we are (as we should) re-using the xHCI
driver, which is a completely separate module.

Together with these three big changes, come a few extra preparatory
patches which most move code around, define macros and so on, as
well as a fix for Isochronous transfers which hasn't been triggered
before.

[ resolved conflicts and build error in drivers/usb/dwc3/gadget.c - gregkh]
2012-05-07 10:09:55 -07:00
Ido Shayevitz 16e78db720 usb: dwc3: Update dwc3 udc to use usb_endpoint_descriptor inside the struct usb_ep
Remove redundant pointer to struct usb_endpoint_descriptor.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-04 15:52:52 +03:00
Felipe Balbi 3ef35fafdc usb: dwc3: define DWC3_EP0_BOUNCE_SIZE
to avoid sprinkling magic constants on the driver
we define a constant to be used when allocating
setup_buffer and ep0_bounce buffer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-04 12:58:14 +03:00
Paul Zimmerman f898ae09a0 usb: dwc3: gadget: issue Update Transfer command after queuing isoc request
Issue an Update Transfer command after queuing a request to an isoc
EP with an active transfer. This is required according to the dwc3
databook. Pratyush Anand reports that this fixes a problem he was
having with Isoc IN transfers.

Tested-by: Pratyush Anand<pratyush.anand@st.com>
Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:54:25 +03:00
Felipe Balbi c12a0d862a usb: dwc3: ep0: implement support for Set Isoch Delay request
This is basically a noop for DWC3. We don't have
to do anything. Basically we test if the request
parameters are correct, cache the Isochronous
Delay and return success.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:43:09 +03:00
Felipe Balbi 7ed6d227c3 usb: dwc3: gadget: increase setup buffer size
We want to re-use that buffer for other USB
requests, so let's increase it to biggest
wMaxPacketSize for ep0 so it works for everything
we have in mind.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:43:08 +03:00
Felipe Balbi 865e09e716 usb: dwc3: ep0: implement Set SEL support
This patch implements Set SEL Standard Request
support for dwc3 driver. It needs to issue a command
to the controller passing the timing we received on
the data phase of the Set SEL request.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:43:08 +03:00
Felipe Balbi b09bb64239 usb: dwc3: gadget: implement Global Command support
This will be used by the ep0 layer for implementing
Set SEL Standard Request.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:42:56 +03:00
Sebastian Andrzej Siewior e6a3b5e288 usb: dwc3: ep0: add LPM handling
On device loading the driver enables LPM and the acceptance of U1 and U2
states. The [Set|Clear]Feature requests for "U1/U2" are forwarded
directly to the hardware and allow / forbid the initiation of the low
power links.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-30 11:31:21 +03:00
Ido Shayevitz 51249dca62 usb: dwc3: core: split host address space
This fix prevents a problem with dwc3 and host mode where
we were requesting the entire memory region in dwc3/core.c,
thus preventing xhci-plat from ever ioremapping its own address space.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-24 15:37:04 +03:00
Ido Shayevitz ab5e59dbdb usb: dwc3: omap: add dwc3_omap_readl/writel functions
We separate between dwc3-omap helper functions to dwc3-core helper
functions. This will allow us to change the helper functions
implementation according to each module need.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-24 15:37:01 +03:00
Felipe Balbi 07e7f47b6d usb: dwc3: workaround: metastability state on Run/Stop bit
All revisions prior to 2.20a have a known issue which
causes metastability state on Run/Stop bit if we
configure the core to work on any of the USB2-only
speeds.

The suggested workaround is just to never configure the
core to anything other than SuperSpeed.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-11 13:12:17 +03:00
Felipe Balbi 1522d7034d usb: dwc3: core: define more revision macros
We have other revisions already released, let's
define revision macros for those so we can do
runtime detection of known erratas.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-11 13:12:16 +03:00
Anton Tikhomirov 64b6c8a701 usb: dwc3: Free event buffers array
Array should be freed together with event buffers, since it was
allocated dynamically.

Signed-off-by: Anton Tikhomirov <av.tikhomirov@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 19:11:46 +03:00
Gerard Cauvy ecb07797ff usb: dwc3: ep0: add a default case for SetFeature command
Without this default case returning an error,
thus replying with a stall, we would fail
USB30CV TD 9.11 Bad Feature test case.

Cc: stable@vger.kernel.org
Signed-off-by: Gerard Cauvy <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 19:11:31 +03:00
Felipe Balbi cd423dd363 usb: dwc3: ep0: increment "actual" on bounced ep0 case
due to a HW limitation we have a bounce buffer for ep0
out transfers which are not aligned with MaxPacketSize.

On such case we were not increment r->actual as we should.

This patch fixes that mistake.

Cc: stable@vger.kernel.org
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 12:21:44 +03:00
Moiz Sonasath 566ccdda07 usb: dwc3: ep0: Handle requests greater than wMaxPacketSize
To allow ep0 out transfers of upto bounce buffer size
instead of maxpacketsize, use the transfer size as multiple
of ep0 maxpacket size.

Cc: stable@vger.kernel.org
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>
Signed-off-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 12:21:43 +03:00
Linus Torvalds ed378a52da USB merge for 3.4-rc1
Here's the big USB merge for the 3.4-rc1 merge window.
 
 Lots of gadget driver reworks here, driver updates, xhci changes, some
 new drivers added, usb-serial core reworking to fix some bugs, and other
 various minor things.
 
 There are some patches touching arch code, but they have all been acked
 by the various arch maintainers.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (GNU/Linux)
 
 iEYEABECAAYFAk9njL8ACgkQMUfUDdst+ylQ9wCfbBOnIT01lGOorkaE9pom0hhk
 HfMAoKq1xzCR2B+OS3UMyUQffk+Ri9Ri
 =KIQ2
 -----END PGP SIGNATURE-----

Merge tag 'usb-3.3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB merge for 3.4-rc1 from Greg KH:
 "Here's the big USB merge for the 3.4-rc1 merge window.

  Lots of gadget driver reworks here, driver updates, xhci changes, some
  new drivers added, usb-serial core reworking to fix some bugs, and
  other various minor things.

  There are some patches touching arch code, but they have all been
  acked by the various arch maintainers."

* tag 'usb-3.3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (302 commits)
  net: qmi_wwan: add support for ZTE MF820D
  USB: option: add ZTE MF820D
  usb: gadget: f_fs: Remove lock is held before freeing checks
  USB: option: make interface blacklist work again
  usb/ub: deprecate & schedule for removal the "Low Performance USB Block" driver
  USB: ohci-pxa27x: add clk_prepare/clk_unprepare calls
  USB: use generic platform driver on ath79
  USB: EHCI: Add a generic platform device driver
  USB: OHCI: Add a generic platform device driver
  USB: ftdi_sio: new PID: LUMEL PD12
  USB: ftdi_sio: add support for FT-X series devices
  USB: serial: mos7840: Fixed MCS7820 device attach problem
  usb: Don't make USB_ARCH_HAS_{XHCI,OHCI,EHCI} depend on USB_SUPPORT.
  usb gadget: fix a section mismatch when compiling g_ffs with CONFIG_USB_FUNCTIONFS_ETH
  USB: ohci-nxp: Remove i2c_write(), use smbus
  USB: ohci-nxp: Support for LPC32xx
  USB: ohci-nxp: Rename symbols from pnx4008 to nxp
  USB: OHCI-HCD: Rename ohci-pnx4008 to ohci-nxp
  usb: gadget: Kconfig: fix typo for 'different'
  usb: dwc3: pci: fix another failure path in dwc3_pci_probe()
  ...
2012-03-20 11:26:30 -07:00
Felipe Balbi 28f1a0d946 usb: dwc3: pci: fix another failure path in dwc3_pci_probe()
When applying commit 7d26b58 (fix failure path in
dwc3_pci_probe()), I mistakenly left out one of the
possible failures where we would return success even
on the error case.

This patch fixes that mistake.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-13 14:24:08 -07:00
Tobias Klauser b1116dcc63 usb: dwc3: core: Convert to module_platform_driver
Use the module_platform_driver macro.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-02 16:20:28 -08:00
Greg Kroah-Hartman 3d71769014 usb: dwc3: changes for v3.4 merge window
Here are the changes for v3.4 merge window.
 
 It includes a new glue layer for Samsung's Exynos platform, a simplification of
 memory management on DWC3 driver by using dev_xxx functions, a few
 optimizations to IRQ handling by dropping memcpy() and using bitshifts, a fix
 for TI's OMAP5430 TX Fifo Allocation, two fixes on USB2 test mode
 implementation (one on debugfs and one on ep0), and several minor changes such
 as whitespace cleanups, simplification of a few parts of the code, decreasing a
 long delay to something a bit saner, dropping a header which was included twice
 and so on.
 
 The highlight on this merge is the support for Samsung's Exynos platform,
 increasing the number of different users for this driver to three.
 
 Note that Samsung Exynos glue layer will only compile on platforms which
 provide implementation for the clk API for now. Once Samsung supports
 pm_runtime, that limitation can be dropped from the Makefile.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJPUJ2bAAoJEIaOsuA1yqREwOgP/2bG6rvPBMlGmXvvR40HNUXJ
 jXzkXcrTBrO172Fxl2P+mAgNFggMURrOdiyXwl7+2Ib0NM7sS9jwikuxos8DwuQv
 Ci0GgJtQySORIl5Sw29uB1W65aV2ieNBh/fN/52LwVOQYITt89GYK1DsRUWRN2V/
 0bw3OepckiAFN5gWRykIYIUXZs8DQa+L1qYc6fexZk7zZ+XrjdNba8RzGzsyUelD
 BB0eOj4E2Mda6Yp7kyiBRuTXVAUChNa5J0iCvXSnR8l2wppfXlmD2UD4Sfo/yxd5
 q25/rm1e1A4iKcPjSkhzTayQKrLWEgCxZK69sZXlEPG9qhA3iMjWDNBvEy6cV4bc
 bFFjwXAObX+bm+QDYqcD66iUZTPzEW149W/e5B7+XGk09NcCs/wqoA1jEgCLEHnv
 3rsG0RvsgtMdwmBYpO8zrhJPTFa6NAq9Qc4nLj3WefXP9Vkl5gpfneIcgYKB6x0q
 LHRQsLHBWl/hXClWAPflDJaGQqEt6hjkA3IqV03yTlMNuYxDNJy931J6Cz9a9Lu5
 Gr2By/bHVcADmt8WzituQsnLvQIzLLGl0U0lKpdl24I52roqMkZVj7XaWDojLVSq
 HZnbk+c3PdEXVIDNCz1QnCY/QojEhKkeR23LP3YD8L9KxcOu8DNyL1RKdYqx3Cnv
 vrqerutPusT6kGvaRQIk
 =4Z2+
 -----END PGP SIGNATURE-----

Merge tag 'dwc3-for-v3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

usb: dwc3: changes for v3.4 merge window

Here are the changes for v3.4 merge window.

It includes a new glue layer for Samsung's Exynos platform, a simplification of
memory management on DWC3 driver by using dev_xxx functions, a few
optimizations to IRQ handling by dropping memcpy() and using bitshifts, a fix
for TI's OMAP5430 TX Fifo Allocation, two fixes on USB2 test mode
implementation (one on debugfs and one on ep0), and several minor changes such
as whitespace cleanups, simplification of a few parts of the code, decreasing a
long delay to something a bit saner, dropping a header which was included twice
and so on.

The highlight on this merge is the support for Samsung's Exynos platform,
increasing the number of different users for this driver to three.

Note that Samsung Exynos glue layer will only compile on platforms which
provide implementation for the clk API for now. Once Samsung supports
pm_runtime, that limitation can be dropped from the Makefile.

Conflicts:
	drivers/usb/dwc3/gadget.c
2012-03-02 15:56:33 -08:00
Paul Zimmerman c2df85ca31 usb: dwc3: clear 'res_trans_idx' as soon as it becomes invalid
Transfer resource index is cleared in hardware when XFERCOMPLETE
event is generated, so clear the driver's res_trans_idx variable
immediately after that event is received. The upcoming hibernation
patches depend on this change.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:11 +02:00
Paul Zimmerman 249a456930 usb: dwc3: take lock while modifying flags
dwc3_gadget_ep_set_wedge() and dwc3_gadget_set_selfpowered() were
modifying dwc->flags/dwc->is_selfpowered without taking the lock.
Since those modifications are non-atomic, that could cause other
flags to be corrupted. Fix them both to take the lock.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:10 +02:00
Paul Zimmerman aee63e3cb6 usb: dwc3: shorten long delay in dwc3_gadget_set_link_state()
The loop in dwc3_gadget_set_link_state() was using a udelay(500),
which is a long time to delay in interrupt context. Change it to
udelay(5) and increase the loop count to match.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:09 +02:00
Paul Zimmerman 7d26b58735 usb: dwc3: pci: fix failure path in dwc3_pci_probe()
dwc3_pci_probe() would return success even if the calls to
dwc3_get_device_id() or platform_device_alloc() fail, fix that.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:07 +02:00
Paul Zimmerman 3e87c42a29 usb: dwc3: replace hard-coded constant in DWC3_GCTL_SCALEDOWN(3)
Define DWC3_GCTL_SCALEDOWN_MASK and use it in place of
DWC3_GCTL_SCALEDOWN(3).

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:06 +02:00
Paul Zimmerman 9bafa56c7c usb: dwc3: fix bogus test in dwc3_gadget_start_isoc
Zero is a valid value for a microframe number. So remove the bogus
test for non-zero in dwc3_gadget_start_isoc().

Cc: stable@vger.kernel.org
Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:05 +02:00
Anton Tikhomirov 27a78d6a28 usb: dwc3: use proper function for setting endpoint name
It's wrong to use the size of array as an argument for strncat.
Memory corruption is possible. strlcat is exactly what we need here.

Cc: stable@vger.kernel.org
Signed-off-by: Anton Tikhomirov <av.tikhomirov@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:04 +02:00
Paul Zimmerman 8d62cd65d7 usb: dwc3: gadget: don't wrap around the TRB poll on non-ISOC
If we have a non-ISOC endpoint, we will not have a Link TRB
pointing to the beginning of the TRB pool. On such endpoints,
we don't want to let the driver wrap around the TRB pool
otherwise controller will hang waiting for a valid TRB.

Cc: stable@vger.kernel.org
Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:03 +02:00
Dan Carpenter 075cd14d2a usb: dwc3: make dwc3_get_device_id() return the id
We always return zero instead of the id we found.

Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:02 +02:00
Paul Zimmerman 1d04679395 usb: dwc3: clean up whitespace damage, typos, missing parens, etc.
trivial patch, no functional changes

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:01 +02:00
Danny Kukawka 2cd0e85121 usb: dwc3: linux/module.h included twice
drivers/usb/dwc3/core.c and drivers/usb/dwc3/dwc3-omap.c
included 'linux/module.h' twice, remove the duplicates.

Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:00 +02:00
Chanho Park 802ca85067 usb: dwc3: use devm_xxx functions
This patch enables to use devm_xxx functions during probing driver.
The devm_xxx series functions are able to release resource when the
driver is detatched. We can remove several codes to release resources
in the probe function.

Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:11:59 +02:00
Anton Tikhomirov d28a9689c9 usb: dwc3: Add Exynos Specific Glue layer
Adds Exynos Specific Glue layer to support USB peripherals
on Samsung Exynos5 chips.

[ balbi@ti.com : prevent compilation of Exynos glue layer
	on platforms which don't provide clk API implementation ]

Signed-off-by: Anton Tikhomirov <av.tikhomirov@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:11:28 +02:00
Greg Kroah-Hartman f9b0f51709 This merge is rather big. Here's what it contains:
For am5536udc we have just simple coding style fixes. Nothing that has any
 potential to cause any issues going forward.
 
 With mv_udc, there's only one single change removing an unneeded NULL check.
 
 at91_udc also only saw a single change this merge window, and that's only
 removing a duplicated header.
 
 The Renesas controller has a few more involved changes. Support for SUDMAC was
 added, there's now a special handling of IRQ resources for when the IRQ line is
 shared between Renesas controller and SUDMAC, we also had a bug fix where
 Renesas controller would sleep in atomic context while doing DMA transfers from
 a tasklet. There were also a set of minor cleanups.
 
 The FSL UDC also had a scheduling in atomic context bug fix, but that's all.
 
 Thanks to Sebastian, the dummy_hcd now works better than ever with support for
 scatterlists and streams. Sebastian also added SuperSpeed descriptors to the
 serial gadgets.
 
 The highlight on this merge is the addition of a generic API for mapping and
 unmapping usb_requests. This will avoid code duplication on all UDC controllers
 and also kills all the defines for DMA_ADDR_INVALID which UDC controllers
 sprinkled around. A few of the UDC controllers were already converted to use
 this new API.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJPTeaWAAoJEIaOsuA1yqREdT8QAK8ob6RqnZs9en7NdaBTq18G
 qPtdheAZ9TkWxv+JE69Nqq1DuLO93+ZqLt88kaIVp/jTg+MxZ4qeANe9Nga0Qr+U
 Qc4d9HOkKsLGC+E45TApAMCQkPZ3DxbObJRUeJI7DBefPJ+MzQYAeeQtzjEeKKf8
 hGY5kh5FdXds/TlTePwWuyVoe09grgoy7cvptIVJRZiWx8+n9PZeMiKe+vAmQDEc
 +V0FfOMZLcSY9Oi14faYDrOFIV5cjBxnwnBpinOYx5TArxep35HSynt/mJtW2a7/
 lcdpbS4Hn35LJQWcYl0onx0GNgvI/YDYg9V6vrSjoBVU7vZ/7slZ896yjiovmAsc
 KQXxKoqss80sd+rYUe/si/Ues+koN9HztucG//+9cuS2ZCnDydHMJHonMBXUZguv
 o2gzQwjRCUOcGLj+vnSAFiBAGZwAZV99rA2VgIz3dSyegDN+SverXJscOuvzzW/V
 6yERLjbmxwtIQczlUMPQgGE9gSMYKRzyDV4JlO1xtfsBwcVc0c4YE+ZnWOeEAbOa
 evrI/3RGjP12rY+eyntlN2ZpHq2ZJnS7guDjooi0mGK16LWeQh8h0zD24XoUiwnr
 nhkv+eqWJQXV2iQcyezO1TLnxhZ7LZdtfkYg5MH/VqGIuh6SNQdhew4bijUuKKsq
 +aLPREySYHdIloQjPBe/
 =RR+f
 -----END PGP SIGNATURE-----

Merge tag 'gadget-for-v3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

USB: Gadget: changes for 3.4

This merge is rather big. Here's what it contains:

For am5536udc we have just simple coding style fixes. Nothing that has any
potential to cause any issues going forward.

With mv_udc, there's only one single change removing an unneeded NULL check.

at91_udc also only saw a single change this merge window, and that's only
removing a duplicated header.

The Renesas controller has a few more involved changes. Support for SUDMAC was
added, there's now a special handling of IRQ resources for when the IRQ line is
shared between Renesas controller and SUDMAC, we also had a bug fix where
Renesas controller would sleep in atomic context while doing DMA transfers from
a tasklet. There were also a set of minor cleanups.

The FSL UDC also had a scheduling in atomic context bug fix, but that's all.

Thanks to Sebastian, the dummy_hcd now works better than ever with support for
scatterlists and streams. Sebastian also added SuperSpeed descriptors to the
serial gadgets.

The highlight on this merge is the addition of a generic API for mapping and
unmapping usb_requests. This will avoid code duplication on all UDC controllers
and also kills all the defines for DMA_ADDR_INVALID which UDC controllers
sprinkled around. A few of the UDC controllers were already converted to use
this new API.

Conflicts:
	drivers/usb/dwc3/gadget.c
2012-03-01 09:20:28 -08:00
Felipe Balbi 0fc9a1be09 usb: dwc3: gadget: use generic map/unmap routines
those routines have everything we need to map/unmap
USB requests and it's better to use them.

In order to achieve that, we had to add a simple
change on how we allocate and use our setup buffer;
we cannot allocate it from coherent anymore otherwise
the generic map/unmap routines won't be able to easily
know that the GetStatus request already has a DMA
address.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-28 14:48:54 +02:00
Ido Shayevitz f9c56cdd39 usb: gadget: Clear usb_endpoint_descriptor inside the struct usb_ep on disable
This fix a bug in f_serial, which expect the ep->desc to be NULL after
disabling an endpoint.

Cc: stable@vger.kernel.org
Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-24 12:22:38 +02:00
Felipe Balbi f6bafc6a1c usb: dwc3: convert TRBs into bitshifts
this will get rid of a useless memcpy on
IRQ handling, thus improving driver performance.

Tested with OMAP5430 running g_mass_storage on
SuperSpeed and HighSpeed.

Note that we are removing the little endian access
of the TRB and all accesses will be in System endianness,
if there happens to be a system in BE, bit 12 of GSBUSCFG0
should be set so that HW does byte invariant BE accesses
when fetching TRBs.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-13 16:02:06 +02:00
Gerard Cauvy 3b637367ae usb: dwc3: ep0: fix SetFeature(TEST)
When host requests us to enter a test mode,
we cannot directly enter the test mode before
Status Phase is completed, otherwise the core
will never be able to deliver the Status ZLP
to host, because it has already entered the
requested Test Mode.

In order to fix the error, we move the actual
start of Test Mode right after we receive
Transfer Complete event of the status phase.

Signed-off-by: Gerard Cauvy <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-10 13:11:46 +02:00
Gerard Cauvy 090725431b usb: dwc3: debugfs: fix off by one when entering testmode
When implementing the USB2 testmode support via debugfs,
Felipe has committed a mistake when counting the number
of letters of some of the strings, resulting on an off
by one error which prevented some of the Test modes to
be entered properly.

This patch, fixes that mistake.

Signed-off-by: Gerard Cauvy <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-10 12:14:53 +02:00
Greg Kroah-Hartman 956563362b DWC3: use module_pci_driver
This cuts down on the boilerplate code.

Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-02-09 08:36:06 -08:00
Felipe Balbi 2e81c36a00 usb: dwc3: gadget: allocate 3 packets for bulk and isoc endpoints
Those transfer types are generally high bandwidth, so we
want to optimize transfers with those endpoints.

For that, databook suggests allocating 3 * wMaxPacketSize
of FIFO. Let's do that.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 17:06:12 +02:00
Felipe Balbi d70d84423c usb: dwc3: gadget: avoid memcpy()ing event buffer
We're only using the 4 byte events and memcpy()
will make us slower. We can easily avoid that.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 13:40:17 +02:00
Felipe Balbi 8b5d6b0a43 usb: dwc3: host: align on host device name
PCI uses xhci-hcd, so let's use the same device
name to avoid confusion.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:42 +02:00
Felipe Balbi 3d4c0d4ffb usb: dwc3: debugfs: fix error check
debugfs APIs will return NULL if it fails
to create the file/directory we ask it to
create.

Instead of checking for IS_ERR(ptr) we must
check for !ptr.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:41 +02:00
Felipe Balbi 45b3cd4ad7 usb: dwc3: omap: convert pdata to of property
Convert our platform_data usage to OF property,
keep the legacy pdata for a while until the complete
conversion is done.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:39 +02:00
Felipe Balbi 8db7ed15f2 usb: dwc3: gadget: start core on Rx.Detect
When we set Run/Stop bit, we also move the
core to Rx.Detect state so that USB3 handshake
can start from a known location.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:36 +02:00
Felipe Balbi 457e84b662 usb: dwc3: gadget: dynamically re-size TxFifos
We need to dynamically re-size TxFifos for the
cases where default values will not do.

While at that, we create a simple function which,
for now, will just allocate one full packet fifo
space for each of the enabled endpoints.

This can be improved later in order to allow for
better throughput by allocating more space for
endpoints which could make good use of that like
isochronous and bulk.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:34 +02:00
Felipe Balbi bb5cfd6811 usb: dwc3: ep0: move to CONFIGURED also on delayed status
Mass Storage gadget will take some time to handle
the SetConfiguration request, but even on those
cases we should move to CONFIGURED state.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:31 +02:00
Felipe Balbi 7b7dd0253c usb: dwc3: gadget: use the descriptor pointer we hold
We hold that pointer for one reason. It just
looks nicer to use it.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:30 +02:00
Felipe Balbi 40aa41fba3 usb: dwc3: gadget: fix XferNotReady debug print
Only bit 3 of the event status bitfield is valid
and the others should not be considered.

Make sure SW matches documentation on that case
to avoid bogus debugging prints which would
confuse an engineer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:28 +02:00
Felipe Balbi 138801aaa5 usb: dwc3: gadget: allow Link state changes via debugfs
This is very useful for low level link testing where
we might not have a USB Host stack, only a scope to
verify signal integrity.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:25 +02:00
Felipe Balbi 8598bde7fa usb: dwc3: gadget: re-factor Link state change to a function
Most link changes will, of course, happen with
the help of a matching host HW, but in some cases
we might want to debug very low level details about
the link and exposing this to debugfs sounds like
a good plan.

This is a preparation for such setup.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:24 +02:00
Felipe Balbi 080d921fe7 usb: dwc3: gadget: allow testmodes changes via debugfs
This is very useful for low level Link Testing where
we might not have a USB Host stack, only a scope to
verify signal integrity.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:22 +02:00
Felipe Balbi 04a9bfcd50 usb: dwc3: gadget: re-factor USB2 test mode to a function
There are some situations were we might need to
enable USB Test Modes without having access to a
Host stack. In such situations we cannot rely
solely on USB Control Messages to enable test
features.

For those cases, we will also allow test mode
to be enabled via debugfs and this patch is a
preparation for that.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:19 +02:00
Sebastian Andrzej Siewior c09d6b51d7 usb: dwc3: unmap the proper number of sg entries
num_sgs contains the number of sgs assigned by the gadget.
num_mapped_sgs contains the number of mapped sgs which may differ from
the gadget's values. For dma_unmap_sg() we have to provide the value
which was returned by dma_map_sg().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-01-24 15:43:17 +02:00
Felipe Balbi 1a0955fed1 usb: dwc3: ep0: fix compile warning
commit 34c60a7 (usb: dwc3: ep0: tidy up Pending
Request handling) introduced a compile warning
by leaving an unused variable.

This patch fixes that warning:

drivers/usb/dwc3/ep0.c: In function ā€˜__dwc3_gadget_ep0_queueā€™:
drivers/usb/dwc3/ep0.c:129:8: warning: unused variable ā€˜typeā€™
[-Wunused-variable]

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-01-24 15:42:25 +02:00
Felipe Balbi 68d8a78157 usb: dwc3: ep0: tidy up Pending Request handling
The way our code was written, we should never have
a DWC3_EP_PENDING_REQUEST flag set out of a Data Phase
and the code in __dwc3_gadget_ep0_queue() did not
reflect that situation properly.

Tidy up that case to avoid any possible mistakes
when starting requests for IRQs which are long
gone.

Cc: stable@vger.kernel.org
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-01-24 15:41:22 +02:00
Linus Torvalds 55b81e6f27 Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (232 commits)
  USB: Add USB-ID for Multiplex RC serial adapter to cp210x.c
  xhci: Clean up 32-bit build warnings.
  USB: update documentation for usbmon
  usb: usb-storage doesn't support dynamic id currently, the patch disables the feature to fix an oops
  drivers/usb/class/cdc-acm.c: clear dangling pointer
  drivers/usb/dwc3/dwc3-pci.c: introduce missing kfree
  drivers/usb/host/isp1760-if.c: introduce missing kfree
  usb: option: add ZD Incorporated HSPA modem
  usb: ch9: fix up MaxStreams helper
  USB: usb-skeleton.c: cleanup open_count
  USB: usb-skeleton.c: fix open/disconnect race
  xhci: Properly handle COMP_2ND_BW_ERR
  USB: remove dead code from suspend/resume path
  USB: add quirk for another camera
  drivers: usb: wusbcore: Fix dependency for USB_WUSB
  xhci: Better debugging for critical host errors.
  xhci: Be less verbose during URB cancellation.
  xhci: Remove debugging about ring structure allocation.
  xhci: Remove debugging about toggling cycle bits.
  xhci: Remove debugging for individual transfers.
  ...
2012-01-09 12:09:47 -08:00
Greg Kroah-Hartman ff4b8a57f0 Merge branch 'driver-core-next' into Linux 3.2
This resolves the conflict in the arch/arm/mach-s3c64xx/s3c6400.c file,
and it fixes the build error in the arch/x86/kernel/microcode_core.c
file, that the merge did not catch.

The microcode_core.c patch was provided by Stephen Rothwell
<sfr@canb.auug.org.au> who was invaluable in the merge issues involved
with the large sysdev removal process in the driver-core tree.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-06 11:42:52 -08:00
Julia Lawall 5632c827cb drivers/usb/dwc3/dwc3-pci.c: introduce missing kfree
Glue needs to be freed on exiting the function in an error case.
Furthermore, pci, which is the first argument to the probe function should
not be freed before leaveing the function, as it is reused at the call
site.  So the free of pci is changed to free glue instead.

A simplified version of the semantic match that finds the problem is as
follows: (http://coccinelle.lip6.fr)

// <smpl>
@r exists@
local idexpression x;
statement S;
identifier f1;
position p1,p2;
expression *ptr != NULL;
@@

x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
...
if (x == NULL) S
<... when != x
     when != if (...) { <+...x...+> }
x->f1
...>
(
 return \(0\|<+...x...+>\|ptr\);
|
 return@p2 ...;
)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-04 15:52:42 -08:00
Felipe Balbi 18b7ede5f7 usb: ch9: fix up MaxStreams helper
According to USB 3.0 Specification Table 9-22, if
bmAttributes [4:0] are set to zero, it means "no
streams supported", but the way this helper was
defined on Linux, we will *always* have one stream
which might cause several problems.

For example on DWC3, we would tell the controller
endpoint has streams enabled and yet start transfers
with Stream ID set to 0, which would goof up the host
side.

While doing that, convert the macro to an inline
function due to the different checks we now need.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-04 15:52:42 -08:00
Greg Kroah-Hartman ee0db58ade Merge branch 'for-gadget/next' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
* 'for-gadget/next' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (24 commits)
  usb: dwc3: gadget: add support for SG lists
  usb: dwc3: gadget: don't force 'LST' always
  usb: dwc3: gadget: don't return anything on prepare trbs
  usb: dwc3: gadget: re-factor dwc3_prepare_trbs()
  usb: gadget: introduce support for sg lists
  usb: renesas: pipe: convert a long if into a XOR operation
  usb: gadget: remove useless depends on Kconfig
  usb: gadget: s3c-hsudc: remove the_controller global
  usb: gadget: s3c-hsudc: use release_mem_region instead of release_resource
  usb: gadget: s3c-hsudc: Add regulator handling
  usb: gadget: s3c-hsudc: use udc_start and udc_stop functions
  usb: gadget: s3c-hsudc: move device registration to probe
  usb: gadget: s3c-hsudc: add missing otg_put_transceiver in probe
  usb: gadget: s3c-hsudc: add __devinit to probe function
  usb: gadget: s3c-hsudc: move platform_data struct to global header
  USB: EHCI: Add Marvell Host Controller driver
  USB: OTG: add Marvell usb OTG driver support
  usb: gadget: mv_udc: drop ARCH dependency
  usb: gadget: mv_udc: fix bug in ep_dequeue
  usb: gadget: enlarge maxburst bit width.
  ...
2011-12-22 14:05:19 -08:00
Greg Kroah-Hartman eea9fc7ddd Merge branch 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
* 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb:
  usb: dwc3: gadget: move us to Default State after reset
2011-12-22 14:01:08 -08:00
Felipe Balbi eeb720fb21 usb: dwc3: gadget: add support for SG lists
add support for SG lists on dwc3 driver. With
this we can e.g. use VFS layer's SG lists on
storage gadgets so that we can start bigger
transfers and improve throughput.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-21 13:24:46 +02:00
Felipe Balbi 42f8eb7a10 usb: dwc3: gadget: don't force 'LST' always
the LST bit is to be set on the last of a series
of consecutive TRBs. We had a workaround for a
problem where data would get corrupted but that
doesn't happen anymore. It's likely that it was
caused by some FPGA instability during development
phase.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-21 13:24:46 +02:00
Felipe Balbi 68e823e24a usb: dwc3: gadget: don't return anything on prepare trbs
all that function does is setup a TRB to be sent
to HW later. There's no need to return anything
actually.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-21 13:24:45 +02:00
Felipe Balbi c71fc37c19 usb: dwc3: gadget: re-factor dwc3_prepare_trbs()
In order to make it easier to add SG support,
let's split the big loop out to its own function.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-21 13:24:45 +02:00
Felipe Balbi 961906edb5 usb: dwc3: gadget: move us to Default State after reset
After a bus reset, we should move our state to
Default, in order to be able to re-enumerate again.

I only managed to trigger this problem with g_ether
by removing the cable after a few transfers had been
completed.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-20 18:28:06 +02:00
Felipe Balbi 248b122b13 usb: dwc3: core: fix cached revision on our structure
All our revision macros are defined with the entire
32-bits which we read from GSNPSID register, so we
must cache all 32-bits properly rather than masking
the top 16-bits.

This will fix all revision checks we have on current
driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-14 21:59:30 +02:00
Greg Kroah-Hartman 121a8cdd79 Merge branch 'for-next/gadget' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
* 'for-next/gadget' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (50 commits)
  usb: renesas_usbhs: show error reason on usbhsh_urb_enqueu()
  usb: renesas_usbhs: add force packet remove method
  usb: renesas_usbhs: care usb_hcd_giveback_urb() status
  usb: renesas_usbhs: add usbhsh_is_running()
  usb: renesas_usbhs: disable attch irq after device attached
  usb: renesas_usbhs: care pipe sequence
  usb: renesas_usbhs: add usbhs_pipe_attach() method
  usb: renesas_usbhs: add usbhsh_endpoint_detach_all() for error case
  usb: renesas_usbhs: modify device attach method
  usb: renesas_usbhs: pop packet when urb dequeued
  usb: renesas_usbhs: add lost error value when enqueue
  usb: gadget: mv_udc: replace some debug info
  usb: gadget: mv_udc: refine suspend/resume function
  usb: gadget: mv_udc: refine the clock relative code
  usb: gadget: mv_udc: disable ISR when stopped
  usb: gadget: mv_udc: add otg relative code
  usb: gadget: Use kcalloc instead of kzalloc to allocate array
  usb: renesas_usbhs: remove the_controller_link
  usb: renesas_usbhs: add test-mode support
  usb: renesas_usbhs: call usbhsg_queue_pop() when pipe disable.
  ...
2011-12-13 09:37:40 -08:00
Greg Kroah-Hartman 007d00d4c1 Merge branch 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
* 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (392 commits)
  usb: dwc3: ep0: fix for possible early delayed_status
  usb: dwc3: gadget: fix stream enable bit
  usb: dwc3: ep0: fix GetStatus handling (again)
  usb: dwc3: ep0: use dwc3_request for ep0 requsts instead of usb_request
  usb: dwc3: use correct hwparam register for power mgm check
  usb: dwc3: omap: move to module_platform_driver
  usb: dwc3: workaround: missing disconnect event
  usb: dwc3: workaround: missing USB3 Reset event
  usb: dwc3: workaround: U1/U2 -> U0 transiton
  usb: dwc3: gadget: return early in dwc3_cleanup_done_reqs()
  usb: dwc3: ep0: handle delayed_status again
  usb: dwc3: ep0: push ep0state into xfernotready processing
  usb: dwc3: fix sparse errors
  usb: dwc3: fix few coding style problems
  usb: dwc3: move generic dwc3 code from gadget into core
  usb: dwc3: use a helper function for operation mode setting
  usb: dwc3: ep0: don't use ep0in for transfers
  usb: dwc3: ep0: use proper endianess in SetFeature for wIndex
  usb: dwc3: core: drop DWC3_EVENT_BUFFERS_MAX
  usb: dwc3: omap: add multiple instances support to OMAP
  ...
2011-12-12 15:19:53 -08:00
Felipe Balbi 68d3e668d2 usb: dwc3: ep0: fix for possible early delayed_status
There is a very small possibility (previously unimagined
by us) that the whole Mass Storage delayed status happens
rather early, before we even get our XferNotReady event.

In that case, we will be queueing a request to ep0 while
we're still on Setup Phase and we would be waiting for
another usb_ep_queue() forever.

Handle such cases by clearing dwc->delayed_status so that
we start control status from the next XferNotReady like
there was no wait for Delayed Status.

Tested against Linux 3.2-rc3 and USB30CV tool from USB-IF
(on a Windows XP with USB3 PCIe card).

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:47 +02:00
Felipe Balbi c90bfaece9 usb: dwc3: gadget: fix stream enable bit
ep->max_streams is a mere hint to the gadget
driver that 'ep' supports stream handling. Using
that as a decision variable for enabling streams
was my worst brain-fart to date.

Instead, we should check from the Superspeed
Endpoint Companion Descriptor if the endpoint
has requested streams. For that we need a little
re-factoring but it is now correct.

Debugged-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:47 +02:00
Felipe Balbi e261779605 usb: dwc3: ep0: fix GetStatus handling (again)
previous commit fixed part of it but it was still
calling usb_ep_queue() from IRQ context without
loosing locks. That cannot be done otherwise we will
have a recursive locking.

Also, we need to assign the 'dep' pointer on
dwc->ep0_usb_req otherwise we will have a NULL
pointer dereference on dwc3_map_buffer_to_dma().

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:46 +02:00
Sebastian Andrzej Siewior e0ce0b0a0a usb: dwc3: ep0: use dwc3_request for ep0 requsts instead of usb_request
Instead of special functions and shortcuts for sending our internal
answers to the host we started doing what the gadget does and used the
public API for this. Since we only were using a few fields the
usb_request was enough. Later added the list handling in order to
synchronize the host / gadget events and now we require to have the
dwc3_request struct around our usb_request or else we touch memory that
does not belong to us. So this patch does this.

Reported-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:45 +02:00
Sebastian Andrzej Siewior 164d773168 usb: dwc3: use correct hwparam register for power mgm check
We mask the correct bits within the wrong register. The power
optimization mode is stored hwparam1 register and not in hwparam0.

Reported-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:44 +02:00
Felipe Balbi 68380876d6 usb: dwc3: omap: move to module_platform_driver
the new module_platform_driver macro is a helper
for modules which just register and unregister the
platform_driver. It allows us to delete a few
duplicated lines.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:43 +02:00
Felipe Balbi df62df56e1 usb: dwc3: workaround: missing disconnect event
DWC3 revisions <1.88a have an issue which would
case a missing Disconnect event if cable is
disconnected while there's a Setup packet
pending the FIFO.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:42 +02:00
Felipe Balbi 05870c5ba2 usb: dwc3: workaround: missing USB3 Reset event
DWC3 revisions <1.90a have an issue which would cause
a missing USB3 Reset event. In such cases, it's
suggested that we follow the steps of a normal
USB3 Reset on Connection Done Event.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:35 +02:00
Felipe Balbi fae2b904aa usb: dwc3: workaround: U1/U2 -> U0 transiton
RTL revisions <1.83a have an issue where, depending
on the link partner, the USB link might do multiple
entry/exit of low power states before a transfer
takes place causing degraded throughput.

The suggested workaround is to clear bits
12:9 of DCTL register if we see a transition
from U1|U2 to U0 and only re-enable that on
a transfer complete IRQ and we have no pending
transfers on any of the enabled endpoints.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:34 +02:00
Sebastian Andrzej Siewior d39ee7be2a usb: dwc3: gadget: return early in dwc3_cleanup_done_reqs()
This patch avoids the compiler spitting out the following warning:
|drivers/usb/dwc3/gadget.c:1304: warning: 'trb' is used uninitialized \
	in this function

This is only uninitialized if the list of to-cleanup TRBs is empty which
should not be the case because we call this functions once a transfer
completed so it should be on list.

In order to make the warning disappear we return early. This should
never happen and the WARN_ON_ONCE(1) is there in case it happens
so we can investigate what went wrong.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:32 +02:00
Sebastian Andrzej Siewior 5bdb1dcc63 usb: dwc3: ep0: handle delayed_status again
Since the re-worked ep0 handling (which uses HW's hints to recognize the ep0
status) we lost the delayed status handling. This is used by the file and mass
storage gadget to gain some extra time so setup its internal status before it
can proceed further requests.
In particular the storage gadget does nothing on USB_REQ_SET_CONFIGURATION but
wakes up a thread which handles the request. If the udc driver continues ep0
handling before the thread did its work then then endpoint is not yet
configured and further requests will fail. Once the gadget is ready, it will
enqueue an empty packet which is used for synchronization.
In order to fix this issue, the patch does the following:
Set ->delayed_status once the delayed_status has been notices and do not
continue on the next XferNotReady event. We will continues ep0 processing once
the gadget enqueued the zero packet for synchronization.

A cleaner approach would be to enforce the gadget to enqueue an empty
(zero) request even for the status phase but this would do for now.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:31 +02:00
Sebastian Andrzej Siewior f0f2b2a2db usb: dwc3: ep0: push ep0state into xfernotready processing
We wait for the XferNotReady before we start the transfer and by then we
know ep0 state in which we supposed to be.
This is some cleanup work for the following patch in which we require to
know the ep0 state before the transfer completes.
While here, also change the argument to dwc3_ep0_do_control_status() so
we don't require the complete event structure but only the required
piece of information.

Inspired-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:30 +02:00
Felipe Balbi 8becf27044 usb: dwc3: fix sparse errors
sparse caught three mistakes on this driver,
fix them:

drivers/usb/dwc3/ep0.c:806:29: warning: duplicate const
drivers/usb/dwc3/debugfs.c:481:15: warning: symbol 'dwc3_debugfs_init' \
	was not declared. Should it be static?
drivers/usb/dwc3/debugfs.c:518:16: warning: symbol 'dwc3_debugfs_exit' \
	was not declared. Should it be static?

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:29 +02:00
Felipe Balbi 25b8ff68bf usb: dwc3: fix few coding style problems
There were a few coding style issues with this driver
which are now fixed:

drivers/usb/dwc3/debugfs.c:48: WARNING: Use #include \
	<linux/uaccess.h> instead of <asm/uaccess.h>
drivers/usb/dwc3/debugfs.c:484: ERROR: space required \
	before the open brace '{'
drivers/usb/dwc3/ep0.c:261: WARNING: line over 80 characters
drivers/usb/dwc3/ep0.c:287: WARNING: suspect code indent \
	for conditional statements (16, 23)
drivers/usb/dwc3/gadget.c:749: WARNING: line over 80 characters
drivers/usb/dwc3/gadget.c:1267: WARNING: line over 80 characters
drivers/usb/dwc3/gadget.h:116: WARNING: line over 80 characters
drivers/usb/dwc3/io.h:42: WARNING: Use #include \
	<linux/io.h> instead of <asm/io.h>

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:29 +02:00
Sebastian Andrzej Siewior 4878a02898 usb: dwc3: move generic dwc3 code from gadget into core
A few inits like the scale value or the removal of the DISSCRAMBLE is
done in the gadget code however it touches a general register.
Move this piece to the core.c file since it is likely to be requied by
both, parts of the core (device and host).

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:27 +02:00
Sebastian Andrzej Siewior 3140e8cbfe usb: dwc3: use a helper function for operation mode setting
There are two where need to set operational mode:
- during initialization while we decide to run in host,device or DRD
  mode
- at runtime via the debugfs interface.

This patch provides a new function which sets the operational mode and
moves its initialiation to the mode switch instead in the gadget code
itself.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:26 +02:00
Sebastian Andrzej Siewior c2da2ff006 usb: dwc3: ep0: don't use ep0in for transfers
In "usb: dwc3: remove special status request handling in ep0" I simplied
a few things and used the generic API for the status transfers. The bug
I introcuded here is that we queue now requests to dep[1] but we don't
clear that list in the stall+start case.
Actually we don't need to use dep[1] at all. We only did in the past to
talk to the correct endpoint (i.e. in or out). This is now take care of
in a diffent place within the ep0 code. So we could queue the in
transfers to dep[0] and don't use dep[1] at all.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:25 +02:00
Sebastian Andrzej Siewior 1e7618d8a1 usb: dwc3: ep0: use proper endianess in SetFeature for wIndex
The first access was correct, the second was wrong.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:25 +02:00
Felipe Balbi 457d3f214f usb: dwc3: core: drop DWC3_EVENT_BUFFERS_MAX
hardware will tell us how many event buffers we
need to support, so let's allocate the array
dynamically too.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:24 +02:00
Felipe Balbi 5ddcee27c1 usb: dwc3: omap: add multiple instances support to OMAP
if we ever have an omap with multiple instances of
the DWC3 IP, we need unique names for them. In order
to achieve that, let's use the dwc3_get/put_device_id()
calls to give us an unique device identifier.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:23 +02:00
Felipe Balbi 8300dd236e usb: dwc3: move dwc3 device ID bitmap to core.c
if we want to support situations where we have
both SoC and PCIe versions of the IP on the same
platform, we need to have sequential numbers between
them, otherwise we will still have name collisions.

Because of that, we need to move dwc3_get/put_device_id()
to core.c and export that symbol to be used by glue
layers.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:21 +02:00
Sebastian Andrzej Siewior 8ee6270c7f usb: dwc3: remove special status request handling in ep0
The GetStatus (STD)-request is handled the driver and uses a tiny hack
to send the two bytes long answer. This patch removes the custom hack
uses the normal usb_ep_queue() for that.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:21 +02:00
Sebastian Andrzej Siewior 0cc7a519c4 usb: dwc3: reset pending status flag in error case
If we stall and restart we have to reset also this flag to 0 as there is
nothing pending anymore.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:20 +02:00
Sebastian Andrzej Siewior bd178f2d62 usb: dwc3: host: remove unused includes
None of these are required atm.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:19 +02:00
Sebastian Andrzej Siewior c5537ea531 usb: dwc3: debugfs: hold the lock in during mode change
The read and write operation is atomic and we need no locking around
this operations. What we need however is a lock that is held which
ensures that the content of the DWC3_GCTL has not been changed. With
this, the conten may have been change changed after the first but before
our write back.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:19 +02:00
Sebastian Andrzej Siewior 7ae4fc4dc8 usb: dwc3: add a platform device alias
We can have three modules here: dwc3.ko, dwc3-omap.ko and dwc3-pci.ko.
The later have already ids-aliases for probing and is fine. The omap
module has alias for DT but lacks alias for the "native"
platform_device. Maybe we should get rid of it and stick to the DT name?
Both glue modules create a new device for which the dwc3.ko module is
responsible and that one lacks the platform alias.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:17 +02:00
Felipe Balbi 9cc9bcd5b3 usb: dwc3: ep0: handle unexpected XferNotReady events
Sometimes the host might be trying to initiate Data or
Status phase for an older Control transfer. In such
situations we must STALL that transfer and restart
the state machine rather than letting such situation
go through the wire.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:16 +02:00
Felipe Balbi 0b9fe32dee usb: dwc3: debugfs: add support for changing port mode
This makes testing a lot easier when trying to
switch between host and device modes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:15 +02:00
Felipe Balbi f96a6ec1db usb: dwc3: ep0: SetAddress() won't be issued while Configured
I have talked to USB-IF about USB30CV issuing SetAddres()
with a device on Configured state and they have agreed on
changing USB30CV not to do so.

Adding back the STALL reply in such case and while at
that, also add a debugging message for an address which
is too large.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:15 +02:00
Felipe Balbi c4da177f1f usb: dwc3: depend on both Host and Gadget stacks
now that we have host support, we must depend
on both sides.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:14 +02:00
Felipe Balbi f80b45e75e usb: dwc3: move gadget prototypes to core.h
host prototypes are there, let's move gadget's
closer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:13 +02:00
Felipe Balbi 67920bd7c9 usb: dwc3: always compile gadget side too
We can decide in runtime if that will be used
or not.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:13 +02:00
Felipe Balbi d07e8819a0 usb: dwc3: add xHCI Host support
The Designware USB3 IP can be configured with
an internal xHCI. If we're running on such a
version, let's start the xHCI stack.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:12 +02:00
Felipe Balbi 0949e99b05 usb: dwc3: fetch mode of operation from HW
There's no need to add driver_data for something
we can fetch from HW.

This also makes our id_table unnecessary - at least
for now -, so we also remove it on the same patch.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:11 +02:00
Felipe Balbi 9f622b2a40 usb: dwc3: calculate number of event buffers dynamically
This will allow us to only allocate memory when
we actually need.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:11 +02:00
Felipe Balbi 6c167fc9b0 usb: dwc3: allow forcing a maximum speed
this is mainly for testing. In order to be able
to test if we're enumerating correctly on all
speeds, let that be controlled by a module
parameter.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:10 +02:00
Felipe Balbi b2c2271c82 usb: dwc3: gadget: don't disable endpoints on exit
when we remove the gadget driver, it will already
do that for us.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:09 +02:00
Michal Nazarewicz d327ab5b6d usb: gadget: replace usb_gadget::is_dualspeed with max_speed
This commit replaces usb_gadget's is_dualspeed field with
a max_speed field.

[ balbi@ti.com : Fixed DWC3 driver ]

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:45:11 +02:00
Axel Lin cc27c96c2b usb: convert drivers/usb/* to use module_platform_driver()
This patch converts the drivers in drivers/usb/* to use the
module_platform_driver() macro which makes the code smaller and a bit
simpler.

Cc: Felipe Balbi <balbi@ti.com>
Cc: Li Yang <leoli@freescale.com>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Peter Korsgaard <jacmet@sunsite.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-11-28 06:48:32 +09:00
Alessandro Rubini 42b4d114b9 usb: dwc3: fix a warning
The previous patch left an unused variable, I apologize.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-11-18 15:19:21 -08:00
Alessandro Rubini c8d2a6f399 usb: dwc3: use debugfs_print_regs32()
This a use example of the regs32 utilities in debugfs, although
this fuse use ":" as separator between name and value, and debugs
uses "=" (as it looked to me a more common practice).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-11-18 11:46:32 -08:00
Sebastian Andrzej Siewior 12d36c16bd usb: dwc3: gadget: initialize max_streams
Without this the gadget will never be able to allocate a stream capable
endpoint. The manual says that the stream id is a 16bit id. It does not
talk about an upper limit in any other way. So I think 15 is a
reasonable limit :)

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-11-14 11:51:31 -08:00
Paul Gortmaker 2204fdee84 usb: Add module.h to various dwc3 drivers
These files uses the full set of MODULE_ macros and so need to
include module.h directly.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:27:28 -07:00
Felipe Balbi dc1c70a774 usb: dwc3: convert structures into bitshifts
our parameter structures need to be written to
HW, so instead of assuming little endian, we
convert those into bit shifts.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:56 -07:00
Felipe Balbi aabb707523 usb: dwc3: gadget: allow clock gating to work
The dwc3 core has internal clock gating support.

Let's allow that to happen by clearing the disable
bit in GCTL register.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:56 -07:00
Felipe Balbi 26ceca9750 usb: dwc3: core: cache GHWPARAMS* registers
cache the contents of GHWPARAMS* registers in
our device structure for easy access.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:55 -07:00
Felipe Balbi a32994998c usb: dwc3: add struct dwc3_hwparams
That structure will hold a copy of readonly
GHWPARAMS* registers for ease accessing by
the driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:55 -07:00
Felipe Balbi 879631aa65 usb: dwc3: gadget: implement streams support
The following patch adds support for streams
to dwc3 driver.

While at that, also fix one small issue on
endpoint disable where we should clear all
flags not only ENABLED.

Reviewied-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:54 -07:00
Felipe Balbi a4af9008bb usb: dwc3: gadget: add support for Bursts
We already have the value from gadget drivers,
just need to pass it to our controller.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:54 -07:00
Paul Zimmerman c439ef87c3 usb: dwc3: gadget: fix DMA offset calculation
Fix offset calculation in dwc3_trb_dma_offset()

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:53 -07:00
Paul Zimmerman 5275455a6e usb: dwc3: gadget: make DWC3_EP_WEDGE do the right thing
This makes DWC3_EP_WEDGE do the right thing, which is
prevent DWC3_EP_WEDGE from ever being cleared by a
ClearFeature(HALT) command.

[ balbi@ti.com : allowed set_wedge to send SetHalt command
	to controller ]

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:53 -07:00
Paul Zimmerman 82828ca77b usb: dwc3: gadget: driver should not wait for RxFIFO to drain
An older version of the databook said to wait for the FIFO to
drain, but that has been removed from the newer databooks.

Waiting for RxFIFO to drain caused problems when testing against
one of the host controllers available in the market.

After talking to one of the RTL engineers, he stated that we
should _not_ wait for RxFIFO to drain.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:53 -07:00
Paul Zimmerman b23c843992 usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs
DEPSTARTCFG for non-EP0 EPs must only be sent once per config

[ balbi@ti.com : changed config_start to start_config_issued ]

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:52 -07:00
Sebastian Andrzej Siewior 49a25cc9a7 usb: dwc: remove "All rights reserved" statement.
Some people think that this line is not compatible with the GPL. The
statement was required due to the Buenos Aires Convention and is now
deprecated. I remove it because it is said that it is pointless nowdays.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:52 -07:00
Sebastian Andrzej Siewior b147f3572d usb: dwc3: ep0: fix debug output
Use "ep0in" and "ep0out" instead "ep1in" and "ep0out" which is confusing
and not consistent with the remaining output.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Sebastian Andrzej Siewior 9876cbe2e2 usb: dwc3: ep0: remove second giveback in error case
We already give requests back in dwc3_ep0_stall_and_restart() so
doing it again here will most likely corrupt the list.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Felipe Balbi 25355be64e usb: dwc3: ep0: fix debug message
The way it was before was really meaningless.
Now it looks saner.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Felipe Balbi d95b09b901 usb: dwc3: ep0: ignore direction on 2-stage transfer
We don't need to care about direction on a two stage
transfer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:50 -07:00
Felipe Balbi 2646021e1d usb: dwc3: ep0: Make USB30CV happy with SetAddress
According to USB 3.0 Specification, a SetAddress()
while device is in Configured State has an unspecified
behavior (see Section 9.4.6). Still USB30CV wasn't
happy with my Stall reply.

To make that thing happy, just accept the SetAddress()
always. No problems have been observed thus far.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:50 -07:00
Felipe Balbi 019ac83252 usb: dwc3: gadget: improve debug on link state change
It's useful to know which states core is going
through, as it might help us figure out misbehavior
on specific link states.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:31 +03:00
Felipe Balbi 4b5faa7aca usb: dwc3: omap: set idle and standby modes
For now, let's disable IDLE and STANDBY transitions
until we have a real HW to validate against.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:30 +03:00
Felipe Balbi 55f3fba6c8 usb: dwc3: ep0: introduce ep0_expect_in flag
This flag will tell us which direction we're
expecting on the next (data or status) phase.

It will help us catching errors of host going
crazy and requesting data of the wrong direction.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:29 +03:00
Felipe Balbi d742220b35 usb: dwc3: ep0: giveback requests on stall_and_restart
if we don't, the list will be busy forever.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:28 +03:00
Felipe Balbi bb7ea2841e usb: dwc3: gadget: drop the useless dma_sync_single* calls
if req->dma isn't DMA_ADDR_INVALID it means gadget driver
mapped the request or allocated from coherent, so it's
unnecessary to do anything.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:26 +03:00
Felipe Balbi 771f184ece usb: dwc3: gadget: fix GCTL programming
ensure a few bits are cleared before enabling
what we need.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:25 +03:00
Felipe Balbi f78d32e79e usb: dwc3: define ScaleDown macro helper
We must ensure that those bits aren't set as
they should only be used in simulation.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:24 +03:00
Felipe Balbi f4aadbe49e usb: dwc3: Fix definition of DWC3_GCTL_U2RSTECN
that should be 1 << 16, not 16. Caused so many
problems and we never caught it before.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:22 +03:00
Sebastian Andrzej Siewior 78c58a53c9 usb: dwc3: gadget: do not map/unmap ZLP transfers
If the gadget drivers sends a ZLP we are trying to map this this request
which does not work on all implementations. So we simply skip mapping
it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:03:46 +03:00
Felipe Balbi 42077b0a33 usb: dwc3: omap: fix IRQ handling
In order to ACK the IRQ we must write back
to the same register the bits we read.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:03:12 +03:00
Felipe Balbi dd17a6b20c usb: dwc3: omap: change IRQ name to dwc3-omap
dwc3-wrapper can be used by any other wrapper,
using dwc3-omap makes it clear that we're running
on OMAP SoC.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:03:07 +03:00
Felipe Balbi a72e658bcd usb: dwc3: add module.h to dwc3-omap.c and core.c
We need that header because of THIS_MODULE.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:03:00 +03:00
Felipe Balbi 9962444f59 usb: dwc3: omap: distinguish between SW and HW modes
The OMAP wrapper allows us to either control internal
OTG signals via SW or HW. Different boards might wish
to use one or the other mode of operation. Let's have
have that information passed via platform_data for now.

After DT conversion is finished for OMAP, we can easily
convert this to a DT attribute.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:45 +03:00
Felipe Balbi 29d8bc133f usb: dwc3: omap: drop DEV_PM_OPS for now
We need to have actual HW in order to implement
and test that part of the code anyway. Until then
it's best to remove it.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:34 +03:00
Felipe Balbi df01c61e06 usb: dwc3: omap: use the macro we already have
trivial patch, no functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:31 +03:00
Felipe Balbi 324e548140 usb: dwc3: omap: do not enable DMA Disable Clear IRQ
Otherwise that IRQ will trigger forever. It's quite
unnecessary.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:28 +03:00
Felipe Balbi ccba3bca5e usb: dwc3: omap: fix dev_dbg() calls
dev_dbg() macro expects a device pointer as
argument, not a memory base address.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:23 +03:00
Felipe Balbi 1ddcb218b5 usb: dwc3: use ep0_next_event field
Start tracking the next expected event and act
on the error conditions as suggested by databook.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:18 +03:00
Felipe Balbi b53c772d16 usb: dwc3: core: add ep0_next_event field
this field will hold the next expected event.

In certain cases, host might fall into some error
condition and ask from us the wrong Control phase.
On such situations, we should stall and restart.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:18 +03:00
Felipe Balbi 0b7836a9eb usb: dwc3: drop EP0_STALL state
Whenever we issue a Set Stall command on EP0,
the state machine will be restarted and Stall
is cleared automatically, when core receives
the next SETUP packet.

There's no need to track that EP0_STALL state.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:17 +03:00
Felipe Balbi 76cb323f80 usb: dwc3: ep0: clear all EP0 flags
when we're going to issue Set Stall command,
we should clear DWC3_EP_STALL flag, but also
we should clear BUSY, HALTED and all others.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:16 +03:00
Felipe Balbi b673cf3002 usb: dwc3: ep0: fix Get Status handling
data was prepared on setup_buf but transfer
was started on ctrl_req, fix it.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:15 +03:00
Sebastian Andrzej Siewior 61d58242f6 usb: dwc3: gadget: replace mdelay with udelay in the busy loop
There are two spots where we wait until the HW finishes processing a
certain command. Initially we had a few problems and we used 500ms as a
limit to be on a the safe side. Paul Zimmerman mentioned this is little too
much. After a debugging session, we noticed that we hardly ever go over 20us
and didn't pass 30usec so far. Using mdelay() seems way overloaded.

Giving the current numbers 500usec as the upper limit is more than  enough.
Should it ever timeout then something is definitely wrong.

While here, also replace the type with u32 since long does not really
fit here.

Cc: Paul Zimmerman <paul.zimmerman@synopsys.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:13 +03:00
Sebastian Andrzej Siewior 624407f96f usb: dwc3: gadget: rework the dequeue on RESET & DISCONNECT
- since a while we are disabling an endpoint and purging every requests on
  RESET and DISCONNECT which leads to a warning since the endpoint was
  disabled twice (once by the UDC, and second time by the gadget). I
  think UDC should nuke all requests because all those requests
  become invalid. It's gadget driver's responsability, though, to disable
  its used endpoints. This is done by merging dwc3_stop_active_transfer()
  and dwc3_gadget_nuke_reqs() into dwc3_remove_requests().

- dwc3_stop_active_transfer() is now no longer called unconditionaly.
  This has the advantage that it is always called to disable an active
  transfer which means if res_trans_idx 0 than something went wrong and
  it is an error condition because we can't clean up the requests.

- Remove the DWC3_EP_WILL_SHUTDOWN which was introduced while
  introducing the command complete part for dequeue. All requests on
  req_queued list should be removed during the dwc3_cleanup_done_reqs()
  callback so there is no reason to go through the list again.
  We consider it an error condition if requests are still on this
  list since we never queue TRB without LST=1 (the last requests has
  always LST=1, there are no requests with LST=0 behind it).

[ balbi@ti.com : reworked commit log a bit, made patch apply ]

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:10 +03:00
Sebastian Andrzej Siewior 7650bd74d3 usb: dwc3: core: move the core check before soft reset
We read the DWC3_GSNPSID register to make sure we got the correct
register offset passed. One of the recent commits moved the soft reset
before this so in case of the wrong offset we end up with "reset timed
out". This patch moves the "id" check before the reset again.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:09 +03:00
Sebastian Andrzej Siewior e7225315a8 usb: dwc3: debugfs: remove test mode interface
There are some issues around for enabling/disabling this mode and
handling it. It does not work perfectly (yet). However we have a few
gadgets tested successfuly so far. That means we are quite confident
that we won't need this in near future.
So I'm for removing it and bringing a working version back once there is
a need for it.

Thanks to Dan Carpenter who spotted the wrong memory handling here.

[ balbi@ti.com : made it actually apply ]

Cc: Dan Carpenter <error27@gmail.com>
Cc: wharms@bfs.de
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:08 +03:00
Felipe Balbi c7fcdeb262 usb: dwc3: ep0: simplify EP0 state machine
The DesignWare USB3 core tells us which phase
of a control transfer should be started, it
also tells us which physical endpoint needs
that transfer.

With these two informations, we have all we
need to simply EP0 handling quite a lot and
get rid rid of the SW state machine tracking
ep0 states.

For achieving this perfectly, we needed to
add support for situations where we get
XferNotReady while endpoint is still busy
and XferNotReady while gadget driver still
hasn't queued a request.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:07 +03:00
Felipe Balbi 984f66a6f9 usb: dwc3: core: add flag for EP0 direction
Add a flag to keep track of ep0 direction.
This flag will be used on a following patch.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:06 +03:00
Felipe Balbi a6829706ce usb: dwc3: ep0: add handling for unaligned OUT transfers
In case we have transfers which aren't aligned
to wMaxPacketSize, we need to be careful with
how we start the transfer with the HW. OUT
transfers _must_ be aligned with wMaxPacketSize
and in order to guarantee that, we use a bounce
buffer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:05 +03:00
Felipe Balbi 5812b1c236 usb: dwc3: add a bounce buffer for control endpoints
This core cannot handle OUT transfers which aren't
aligned to wMaxPacketSize, but that can happen at
least on control endpoint with the USB Audio Class.

This patch adds a bounce buffer to be used on the
case of a non-aligned ep0out request is queued.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:04 +03:00
Felipe Balbi dc137f01ac usb: dwc3: core: add defines for XferNotReady event on Control EPs
The status field of the Transfer Not Read event
is different on Control Endpoints. On this patch
we are just adding the defines to be used on a
later patch which will re-work the control endpoint
handling.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:03 +03:00
Felipe Balbi 164f6e141e usb: dwc3: gadget: improve command completion debug message
the previous message had too little meaning. Make
it more human readable and use the macro we already
had for extracting the command completion status out
of DEPCMDn register.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:02 +03:00
Felipe Balbi f198ead21b usb: dwc3: gadget: set request dma to invalid when unmapping
if we don't set DMA address to invalid when unmapping,
we might fall in a situation where request buffer
can't be mapped to DMA again.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:01 +03:00
Felipe Balbi c611ccb48a usb: dwc3: ep0: fix 'transfered' typo
trivial patch. No functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:00 +03:00
Felipe Balbi 91db07dcbf usb: dwc3: core: add missing @ for kerneldoc
trivial patch, no functional changes

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:00 +03:00
Dan Carpenter b4f28a98ea usb: dwc3: debugfs: add a kfree() on error to dwc3_testmode_open()
We may as well fix this potential leak so we don't have to listen to
the static checkers complain.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:01:59 +03:00
Sebastian Andrzej Siewior 0156cf8603 usb: dwc3: gaget: clear DWC3_EP_WILL_SHUTDOWN bit
Without this patch we won't clear that bit and instead will
clear all other bits on our endpoint flag.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:01:57 +03:00
Sebastian Andrzej Siewior 5a18999ebd usb: dwc3: gadget: use TRB type 6 for ISOC transfers
Type 6 should be used for the first transfer during an interval. This is
also what the reference driver is using. Type 7 seems to be for following
or additional transfers within the same interval.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:01:56 +03:00
Sebastian Andrzej Siewior a1ae9be5fc usb: dwc3: gadget: reset resource index to zero
If we collected two requests together (i.e. only the last of them has
LST=1) then we only have to stop transfer once: The clean-up code will
cleanup everything until first TRB with the LST bit set.
After XferComplete this index should be no longer valid since there is
no transfer pending.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:01:55 +03:00
Sebastian Andrzej Siewior 0d2f475853 usb: dwc3: gadget: fixing dequeue of TRBs
A TRB which is dequeued seems to have its HWO bits set to 1. Therefore
we ignore it if we dequeue it after the command is completed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:01:54 +03:00
Randy Dunlap 096cb25d62 usb: fix dwc3 build when USB_GADGET_DWC3 is not enabled
Fix build error when CONFIG_USB_GADGET_DWC3 is not enabled:

ERROR: "dwc3_send_gadget_ep_cmd" [drivers/usb/dwc3/dwc3.ko] undefined!

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-08-24 15:06:53 -07:00
Kuninori Morimoto 29cc88979a USB: use usb_endpoint_maxp() instead of le16_to_cpu()
Now ${LINUX}/drivers/usb/* can use usb_endpoint_maxp(desc) to get maximum packet size
instead of le16_to_cpu(desc->wMaxPacketSize).
This patch fix it up

Cc: Armin Fuerst <fuerst@in.tum.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Johannes Erdfelt <johannes@erdfelt.com>
Cc: Vojtech Pavlik <vojtech@suse.cz>
Cc: Oliver Neukum <oliver@neukum.name>
Cc: David Kubicek <dave@awk.cz>
Cc: Johan Hovold <jhovold@gmail.com>
Cc: Brad Hards <bhards@bigpond.net.au>
Acked-by: Felipe Balbi <balbi@ti.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Dahlmann <dahlmann.thomas@arcor.de>
Cc: David Brownell <david-b@pacbell.net>
Cc: David Lopo <dlopo@chipidea.mips.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Xie Xiaobo <X.Xie@freescale.com>
Cc: Li Yang <leoli@freescale.com>
Cc: Jiang Bo <tanya.jiang@freescale.com>
Cc: Yuan-hsin Chen <yhchen@faraday-tech.com>
Cc: Darius Augulis <augulis.darius@gmail.com>
Cc: Xiaochen Shen <xiaochen.shen@intel.com>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Ben Dooks <ben@simtec.co.uk>
Cc: Thomas Abraham <thomas.ab@samsung.com>
Cc: Herbert Pƶtzl <herbert@13thfloor.at>
Cc: Arnaud Patard <arnaud.patard@rtp-net.org>
Cc: Roman Weissgaerber <weissg@vienna.at>
Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: Tony Olech <tony.olech@elandigitalsystems.com>
Cc: Florian Floe Echtler <echtler@fs.tum.de>
Cc: Christian Lucht <lucht@codemercs.com>
Cc: Juergen Stuber <starblue@sourceforge.net>
Cc: Georges Toth <g.toth@e-biz.lu>
Cc: Bill Ryder <bryder@sgi.com>
Cc: Kuba Ober <kuba@mareimbrium.org>
Cc: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-08-23 09:47:40 -07:00
Stephen Rothwell 46a57283e8 usb: include module.h in the DesignWare USB3 DRD driver
Fixes this build error:

drivers/usb/dwc3/dwc3-pci.c: In function 'dwc3_pci_init':
drivers/usb/dwc3/dwc3-pci.c:211:9: error: 'THIS_MODULE' undeclared (first use in this function)

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-08-23 09:47:40 -07:00
Felipe Balbi 72246da40f usb: Introduce DesignWare USB3 DRD Driver
The DesignWare USB3 is a highly
configurable IP Core which can be
instantiated as Dual-Role Device (DRD),
Peripheral Only and Host Only (XHCI)
configurations.

Several other parameters can be configured
like amount of FIFO space, amount of TX and
RX endpoints, amount of Host Interrupters,
etc.

The current driver has been validated with
a virtual model of version 1.73a of that core
and with an FPGA burned with version 1.83a
of the DRD core. We have support for PCIe
bus, which is used on FPGA prototyping, and
for the OMAP5, more adaptation (or glue)
layers can be easily added and the driver
is half prepared to handle any possible
configuration the HW engineer has chosen
considering we have the information on
one of the GHWPARAMS registers to do
runtime checking of certain features.

More runtime checks can, and should, be added
in order to make this driver even more flexible
with regards to number of endpoints, FIFO sizes,
transfer types, etc.

While this supports only the device side, for
now, we will add support for Host side (xHCI -
see the updated series Sebastian has sent [1])
and OTG after we have it all stabilized.

[1] http://marc.info/?l=linux-usb&m=131341992020339&w=2

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-08-22 16:03:11 -07:00