power: qpnp-bms: Avoid deadlock in reset_vbat_monitoring

Avoid using mutex in reset_vbat_monitoring() as this function is
already called holding the same mutex.

Change-Id: I18f361d78ee3a53f69e57265faa513987961f32b
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: qpnp-bms: Improve SoC response time while charging

Currently, there are a number of issues that can cause SoC reported
while charging to lag behind the true calculated SoC.

First, if the charger driver probes before the BMS and starts
charging before the BMS driver probes, the BMS will not know that
the battery is charging. Fix this by checking the charging status at
BMS driver probe time.

Second, In a previous patch, the check for SoC changes was moved in
the calculate_state_of_charge function. This can cause SoC to not be
updated and propagated into userspace at times. Fix this by checking
for SoC changes to an earlier spot in the function.

Third, while charging, the SoC can change faster than once per 20
seconds. Change this limit to 1 SoC per 5 seconds.

Change-Id: I25575b2f3e7170f69a902fd7cc731fc6f06dc06d
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: Clear fcc_count if battery removal is detected

The last_fcc_update_count tracks the updated location of the
FCC data array. Reset this variable if battery removal is
detected.

While at it, avoid FCC updates from userspace after the intial
set of FCC data tuple. Such a condition can occur if userspace
reboots/restarts.

Change-Id: I7a0eb70f73241874dab6b4c6b39795d18509f0cd
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power_supply: Add CHARGE_COUNTER_SHADOW property to power supply

Add the "CHARGE_COUNTER_SHADOW" property to the power supply
framework that signifies a shadow charge counter of the power supply.
This should be a shadowed version of the charge counter that is not
cleared automatically.
The units for this property should be in microamp-hours.

Change-Id: Ia9504a3c36af305e42d0503cf791594449249fa0
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: export shadow coulomb counter value

Export the shadow coulomb counter register value to userspace in
order to assist in recording power consumption.

Change-Id: I47ac60ce3d17e96f9cef418f5f346ba278d09521
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: improve coulomb counter shadow performance

Improve the shadow coulomb counter performance by keeping a software
shadow of it and periodically adding error compensated readings.

Change-Id: Ie549b7d0eef362f7473621de78f536173dcff09d
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: wake up when SoC changes while battery is full

Currently, the apps processor can be asleep when SoC drops below
the charging resume limit. Change this by setting the good_ocv and
cc_thr interrupts to be wakeable, and configuring the coulomb
counter threshold to be when SoC would change.

Change-Id: Ibefaf82570f875ca0ceabf0d2f693ba3e14ef595
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: use a separate flag to indicate registration

The current code uses the name of the bms power supply to indicate that
it is successfully registered. There is a time window where the name is
set but bms power supply is not registered. Interrupts executing during
this time window will call power supply apis on the bms power supply
since they see the name member initialized. These api calls on a non
registered power supply causes errors, most notably

[] (__queue_work+0x2b8/0x42c) from [] (queue_work_on+0x3c/0x44)
[] (queue_work_on+0x3c/0x44) from [] (queue_work+0x24/0x58)
[] (queue_work+0x24/0x58) from [] (btm_notify_vbat+0xb0/0x534)
[] (btm_notify_vbat+0xb0/0x534) from [] (notify_adc_tm_fn+0x98/0x154)
[] (notify_adc_tm_fn+0x98/0x154) from [] (process_one_work+0x12c/0x4b4)
[] (process_one_work+0x12c/0x4b4) from [] (worker_thread+0x160/0x3d4)
[] (worker_thread+0x160/0x3d4) from [] (kthread+0x84/0x90)
[] (kthread+0x84/0x90) from [] (kernel_thread_exit+0x0/0x8)

Update the code to not use name member and create a separate boolean to
indicate bms power supply is successfully registered.

Change-Id: I09c1d848096f4bd5de4ee4be1e0edeb100bf6113
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: qpnp-bms: Support POWER_SUPPLY_PROP_CHARGE_FULL property

This property reports the real(current) full charge capacity (FCC)
in uAh.

Change-Id: I2ebf1333a53723c4c42800b073ce464efc148e19
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: qpnp-bms: request interrupts at the end of probe

The current driver requests interrupts before it initializes other
data structures. This creates NULL pointer exceptions if an interrupt
triggers before the data structures are initialized.

Move requesting interrupts towards the end of the probe function, after
data structures are initialized.

