OSDN Git Service

uclinux-h8/linux.git
7 years agousb: dwc3: use bus->sysdev for DMA configuration
Arnd Bergmann [Thu, 17 Nov 2016 11:43:47 +0000 (17:13 +0530)]
usb: dwc3: use bus->sysdev for DMA configuration

The dma ops for dwc3 devices are not set properly. So, use a
physical device sysdev, which will be inherited from parent,
to set the hardware / firmware parameters like dma.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sriram Dash <sriram.dash@nxp.com>
Tested-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: ep0: avoid empty-body warning
Arnd Bergmann [Wed, 16 Nov 2016 15:37:30 +0000 (16:37 +0100)]
usb: dwc3: ep0: avoid empty-body warning

Building with W=1, we get a warning about harmless empty statements:

drivers/usb/dwc3/ep0.c: In function 'dwc3_ep0_handle_intf':
drivers/usb/dwc3/ep0.c:491:4: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

Instead of adding empty braces which would introduce checkpatch.pl
warnings, we're just removing the code which doesn't do anything and
making sure we return 0 so USBCV tool is happy.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Move functions from header to source
Razmik Karapetyan [Wed, 16 Nov 2016 23:34:04 +0000 (15:34 -0800)]
usb: dwc2: Move functions from header to source

Removed extern specifier from dwc2_host_start(), dwc2_host_disconnect()
and dwc2_host_hub_info() functions. Moved those functions from header
to source. Then make them static.

Signed-off-by: Razmik Karapetyan <razmik@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Fix fifo_show() functionality
Razmik Karapetyan [Wed, 16 Nov 2016 23:34:02 +0000 (15:34 -0800)]
usb: dwc2: Fix fifo_show() functionality

NPTXFIFO's start address is showing 0x03000000 instead of 0x00000800.
Replaced val & FIFOSIZE_DEPTH_MASK by val & FIFOSIZE_STARTADDR_MASK in
fifo_show() function.

Signed-off-by: Razmik Karapetyan <razmik@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove unnecessary request length checking
Razmik Karapetyan [Wed, 16 Nov 2016 23:33:59 +0000 (15:33 -0800)]
usb: dwc2: Remove unnecessary request length checking

Remove request length checking from dwc2_hsotg_unmap_dma() and
dwc2_hsotg_map_dma(). That checking is done in functions called from
those functions, usb_gadget_unmap_request_by_dev() and
usb_gadget_map_request_by_dev() respectively, so it's unnecessary.

Signed-off-by: Razmik Karapetyan <razmik@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Fix Control Write issue in DMA mode
Razmik Karapetyan [Wed, 16 Nov 2016 23:33:57 +0000 (15:33 -0800)]
usb: dwc2: Fix Control Write issue in DMA mode

While sending zlp for DWC2_EP0_STATUS_IN EP direction was changed to IN.
Change it back to complete OUT transfer request.

This affects only on DMA mode, because DMA buffer map/unmap function is
direction sensitive.

Signed-off-by: Razmik Karapetyan <razmik@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Don't program DMA address for 0 length request
Razmik Karapetyan [Wed, 16 Nov 2016 23:33:55 +0000 (15:33 -0800)]
usb: dwc2: Don't program DMA address for 0 length request

Check the request length in dwc2_hsotg_start_req() function. If
length == 0, do not write DMA address to control register.

Signed-off-by: Razmik Karapetyan <razmik@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Stop Complete Splits after Data PID == 0
Sevak Arakelyan [Wed, 16 Nov 2016 23:33:52 +0000 (15:33 -0800)]
usb: dwc2: Stop Complete Splits after Data PID == 0

Stop sending complete split requests in case of ISOC IN split transfers
after getting data with PID0. Otherwise we will get a NYET for each
additional IN token.

Signed-off-by: Sevak Arakelyan <sevaka@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: pci: avoid build warning
Felipe Balbi [Wed, 16 Nov 2016 11:16:22 +0000 (13:16 +0200)]
usb: dwc3: pci: avoid build warning

dwc3_pci_dsm() is only needed if (PM || PM_SLEEP),
we should make sure it's not defined if neither of
those is defined.

This fixes a randconfig build warning.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: Workaround for irq mask issue
John Youn [Mon, 14 Nov 2016 20:32:45 +0000 (12:32 -0800)]
usb: dwc3: Workaround for irq mask issue

This is a workaround for STAR 9000961433 which affects only version
3.00a of the DWC_usb3 core. This prevents the controller interrupt from
being masked while handling events. Enabling interrupt moderation allows
us to work around this issue because once the GEVNTCOUNT.count is
written the IRQ is immediately deasserted and won't be asserted again
until GEVNTCOUNT.EHB is cleared.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: Implement interrupt moderation
John Youn [Mon, 14 Nov 2016 20:32:43 +0000 (12:32 -0800)]
usb: dwc3: Implement interrupt moderation

Implement interrupt moderation which allows the interrupt rate to be
throttled. To enable this feature the dwc->imod_interval must be set to
1 or greater. This value specifies the minimum inter-interrupt interval,
in 250 ns increments. A value of 0 disables interrupt moderation.

This applies for DWC_usb3 version 3.00a and higher and for DWC_usb31
version 1.20a and higher.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: add amcc,dwc-otg support
Christian Lamparter [Tue, 15 Nov 2016 23:03:40 +0000 (15:03 -0800)]
usb: dwc2: add amcc,dwc-otg support

