power: pm8921-bms: implement BMS reset

Sometimes during testing it is convenient to force the BMS to take a new
OCV, essentially restarting the BMS soc calculation in order to test
short portions of the battery profile.

Implement a BMS_reset module parameter, which sets OCV to the
instantaneous VBAT and resets the coulomb counter whenever a 'Y' is
written to it.

Furthermore, in the bms reset mode, keep UUC constant at 3%, and do not
run adjusting algorithms until a 'N' is written to the module parameter.

Note that this feature should only be used with a fake battery, as it
maintains a constant voltage and gives us near true OCV estimates.
Also, the adjusting algorithm is disabled due to this reason. If
adjustments to the OCV were allowed, we will end up adjusting the SOC
higher, because the OCV est will never go low as the battery discharges.
It will fail the test cases for which this feature is designed.

Change-Id: Idfe7f0edf9c25f018f6e6d0a9df20a1a04d5277a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: disable ocv updates for flat portion of the curve

An issue is observed when an OCV is updated while the device is
sleeping. When it wakes up the SOC calculations are run on the new OCV
which result in a drastically different SOC than previously reported.
The root cause of this issue is PON OCV likely was unsettled.

Provide a feature where OCV updates can be disabled between certain
SOC range.

Change-Id: I54a75a7e9d05ff2c8ccd484850f02a0190d6a3b7
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: fix override mode causes sleep current increase

The override mode is used to measure battery voltage and current
simultaneously. We observed that the XOADC and the AMUX
were left enabled even after the override mode is exited. This
causes the current consumption to increase by 500uA.

Execute a dummy XOADC read after override mode is exited. This will
ensure that the XOADC and the AMUX get turned off after the dummy
transaction is completed.

CRs-Fixed: 440864
Change-Id: I53b8b67d55bbab1de588a36b7d2eca26ba6e6bfd
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: Enable batt alarm

Set the batt alarm to wake up the system if the
battery voltage falls below a threshold. This is to
make sure that the device does not shutdown abruptly
without any notification.

Hold the low voltage wakelock to prevent the device
from going to sleep immediately after the low voltage
notification.

Change-Id: Ifaeeeb27bd85f9c95f026ac3565681432e247b02
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: pm8921-bms: correct even after faking 100%

The current driver restores the OCV to the max voltage when the
BMS is in a mode where it fakes 100%.

This erases any corrections done to the OCV. Fix it by
forcing the OCV to max voltage just once right after charging
is done with a full battery.

Change-Id: Ibcbc20386e7932fe25d8152943be409397353988
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: Fix CC conversion precision

In a previous patch, the precision of the coulomb counter conversion
was reduced. Fix this by converting the CC value to picovolt-hours
before dividing by r_sense uohm to convert back to microvolt-hours.

Change-Id: I2cb4f99ea3636159dfefd2747b24e6ac3bbb7a04
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-bms: add capacitive resistance

The current code only accounts for the series resistance via a lookup
table. Add a configurable parameter to account for capacitive resistance.

Change-Id: I6a844b51970a6bdf40cfc1340fa31f580efc1c9e
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: fix the mutex usage

get_reading() should be protected by the ocv mutex not the bms output
mutex.

Change-Id: I24eea963611a8df87ce350120d318319cd1a6c3a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: optimize finding ocv

The current code returns if the OCV is within 1% of the expected
percent charge. This is suboptimal and instead it should try to
be find an OCV that results exactly in the desired percent charge.

Change-Id: If0918d0fb386719487c2e0dfa24c255b3c32c5dc
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

Conflicts:
	drivers/power/pm8921-bms.c
power: pm8921-bms: reset coulomb counter when faking high ocv

When charging is complete, BMS will fake a high OCV in order to appear
at 100%. Instead of tracking the cc value at EOC and using that to
offset further CC reads reset the coulomb counter in the h/w itself.

Change-Id: I7e4cb7a057d19c43aa0f949411b272a9e02d7cfd
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Merge "ASoC: msm: Mixer control to update the sample rate of HDMI interface"
Merge "wcnss: Add support for nv bin download at coldboot"
msm_serial_hs: Wait for discard flush completion for UART Rx channel

