sched: Reset rq->next_interval before going idle

next_balance, the point in jiffy time scale when a cpu will next load
balance, could have been calculated when the cpu was busy. A busy cpu
will apply its sched domain's busy_factor (usually > 1) in computing
next_balance for that sched domain, which causes the (busy) cpu to load
balance less frequently in its sched domains. However when the same cpu
is going idle, its next_balance needs to be reset without consideration
of busy_factor. Failure to do so would not trigger nohz idle balancer on
that cpu for unnecessarily long time (introducing additional scheduling
latencies for tasks). Fix bug in scheduler which aims to reset
next_balance before a cpu goes idle (as per existing comment) but is
clearly not doing so.

Change-Id: I7e027a51686528c4092d770c7d33c874d38f5df4
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
ASoC: audio: Fix BE not disconnected even codec teardown

Scenario:
When FE1(LowLatency) comes in which opens BE1 and puts it in state
SND_SOC_DPCM_STATE_START. Similarly FE2(LPA) comes in with
connecting to same BE. Now FE2 is in SND_SOC_DPCM_STATE_PREPARE
state and waits for TRIGGER_START. Meanwhile FE1 is closed which
doesn't affect BE1 and FE2 which are connected.
Also, for FE2 pcm_close is called before TRIGGER_START itself.
In such a case, BE1 is not getting disconnected (afe_close is
not called) while Codec is teared down resulting in Slimbus
overflow.

Fix:
Whenever BE1 is found to be in SND_SOC_DPCM_STATE_START state
and FE1 being connected is not started yet, and close sequence
happens for this FE, then allow hw_free to happen for BE1 if
this is the only FE connected to this BE1. This allows BE to be
disconnected which calls afe_close then followed by Codec teardown
not resulting in any Slimbus overflows.

CRs-Fixed: 468118
Change-Id: I03a80a12c1fd0cf09bd2e3dfe1f1eb56589016d3
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
msm: smd: add smd_write_segment_avail()

Packet based SMD channels support transactions which allow the client to
send data payloads that exceed the size of the transport buffer.
Currently clients using this feature call smd_write_avail() to determine
how much free space is available in the buffer for the next segment of the
payload.

This causes inefficencies for the client, as smd_write_avail()
reserves SMD_HEADER_SIZE bytes from the client under the assumption that
a transport level header needs to be written to the transport buffer.  If
the transaction is already started, this assumption becomes incorrect and
space that could be used by the client to reduce the number of write in
some scenarios goes unused.

Add a function to the transaction API, smd_write_segment_avail(), which
is aware of if the transport level header needs to be written or not, and
return the correct ammount of usable space to the client.  Also, convert
the current clients of the transaction API to use
smd_write_segment_avail() as necessary.

CRs-Fixed: 471277
Change-Id: Ibdacd2572fa274c971eb679bc1d60eb2a7e1cab2
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
arm/dt: msm8974: Correct the default Vdd Cx vote

Correct the default vote for Vdd Cx resource. The incorrect enum was
used. This change is needed to allow scaling of the global memory rails.

Change-Id: Ia61940524639da913462cfa77b34aa7117ed0811
CRs-Fixed: 452874
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
msm: kgsl: improve active_cnt and ACTIVE state management

Require any code path which intends to touch the hardware
to take a reference on active_cnt with kgsl_active_count_get()
and release it with kgsl_active_count_put() when finished.
These functions now do the wake / sleep steps that were
previously handled by kgsl_check_suspended() and
kgsl_check_idle().

Additionally, kgsl_pre_hwaccess() will no longer turn on
the clocks, it just enforces via BUG_ON that the clocks
are enabled before a register is touched.

Change-Id: I31b0d067e6d600f0228450dbd73f69caa919ce13
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: camera: Do not do HW reset of the ISPIF

There is no real need to reset the ISPIF, as all the ISPIF reset is
doing is to reset the registers to default values. But there are too
many problems trying to do a reset of the ISPIF as it requires all the
clocks from CSID and all clocks from every VFE interface to complete the
reset. Because of this it simpler to replace the HW reset with a SW one,
where the registers are set to the default value.

The only place where ISPIF driver explicitly requires clocks to be
enabled is when reset is performed. Because the ISPIF needs only the
ispif_ahb_clk clock to be programmed there is also no need to keep the
request for the other clocks in the driver. So we can leave this job to
the CSID and VFE blocks themselves.

This way only the ispif_ahb_clk clock enable requests will be done by
the ISPIF and the other clock enable requests will be left to the CSID
and VFE drivers per device only when they are used and really needed.
This will be enough for the ISPIF to work as desired, as there is no
time when the ISPIF can work alone without the CSID and/or VFE running
in the same time.

Change-Id: I0dbde8b4fef6ee4d5ff15f2195b3dd7936d5eb07
Signed-off-by: Vladislav Hristov <vhrist@codeaurora.org>
msm: camera: Handle no free buffer for dual ISP