CRs-Fixed: 506597
Change-Id: I94a524a0a1b8a5fa9372e414bcf36d8448fc1e4a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
arm/dt: 8974: Configure FCC learning parameters

Set the Full Charge Capacity (FCC) learning parameters
and enable FCC learning.

Change-Id: I7119eb60886509b8c3a40cfea8e7907386c5088c
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: qpnp-bms: Store FCC learnt data in BMS registers

BMS module supports 16 (8-bit) battery backed-up registers.
Use these registers to store the learnt FCC data. Prior to
this change, the generated FCC data was expected to be
maintained by userspace.

Every new FCC value is first interpolated to a default
temperature (this eliminates the use of storing the
temperature at which the FCC is generated). The FCC value
(in mAh) is mapped to a 8-bit value and stored accordingly.
Same encoding mechanism is used to store the charge-cycles.

Change-Id: I1f5870afbccb306cc2e54b1d539f8446c10540f6
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
power: qpnp-bms: Remove the FCC sysfs files and module parameters

The FCC data is now stored in the battery backed-up
registers in the BMS. It is not required to expose
them to userspace.

Change-Id: Id88f7ba13317a2f15ff93d9409106d84443e1c33
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
msm_fb: mdss: register mdss devices for system shutdown

When device is restarted it is necessary to power down display panel
in order to avoid any residue gliches for the next session. And in order
to power down display devices, respective drivers need to support
shutdown sequence. Implement driver shutdown for fb and mdp devices.

CRs-Fixed: 504751
Change-Id: I80acbdbb8eb9bb4999617698f7314fd8482f4403
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
msm: qpnp-power-on: Add finer control of PMIC power off type

Modify the qpnp_pon_system_pwr_off() function so that different
types of PMIC reset may be requested.  In particular, add support
so that both warm and hard reset may be used.  Warm reset
maintains the hardware state of some PMIC peripherals.  Hard
reset resets all PMIC peripherals.

Change-Id: Ibe1491acfe90364e96b776d26e158522dfea9c2b
CRs-Fixed: 507850
Signed-off-by: David Collins <collinsd@codeaurora.org>
qseecom: Fix return path of qseecom load app if app exists

Fixes the issue during the return path of qseecom load_app. If
the application is already up and running then second time load
app should return with proper error. During this process SFAB
disable clock vote is missed, which might create problem. So
this patch adds the appropriate disable call for the SFAB clock
which fixes the issue.

Change-Id: I744a923f7e08fea85ef5bada5538f1a28c52e4e7
CRs-fixed: 498153
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
qseecom: Fix issues in the return path of load external elf

Fixes the issues during the return path of qseecom load external
elf function. Improper return paths are present during the error
handling cases. Wrong goto calls results in unwanted code clean-ups
which might create problems. This patch corrects the return paths
during the error cases.

Change-Id: Icd526448e7be355acb438fff600e3e85664f75f5
CRs-fixed: 498153
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
msm: mdss: cancel or wait for the clock work to finish

The clock work has to be finished in mdp cmd stop function during adb
shell stop or suspend, otherwise, system crashes due to the unreleased
mutex lock in work queue. First, the stop_comp completion is issued
from isr, not from work queue, so that rdptr ticks can be done without
dependency on work queue, then cancel_work_sync is called to guarantee
the clk work is either cancelled or finished, and finally clk off is
called again to make sure clks are shut down.

CRs-fixed: 511249
Change-Id: Iadca3ffce7999e31e2a720a5ad6330f939b4ea98
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
arm/dt: msm-pm8110: Add PMIC PM8110 PWM device

Add PMIC PM8110 PWM device found on slave ID 1. The PWM device
does not support LUT mode, thus LUT base address is not provided.

Change-Id: I49daf510378935bb059a2b404822da3a21ce1fbb
Signed-off-by: Jay Chokshi <jchokshi@codeaurora.org>
qpnp: pwm: Add support for additional pwm sizes

The existing pwm driver only supports 6 and 9bit pwm modes. It is
a limitation to the pwm use-cases and some of the LPG channels
do not even support these PWM bit modes. Thus, add the support
for the rest of the available bit modes.

Change-Id: I09ad379358c230c2e9fbe2715bdce9cc145dd8af
Signed-off-by: Jay Chokshi <jchokshi@codeaurora.org>