ASoC: update drivers to handle errors correctly

Avoid logical conflicts seen while error handling.

Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ASoC: msm: fix the hph and lineout concurrency

There was a noise observed during the concurrency of the
hph and the lineout usecase.
This is due to incorrect register value updates in the concurrencies.
Update the register values as per the hw/sw document.

Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: avoid lockdep splat by revalidate_disk

Sasha reported lockdep warning [1] introduced by [2].

It could be fixed by doing disk revalidation out of the init_lock.  It's
okay because disk capacity change is protected by init_lock so that
revalidate_disk always sees up-to-date value so there is no race.

[1] https://lkml.org/lkml/2014/7/3/735
[2] zram: revalidate disk after capacity change

Fixes ("zram: revalidate disk after capacity change").

Signed-off-by: Minchan Kim <minchan@kernel.org>
Reported-by: Sasha Levin <sasha.levin@oracle.com>
Cc: "Alexander E. Patrakov" <patrakov@gmail.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
CC: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: spm-v2: Store voltage levels into PMIC_DATA3

On certain targets, where the SPM controls the power supply for each
core, the SPM power down sequence takes care of restoring the Voltage
level after a power collapse to the appropriate sleep level. The active
voltage level is stored in the PMIC_DATA_3 register and SPM state
machine uses the data in this register to restore the voltage to the
current active level.

Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: spm-v2: Flush the PMIC_DATA registers

Different versions of SAW use different PMIC_DATA registers to
save the current voltage, which is used to restore voltage when
exiting low power modes. Flush the appropriate PMIC_DATA registers
depending on the SAW versions.

Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: spm-v2: Use proper register offsets for SAW2_v3.0

Current code get the register offsets for SAW2 based
on hardcode macros. Use SAW2 major, minor numbers to
get the proper register offsets to different versions
of SAW2 controllers(i.e: SAW2_v2.1 and SAW2_v3.0) and
this patch remove the SAW2_v1.1 controller related code.

Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: spm: set pc mode bit for SAW2_3.0

Set the power collapse bitin SAW2_SPM_CTL register.
This bit is used to differentiate other low power modes
from power collapse mode. This information is used for
contolling DBGWRDUP input signal. If PC_MODE is set DBGPWRDUP
signal is de-asserted as soon as SPM_WAIT_ACK becomes HIGH.
When the PC mode is not set it will help in early exit from
clock gating.

Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: spm: Update msm_spm_turn_on_cpu_rail() to use new SAW2 base address

Update the msm_spm_turn_on_cpu_rail() to use SAW2 base addresses passed
from the release_secondary to turn on the cpu rail, before bringing back
the cpu online.

Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ocmem: Add support for driver probe deferral

If a driver which needs to be probed before the ocmem
driver returns a EPROBE_DEFER, then the successive probe
of the ocmem driver will fail. Add support for probe
deferral in the ocmem driver.

Signed-off-by: Neeti Desai <neetid@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Set default rate control to VBR/VFR

In case client doesn't set the rate control, default to VBR/VFR.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Clean up code in mdp subdevice

Just a general cleanup of code in the mdp5 subdevice.  Also fixed a minor
bug in which we called msm_fb_get_writeback_fb() twice for no good
reason.

Change-Id: I805f5f2e5e04d365cd0d93281a0c835940cea0fe
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Add an dummy encoder subdevice for debugging

Created a dummy encoder subdevice that just copies the input buffer into
the output buffer.  This is useful when we'd like to examine the MDP
output, which is normally very difficult as the buffers associated with
the MDP output aren't exposed to userspace.  Since the dummy enc-subdev,
copies the input buffer into the output buffer, which is exposed to
userspace, we can easily dump the MDP data.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Stop mapping buffers into kernel memory

Aside for debugging purposes, there's no need to map input/output
buffers into kernel.  Unnecessarily mapping it causes low memory issues
on various targets as the buffers are as big as 2MB each.

As kernel mappings are useful for debugging, map it only when
CONFIG_MSM_WFD_DEBUG has been enabled.

Change-Id: I2c3d48397a0ebdd5c8dc559c306c54bda0b7d076
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Revert "msm: wfd: Set default rate control to VBR/VFR"

Reverting commit as we
currently see much better performance with CBR/CFR.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Allow client to provide a tolerance for an acceptable FPS

In cases the driver's frameskipping is unacceptable, provide a tuning
parameter that controls the skip frequency.  fpsvariance is the
percentage for the fps that the driver can overshoot by, which allows
for the driver to skip fewer frames.  fpsvariance == 0 forces the driver
to strictly observe the fps, whereas fpsvariance == 100, allows the
driver to completely ignore the fps, allowing to run in a free-running
mode.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: protect queued buffers list with lock

- Queued buffers list is accessed in both queue and
  dequeue functions. Without proper locking queue gets
  corrupted resulting in crash eventually.
- To avoid race condition, added mutex around vb2_dqbuf call.

Signed-off-by: Srinu Gorle <sgorle@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Add timeouts to completions

In the case of Venus going into a bad state and not returning buffers,
timeout of the completion so that the driver isn't stuck perpetually
waiting for a buffer.  This at least gives the driver a chance to clean
up and exit gracefully.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Lock the state in vsg_start

Protect the state in vsg_start with a mutex as it can be accessed from
other threads.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: wfd: Modify enc_avg_latency to only measure the encode latency

Previously enc_avg_latency measured the time Video code took took to
encode a frame and the latency of the userspace client in picking up the
buffer.  Change the meaning just to measure encoder busy time.

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: vidc: Free memory allocated to keep track of buffer ownership

Memory for free_output_indices and free_input_indices was never freed.
This commit kfrees the memory as part of venc_close().

Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>