Revert "USB: android: Avoid re-enabling the same configuration"

Commit d9b1897713 doesn't allow re-enumeration of USB default composition
on bus reset. if adb close and adb open has been called within 1 second
of duration. with adb usb command, it restarts the adb into USB mode after
closing the adb device and re-opening the same within 1 second. To the
user it looks as if command is stuck. Terminating adb usb based command
prompt, killing adb server and doing adb shell again gets the adb
functionality. Here user doesn't see any USB re-enumeration with it. Hence
revert commit d9b1897713 which doesn't block the adb usb command and
re-enumeration of USB.

(cherry picked from commit ff3e0492ee60c8594b3f48eed87e086f4b3d5b0b)

Change-Id: I50ab56f94293b2e02b66c548ee703d26284bcc57
CRs-Fixed: 385973
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
USB: android: Don't disable configuration for every adb close

Certain ADB commands like "adb usb" and "adb root" restart the
adb daemon running on the device.  These commands require USB
bus reset, otherwise adb commands on the host side would stuck
for ever.

USB bus reset can be forced from device side by re-enabling the
same composition.  Earlier, configuration is disabled when adb
daemon closes /dev/android_usb device file.  The configuration
is enabled again after adb daemon opens the device file. This
approach solves the "adb usb" problem with the below side effects.

1. When USB cable is disconnected, the Rx request is flushed and
an error code is returned to user space.  The adb daemon is simply
restarted in this case which cause an unnecessary rebinding of
all functions.
2. The above scenario can happen if host reset the bus when device
is in configured state.  If device disable pull-up during, bus
reset, USB CV CH9 test cases are failing.

The commit d9b1897 (USB: android: Avoid re-enabling the same
configuration) fixed the above side effects. But silently ignores the
original "adb usb" problem.

This commit is another attempt to solve all the above mentioned problems
by forcing re-enumeration only when device is in connected state.  That
means, "adb usb" and "adb root" commands force usb bus reset where as
plugging out a cable does not.

(cherry picked from commit 1aa235a6c0a3d67bff24609766baf5a7d5d8e3e4)

(cherry picked from commit 81fefe664ab6333f05209bed959a599a47baf71f)

Change-Id: Id3a40f62dd51aba6ec690d3326ed67ced32b946a
CRs-Fixed: 407882
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>

Signed-off-by: Neha Pandey <nehap@codeaurora.org>
USB: android: Fix adb device file closing bug

adb device file closing and config disabling can happen in
parallel during composition switch.  If adb device file
is closed prior to config disable, adb function driver request
android to disable configuration.  But this is not undone later
when adb device file is opened.  Due to this bug config remains
disabled after composition switch completion.  Fix this bug.

(cherry picked from commit c4d8e2ca7cfb2118bcc9f14a97568bfe42b76bcc)

Change-Id: Ia2b7024cfcc438f4e17ca1f165be03abcf380230
CRs-Fixed: 414360
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
msm: kgsl: Restore the value of RB_BC_CONTROL on context
 switch

On 8x25Q, when GPU footswitch is turned off during TCXO shutdown, the
RB_BC_CONTROL register value is lost which causes GPU hang after coming
out of TCXO shutdown. Now the value of RB_BC_CONTROL is preserved properly
during context save and restore.

(cherry picked from commit 6b761ba560847bd7df4c6ff9de87bd6298d4b6e2)

Change-Id: I1999f88a5416445568c4b63ca0b99233551258f4
CRs-fixed: 441134
Signed-off-by: Vinay Roy <vroy@codeaurora.org>
msm: kgsl: Calculate busy interval considering GPU freq as float

GPU freq could be non-integral value and treating it as an integer
to calculate GPU busy insterval leads to higher busy interval
and more often we see negative idle stats. This change caculates
busy interval by treating gpu freq to the correct precision.

Change-Id: Ic54130803d7a0436b4ba31b09915eb7165d16590
CRs-fixed: 454972
Signed-off-by: Vinay Roy <vroy@codeaurora.org>
msm: kgsl: Protect the mem_entry list during deletion

Use the spinlock to prevent corruption of the mem_entry list during
deletion. Otherwise the mem_entry list may be modified by another
thread at the same time resulting in memory corruption.

Change-Id: I5728a8b925753d5fda82413615e5ebaf0366dfd8
CRs-fixed: 489224
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm: kgsl: Lower bounds check the number of power levels

A misconfigured board file could cause an out-of-bounds
array access through this value.

Change-Id: I64bbad0c096a2efe65376991537d810141370d72
CRs-Fixed: 439230
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
msm: kgsl: Add context reference counting to KGSL events

Add reference counting to all KGSL events since they are dependent
on the context.  This avoids a race condition where the context
could be destroyed while the events are being processed during cleanup.

