video: msm: Clear previous histogram data on next startup

Clear the pointer to the userspace histogram struct when histogram is
started. Previously, when the histogram was stopped while a histogram read
was in progress, the pointer was not cleared, causing the next histogram
read to think that someone was already using the histogram.

CRs-Fixed: 361640
(cherry picked from commit 19e4b71f617e307cacf0be077e08bec5c37df290)

Change-Id: If09017149e98b35c49603372c554aa4c97f2de82
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
video: msm: Check for multiple readers of histogram

Check to ensure that only one reader attempts to read one frame's worth of
data from a histogram block. Prevent the case where two readers attempt to
get data, but end up causing a loop where neither of them do.

CRs-Fixed: 361640
(cherry picked from commit 71cf95bf1100ab5de55bf3858d40996be7dc445e)

Change-Id: I48878d9fe02d96f306894ed9acc47bf41cd9984b
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
video: msm: Avoid waking readers on failed histogram copy

Avoid waking up the waiting histogram reader when the current histogram has
failed to copy. Additionally, clean up initialization of histogram
workqueue (was initialized twice).

CRs-Fixed: 361640
(cherry picked from commit 0dc81db9cf48d869987e8fa8ab8914fcec964bda)

Change-Id: I376c0193b8e34aba5b0aef54feb9504f450ffff4
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>

Conflicts:
	drivers/video/msm/mdp.c
msm_fb: Check for Histogram NULL while queuing work

Don't queue the work if the user hasn't requested for the
histogram data

CRs-Fixed: 365729
(cherry picked from commit ff42a9a426ab9a76d75a29464412807dd72ceb13)

Change-Id: I0b28097fa00f13a836c2ee9d35e8e4557f1c70f0
Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>

Conflicts:
	drivers/video/msm/mdp.c
video: msm: Always queue histogram work

Always queue histogram read worker in order to gain concurrency protection
from the histogram management mutex (move previous checks/calls into worker
itself).

CRs-fixed: 363763
(cherry picked from commit c0d815c2a4118d1ba51e316c6cb59bee4d68eb9b)

Change-Id: If9e3c13b5e4005f81fd1b5d2664af206b1decf5b
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
video: msm: Resolve post processing memory leaks

Allocate memory for post processing only once. Free post processing memory
when MDP is removed.

CRs-fixed: 366325
(cherry picked from commit d60ac323a1e3e7086ef2d77c866d5ed482d2a4e9)

Change-Id: I244f4e10a6933e2acaf69a83d8b91ee5f6e27557
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
video: msm: Always queue histogram work & lock histogram calls

Always queue histogram read worker in order to gain concurrency protection
from the histogram management mutex (move previous checks/calls into worker
itself).

Lock the mdp_histogram_start and mdp_histogram_stop calls with the same
lock used currently by mdp_do_histogram to maintain that every do_histogram
called between a start and stop will be completed.

Add a timeout to do_histogram wait_for_completion so that it will unlock
and yield to other histogram calls if it waits for longer than 33 msec.

CRs-fixed: 363763
(cherry picked from commit 56a123baaab84af584fbbf5cbb29955ec5c92f39)

Change-Id: Icc503aed4e60dd01941682003ca3dbc844aed8d9
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
msm_fb: Handle multiple histogram reader errors during suspend/resume

If a histogram reader waits for completion in the do_histogram ioctl
and during this time the device is suspended, the complete for this
gets called from mdp_histogram_ctrl_all() in the panel_next_off()
sequence. This results in mgmt->hist not set to NULL. The subsequent
do_histogram ioctls after device resume fail due to multiple reader
failure condition since the histogram irq will be enabled now from
the same mdp_histogram_ctrl_all() during panel_next_on() sequence and
this by-passes mgmt->hist getting set to NULL that is present in
histogram_start() ioctl. Handle this scenario.

(cherry picked from commit a43f44b44ee221df11ad84b8536c1c8d5373cbaf)

Change-Id: Ib0485da24c0f09a3f26768b75231903c8a2e0033
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
video: msm: Fix corner cases of "read twice" error

Fix several cases where histogram's completion structure is completed
multiple times which causes the next histogram read to force the histogram
software state machine into believing that the histogram is always being
read by someone.

When the timeout in mdp_do_histogram times out and then soon after the work
that was being waited on completes, the next do_histogram call that is
processed will not wait (and thus will not have its hist field set to
NULL). This will cause all subsequent do_histograms to think that the
histogram is currently being read, and will cause the "read twice" message
to flood the kernel logs.