This patch adds support for the "amcc,usb-otg" device
which is found in the PowerPC Canyonlands' dts.

The device definition was added by:

commit c89b3458d8cc ("powerpc/44x: Add USB DWC DTS entry to Canyonlands
board")

but without any driver support as the dwc2 driver wasn't available at
that time.

Note: The system can't use the generic "snps,dwc2" compatible
because of the special ahbcfg configuration. The default
GAHBCFG_HBSTLEN_INCR4 of snps,dwc2 can cause a system hang
when the USB and SATA is used concurrently.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: fixes host_dma logic
Christian Lamparter [Tue, 15 Nov 2016 12:11:55 +0000 (14:11 +0200)]
usb: dwc2: fixes host_dma logic

This patch moves the the host_dma initialization
before dwc2_set_param_dma_desc_enable() and
dwc2_set_param_dma_desc_fs_enable(). The reason being
that both function need it.

Fixes: 1205489cee75bf39 ("usb: dwc2: Get host DMA device properties")

Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add new core parameter for low speed
Vardan Mikayelyan [Tue, 15 Nov 2016 03:17:03 +0000 (19:17 -0800)]
usb: dwc2: gadget: Add new core parameter for low speed

Added new core param for low speed, which can be used only when SNPSID
is equal to DWC2_CORE_FS_IOT. When LS mode is enabled, we are
restricting ep types and providing to upper layer only INTR and CTRL
endpoints.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Program ep0_mps for LS
Vardan Mikayelyan [Tue, 15 Nov 2016 03:17:00 +0000 (19:17 -0800)]
usb: dwc2: gadget: Program ep0_mps for LS

When device is enumerated in LS we should program ep0_mps accordingly.
USB2 spec says that in LS mode, control ep mps must be 8.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add IOT device IDs, configure core accordingly
Vardan Mikayelyan [Tue, 15 Nov 2016 03:16:58 +0000 (19:16 -0800)]
usb: dwc2: gadget: Add IOT device IDs, configure core accordingly

Add new device IDs for IOT gadget. Done changes in probe to
configure core accordingly depending on device ID value.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Add support of dedicated full-speed PHY interface
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:55 +0000 (19:16 -0800)]
usb: dwc2: Add support of dedicated full-speed PHY interface

Do modifications in dwc2_hsotg_core_init_disconnected() function to
enable USB 1.1 Full-Speed Serial Transceiver Select in GUSBCFG register
if corresponding speed and PHY types are chosen. Adjust device speed
selection in DCFG register as well.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Disable enabled HW endpoint in dwc2_hsotg_ep_disable
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:53 +0000 (19:16 -0800)]
usb: dwc2: gadget: Disable enabled HW endpoint in dwc2_hsotg_ep_disable

Check if endpoint is enabled during dwc2_hsotg_ep_disable() function
processing and call dwc2_hsotg_ep_stop_xfr() to disable it and flush
associated FIFO.

Move dwc2_hsotg_ep_stop_xfr() and dwc2_hsotg_wait_bit_set() functions
upper before dwc2_hsotg_ep_enable and dwc2_hsotg_ep_disable function
definitions.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Correct dwc2_hsotg_ep_stop_xfr() function
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:51 +0000 (19:16 -0800)]
usb: dwc2: gadget: Correct dwc2_hsotg_ep_stop_xfr() function

Correct dwc2_hsotg_ep_stop_xfr() function to follow dwc2 programming
guide for setting NAK on specific endpoint, disabling it and flushing
corresponding FIFO.

Current code does not take into account whether core acts in shared or
dedicated FIFO mode, current endpoint is periodic or not. It does not
clear EPDISBLD interrupt after programming of DXEPCTL_EPDIS, does not
flush shared TX FIFO and tries to clear global out NAK in wrong manner
instead of setting DCTL_CGOUTNAK.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: For DDMA parse setup only after SetUp interrupt
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:48 +0000 (19:16 -0800)]
usb: dwc2: gadget: For DDMA parse setup only after SetUp interrupt

Tests with various hosts show that depend on time difference between
host sending SETUP packet and IN/OUT token SW could get Xfercomplete
interrupt without SetUp interrupt. On the other hand, SW should parse
received SETUP packet only after ensuring that Host has moved to either
Data or Status stage of control transfer.

For this purpose added checking in the dwc2_hsotg_epint() function to
not handle xfercomplete and postpone SETUP packet analysis till SW's
getting of setup phase done interrupt.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Adjust ISOC OUT request's actual len for DDMA
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:46 +0000 (19:16 -0800)]
usb: dwc2: gadget: Adjust ISOC OUT request's actual len for DDMA

In DDMA mode if programmed ISOC OUT transfer length is not DWORD
aligned, after closing descriptor HW leaves value of 4 - (ureq->length %
4) in the RX bytes. This is caused because DMA works using 4B chunks.
Example: if length = 9 and all 9 bytes were received from the bus, after
xfercomplete rx_bytes value is 3. Hence add this value to the amount of
transferred bytes.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Enable the BNA interrupt
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:43 +0000 (19:16 -0800)]
usb: dwc2: gadget: Enable the BNA interrupt

