msm: mdss: add proper pipe unmap calls for pipe references

For every pipe get/map call there needs to be a related unmap call.
These are missing in some cases.

Change-Id: I85f8897be6d34ef217102ef922a48afb6e6cc838
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: display: reduce display commit prepare waiting time

Unblock overlay_set, prepare and buffer sync ioctls when
commit thread finishes hardware programming.
Use wait_for_kickoff nstead of pan_idle for these ioctls.

Change-Id: Iefb6cbc390d2130926fdcb93688b4d92bfb26937
Signed-off-by: Ken Zhang <kenz@codeaurora.org>
Signed-off-by: Neti Ravi Kumar <ravineti@codeaurora.org>
msm: mdss: add support for rotator in mdss_mdp_mixer_get

Currently ctl->mfd is not populated for rotator sessions. If
mdss_mdp_mixer_get is called by rotator session then it will always
fail the NULL check for ctl->mfd. This will flood the logs for every
rotator commit and can lead to un-predictable outcome. Fix this by
properly handling rotator case in mdss_mdp_mixer_get.

Change-Id: Ib1896149302bd60b99028ae26df2393fab30dd6e
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
msm: mdss: fix sync fence deadlock when rotator is used

In the current implementation, whenever rotator play is called, it
forces DMA pipes to be released by calling commit on video mode ctl
paths if they are using DMA pipes. Here assumption was that DMA pipes
will either be used in block mode or line mode, all or none. But this
assumption is not valid any more where we can have a use-case where
DMA0 is used for rotator and DMA1 for video mode ctl path. In this
use-case, current implementation can lead to sync fence deadlock. Fix
this by removing obsolete assumption.

Change-Id: I2d1da9dca5d958257796d617db11d93631c98f27
CRs-Fixed: 656463
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
(cherry picked from commit 1f3710b6b90753ee4670cc1ad009f6f763b8fbf2)
msm: mdss: add dynamic clk status check to pipe idle verification

Dynamic clk status of pipe can indicate if that pipe is active or not.
This status in conjunction VBIF halt status of pipe describes the idle
state of the pipe. Add support to parse necessary offsets from DT and
use them to find idle state of the pipe.

Change-Id: I83c6f323d48a85bfc08ff7bcee47f7c3038ea7e1
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
msm: mdss: ensure pipe is halted before freeing buffers

When pipe is being detached from mixer, there is potential corner case
if underrun occurs at the same time which can cause pipe to flood the
VBIF. On the other hand unmapping a buffer requires VBIF to be idle to
sync TLB, so need to ensure pipe halt is done before freeing the pipe
buffers.

Change-Id: I9686b9d7d17d8dc2a8334157cfa8fa23ba5b47ee
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: mdss: Handle case when pipe is not idle during cleanup.

When pipe is not idle during cleanup, MDP can go into an unrecoverable
state, which can lead into other issues. If it gets to this point we
need to recover even if it means changing display contents for a
fraction of time. To handle this follow recovery sequence:
1. Setup the pipes that are not idle to solid fill mode so that nothing
   is fetched from memory on these pipes.
2. Stage them into mixer, flush and wait for a vsync to happen and reset
   sequence to take effect on these.
3. Finally, reattach the current frame pipes to restore display back to
   normal.

Change-Id: If545b56bf32a46699871381d86e80c1980ec3cc7
Signed-off-by: Jayant Shekhar <jshekhar@codeaurora.org>
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: mdss: Prevent excessive logging during rotation set failure

Changing the error log to debug log in case SMP reserve fails
for rotation. The use case falls back to GPU. Same is being
done in  case of mdp interface set path.

Change-Id: I00a9e05b3a04a87e354fd0e60ad900f4f71cdfc1
Signed-off-by: Vineet Bajaj <vbajaj@codeaurora.org>
msm: mdss: Remove init phase programming

Init phase should only be programmed to a non zero value only through
a user program. Default value of zero is programmed by the driver to
avoid hardware hangs

Change-Id: Iff99394d2f3a937c5bb4456c2f7ca5669a5c732b
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>
msm: mdss: prevent dereferencing of user space pointer

We were dereferencing a userspace pointer in kernel.

Change-Id: I128455904cd396690350fc6b784a8844d594539c
Signed-off-by: Terence Hampson <thampson@codeaurora.org>
msm: mdss: Hold MDP clock Ref count in pan_display path

If handoff fails, the clock ref count becomes 0 and iommu
will get detached. In pan display path, since at that
particular instant iommu gets detached, we use physical
address. After this if iommu is again attached and physical
address is fetched, it can result in continuous IOMMU page
faults. To address this hold MDP clock ref count
in pan display path.

