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>
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>
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: Update backlight level on resume after first pan display

Use shared workqueue to delay the update of backlight after
a first valid frame is displayed on the panel. This avoids any
transients being displayed during resume.

CRs-fixed: 361002
Change-Id: Ia2c2e39aae62e9ddfebe3a26fb4dbc969d0892c2
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
(cherry picked from commit 8c13d2615b1c608f941137166efb649353cc0bdb)
Merge "msm_fb: Update backlight level on resume after first pan display"
arm: Don't disable interrupts during WFE fixup

Disabling interrupts during the Krait WFE fixup can result
in deadlock if a thread tries to acquire a spinlock that is
released from an interrupt context. Instead of disabling
interrupts, modify the interrupt handler to reset the fixup
condition to put the processor into a safe state in the
event that the interrupt came in during the fixup window.

CRs-Fixed: 383670
Change-Id: Id504f46d6f840dc32ca11ed2f813003143e60f2d
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
(cherry picked from commit 1fd137804b489f7a0b4103d846cda13a07e26cdf)
msm: bam_dmux: Extend locking around SPS transfer call

When a new receive packet is created in queue_rx(), it is added to the
receive packet queue and also queued with the SPS driver.  Once the
packet is filled, then BAM DMUX calls sps_get_iovec() to get the filled
receive buffer.  BAM DMUX then pulls the receive packet info off of the
RX queue and compares the DMA address from the sps_get_iovec() call to
the expected DMA address.  In some cases, they do not match resulting in
BAM DMUX processing the wrong RX buffer.

Going back to the queue_rx() processing, the packet is added to the
receive queue with a mutex locked, but then the mutex is unlocked before
the call to sps_transfer_one() which allows a race condition to exist if
multiple threads call queue_rx().

During normal operation, queue_rx() is only called by the
single-threaded receive workqueue, but during the call to
reconnect_to_bam(), a race condition is expected between the call to
rx_siwtch_to_interrupt_mode() and the final call to queue_rx() if a
packet comes in and is processed before the queue_rx() call is
completed.

This change extends the receive pool mutex locking around
sps_transfer_one() call which resolves the issue.

CRs-Fixed: 377609
Change-Id: Iba5b10e291a1612846fa58dae87aadbd79aa297b
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit 00cf869cf08158aae15e568d687603512f99dfd6)
msm: wfd: Add error handling for input buffer ion map failure

Target reset happens when trying to do a ion_unmap_iommu
on the above fd, which was never mapped. Added a check for
non-zero virtual address.

Change-Id: If77c268062fbf6e31aa930f09c0088e8844db5ea
CRs-fixed: 394779
Signed-off-by: Srinu Gorle <sgorle@codeaurora.org>
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm: vidc: Reset data corrupt flag for non-H264 decoder

Core does not set display correctness flag on decoder
output buffers for non H264 video codec. With this change,
we reset the data corrupt flag for non-H264 codec.

CRs-fixed: 397599
Signed-off-by: Rajeshwar Kurapaty <rkurapat@codeaurora.org>
(cherry picked from commit fde67e239d8ac3a1e983b7d82d0c37af47464138)

Change-Id: I8247e9dff7a66b9538b102df158dfe1bca0d937c
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm: camera: Fix color invert issue

The bayer pattern will invert if the frame lenght line
is odd. The change ensures frame length line is always
even.

Change-Id: I7f796b8b0580a563c376f13ed781535df7f54389
Signed-off-by: Rajakumar Govindaram <rajakuma@codeaurora.org>
(cherry picked from commit ad09ecea54bb88dea5145a08f5b0c380f053d2c4)
Merge "msm: camera: Fix color invert issue"
Merge "arm: Don't disable interrupts during WFE fixup"
Merge "msm: bam_dmux: Extend locking around SPS transfer call"