Enable the BNA (Buffer Not Available) interrupt in descriptor DMA mode.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Start and complete DDMA isoc transfers
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:41 +0000 (19:16 -0800)]
usb: dwc2: gadget: Start and complete DDMA isoc transfers

For DDMA mode in case of isochronous transfers completion performed
differently than other transfer types. This is because each usb request
was mapped to one descriptor in the chain and SW gets xfercomplete
interrupt on all descriptors. The endpoint remains enabled until HW
processes last descriptor with "L" bit set or BNA interrupt gets
asserted for IN and OUT endpoints correspondingly.

Add function dwc2_gadget_complete_isoc_request_ddma() - completes one
isochronous request taken from endpoint's queue.

Add function dwc2_gadget_start_next_isoc_ddma() - tries to restart
isochronous endpoint if requests are pending. Check for EPENA. If the
endpoint was disabled, try to restart it after programming descriptor
chain prepared by SW earlier, switch SW to fill the other half of chain.

Add function dwc2_gadget_fill_isoc_desc() - initializes DMA descriptor
for isochronous transfer based on the received request data and endpoint
characteristics.

Added function dwc2_gadget_start_isoc_ddma() - prepare DMA chain for
isochronous transfer in DDMA, programs corresponding DMA address to
DEPDMA, enables the endpoint. This function is called once SW decides to
start isochronous IN or OUT transfer depend on reception of NAK or
OUTTknEPdis interrupts indicating first isochronous token arrival from
host.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: In DDMA keep incompISOOUT and incompISOIN masked
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:38 +0000 (19:16 -0800)]
usb: dwc2: gadget: In DDMA keep incompISOOUT and incompISOIN masked

In DDMA mode incompISOOUT should be masked, similar as Bulk Out -
XferCompl and BNA should be handled. incompISOIN is not valid in DDMA
and is not getting asserted.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add DDMA isoc related fields to dwc2_hsotg_ep
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:36 +0000 (19:16 -0800)]
usb: dwc2: gadget: Add DDMA isoc related fields to dwc2_hsotg_ep

Preparing for isochronous transfers support adding in DDMA mode. In DDMA
isochronous transfers are handled differently compared to Slave and BDMA
modes. This is caused by fact that isoc requests contain data for one
frame/microframe. HW descriptor should contain data of one
frame/microframe as well. Hence each DMA descriptor in the chain will
correspond to one usb request.

Decided to divide endpoints descriptor chain to two halves - while one
will be processed by HW, other one will be under SW control. First part
will be passed to HW once ISOC traffic needs to be started. In parallel
to HW's work SW will keep creating new entries in the other half of
chain if new requests arrive in ep_queue routine. This will allow
passing of already pre-prepared descriptors to HW immediately after
endpoint gets disabled. The endpoint should be disabled once HW closes
descriptor with "L" bit set. Afterwards SW will switch to use first part
of chain if more requests are arriving.

Add two members to the dwc2_hsotg_ep structure to be used in isochronous
transfers' handling in DDMA mode:

-isoc_chain_num - indicates which half of EP descriptor chain can be
used by SW to add new queued requests while HW is
processing other half.

-next_desc - index which points to next not yet programmed descriptor in
the half of descriptor chain which is under SW control.

Also add initialization of these fields in function
dwc2_hsotg_ep_enable().

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Enable descriptor DMA mode
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:34 +0000 (19:16 -0800)]
usb: dwc2: gadget: Enable descriptor DMA mode

Add DCFG register field macro for descriptor DMA mode and update core
initialization routine to set that bit accordingly.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Start DDMA IN status phase in StsPhseRcvd handler
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:31 +0000 (19:16 -0800)]
usb: dwc2: gadget: Start DDMA IN status phase in StsPhseRcvd handler

In DDMA mode of operation IN status phase of control write transfer
should start after getting StsPhseRcvd interrupt. This interrupt is
issued by HW once host starts to send IN tokens after data stage.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Fixes for StsPhseRcvd interrupt
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:29 +0000 (19:16 -0800)]
usb: dwc2: gadget: Fixes for StsPhseRcvd interrupt

The StsPhseRcvd interrupt should not be enabled in slave mode.

Also move the StsPhsRcvd interrupt checking in the endpoint interrupt
handler to the correct order according to the databook. The interrupt
itself will be implemented in a later commit.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: DDMA transfer start and complete
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:26 +0000 (19:16 -0800)]
usb: dwc2: gadget: DDMA transfer start and complete

Update transfer starting dwc2_hsotg_start_req() routine with call of
function dwc2_gadget_config_nonisoc_xfer_ddma() to fill descriptor
chain.

Add call of dwc2_gadget_get_xfersize_ddma() in
dwc2_hsotg_handle_outdone() and dwc2_hsotg_complete_in() interrupt
handlers for DDMA mode to get information on transferred data from
descriptors instead of DXEPTSIZ.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: EP 0 specific DDMA programming
Vahram Aharonyan [Tue, 15 Nov 2016 03:16:24 +0000 (19:16 -0800)]
usb: dwc2: gadget: EP 0 specific DDMA programming

Add dwc2_gadget_set_ep0_desc_chain() function to switch between EP0 DDMA
chains depend on the stage of control transfer.