Change-Id: I2370b276acdced2cf22083eb80fcad1b2e454315
Signed-off-by: Jayant Shekhar <jshekhar@codeaurora.org>
msm: mdss: Add update notify for backlight change in static screen

Previously, the change of backlight sysfs node value will not trigger
notify updates if display is in static screen case. This will cause
delay or wrong configuration for assertive display. This patch fixes
the above issue by adding an update notify if backlight changes when
there are no display updates.

Change-Id: I1475896214a50dc1fa71739aa751b2e626d27adb
Signed-off-by: Ping Li <quicpingli@codeaurora.org>
msm: mdss: disable irq to enforce mutex within dsi_event_thread

Mdp spin lock is used in dsi_event_thread and in irq context.
Disable irq while holding spinlock to avoid context switching
into irq context and cause spinlock recursion

CRs-fixed: 652850
Change-Id: I4bd8cadb1f5d83acc7e866344b7585e7944e08ac
Signed-off-by: Kuogee Hsieh <khsieh@codeaurora.org>
msm: mdss: Clear the previous state of pipe during SOLID_FILL

Clear the previous state of pipe when it is being used in SOLID_FILL
operation to prevent wrong register configuration. For ex: Use case
when DMA pipe was used in BLOCK mode in previous frame, then it is
being used in LINE mode for SOLID_FILL operation in current frame.

CRs-Fixed: 655993
Change-Id: I0ed257276428b96c10a92457a16df4dfdc42c1f8
Signed-off-by: Sushil Chauhan <sushilchauhan@codeaurora.org>
msm: mdss: refactor pipe retrieval and ref count logic

Allow only retrieval of pipes that are on particular framebuffer device
used list. This ensures that pipe is not modified from a different fb
device node and cause potential issues.

Also, modify the ref count logic to use kref and ensure pipe is freed
only while holding mutex in case there could be race condition that
pipe is allocated while being freed.

Change-Id: I626323b5df981a7ed1e03196126cd4376b5ba6a6
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
Signed-off-by: Anusha Koduru <kanusha@codeaurora.org>
Revert "Revert "msm: mdss: refactor pipe list management""

This reverts commit 38a91163f5f56613e1b980441c8fe17e74218d01.

Change-Id: I28c2767aadcbcbf89ac78206d467d35aa329e0fe
Signed-off-by: Vishnuvardhan Prodduturi <vproddut@codeaurora.org>
msm: mdss: fix multiple overlay release sequence

Overlay release allows multiple releases to happen by having
multiple bits set in overlay unset call. Fix logic to find
all pipes which match the bitmap.

Change-Id: I6a25a81fe4c437b5546537d48e250055357682f0
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
Signed-off-by: Vishnuvardhan Prodduturi <vproddut@codeaurora.org>
msm: mdss: Allow DMA pipe sharing only on WB mixer

DMA pipe can only be shared on the writeback mixer for
concurrent line and block mode operations. Only allow
sharing if the mixer attached to the pipe is already a
writeback mixer.

Change-Id: I9a0e5144fdf87f681493cd92d9cc809836ab1a5c
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>
msm: mdss: remove extra lock for ctl calls

Some ctl functions need only protection for mixer programming changes,
since all of these calls are made within ov_lock there is no need for
additional protection. Specially since ctl->lock is still held when
mixer configuration is safe to be changed.

Change-Id: I4f39e28f40ef18789a653d02346358b7ca7590c6
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: mdss: Fix rgb_565 format for 90 degree rotation

Make rotator output format for rgb_565 and bgr_565
as rgb_888 for 90 degree rotation as expected by
MDSS.

Change-Id: I0865b5688fa662d1e88d1efebef26a38d4abfd61
Signed-off-by: Pawan Kumar <pavaku@codeaurora.org>

msm: mdss: Swap RGBA format to BGRA with bwc rotation

When BWC is enabled, rotator format needs to be swapped from
RGBA to BGRA to avoid color mismatch on the ouput image.
This is specially needed with a GPU composed FB.

Change-Id: I956a354f3fe605e2c7bda4c4331cfe5bcd6417c7
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>

msm: mdss: synchronize formats across rotator output and pipe setup

The rules applied to switch formats must be the same across
rotator output and the following pipe setup. Also, yuv rotator
output format should always be set to pseudo planar for MDP
hardware optimality.

Change-Id: I3f5f09bcc599627e47495fab253ec0d9d8d5fa1c
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>