For dual ISP, both ISP need to write to the same buffer
in order to ensure the image consistency. When ISP
cannot fetch a new buffer, the hardware buffer address
will not be updated. However, there could be a race condition
where one ISP cannot get a new buffer but the second ISP is able
to get a new buffer. In that case, the image will become out of sync.
This change queue an empty buffer to shared queue for the second
ISP to fetch. When the second ISP fetch the empty buffer, it will
return and not update the hardware buffer address

Change-Id: I0970bf04476661ff7c10680c4b08bd98ac94ec6f
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
msm: camera: Fix for bandwidth update

Bandwidth should be calculated using all clients state,
instead of the state of the caller.

Change-Id: I28f78c9753dd58c821aa25afd28eb4ed83081e81
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
msm: Add support for composite ISP statistics

ISP image statistics done interrupt
 for each stats can be fired at different
time, the timing is based on the statistics
window. For high frame rate camera, the number
of interrupts will be significantly higher if
statistics are collected for each frame. This
change add the support to change the interrupt
policy and configure the hardware to generate
one interrupt when all the image statistics are
collect.

Change-Id: Ib2d103bcd46da6c52de246b1245d8928f37be0c5
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
msm: camera: Attach all ISP context during ISP open

When one ISP is active and another ISP opens, the iommu
attach context call will halt the iommu in order to
program attach the context for the second ISP. This will
cause the first ISP write operation to pause and results
in overflow. This change workaround the issue by
attaching both contexts when the first ISP is opened.

Change-Id: I04202c4bbebc250c5f3af72f8800cc581727a9ea
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
arm/dt: 8226: Trigger on low level and oneshot

Trigger on falling edge is sometimes missed, so
trigger on low level and oneshot instead.

Change-Id: I499bc55e978ddd8f3ac63b458266589f11f0ed1e
Signed-off-by: Amy Maloche <amaloche@codeaurora.org>
msm: clock-local2: Insert dummy write in branch_clk_set_flags()

8974v2.2 will have a requirement for FORCE_MEM_CORE_ON and
FORCE_MEM_PERIPH_ON bits to be set at least two bus clock
cycles apart. Add an extra register write to guarantee this.

This is preferably to inserting an explicit delay, since even
1 us is far more than necessary and would add needless latency.

Change-Id: I1b0f1588067690c0978b629ffab72ebb287b8cb1
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
msm: audio: qdsp6v2: Reset afe calibration data post ssr

In reset event handling for afe, clean up afe calibration block
as part of handling adsp subsystem restart.

Change-Id: Icc32120cded3ae6ddd0dda53708a001e0109e4f3
Signed-off-by: Ravishankar Sarawadi <crsaraw@codeaurora.org>
msm: adsp: Migrate to SMP2P framework from SMSM mechanism

The new SMSM Point-to-Point (SMP2P) framework allows point to
point communication of state information between subsystems.

Use this framework to indicate apps of fatal error on adsp and
also use it to propagate force stop notification from Apps to adsp.

Change-Id: I00d16fd4f50e910807fd667eed3163945168e36f
Signed-off-by: Ravishankar Sarawadi <crsaraw@codeaurora.org>
input: atmel_mxt_ts: Disabling secure touch for power events.

Any power event in the driver happening while secure touch is
active will cause it to close.
Additional fix to make sure secure touch events are forwarded
only if all previous events have already been processed.

Change-Id: I57f7cb45e2e53a923b9ab3b7c9baa34f1d3f9b5f
Acked-by: Christian Bolis <cbolis@qti.qualcomm.com>
Signed-off-by: Amy Maloche <amaloche@codeaurora.org>
msm: mdss: reduce timeline for writeback display

For writeback display, buffers can be released and signaled as soon as
commit is done since the contents will be pushed directly to memory.
That is, there is no need to hold buffer for extra timeline. Reduce
timeline by one for buffers pushed to writeback display to allow buffers
to be reused as soon as possible.

CRs-Fixed: 474903
Change-Id: I896803a12e5dde2983cb284d6914f195ac996337
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: mdss: enable setting secure destination for writeback

New MDSS revision allows setting secure destination flag to tell
writeback block that contents should be written back to secure buffer.
This overrides previous approach to allocate a secure source pipe for
the sole purpose of enabling secure content writeback.

CRs-Fixed: 472679
Change-Id: I073db54ac930dbdead9754dec3a7dbfb0dbee316
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm: mdss: Avoid potential deadlock scenarios

Ensuring that deadlocks are prevented by clearing
locks in all paths of execution.

Change-Id: Ia79f9449c4b040366fa4ed21776c9442bd6fdda3
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>
msm: mdss: Remove background blending config for FB

Background blending for framebuffer isn't handled specially
in the driver. All blending assumes source over destination blending
from userspace.

CRs-fixed: 470535
Change-Id: Idbff01d9d976e57daaa2e5c128575a0dec07b38b
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>
arm/dt: msm9625: add cdp and mtp dts include files

Add support for CDP/MTP dts include files to
reduce common code duplication in various
revisions of hardware.

Change-Id: Id1d487524bcd91ba23fc8960d217bfcce5d8e8f3
Signed-off-by: Abhimanyu Kapur <abhimany@codeaurora.org>