firefly-linux-kernel-4.4.55.git
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)

7 years agoUPSTREAM: PCI: rockchip: split out rockchip_cfg_atu
Shawn Lin [Thu, 24 Nov 2016 01:54:20 +0000 (09:54 +0800)]
UPSTREAM: PCI: rockchip: split out rockchip_cfg_atu

We split out a new function, rockchip_cfg_atu, in order to
re-configure the atu when missing these information after
wakeup from S3.

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

7 years agoarm64: dts: rockchip: add PCIe stuff for rk3399-tve1205g
Shawn Lin [Tue, 27 Dec 2016 07:20:23 +0000 (15:20 +0800)]
arm64: dts: rockchip: add PCIe stuff for rk3399-tve1205g

Add PCIe dt-bindings for rk3399-tve1205g and keep them as
disabled status currently.

Change-Id: Ie92c6e330a6588ff88d69306674429d69b971b58
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
7 years agovideo/rockchip: rga2 can be used dma coherent
Zikim,Wei [Fri, 23 Dec 2016 12:20:51 +0000 (20:20 +0800)]
video/rockchip: rga2 can be used dma coherent

Change-Id: I123bec313212ae2a9682e1d6f219a2f705c25187
Signed-off-by: Zikim,Wei <wzq@rock-chips.com>
7 years agodrm/rockchip: add mm dump debugfs
Mark Yao [Tue, 3 Jan 2017 03:50:55 +0000 (11:50 +0800)]
drm/rockchip: add mm dump debugfs

shell# cat /sys/kernel/debug/dri/0/mm_dump

0x0000000000000000-0x00000000000a6000: 679936: free
0x00000000000a6000-0x0000000000970000: 9216000: used
0x0000000000970000-0x000000000123a000: 9216000: used
0x000000000123a000-0x0000000001b04000: 9216000: used
0x0000000001b04000-0x00000000023ce000: 9216000: used
0x00000000023ce000-0x0000000002c98000: 9216000: used
0x0000000002c98000-0x0000000003562000: 9216000: used
0x0000000003562000-0x0000000003e2c000: 9216000: used
0x0000000003e2c000-0x0000000100000000: 4229775360: free
total: 4294967296, used 64512000 free 4230455296

Change-Id: I39cb5b12a63418c050b3bd890829f831f898db4e
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agodrm/rockchip: add drm summary debugfs node
Mark Yao [Fri, 30 Dec 2016 09:03:51 +0000 (17:03 +0800)]
drm/rockchip: add drm summary debugfs node

With the summary debug node, show current display status would be easier.

Using step:
shell# cat /sys/kernel/debug/dri/0/summary

vop name: ff900000.vop status=active
Display mode: 1200x1920 fps[60] clk[160000] type[8] flag[a]
        H: 1200 1320 1340 1361
        V: 1920 1941 1944 1962
win0-0: status=active
        format: AB24 little-endian (0x34324241)
        zpos: 0
        src: pos[0x0] rect[1200x1920]
        dst: pos[0x0] rect[1200x1920]
        buf[0]: addr: 0x9e19000 pitch: 4800 offset: 0
win1-0: status=disabled
win2-0: status=disabled
win2-0: status=disabled
win2-1: status=disabled
win2-2: status=disabled
win3-0: status=disabled
win3-0: status=disabled
win3-1: status=disabled
win3-2: status=disabled
vop name: ff8f0000.vop status=disabled

Change-Id: I386398b0617f0c18902c4cadad5906be343cc4de
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agovideo: rockchip: dp: modify the function names for fb-based dp driver.
wenping.zhang [Tue, 3 Jan 2017 05:48:48 +0000 (13:48 +0800)]
video: rockchip: dp: modify the function names for fb-based dp driver.

change the name of functions for fb-based dp driver in order to fix
the compile errors of drm-based dp driver.

Change-Id: I6544c82d81bf4d8e5a7b936c7959349765d55049
Signed-off-by: wenping.zhang <wenping.zhang@rock-chips.com>
7 years agoARM64: dts: rk3399: sapphire-excavator enabled pcie audio ir
wuliangqing [Fri, 16 Dec 2016 03:12:41 +0000 (11:12 +0800)]
ARM64: dts: rk3399: sapphire-excavator enabled pcie audio ir