Include EP0 DDMA chain selection during ep_queue called from
dwc2_hsotg_enqueue_setup() for setup stage. Selecting and filling DDMA
chain for status phase as well - add calls of
dwc2_gadget_set_ep0_desc_chain() and
dwc2_gadget_config_nonisoc_xfer_ddma() functions.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove reading in of invalid property
John Youn [Tue, 15 Nov 2016 02:29:57 +0000 (18:29 -0800)]
usb: dwc2: Remove reading in of invalid property

This property was mistakenly added, then removed, so don't read it in.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: twl6030-usb: make driver DT only
Nicolae Rosia [Sat, 12 Nov 2016 10:47:43 +0000 (12:47 +0200)]
usb: twl6030-usb: make driver DT only

All users are DT-only and it makes no sense to keep
unused code

Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Nicolae Rosia <Nicolae_Rosia@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: clear events in top-half handler
John Youn [Tue, 15 Nov 2016 11:08:59 +0000 (13:08 +0200)]
usb: dwc3: gadget: clear events in top-half handler

Now that all the infrastructure is in place, we can
clear events in the top-half handler in order to
bring IRQ line low ASAP.

This is also a necessary step in order to implement
workaround for known erratum in follow-up patches.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: use evt->cache for processing events
John Youn [Tue, 15 Nov 2016 11:07:02 +0000 (13:07 +0200)]
usb: dwc3: gadget: use evt->cache for processing events

Let's start copying events from evt->buf to
evt->cache and use evt->cache for processing events.

A follow-up patch will be added to clear events in
the top-half handler in order to bring IRQ line low
as soon as possible.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: use evt->length as we should
Felipe Balbi [Tue, 15 Nov 2016 11:05:23 +0000 (13:05 +0200)]
usb: dwc3: gadget: use evt->length as we should

Instead of always accessing the macro directly,
let's rely on evt->length which is the actual length
of current event buffer. While unlikely, we could
change event buffer's size at any time.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: core: add a event buffer cache
John Youn [Tue, 15 Nov 2016 10:54:15 +0000 (12:54 +0200)]
usb: dwc3: core: add a event buffer cache

This extra buffer will be used so we can copy
triggered events from our event buffer to this cache
and process all of them later in bottom half
handler.

We need this in order to implement a workaround for
a known erratum in recent DWC3 release.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: phy: phy-generic: add the implementation of .set_suspend
Peter Chen [Mon, 31 Oct 2016 02:18:20 +0000 (10:18 +0800)]
usb: phy: phy-generic: add the implementation of .set_suspend

Add clock operation at .set_suspend if the PHY has
suspend requirement, it can be benefit of power saving for
phy and the whole system (parent clock may also be disabled).

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: core: remove dwc3_soft_reset()
Felipe Balbi [Mon, 14 Nov 2016 09:24:53 +0000 (11:24 +0200)]
usb: dwc3: core: remove dwc3_soft_reset()

dwc3_soft_reset() is doing the same thing as
dwc3_core_soft_reset(). Let's remove
dwc3_soft_reset() since that's not needed anymore.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: Fix checkpatch error for braces
Anson Jacob [Sat, 12 Nov 2016 00:07:01 +0000 (19:07 -0500)]
usb: gadget: Fix checkpatch error for braces

Fix error message by checkpath.pl
open brace '{' following struct/enum go on the same line

Patch applied by running fix inplace capability of checkpatch:
checkpatch.pl -f *.[ch] --types OPEN_BRACE --fix-inplace

Signed-off-by: Anson Jacob <ansonjacob.aj@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: isp1301-omap: don't opencode IS_REACHABLE()
Fabian Frederick [Sat, 12 Nov 2016 08:49:12 +0000 (09:49 +0100)]
usb: isp1301-omap: don't opencode IS_REACHABLE()

We have a macro which does the same trick. Let's
use it.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: core: urb make use of usb_endpoint_maxp_mult
Mike Krinkin [Sun, 13 Nov 2016 10:31:16 +0000 (13:31 +0300)]
usb: core: urb make use of usb_endpoint_maxp_mult

Since usb_endpoint_maxp now returns only lower 11 bits mult
calculation here isn't correct anymore and that breaks webcam
for me. Patch make use of usb_endpoint_maxp_mult instead of
direct calculation.

Fixes: abb621844f6a ("usb: ch9: make usb_endpoint_maxp() return
       only packet size")

Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: Add a function to check properties
John Youn [Fri, 11 Nov 2016 01:08:51 +0000 (17:08 -0800)]
usb: dwc3: Add a function to check properties

Add a function to check properties and call it from probe. This will
allow us to add check code without bloating the probe function. This
needs to be done after dwc3_get_properties() and dwc3_core_init() so
that all the properties and hardware configs are available.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: Add a check for the DWC_usb3 core
John Youn [Fri, 11 Nov 2016 01:08:48 +0000 (17:08 -0800)]
usb: dwc3: Add a check for the DWC_usb3 core

Add a helper function to check if we are running on a DWC_usb3 core.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add DDMA chain pointers to dwc2_hsotg_ep structure
Vahram Aharonyan [Thu, 10 Nov 2016 03:28:03 +0000 (19:28 -0800)]
usb: dwc2: gadget: Add DDMA chain pointers to dwc2_hsotg_ep structure

Add DMA descriptor members to the dwc2_hsotg_ep structure.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Transfer length limit checking for DDMA
Vahram Aharonyan [Thu, 10 Nov 2016 03:28:01 +0000 (19:28 -0800)]
usb: dwc2: gadget: Transfer length limit checking for DDMA

Add dwc2_gadget_get_chain_limit() function and its call in transfer
start routine to correctly estimate one go on transfer size if
descriptor DMA mode is selected.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: host: Rename MAX_DMA_DESC_SIZE to HOST_DMA_NBYTES_LIMIT
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:58 +0000 (19:27 -0800)]
usb: dwc2: host: Rename MAX_DMA_DESC_SIZE to HOST_DMA_NBYTES_LIMIT

