ASoC: msm: Modify min and max period bytes and num periods

Modify min and max period bytes and number of periods in
compressed driver so as to be consistent with lpa and to
meet ION memory requirements. This avoids using huge
buffer sizes for tunnel decode.

Change-Id: Ib71da4cebfc097e7aeaf0ca0e65ee847ba7cceb7
Signed-off-by: Phani Kumar Uppalapati <phanik@codeaurora.org>
mmc: msm_sdcc: Reset SDCC controller if check for Tx/Rx active fails

Reset SDCC controller if the check for TX/RX ACTIVE bit fails while
carrying out DPSM reset after the end of current transaction
instead of taking the entire system down by doing BUG().

CRs-Fixed: 423356
Change-Id: I9e2e945eb9a31d12e0a435df29a8215ae634724b
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
(cherry picked from commit 0a29588be6d3d6bd9122191e7e850c687bb1b166)

Signed-off-by: Maya Erez <merez@codeaurora.org>
Change priority of kernel message to avoid message flooding in logs.

kernel logs are flooded with info message from mdp4_overlay_mdp_perf_upd,
so changed the priority of message to debug.

Change-Id: I1ed9e7a372c563078a8127b324c05b90c67c5849
Signed-off-by: Sangani Suryanarayana Raju <csuryan@codeaurora.org>
power: pm8921-bms: limit the number of tries for ocv calculation

When we want to force a certain percent charge we calculate the
expect percent charge (pc) from the expected RC (remaining charge
same as ocv based charge). We reverse lookup the ocv (open circuit
voltage) based on the pc. We double make sure that a forward lookup
matches the reverse lookup and if it does not within a percent limit
we repeatedly tweak the ocv by 5mV to get it to match.

This tweaking is unbounded and based on the battery profile could
result in a infinite loop. Limit the number of times we tweak the ocv
to prevent a possible watchdog bark.

CRs-Fixed: 406197
Change-Id: Iea874027a9e2f7ce326c8398f255e393fa7e4529
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: Change usb trim value for 1A on PM8917

Adjust a trim code for PM8917 for the 1A setting.

Change-Id: I07c346475fb4a294bc8eb8da8c2048cc23394e20
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: change ENERGY_FULL to CHARGE_FULL

Currently the reported ENERGY_FULL property reports
a value in nAh which does not comply with the power
supply class.

Fix this by changing the property to CHARGE_FULL and
changing the reported units to uAh.

Change-Id: Ib1161d3d8c4a9378eabf44f9de1eae9556d82643
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-bms: fix charging accuracy

The current driver assumes 100mA as the charge termination current.
Use the value configured from the board file.

Also the driver uses the battery voltage at the ADC to determine CC
to CV point. Although it works, it is more appropriate to calculate
battery terminal voltage and base CC to CV point on it.

CRs-Fixed: 420670
Change-Id: Ib046fd7149d71fc62c8f2df7a9747d6b54e95138
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: speed up AICL

An issue is observed where it takes 3 to 4 seconds for the AICL
algorithm to settle on a certain USB current. This should be as
fast as possible.

Fix this by circumventing the delay of the unplug check worker if the
USB input current limit has increased.

Also remove the rounding of jiffies to the nearest second
when unplug check worker is called. This way we guarantee
that unplug check worker (and AICL) runs within the timing
requirements.

Change-Id: I546ff57d76e50ad86eb5853782fdcc1f348c9f0e
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: support temperature less configurations

There could be configurations where the voltage that appears on
the batt_therm line is out of specification and makes the battery
temperature comparators (btc) useless i.e. the  comparators could
trigger when the battery is not really cold or hot.

Add software support to monitor battery temperature. While charging
start a worker which polls the temperature every few (configurable) ms.
If the temperature is hot or cold override btc to force hot or cold
which in turn feeds in to the charging FSM and disables charging.
When the temperature comes back to normal override btc to force normal
temperature. Note that when the temperature goes out of range while
charging the end of charge worker still runs, we can run the btc worker
piggy backed on that wakelock.

Change-Id: I1293ecc2974bae4ad530ecb775cd19072e413c72
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8xxx-ccadc: Disable the interrupt before registering

There is possibility of a race if the IRQ triggers immediately
after requesting. Fix this by disabling the IRQ before it
registers.

Change-Id: I8db5a202a2e63ca0a3e355a6083d426acb7342cb
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: pm8921-charger: PM8917 USB trimming fix

PM8917 has slightly different trimming setup than
other PMIC platforms and requires a 7th bit.