Change-Id: Idba0460db911d45a2b546bfa6aabf2a4f8ca7dcd
Signed-off-by: Wu Liangqing <wlq@rock-chips.com>
7 years agoUPSTREAM: drm/mm: avoid possible null pointer dereference
Heinrich Schuchardt [Wed, 18 May 2016 20:17:19 +0000 (22:17 +0200)]
UPSTREAM: drm/mm: avoid possible null pointer dereference

Do not dereference node before the check if node is NULL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1463602639-4861-1-git-send-email-xypron.glpk@gmx.de
(cherry picked from commit b80d3942329dcd43580adc3f7c0a098515b5feec)

Change-Id: I672ce10214e1268a043e6a11268ff400024cc883
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm/rockchip: Finish initialization before registering DRM device
Tomasz Figa [Tue, 21 Jun 2016 04:27:34 +0000 (13:27 +0900)]
UPSTREAM: drm/rockchip: Finish initialization before registering DRM device

Currently the driver calls drm_dev_register() directly after allocating
the DRM device and then continues with further initialization. This is
incorrect, because drm_dev_register() is supposed to be called after all
initialization is done. This problem was masked by the fact that
drm_dev_register() did not use to do anything special before, but
recently it started to call drm_connector_register_all(), which leads to
a crash if the driver is not fully initialized.

This patch fixes the problem by moving the call to drm_dev_register() to
the end of the initialization sequence and also removing the, now
unnecessary, call to drm_connector_register_all() from driver code.

