firefly-linux-kernel-4.4.55.git
7 years agorockchip: clk: rk3399: make the cpll as parent just for vop
Elaine Zhang [Mon, 12 Sep 2016 01:57:04 +0000 (09:57 +0800)]
rockchip: clk: rk3399: make the cpll as parent just for vop

others clk change it's parent from cpll to dummy_cpll.
the vop's parent just vpll and cpll,
make sure each vop have it's own pll as parent.

Change-Id: Ia61e10918e14a69c053455018ddf0183ff15ea19
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
7 years agoUPSTREAM: USB: dwc2-usb: add USB_GADGET dependency
Arnd Bergmann [Fri, 24 Jun 2016 07:30:26 +0000 (09:30 +0200)]
UPSTREAM: USB: dwc2-usb: add USB_GADGET dependency

The driver selects NOP_USB_XCEIV, which can only be built-in if
USB_GADGET is either disabled or also built-in, so with USB_DWC2_PCI=y
and USB_GADGET=m, NOP_USB_XCEIV is also built-in and we get this link
error:

drivers/usb/built-in.o: In function `nop_set_peripheral':
(text+0x1927c): undefined reference to `usb_gadget_vbus_connect'
drivers/usb/built-in.o: In function `nop_gpio_vbus_thread':
(text+0x197a0): undefined reference to `usb_gadget_vbus_connect'
(text+0x19830): undefined reference to `usb_gadget_vbus_disconnect'

This adds the same dependency for the dwc2 driver to avoid that
broken configuration.

Change-Id: Ia3f3812443ec143665a9c0382b8f5a2e0c52e9eb
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit e43470dbdfe8922f9b2962184336efaa71e59727)

7 years agoUPSTREAM: usb: dwc2: add printf attribute to cat_printf()
Nicolas Iooss [Sun, 26 Jun 2016 08:12:38 +0000 (10:12 +0200)]
UPSTREAM: usb: dwc2: add printf attribute to cat_printf()

As cat_printf() uses printf format strings in its parameters, adding
__printf attribute allows the compiler to detect at compile-time some
errors related to format strings (with -Wformat warning flag).

Change-Id: I3558d4a331acdf057c1daccbe86008ae0fd07216
Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit e135ab7405f562c7709806e355b1521ee68548dc)

7 years agoUPSTREAM: usb: dwc2: gadget: Final fixes for BDMA ISOC
Vardan Mikayelyan [Thu, 26 May 2016 01:07:22 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Final fixes for BDMA ISOC

Done fixes and tested hsotg gadget's BDMA mode. Tested Control,
Bulk, Isoc, Inter transfers. Added code for isoc transfers,
removed unusable code, done minor fixes. Affected functions
and IRQ handlers:
- dwc2_hsotg_start_req(),
- dwc2_hsotg_ep_enable(),
- dwc2_hsotg_ep_queue(),
- dwc2_hsotg_handle_outdone(),
- GINTSTS_GOUTNAKEFF handler,

Removed 'has_correct_parity' flag from 'dwc2_hsotg_ep' struct.
Before this patch series, to set the data pid the DWC2 gadget
driver was toggling the even/odd until it match, then were
leaving it set. But now I have added mechanism to set pid and
excluded all code where this flag was set.

Change-Id: Iba211bde33c6bdb19617d69b5cff2923c37e0e20
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 837e9f00bf9966d64abc1bce678271099a72423b)

7 years agoUPSTREAM: usb: dwc2: gadget: Add EP disabled interrupt handler
Vardan Mikayelyan [Thu, 26 May 2016 01:07:19 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add EP disabled interrupt handler

Reimplemented EP disabled interrupt handler and moved to
corresponding function.

This interrupt indicates that the endpoint has been disabled per
the application's request.

For IN endpoints flushes txfifo, in case of BULK clears DCTL_CGNPINNAK,
in case of ISOC completes current request.

For ISOC-OUT endpoints completes expired requests. If there is
remaining request starts it. This is the part of ISOC-OUT transfer
drop flow. When ISOC-OUT transfer expired we must disable ep to drop
ongoing transfer.

Change-Id: Id79f0ad59a3904a1f4951138463fd4cc0aa3b611
Tested-by: John Keeping <john@metanate.com>
Reviewed-by: Vahram Aharonyan <vahrama@synopsys.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit bd9971f0a1efe4b3ac6e2f8ec864c75f73ca7829)

7 years agoUPSTREAM: usb: dwc2: gadget: Add Incomplete ISO IN/OUT Interrupt handlers
Vardan Mikayelyan [Thu, 26 May 2016 01:07:17 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add Incomplete ISO IN/OUT Interrupt handlers

Incomplete ISO IN interrupt indicates one of the following conditions
occurred while transmitting an ISOC transaction.
- Corrupted IN Token for ISOC EP.
- Packet not complete in FIFO.

Incomplete ISO OUT indicates that there is at least one isochronous OUT
endpoint on which the transfer is not completed in the current
microframe.

The following actions will be taken:

In case of EP-IN
- Determine the EP
- Disable EP directly from this handler; when "Endpoint Disabled"
  interrupt is received flush FIFO

In case of EP-OUT
- Determine the EP
- If target frame elapsed set DCTL_SGOUTNAK, unmask GOUTNAKEFF and
  proceed as described in section 7.5.1 of DWC-HSOTG Programming Guide

Also added dwc2_gadget_target_frame_elapsed() helper function which
will be used in Incomplete ISO IN/OUT Interrupt handlers.

Change-Id: Id9832f7832eafc2c510f0d87bd38e4b820111352
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 381fc8f8228923026b3d75c8230fa2ee4d688f32)

7 years agoUPSTREAM: usb: dwc2: gadget: Add OUTTKNEPDIS and NAKINTRPT handlers
Vardan Mikayelyan [Thu, 26 May 2016 01:07:14 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add OUTTKNEPDIS and NAKINTRPT handlers

NAKINTRPT interrupt is starting point for isoc-in transfer,
synchronization done with first in token received from host,
core asserts this interrupt when responds with 0 length data
to in token, received from host.

The first IN token is asynchronous for device - device does not
know when first one token will arrive from host. On first token
arrival HW generates 2 interrupts: 'in token received while FIFO
empty' and 'NAK'. NAK interrupt for ISOC in means that token has
arrived and ZLP was sent in response to that as there was no data
in FIFO. SW is basing on this interrupt to obtain frame in which
token has come and then based on the interval calculates next
frame for transfer.

OUTTKNEPDIS interrupt is starting point for isoc-out transfer,
synchronization done with first out token received from host
while corresponding ep is disabled.

For OUTs the reason is same - device does not know initial frame
in which out token will come. For this HW generates OUTTKNEPDIS
- out token is received while EP is disabled. Upon getting this
interrupt SW starts calculation for next transfer frame.

Change-Id: I178a19c9afbac314096e9a989966c3c778f95fce
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 5321922cb6fa0f513fdd8ce73b281f4b9957886b)

7 years agoUPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_start_next_request function
Vardan Mikayelyan [Thu, 26 May 2016 01:07:12 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_start_next_request function

Replaced repeating code with function call.

Starts next request from ep queue.
If queue is empty and ep is isoc
-In case of OUT-EP unmasks OUTTKNEPDIS.

OUTTKNEPDIS is masked in it's handler, so we need to unmask it here
to be able to do resynchronization.

Change-Id: Ib9d72c0ef728e145ac959218386c333f674ae0e2
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 41cc4cd2716fa6d18a1a09d740ea075adecfa7dd)

7 years agoUPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_read_ep_interrupts function
Vardan Mikayelyan [Thu, 26 May 2016 01:07:10 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_read_ep_interrupts function

Reads and returns interrupts for given endpoint, by masking epint_reg
with corresponding mask.

Change-Id: I8f5af249b8569a19435665bef2c2a841672f1c03
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 326015887b6a1321fd61f7a16816241ad841a03c)

7 years agoUPSTREAM: usb: dwc2: gadget: Corrected interval calculation
Vardan Mikayelyan [Thu, 26 May 2016 01:07:07 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Corrected interval calculation

Calculate the interval according to the USB 2.0 specification section
9.6.6.

Change-Id: I918faedbaa22d0151d48ed45907baf71f000c831
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 142bd33fcd185d850178f7f8697ecbeaaa18e257)

7 years agoUPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_incr_frame_num()
Vardan Mikayelyan [Thu, 26 May 2016 01:07:05 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_incr_frame_num()

Increases and checks targeted frame number of current ep
if overrun happened, sets flag and masks with DSTS_SOFFN_LIMIT

Added following fields to struct dwc2_hsotg_ep
-target_frame: Targeted frame num to setup next ISOC transfer
-frame_overrun: Indicates SOF number overrun in DSTS

Change-Id: I80c0bc7bfe18e4e88b051795486c1cfccaa95b42
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 92d1635d781ac17fc7d886b0c126838083f3c2b9)

7 years agoUPSTREAM: usb: dwc2: gadget: Fix transfer stop programming for out endpoint
Vardan Mikayelyan [Thu, 26 May 2016 01:07:02 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Fix transfer stop programming for out endpoint

According DWC-OTG databook, "GOUTNakEff" is read only and can be
cleared only by "DCTL.CGOUTNak", but here we do not need to clear
it because DWC-OTG programming guide says that before disabling
any OUT endpoint, the application must enable Global OUT NAK mode,
so if this mode is enabled we can continue without this step.

Change-Id: If85da6787d585582712ca5d116db52caa70e72fc
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6b58cb07a850f9b6d348feb2455b2c264a515f4a)

7 years agoUPSTREAM: usb: dwc2: gadget: Corrected field names
Vardan Mikayelyan [Thu, 26 May 2016 01:07:00 +0000 (18:07 -0700)]
UPSTREAM: usb: dwc2: gadget: Corrected field names

No-op change. Changed field names to prevent misunderstanding.

Change-Id: I16d6c510a8efb88c12e2205a23d838e23012ed97
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 26ddef5da62993fb9189a822d3545fc00451d242)

7 years agoUPSTREAM: usb: dwc2: gadget: Remove unnecessary code
Vardan Mikayelyan [Thu, 26 May 2016 01:06:58 +0000 (18:06 -0700)]
UPSTREAM: usb: dwc2: gadget: Remove unnecessary code

This chunk is not needed here. There is no functionality
depend on this, so if no-op, I think we do not need to have
this interrupt unmasked.

Change-Id: I74a0861ce66e23888c001b7cf1833b7cce715362
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 7c01b99154c5819bb811100738880a1341bca64a)

7 years agoUPSTREAM: usb: dwc2: gadget: Remove unnecessary line
Vardan Mikayelyan [Thu, 26 May 2016 01:06:55 +0000 (18:06 -0700)]
UPSTREAM: usb: dwc2: gadget: Remove unnecessary line

Removed "ctrl |= DXEPCTL_USBACTEP" from
dwc2_hsotg_start_req() function because this
step is done in dwc2_hsotg_ep_enable().

Change-Id: I9675b30e1849c4f9d1ee099df44023dda8b5cf13
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 04cde4787d8d9c56bd7b0bc5ee15af4435275134)

7 years agoUPSTREAM: usb: dwc2: Add missing register field definitions
Vardan Mikayelyan [Thu, 26 May 2016 01:06:53 +0000 (18:06 -0700)]
UPSTREAM: usb: dwc2: Add missing register field definitions

Added register field definitions, register names are according
DWC-OTG databook.

Change-Id: I4eb5aa7763760bb9c9ef9e0107250fe4015c8750
Tested-by: John Keeping <john@metanate.com>
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 106528b21df7dd9da9ca3e5e4ff4e015c33211be)

7 years agoUPSTREAM: usb: dwc2: gadget: Do not halt isochronous endpoints
Vahram Aharonyan [Tue, 24 May 2016 05:41:59 +0000 (22:41 -0700)]
UPSTREAM: usb: dwc2: gadget: Do not halt isochronous endpoints

Add a check in dwc2_hsotg_ep_sethalt() so that it does not halt
isochronous endpoints.

Change-Id: I72d5cf2ba7fb6cfa8ab8e33d16c4e3b33ce31e4f
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 15186f1011b088432a10f435aa6e2df5ab177503)

7 years agoUPSTREAM: usb: dwc2: gadget: Do not halt endpoint if active
Vahram Aharonyan [Tue, 24 May 2016 05:41:57 +0000 (22:41 -0700)]
UPSTREAM: usb: dwc2: gadget: Do not halt endpoint if active

The gadget API function usb_ep_set_halt() expects the gadget to return
-EAGAIN if the ep is active. Add support for this behavior.

Otherwise this may break mass storage protocol if a STALL is attempted
on the endpoint.

Change-Id: I935ca97dfc5f6a97c2aeaef0afab97d7a0324a3a
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 51da43b555ba19e0230ff5a5acc58eb0fffb6026)

7 years agoUPSTREAM: usb: dwc2: Proper cleanup on dr_mode failure
John Youn [Thu, 28 Apr 2016 03:20:56 +0000 (20:20 -0700)]
UPSTREAM: usb: dwc2: Proper cleanup on dr_mode failure

Cleanup in probe if we fail to get dr_mode.

Change-Id: I8b2f1cf210b9baa6fc81bddd9b64be1bf5e657fb
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit a6ef3e02542a33fb705e6977221deb0292b27398)

7 years agoUPSTREAM: usb: dwc2: Fixed SOF interrupt enabling/disabling
Sevak Arakelyan [Thu, 28 Apr 2016 03:20:53 +0000 (20:20 -0700)]
UPSTREAM: usb: dwc2: Fixed SOF interrupt enabling/disabling

In case of DDMA mode we don't need to get an SOF interrupt so disable
the unmasking of SOF interrupt in DDMA mode.

Change-Id: I8a58bf26e8c9493a39e3f8ba6da1204d13b52127
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 907a444718b8f93956acac1c944d880c54ab900d)

7 years agoUPSTREAM: usb: dwc2: host: Setting qtd to NULL after freeing it
Vardan Mikayelyan [Thu, 28 Apr 2016 03:20:51 +0000 (20:20 -0700)]
UPSTREAM: usb: dwc2: host: Setting qtd to NULL after freeing it

This is safety change added while doing slub debugging.

Affected functions:
dwc2_hcd_qtd_unlink_and_free()
_dwc2_hcd_urb_enqueue()

Change-Id: Ie541e0390fd5475852ede4216b2b90d7a87f5430
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit b0d659022e5c96ee5c4bd62d22d3da2d66de306b)

7 years agoUPSTREAM: usb: dwc2: gadget: Prevent handling of host interrupts
Vardan Mikayelyan [Thu, 28 Apr 2016 03:20:48 +0000 (20:20 -0700)]
UPSTREAM: usb: dwc2: gadget: Prevent handling of host interrupts

In host slave mode, the core asserts the rxready, txfifoempty interrupts
that get serviced in the gadget irq handler. Prevent servicing of these
when not in the gadget mode of operation.

Change-Id: I821c48399f876de045649507435bf2a3e9cf4cc5
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit ee3de8d750134703c702534173cd8623d1b32c38)

7 years agoUPSTREAM: usb: dwc2: gadget: Check for ep0 in enable
Vahram Aharonyan [Thu, 28 Apr 2016 03:20:46 +0000 (20:20 -0700)]
UPSTREAM: usb: dwc2: gadget: Check for ep0 in enable

Replaced the WARN_ON with a check and return of -EINVAL in the
dwc2_hsotg_ep_enable function if ep0 is passed in.

Change-Id: Idf4bf147a52ff9dca294f76263438e41cc511cfc
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>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 8c3d609275f7f39d308e5c40a6220c67454f7a28)

7 years agoUPSTREAM: usb: dwc2: do not override forced dr_mode in gadget setup
Przemek Rudy [Wed, 16 Mar 2016 22:10:26 +0000 (23:10 +0100)]
UPSTREAM: usb: dwc2: do not override forced dr_mode in gadget setup

The host/device mode set with dr_mode should be kept all the time,
not being changed to OTG in gadget setup (by overriding CFGUSB_FORCEDEVMODE
and CFGUSB_FORCEHOSTMODE bits).

Change-Id: I80037fb325d00cb302c223a65ef3ac628955fe08
Acked-by: John Youn <johnyoun@synopsys.com>
Tested-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Przemek Rudy <prudy1@o2.pl>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit ecd9a7ad453c5effc9a26355b79ee83f1337cba4)

7 years agoUPSTREAM: usb: dwc2: Fix issues in dwc2_complete_non_isoc_xfer_ddma()
John Youn [Tue, 1 Mar 2016 01:53:35 +0000 (17:53 -0800)]
UPSTREAM: usb: dwc2: Fix issues in dwc2_complete_non_isoc_xfer_ddma()

Fixes a static analysis issue in dwc2_complete_non_isoc_xfer_ddma(). The
qtd was being passed to a function after being freed. It was not being
used in the function so this doesn't fix any bugs. But it fixes up the
warning and makes the code safer by setting qtd to NULL and not using it
at all.

Change-Id: I5224d5b7854c23cc0d0931b5a131f93b9a2ce8c8
Reported-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 1fc659894994c7faa67e51a4b5a981ab4cf0f3a5)

7 years agoUPSTREAM: usb: dwc2: Add support for Lantiq ARX and XRX SoCs
Antti Seppälä [Sat, 27 Feb 2016 10:31:24 +0000 (12:31 +0200)]
UPSTREAM: usb: dwc2: Add support for Lantiq ARX and XRX SoCs

Add support for Lantiq ARX and XRX SoC families to the dwc2 driver.

Change-Id: If63c644caae24de6f7230923a63eda40a6b486c2
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6c0c0951bbf8c2c216675fe277fba4c42aa0a2bf)

7 years agoUPSTREAM: usb: dwc2: Move host-specific core functions into hcd.c
John Youn [Wed, 24 Feb 2016 03:55:00 +0000 (19:55 -0800)]
UPSTREAM: usb: dwc2: Move host-specific core functions into hcd.c

Move host core initialization and host channel routines into hcd.c. This
allows these functions to only be compiled in host-enabled driver
configurations (DRD or host-only).

Change-Id: Ib7ed69e977143de58a6055ecf417a48cf603cdff
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit b02038faa7f1b228983d05633c8345f826b20042)

7 years agoUPSTREAM: usb: dwc2: Move register save and restore functions
John Youn [Wed, 24 Feb 2016 03:54:57 +0000 (19:54 -0800)]
UPSTREAM: usb: dwc2: Move register save and restore functions

Move the register save and restore functions into the host and gadget
specific files.

Change-Id: If9a11b19ee459d0cd1cd560f0302c83518b3f6af
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 58e52ff6a6c3ce964c71b2dd9f06be426f993524)

7 years agoUPSTREAM: usb: dwc2: Use kmem_cache_free()
Amitoj Kaur Chawla [Mon, 22 Feb 2016 08:10:32 +0000 (13:40 +0530)]
UPSTREAM: usb: dwc2: Use kmem_cache_free()

Here, free memory is allocated using kmem_cache_zalloc.  So, use
kmem_cache_free instead of kfree.

This is done using Coccinelle and semantic patch used
is as follows:

//<smpl>
@@
expression x,E,c;
@@
 x =
\(kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\)(c,...)
 ... when != x = E
     when != &x
?-kfree(x)
+kmem_cache_free(c,x)
//</smpl>

Change-Id: I41fee7d3451196cc04d99104ecb7f4e7f84df3c9
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 9bbe91a1ea4cae20ff9f8f175c92e1e49b4296d9)

7 years agoUPSTREAM: usb: dwc2: host: If using uframe scheduler, end splits better
Douglas Anderson [Fri, 29 Jan 2016 02:20:13 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: If using uframe scheduler, end splits better

The microframe scheduler figured out exactly how many transfers we need
for a split transaction.  Let's use this knowledge to know when to end
things.

Without this I found that certain devices would just keep responding
with tons of NYET resonses on their INT_IN endpoint.  These would just
keep going and going and eventually we'd decide to terminate the
transfer (because the whole frame changed), but by that time the
scheduler would decide that we "missed" the start of the next transfer.
I can also imagine that if we blow past the end of our scheduled time we
may mess up other things that were scheduled to happen.

No known test cases are improved by this patch except that the scheduler
code doesn't yell about MISSES constantly anymore.

Change-Id: I743b8b121a3c41fdec33b463318f816654aa2bba
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 1479cb698ac07d5dc4cc2b7de3588d38484267e9)

7 years agoUPSTREAM: usb: dwc2: host: Totally redo the microframe scheduler
Douglas Anderson [Fri, 29 Jan 2016 02:20:12 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Totally redo the microframe scheduler

This totally reimplements the microframe scheduler in dwc2 to attempt to
handle periodic splits properly.  The old code didn't even try, so this
was a significant effort since periodic splits are one of the most
complicated things in USB.

I've attempted to keep the old "don't use the microframe" schduler
around for now, but not sure it's needed.  It has also only been lightly
tested.

I think it's pretty certain that this scheduler isn't perfect and might
have some bugs, but it seems much better than what was there before.
With this change my stressful USB test (USB webcam + USB audio + some
keyboards) crackles less.

Change-Id: Ifca7815fdff3301c0897aa4eb55e573384596344
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 9f9f09b048f5fdfded26149defd61b737b314ba0)

7 years agoUPSTREAM: usb: dwc2: host: Properly set even/odd frame
Douglas Anderson [Fri, 29 Jan 2016 02:20:11 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Properly set even/odd frame

When setting up ISO and INT transfers dwc2 needs to specify whether the
transfer is for an even or an odd frame (or microframe if the controller
is running in high speed mode).

The controller appears to use this as a simple way to figure out if a
transfer should happen right away (in the current microframe) or should
happen at the start of the next microframe.  Said another way:

- If you set "odd" and the current frame number is odd it appears that
  the controller will try to transfer right away.  Same thing if you set
  "even" and the current frame number is even.
- If the oddness you set and the oddness of the frame number are
  _different_, the transfer will be delayed until the frame number
  changes.

As I understand it, the above technique allows you to plan ahead of time
where possible by always working on the next frame.  ...but it still
allows you to properly respond immediately to things that happened in
the previous frame.

The old dwc2_hc_set_even_odd_frame() didn't really handle this concept.
It always looked at the frame number and setup the transfer to happen in
the next frame.  In some cases that meant that certain transactions
would be transferred in the wrong frame.

We'll try our best to set the even / odd to do the transfer in the
scheduled frame.  If that fails then we'll do an ugly "schedule ASAP".
We'll also modify the scheduler code to handle this and not try to
schedule a second transfer for the same frame.

Note that this change relies on the work to redo the microframe
scheduler.  It can work atop ("usb: dwc2: host: Manage frame nums better
in scheduler") but it works even better after ("usb: dwc2: host: Totally
redo the microframe scheduler").

With this change my stressful USB test (USB webcam + USB audio +
keyboards) has less audio crackling than before.

Change-Id: I235e689c89be99a9f6ac406164c88e1d82e87260
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 9cf1a601d2affe9c2633ac47ac875c035dd1eb69)

7 years agoUPSTREAM: usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call
Douglas Anderson [Fri, 29 Jan 2016 02:20:10 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call

As we start getting more exact about our scheduling it's becoming more
and more important to know exactly how far through the current frame we
are.  This lets us make decisions about whether there's still time left
to start a new transaction in the current frame.

We'll add dwc2_hcd_get_future_frame_number() which will tell you what
the frame number will be a certain number of microseconds (us) from
now.  We can use this information to help decide if there's enough time
left in the frame for a transaction that will take a certain duration.

This is expected to be used by a future change ("usb: dwc2: host:
Properly set even/odd frame").

Change-Id: I3cb39be7281e537696b6378e798c36ccea254739
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit fae4e82609b0887d6d675170d0c20b6af45d83ba)

7 years agoUPSTREAM: usb: dwc2: host: Manage frame nums better in scheduler
Douglas Anderson [Fri, 29 Jan 2016 02:20:08 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Manage frame nums better in scheduler

The dwc2 scheduler (contained in hcd_queue.c) was a bit confusing in the
way it initted / kept track of which frames a QH was going to be active
in.  Let's clean things up a little bit in preparation for a rewrite of
the microframe scheduler.

Specifically:
* Old code would pick a frame number in dwc2_qh_init() and would try to
  pick it "in a slightly future (micro)frame".  As far as I can tell the
  reason for this was that there was a delay between dwc2_qh_init() and
  when we actually wanted to dwc2_hcd_qh_add().  ...but apparently this
  attempt to be slightly in the future wasn't enough because
  dwc2_hcd_qh_add() then had code to reset things if the frame _wasn't_
  in the future.  There's no reason not to just pick the frame later.
  For non-periodic QH we now pick the frame in dwc2_hcd_qh_add().  For
  periodic QH we pick the frame at dwc2_schedule_periodic() time.
* The old "dwc2_qh_init() actually assigned to "hsotg->frame_number".
  This doesn't seem like a great idea since that variable is supposed to
  be used to keep track of which SOF the interrupt handler has seen.
  Let's be clean: anyone who wants the current frame number (instead of
  the one as of the last interrupt) should ask for it.
* The old code wasn't terribly consistent about trying to use the frame
  that the microframe scheduler assigned to it.  In
  dwc2_sched_periodic_split() when it was scheduling the first frame it
  always "ORed" in 0x7 (!).  Since the frame goes on the wire 1 uFrame
  after next_active_frame it meant that the SSPLIT would always try for
  uFrame 0 and the transaction would happen on the low speed bus during
  uFrame 1.  This is irregardless of what the microframe scheduler
  said.
* The old code assumed it would get called to schedule the next in a
  periodic split very quickly.  That is if next_active_frame was
  0 (transfer on wire in uFrame 1) it assumed it was getting called to
  schedule the next uFrame during uFrame 1 too (so it could queue
  something up for uFrame 2).  It should be possible to actually queue
  something up for uFrame 2 while in uFrame 2 (AKA queue up ASAP).  To
  do this, code needs to look at the previously scheduled frame when
  deciding when to next be active, not look at the current frame number.
* If there was no microframe scheduler, the old code would check for
  whether we should be active using "qh->next_active_frame ==
  frame_number".  This seemed like a race waiting to happen.  ...plus
  there's no way that you wouldn't want to schedule if next_active_frame
  was actually less than frame number.

Note that this change doesn't make 100% sense on its own since it's
expecting some sanity in the frame numbers assigned by the microframe
scheduler and (as per the future patch which rewries it) I think that
the current microframe scheduler is quite insane.  However, it seems
like splitting this up from the microframe scheduler patch makes things
into smaller chunks and hopefully adds to clarity rather than reduces
it.  The two patches could certainly be squashed.  Not that in the very
least, I don't see any obvious bad behavior introduced with just this
patch.

I've attempted to keep the config parameter to disable the microframe
scheduler in tact in this change, though I'm not sure it's worth it.
Obviously the code is touched a lot so it's possible I regressed
something when the microframe scheduler is disabled, though I did some
basic testing and it seemed to work OK.  I'm still not 100% sure why you
wouldn't want the microframe scheduler (presuming it works), so maybe a
future patch (or a future version of this patch?) could remove that
parameter.

Change-Id: I22486b060e24c06868a31ed593a1e38608fe1f02
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit fb616e3f837eee20cc0c6d5866983f7d2730d5a3)

7 years agoUPSTREAM: usb: dwc2: host: Add scheduler logging for missed SOFs
Douglas Anderson [Fri, 29 Jan 2016 02:20:07 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Add scheduler logging for missed SOFs

We'll use the new "scheduler verbose debugging" macro to log missed
SOFs.  This is fast enough (assuming you configure it to use the ftrace
buffer) that we can do it without worrying about the speed hit.  The
overhead hit if the scheduler tracing is set to "no_printk" should be
near zero.

Change-Id: I2b4fa9ec5b4ddf15f9ff28d7a876cb4e6341a55d
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 483bb2544c470aebdcc41199c0b145d05058a3bd)

7 years agoUPSTREAM: usb: dwc2: host: Split code out to make dwc2_do_reserve()
Douglas Anderson [Fri, 29 Jan 2016 02:20:06 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Split code out to make dwc2_do_reserve()

This no-op change splits code out of dwc2_schedule_periodic() into a
dwc2_do_reserve() function.  This makes it a little easier to follow the
logic.

Change-Id: I24cd8d2718b150fdc0b4428e645c545b1d8dbeda
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 2d3f139810cd5d491d8dc8c3332c9d32b9b8e1f1)

7 years agoUPSTREAM: usb: dwc2: host: Reorder things in hcd_queue.c
Douglas Anderson [Fri, 29 Jan 2016 02:20:05 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Reorder things in hcd_queue.c

This no-op change just reorders a few functions in hcd_queue.c in order
to prepare for future changes.  Motivations here:

The functions dwc2_hcd_qh_free() and dwc2_hcd_qh_create() are exported
functions.  They are not called within the file.  That means that they
should be near the bottom so that they can easily call static helpers.

The function dwc2_qh_init() is only called by dwc2_hcd_qh_create() and
should move near the bottom with it.

The only reason that the dwc2_unreserve_timer_fn() timer function (and
its subroutine dwc2_do_unreserve()) were so high in the file was that
they needed to be above dwc2_qh_init().  Now that dwc2_qh_init() has
been moved down it can be moved down a bit.  A later patch will split
the reserve code out of dwc2_schedule_periodic() and the reserve
function should be near the unreserve function.  The reserve function
needs to be below dwc2_find_uframe() since it calls that.

Change-Id: Ia9a230c8521ca8e98bff606d1863760a62a448d1
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit b951c6c7f875d2c72c6e16a4d5fa810cbb33ae32)

7 years agoUPSTREAM: usb: dwc2: host: Rename some fields in struct dwc2_qh
Douglas Anderson [Fri, 29 Jan 2016 02:20:04 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Rename some fields in struct dwc2_qh

This no-op change just does some renames to simplify a future patch.

1. The "interval" field is renamed to "host_interval" to make it more
   obvious that this interval may be 8 times the interval that the
   device sees (if we're doing split transactions).  A future patch will
   also add the "device_interval" field.
2. The "usecs" field is renamed to "host_us" again to make it more
   obvious that this is the time for the transaction as seen by the
   host.  For split transactions the device may see a much longer
   transaction time.  A future patch will also add "device_us".
3. The "sched_frame" field is renamed to "next_active_frame".  The name
   "sched_frame" kept confusing me because it felt like something more
   permament (the QH's reservation or something).  The name
   "next_active_frame" makes it more obvious that this field is
   constantly changing.

Change-Id: I407af5bc79f46fcc63175603354ce20e8962982c
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit ced9eee1229db3bbe683ae17e0a91a8642382a39)

7 years agoUPSTREAM: usb: dwc2: host: Use periodic interrupt even with DMA
Douglas Anderson [Fri, 29 Jan 2016 02:20:03 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Use periodic interrupt even with DMA

The old code in dwc2_process_periodic_channels() would only enable the
"periodic empty" interrupt if we weren't using DMA.  That wasn't right
since we can still get into cases where we have small FIFOs even on
systems that have DMA (the rk3288 is a prime example).

Let's always enable/disable the "periodic empty" when appropriate.  As
part of this:

* Always call dwc2_process_periodic_channels() even if there's nothing
  in periodic_sched_assigned (we move the queue empty check so we still
  avoid the extra work).  That will make extra certain that we will
  properly disable the "periodic empty" interrupt even if there's
  nothing queued up.

* Move the enable of "periodic empty" due to non-empty
  periodic_sched_assigned to be for slave mode (non-DMA mode) only.
  Presumably this was the original intention of the check for DMA since
  it seems to match the comments above where in slave mode we leave
  things on the assigned queue.

Note that even before this change slave mode didn't work for me, so I
can't say for sure that my understanding of slave mode is correct.
However, this shouldn't change anything for slave mode so if slave mode
worked for someone in the past it ought to still work.

With this change, I no longer get constant misses reported by my other
debugging code (and with future patches) when I've got:
* Rockchip rk3288 Chromebook, using port ff540000
  -> Pluggable 7-port Hub with Charging (powered)
     -> Microsoft Wireless Keyboard 2000 in port 1.
     -> Das Keyboard in port 2.
     -> Jabra Speaker in port 3
     -> Logitech, Inc. Webcam C600 in port 4
     -> Microsoft Sidewinder X6 Keyboard in port 5

...and I'm playing music on the USB speaker and capturing video from the
webcam.

Change-Id: I9e6a9be0bcd35e4aff4eb8b004a40c31584f02cb
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 4e50e0110c5cdc6d361b813692857e09ec918c9d)

7 years agoUPSTREAM: usb: dwc2: host: There's not really a TT for the root hub
Douglas Anderson [Fri, 29 Jan 2016 02:20:02 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: There's not really a TT for the root hub

I find that when I plug a full speed (NOT high speed) hub into a dwc2
port and then I plug a bunch of devices into that full speed hub that
dwc2 goes bat guano crazy.  Specifically, it just spews errors like this
in the console:
  usb usb1: clear tt 1 (9043) error -22

The specific test case I used looks like this:
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
    |__ Port 1: Dev 17, If 0, Class=Hub, Driver=hub/4p, 12M
        |__ Port 2: Dev 19, If 0, ..., Driver=usbhid, 1.5M
        |__ Port 4: Dev 20, If 0, ..., Driver=usbhid, 12M
        |__ Port 4: Dev 20, If 1, ..., Driver=usbhid, 12M
        |__ Port 4: Dev 20, If 2, ..., Driver=usbhid, 12M

Showing VID/PID:
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 001 Device 017: ID 03eb:3301 Atmel Corp. at43301 4-Port Hub
 Bus 001 Device 020: ID 045e:0745 Microsoft Corp. Nano Transceiver ...
 Bus 001 Device 019: ID 046d:c404 Logitech, Inc. TrackMan Wheel

I spent a bunch of time trying to figure out why there are errors to
begin with.  I believe that the issue may be a hardware issue where the
transceiver sometimes accidentally sends a PREAMBLE packet if you send a
packet to a full speed device right after one to a low speed device.
Luckily the USB driver retries and the second time things work OK.

In any case, things kinda seem work despite the errors, except for the
"clear tt" spew mucking up my console.  Chalk it up for a win for
retries and robust protocols.

So getting back to the "clear tt" problem, it appears that we get those
because there's not actually a TT here to clear.  It's my understanding
that when dwc2 operates in low speed or full speed mode that there's no
real TT out there.  That makes all these attempts to "clear the TT"
somewhat meaningless and also causes the spew in the log.

Let's just skip all the useless TT clears.  Eventually we should root
cause the errors, but even if we do this is still a proper fix and is
likely to avoid the "clear tt" error in the future.

Note that hooking up a Full Speed USB Audio Device (Jabra 510) to this
same hub with the keyboard / trackball shows that even audio works over
this janky connection.  As a point to note, this particular change (skip
bogus TT clears) compared to just commenting out the dev_err() in
hub_tt_work() actually produces better audio.

Note: don't ask me where I got a full speed USB hub or whether the
massive amount of dust that accumulated on it while it was in my junk
box affected its funtionality.  Just smile and nod.

Change-Id: I58e40aa7ce25ef3138ed03913b27a19218b5bdbd
Acked-by: John Youn <johnyoun@synopsys.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit d82a810eede9c324d8353edde79b7e316f145f87)

7 years agoUPSTREAM: usb: dwc2: host: Properly set the HFIR
Douglas Anderson [Fri, 29 Jan 2016 02:20:01 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Properly set the HFIR

According to the most up to date version of the dwc2 databook, the FRINT
field of the HFIR register should be programmed to:
* 125 us * (PHY clock freq for HS) - 1
* 1000 us * (PHY clock freq for FS/LS) - 1

This is opposed to older versions of the doc that claimed it should be:
* 125 us * (PHY clock freq for HS)
* 1000 us * (PHY clock freq for FS/LS)

In case you didn't spot it, the difference is the "- 1".

Let's add the "- 1" to match the newest user manual.  It's presumed that
the "- 1" should have always been there and that this was always a
documentation error.  If some hardware needs the "- 1" and other
hardware doesn't, we'll have to add a configuration parameter for it in
the future.

I checked things before and after this patch on rk3288 using a Total
Phase Beagle 5000 analyzer.

Before this patch, a low speed mouse shows constant Frame Timing Jitter
errors.  After this patch errors have gone away.

Before this patch SOF packets move forward about 1 us per 4 ms.  After
this patch the SOF packets move backward about 1 us per 255 ms.  Some
specific SOF timestamps from the analyzer are below.

Before:
  6.603.790
  6.603.916
  6.604.041
  6.604.166
  ...
  6.607.541
  6.607.667
  6.607.792
  6.607.917
  ...
  6.611.417
  6.611.543
  6.611.668
  6.611.793

After:
  6.215.159
  6.215.284
  6.215.408
  6.215.533
  6.215.658
  ...
  6.470.658
  6.470.783
  6.470.907
  ...
  6.726.032
  6.726.157
  6.725.281
  6.725.406

Change-Id: Id431ef8fc208e8c73c22358422faf1016f81896a
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 9ed04d976146cf10dfa4c71171434af7c0348747)

7 years agoUPSTREAM: usb: dwc2: host: Giveback URB in tasklet context
Douglas Anderson [Fri, 29 Jan 2016 02:20:00 +0000 (18:20 -0800)]
UPSTREAM: usb: dwc2: host: Giveback URB in tasklet context

In commit 94dfd7edfd5c ("USB: HCD: support giveback of URB in tasklet
context") support was added to give back the URB in tasklet context.
Let's take advantage of this in dwc2.

This speeds up the dwc2 interrupt handler considerably.

Note that this requires the change ("usb: dwc2: host: Add a delay before
releasing periodic bandwidth") to come first.

Note that, as per Alan Stern in
<https://patchwork.kernel.org/patch/7555771/>, we also need to make sure
that the extra delay before the device drivers submit more data doesn't
break the scheduler.  At the moment the scheduler is pretty broken (see
future patches) so it's hard to be 100% certain, but I have yet to see
any new breakage introduced by this delay.  ...and speeding up interrupt
processing for dwc2 is a huge deal because it means we've got a better
chance of not missing SOF interrupts.  That means we've got an overall
win here.

Note that when playing USB audio and using a USB webcam and having
several USB keyboards plugged in, the crackling on the USB audio device
is noticably reduced with this patch.

Change-Id: Ieab057cad78d41492a390e9cfff825eed0f728a9
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 8add17cf8e4c55c8c4342ed42c8cdc1649ce0ab8)

7 years agoUPSTREAM: usb: dwc2: host: Add a delay before releasing periodic bandwidth
Douglas Anderson [Fri, 29 Jan 2016 02:19:59 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Add a delay before releasing periodic bandwidth

We'd like to be able to use HCD_BH in order to speed up the dwc2 host
interrupt handler quite a bit.  However, according to the kernel doc for
usb_submit_urb() (specifically the part about "Reserved Bandwidth
Transfers"), we need to keep a reservation active as long as a device
driver keeps submitting.  That was easy to do when we gave back the URB
in the interrupt context: we just looked at when our queue was empty and
released the reserved bandwidth then.  ...but now we need a little more
complexity.

We'll follow EHCI's lead in commit 9118f9eb4f1e ("USB: EHCI: improve
interrupt qh unlink") and add a 5ms delay.  Since we don't have a whole
timer infrastructure in dwc2, we'll just add a timer per QH.  The
overhead for this is very small.

Note that the dwc2 scheduler is pretty broken (see future patches to fix
it).  This patch attempts to replicate all old behavior and just add the
proper delay.

Change-Id: I051d768b1cefdbe8990a2dfae9c68c61ec9eedf0
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 17dd5b642d836ff7e12a780c2ec71a4be9bf9546)

7 years agoUPSTREAM: usb: dwc2: host: Add scheduler tracing
Douglas Anderson [Fri, 29 Jan 2016 02:19:58 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Add scheduler tracing

In preparation for future changes to the scheduler let's add some
tracing that makes it easy for us to see what's happening.  By default
this tracing will be off.

By changing "core.h" you can easily trace to ftrace, the console, or
nowhere.

Change-Id: I5a9ba2c44ac5caeecfae5910cc5434941c8d0fb8
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 74fc4a7558f859e89b849cc87afed38f517ded9a)

7 years agoUPSTREAM: usb: dwc2: host: fix split transfer schedule sequence
Douglas Anderson [Fri, 29 Jan 2016 02:19:57 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: fix split transfer schedule sequence

We're supposed to keep outstanding splits in order.  Keep track of a
list of the order of splits and process channel interrupts in that
order.

Without this change and the following setup:
* Rockchip rk3288 Chromebook, using port ff540000
  -> Pluggable 7-port Hub with Charging (powered)
     -> Microsoft Wireless Keyboard 2000 in port 1.
     -> Das Keyboard in port 2.

...I find that I get dropped keys on the Microsoft keyboard (I'm sure
there are other combinations that fail, but this documents my test).
Specifically I've been typing "hahahahahahaha" on the keyboard and often
see keys dropped or repeated.

After this change the above setup works properly.  This patch is based
on a previous patch proposed by Yunzhi Li ("usb: dwc2: hcd: fix periodic
transfer schedule sequence")

Change-Id: I1d461d73c21a117de86de2863c0412b4980a16d8
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Yunzhi Li <lyz@rock-chips.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
(cherry picked from commit c9c8ac0150df2b75b25683cd3df3cb56877e4e52)

7 years agoUPSTREAM: usb: dwc2: host: Always add to the tail of queues
Douglas Anderson [Fri, 29 Jan 2016 02:19:56 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Always add to the tail of queues

The queues the the dwc2 host controller used are truly queues.  That
means FIFO or first in first out.

Unfortunately though the code was iterating through these queues
starting from the head, some places in the code was adding things to the
queue by adding at the head instead of the tail.  That means last in
first out.  Doh.

Go through and just always add to the tail.

Doing this makes things much happier when I've got:
* 7-port USB 2.0 Single-TT hub
* - Microsoft 2.4 GHz Transceiver v7.0 dongle
* - Jabra speakerphone playing music

Change-Id: Iaaece8906b95cba659dab8b81211d83b23d11308
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 94ef7aee11c26e79441276ca43f0c25a04bd1303)

7 years agoUPSTREAM: usb: dwc2: host: Avoid use of chan->qh after qh freed
Douglas Anderson [Fri, 29 Jan 2016 02:19:55 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Avoid use of chan->qh after qh freed

When poking around with USB devices with slub_debug enabled, I found
another obvious use after free.  Turns out that in dwc2_hc_n_intr() I
was in a state when the contents of chan->qh was filled with 0x6b,
indicating that chan->qh was freed but chan still had a reference to
it.

Let's make sure that whenever we free qh we also make sure we remove a
reference from its channel.

The bug fixed here doesn't appear to be new--I believe I just got lucky
and happened to see it while stress testing.

Change-Id: I5affca3f0edc051a95c4992ade6b940e07ef3869
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 16e80218816488f016418717d23c660abe073a67)

7 years agoUPSTREAM: usb: dwc2: host: Set host_rx_fifo_size to 525 for rk3066
Douglas Anderson [Fri, 29 Jan 2016 02:19:54 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Set host_rx_fifo_size to 525 for rk3066

As documented in dwc2_calculate_dynamic_fifo(), host_rx_fifo_size should
really be:
 2 * ((Largest Packet size / 4) + 1 + 1) + n
 with n = number of host channel.

We have 9 host channels, so
 2 * ((1024/4) + 2) + 9 = 516 + 9 = 525

We've got 960 / 972 total_fifo_size on rk3288 (and presumably on
rk3066) and 525 + 128 + 256 = 909 so we're still under on both ports
even when we increment by 5.

In the future, it would be nice if dwc2_calculate_dynamic_fifo() could
handle the "too small" FIFO case and come up with something more
dynamically.  When we do that we can figure out how to allocate the
extra 48 / 60 bytes of FIFO that we're currently wasting.

NOTE: no known bugs are fixed by this patch, but it seems like a simple
fix and ought to fix someone.

Change-Id: Ia56c4cce7a01f570cce035a5e45c11ca431a797d
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 098c1ef8fe6bcdfed7905cea1debdd3a0ff9a16f)

7 years agoUPSTREAM: usb: dwc2: host: Get aligned DMA in a more supported way
Douglas Anderson [Fri, 29 Jan 2016 02:19:53 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: host: Get aligned DMA in a more supported way

All other host controllers who want aligned buffers for DMA do it a
certain way.  Let's do that too instead of working behind the USB core's
back.  This makes our interrupt handler not take forever and also rips
out a lot of code, simplifying things a bunch.

This also has the side effect of removing the 65535 max transfer size
limit.

NOTE: The actual code to allocate the aligned buffers is ripped almost
completely from the tegra EHCI driver.  At some point in the future we
may want to add this functionality to the USB core to share more code
everywhere.

Change-Id: Id4a2ebf476148b51ed4a514590887678d8901039
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: John Youn <johnyoun@synopsys.com>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3bc04e28a030a8b7dfa2227a7eaf748ada5e2c94)

7 years agoUPSTREAM: usb: dwc2: rockchip: Make the max_transfer_size automatic
Douglas Anderson [Fri, 29 Jan 2016 02:19:52 +0000 (18:19 -0800)]
UPSTREAM: usb: dwc2: rockchip: Make the max_transfer_size automatic

Previously we needed to set the max_transfer_size to explicitly be 65535
because the old driver would detect that our hardware could support much
bigger transfers and then would try to do them.  This wouldn't work
since the DMA alignment code couldn't support it.

Later in commit e8f8c14d9da7 ("usb: dwc2: clip max_transfer_size to
65535") upstream added support for clipping this automatically.  Since
that commit it has been OK to just use "-1" (default), but nobody
bothered to change it.

Let's change it to default now for two reasons:
- It's nice to use autodetected params.
- If we can remove the 65535 limit, we can transfer more!

Change-Id: I020c984ac4edf32488743d4daa0e24168f3152c0
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 40eed7d78378f1f609680a8a891a50cce12ed612)

7 years agoUPSTREAM: usb: dwc2: USB_DWC2 should depend on HAS_DMA
Geert Uytterhoeven [Tue, 16 Feb 2016 15:10:59 +0000 (16:10 +0100)]
UPSTREAM: usb: dwc2: USB_DWC2 should depend on HAS_DMA

If NO_DMA=y:

    ERROR: "usb_gadget_map_request" [drivers/usb/dwc2/dwc2.ko] undefined!
    ERROR: "usb_gadget_unmap_request" [drivers/usb/dwc2/dwc2.ko] undefined!
    ERROR: "bad_dma_ops" [drivers/usb/dwc2/dwc2.ko] undefined!

Add a dependency on HAS_DMA to fix this.

Change-Id: I293b13982d0c35afd48aa38c0dec4c31ebfa20ce
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit ee89b641a9ddca5f2d1e38d205473c4b0d26c670)

7 years agoUPSTREAM: usb: dwc2: host: fix the data toggle error in full speed descriptor dma
Tang, Jianqiang [Tue, 16 Feb 2016 23:02:07 +0000 (15:02 -0800)]
UPSTREAM: usb: dwc2: host: fix the data toggle error in full speed descriptor dma

There will be data toggle error happen for full speed buld-out transfer.
The data toggle bit is saved in qh for non-control transfers, it is wrong
to  check the qtd for that case.

Also fix one static analysis tool issue after fix the data toggle error.

John Youn:
* Added WARN() to warn on improper usage of the
  dwc2_hcd_save_data_toggle() function.

Change-Id: I9d0efcbf96aa65e7255397aa54af15d8b99d06a5
Signed-off-by: Dyson Lee <dyson.lee@intel.com>
Signed-off-by: Tang, Jianqiang <jianqiang.tang@intel.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 62943b7dfa35887a40f71f698deec4488bf73036)

7 years agoUPSTREAM: usb: dwc2: host: fix logical omissions in dwc2_process_non_isoc_desc
Vardan Mikayelyan [Tue, 16 Feb 2016 23:01:53 +0000 (15:01 -0800)]
UPSTREAM: usb: dwc2: host: fix logical omissions in dwc2_process_non_isoc_desc

Fixes memory manipulation issues and makes Host DDMA bulk transfers
work.

dwc2_process_non_isoc_desc() must return non zero value ONLY when
failure happens in one of the queued descriptors. After receiving
non zero value the caller must stop processing of remaining
QTDs and their descriptors from chain.

Commit 26a19ea699060fde ("usb: dwc2: host: fix use of qtd after
free in desc dma mode") breaks non_isoc transaction completion logic
in Host DDMA mode. There were bugs before that, but after this patch
dwc2_process_non_isoc_desc() returns fail status even if descriptor
was processed normally. This causes break from loop which is processing
remaining descriptors assigned to QTD, which is not correct for QTDs
containing more than one descriptor.

Current dwc2 driver gathers queued BULK URBs until receiving URB
without URB_NO_INTERRUPT flag. Once getting it, SW creates
descriptor chain, stores it in qh structure and passes start
address to HW. Multiple URB data is contained in that chain.
Hence on getting error on descriptor after its processing by HW,
SW should go out of both loops(qh->qtd, qtd->descs) and report
the failure.

Change-Id: Ie23695bcad29c155f3d22ecaba0a1c78ec35aec7
Fixes: 26a19ea699060fde ("usb: dwc2: host: fix use of qtd after free in desc dma mode")
Cc: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3142a16b9816c24501103a92010a283eb6e2766c)

7 years agoUPSTREAM: usb: dwc2: Add extra delay when forcing dr_mode
John Youn [Mon, 15 Feb 2016 23:30:20 +0000 (15:30 -0800)]
UPSTREAM: usb: dwc2: Add extra delay when forcing dr_mode

Fixes an issue found on rockchip rk3036 and rk3188 SOC platforms. For
some reason, the existing msleep(25) is not enough after the force mode.
The following patch was reported to fix the issue.

This does increase the probe delay again slightly, but not up to the
level it was before the original series of patches that this fixes. It
does not cause any other issues when tested on Synopsys HAPS and Altera
socfpga platforms.

Need to revisit this series next release to see if we can address these
issues without having an unconditional delay.

Change-Id: Ie06514eb87b0acc66edca21755069ba69751e6a5
Fixes: 09c96980dc72 ("usb: dwc2: Add functions to set and clear force mode")
Reported-by: Caesar Wang <caesar.upstream@gmail.com>
Reported-by: Michael Niewoehner <linux@mniewoehner.de>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Caesar Wang <caesar.upstream@gmail.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit bd84f4ae9986ac9acd278566ccb39c60bc961abb)

7 years agoUPSTREAM: usb: add HAS_IOMEM dependency to USB_DWC2
Vegard Nossum [Wed, 10 Feb 2016 14:29:44 +0000 (15:29 +0100)]
UPSTREAM: usb: add HAS_IOMEM dependency to USB_DWC2

drivers/built-in.o: In function `dwc2_driver_probe':
/home/vegard/linux/drivers/usb/dwc2/platform.c:491: undefined reference to `devm_ioremap_resource'

Change-Id: I34a1b15886144ece1dcd0561ed34995599eb2cd7
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 89f1ec8ee251920dd1bf07abf7a14c62d81d5733)

7 years agoUPSTREAM: usb: dwc2: Fix probe problem on bcm2835
John Youn [Tue, 12 Jan 2016 00:32:28 +0000 (16:32 -0800)]
UPSTREAM: usb: dwc2: Fix probe problem on bcm2835

Fixes an issue found on Raspberry PI platform that prevents probe. Don't
skip setting the force mode if it's already set.

Change-Id: I8fcef478dd4ad669cb3fc49d2308d126873213c7
Fixes: 09c96980dc72 ("usb: dwc2: Add functions to set and clear force mode")
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Reported-by: Stefan Wahren <stefan.wahren@i2se.com>
Reported-by: Remi Pommarel <repk@triplefau.lt>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Remi Pommarel <repk@triplefau.lt>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 192cb07f7928e8cb09a9851e6c0f7478baa3bc6d)

7 years agoUPSTREAM: Revert "usb: dwc2: Move reset into dwc2_get_hwparams()"
John Youn [Tue, 12 Jan 2016 00:32:14 +0000 (16:32 -0800)]
UPSTREAM: Revert "usb: dwc2: Move reset into dwc2_get_hwparams()"

This reverts commit 263b7fb557f7 ("usb: dwc2: Move reset into
dwc2_get_hwparams()") due to regression found on bcm2835 platform. USB
ethernet fails, due to being unable to pick up proper parameters when
performing a plain reset before reading hw params.

Below shows the results of the gnptxfsiz and hptxfsiz with and before
and after reverting this (from Stefan Wahren):

So here is the probe result before Patch 1 is applied:

[    1.283148] dwc2 20980000.usb: Configuration mismatch. dr_mode forced to host
[    1.313894] dwc2 20980000.usb: gnptxfsiz=00201000
[    1.314104] dwc2 20980000.usb: hptxfsiz=00000000
[    1.353908] dwc2 20980000.usb: 256 invalid for host_nperio_tx_fifo_size. Check HW configuration.
[    1.354262] dwc2 20980000.usb: 512 invalid for host_perio_tx_fifo_size. Check HW configuration.
[    1.394249] dwc2 20980000.usb: DWC OTG Controller
[    1.394561] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[    1.394917] dwc2 20980000.usb: irq 33, io mem 0x00000000

And here is the probe result after Patch 1 is applied:

[    1.280107] dwc2 20980000.usb: Configuration mismatch. dr_mode forced to host
[    1.353949] dwc2 20980000.usb: gnptxfsiz=01001000
[    1.354166] dwc2 20980000.usb: hptxfsiz=02002000
[    1.434301] dwc2 20980000.usb: DWC OTG Controller
[    1.434616] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[    1.434973] dwc2 20980000.usb: irq 33, io mem 0x00000000

Change-Id: I5a0f97b13d69654bf13344ae97096099ce551753
Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Reported-by: Stefan Wahren <stefan.wahren@i2se.com>
Reported-by: Remi Pommarel <repk@triplefau.lt>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Remi Pommarel <repk@triplefau.lt>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 03b32e4c9bd1b52fcf1e4304e7a704aa0315e398)

7 years agoUPSTREAM: usb: dwc2: add shutdown callback to platform variant
Heiko Stübner [Fri, 18 Dec 2015 18:30:59 +0000 (19:30 +0100)]
UPSTREAM: usb: dwc2: add shutdown callback to platform variant

In specific conditions (involving usb hubs) dwc2 devices can create a
lot of interrupts, even to the point of overwhelming devices running
at low frequencies. Some devices need to do special clock handling
at shutdown-time which may bring the system clock below the threshold
of being able to handle the dwc2 interrupts. Disabling dwc2-irqs
in a shutdown callbacks prevents reboots/poweroffs from getting stuck
in such cases.

The hsotg struct already contains an unused irq element, so we can
just use it to store the irq number for the shutdown callback.

Change-Id: Id320a8fdcd155d98ab5bb7768d03f15fa7b29c14
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Heiko Stuebner <heiko.stuebner@collabora.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit a40a00318c7fcdd23e73cfffac0e33430a43a3e3)

7 years agoUPSTREAM: usb: dwc2: gadget: Repair DSTS register decoding
Marek Vasut [Fri, 18 Dec 2015 02:26:17 +0000 (03:26 +0100)]
UPSTREAM: usb: dwc2: gadget: Repair DSTS register decoding

The "enumspd" field is located in register DSTS[2:1], but the code
which checks the bitfield does not shift the value accordingly. This
in turn causes incorrect detection of gadget link partner speed in
dwc2_hsotg_irq_enumdone() .

Shift the value accordingly to fix the problem with speed detection.

Change-Id: Ia84392906159ec512c71173ee842ea5c24b0eb0d
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6d76c92c2fcbee4fd1f6d7b375d71057c7a615b1)

7 years agoUPSTREAM: usb: dwc2: gadget: Remove call to dwc2_hsotg_init()
John Youn [Thu, 17 Dec 2015 19:18:41 +0000 (11:18 -0800)]
UPSTREAM: usb: dwc2: gadget: Remove call to dwc2_hsotg_init()

Remove call to dwc2_hsotg_init() from dwc2_gadget_init(). The
gadget_init function should not access any device registers because the
mode isn't guaranteed here.

Also, this is already called elsewhere before anything starts on the
gadget so it is not necessary here.

Change-Id: I677a97b4175af223a6e07bdd5eadd6e0d9deb723
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 60c0288c72c980fb37ed4e48f68c9743a53b662c)

7 years agoUPSTREAM: usb: dwc2: Remove redundant reset in probe
John Youn [Thu, 17 Dec 2015 19:18:27 +0000 (11:18 -0800)]
UPSTREAM: usb: dwc2: Remove redundant reset in probe

Reset already happens before this so just force the dr_mode.

Change-Id: I308ef9ea795ba654aca98af67ee1ecaba415397f
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 25362d318371e1e271dda24995ceabb8457b3b7c)

7 years agoUPSTREAM: usb: dwc2: Reduce delay when forcing mode in reset
John Youn [Thu, 17 Dec 2015 19:18:13 +0000 (11:18 -0800)]
UPSTREAM: usb: dwc2: Reduce delay when forcing mode in reset

The delay for force mode is only 25ms according to the databook.

Change-Id: Ib51c99f316a1efbf3ac2838ee2c248d6ad24c666
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 97e463886b873f62bea2293e7edf81fdb884b84f)

7 years agoUPSTREAM: usb: dwc2: gadget: Replace dwc2_hsotg_corereset()
John Youn [Thu, 17 Dec 2015 19:17:59 +0000 (11:17 -0800)]
UPSTREAM: usb: dwc2: gadget: Replace dwc2_hsotg_corereset()

The dwc2_core_reset() function exists in the core so use that one
instead.

Change-Id: I39a21bd4896221a6217d807f4a211af243686dd7
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 241729baa932a69cd203dbaa81abbb8af5b77b65)

7 years agoUPSTREAM: usb: dwc2: gadget: Use hw params from core
John Youn [Thu, 17 Dec 2015 19:17:45 +0000 (11:17 -0800)]
UPSTREAM: usb: dwc2: gadget: Use hw params from core

Use the previously cached hw params in the gadget. This saves a reset
and force mode in the gadget initialization during probe and makes
getting the hardware parameters consistent between gadget and host.

Change-Id: I62e3f1fadfc5a3a4e5af24b671e5a71e616c48e1
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 43e9034904dd37db7ed87fa8f5039c561c4004cd)

7 years agoUPSTREAM: usb: dwc2: Improve handling of host and device hwparams
John Youn [Thu, 17 Dec 2015 19:17:31 +0000 (11:17 -0800)]
UPSTREAM: usb: dwc2: Improve handling of host and device hwparams

Adds separate functions to get the host and device specific hardware
parameters. The functions check whether the parameters need to be read
at all, depending on dr_mode, and forces the mode only if necessary.
This saves some delays during probe. This also adds two device mode
parameters that will be used by the gadget.

Change-Id: I474f447fa750c9d5daa98a6ebd37b7929d0b4515
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 55e1040e424b59063da627fb580ec953f4c01de7)

7 years agoUPSTREAM: usb: dwc2: Add functions to set and clear force mode
John Youn [Thu, 17 Dec 2015 19:17:12 +0000 (11:17 -0800)]
UPSTREAM: usb: dwc2: Add functions to set and clear force mode

Added functions to set force mode for host and device. These functions
will check the current mode and only force if needed thus avoiding
unnecessary force mode delays. However clearing the mode is currently
done unconditionally and with the delay in place. This is needed during
the connector ID status change interrupt in order to ensure that the
mode has changed properly. This preserves the old behavior only for this
case. The warning comment about this is moved into the clear mode
condition.

Change-Id: I9f7f1056071e2bb4ac1f6482d355241f1c827469
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 09c96980dc723462ed2eeacc945fed5bcb278f85)

7 years agoUPSTREAM: usb: dwc2: Move reset into dwc2_get_hwparams()
John Youn [Thu, 17 Dec 2015 19:16:58 +0000 (11:16 -0800)]
UPSTREAM: usb: dwc2: Move reset into dwc2_get_hwparams()

The reset is required to get reset values of the hardware parameters but
the force mode is not. Move the base reset into dwc2_get_hwparams() and
do the reset and force mode afterwards.

Change-Id: I6ff12abe95a1dc9205496cb140c8c61958088c0e
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 263b7fb557f797d9d4d1dcf93fb6bb2efc3f1d46)

7 years agoUPSTREAM: usb: dwc2: Move mode querying functions into core.h
John Youn [Thu, 17 Dec 2015 19:16:45 +0000 (11:16 -0800)]
UPSTREAM: usb: dwc2: Move mode querying functions into core.h

These functions should go in core.h where they can be called from core,
device, or host.

Change-Id: I03e22ee0f6819998d152fab25c5b0b47e76275e1
Signed-off-by: John Youn <johnyoun@synopsys.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 1696d5ab99ef885ae62da5ad58f9eff16da7ff78)

7 years agoUPSTREAM: usb: dwc2: Fix dr_mode validation
John Youn [Thu, 17 Dec 2015 19:16:31 +0000 (11:16 -0800)]
UPSTREAM: usb: dwc2: Fix dr_mode validation

The dr_mode parameter was being checked against how the dwc2 module
was being configured at compile time. But it wasn't checked against
the hardware capabilities, nor were the hardware capabilities checked
against the compilation parameters.

This commit adds those checks and adjusts dr_mode to an appropriate
value, if needed. If the hardware capabilities and module compilation
do not match then we fail as it wouldn't be possible to run properly.

The hardware, module, and dr_mode, can each be set to host, device,
or otg. Check that all these values are compatible and adjust the
value of dr_mode if possible.

The following table summarizes the behavior:

                     actual
   HW  MOD dr_mode   dr_mode
 ------------------------------
  HST  HST  any    :  HST
  HST  DEV  any    :  ---
  HST  OTG  any    :  HST

  DEV  HST  any    :  ---
  DEV  DEV  any    :  DEV
  DEV  OTG  any    :  DEV

  OTG  HST  any    :  HST
  OTG  DEV  any    :  DEV
  OTG  OTG  any    :  dr_mode

Change-Id: I46f3925adffdea510366ff5d61c1faa23d8190a3
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 5268ed9d2e3b52f703f3661eef14cecbb2b572d4)

7 years agoUPSTREAM: usb: dwc2: Add functions to check the HW OTG config
John Youn [Thu, 17 Dec 2015 19:16:17 +0000 (11:16 -0800)]
UPSTREAM: usb: dwc2: Add functions to check the HW OTG config

Added functions to query the GHWCFG2.OTG_MODE. This tells us whether the
controller hardware is configured for OTG, device-only, or host-only.

Change-Id: I8f927d130a675ceb598b118d0c9a4e5d5b698739
Signed-off-by: John Youn <johnyoun@synopsys.com>
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6bea962053e76a4407f0d138184a8737eea960ee)

7 years agoUPSTREAM: usb: dwc2: Add dwc2_core_reset()
John Youn [Thu, 17 Dec 2015 19:16:03 +0000 (11:16 -0800)]
UPSTREAM: usb: dwc2: Add dwc2_core_reset()

dwc2_core_reset() was previously renamed to
dwc2_core_reset_and_dr_force_mode(). Now add back dwc2_core_reset() which
performs only a basic core reset without forcing the mode.

Change-Id: Id29e7e5d7bb473dd9f904a1a07cc544ba418805e
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit b5d308abef1c5c0f24128845e41d414a8f8438f6)

7 years agoUPSTREAM: usb: dwc2: Rename dwc2_core_reset()
John Youn [Thu, 17 Dec 2015 19:15:49 +0000 (11:15 -0800)]
UPSTREAM: usb: dwc2: Rename dwc2_core_reset()

Renamed dwc2_core_reset() to dwc2_core_reset_and_force_dr_mode(). This
describes what it is doing more accurately. This is in preparation of
introducing a plain dwc2_core_reset() function that only performs the
reset and doesn't force the mode.

Change-Id: I1c0c17ed45cfcffe30561eaccd773d489e3c980c
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6d58f346a61ff50eda740e6216e9829e572d75c8)

7 years agoUPSTREAM: usb: dwc2: gadget: don't overwrite DCTL register on NAKEFF interrupts
Gregory Herrero [Mon, 7 Dec 2015 11:07:31 +0000 (12:07 +0100)]
UPSTREAM: usb: dwc2: gadget: don't overwrite DCTL register on NAKEFF interrupts

When receiving GINTSTS_GINNAKEFF or GINTSTS_GOUTNAKEFF interrupt,
DCTL will be overwritten with DCTL_CGOUTNAK or DCTL_CGNPINNAK values.
Instead of overwriting it, write only needed bits.

It could cause an issue if GINTSTS_GINNAKEFF or GINTSTS_GOUTNAKEFF
interrupt is received after dwc2 disabled pullup by writing
DCTL_SFTDISCON bit.
Pullup will then be re-enabled whereas it should not.

Change-Id: Idd93b20c3d780fffdf03cc30481eb4aed9aafe1e
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3be99cd0e882dd2127b8cfe3942f5e464915aeba)

7 years agoUPSTREAM: usb: dwc2: fix transfer stop programming for out endpoint
Du, Changbin [Fri, 4 Dec 2015 07:38:23 +0000 (15:38 +0800)]
UPSTREAM: usb: dwc2: fix transfer stop programming for out endpoint

To stop an out endpoint, software should set sets the Global OUT NAK,
but not the Global Non-periodic IN NAK. This driver bug leads the out-ep
failed be in disabled state with below error.

dwc2_hsotg_ep_stop_xfr: timeout DOEPCTL.EPDisable

Change-Id: I5f8cc03a2a8c33311d9caf76fd028d15c66e58a8
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Du, Changbin <changbin.du@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 0676c7e734e3807f4e91f5d0edcaeed1f5ff412a)

7 years agoUPSTREAM: usb: dwc2: host: Clear interrupts before handling them
Douglas Anderson [Fri, 20 Nov 2015 17:06:28 +0000 (09:06 -0800)]
UPSTREAM: usb: dwc2: host: Clear interrupts before handling them

In general it is wise to clear interrupts before processing them.  If
you don't do that, you can get:
 1. Interrupt happens
 2. You look at system state and process interrupt
 3. A new interrupt happens
 4. You clear interrupt without processing it.

This patch was actually a first attempt to fix missing device insertions
as described in (usb: dwc2: host: Fix missing device insertions) and it
did solve some of the signal bouncing problems but not all of
them (which is why I submitted the other patch).  Specifically, this
patch itself would sometimes change:
 1. hardware sees connect
 2. hardware sees disconnect
 3. hardware sees connect
 4. dwc2_port_intr() - clears connect interrupt
 5. dwc2_handle_common_intr() - calls dwc2_hcd_disconnect()

...to:
 1. hardware sees connect
 2. hardware sees disconnect
 3. dwc2_port_intr() - clears connect interrupt
 4. hardware sees connect
 5. dwc2_handle_common_intr() - calls dwc2_hcd_disconnect()

...but with different timing then sometimes we'd still miss cable
insertions.

In any case, though this patch doesn't fix any (known) problems, it
still seems wise as a general policy to clear interrupt before handling
them.

Note that for dwc2_handle_usb_port_intr(), instead of moving the clear
of PRTINT to the beginning of the function we remove it completely.  The
only way to clear PRTINT is to clear the sources that set it in the
first place.

Change-Id: I94b427aa819f477930287c8c3e85d14e80891f86
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 29539019b46f0e5f64f80f2e9dc8f9bb34d16b4b)

7 years agoUPSTREAM: usb: dwc2: host: Add missing spinlock in dwc2_hcd_reset_func()
Douglas Anderson [Fri, 20 Nov 2015 17:06:27 +0000 (09:06 -0800)]
UPSTREAM: usb: dwc2: host: Add missing spinlock in dwc2_hcd_reset_func()

The dwc2_hcd_reset_func() function is only ever called directly by a
delayed work function.  As such no locks are already held when the
function is called.

Doing a read-modify-write of CPU registers and setting fields in the
main hsotg data structure is a bad idea without locks.  Let's add
locks.

The bug was found by code inspection only.  It turns out that the
dwc2_hcd_reset_func() is only ever called today if the
"host_support_fs_ls_low_power" parameter is enabled and no code in
mainline enables that parameter.  Thus no known issues in mainline are
fixed by this patch, but it's still probably wise to fix the function.

Change-Id: I14ff93f64f1fd405d4911d67c7d0b20e50be4f53
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 4a065c7bdbec9536f7b899241b125b9c3b5ba97a)

7 years agoUPSTREAM: usb: dwc2: host: Support immediate retries for split transactions
Douglas Anderson [Wed, 11 Nov 2015 18:33:52 +0000 (10:33 -0800)]
UPSTREAM: usb: dwc2: host: Support immediate retries for split transactions

In some cases, like when you've got a "Microsoft Wireless Keyboard 2000"
connected to dwc2 with a hub, expected that we'll get some transfer
errors sometimes.  The controller is expected to try at least 3 times
before giving up.  See figure "Figure A-67. Normal HS CSPLIT 3 Strikes
Smash" in the USB spec.

The dwc2 controller has a way to support this by using the "EC_MC"
field.  The Raspberry Pi driver has logic for setting this right.  See
fiq_fsm_queue_split_transaction() in their "dwc_otg_hcd.c".  Let's use
the same logic.

After making this change, we no longer get dropped characters from the
above mentioned keyboard.  Other devices on the same bus as the keyboard
also behave more properly.

Thanks for Julius Werner for the expert analysis and suggestions.

Change-Id: I2351f95a0c6db1ca24c54edce574c42e073b7211
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 69b76cdff592058ea445cd40e18c75dffaba4cb9)

7 years agoUPSTREAM: usb: dwc2: host: Fix missing device insertions
Douglas Anderson [Thu, 19 Nov 2015 21:23:14 +0000 (13:23 -0800)]
UPSTREAM: usb: dwc2: host: Fix missing device insertions

If you've got your interrupt signals bouncing a bit as you insert your
USB device, you might end up in a state when the device is connected but
the driver doesn't know it.

Specifically, the observed order is:
 1. hardware sees connect
 2. hardware sees disconnect
 3. hardware sees connect
 4. dwc2_port_intr() - clears connect interrupt
 5. dwc2_handle_common_intr() - calls dwc2_hcd_disconnect()

Now you'll be stuck with the cable plugged in and no further interrupts
coming in but the driver will think we're disconnected.

We'll fix this by checking for the missing connect interrupt and
re-connecting after the disconnect is posted.  We don't skip the
disconnect because if there is a transitory disconnect we really want to
de-enumerate and re-enumerate.

Notes:
1. As part of this change we add a "force" parameter to
   dwc2_hcd_disconnect() so that when we're unloading the module we
   avoid the new behavior.  The need for this was pointed out by John
   Youn.
2. The bit of code needed at the end of dwc2_hcd_disconnect() is
   exactly the same bit of code from dwc2_port_intr().  To avoid
   duplication, we refactor that code out into a new function
   dwc2_hcd_connect().

Change-Id: Ibe9c7d62b2b35f5666ffcde75a65e7fca9f6805a
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Tested-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 6a6595318ac2dd169d2931a1d9431a64f4ada75c)

7 years agoUPSTREAM: usb: dwc2: add support of hi6220
Zhangfei Gao [Wed, 18 Nov 2015 07:39:47 +0000 (15:39 +0800)]
UPSTREAM: usb: dwc2: add support of hi6220

Support hisilicon,hi6220-usb for HiKey board

Change-Id: Ib3ca531022f812851566b11fc2174be57eb1d02b
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 37dd9d65cc41fcc7e77645a1cdf2659472809b96)

7 years agoUPSTREAM: usb: dwc2: host: use kmem cache to allocate descriptors
Gregory Herrero [Fri, 20 Nov 2015 10:49:31 +0000 (11:49 +0100)]
UPSTREAM: usb: dwc2: host: use kmem cache to allocate descriptors

Kmem caches help to get correct boundary for descriptor buffers
which need to be 512 bytes aligned for dwc2 controller.
Two kmem caches are needed for generic descriptors and for
hs isochronous descriptors which doesn't have same size.

Change-Id: Ic5af8b3871a32d51942aad35e0968ddbd803a73e
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3b5fcc9ac2f4453a5609cc89ac7618b1b27ccb01)

7 years agoUPSTREAM: usb: dwc2: host: fix descriptor list address masking
Mian Yousaf Kaukab [Fri, 20 Nov 2015 10:49:30 +0000 (11:49 +0100)]
UPSTREAM: usb: dwc2: host: fix descriptor list address masking

Masks for HCDMA.CTD and HCDMA.DMAAddr are incorrect. As we always
start from first descriptor, no need to mask the address anyway.

Change-Id: Iaeb063357dc4ffa905a9e1081793648ce1153d59
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit e23b8a54a440a2b8ee5c9dc3eb2099ecf813ef70)

7 years agoUPSTREAM: usb: dwc2: host: avoid usage of dma_alloc_coherent with irqs disabled
Gregory Herrero [Fri, 20 Nov 2015 10:49:29 +0000 (11:49 +0100)]
UPSTREAM: usb: dwc2: host: avoid usage of dma_alloc_coherent with irqs disabled

Use Streaming DMA mappings to handle cache coherency of frame list and
descriptor list. Cache are always flushed before controller access it
or before cpu access it.

Change-Id: I369dfb990bcef4aa0cb16b00539011bcab9732df
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 95105a998dff0747327f11708ea24480ee0eca54)

7 years agoUPSTREAM: usb: dwc2: host: enable descriptor dma for fs devices
Mian Yousaf Kaukab [Fri, 20 Nov 2015 10:49:28 +0000 (11:49 +0100)]
UPSTREAM: usb: dwc2: host: enable descriptor dma for fs devices

As descriptor dma mode does not support split transfers, it can't be
enabled for high speed devices. Add a core parameter to enable it for
full speed devices.

Ensure frame list and descriptor list are correctly freed during
disconnect.

Change-Id: I3793f7d00d5c791469daa1e4eb39bfff7a2a5c65
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit fbb9e22b15ad3c9a98c66bad801b4d1366e8bf20)

7 years agoUPSTREAM: usb: dwc2: host: process all completed urbs
Gregory Herrero [Thu, 5 Nov 2015 08:41:45 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: process all completed urbs

Process all completed urbs, if more urbs are complete by the time
driver processes completion interrupt.

Change-Id: I04813bea1208637824e1bfb36ab43fd939763324
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 762d3a1a9cd7438a8453e005ee5b2bab3203d9c3)

7 years agoUPSTREAM: usb: dwc2: host: always increment available host channel during release
Gregory Herrero [Thu, 5 Nov 2015 08:41:44 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: always increment available host channel during release

When releasing a channel, increment hsotg->available_host_channels even
in case a periodic channel is released.

Change-Id: I436f6b2db2a823e3479e7f1cd0a8c97ee498a64b
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3f808bdae75eaf464b1b2710894950772a3784f8)

7 years agoUPSTREAM: usb: dwc2: host: program descriptor for next frame
Gregory Herrero [Thu, 5 Nov 2015 08:41:43 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: program descriptor for next frame

Isochronous descriptor is currently programmed for the frame
after the last descriptor was programmed.

If the last descriptor frame underrun, then current descriptor must
take this into account and must be programmed on the current frame + 1.
This overrun usually happens when system is loaded and dwc2 can't init
descriptor list in time.

Change-Id: Ic1a50ef6c3325cbf171cc370e43569c8a3b7bd69
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit c17b337c1ea4c681595531912585a94f4bd7f8e7)

7 years agoUPSTREAM: usb: dwc2: host: add function to compare frame index
Gregory Herrero [Thu, 5 Nov 2015 08:41:42 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: add function to compare frame index

This function allow comparing frame index used for
descriptor list which has 64 entries.

Change-Id: I72ac09aff8a8ca14d52d56c07f582df993a67c32
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit b9392d9920fdce50abbe4af758cd1a24b922c81c)

7 years agoUPSTREAM: usb: dwc2: host: spinlock release channel
Gregory Herrero [Thu, 5 Nov 2015 08:41:41 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: spinlock release channel

Prevent dwc2 driver from accessing channel while it frees it.

Change-Id: Ia3c1593d84f3bb164ca165c1f35e574fd6afbb8b
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 2b046bc5aaefd4aba7195e6a73afe14f7f786692)

7 years agoUPSTREAM: usb: dwc2: host: fix use of qtd after free in desc dma mode
Gregory Herrero [Thu, 5 Nov 2015 08:41:40 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: fix use of qtd after free in desc dma mode

When completing non isoc xfer, dwc2_complete_non_isoc_xfer_ddma()
is relying on qtd->n_desc to process the corresponding number of
descriptors.

During the processing of these descriptors, qtd could be unlinked
and freed if xfer is done and urb is no more in progress.

In this case, dwc2_complete_non_isoc_xfer_ddma() will read again
qtd->n_desc whereas qtd has been freed. This will lead to unpredictable
results since qtd->n_desc is no more valid value.

To avoid this error, return a result != 0 in dwc2_process_non_isoc_desc(),
so that dwc2_complete_non_isoc_xfer_ddma() stops desc processing.

This has been seen with Slub debug enabled.

Change-Id: I375ddf56fbf4b4e19610d24891491868872d0e84
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 26a19ea699060fded98257e65b0ae5272a5ea1da)

7 years agoUPSTREAM: usb: dwc2: host: rework isochronous halt path
Gregory Herrero [Thu, 5 Nov 2015 08:41:39 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: rework isochronous halt path

When a channel is halted because of urb dequeue during transfer
completion, no other qtds must be scheduled until halt is done.
Moreover, all in progress qtds must be given back.

Change-Id: I87d6a92372046f34fd66713db75690b4a096fc66
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit c503b38153852d88774b54ae17f7723f68c6dc33)

7 years agoUPSTREAM: usb: dwc2: host: set active bit in isochronous descriptors
Gregory Herrero [Thu, 5 Nov 2015 08:41:38 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: set active bit in isochronous descriptors

Active bit must be enabled in all scheduled descriptors. Else transfer
never start.
Remove previous code which was not correctly configuring descriptors.
Active bit was set before calling dwc2_fill_host_isoc_dma_desc() which
is erasing dma_desc->status.

Change-Id: Ifee640205fc2af53c2f7859153209cb5de289988
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit dde4c1bf5df0f852e497e5644d3578885b969fdb)

7 years agoUPSTREAM: usb: dwc2: host: ensure filling of isoc desc is correctly done
Gregory Herrero [Thu, 5 Nov 2015 08:41:37 +0000 (09:41 +0100)]
UPSTREAM: usb: dwc2: host: ensure filling of isoc desc is correctly done

Increment qtd->isoc_frame_index_last before testing it, else below
check will never be true and IOC (Interrupt On Complete) bit for
last frame will never be set in descriptor status.

  /* Set IOC for each descriptor corresponding to last frame of URB */
  if (qtd->isoc_frame_index_last == qtd->urb->packet_count)
dma_desc->status |= HOST_DMA_IOC;

Change-Id: Ie4d30f20a3990d16cb27d0e137bb693fd7426376
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Gregory Herrero <gregory.herrero@intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 3ac38d260fa5dc8ec26ee5b6f5330d726ec00065)

7 years agoRevert "UPSTREAM: usb: dwc2: host: Always add to the tail of queuesa"
Jacob Chen [Thu, 3 Nov 2016 07:50:13 +0000 (15:50 +0800)]
Revert "UPSTREAM: usb: dwc2: host: Always add to the tail of queuesa"

This reverts commit abda71220e727633ad5dd404e0e09f04f0eb2d1b.

Change-Id: I71b3064a6a9439ab7b3893dcd20b8df4c4fad742
Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
7 years agoarm64: rockchip_defconfig: add NVMe support
Shawn Lin [Tue, 3 Jan 2017 09:11:26 +0000 (17:11 +0800)]
arm64: rockchip_defconfig: add NVMe support

Change-Id: Ib943c7ee92fb18444fd8c69440a0ae4cf29f00f0
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
7 years agopower_supply: bq25700: add dual type-c charge
Shunqing Chen [Thu, 15 Dec 2016 12:27:16 +0000 (20:27 +0800)]
power_supply: bq25700: add dual type-c charge

Change-Id: I97e4962229ed337752134aaf31b3f3e75b113440
Signed-off-by: Shunqing Chen <csq@rock-chips.com>
7 years agoFROMLIST: PCI: rockchip: Add system PM support
Shawn Lin [Tue, 3 Jan 2017 07:35:28 +0000 (15:35 +0800)]
FROMLIST: PCI: rockchip: Add system PM support

This patch adds system PM support for Rockchip's RC.
For pre S3, the EP is configured into D3 state which guarantees
the link state should be in L1. So we could send PME_Turn_Off message
to the EP and wait for its ACK to make the link state into L2 or L3
without the aux-supply. This could help save more power which I think
should be very important for mobile devices.

As note that there is a 5s timeout for RC to wait for the PMA_ACK
aftering send PME_Turn_Off. Technically it should depends on the
hierarchy of devices but seems PCIe core framework doesn't handle the
L2/3 for S3 at all. So that means we should presume to set a default
value for PME_ACK. From the bug report[1], we could find a statement that
Microsoft Windows versions typically wait for 5 seconds. So we are prone
to take 5s for this timeout here.

Change-Id: I3500911daaad07dfd632cda0f2f4b62cfc2909a2
[1] https://lists.launchpad.net/kernel-packages/msg123315.html
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
(cherry picked from https://patchwork.kernel.org/patch/9470515/)

7 years agodt-bindings: iommu: Add clock and pd for rockchip iommu
Simon [Mon, 19 Dec 2016 12:24:02 +0000 (20:24 +0800)]
dt-bindings: iommu: Add clock and pd for rockchip iommu

Change-Id: I7762dc71253aed0f5e06c0bf66e0bd668b3b4821
Signed-off-by: Simon <xxm@rock-chips.com>
7 years agoiommu/rockchip: Add pd/clk operation in iommu
Simon [Fri, 16 Dec 2016 03:48:06 +0000 (11:48 +0800)]
iommu/rockchip: Add pd/clk operation in iommu

Rk iommus share pd and clk with their masters, to make iommus independent,
iommus need to manage pd and clk by using pm_runtime_get_sync API who is
not atomic save, might lead to sleep, we change the spin lock to mutex to
satisfy the pm_runtime_get_sync, callers of rk_iommu_attach_device
and rk_iommu_map should guarantee not in a atomic path.

Change-Id: Icbe175030d36572e19740d23eae94f49fe59eb10
Signed-off-by: Simon <xxm@rock-chips.com>
7 years agousb: xhci-plat: check hcc_params after add hcd
William Wu [Fri, 30 Dec 2016 11:45:49 +0000 (19:45 +0800)]
usb: xhci-plat: check hcc_params after add hcd

The commit 4ac53087d6d4 ("usb: xhci: plat: Create both
HCDs before adding them") move add hcd to the end of
probe, this cause hcc_params uninitiated, because xHCI
driver sets hcc_params in xhci_gen_setup() called from
usb_add_hcd().

This patch checks the Maximum Primary Stream Array Size
in the hcc_params register after add hcd.

Change-Id: I5a05ca6a8ac25e914752914abb70612849cc175e
Signed-off-by: William Wu <wulf@rock-chips.com>
7 years agoUPSTREAM: PCI: rockchip: move the deassert of pm/aclk/pclk after phy_init
Shawn Lin [Thu, 24 Nov 2016 01:54:21 +0000 (09:54 +0800)]
UPSTREAM: PCI: rockchip: move the deassert of pm/aclk/pclk after phy_init

Move them after phy_init as we want to optimize the logic
of reset control and reuse rockchip_pcie_init_port later
which should fully follow the cold boot procedure of ROM
code.

Change-Id: I0a826a6de91a7c413e42e36ea5ceea5007ee7b73
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
(cherry picked from 0722bdd2962a4a0f6d5e8973b0d274d147adacfb)