Fix this by reading another scratch register to obtain
this value.

CRs-Fixed: 428106
Change-Id: I71482f9a4430a8bbcd02c954a415ff3fab2a0c8f
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: add pm_chg_write wrapper

A complex workaround needs to make changes in the charger
hardware block during every write to charger registers.

Fix this by adding a pm_chg_write wrapper function and
replacing all pm8xxx_writeb function calls with this
function.

Change-Id: I0c5656798444764b52f4d9d8889f831d674a1610
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-bms: change invalid soc logging to debug

Currently, when unusable charge is calculated to be above full charge,
a warning is logged. Also, if SoC is calculated to be below 0, a error
is logged.

Change both of these to debug as to not confuse people debugging the
kernel when BMS is having accuracy issues.

Change-Id: I93b830d42e7d44435c790832c11d5d38861015e0
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-bms: Add error handling logic

Handle return code in reading vsense average so that
the parent function pm8921_bms_get_battery_current does not
report invalid battery current. While at it, also fix the
variable initialization.

CRs-Fixed: 389636
Change-Id: If24985f47cc9fcd6c2eb84a73165878559008120
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: pm8921-charger: smbc uvlo lockup workaround

During UVLO events the charger hardware may lock up
and hence the charger poweron trigger will not work.

Add a workaround which ensures that
low power mode (LPM) is always enabled while the device
is running off the battery. This forces the
charger to run off the 32kHz clock which prevents
a lockup during a UVLO event.

However as a caveat charger register writes do not
work during LPM and hence during every write that happens
the software makes sure that LPM bit is disabled.
Note that this has no effect while a charger is connected
because the hardware automatically switches over to the
19.2 MHz clock which is needed for the registers writes.

While in LPM mode the bat_gone debouncer is bypassed while
a charger is not connected and re-enabled when a charger
is connected to avoid a debounce delay due to the clock
switching.

Note that all previous clock switching logic
including the battery alarm that was used to force on
the 19.2Mhz clock has been removed as part of this change.

Change-Id: I39b908451f4b678ed63b872ffc46590e2c728b2c
CRs-Fixed: 390327
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: remove the use of vbat_ov irq

It was believed that the vbat_ov irq triggers when the battery voltage
goes above vdd_max. That interpretation is wrong, the vbat_ov irq
triggers when the battery goes above vbatdet threshold.

Remove all the useage and requesting of this interrupt.

Change-Id: If7e5622067c77c4c8d64ee466d1c62e4dcb0e53f
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: charging time expiry fixes

When the charger timer expires charger h/w raises an interrupt and sets
the charger failed bit. Once the charger failed bit is set to 0 by s/w
the charger hardware resumes charging.

The current charging driver resets the charge failed bit periodically.
This is not safe. Update the code to reset failed bit only when the
charger failed interrupt happens and only if a configurable parameter
is enabled.

CRs-Fixed: 428877
Change-Id: If58279329f6c76978223369a2d08d47a7b1e3579
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: recalculate soc immediately upon wakeup

Under certain conditions, sleep current may be very high, and the BMS
may have counted a lot of current. However, SoC is only recalculated
once every 20 seconds of kernel time. If SoC has been recalculated just
before sleep, there may be almost 20 seconds before the SoC is updated.
The user will see SoC make a big jump a few seconds after waking up.

Fix this by recalculating SoC immediately after resume in the BMS so that
SoC is immediately refreshed upon wakeup.

Change-Id: I358909c38b0771fe0283386841b6123ddb2931a6
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-bms: account for sleep time in ADC calibration

Currently, the system calibrates the CCADC and HKADC every 10 minutes of
kernel time. However, this does not count sleep time, which could make
calibration much more infrequent.

Fix this by saving the time of the last calibration for both ADCs and
immediately calibrate upon resume if the elapsed time is longer than the
calibration period.

Change-Id: I34f51c6202cbaa805c496360e8dbd391890decc6
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-charger: set USB OVP time to maximum for PM8917

The USB OVP debounce time play a significant role when a
watchdog reset occurs on PM8917. If the default value of 4
ms is set this can lead the SMBC to mistakenly enter restart_pon
and reset all regulators.

Fix this by increasing the USB OVP debounce time to the maximum
setting of 15ms.

CRs-Fixed: 434656
Change-Id: Iaab82ea254444bba233cd9ebad93d38426154ca4
Signed-off-by: David Keitel <dkeitel@codeaurora.org>