pa-therm, xo_therm channels are used for reading the temperature.
Calibration type for above thermistor channels has to be absolute
for PM8950 1.0 and ratiometric for PM8950 2.0. Add version check to
detect the PMIC used and update the calibration type accordingly.
Change-Id: Ie2ab723152eb0a94a163e484c0d694e8bc327e5d
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
CHG_TEMP VADC channel used for reading the charger temperature
is not available on PMI8994 1.0. Add version check to return
an error if clients try and read this channel on the PMI8994 1.0
version.
Change-Id: I6443ca37f1312d0c4088d7ad6af01a0cdc75d3e0
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The voltage measured by the HKADC is related to the junction
temperature and scaled by the following equation
tj = -138.89degC * (v_adc * 2) + 391.75degC
Change-Id: Ibd6185c3926f9f5e482b3990adff3eee61e7caa5
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The function qpnp_vadc_check_result() checks the code against
ideal min/max for 0V and 1.8V and truncates the result within
these values. However if there is a positive offset the ADC
value can be greater than 0xA800 when applying a voltage of
1.8V. Similarly if the offset is negative the value can be
less than 0x6000 when applying 0V. Having this check can
result in incorrect ratiometric calibration if the value
read for 0V and 1.8V is outside the ideal ADC code and
the value is truncated by this function call.
Change-Id: If0c89ac4bffdea5438e256233860b2aca80e826b
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The skue is using the different battery thermistor and mapping table
from the default. A new scale function is needed to use this mapping
table in the thermal adc driver.
Change-Id: Ib154bafe821ceae33803efced3c15321a39f1dad
Signed-off-by: Chunmei Cai <ccai@codeaurora.org>
Incorrect channel readings are observed for xo_therm , pa_therm.
Changing the calibration type to absolute.
Change-Id: Ibec68b5c20206f26e1dfb4be2e02288696a64b9d
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
Add support to vote for HKADC LDO and HKADC LDO ok signal
if needed.
Change-Id: I92dcb8bf0495e93a8eaedabfbd82c3cc9a527f7c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Tcold = -20 DegC and Thot = 60 DegC are used for 8909 SKUE device.
Update battery thermistor mapping table for it.
Change-Id: Id07a66fc343c8375dd6e8ae466ff6c0e700f58cc
Signed-off-by: Chunmei Cai <ccai@codeaurora.org>
Add VBAT and OCV temperature compensation for PM8909
v1.0 SMIC parts.
The temperature compensation is required on top of
gain/offset calibration to compensate for variations
due to chip revision, manufacturer and temperature.
Change-Id: Ic0f110ed53dba314196af31c16c1fd58d20f7f1d
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
Tcold = 0 DegC and Thot = 50 DegC are used for 8909 SKUC device.
Update battery thermistor mapping table for it.
Change-Id: Ib519fe67c4ad69d2727000fae1e4f1bd181c2355
Signed-off-by: Chunmei Cai <ccai@codeaurora.org>
In VADC driver with recalibration parameter enabled and
MPP2 or MPP4 current sink configuration some ratiometric
channels report the adc code higher than maximum permitted
value.
VADC driver checks the adc code against the permitted
maximum value and overwrites adc code to permitted maximum
value if it is higher and this results into incorrect adc
readings.
Fix this problem by avoiding the adc code check when
recalibration parameter enabled.
Change-Id: Ic1bcc8b4e52cddc013cf1654c229c22fd348159e
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
Fix using the correct types when performing integer
arithmetic.
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Change-Id: I712a22d3f550efac1d059e1dd3ae933a3de84acd
Tcold = 0 DegC and Thot = 45 DegC are used for 8916 SKUT1 device.
Update battery thermistor mapping table for it.
Change-Id: I53a27c73973bb94d998485b2037d54ff833b54bd
Signed-off-by: Gustavo Solaira <gustavos@codeaurora.org>
Add separate VADC reverse scaling function to consider
the channel properties that include the pre-div scaling
for the reverse calibration on VADC channels to support
recurring channel measurement mode.
Change-Id: Ifd863c3c3fd0c3c7f93b80fac8cf186f10c69e38
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Removing redundant parameters which are not applicable
on the IADC peripheral.
Fix the issue with "fast_avg_setup" and "decimation"
parameters to configure correctly as per channel
configuration.
Change-Id: Idfe823effc6255b57e31f37621971aab29f08020
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
BTC_HOT interrupt might be triggered by glitches on BAT_THERM pin and
causes charging stopped unexpected.
Using VADC to sample the voltage on BAT_THERM pin when BTC_TEMP_OK
interrupt triggered and BAT_TEMP_STATUS is HOT. If HOT_THD is set
to 35% of the VREF_BAT_THM, and the voltage sampled on BATT_THERM
is higher than HOT_THD, override BTC VCP_DET comparator and toggle
HOT_THD setting to 25% to take charging back immediately.
CRs-Fixed: 685765
Change-Id: I83b3d2b8eb430be20418ba0b58c0eb8d7b8f22ec
Signed-off-by: Chunmei Cai <ccai@codeaurora.org>
Add support for thermistor design and mapping
table used on fsm9900 target.
Change-Id: I1c22e6a55ddb5dfcb75b69ec6f807f8c2d6b2eb8
Acked-by: Jim Granitzki <jamesg@qti.qualcomm.com>
Signed-off-by: Venkatesh Yadav Abbarapu <quicvenkat@codeaurora.org>
The skuh is using the different battery thermistor and mapping table from
the default. A new scale function is needed to use this mapping table in
the thermal adc driver.
Change-Id: I63fb02244b55b51d967b85a90cc700ef1764d20d
Signed-off-by: Jie Cheng <rockiec@codeaurora.org>
Tcold = 0 DegC and Thot = 58 DegC are used for 8916 SKUH device.
Update battery thermistor mapping table for it.
Change-Id: I37a76022d7488734924d5fe213bc86dbf0fcea07
Signed-off-by: Zhenhua Huang <zhenhuah@codeaurora.org>
Update default scaling API to support absolute and
ratiometric calibration both to convert raw adc data
to voltages.
Change-Id: I45a109d77c388564c0063d1de926813a4a929c48
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
On PM8941 depending on the status of the BATFET
the reads on channel 0 for Internal RSENSE go to
channel 5 therefore the offset is performed on that
channel. This is applicable to only to PM8941 and
not on PM8026 and PM8110. Therefore apply the check
for offset channel selection based on the BATFET
status on PM8941 only.
Change-Id: I146b244c2b562664b85e804694f8d4b2aac3fa86
CRs-Fixed: 629758
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Add reverse scaling to convert voltage in uV using absolute
calibration to raw ADC code written to set high/low threshold
for a specified BTM channel.
Change-Id: Ic56465df5ab60100cffe4303ff983480b71c0c95
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Add temperature compensation for IADC PM8026v2.2.
It shares the same temperature compensation parameters
as PM8026v2.1. The temperature compensation is required
on top of gain/offset calibration to compensate for
variations due to chip revision, manufacturer and
temperature.
Change-Id: Ic39ba249d8d28c36bf59d650dcc2c2a3889ee55b
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Since the new values of parameters including Rs1=30.3K,
Rs2=12.8K, Tcold=-15DegC and Thot=55DegC are used for
skug device, we add a new table accordingly.
Change-Id: I89d86274c5c198f904766d818cb2a7882c462496
Signed-off-by: Wu Fenglin <fenglinw@codeaurora.org>
Add check when adc calibration data are similar
for both reference channels and return error to
avoid division by zero errors.
Change-Id: Id884eb79f606fb7361fc47a96e7a6f009a113869
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
Add in support for PM8110 2.0 temperature compensation. Also, fix a few
bugs in the ADC compensation algorithm where 25C was treated as 2.5C.
Change-Id: Iafa3ceca2b5938432116ecc905dd54b2da7c4b0b
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
Update the revid check to use pr_debug instead of
pr_err to reduce potential errors to get printed.
This is an optional property as far is IADC is concerned
to apply temperature compensation for the supported chips.
Change-Id: I77036fb9f0eb640e43216762461ba036b2aa0caf
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The batt_therm connected to SMB THERM uses a
100K pull-up. This channel can also be read through
PMA8084 VADC. Add resistive divider table that
converts voltage to temperature in decidegC for the
corresponding battery thermistor.
Change-Id: I7af1c6b74a14d292c7cff37f5e9673980df67912
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Add temperature compensation parameters for PM8026 2.1.
Compensate the vbatt voltage for temperature variance above
25degC. Add similar compensation for current compensation.
Also update using the revid api's to check for PMIC revision
instead of using peripheral revision registers. Using
revid PMIC api's makes it easy to follow on what PMIC versions
are the temperature compensation being applied to. Depending
on VADC/IADC revision registers alone may not suffice since
there is no correlation between the individual peripheral
revision and the PMIC number. You could have the same
VADC revision on different PMIC's and to avoid such a scenario
use the PMIC revid.
Change-Id: I90adb1130b2e2461f762df774ddcd018e806cf78
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Since the new values of parameters including Rs1=17.8K,
Rs2=6.1K, Tcold=-5DegC and Thot=55DegC are used for
msm8610 qrd skuaa, we add a new table accordingly.
Change-Id: I14eab97a012de62cfdddf1df920ce16ac0f3561c
Signed-off-by: Xu Kai <kaixu@codeaurora.org>
Change the battery thermistor voltage under the corresponding
temperature based on the values of parameters including
R0=10.0K @ 25DegC, Rs1=13.0K, Rs2=2.1K, B=3380K, Tcold=0DegC
and Thot=45DegC.
Change-Id: Icc6957946b456be4cfecc18c92cc79db85ea215e
Signed-off-by: Xu Kai <kaixu@codeaurora.org>
Support multiple voltage ADC device instance. Clients
need to register with the voltage ADC using the device
consumer name used to associate with the corresponding
phandle of the VADC. Clients receive the device instance
which is to be used everytime an ADC request is made.
This change involves changing the interface to issue
ADC request and the corresponding clients changes.
Change-Id: If0557bc657fecd172a8cf960900ee93b4bce37f8
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
There is a possibility of potential out of bound array
access errors and uninitialized variable access from code
inspection. Add additional checks in voltage ADC and
TSENS to check for such errors.
Change-Id: I1213cd76fb636aa457c88d3bdc3740b692f01cce
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Add mapping table used for converting battery thermistor
voltage to the corresponding temperature based on
the qrd resistive divider circuit.
Change-Id: I5d3a8fd446cc59e30192485f28a9436e5517350f
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Add more die_temp debug logs and fix the units for
converting millidegC to K during reverse calibration.
Also add bound checks in the status read to prevent
spurious interrupts.
Change-Id: I888216383ae9e8aed83bc5b22b4e36499b500c11
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The qpnp adc drivers take different mutex locks one after the
other but lockdep can't figure that out because each mutex is
intialized with one call to mutex_init() in
qpnp_adc_get_devicetree_data(). Move the mutex initialization to
each caller so that lockdep can see different lock classes for
each adc mutex. This silences the below recursive mutex warning.
=============================================
[ INFO: possible recursive locking detected ]
3.4.0-gc11e688-00030-g8f5e269-dirty #567 Tainted: G W
---------------------------------------------
kworker/u:2/21 is trying to acquire lock:
(&adc_qpnp->adc_lock){+.+...}, at: [<c04c0918>] qpnp_iadc_read+0x64/0x174
but task is already holding lock:
(&adc_qpnp->adc_lock){+.+...}, at: [<c04be7f4>] qpnp_vadc_iadc_sync_request+0x34/0x198
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&adc_qpnp->adc_lock);
lock(&adc_qpnp->adc_lock);
*** DEADLOCK ***
May be due to missing lock nesting notation
6 locks held by kworker/u:2/21:
#0: (deferwq){.+.+.+}, at: [<c00a7e84>] process_one_work+0x1c8/0x528
#1: (deferred_probe_work){+.+.+.}, at: [<c00a7e84>] process_one_work+0x1c8/0x528
#2: (&__lockdep_no_validate__){......}, at: [<c0339670>] device_attach+0x18/0xa4
#3: (&chip->last_ocv_uv_mutex){+.+...}, at: [<c04b8b74>] recalculate_soc+0x190/0x124c
#4: (&iadc->iadc_vadc_lock){+.+...}, at: [<c04c0aa8>] qpnp_iadc_vadc_sync_read+0x40/0xe4
#5: (&adc_qpnp->adc_lock){+.+...}, at: [<c04be7f4>] qpnp_vadc_iadc_sync_request+0x34/0x198
stack backtrace:
[<c00140cc>] (unwind_backtrace+0x0/0x11c) from [<c00d6ea8>] (__lock_acquire+0x238/0x1784)
[<c00d6ea8>] (__lock_acquire+0x238/0x1784) from [<c00d895c>] (lock_acquire+0xf0/0x138)
[<c00d895c>] (lock_acquire+0xf0/0x138) from [<c079aa50>] (mutex_lock_nested+0x5c/0x3d8)
[<c079aa50>] (mutex_lock_nested+0x5c/0x3d8) from [<c04c0918>] (qpnp_iadc_read+0x64/0x174)
[<c04c0918>] (qpnp_iadc_read+0x64/0x174) from [<c04c0ae0>] (qpnp_iadc_vadc_sync_read+0x78/0xe4)
[<c04c0ae0>] (qpnp_iadc_vadc_sync_read+0x78/0xe4) from [<c04b6d88>] (get_simultaneous_batt_v_and_i+0x24/0x68)
[<c04b6d88>] (get_simultaneous_batt_v_and_i+0x24/0x68) from [<c04b927c>] (recalculate_soc+0x898/0x124c)
[<c04b927c>] (recalculate_soc+0x898/0x124c) from [<c04b9cfc>] (calculate_soc_work+0x10/0x4c)
[<c04b9cfc>] (calculate_soc_work+0x10/0x4c) from [<c07750f8>] (qpnp_bms_probe+0xeac/0x1228)
[<c07750f8>] (qpnp_bms_probe+0xeac/0x1228) from [<c037d6b0>] (spmi_drv_probe+0x10/0x14)
[<c037d6b0>] (spmi_drv_probe+0x10/0x14) from [<c0339884>] (driver_probe_device+0x134/0x338)
[<c0339884>] (driver_probe_device+0x134/0x338) from [<c0337d28>] (bus_for_each_drv+0x48/0x8c)
[<c0337d28>] (bus_for_each_drv+0x48/0x8c) from [<c03396d8>] (device_attach+0x80/0xa4)
[<c03396d8>] (device_attach+0x80/0xa4) from [<c0338bdc>] (bus_probe_device+0x28/0x9c)
[<c0338bdc>] (bus_probe_device+0x28/0x9c) from [<c0339144>] (deferred_probe_work_func+0x68/0xa0)
[<c0339144>] (deferred_probe_work_func+0x68/0xa0) from [<c00a7f54>] (process_one_work+0x298/0x528)
[<c00a7f54>] (process_one_work+0x298/0x528) from [<c00a83a8>] (worker_thread+0x198/0x2b8)
[<c00a83a8>] (worker_thread+0x198/0x2b8) from [<c00ad2fc>] (kthread+0x90/0xa4)
[<c00ad2fc>] (kthread+0x90/0xa4) from [<c000edcc>] (kernel_thread_exit+0x0/0x8)
Change-Id: Iebda9a8dfc407273748545bb81f91d6dc27e97cc
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Use int64_t type to while scaling the threshold values with
absolute calibration arithmetic avoid overflow errors.
Change-Id: I29d3b4ad71776a45ec1cd2c076b0f058b7bf8723
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Update the scaling function for vbatt reverse scaling
api to fix issues while performing integer operations.
Clients request the voltage in micro-volts and the
reverse scaling fix is the use the correct absolute
reverse scaling function to convert it to voltage thresholds.
Change-Id: Iea61b768daf708b4f59e5728ed1249dd60f18258
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Remove instances of EXPORT_SYMBOL_GPL from the qpnp-adc driver.
Use EXPORT_SYMBOL instead.
Change-Id: If598d64a7978af8a8c1671fec9b11b6ac81d5517
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
For battery client the warm temperature equates to a low voltage
threshold and cool temperature equates to a high voltage. Factor
it in the reverse scaling when client enters the temperature
threshold.
Change-Id: I884319bd53f4c3c563f4536a6a3462ebdf805898
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The change adds 3 additional channels and run-time
detects the supported number of channels to allow
clients to set threshold notification.
To support this, optimize the kernel api used to configure
and start a threshold monitoring request to include multiple
clients thus avoiding the need to have seperate kernel api's
for different clients. Changes are made to avoid the driver
depending on the order in which the VADC_TM DT channel
nodes should be added. Support is now included to
monitor DIE temperature for reading the pmic_therm, VBATT
and msm_thermistor scaling functions.
The change also disables the bank when an interrupt is
received or any changes are to be made in the settings,
make sure no measurements are in the queue, settings updated
and the bank is re-enabled.
Change-Id: I7a7c03857c86127dd6f1055df17099ecff4bb2f7
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
USB scaling should use ratiometric calibration when
performing reverse calibration to calculate set
thresholds written for threshold monitoring as it uses
the 100k pull-up.
Change-Id: Ic4317ecd9d69b17f11618abc66ae609b744f8d6e
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Use the 100K pull-up voltage to temperature mapping table
for xo_therm. The units returned to the user is in degC.
Change-Id: I63caac691df242d3cf8595fa161114042305e16c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Update AMUX devicetree channel node to include the reg property.
Each channel node has an index value to represent the AMUX channel
number that is used to select the corresponding analog input. The
reg property can be used to represent the above channel number
and conforms with the devicetree spec.
Change-Id: Ica53255354006ca44c57b6ca13e84fd7fb6b02de
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
The thermal monitoring QPNP ADC driver is used for
monitoring multiple channels with recurring
measurements. It configures the VADC_TM peripheral
to set voltage and temperature thresholds and
notifies clients once the thresholds are crossed.
Upto five channels can be individually configured
for input channel, interval time, low and high
threshold.
The driver is added as part of the thermal sysfs
interface to provide the thermal clients the
ability to set temperature thresholds and receive
notification. Clients can separately enable/disable
low/high temperature thresholds for notification.
Channels 3 through 5 are allocated for thermistor
channels that can be used by the thermal clients
using thermal sysfs for temperature threshold
notification.
Separate kernel api's are provided for usb_id
and batt_therm driver to set voltage and temperature
threshold notifications. TM Channels 0 and 1 are
statically mapped for usb_id and batt_therm monitoring
respectively.
Change-Id: I8de8a494d68d3b29c029fdc7d650a8b74f17a645
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>