Rename MAX_DMA_DESC_SIZE to HOST_DMA_NBYTES_LIMIT as it stores value of
host DMA descriptor transfer bytes' limit. Values are different in case
of gadget DMA descriptors.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add DMA descriptor chains for EP 0
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:56 +0000 (19:27 -0800)]
usb: dwc2: gadget: Add DMA descriptor chains for EP 0

Update dwc2_hsotg structure to add descriptor chains for EP 0: two DMA
descriptors for Setup phase, per one for IN/OUT data and status phases.
Add their allocation function dwc2_gadget_alloc_ctrl_desc_chains() and
its call during gadget probe.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add DMA descriptor status quadlet fields
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:53 +0000 (19:27 -0800)]
usb: dwc2: gadget: Add DMA descriptor status quadlet fields

Add device mode DMA transfer descriptor status quadlet field notations.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Add descriptor DMA parameter
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:48 +0000 (19:27 -0800)]
usb: dwc2: gadget: Add descriptor DMA parameter

Add a parameter for descriptor DMA and set it based on hardware
capabilities. This won't actually be used by the gadget until later,
when the descriptor DMA code is in place.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Make the DMA descriptor structure packed
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:46 +0000 (19:27 -0800)]
usb: dwc2: Make the DMA descriptor structure packed

Make the DMA descriptor structure packed to guarantee alignment and size
in memory.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Update DMA descriptor structure
Vahram Aharonyan [Thu, 10 Nov 2016 03:27:43 +0000 (19:27 -0800)]
usb: dwc2: Update DMA descriptor structure

Rename DMA descriptor structure from dwc2_hcd_dma_desc to dwc2_dma_desc
as it is applies to both host and gadget.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Deprecate g-use-dma binding
John Youn [Thu, 10 Nov 2016 03:27:40 +0000 (19:27 -0800)]
usb: dwc2: Deprecate g-use-dma binding

This is not needed as the gadget now fully supports DMA and it can
autodetect it. This was initially added because gadget DMA mode was only
partially implemented so could not be automatically enabled.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: Fix dead code writing GCTL.RAMCLKSEL
John Youn [Fri, 11 Nov 2016 01:23:25 +0000 (17:23 -0800)]
usb: dwc3: gadget: Fix dead code writing GCTL.RAMCLKSEL

The register programming code in dwc2_updated_ram_clk_sel() will never
be executed. And in fact the entire function can be removed as there is
no way to override the default value of GCTL.RAMCLKSEL. Remove the
function and add a comment explaining where GCTL.RAMCLKSEL should be
programmed if needed in the future.

This fixes dead code warnings in coverity.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Fix coverity issue in hcd_queue.c
Vardan Mikayelyan [Fri, 11 Nov 2016 01:38:21 +0000 (17:38 -0800)]
usb: dwc2: Fix coverity issue in hcd_queue.c

This fixes the coverity issues related to unreachable code with
debugging off.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Fix dead code in hcd.c
Vardan Mikayelyan [Fri, 11 Nov 2016 01:38:19 +0000 (17:38 -0800)]
usb: dwc2: Fix dead code in hcd.c

Because usb_pipetype() masks urb->pipe, the default case can never be
hit. Remove it. This cleans up a coverity warning.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: Remove descriptor arguments to ep_enable
John Youn [Thu, 10 Nov 2016 00:36:28 +0000 (16:36 -0800)]
usb: dwc3: gadget: Remove descriptor arguments to ep_enable

The __dwc3_gadget_endpoint_enable() function has access to the endpoint
descriptors via the usb_ep. So we don't need to pass them in as
arguments. The descriptors should be set by the caller prior to calling
usb_ep_enable().

Signed-off-by: John Youn <johnyoun@synopsys.com>
[felipe.balbi@linux.intel.com : minor improvements]

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: gadget: Update for new usb_endpoint_maxp()
Vardan Mikayelyan [Tue, 8 Nov 2016 18:57:00 +0000 (10:57 -0800)]
usb: dwc2: gadget: Update for new usb_endpoint_maxp()

Update the dwc2 driver for the new behavior of the usb_endpoint_maxp()
and also use the new usb_endpoint_maxp_mult() helper function.

This commit fixes failures in high-badwith ISOC transfer tests.

Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: warn on once when no trbs
Janusz Dziedzic [Wed, 9 Nov 2016 10:01:35 +0000 (11:01 +0100)]
usb: dwc3: warn on once when no trbs

Seems last time we hit few issues where
we get trb_left = 0, mainly because of
HWO bit still set in previous TRB.
Add warn on once to catch/fix such
problems much faster.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: isoc clean DWC3_EP_PENDING_REQUEST flag
Janusz Dziedzic [Wed, 9 Nov 2016 10:01:34 +0000 (11:01 +0100)]
usb: dwc3: isoc clean DWC3_EP_PENDING_REQUEST flag