Fixes: f706974a69b6 ("drm/rockchip: Drop drm_driver.load/unload callbacks")
Signed-off-by: Tomasz Figa <tfiga@chromium.org>
[danvet: Fix up cleanup labels a bit.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1466483254-35373-1-git-send-email-tfiga@chromium.org
(cherry picked from commit 9127f99c4801f323ffbb3b755259f3a679f66c7c)

Change-Id: Ie6d56242507c413db5e1b93e587d89a3a2200db6
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm/rockchip: Drop drm_driver.load/unload callbacks
Tomeu Vizoso [Fri, 10 Jun 2016 11:14:13 +0000 (13:14 +0200)]
UPSTREAM: drm/rockchip: Drop drm_driver.load/unload callbacks

They are deprecated and by moving their implementations to bind/unbind
we can call drm_connector_register_all instead of open-coding it.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1465557253-10670-1-git-send-email-tomeu.vizoso@collabora.com
(cherry picked from commit f706974a69b6e2be8f69fb4dc89158a6297338f9)

Change-Id: I9e97e25f1bf84609ba1dd7040478dee0686e665b
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Paper over locking inversion after registration rework
Daniel Vetter [Thu, 4 Aug 2016 16:35:48 +0000 (18:35 +0200)]
UPSTREAM: drm: Paper over locking inversion after registration rework

drm_connector_register_all requires a few too many locks because our
connector_list locking is busted. Add another FIXME+hack to work
around this. This should address the below lockdep splat:

======================================================
[ INFO: possible circular locking dependency detected ]
4.7.0-rc5+ #524 Tainted: G           O
-------------------------------------------------------
kworker/u8:0/6 is trying to acquire lock:
 (&dev->mode_config.mutex){+.+.+.}, at: [<ffffffff815afde0>] drm_modeset_lock_all+0x40/0x120

but task is already holding lock:
 ((fb_notifier_list).rwsem){++++.+}, at: [<ffffffff810ac195>] __blocking_notifier_call_chain+0x35/0x70

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 ((fb_notifier_list).rwsem){++++.+}:
       [<ffffffff810df611>] lock_acquire+0xb1/0x200
       [<ffffffff819a55b4>] down_write+0x44/0x80
       [<ffffffff810abf91>] blocking_notifier_chain_register+0x21/0xb0
       [<ffffffff814c7448>] fb_register_client+0x18/0x20
       [<ffffffff814c6c86>] backlight_device_register+0x136/0x260
       [<ffffffffa0127eb2>] intel_backlight_device_register+0xa2/0x160 [i915]
       [<ffffffffa00f46be>] intel_connector_register+0xe/0x10 [i915]
       [<ffffffffa0112bfb>] intel_dp_connector_register+0x1b/0x80 [i915]
       [<ffffffff8159dfea>] drm_connector_register+0x4a/0x80
       [<ffffffff8159fe44>] drm_connector_register_all+0x64/0xf0
       [<ffffffff815a2a64>] drm_modeset_register_all+0x174/0x1c0
       [<ffffffff81599b72>] drm_dev_register+0xc2/0xd0
       [<ffffffffa00621d7>] i915_driver_load+0x1547/0x2200 [i915]
       [<ffffffffa006d80f>] i915_pci_probe+0x4f/0x70 [i915]
       [<ffffffff814a2135>] local_pci_probe+0x45/0xa0
       [<ffffffff814a349b>] pci_device_probe+0xdb/0x130
       [<ffffffff815c07e3>] driver_probe_device+0x223/0x440
       [<ffffffff815c0ad5>] __driver_attach+0xd5/0x100
       [<ffffffff815be386>] bus_for_each_dev+0x66/0xa0
       [<ffffffff815c002e>] driver_attach+0x1e/0x20
       [<ffffffff815bf9be>] bus_add_driver+0x1ee/0x280
       [<ffffffff815c1810>] driver_register+0x60/0xe0
       [<ffffffff814a1a10>] __pci_register_driver+0x60/0x70
       [<ffffffffa01a905b>] i915_init+0x5b/0x62 [i915]
       [<ffffffff8100042d>] do_one_initcall+0x3d/0x150
       [<ffffffff811a935b>] do_init_module+0x5f/0x1d9
       [<ffffffff81124416>] load_module+0x20e6/0x27e0
       [<ffffffff81124d63>] SYSC_finit_module+0xc3/0xf0
       [<ffffffff81124dae>] SyS_finit_module+0xe/0x10
       [<ffffffff819a83a9>] entry_SYSCALL_64_fastpath+0x1c/0xac

-> #0 (&dev->mode_config.mutex){+.+.+.}:
       [<ffffffff810df0ac>] __lock_acquire+0x10fc/0x1260
       [<ffffffff810df611>] lock_acquire+0xb1/0x200
       [<ffffffff819a3097>] mutex_lock_nested+0x67/0x3c0
       [<ffffffff815afde0>] drm_modeset_lock_all+0x40/0x120
       [<ffffffff8158f79b>] drm_fb_helper_restore_fbdev_mode_unlocked+0x2b/0x80
       [<ffffffff8158f81d>] drm_fb_helper_set_par+0x2d/0x50
       [<ffffffffa0105f7a>] intel_fbdev_set_par+0x1a/0x60 [i915]
       [<ffffffff814c13c6>] fbcon_init+0x586/0x610
       [<ffffffff8154d16a>] visual_init+0xca/0x130
       [<ffffffff8154e611>] do_bind_con_driver+0x1c1/0x3a0
       [<ffffffff8154eaf6>] do_take_over_console+0x116/0x180
       [<ffffffff814bd3a7>] do_fbcon_takeover+0x57/0xb0
       [<ffffffff814c1e48>] fbcon_event_notify+0x658/0x750
       [<ffffffff810abcae>] notifier_call_chain+0x3e/0xb0
       [<ffffffff810ac1ad>] __blocking_notifier_call_chain+0x4d/0x70
       [<ffffffff810ac1e6>] blocking_notifier_call_chain+0x16/0x20
       [<ffffffff814c748b>] fb_notifier_call_chain+0x1b/0x20
       [<ffffffff814c86b1>] register_framebuffer+0x251/0x330
       [<ffffffff8158fa9f>] drm_fb_helper_initial_config+0x25f/0x3f0
       [<ffffffffa0106b48>] intel_fbdev_initial_config+0x18/0x30 [i915]
       [<ffffffff810adfd8>] async_run_entry_fn+0x48/0x150
       [<ffffffff810a3947>] process_one_work+0x1e7/0x750
       [<ffffffff810a3efb>] worker_thread+0x4b/0x4f0
       [<ffffffff810aad4f>] kthread+0xef/0x110
       [<ffffffff819a85ef>] ret_from_fork+0x1f/0x40

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock((fb_notifier_list).rwsem);
                               lock(&dev->mode_config.mutex);
                               lock((fb_notifier_list).rwsem);
  lock(&dev->mode_config.mutex);

 *** DEADLOCK ***

6 locks held by kworker/u8:0/6:
 #0:  ("events_unbound"){.+.+.+}, at: [<ffffffff810a38c9>] process_one_work+0x169/0x750
 #1:  ((&entry->work)){+.+.+.}, at: [<ffffffff810a38c9>] process_one_work+0x169/0x750
 #2:  (registration_lock){+.+.+.}, at: [<ffffffff814c8487>] register_framebuffer+0x27/0x330
 #3:  (console_lock){+.+.+.}, at: [<ffffffff814c86ce>] register_framebuffer+0x26e/0x330
 #4:  (&fb_info->lock){+.+.+.}, at: [<ffffffff814c78dd>] lock_fb_info+0x1d/0x40
 #5:  ((fb_notifier_list).rwsem){++++.+}, at: [<ffffffff810ac195>] __blocking_notifier_call_chain+0x35/0x70

stack backtrace:
CPU: 2 PID: 6 Comm: kworker/u8:0 Tainted: G           O    4.7.0-rc5+ #524
Hardware name: Intel Corp. Broxton P/NOTEBOOK, BIOS APLKRVPA.X64.0138.B33.1606250842 06/25/2016
Workqueue: events_unbound async_run_entry_fn
 0000000000000000 ffff8800758577f0 ffffffff814507a5 ffffffff828b9900
 ffffffff828b9900 ffff880075857830 ffffffff810dc6fa ffff880075857880
 ffff88007584d688 0000000000000005 0000000000000006 ffff88007584d6b0
Call Trace:
 [<ffffffff814507a5>] dump_stack+0x67/0x92
 [<ffffffff810dc6fa>] print_circular_bug+0x1aa/0x200
 [<ffffffff810df0ac>] __lock_acquire+0x10fc/0x1260
 [<ffffffff810df611>] lock_acquire+0xb1/0x200
 [<ffffffff815afde0>] ? drm_modeset_lock_all+0x40/0x120
 [<ffffffff815afde0>] ? drm_modeset_lock_all+0x40/0x120
 [<ffffffff819a3097>] mutex_lock_nested+0x67/0x3c0
 [<ffffffff815afde0>] ? drm_modeset_lock_all+0x40/0x120
 [<ffffffff810fa85f>] ? rcu_read_lock_sched_held+0x7f/0x90
 [<ffffffff81208218>] ? kmem_cache_alloc_trace+0x248/0x2b0
 [<ffffffff815afdc5>] ? drm_modeset_lock_all+0x25/0x120
 [<ffffffff815afde0>] drm_modeset_lock_all+0x40/0x120
 [<ffffffff8158f79b>] drm_fb_helper_restore_fbdev_mode_unlocked+0x2b/0x80
 [<ffffffff8158f81d>] drm_fb_helper_set_par+0x2d/0x50
 [<ffffffffa0105f7a>] intel_fbdev_set_par+0x1a/0x60 [i915]
 [<ffffffff814c13c6>] fbcon_init+0x586/0x610
 [<ffffffff8154d16a>] visual_init+0xca/0x130
 [<ffffffff8154e611>] do_bind_con_driver+0x1c1/0x3a0
 [<ffffffff8154eaf6>] do_take_over_console+0x116/0x180
 [<ffffffff814bd3a7>] do_fbcon_takeover+0x57/0xb0
 [<ffffffff814c1e48>] fbcon_event_notify+0x658/0x750
 [<ffffffff810abcae>] notifier_call_chain+0x3e/0xb0
 [<ffffffff810ac1ad>] __blocking_notifier_call_chain+0x4d/0x70
 [<ffffffff810ac1e6>] blocking_notifier_call_chain+0x16/0x20
 [<ffffffff814c748b>] fb_notifier_call_chain+0x1b/0x20
 [<ffffffff814c86b1>] register_framebuffer+0x251/0x330
 [<ffffffff815b7e8d>] ? vga_switcheroo_client_fb_set+0x5d/0x70
 [<ffffffff8158fa9f>] drm_fb_helper_initial_config+0x25f/0x3f0
 [<ffffffffa0106b48>] intel_fbdev_initial_config+0x18/0x30 [i915]
 [<ffffffff810adfd8>] async_run_entry_fn+0x48/0x150
 [<ffffffff810a3947>] process_one_work+0x1e7/0x750
 [<ffffffff810a38c9>] ? process_one_work+0x169/0x750
 [<ffffffff810a3efb>] worker_thread+0x4b/0x4f0
 [<ffffffff810a3eb0>] ? process_one_work+0x750/0x750
 [<ffffffff810aad4f>] kthread+0xef/0x110
 [<ffffffff819a85ef>] ret_from_fork+0x1f/0x40
 [<ffffffff810aac60>] ? kthread_stop+0x2e0/0x2e0

v2: Rebase onto the right branch (hand-editing patches ftw) and add more
reporters.

Reported-by: Imre Deak <imre.deak@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
Reported-by: Jiri Kosina <jikos@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
(cherry picked from commit 5c6c201ccbaf9d3901f829441d457293f7ca8ef4)

Change-Id: I24bc8426dafa81dc1f1de31aea527d75060ed68f
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Add callbacks for late registering
Benjamin Gaignard [Tue, 21 Jun 2016 14:37:09 +0000 (16:37 +0200)]
UPSTREAM: drm: Add callbacks for late registering

Like what has been done for connectors add callbacks on encoder,
crtc and plane to let driver do actions after drm device registration.

Correspondingly, add callbacks called before unregister drm device.

version 2:
add drm_modeset_register_all() and drm_modeset_unregister_all()
to centralize all calls

version 3:
in error case unwind registers in drm_modeset_register_all
fix uninitialed return value
inverse order of unregistration in drm_modeset_unregister_all

version 4:
move function definitions in drm_crtc_internal.h
remove not needed documentation

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1466519829-4000-1-git-send-email-benjamin.gaignard@linaro.org
(cherry picked from commit 79190ea2658a93818791335aa99969ca779161c6)

Change-Id: I836e8ea62b46c0eae89cf8c70bcf3ea4e10068f5
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Protect drm_connector_register_all() under DRIVER_MODESET
Chris Wilson [Sat, 18 Jun 2016 13:46:41 +0000 (14:46 +0100)]
UPSTREAM: drm: Protect drm_connector_register_all() under DRIVER_MODESET

0-day kbuilder found

[    1.360244] BUG: unable to handle kernel NULL pointer dereference at   (null)
[    1.360972] IP: [<c14db9ad>] mutex_lock_nested+0x11f/0x2c3
[    1.361512] *pde = 00000000
[    1.361827] Oops: 0002 [#1]
[    1.362123] Modules linked in:
[    1.362451] CPU: 0 PID: 1 Comm: swapper Not tainted 4.7.0-rc2-00564-ge28cd4d #1
[    1.363202] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Debian-1.8.2-1 04/01/2014
[    1.364105] task: c03d0000 ti: d28da000 task.ti: d28da000
[    1.364636] EIP: 0060:[<c14db9ad>] EFLAGS: 00210096 CPU: 0
[    1.365215] EIP is at mutex_lock_nested+0x11f/0x2c3
[    1.365703] EAX: 00000000 EBX: d39e8ae8 ECX: d39e8b14 EDX: c1361cf9
[    1.366351] ESI: c03d0000 EDI: d28dbed0 EBP: d28dbeec ESP: d28dbec0
[    1.367010]  DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068
[    1.367534] CR0: 80050033 CR2: 00000000 CR3: 019a9000 CR4: 00000690
[    1.368152] Stack:
[    1.368356]  d39e8b14 d39e8b24 c1361cf9 00200246 d39e8b14 00000000 11111111 d28dbed0
[    1.369235]  d39e8800 d39e8ae8 00000000 d28dbf08 c1361cf9 d28dbf0c c10b25be d39e8800
[    1.370087]  00000000 00000000 d28dbf1c c135e37d fffffff4 ffffffff 00000000 d28dbf28
[    1.371012] Call Trace:
[    1.371272]  [<c1361cf9>] ? drm_connector_register_all+0x1a/0x92
[    1.371847]  [<c1361cf9>] drm_connector_register_all+0x1a/0x92
[    1.372421]  [<c10b25be>] ? kstrdup+0x25/0x3a
[    1.372863]  [<c135e37d>] drm_dev_register+0x59/0x99
[    1.373358]  [<c195ea3e>] vgem_init+0x34/0x49
[    1.373770]  [<c195ea0a>] ? mipi_dsi_bus_init+0xf/0xf
[    1.374257]  [<c100048f>] do_one_initcall+0x7c/0xfd
[    1.374754]  [<c104b409>] ? parse_args+0x1fd/0x314
[    1.375259]  [<c1939c10>] ? kernel_init_freeable+0xd0/0x179
[    1.375837]  [<c1939c2c>] kernel_init_freeable+0xec/0x179
[    1.376371]  [<c14d66ea>] kernel_init+0x8/0xcb
[    1.376806]  [<c14debce>] ret_from_kernel_thread+0xe/0x30
[    1.377322]  [<c14d66e2>] ? rest_init+0x10e/0x10e
[    1.377754] Code: 89 fa e8 71 c5 b7 ff 8b 4e 04 89 fa 89 d8 e8 8e c6 b7 ff 8d 43 2c 89 45 d4 8b 43 30 8d 4b 2c 89 45 e8 89 7b 30 89 4d e4 8b 55 dc <89> 38 8d 43 3c 89 75 ec e8 c9 dd b7 ff eb 0c 31 c0 87 03 48
+75
[    1.380442] EIP: [<c14db9ad>] mutex_lock_nested+0x11f/0x2c3 SS:ESP 0068:d28dbec0
[    1.381174] CR2: 0000000000000000

when loading the non-modesetting vGEM module. To prevent use of the
uninitialised dev->mode_config from drm_dev_register() we move the
drm_connector_register_all() under a DRIVER_MODESET guard. Longer term,
we probably want to initialise the embedded dev->mode_config automatically
from drm_dev_init() for all DRIVER_MODESET drivers.

v2: Also protect drm_dev_unregister.

Fixes: e28cd4d0a223 ("drm: Automatically register/unregister all connectors")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Testcase: igt/vgem_reload_basic
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1466257601-5656-1-git-send-email-chris@chris-wilson.co.uk
(cherry picked from commit bee7fb158f40c4ab27af352d5e9826ef2b9f4432)

Change-Id: I5387cd16d163573dcb14028be5234da12fb0cdab
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Automatically register/unregister all connectors
Chris Wilson [Fri, 17 Jun 2016 08:25:17 +0000 (09:25 +0100)]
UPSTREAM: drm: Automatically register/unregister all connectors

As the drm_connector is now safe for multiple calls to
register/unregister, automatically perform a registration on all known
connectors drm drv_register (and unregister from drm_drv_unregister).
Drivers can still call drm_connector_register() and
drm_connector_unregister() individually, or defer as required.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1466151923-1572-2-git-send-email-chris@chris-wilson.co.uk
(cherry picked from commit e28cd4d0a223e1bcea616326e2281900e7e7e9a2)

Change-Id: I30a4e2e65a88e824597774f8c59671fcf4cd0384
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Introduce drm_connector_register_all() helper
Alexey Brodkin [Tue, 19 Apr 2016 12:24:51 +0000 (15:24 +0300)]
UPSTREAM: drm: Introduce drm_connector_register_all() helper

As a pair to already existing drm_connector_unregister_all() we're adding
generic implementation of what is already done in some drivers.

Once this helper is implemented we'll be ready to switch existing
driver-specific implementations with the generic one.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1461068693-11260-2-git-send-email-abrodkin@synopsys.com
(cherry-pick from commit 54d2c2da0946368b96b63e6daed7920f3681243e)

Change-Id: Ibfeeebe5d02b77b9a670f7c303417a8d20677376
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
7 years agoUPSTREAM: drm: Rename drm_connector_unplug_all() to drm_connector_unregister_all()
Alexey Brodkin [Wed, 23 Mar 2016 08:42:54 +0000 (11:42 +0300)]
UPSTREAM: drm: Rename drm_connector_unplug_all() to drm_connector_unregister_all()

Current name is a bit misleading because what that helper function
really does it calls drm_connector_unregister() for all connectors.

This all has nothing to do with hotplugging so let's name things
properly.

And while at it remove potentially dangerous locking around
drm_connector_unregister() in rcar_du_remove() as mentioned
in kerneldoc for drm_connector_unregister_all().

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: linux-renesas-soc@vger.kernel.org
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1458722577-20283-2-git-send-email-abrodkin@synopsys.com
(cherry-pick from commit 6c87e5c3ec6db052f3744804a517b6fb003906e1)

Change-Id: I42a56d8d2b8bef8f062ca9ecc478d0348e738ea7
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>