Change-Id: Ifcd9655a6335d22c01f2606a0fbc5346d9a0314f
CRs-fixed: 438134
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Don't silently ignore events that have a retired
 timestamp

After all the current events are processed in the main loop, the next
pending event is marked to fire an interrupt to start the cycle anew.
When the event is marked, we check the timestamp again to make sure that
we are always caught up with the GPU.  If the timestamp for the next
event happens to be retired when we get to this point, we silently leave
the function.

If there are no other subsequent events or waittimestamp requests, then
it is possible that another interrupt might never be fired for that context
and then the event gets missed.  Return a 1 in this case all the way back
up the stack and make the event code keep processing events until we are
positive that none are past.

Change-Id: I5a770e7f06612e1aecbfe2e8ccbfeebdab3fc9fc
CRs-Fixed: 441191
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Delete the context event while the context is
 still valid

Make sure that the context is freed only after the event is deleted
from the list to avoid accessing invalid list pointers. This makes
sure that the context memory is not accessed after being freed.

Change-Id: I9196219f1472396c0063dbeaa5351f66e6e5648f
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
Signed-off-by: Uma Maheshwari Bhiram <ubhira@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_events.c
msm: kgsl: Add NULL check for next_event hook

KGSL driver needs to check that the function pointer
is not NULL before calling the hook. next_event
is an optional function not implemented by the 2d
core. This fix ensures that optional and unimplemented
function will not invoked by the driver.

Change-Id: I687b028260e3ec304d973c6a5bded0a8fdbfb73b
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
msm: kgsl: Remove extra call to sync_fence_put()

sync_fence_put is called twice and cause NULL pointer dereference.

Change-Id: Ia29e676af28d9040d1ba1ee8669f1306cc8b4035
Signed-off-by: Alex Wong <waiw@codeaurora.org>
msm: kgsl: generate descriptive names for kgsl-timeline

Generate names for kgsl-timelines using the following format:
<device>-<thread name>(<tid>)-<proc name>(<pid>)-<context id>

This makes it possible to identify the context of a timeline in the
sync dump, which makes it much easier to identify which context has
a GPU timeout.

Change-Id: I0ce0614a53a93fd81094d92c9bef7053e6d416d2
Git-commit: e3348f389f715cb2143a708ec6796d3f65e03821
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: show timestamp in sync dump

Improve the debug information printed for kgsl points and timelines.

kgsl_sync_pt_value_str:
  - show timestamp passed to kgsl_add_fence_event()
kgsl_sync_timeline_value_str:
  - show most recent timestamp passed to kgsl_sync_timeline_signal()
  - show last retired timestamp according to kgsl_sync_get_timestamp()

Change-Id: I93fe408b06de054b11e05784cd7175ed3fcb76ad
Git-commit: 595e213985f63d6aa484c966a4f4a710b31ca209
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm_fb: Increase base fence timeout

The earlier value of 1 second caused unnecessary warnings on
heavy workloads by the GPU.

Change-Id: Ib4a5b098267251d5c63c4d8d2a2f51b339acc1d2
Signed-off-by: Naseer Ahmed <naseer@codeaurora.org>
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm_fb: display: wake up system around vsync

To avoid frame drops due to power collapse,
wake up cpu right before vsync.

Change-Id: I63385eb329ae5e74cbac5256823fd3a213e0a0e1
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
msm: display: panel frame rate report

Add metadata ioctl for retrieving panel frame rate.
Get ready to remove reserved fields usage.

Change-Id: I51a4aed9d85efd5f83a184100b6a3dc682c7a67c
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
msm_fb: display: fix frame rate wrong calculation

For cmd mode the frame rate calculation result is wrong. Also in mdp
driver there are several places to do the same calculation. So fix the
wrong calculation and use a single func to do calculation.

Change-Id: I3a4be39e480ce82677dcefb666202947f7f6d3c1
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
(cherry picked from commit d4eb5a1a3ef0935ce6aeffb2b48974c01b9518b9)
Signed-off-by: Neha Pandey <nehap@codeaurora.org>

Conflicts:
	drivers/video/msm/msm_fb.c
msm_fb: display: get mipi frame rate from panel file

If frame rate value for mipi video panel is coded in panel file it can
be directly used to avoid calculation error.

Change-Id: I6ad86226c81da4bcf36196385f9ff4bea0bef0ca
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
msm_fb: Fix chroma offset calculation for YUV as source format

For frame composition using MDP, fix the calculation of source
chroma offset pointer to be programmed to MDP hardware whenever
the crop 'y' value is non-zero. This prevents green lines/chroma
shift and other artifacts from being seen on the panel.

CRs-fixed: 438027
Change-Id: Id6c2a7d2c2709edd0bacfc049df360e1c0f3b90f
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>