After we kick_transfer we should clean
DWC3_EP_PENDING_REQUEST endpoint flag.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: fix post-increment
Janusz Dziedzic [Wed, 9 Nov 2016 10:01:33 +0000 (11:01 +0100)]
usb: dwc3: fix post-increment

Use pre-increment and set -ETIMEDOUT correctly.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: clean TRB if STARTTRANSFER fail
Janusz Dziedzic [Wed, 9 Nov 2016 10:01:32 +0000 (11:01 +0100)]
usb: dwc3: clean TRB if STARTTRANSFER fail

In case STARTTRANSFER will fail, clean TRB.
Seems HW in such case don't clean HWO bit.
So, without this cleanup prev_trb still have
HWO bit set.

In my case (without patch), after first START failed:
- dep->enqueue == 1
- dep->dequeue == 1
- prev_trb still have HWO set
- left_trb() == 0
No way to send more data.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: decrement queued_requests
Janusz Dziedzic [Wed, 9 Nov 2016 10:01:31 +0000 (11:01 +0100)]
usb: dwc3: decrement queued_requests

In case we will fail to STARTTRANSFER we should
also decrement queued_requests.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Add PCI properties
Vahram Aharonyan [Fri, 4 Nov 2016 00:56:15 +0000 (17:56 -0700)]
usb: dwc2: Add PCI properties

Add device parameters handling in dwc2-pci similar what is done in dwc3.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Get host DMA device properties
John Youn [Fri, 4 Nov 2016 00:56:12 +0000 (17:56 -0700)]
usb: dwc2: Get host DMA device properties

The driver will automatically enable host DMA and use it if available.
This is consistent with the behavior of all existing platforms.

Read in the "snps,host-dma-disable" device property to disable it.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Rename the dma_enable parameter to host_dma
John Youn [Fri, 4 Nov 2016 00:56:07 +0000 (17:56 -0700)]
usb: dwc2: Rename the dma_enable parameter to host_dma

Rename it so that it is more consistent with the gadget dma parameter.
It only affects host-mode operation so prefix it with "host".

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Move gadget settings into core_params
John Youn [Fri, 4 Nov 2016 00:56:05 +0000 (17:56 -0700)]
usb: dwc2: Move gadget settings into core_params

Move the gadget devicetree settings into the core_params structure and
document them. Then set and check them in params.c, with the addition of
some helper functions, and remove the equivalent code in gadget.c.

Because these parameters came from the standalone s3c driver, they have
a fixed default value rather than an autodetected one. Preserve and
document this behavior to avoid any compatibility issues.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Rename host_rx_fifo_size hardware parameter
John Youn [Fri, 4 Nov 2016 00:56:02 +0000 (17:56 -0700)]
usb: dwc2: Rename host_rx_fifo_size hardware parameter

This hardware parameter is not host specific. It also applies to device
mode. Drop the "host" from the name to make that clear.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove unnecessary prototypes
John Youn [Fri, 4 Nov 2016 00:56:00 +0000 (17:56 -0700)]
usb: dwc2: Remove unnecessary prototypes

Remove the unnecessary prototypes for all the parameter setting
functions and declare those functions 'static' in the params.c file.

Also remove the duplicate documentation that went along with them. They
are already documented as part of the params structure definition.

Then move the constants that went along with the prototype into the
structure.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove dwc2_set_all_params function
John Youn [Fri, 4 Nov 2016 00:55:57 +0000 (17:55 -0700)]
usb: dwc2: Remove dwc2_set_all_params function

Replace this by statically defining a function with defaults, and just
assigning it. This will allow us to use parameters of any type and any
default value.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Move parameter initialization into params.c
John Youn [Fri, 4 Nov 2016 00:55:55 +0000 (17:55 -0700)]
usb: dwc2: Move parameter initialization into params.c

Consolidate and move all the parameter initialization code from the
probe function to params.c.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Declare the core params struct statically
John Youn [Fri, 4 Nov 2016 00:55:53 +0000 (17:55 -0700)]
usb: dwc2: Declare the core params struct statically

This makes it consistent with the hw_params struct and simplifies the
memory management for future refactoring. Fix up usage in all files.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Add params.c file
John Youn [Fri, 4 Nov 2016 00:55:50 +0000 (17:55 -0700)]
usb: dwc2: Add params.c file

Add a params.c file and move all driver parameter code there, including
all the static parameter definitions.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove unused hardware parameter
John Youn [Fri, 4 Nov 2016 00:55:48 +0000 (17:55 -0700)]
usb: dwc2: Remove unused hardware parameter

The dma_desc_fs_enable does not correspond to any hardware parameter and
is unused. Remove it.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: Remove unnecessary kfree
John Youn [Fri, 4 Nov 2016 00:55:45 +0000 (17:55 -0700)]
usb: dwc2: Remove unnecessary kfree

This shouldn't be freed by the HCD as it is owned by the core and
allocated with devm_kzalloc.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agoUSB: phy: am335x-control: fix device and of_node leaks
Johan Hovold [Tue, 1 Nov 2016 10:40:25 +0000 (11:40 +0100)]
USB: phy: am335x-control: fix device and of_node leaks

Make sure to drop the references taken by of_parse_phandle() and
bus_find_device() before returning from am335x_get_phy_control().