Completion of requested flush command with ADM driver is having more
latency then previously. Hence now it is required to wait for discard
flush complete if there is more events expected with UART driver which
would go out of sync without it. Below are 2 instances where it is must
to wait for discard flush completion requested on UART Rx channel.

1. Changing Baud Rate of UART
UART application can send baud rate change request based on its requirement
of communication with connected device on remote uart. Serial core also
does set by default baud rate when application is opening the uart port. As
Rx command is queued always with ADM driver from UART driver, for above
events it is required to flush the same after setting the baud rate. Not
waiting for completion of Rx flush would allow application to send command
on Tx or any other ioctl which would reach to connected device but response
may not be received as Rx flush completion is not received to queue next Rx
command to ADM. Hence with this there are chances that received data with
UART wil be lost when Rx flush completion is not received in-time. Hence
wait for Rx flush completion from set_termios() with timeout as 300 jiffie.
Rx flush completion time is non-deterministic as it depends on number of
commands queued to ADM driver from ADM client drivers.

2. While going for UART clock off
UART clock off has multiple state machines and before going into last
state it makes sure that there are no pending data in UART Tx and Rx FIFO.
Although there would be one Rx command queued which is flushed before
moving to last state and going ahead with UART clock off. If UART clock is
turned off before Rx flush request is being executed and ADM tried to flush
Rx command, ADM encounters data bus error on UART Rx Channel. Hence with
waiting for Rx flush completion, and then doing UART clock off on receving
the same would resolve ADM data bus error issue on UART Rx channel.

CRs-Fixed: 457769
Change-Id: I9344277224a2dc3f28140a1f42aa3feed5411b97
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Bluetooth: GAP: Disconnect ACL immediately after Auth failure.

The patch fixes issue of ACL lingering for 2 seconds after
Authentication failure. Another Auth request during this
time results in improper connection reference and hence
resulting in ACL to persist forever if remote doesn't
disconnect.

Change-Id: Ief920af97d8f27e93460130dc86113b40dc5f6a5
Signed-off-by: Mallikarjuna GB <gbmalli@codeaurora.org>
msm: camera: Fix for inverted preview with front camera in 8930
             fluid device.

             Changed mount angle for front sensor(mt9m114) in 8930
             fluid from 90 to 270.

Change-Id: I47b7b211507963a1c25e67cb5b6131b3143ba349

Signed-off-by: Sai Kumar Sanagavarapu <ssanagav@codeaurora.org>
Revert "wcnss: Add support for nv bin download at coldboot"

This reverts commit 8c8778cb99adcf82d36a156761478462110d1714.

Change-Id: I8802851f2a04310bbf94d3129ba1c9fc8a4987d5
Signed-off-by: Uma Maheshwari Bhiram <ubhira@codeaurora.org>
diag: Bring Diag up to date

Diag on the A-Family mainline is out of date. This change brings
the diag code up to date.

This includes reducing the error message frequency and the latest
msg SSIDs, log codes and event IDs.

Change-Id: Ibfce8ea52e25044df32bdff419d457ad296c6fc1
CRs-Fixed: 455623
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
msm: camera: Fix the composite stats buffer handling.

Currently we configure composite stats in HFR mode. In composite stats
mode, the stats buffers are not getting dequeued and dispatched properly.
Hence the stats are not processed properly in HFR mode, resulting in dark
preview in camcorder HFR mode. Fix this by correcting the buffer handling
logic in case of composite stats.

CRs-Fixed: 452197
Change-Id: I98be1160001deea72d0fa31e0e804d523fd72c20
Signed-off-by: Ashwini Rao <ashwinik@codeaurora.org>
Signed-off-by: Kiran Kumar H N <hurlisal@codeaurora.org>
Bluetooth: Dont retry eSCO for WBS

This fix will allow the hci event handler
to notify the eSCO connection failure for mSBC,
to BT host which can fallback to CVSD and retry
the eSCO again with a new codec negotiation.
This behavior will allow PTS test case
TC_AG_ACC_BI_12_I to pass as it expects
a codec negotiation after the first attempt
for mSBC is rejected from the PTS.

CRs-Fixed: 390563
Change-Id: I93973d14a035a743f582e751047bf23b66681932
Signed-off-by: Nitin Srivastava <nitinsr@codeaurora.org>
Merge "Revert "wcnss: Add support for nv bin download at coldboot""