msm: vidc: add hevc hybrid driver support

Changes to support hybrid hevc decoder in
v4l2 video driver. Dsp only hevc decoder does not
have mips to handle high resolution (1080p) and
software only solution has thermal/power impact.
Hybrid hevc decoder will have lower power numbers and
better performance for high resolution (1080p).

Change-Id: I9fc4e00fc230c481b18c929c5eb867ac80aec987
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
msm: vidc: Supress non fatal Session errors

FW sends SESSION_ERROR for various reasons. The session error
might not be fatal always. This is conveyed using event_data1.
Driver needs to process this message and supress non fatal
errors and reports only fatal errors to clients.

Change-Id: If9ded26977805e2c2299ef1c4a63212d2679495c
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: fix setting of client buffer count

The client requested buffer count was not honoured
in specific case - when requested buffer count
was less than actual buffer count, but greater than
min buffer count. It would be set to the min buffer
count, which would fail playback.

Change-Id: I10859fd2cb309b8f2b4fb106f9a78f4dc46d45ed
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Remove frame size setting on OUTPUT Port

Currently driver sets frame size to FW on both INPUT and OUTPUT ports.
1.4 FW version doesn't support frame size setting on OUTPUT port.
FW uses the size set on INPUT port for decoding. Hence removing
the frame size setting to FW.

Change-Id: If2c2a202ccc069cf30b65669c5c57d5179bcc108
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: read Dynamic Buffer mode capabilities

During session_init_done firmware will inform if it
supports Dynamic Buffer mode for output buffers.

Change-Id: I6b29f881f44c89b3821e68aff10511644771a6d1
Signed-off-by: Arun Menon <avmenon@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/msm_vidc_internal.h
msm: vidc: add set ctrl for Dynamic Buffer mode

The video driver will support Dynamic Buffer mode
for capture port. With Static Buffer mode, all the
output buffers are pre-registered with firmware
before stream-on. In dynamic buffer mode, there will
be no pre-registeration of output buffers with
firmware. This mode is primarily for streaming
use case, to save on video start-up latency.

Change-Id: Iafb9541bd185a474b169dfe17a5a278b930bdad6
Signed-off-by: Arun Menon <avmenon@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/msm_vdec.c
msm: vidc: move buffer handling inside msm_vidc

Dynamic Buffer mode support will require buffer
handling support in vidc layer, rather than v4l2
layer.

Change-Id: I4732a09afc6b9dc279d7dbf28e362bf400e09cc9
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: cleanup vidc function to register o/p buf

This change modularizes map_and_register_buf function
used to add output buffer to registered buffer list.

Change-Id: I73c1d4b5c66f75fe4b1bce2c2bfc2277a6157e0a
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: handle mappings for Dynamic Buffer mode

For dynamic buffer mode, map and register each
buffer during qbuf before sending to firmware,
instead of doing it during prepare_buf. Based on
the buffer ref count, the FBD from the firmware is
unmapped and released back to client or queued back
to firmware.

Change-Id: I91aaf80f0177bcf2e18d3d26b41f5ea131334579
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: handle release ref events for Dynamic Buffers

For dynamic output buffers, firmware can hold on to a
output buffer reference after releasing it to
driver. The buffer is marked as read only and sent
back to client. The driver maintains the reference
of this buffer and decrements it when firmware
sends the release reference event. The client is
notified of the release reference event.

Change-Id: Ie3c014af255e09f6dac9b3b853c9994b97d830b6
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: flush Dynamic Buffers held in driver

A dynamic buffer whose reference is pending
with f/w and queued back by client, will be
held in the driver. During flush, f/w will
release the reference, but driver should not
queue back the buffer to f/w.

Change-Id: If6fea08645a186691d49beaaf7a51a75f4b3121e
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: add debugfs support for Dynamic Buffer mode

video driver debugfs will provide the following info
(a) buffer mode for each buffer type
(b) list of pending output dynamic buffers with
firmware and driver along with their ref count, fd
and address.

Change-Id: Idc3816c825dfb0c174e6d01b72e741d14f9299e3
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: query tz for Dynamic Buffer feature support

Query TZ before returning to video hal whether dynamic buffer
mode is supported or not for secure playback.

Change-Id: I77744807524f5d6a4a1e45ea12719c5d4fd6df39
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Shalaj Jain <shalajj@codeaurora.org>
msm: vidc: avoid usage of output_tag to get session_id

The firmware will send session_id as part of
struct hfi_msg_event_notify_packet. The driver should use
the session_id in this structure rather than from output_tag.
Without this change release reference event will not be
handled correctly by driver.

Change-Id: I6005482a1b2dfefb6acf0ff797c291197791ca4a
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: add 4cc for hevc hybrid decoder

Change needed to support hevc hybrid decoder
in v4l2 video driver.

Change-Id: I830ccc7c180a3b09d8046873f9fa1daf195f6b65
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
msm: vidc: Add clocks and power counts

Enable power and clock ref counts in debugfs
to easily debug any ref count mismatch.

Change-Id: If06ef139f5a4517cb29a84e86193a6cc2c0f9e64
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
msm: vidc: Add support for encoder rotation

Venus FW supports rotation. Driver sets the rotation
angle and updated height and width. Rotation support
added for Venus based chips.

Change-Id: I564dea14140accf09621357c4a40b8769e719e3a
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: Synchronise data shared between controls

Some of the V4L2 controls perform similar tasks and have some shared
data between them.  Unexpected sequences of controls can possibly cause
data coherency issues causing the firmware to be programmed incorrectly.
So, when a control is updated with a new value, update related controls
with a similar enum so that they both have similar values.

Also, change the frame rate values to normal FPS rather than Q16 format.

Change-Id: Iebb0ddc33374ab8eb7106b005965c2eede797aea
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: fix a race condition in dynamic buffer handling

Fixes a race condition while ftb is queued to the driver
and release reference event for the same has been returned
from the firmware. Without this change, we would end up
having a buffer which is registered in the list but not
queued to firmware. As a result during flush this buffer is
not returned back to client and results in video freeze.

Change-Id: Iaf224a56a5b6c5042bdd662bb14cd63b29586854
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: flush dynamic output buffers in reconfig

In dynamic buffer mode, if driver receives a
flush during reconfig, it should release all
buffers held in the kernel and not queued to
firmware. Without this change, the buffers held in
the kernel do not get flushed and video client
hangs waiting for release of output buffer.

Change-Id: I39bc31bda755947dec0db8a55583da8ad5b21678
Signed-off-by: Arun Menon <avmenon@codeaurora.org>