This error is fixed by always initializing the completion structure before
waiting for the histogram to complete. That way if the completion happens
after the timeout, instead of causing the error, the completion's internal
counter is reset to zero, which prevents the next histogram read from
completing without waiting.

(cherry picked from commit 3d297368b8199b07bda815915e94ecb5761561b0)

Change-Id: Ic1bc4b8688cd191d226de1df15d389de09996106
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
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
(cherry picked from commit 1bb4edf9242b0397975636a4442318713a53b5e6)

Change-Id: I0712924d669abcb820654cd6ca5f7da37bed57e6
Signed-off-by: Pravin Tamkhane <pravint@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
msm_fb: display: remove mdp_lut_enable call to avoid hang issue

Calling this function is not necessary in mdp overlay2 writeback
driver. If called, it causes command mode primary hang.

CRs-fixed: 365332
Change-Id: Id7054c3e56224035ec5939d91f8ce152b038e858
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
(cherry picked from commit 98b3a61592b34d0f39ed2dd00ef56b3ad575e0d2)
Revert "msm_fb: display: Add timeout for waiting on update"

This reverts commit c814cd27862671709b6cc5dbdad665d182fe37a6.
msm_fb: display: add stage commit before kickoff to WFD

Since stage commit had been splited out of stage up fucnction,
it needed to be called to stage pipes into mixer befroe
kickoff mixer. Add this function into overlay writeback for WFD.
This patch varies a little bit from the mainline patch as it got
updated again. Now making it equivalent to mainline.

(cherry picked from commit e540ed2d72f723d3b5ac7e444899921cc227ff63)

Change-Id: Ic2bf488ef61d6c31a3997906b2d70090818a9bc0
Signed-off-by: Kuogee Hsieh <khsieh@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>
msm: display: Buffer sync point support

Add MSMFB_BUFFER_SYNC ioctl for the communication of
the acquired and released fence fd between kernel and hwc.

Wait for acquired fence before pan display.
Signal the previous released fence after pan display

(cherry picked from commit fd384f86cd5214a9359c56dc93affe95f2d802a4)

Change-Id: I30a7b33f523acc6e42978c8cbd0fa526808a06ed
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>

Conflicts:
	drivers/video/msm/msm_fb.c
	drivers/video/msm/msm_fb.h
	include/linux/msm_mdp.h

Conflicts:
	drivers/video/msm/msm_fb.h
msm: display: add sync point support in overlay commit

Wait for fence signaled before commit, signal previous
fence after commit done. Same as pan display

(cherry picked from commit e622fc13cb58becfc077a830421e471abcc08140)

Change-Id: Ic7f95de86c5776a17ab1e5b7457e2dfb1108b576
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>
msm: display: make pan display as a non-blocking call

Schedule a workqueue, do the current job in the workqueue handler.
Block the second entry if the first one has not finished

(cherry picked from commit c760154faefd4772824cc2b032f5375f4ff1b75e)

Change-Id: I38d5487a9002d08449f865b35720adb54e158f5b
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
msm: display: add display commit ioctl

Display commit ioctl will do what pan_display
can do, addtionally has customized setting, such
as non-blocking call.

(cherry picked from commit d88df9d27e44fc35d16c7a4ea92508db1df12d8f)

Change-Id: I17e781c96f93f3d937020392e3bb7f090283a0b2
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>

Conflicts:
	include/linux/msm_mdp.h

Conflicts:
	include/linux/msm_mdp.h
msm: display: fence fd releasing

Release the fence fd after the fence has been signaled.

(cherry picked from commit 67945f986c46d592e26faba303b8b694397432a4)

Change-Id: Idc79eda3cbb518938d83a6c86a9af96db7f4675e
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>
msm: display: buf sync enhancement

Support wait for fence when flag is set

(cherry picked from commit 0745ebc4d82b4676da9b5ab8490824f6f9faa31b)

Change-Id: I2096103149874b3c7db90c38df59a1c767146994
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>
msm: display: allow fb open even in suspend state

resume might be coming later, allow fb open sucessfully, only
panel driver needs be delayed

(cherry picked from commit 89380aac14332dd3ff39a3f0904bfed117458abc)

Change-Id: Id24112f5bba7ba6290113987ebcc8ba6e4256419
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>