Note that there is no guarantee that the devres-managed struct
phy_control will be valid for the lifetime of the sibling phy device
regardless of this change.

Fixes: 3bb869c8b3f1 ("usb: phy: Add AM335x PHY driver")
Acked-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: f_uac2: fix error handling at afunc_bind
Peter Chen [Tue, 8 Nov 2016 02:10:44 +0000 (10:10 +0800)]
usb: gadget: f_uac2: fix error handling at afunc_bind

The current error handling flow uses incorrect goto label, fix it

Cc: <stable@vger.kernel.org>
Fixes: d12a8727171c ("usb: gadget: function: Remove
redundant usb_free_all_descriptors")
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: fix request length error for isoc transfer
Peter Chen [Tue, 8 Nov 2016 02:08:24 +0000 (10:08 +0800)]
usb: gadget: fix request length error for isoc transfer

For isoc endpoint descriptor, the wMaxPacketSize is not real max packet
size (see Table 9-13. Standard Endpoint Descriptor, USB 2.0 specifcation),
it may contain the number of packet, so the real max packet should be
ep->desc->wMaxPacketSize && 0x7ff.

Cc: Felipe F. Tonello <eu@felipetonello.com>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Fixes: 16b114a6d797 ("usb: gadget: fix usb_ep_align_maybe
  endianness and new usb_ep_aligna")

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: f_hid add super speed support
Janusz Dziedzic [Thu, 3 Nov 2016 09:27:15 +0000 (10:27 +0100)]
usb: gadget: f_hid add super speed support

Add super speed descriptors to f_hid.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: mv_u3d: mv_u3d_start_queue() refactoring
Alexey Khoroshilov [Thu, 3 Nov 2016 13:16:32 +0000 (16:16 +0300)]
usb: gadget: mv_u3d: mv_u3d_start_queue() refactoring

The patch improves readability of mv_u3d_start_queue()
by rearranging its code with two semantic modifications:
- assignment zero to ep->processing if usb_gadget_map_request() fails;
- propagation of error code from mv_u3d_req_to_trb() instead of
  hardcoded -ENOMEM.

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: mv_u3d: add check for dma mapping error
Alexey Khoroshilov [Thu, 3 Nov 2016 13:16:31 +0000 (16:16 +0300)]
usb: gadget: mv_u3d: add check for dma mapping error

mv_u3d_req_to_trb() does not check for dma mapping errors.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: trace: purge dwc3_trace()
Felipe Balbi [Thu, 3 Nov 2016 12:07:51 +0000 (14:07 +0200)]
usb: dwc3: trace: purge dwc3_trace()

Finally get rid of dwc3_trace() hack. If any other
message is truly needed, we should add proper
tracepoints for them instead of hacking around with
dwc3_trace() or similar.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: trace: add a tracepoint for ep enable/disable
Felipe Balbi [Thu, 3 Nov 2016 11:53:29 +0000 (13:53 +0200)]
usb: dwc3: trace: add a tracepoint for ep enable/disable

instead of using a simple trace_printk() wrapper,
let's add an actual tracepoint and print further
details about the endpoint being operated upon.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: pci: call _DSM for suspend/resume
Felipe Balbi [Mon, 24 Oct 2016 07:40:18 +0000 (10:40 +0300)]
usb: dwc3: pci: call _DSM for suspend/resume

Intel's BXT devices need to execute a _DSM method
during {runtime_,}{suspend,resume} in order to get a
chunk of dwc3 to power gate and save some extra
power.

Let's do that now.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: pci: add a private driver structure
Felipe Balbi [Mon, 24 Oct 2016 07:29:01 +0000 (10:29 +0300)]
usb: dwc3: pci: add a private driver structure

We'll be tracking a little more information for PCI
drivers, it's about time we add a private structure
for that.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: always kick if num_pending_sgs > 0
Felipe Balbi [Tue, 25 Oct 2016 10:54:00 +0000 (13:54 +0300)]
usb: dwc3: gadget: always kick if num_pending_sgs > 0

When we get a half-way processed request, we should
make sure to try to prepare further TRBs for it or
for any possibly queued up request held in our
pending_list. This will make sure our controller is
kept busy for as long as possible.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: stop touching HWO TRBs
Felipe Balbi [Tue, 25 Oct 2016 10:50:46 +0000 (13:50 +0300)]
usb: dwc3: gadget: stop touching HWO TRBs

Say we have three requests prepared to the HW (reqA,
reqB, and reqC). All of them are composed of
SG-lists with several entries and they all requests
interrupt only on last TRBs of the SG-list.

When we get interrupt for reqA, it could be that
reqB is already half-way transferred and some of its
TRBs will have HWO already cleared.

It's okay to free up TRBs without HWO bit set, but
we need to guarantee we don't giveback a request
that's half-way transferred as that will confuse
gadget drivers.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: always try to prepare on started_list first
Felipe Balbi [Tue, 25 Oct 2016 10:48:52 +0000 (13:48 +0300)]
usb: dwc3: gadget: always try to prepare on started_list first

In cases where we're given an SG-list which is
longer than the amount of currently available TRBs,
we will be left with the same request on
started_list and we should prioritize that request
over possible new requests on pending_list. That's
a way to guarantee requests complete in order.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: tracking per-TRB remaining bytes
Felipe Balbi [Tue, 25 Oct 2016 10:47:21 +0000 (13:47 +0300)]
usb: dwc3: gadget: tracking per-TRB remaining bytes

This will give us a simpler way of figuring out how
many bytes were left in each TRB. It's useful for
cases where we queue only part of an SG-list due to
amount of available TRBs at the time of kicking the
transfer.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: cope with XferNotReady before usb_ep_queue()
Felipe Balbi [Fri, 21 Oct 2016 10:07:09 +0000 (13:07 +0300)]
usb: dwc3: gadget: cope with XferNotReady before usb_ep_queue()

If XferNotReady comes before usb_ep_queue() we will
set our PENDING request flag and wait for a
request. However, originally, we were assuming
usb_ep_queue() would always happen before our first
XferNotReady and that causes a corner case where we
could try to issue ENDTRANSFER command before
STARTTRANSFER.

Let's fix that by tracking endpoints which have been
started.

Reported-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: wait for End Transfer to complete
Baolin Wang [Mon, 31 Oct 2016 11:38:36 +0000 (19:38 +0800)]
usb: dwc3: gadget: wait for End Transfer to complete

Instead of just delaying for 100us, we should
actually wait for End Transfer Command Complete
interrupt before moving on. Note that this should
only be done if we're dealing with one of the core
revisions that actually require the interrupt before
moving on.

[ felipe.balbi@linux.intel.com: minor improvements ]

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: NCM: differentiate consumed packets from dropped packets
Torsten Polle [Mon, 19 Sep 2016 08:05:42 +0000 (10:05 +0200)]
usb: gadget: NCM: differentiate consumed packets from dropped packets

dev_kfree_skb_any() is used to free packets that are dropped by the
network stack. Therefore the function should not be used for packets
that have been successfully processed by the network stack. Instead
dev_consume_skb_any() has to be used for such consumed packets.

This separation helps to identify dropped packets.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: u_ether: link socket buffers to the device for received packets
Torsten Polle [Mon, 19 Sep 2016 08:05:41 +0000 (10:05 +0200)]
usb: gadget: u_ether: link socket buffers to the device for received packets

Socket buffers should be linked to the (network) device that allocated
the buffers. __netdev_alloc_skb performs this task.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: NCM: link socket buffers to the device for tx packets
Torsten Polle [Mon, 19 Sep 2016 08:05:40 +0000 (10:05 +0200)]
usb: gadget: NCM: link socket buffers to the device for tx packets

Socket buffers should be linked to the (network) device that allocated
the buffers.

Signed-off-by: Torsten Polle <tpolle@de.adit-jv.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: f_fs: use complete() instead complete_all()
Daniel Wagner [Thu, 22 Sep 2016 13:51:53 +0000 (15:51 +0200)]
usb: gadget: f_fs: use complete() instead complete_all()

There is only one waiter for the completion, therefore there
is no need to use complete_all(). Let's make that clear by
using complete() instead of complete_all().

The usage pattern of the completion is:

waiter context                          waker context
  reinit_completion()
  usb_esp_queue()
  wait_for_completion_interruptible()

ffs_ep0_complete()
  complete()

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: renesas_usbhs: cleanup with list_first_entry_or_null()
Masahiro Yamada [Sun, 18 Sep 2016 16:03:15 +0000 (01:03 +0900)]
usb: renesas_usbhs: cleanup with list_first_entry_or_null()

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: cleanup with list_first_entry_or_null()
Masahiro Yamada [Sun, 18 Sep 2016 16:03:14 +0000 (01:03 +0900)]
usb: dwc3: cleanup with list_first_entry_or_null()

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc2: cleanup with list_first_entry_or_null()
Masahiro Yamada [Sun, 18 Sep 2016 16:03:13 +0000 (01:03 +0900)]
usb: dwc2: cleanup with list_first_entry_or_null()

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: Convert pr_warning to pr_warn
Joe Perches [Tue, 27 Sep 2016 16:16:59 +0000 (09:16 -0700)]
usb: Convert pr_warning to pr_warn

Use the more common logging mechanism.

Miscellanea:

o Realign multiline statements
o Coalesce format

Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: gadget: composite: use kasprintf() instead of open coding it
Juergen Gross [Mon, 10 Oct 2016 10:48:36 +0000 (12:48 +0200)]
usb: gadget: composite: use kasprintf() instead of open coding it

Let's not reimplement generic kernel helpers,
instead call kasprintf().

[ felipe.balbi@linux.intel.com: better commit log ]

Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
7 years agousb: dwc3: gadget: don't clear RUN/STOP when it's invalid to do so
Baolin Wang [Fri, 14 Oct 2016 09:11:33 +0000 (17:11 +0800)]
usb: dwc3: gadget: don't clear RUN/STOP when it's invalid to do so

When we change the USB function with configfs dynamically, we possibly
met this situation: one core is doing the control transfer, another core
is trying to unregister the USB gadget from userspace, we must wait for
completing this control tranfer, or it will hang the controller to set
the DEVCTRLHLT flag.

[ felipe.balbi@linux.intel.com: several fixes to the patch
- call complete() before starting following SETUP transfer
- add a macro for ep0_in_setup's timeout
- change commit subject slightly
- break lines at 72 characters (git adds an 8-character tab)
- avoid changes to dwc3_gadget_run_stop() ]

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>