msm_fb : Avoid trying to acquire an already acquired mutex

MDP driver for LCDC is trying to acquire the same mutex after
acquiring it already. This is causing boot up issues on devices
using LCDC interface. This change avoids the problem.

Signed-off-by: Pradeep Jilagam <pjilagam@codeaurora.org>
(cherry picked from commit 06abe49ea4b91ea64c8f1e738756e43e0e6a8662)

Change-Id: I0ce0e6d9414d3eb5e3e5c0e4883a39da655922d3
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm_fb: display: add wait for overlay0 done

Dcs command mode BLT involves both overlay0 done interrupt
and dmap done interrupt. A transaction is start at kickoff and
end with done interrupt.  At some cornor cases both overlay0 and
dmap transaction need to be completed before kickoff new transaction.

Change-Id: I5a3cc6e8255acf2c61fc627d35f990182d226f63
Signed-off-by: Kuogee Hsieh <khsieh@codeaurora.org>
(cherry picked from commit 521230e19ad81077bf0ad51ee2989e058e129837)
video: msm_fb: Increase display timeout to 2 seconds

One second time out for no frame update, as in current implementation,
does not allow CABL to reach minimum backlight level possible because
histograms dont get generated after one second. So increase time out
period to two seconds which seem to be sufficient for complete black to
complete white and vice versa transitions.

CRs-Fixed: 370804
Change-Id: I0712924d669abcb820654cd6ca5f7da37bed57e6
Signed-off-by: Pravin Tamkhane <pravint@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
(cherry picked from commit 1bb4edf9242b0397975636a4442318713a53b5e6)
msm_fb: Allow MDP hardware init for continuous splashscreen

MDP hw init is getting avoided for MDP3.x targets to support
continuous splashscreen. This avoids complete initialization
of MDP and hence usecases are failing. This change allows the
hw init.

Signed-off-by: Pradeep Jilagam <pjilagam@codeaurora.org>
(cherry picked from commit 5d7e5b30a98110dd138fddee58bc2a4f3ffdc715)

Change-Id: Id4b2cc22a15937a9208fe342b0cf990de72d315f
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	drivers/video/msm/mdp.c
msm_fb: hdmi: Proper switching of switch device

Switch device used to tell userspace about HDMI connection
needs to be enabled when:
1. HPD connect
2. Authentication successful

And disable when:
1. HPD disconnect
2. Authentication failed

Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
(cherry picked from commit fccacdf4e72f8b39c3087628aee41bf94652e220)

Change-Id: I3e2f5a4441d8dfaadb45f7084cd7471d49f61a12
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	drivers/video/msm/hdmi_msm.c
msm_fb: HDMI: Fix for high HDMI sleep current

In certain cases, the HPD circuitry is not switched off when the
device goes to suspend state, resulting in high sleep current on
the HDMI power rail. This patch ensures that the HPD circuitry is
always turned off during suspend operation by removing an
unnecessary condition check.

Signed-off-by: Aravind Venkateswaran <aravindh@codeaurora.org>
(cherry picked from commit 3bb47a097c62b71c7f8f2be888a1f73c6cfb8142)

Change-Id: I1f18e7553ebbf8ac260db7fb4daa8607a70f74d9
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	drivers/video/msm/hdmi_msm.c
msm_fb: display: suspend-resume on HDMI

When HDMI is primary, suspend-resume is not happening.
For HDMI as primary case, early suspend and resume can be
used. This change implements early suspend and resume for
hdmi as primary case.

CRs-fixed: 381097
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
(cherry picked from commit 30befc28305440f30770a6545839fe4b55ee2207)

Change-Id: I102c733aa21e0a3ce7b2ae448066cc04e9f12c67
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm_fb: display: HDMI power reduction at suspend

During suspend, HDMI clocks are still running and power
consumption is high. Usually HPD module is kept on even
when the cable is not connected to sense the cable
re-connect. But cable connect sense is not required when
the device is suspended. This change makes sure that HPD,
along with other HDMI modules, are totally shutdown during
suspend and there is no power consumption by HDMI.

(cherry picked from commit 88ad8a7be06a86104169cf2739c18c7d4409dde6)

Change-Id: I535645fb489cb89c5450f9caa2ba1823190c7456
CRs-fixed: 335821
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
Fix building
msm_fb: HDMI: Do not add HPD state timer during probe

Currently all HDMI timers are initialized in the driver's
probe function with a maximum possible expiration value. However,
the 32-bit jiffies value is initialized in the kernel so as to
wrap 5 minutes after boot. This results in the HPD timer being
fired 5 minutes after boot even though cable  is not
connected. This change fixes this issue by not starting the HPD
timer during probe.

Change-Id: I9eeb8b892be2476e8debdd4ec5897a103cc34665
Signed-off-by: Aravind Venkateswaran <aravindh@codeaurora.org>
Signed-off-by: Abhishek Kharbanda <akharban@codeaurora.org>
Signed-off-by: Manoj Rao <manojraj@codeaurora.org>
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
msm_fb: hdmi: Do not turn on HPD at boot

HPD is getting turned on by userspace if HDMI is enabled.
We don't need to turn on the HPD from HDMI driver.

CRs-Fixed: 377899
Change-Id: I29af0ca6ba222c7af61b1a0e8b51be35dee6426c
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>

Conflicts:

	drivers/video/msm/hdmi_msm.c
msm_fb: HDMI: Fix lockdep warning

Locks must always be taken in the same order to prevent AB-BA
scenarios from occuring:

======================================================
[ INFO: possible circular locking dependency detected ]
3.4.0-g55e6e49-00052-g71783d6-dirty #3258 Tainted: G        W
-------------------------------------------------------
kworker/0:1/15 is trying to acquire lock:
 (hdmi_msm_state_mutex){+.+...}, at: [<c0340e98>]
 hdmi_msm_hpd_state_work+0x78/0x2d8

but task is already holding lock:
 (external_common_state_hpd_mutex){+.+...}, at: [<c0340e8c>]
 hdmi_msm_hpd_state_work+0x6c/0x2d8

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (external_common_state_hpd_mutex){+.+...}:
       [<c00cd744>] __lock_acquire+0x950/0xa10
       [<c00cd990>] lock_acquire+0x18c/0x1e8
       [<c080c248>] mutex_lock_nested+0x68/0x3c4
       [<c0341510>] hdmi_msm_hpd_on.clone.0+0x230/0x2c4
       [<c07e5dfc>] hdmi_msm_probe+0x378/0x588
       [<c03dcc00>] platform_drv_probe+0x18/0x1c
       [<c03db920>] driver_probe_device+0x148/0x334
       [<c03d9f5c>] bus_for_each_drv+0x48/0x84
       [<c03db7ac>] device_attach+0x78/0xa4
       [<c03daa4c>] bus_probe_device+0x28/0x9c
       [<c03d97e4>] device_add+0x438/0x5e0
       [<c03dd13c>] platform_device_add+0x13c/0x1a0
       [<c0d255d8>] hdmi_msm_init+0x218/0x2d0
       [<c0008708>] do_one_initcall+0x94/0x168
       [<c0d002fc>] kernel_init+0xe4/0x1b8
       [<c000f4f8>] kernel_thread_exit+0x0/0x8

-> #0 (hdmi_msm_state_mutex){+.+...}:
       [<c00cc6b8>] validate_chain+0x944/0x1080
       [<c00cd744>] __lock_acquire+0x950/0xa10
       [<c00cd990>] lock_acquire+0x18c/0x1e8
       [<c080c248>] mutex_lock_nested+0x68/0x3c4
       [<c0340e98>] hdmi_msm_hpd_state_work+0x78/0x2d8
       [<c0097420>] process_one_work+0x37c/0x694
       [<c0099978>] worker_thread+0x22c/0x3bc
       [<c009ecdc>] kthread+0x8c/0x9c
       [<c000f4f8>] kernel_thread_exit+0x0/0x8

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(external_common_state_hpd_mutex);
                               lock(hdmi_msm_state_mutex);
                               lock(external_common_state_hpd_mutex);
  lock(hdmi_msm_state_mutex);

 *** DEADLOCK ***

3 locks held by kworker/0:1/15:
 #0:  (hdmi_hdcp){.+.+..}, at: [<c00972b8>] process_one_work+0x214/0x694
 #1:  ((&hdmi_msm_state->hpd_state_work)){+.+...}, at: [<c00972b8>]
 process_one_work+0x214/0x694
 #2:  (external_common_state_hpd_mutex){+.+...}, at: [<c0340e8c>]
 hdmi_msm_hpd_state_work+0x6c/0x2d8

stack backtrace:
[<c001521c>] (unwind_backtrace+0x0/0x12c) from [<c00cbb14>]
(print_circular_bug+0x288/0x2d4)
[<c00cbb14>] (print_circular_bug+0x288/0x2d4) from [<c00cc6b8>]
(validate_chain+0x944/0x1080)
[<c00cc6b8>] (validate_chain+0x944/0x1080) from [<c00cd744>]
(__lock_acquire+0x950/0xa10)
[<c00cd744>] (__lock_acquire+0x950/0xa10) from [<c00cd990>]
(lock_acquire+0x18c/0x1e8)
[<c00cd990>] (lock_acquire+0x18c/0x1e8) from [<c080c248>]
(mutex_lock_nested+0x68/0x3c4)
[<c080c248>] (mutex_lock_nested+0x68/0x3c4) from [<c0340e98>]
(hdmi_msm_hpd_state_work+0x78/0x2d8)
[<c0340e98>] (hdmi_msm_hpd_state_work+0x78/0x2d8) from [<c0097420>]
(process_one_work+0x37c/0x694)
[<c0097420>] (process_one_work+0x37c/0x694) from [<c0099978>]
(worker_thread+0x22c/0x3bc)
[<c0099978>] (worker_thread+0x22c/0x3bc) from [<c009ecdc>]
(kthread+0x8c/0x9c)
[<c009ecdc>] (kthread+0x8c/0x9c) from [<c000f4f8>]
(kernel_thread_exit+0x0/0x8)

Change-Id: I251049edbc97a5fe0e6c67801cf472fdc48722a7
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
msm_fb: Handle vsync interrupt properly on MDP 3.03 targets

Handle enabling/disabling the vsync interrupt and mdp clock
enabling/disabling in a better way on MDP 3.03 targets. This
will avoid target crashes due to unclocked register access.

CRs-fixed: 388751
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
(cherry picked from commit ab6afa609f541da1ddc585bb0c08ece105a9f8bb)

Change-Id: Ib4c7c2181c8a1791e9cf7417616571340e06cf97
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	drivers/video/msm/mdp.c
msm_fb: Return ioctl on vsync interrupt disable

Before the vsync interrupt gets disabled, initialize the completion
structure and then disable the interrupt. This enables the ioctl to
return successfully in all the cases.

Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
(cherry picked from commit 877932c6538689854e2b6a75ce24c8782fbe1fe0)

Change-Id: I54c42851bc75d3aa16662f9d71baafde2bd6ef27
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>