Commit Graph

2377 Commits

Author SHA1 Message Date
Dipen Parmar b72f7f8ba1 qpnp-adc: current: Add check for rsense and calib data
Add check for rsense and calib data to avoid division by
zero errors.

CRs-fixed: 619889
Change-Id: Icf282341107905b382eb3fa34d73cf11665ca647
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2014-03-04 10:38:01 +05:30
Doug Anderson 600b64afd7 hwmon: (ntc_thermistor) Avoid math overflow
commit d3d89c468ceebbcf9423d1a3d66c5bf91f569570 upstream.

The ntc thermistor code was doing math whose temporary result might
have overflowed 32-bits.  We need some casts in there to make it safe.

In one example I found:
- pullup_uV: 1800000
- result of iio_read_channel_raw: 3226
- 1800000 * 3226 => 0x15a1cbc80

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-22 12:41:27 -08:00
Siddartha Mohanadoss 75e0057492 hwmon: qpnp-adc-voltage: Modify temperature compensation
Apply temperature compensation to minimum(die_temp, 60degC)
for vbatt compensation. For OCV temperature compensation
apply the compensation based on the die_temp for the
corresponding PMIC. The temperature compensation is
required on top of gain/offset calibration to compensate
for variations due to chip revision, manufacturer and
temperature.

Change-Id: I0826993ddebe7dae2f033d995fa1266f9509002c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2014-02-14 13:54:38 -08:00
Siddartha Mohanadoss 256b803104 hwmon: qpnp-adc-voltage: Add temperature compensation
Add VBAT and OCV temperature compensation for PM8026v2.2.
The temperature compensation is required on top of
gain/offset calibration to compensate for variations
due to chip revision, manufacturer and temperature.

Change-Id: I7c62340a74a118d6f80e4e6bba51c2d07c4a57c6
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2014-02-10 17:14:29 -08:00
Phil Pokorny 1d136c9b1e hwmon: (k10temp) Add support for Kaveri CPUs
commit d303b1b5fbb688282bbf72a534b9dfed7af9fe4f upstream.

Add new PCI ID to support new model "Kaveri" family.

Signed-off-by: Philip Pokorny <ppokorny@penguincomputing.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-02-06 11:08:14 -08:00
Siddartha Mohanadoss b69ed0a419 hwmon: qpnp-adc-current: Add temperature compensation
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>
2014-01-28 19:53:38 -08:00
Siddartha Mohanadoss 1c5e71137d hwmon: qpnp-adc-current: Fix IADC RSENSE trim error
This is a workaround for a RSENSE trim issue that may
affect some of the parts. The RSENSE might be trimmed to a
incorrect value resulting in an incorrect current value.
The workaround will check if the trim values stored in the
registers are valid and if not use a default RSENSE value.

CRs-Fixed: 606553
Change-Id: I8d77a2c6c28e57f2e537d1c5b65d0e08d5fabd90
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2014-01-28 19:32:01 -08:00
Jean Delvare 02cb5b6b8b hwmon: (coretemp) Fix truncated name of alarm attributes
commit 3f9aec7610b39521c7c69d754de7265f6994c194 upstream.

When the core number exceeds 9, the size of the buffer storing the
alarm attribute name is insufficient and the attribute name is
truncated. This causes libsensors to skip these attributes as the
truncated name is not recognized.

Reported-by: Andreas Hollmann <hollmann@in.tum.de>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-25 08:27:11 -08:00
Linux Build Service Account d59ca464e6 Merge "hwmon: epm_adc: Add debug logs" 2013-12-26 18:48:05 -08:00
Linux Build Service Account ba446430bd Merge "hwmon: epm_adc: Add configurable global GPIO enable" 2013-12-26 18:48:05 -08:00
Siddartha Mohanadoss 147337d89b hwmon: epm_adc: Add debug logs
Add Version and firmware debug logs during initialization.

Change-Id: I3ded6b8a141a1b20b155309df5cac42fd76b9471
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-12-26 14:41:41 -08:00
Siddartha Mohanadoss a5b117f24f hwmon: epm_adc: Add configurable global GPIO enable
Embedded power monitor (EPM) PSoC is powered through a GPIO.
Add a property to pass the GPIO to the driver since this
the global enable for the EPM varies from target to target.

Change-Id: I731302f9ab33c216f5794721a4d36ee20fb261ec
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-12-26 14:41:41 -08:00
Wu Fenglin 00b02e95f4 hwmon: qpnp-adc: add battery thermistor mapping table for skug
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>
2013-12-26 11:52:44 +08:00
Jean Delvare a903818b46 hwmon: (w83l768ng) Fix fan speed control range
commit 33a7ab91d509fa33b4bcd3ce0038cc80298050da upstream.

The W83L786NG stores the fan speed on 4 bits while the sysfs interface
uses a 0-255 range. Thus the driver should scale the user input down
to map it to the device range, and scale up the value read from the
device before presenting it to the user. The reserved register nibble
should be left unchanged.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 07:45:08 -08:00
Brian Carnes d6eb2d04bb hwmon: (w83l786ng) Fix fan speed control mode setting and reporting
commit cf7559bc053471f32373d71d04a9aa19e0b48d59 upstream.

The wrong mask is used, which causes some fan speed control modes
(pwmX_enable) to be incorrectly reported, and some modes to be
impossible to set.

[JD: add subject and description.]

Signed-off-by: Brian Carnes <bmcarnes@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 07:45:07 -08:00
José Miguel Gonçalves d4fa5279d7 hwmon: HIH-6130: Support I2C bus drivers without I2C_FUNC_SMBUS_QUICK
commit efabcc2123f0ed47870033b8d6fc73b50d76d635 upstream.

Some I2C bus drivers do not allow zero-length data transfers which are
required to start a measurement with the HIH6130/1 sensor. Nevertheless,
we can overcome this limitation by writing a zero dummy byte. This byte
is ignored by the sensor and was verified to be working with the OMAP
I2C bus driver in a BeagleBone board.

Signed-off-by: José Miguel Gonçalves <jose.goncalves@inov.pt>
[Guenter Roeck: Simplified complexity of write_length initialization]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 07:45:07 -08:00
Dan Carpenter 223cc81c8c hwmon: Prevent some divide by zeros in FAN_TO_REG()
commit 3806b45ba4655147a011df03242cc197ab986c43 upstream.

The "rpm * div" operations can overflow here, so this patch adds an
upper limit to rpm to prevent that.  Jean Delvare helped me with this
patch.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Roger Lucas <vt8231@hiddenengine.co.uk>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 07:45:07 -08:00
Dipen Parmar add0879f00 hwmon: qpnp-adc: Add check for wrong calib data
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>
2013-12-18 18:02:30 +05:30
Xiaozhe Shi df7598c474 hwmon: qpnp-adc-current: log the compensation coefficients
The compensation coefficients are used to execute performance tests.
Provide this information in the debug logs of the IADC driver.

Change-Id: I59df9501d8edf652c6cf0999a17cc820115b07cc
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
2013-12-03 13:45:48 -08:00
Guenter Roeck 598f412c2f hwmon: (lm90) Fix max6696 alarm handling
commit e41fae2b1ed8c78283d73651cd65be0228c0dd1c upstream.

Bit 2 of status register 2 on MAX6696 (external diode 2 open)
sets ALERT; the bit thus has to be listed in alert_alarms.
Also display a message in the alert handler if the condition
is encountered.

Even though not all overtemperature conditions cause ALERT
to be set, we should not ignore them in the alert handler.
Display messages for all out-of-range conditions.

Reported-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-11-29 11:11:50 -08:00
Linux Build Service Account a5b0c890bc Merge "hwmon: qpnp-adc-current: Fix potential race condition" 2013-11-25 13:51:57 -08:00
Siddartha Mohanadoss 83759a96fd hwmon: qpnp-adc-current: Fix potential race condition
There should be no synchronous Voltage and Current readings
initiated on IADC_USR when a single VADC_USR conversion is
in progress. If a synchronous Voltage and Current read
occures while a VADC_USR is in progress it results in an
invalid state for that single conversion on the VADC_USR.
There is a potential race condition where the above scenario
can occur that is due to an IADC conversion occuring before
the VADC_IADC USR sync conversion is complete and ends up
using the mode select as a VADC_IADC sync request.
Therefore use a single lock for both IADC and
synchronous VADC_IADC request.

Change-Id: Idb451b813bc5f08b7239d371fc0f8fa5e17429b1
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-11-25 09:42:29 -08:00
Linux Build Service Account 62dd845652 Merge "hwmon: epm_adc: Add 16 bit buffering and generic support" 2013-11-22 21:10:50 -08:00
Siddartha Mohanadoss 71faee8b90 hwmon: epm_adc: Add 16 bit buffering and generic support
Add support to return 16bit results for averaging buffering
command. This allows additional channels to be measured.
The generic command allows clients to send requests that
are supported by the PSoC. In addition fix the marker
gpio numbers between the marker 1 and marker 2 that are
flipped.

Change-Id: I2bf87ceb8fa9fa633ab6d082b12f66c77a374d34
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-11-22 11:24:13 -08:00
Ian Maund f06163e6d0 msm: reap unused kernel files
This change removes source files from the kernel tree that
were not being used during make. The list of used files
was generated using an annotated make log and was then
compared with new files added since the public release of
kernel version 3.10.00. New files which were added but
not used have been removed from the tree.

A diff was also run to determine the list of files that had
been modified since the release of kernel version 3.10.00.
These files were then scrubbed based on the current kernel
configuration, removing invalid and unused conditionals.

Some files which support planned functionality or are
useful in debugging have been excluded from this reap.

Change-Id: Ia44a224d3cea7bc78dd45e8a8279860d35d4b008
Signed-off-by: Ian Maund <imaund@codeaurora.org>
2013-11-21 17:45:28 -08:00
Xiaozhe Shi ee8fec3522 hwmon: qpnp-adc-current: fix current compensation direction
Currently the current compensation in the IADC driver is using the wrong
polarity. The compensation function is treating the current with the
battery being the source (i.e. discharging is positive and charging is
negative), but the IADC's IBAT readings treat the battery as a sink
(i.e. charging is positive and discharging is negative).

Fix this by reversing the sign of the iadc current readings before doing
compensation.

Change-Id: I1413ce491b1f430b6a78bfc480174321c512e289
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
2013-11-12 14:55:49 -08:00
Xiaozhe Shi 6c5843508e hwmon: qpnp-adc: add PM8110 2.0 temperature compensation info
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>
2013-11-12 14:55:43 -08:00
Siddartha Mohanadoss b8e1e4f4de hwmon: qpnp-adc-common: Reduce kernel error prints
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>
2013-10-24 15:51:06 -07:00
Henrik Rydberg 8c27969472 hwmon: (applesmc) Always read until end of data
commit 25f2bd7f5add608c1d1405938f39c96927b275ca upstream.

The crash reported and investigated in commit 5f4513 turned out to be
caused by a change to the read interface on newer (2012) SMCs.

Tests by Chris show that simply reading the data valid line is enough
for the problem to go away. Additional tests show that the newer SMCs
no longer wait for the number of requested bytes, but start sending
data right away.  Apparently the number of bytes to read is no longer
specified as before, but instead found out by reading until end of
data. Failure to read until end of data confuses the state machine,
which eventually causes the crash.

As a remedy, assuming bit0 is the read valid line, make sure there is
nothing more to read before leaving the read function.

Tested to resolve the original problem, and runtested on MBA3,1,
MBP4,1, MBP8,2, MBP10,1, MBP10,2. The patch seems to have no effect on
machines before 2012.

Tested-by: Chris Murphy <chris@cmurf.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-18 07:45:44 -07:00
Siddartha Mohanadoss acec6c4e3c hwmon: qpnp-adc: Add smb batt_therm mapping table
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>
2013-10-11 11:14:46 -07:00
Siddartha Mohanadoss e17597ed0d hwmon: qpnp-adc-current: Add temperature compensation
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>
2013-10-08 16:01:02 -07:00
Henrik Rydberg 332769e13b hwmon: (applesmc) Check key count before proceeding
commit 5f4513864304672e6ea9eac60583eeac32e679f2 upstream.

After reports from Chris and Josh Boyer of a rare crash in applesmc,
Guenter pointed at the initialization problem fixed below. The patch
has not been verified to fix the crash, but should be applied
regardless.

Reported-by: <jwboyer@fedoraproject.org>
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-05 07:13:12 -07:00
Wei Hu c2fcdfd1a9 hwmon: (k10temp) Add support for Fam16h (Kabini)
commit 30b146d1cb5e7560192057098eb705118bd5511f upstream.

The temperature reporting interface stays the same, so we just
add the PCI-ID to the list.

Verified on AMD Olive Hill.

Signed-off-by: Wei Hu <wei@aristanetworks.com>
Acked-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-09-07 22:09:59 -07:00
Siddartha Mohanadoss 7f4e53a430 hwmon: qpnp-adc-current: Fix temperature compensation overflow
Fix the temperature compensation overflow that can occur when
using external rsense. Also fix the corresponding units for
coefficient on PM8941 3.1.

Change-Id: I9b27b54c606482fa42928f79460c3ae7ceb693b3
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-05 14:54:34 -07:00
Siddartha Mohanadoss d15a5f973b hwmon: qpnp-adc: Fix panic in ADC workqueue
During warm/soft reset it is seen during qpnp-adc-tm
driver interrupt registration there are pending
interrupts.

Register the ADC interrupt handler after initializing
the workqueue to handle potential cases where interrupt
is pending when an interrupt is requested and causes
panic because the workqueue is called when its not
initialized yet.

Change-Id: Iba88ab3c9f71dc94579ab85980f8cfd726f3c5c1
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-05 14:52:37 -07:00
Siddartha Mohanadoss 6299618686 hwmon: qpnp-adc-scale: Fix batt_therm mapping table
Mapping table for batt_therm used for converting voltage
to temperature is incorrect after 65degC. Fix the voltage
to temperature mapping for values after 65degC.

Change-Id: Ib8534a2be3b66f61b4edbe8f283cfee9f873af81
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:29:16 -07:00
Siddartha Mohanadoss a3d5f9ee18 hwmon: qpnp-adc-current: Fix current resolution units
Existing units returned for IADC current is in mA when
using external rsense. Fix it to return the units in uA
to keep it consistent with current read from internal rsense.

Change-Id: Ia9792ea4d894500829011db5510363b4e6e14616
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:28:42 -07:00
Siddartha Mohanadoss 3906a96b21 hwmon: qpnp-adc-voltage: Add temperature compensation
The VADC does not meet VBAT and OCV accuracy spec with just
gain and offset calibration. Additional compensation is required
on top of gain/offset calibrated reading to compensate for
variations based on chip revision, manufacturer and tempreature.

Change-Id: I9e08987ac39ac8de8e880b96bee4f8bc76a88e46
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:20:06 -07:00
Siddartha Mohanadoss 4ec9647cd2 hwmon: qpnp-adc-current: Add temperature compensation
The IADC does not meet accuracy spec with just gain
and offset calibration. Additional compensation is
required on top of gain/offset calibration to compensate
for variations due to chip revision, manufacturer and
temperature.

Change-Id: If69ec412b05746e49e98fff761a70cd987bd6f7e
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:20:05 -07:00
Siddartha Mohanadoss ca4e012922 hwmon: qpnp-adc-current: Fix error path
Invalid jump to cleanup before the hwmon device
is registered. Cleanup the error path to avoid
panic if a failure occurs before hwmon device
register occurs.

Change-Id: I3477d207dc6402bed33d15723f2763ee85a1ca46
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:17:37 -07:00
Xu Kai 2983a75b71 hwmon: qpnp-adc: add battery thermistor mapping table for msm8610 qrd skuaa
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>
2013-09-04 17:17:10 -07:00
Xu Kai f110b4ab2d hwmon: qpnp-adc: modify qrd battery thermistor mapping table
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>
2013-09-04 17:17:08 -07:00
Siddartha Mohanadoss 147a6b4301 hwmon: qpnp-current: Add configurable EOC option.
Provide a DT property qcom,iadc-poll-eoc option to
allow clients to choose between using interrupt or
polling method for end of conversion interrupt.
When the optional property is present, use polling
when an ADC conversion is requested.

Change-Id: I2c62a9f8e30f5c1200d439343f0548212977b731
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:16:38 -07:00
Siddartha Mohanadoss 5abeea8be3 hwmon: qpnp-vadc: Add EOC polling option
Add a DT property qcom,vadc-poll-eoc option to allow
clients to use either interrupt mode or polling mode
for end of conversion request. The DT property is a
optional property to specify polling. If this property is not
present default to use interrupt mode.

Change-Id: I16f3677a24200b80dc5a8535a98ec4a44158302c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:16:36 -07:00
Xiaozhe Shi 27c40bec84 hwmon: qpnp-current: Use ideal gain for PM8026
The IADC on PM8026 has been found to have improved accuracy if the
gain compensation is removed from the conversion equation. Implement
this in the IADC driver by faking a gain read of offset + ideal gain
during calibration.

Change-Id: I85abf713e796666946674e5ae603c918cfa9ae5a
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
2013-09-04 17:16:18 -07:00
Siddartha Mohanadoss cc6f8b40e6 hwmon: qpnp-current: Support multiple instance
Support multiple instance of the IADC device. Clients
need to register with the current ADC using the device
consumer name used to associate with the corresponding
phandle of the IADC. 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: I51423395ed7282669ca7fbc7dc585e0292417e71
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:15:08 -07:00
Siddartha Mohanadoss 000325beb7 hwmon: qpnp-voltage: Support multiple device instance
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>
2013-09-04 17:14:32 -07:00
Abhijeet Dharmapurikar e672d0d48a power: qpnp-bms: implement workarounds for coupling issue
On certain PMICs there is a coupling issue which causes bad calibration
values that reports a high current value even when the BATFET is open.
This coupling issue happens regardless of an internal/external rsense
configuration.

The suggested workaround is to repeatedly calibrate until we get values
that result in less than 3mA of current.

Expose the BATFET open/closed as battery's ONLINE property. It is
reasonable use of this property since PRESENT suggests a battery is
actually present in the device and ONLINE suggests if it is connected to
the system via BATFET.

The BATFET can open when a charger is present and
* the battery is fully charged
* the battery is hot/cold
(Note that if charger is disabled the buck will not operate
and we don't have coupling issue)
The fully charged notifications trickle down to BMS driver,
since battery psy supplies to "bms", use it to check if the
BATFET has opened.
The hot/cold interrupt is not yet registered to, add it so we can notify
the BMS driver if the battery goes hot or cold. Since the battery can
go hot or cold while the device is sleeping, we need to wakeup for
calibration workaround.

The BATFET can close when
* the charger is removed
* the battery recovers form hot/cold conditions when charger is present
These notifications too trickle down to the BMS driver and can be used to
check if the BATFET has closed.

Also once good calibration values are detected above use them until BATFET
closes i.e. do NOT calibrate until the BATFET closes. Update the code
that periodically calculates SOC to skip calibrations as long as BATFET
is open. On the same lines ask the iadc driver to skip auto calibrations
until BATFET closes.

CRs-Fixed: 509620
Change-Id: I89b521368304d7171d75e462cf15f2f1daa55cdc
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2013-09-04 17:13:46 -07:00
Abhijeet Dharmapurikar 25ca2ccfde hwmon: qpnp-current: specify batfet status while calibrating
For internal Rsense or external Rsense, when current is requested by
BMS while battery fet (BATFET) is open, IADC switches to channel 5
even though channel 0 or channel 1 was requested. This is done so that
it returns the same value as offset calibration would have returned
resulting in 0mA of current.

This is okay for external Rsense since offset calibrations are done on
channel 5 which measures across same pins as those used for current
readings.

However this results in incorrect offset values for internal Rsense
because the offset calibrations happens on channel 6 which uses
different pins than channel 5.

Update the code to specify whether a calibration is being requested
while the battery fet is open. If it is open then use channel 5 for offset
calculations even when internal Rsense is used.

Change-Id: I1b36ea1d5dd078b177d6c5a92d7c49e8402c36dc
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2013-09-04 17:12:54 -07:00
Abhijeet Dharmapurikar 0ed4075cb8 hwmon: qpnp-current: fix converting offset and gain to voltage
The current driver forces a value of 0uV for offset and always
lands up with 17.857mV for gain. The raw values for offset and
gain are correct however.

Update the driver to do a proper conversion of raw offset and
gain to values in microvolts.

Change-Id: I19eda7a4f0cc8ab6af0d31e01e1168d99f00bf7a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2013-09-04 17:12:53 -07:00
Siddartha Mohanadoss ba41c92558 hwmon: epm_adc: Add pause and unpause commands
Pause/unpause commands can be issued when clients want
to use buffered averaging and would like to pause the
psoc from filling the buffer with samples to avoid
overflow.

Change-Id: I60c184a62d432a41960c6f76d7356667f35bdf92
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:10:40 -07:00
Siddartha Mohanadoss 6520dd6c53 hwmon: epm_adc: Add gpio buffer commands
Add support to set requests to monitor gpio commands
such as markers and supported PSOC gpio functionality.

Change-Id: I4be00b4330f68e683912412bcf84dd801997eafc
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:10:38 -07:00
Siddartha Mohanadoss 166c415666 hwmon: qpnp-adc: Fix potential errors
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>
2013-09-04 17:09:55 -07:00
Siddartha Mohanadoss 1f7e6df1b2 hwmon: epm_adc: Add init/de-init support
Add support to have clients call the de-init of the PSOC
device which disables the EPM GPIO used to power up
the device. When clients call the Init ioctl call the
gpio request to enable the device.

Change-Id: Ifa2e165cb0297728b128aece14e0fea3d314749a
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:08:59 -07:00
Siddartha Mohanadoss e838122faf hwmon: epm_adc: Add Marker support
Clients can request start/stop markers and perform
current measurement. Support is added to request a
marker and set a desired level. When client
has finished it needs to call release for freeing
the gpio.

Change-Id: I3e805352a8c4cd56e616f76fc77e8fb7fa97fb50
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:08:58 -07:00
Siddartha Mohanadoss 27943b2ed5 hwmon: qpnp-current: Update offset channel selection based on rsense
Use the appropriate offset channel based on whether
the rsense is external or internal.

Change-Id: I573571653c6cee41fa396a2fd123641cdcf085d6
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:08:43 -07:00
Stepan Moskovchenko c47f5bc2c8 hwmon: qpnp-vadc: Fix probe error paths
Execute the complete probe failure path in the event that
QPNP VADC registers could not be read, to prevent a
use-after-free scenario with the qpnp_vadc data structure.

Change-Id: Ib22faded23d9bc5939f1481bfcd21f7235699b16
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2013-09-04 17:04:15 -07:00
Siddartha Mohanadoss 21478a1435 hwmon: qpnp-adc-current: Fix setting external rsense
The iadc compensation uses the external/internal rsense
as one of the parameters for compensating the values
for current. Currently it defaults to internal rsense.
Fix this by updating the compensation rsense parameter
based on the inputs from the DT whether its internal
or external rsense.

Change-Id: Id931e20915967f410b16174eb2484377fbc858f3
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 17:03:13 -07:00
Siddartha Mohanadoss 42a5ed507a hwmon: epm_adc: Fix clear buffer command
Currently when clients request to clear the PSOC buffer
the result returned to the user is not valid. This is
because the response byte that indicates the status
of the PSOC is the second byte and not the third.
Fix it by reading the appropriate byte to indicate
the status of the command request.

Change-Id: I1604274619bb881ecc2e0afc46979ae4eb85a154
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:58:12 -07:00
Siddartha Mohanadoss 898cf5a8f2 hwmon: epm_adc: Update timestamp commands
Provide a seperate ioctl interface for obtaining and
setting the PSOC timestamp. Currently we rely on the
clients to set the get/set timestamp command within
the PSOC request command. Unlike other commands
which are obvious, this particular command relies
on the clients. Therefore seperate the command
so that it is obvious and a cleaner approach.

Change-Id: I71915a3e58751cf7c0a961b062c7c06948658e09
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:58:10 -07:00
Siddartha Mohanadoss f3d1e0b742 hwmon: qpnp-adc-current: Fix external rsense value
When external rsense is selected the api used to
calculate the rsense needs to return back. Instead
it recalculates the rsense using the trim procedure
used for calcuating the internal rsense. Fix it
by returning the value that is used for the external
rsense.

Change-Id: Icde61ca2c95d1b4ab64d9f6db2fc97ac4e47daab
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:45:12 -07:00
Siddartha Mohanadoss a11187ad24 hwmon: qpnp-vadc: Set peripheral warm reset
It is seen on certain conditions during bootup the end
of conversion interrupt is latched and this causes the
VADC to never receive the end of conversion interrupt.
This causes the clients to experience delays when requesting
an ADC request and on certain scenario during a soft reset
condition delays bootup.

qpnp-int expects the peripheral interrupt registers to be
in a known state. If an interrupt occured and is not
handled correctly it could lead to the interrupt being
latched and subsequent interrupts are never handled.

Each qpnp peripheral has an option to reset the peripheral
when a warm reset occurs to reset the peripheral to its
power on reset state. Set the VADC peripheral reset register
to enable resetting the peripheral during a warm reset.

Change-Id: Ic59726d327bf93900011d6f7051b2967ed0eae87
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:36:34 -07:00
Xiaozhe Shi 55f578e804 hwmon: qpnp-adc: fix iadc compensation for pmic 3.0
With PMIC 3.0, the iadc compensation scheme will return 0 current
because of an conversion bug. Fix this in the iadc driver.

Also, the iadc driver was incorrectly assuming GF as the fab. Remove
this from the compensation scheme.

Finally, when the ADC revision is unsupported, simply do not
compensate.

Change-Id: I8d4ec7bfe7e125bd18da9dba5d78f988ffaea515
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
2013-09-04 16:35:05 -07:00
Siddartha Mohanadoss f1975ed6a1 hwmon: qpnp-adc: Add current and vbat compensation
Compensate the vbatt voltage for temperature variance
above 25degC. The vbatt readings improve with voltage
compensation based on the revision. Similar compensation
is applied to current which are based on the internal
or external rsense and the revision.

Change-Id: I3df8b918e6247041d651a0c9d819d77cc6af978c
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:33:21 -07:00
Siddartha Mohanadoss 4b6caea204 hwmon: qpnp-adc: Add battery thermistor mapping table
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>
2013-09-04 16:28:24 -07:00
Siddartha Mohanadoss 2df33bd969 hwmon: qpnp-adc: Use buffered 625mV reference channel
Use channel 0xc to read the buffered 625mV reference
channel during calibration if it exists. The channel
may not exist on all the PMIC versions. If the channel
is supported in the PMIC add it as a channel in the
VADC DT channel node.

Change-Id: I49b54e161538f075fcd89ed9beb7ffbdd8034a87
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:27:17 -07:00
Siddartha Mohanadoss 08501a45d1 thermal: qpnp-adc-tm: Add die_temp debug logs
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>
2013-09-04 16:26:16 -07:00
Stephen Boyd a947a2fa21 hwmon: qpnp-adc: Initialize adc mutex in each driver
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>
2013-09-04 16:25:59 -07:00
Siddartha Mohanadoss 691cfcfd09 hwmon: qpnp-adc-common: Fix setting reverse vbatt values
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>
2013-09-04 16:24:13 -07:00
Siddartha Mohanadoss f4b756bca1 hwmon: qpnp-adc-current: Update die_temp read
Instead of reading the die_temperature every time
perform calibration only if the die_temperature between
the previous calibration was greater than 5degC. It is
fine to perform calibration but is unnecessary to perform
it for every other read.

Change-Id: I2f819044395b37dd4aa906b3711a9de068260b3f
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:22:58 -07:00
Siddartha Mohanadoss 4a013d6b08 hwmon: qpnp-adc: Modify rsense parameter
Add support to read external rsense. We have an
existing DT property to pass the external rsense
value. Modify it as an optional property and when
present use it determine using the external rsense
and the corresponding value for computing the current.

Change-Id: Ie372bd25687b49d399f91bfcb803c669087655f0
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:22:57 -07:00
Siddartha Mohanadoss 27a2b33838 hwmon: qpnp-adc-current: Fix IADC current units
At low current values, not using the correct units
for scaling the voltage and dividing it by the appropriate
units for rsense causes incorrect resolution in units for
current. Fix it by using the correct units.

Change-Id: Ia76382268b69db194f5f17f5a129140e75d66298
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:18:16 -07:00
Siddartha Mohanadoss cd71d2646a hwmon: qpnp-adc-current: Add init_completion
Initialize the completion before requesting a
conversion. This is to avoid cases where we might
miss the completion and rely on the timed wait which
would cause slight delay before returning the result
to the client.

Change-Id: I49b635699c3432ca8363d68493ea02e17f7c6c64
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:17:58 -07:00
Siddartha Mohanadoss df2ad43ead hwmon: qpnp-adc: Fix blocking call at qpnp_vadc_calib()
Fix issue when a call to qpnp_vadc_calib() does not
return due to the end of conversion status bits not
being set. Add a count check while reading the status
registers instead of waiting forever till the end of
conversion bits get set. Also make changes in the IADC
driver to schedule work for calibration when there
are no errors. Previously we wanted to give a couple
of re-tries but once the calibration error occurs we
have seen it fail continously so there is no need to
have retries.

Change-Id: I5f994f38fbeb0a044146174d4189b1cd95fd040e
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:17:12 -07:00
Siddartha Mohanadoss 6ea00c94ac hwmon: qpnp-adc-common: Fix vbatt reverse scaling
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>
2013-09-04 16:15:53 -07:00
Siddartha Mohanadoss 4b7be4dcc4 hwmon: qpnp-adc-current: Export calibration api
Currently calibration is performed every 5 minutes. Provide
an option to the clients to request for IADC re-calibration.

Change-Id: Ia66866610e0702dc25d4235608d123b2e0bf8004
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:15:02 -07:00
Siddartha Mohanadoss a232715673 hwmon: qpnp-adc: Use EXPORT_SYMBOL
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>
2013-09-04 16:14:57 -07:00
Siddartha Mohanadoss e5dbb07a15 hwmon: qpnp-adc: Add debug information
Add IADC gain, offset and rsense information for debug.
Also add VADC reference channel debug information.

Change-Id: Ice81d8ce8d4b725b3e5cbef33159a3bdd69dd621
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:14:18 -07:00
Siddartha Mohanadoss 6fe3a4edab hwmon: qpnp-adc-tm: Modify the btm scaling function
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>
2013-09-04 16:13:43 -07:00
Siddartha Mohanadoss 0194e1fc25 hwmon: qpnp-adc-tm: Optimize and add more TM channel support
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>
2013-09-04 16:13:28 -07:00
Siddartha Mohanadoss 0c040d1a73 hwmon: epm_adc: Fix reporting large current values
The A/D code from the PSOC can report negative values.
Use the correct typecast and treat the code as an int
to report low negative current readings. Currently we
treat the results as an uint and the value gets reported
as a huge value for low negative current readings.

Change-Id: I754f08e83b4664b72d33725f0d9227774d9896af
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:08:47 -07:00
Siddartha Mohanadoss 9bd0210c96 hwmon: qpnp-adc-current: Add div0 error checks during calibration
Add error checks to avoid div0 condition during periodic
gain/offset calibration and print more debug info
of the gain and offet while we are here.

Change-Id: I2b8431efa21eb9fe685455286f32fc825b924bee
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:02:40 -07:00
Siddartha Mohanadoss ea8bd95fbb hwmon: qpnp-adc-current: Perform trim update after init
Perform calibration to update trim immediately after
initialization to utilize interrupts as opposed to
performing it as part of driver initialization and
rely on polling. This improves the boot time. Also
add additional checks to ensure driver is initialized
before reading from rsense.

Change-Id: Ibfea3aa67abf86559830d85cb70a722168848a84
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 16:01:43 -07:00
Siddartha Mohanadoss d723136ed5 hwmon: qpnp-adc: Ratelimit periodic calibration on error
Ratelimit the calls to do IADC periodic calibration based
on the error count. Once the IADC locks-up performing a
periodic calibration does not help. Ratelimit it to avoid
kernel buffer overflow with the IADC error logs.

Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Change-Id: I5e24854727a513758f40bbdf18ea6b1147d7e569
2013-09-04 15:59:37 -07:00
Siddartha Mohanadoss 6f14f24cce hwmon: qpnp-adc: Add synchronous vadc and iadc api
Support simultaneous voltage and current ADC request
to read vbatt and battery current. The IADC peripheral
issues the simultaneous VADC/IADC sync request. The
VADC peripheral is first prepared to issue an voltage
ADC request but does not request the conversion. The
IADC peripheral sets its conversion request and issues
an ADC request for simultaneous read. The api is
intended to be used by the BMS.

Change-Id: I978db99662313d7344bd2e4c8534f23cab398011
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:59:36 -07:00
Siddartha Mohanadoss ba2c302212 hwmon: qpnp-adc-common: Fix usb scaling
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>
2013-09-04 15:55:41 -07:00
Xiaozhe Shi 0df5a5f83e power: qpnp-bms: Implement RDS resistance reading
Up until now, qpnp-bms did not actually support using internal
rsense. When configured to use internal rsense, the BMS driver would
simply use the external rsense value provided in place of the RDS
resistance.

Implement reading the RDS resistance from the IADC at BMS probe time,
and save it as the canonical rsense resistance value. Also, expose
the IADC function qpnp_iadc_get_rsense to facilitate reading the iadc
rsense trim registers.

Change-Id: Iab0834e6228c0263cd055bdf6ac5c2561a375a85
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
2013-09-04 15:49:19 -07:00
Dipen Parmar 85dd8d5bca hwmon: pm8xxx-adc: Update get_adc() to print signed int64_t values
In pm8xxx-adc.c file get_adc() is printing wrong values for signed int64_t.
Fix it by replacing format specifier from %llu to %lld in attribute macro
for get_adc.

Change-Id: I3a9fd86fb52b1a79acf586a0c88613f397cb59b4
CRs-Fixed: 435666
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2013-09-04 15:47:32 -07:00
Dipen Parmar bce1ad8caf hwmon: pm8xxx-adc-scale: Update XO thermal table and scaling function
XO Therm channel of adc driver is printing +ve temperature values on
actual -ve temperature.Fix it by updating scaling function and mapping
table for XO Thermistor.

Change-Id: Ie7443251f4cfbd756848b92d94ff67f0322f5e26
CRs-Fixed: 435666
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2013-09-04 15:47:32 -07:00
Siddartha Mohanadoss 7a007578df hwmon: qpnp-adc-common: Update xo_therm scaling function
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>
2013-09-04 15:46:40 -07:00
Siddartha Mohanadoss cfd0780b38 hwmon: qpnp-adc: Set correct adc_drv to NULL
Fix setting the correct adc_drv to NULL on error path during
probe.

Change-Id: I7923f79b65cc6303a1a31429287fcef356522d68
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:46:39 -07:00
Siddartha Mohanadoss d894733d97 hwmon: qpnp-vadc: Hold a lock during calibration
Calibration is performed during the first read request.
Have a lock around the calibration function to avoid
race condition of running into a scenario if two clients
issue an ADC request at the same time.

Change-Id: I0f7d0978da0179937b2d4699b4402c8666482cd0
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:45:56 -07:00
Siddartha Mohanadoss ea53aa03d6 hwmon:qpnp-adc: Set adc_drv to NULL on error
Set the adc_drv to NULL during probe error before
we exit. Not setting the adc_drv to NULL can cause
panic on conditions when adc requests are made when
an error occured during probe. Fix it by setting the
adc_drv to NULL since we have checks in the adc read
requests. Also add the adc_drv is valid check in the
work scheduler to ensure against conditions of
receiving an interrupt immediately when a irq_request
is made during probe initialization.

Change-Id: I5d921a67306bb9e401dbe798599c200d9f8eed28
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:45:55 -07:00
Siddartha Mohanadoss a5abe352f0 hwmon: qpnp-adc-voltage: Add debug status api
Collect status information from the VADC peripheral when
the end of status conversion bit is not set.

Change-Id: If73c78eb3105cdf116aac69361bc9944c561918c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:45:54 -07:00
Siddartha Mohanadoss eeb4da41b1 hwmon: qpnp-adc-current: Disable IADC bank on the error path
Disable the IADC bank on the error path. If the end of conversion
bit is not set some of the status registers are collected. After
collecting them, disable the bank to avoid keeping the bank
enabled all the time. The bank is disabled on the success path
when the result is read.

Change-Id: Ie3e7497bc4b1497e5db5c7b4374debaf8dbd9f5c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:45:54 -07:00
Siddartha Mohanadoss 85cd4b4412 hwmon: epm_adc: Add psoc voltage scaling
For voltage channels the psoc uses a 12 bit ADC. For current
channels a 16 bit ADC is used with the sign bit. Use the
channel mask to determine the channel scaling being performed
is for a voltage channel and scale the result appropriately
for voltage and current channel.

Change-Id: I7e238dd6ed0de6bcfaaf4186eaa3770de43d254f
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:44:03 -07:00
Siddartha Mohanadoss 4d46b40b02 hwmon: qpnp-adc: Remove exporting qpnp_vadc_configure api
qpnp_vadc_configure() api should be a static function and
used only by the qpnp vadc driver. Remove exporting it to
avoid clients using it directly.

Change-Id: I8ccc9b286a76be5dcad21c11bce57f2c59d286e5
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:44:02 -07:00
Siddartha Mohanadoss 61e1acf051 hwmon: qpnp-adc-voltage: Verify channel being read
Add channel verification to check for valid channel being
read from the voltage ADC configuration list.

Change-Id: I2e9fef065088bd4e5b9e3c6715c83c140b5b2555
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:44:02 -07:00
Siddartha Mohanadoss 7945e67c81 hwmon: qpnp-adc: Update mode register to set trim
The trim bits are set in the mode control registers
to improve reading accuracy.

Change-Id: I1efcb8450cab055c4c4410f78e349f9e3c664319
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:44:00 -07:00
Siddartha Mohanadoss b9934e231f hwmon: qpnp-adc-current: Add debug status api
Add debug api to printout the status registers when
the end of conversion interrupt is not received.

Change-Id: Id1647154e8288f7e34c5fae830da249823c7b7d8
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:44:00 -07:00
Siddartha Mohanadoss a54f59cdb0 arm/dt: Update AMUX channel number property
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>
2013-09-04 15:43:26 -07:00
Siddartha Mohanadoss 758a9c329c thermal: qpnp-adc: Add thermal monitoring ADC driver
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>
2013-09-04 15:43:25 -07:00
Siddartha Mohanadoss b21897298e hwmon: epm_adc: Update sysfs channel names
Update the channel name listing from ADS to PSOC.
The newer EPM uses PSOC, therefore update the string
names to accurately reflect the underlying interface
to measure the ADC for EPM.

Change-Id: I89931c9cffe91ff1846c91a85629c7b5d494bf57
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:42:17 -07:00
Siddartha Mohanadoss 7efed8e6f4 hwmon: epm_adc: Scale single measurement result
EPM driver can scale the result returned to the user
instead of returning raw ADC code that is obtained
through the PSOC.

The range of the code is from 0-0x7fff with the
corresponding voltage range from 0 to 2.048V. The
voltage units are in mV. The current is computed
using the corresponding channel's rsense value
with the units in mA.

Change-Id: I6fc4b264fa170e412800f4ef77b4c3dacb90186c
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:42:14 -07:00
Siddartha Mohanadoss d4afc55092 hwmon: epm_adc: Register epm_adc with misc
epm_adc is required by misc to access the file I/O that is
exposed by the epm_adc interface for clients to issue
requests to read the ADC.

Change-Id: Ib731c5dc5f6844d28f9031756ab2735b141f8c39
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:42:14 -07:00
Siddartha Mohanadoss 552dc86589 hwmon: qpnp-adc: Add Reverse calibration
On VADC_TM peripheral, clients have the ability
to set thresholds and receive interrupts when the
thresholds are crossed. These thresholds are required
to be converted to voltages if its a temperature
threshold and calibration is to be applied on them.
Depending on the channels the voltage and gain
api returns the absolute or ratiometric calibration
values for scaling functions. The scaling functions
currently supported are for channels usb_id, batt_therm
and thermistor channels using 100k pull-ups.

Change-Id: I1973f5b3fa81a3e668baed253a501b5ab3256e98
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:39:31 -07:00
Siddartha Mohanadoss 4df7605e2e hwmon: qpnp-adc: Request interrupt by name instead of number
Request the interrupt source by name instead of the number.
This is to make it more obvious what interrupt source is
being requested. There are multiple interrupts within the ADC
and requesting by name makes it know what interrupt is being
requested instead of using only an interrupt index. For normal
ADC operation the end of conversion interrupt is to
being requested here.

Change-Id: I2d24446daaba7f2d5a8f8a408ccfc6bd6bfcffa2
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:39:30 -07:00
Siddartha Mohanadoss 9009df4509 hwmon: qpnp-adc-common: Update mapping table
Update mapping table for 100k/150k to keep it
consistent with other voltage-temperature mapping tables.

The previous mapping table format was in temperature-voltage.
Having a single format as much as possible avoids confusion
with the clients when it comes to using the appropriate
api's to convert temperature-voltage or voltage-temperature.

Change-Id: I736710d243527e02b8521e7b5cd9bf2192809289
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:38:02 -07:00
Siddartha Mohanadoss b4b5c4ce55 hwmon: qpnp-adc-common: Update scaling api names
Update api name used for converting voltage-temperature
and temperature-voltage from the mapping table to make
it more obvious for clients to call the appropriate
functions.

Change-Id: I582f9dabd563a3c8cf0a9b580adb1a355856099a
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:38:01 -07:00
Siddartha Mohanadoss 9faaf75d45 hwmon: qpnp-adc-voltage: Add timeout for end of conversion
Add a timeout while the ADC read API waits for the end of
conversion interrupt. After a timeout, the status register
is read to ensure the ADC conversion is complete. The
timeout is added to return back to the user if the end
of conversion interrupt is not triggered.

Change-Id: I0deed0099212221c938a5ab7f775231e2bc85905
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:35:23 -07:00
Siddartha Mohanadoss 82b61b698f hwmon: qpnp-adc: Remove interrupt initialization
The SPMI peripheral driver is not required to initialize
the peripheral interrupts. The QPNP interrupt driver
handles setting the configuration for the corresponding
interrupt bit for which the peripheral driver makes a request.

Remove the free_irq for voltage irq in the failure path.
The request is made through devm_request_irq and it will
handle freeing the irq.

Change-Id: Ie0b416d39dfe9a9811f5e21512413b62c6db27de
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:35:22 -07:00
Stephen Boyd ce41a3ad72 hwmon: qpnp-adc: Fix key not in data bug
The sysfs attribute is initialized properly, but the
initialization is overwritten by the memcpy directly following
that line. Do the initialization after the memcpy to avoid the

	BUG: key eeb16158 not in .data!

warnings from lockdep.

Change-Id: I9ff7f750a29b637348aa4fbd1a17bc5c2cfb1302
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 15:32:21 -07:00
Stephen Boyd 45ec7b6e00 hwmon: qpnp-adc-current: Fix key not in data bug
The sysfs attribute is initialized properly, but the
initialization is overwritten by the memcpy directly following
that line. Do the initialization after the memcpy to avoid the

	BUG: key eeb16158 not in .data!

warnings from lockdep.

Change-Id: Idb69bf631a684c689be5230200b5ab1341b4ec36
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 15:32:19 -07:00
Siddartha Mohanadoss 963f1f82ab hwmon: qpnp-adc-current: Add periodic calibration
Support periodic IADC peripheral calibration to perform
calibration as a function of time and temperature.
Calibration is performed every 5 minutes and for
every 5degC temperature change in the die temperature.

As part of the periodic calibration update the USR trim
registers with fresh offset values. The clients can read
the offset trim values through their own trim registers.

Support reading internal RSENSE trim register and
use it for current calculation.

Also update the gain and offset api to support clients
who require the updated periodic calibrated values.

Change-Id: I2b3f0383b76417069333fb95c0c7fc1ac06eafd5
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:31:27 -07:00
Siddartha Mohanadoss 06b7e83db7 hwmon: epm-adc: Update compatible value in the match table
Update the compatible value in the match table to be
more device specific. EPM driver uses Cypress
CY8C5568LTI-114 to perform ADC reads.

Change-Id: I4331662a9b7e461b2b1ef0b54354340199fc2181
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:31:21 -07:00
Siddartha Mohanadoss 4f5b05ea9a hwmon: epm_adc: Add average buffering command
The average buffering is used by clients who want
to set a period for which they want the PSoC to
measure and collect samples for the enabled channels.
The data obtained from the PSoC is a 12bit data for
each channel measurement. The EPM driver parses the
data for each of this channel and stores the result
for clients who issued the average buffered request.

Change-Id: I78dd7024c3146aa9578dc65e497021e42efbbd45
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:21:06 -07:00
Siddartha Mohanadoss 7f2b6b0e7c hwmon: pm8xxx-adc: Vote for a PMIC clock buffer
Incorrect PMIC_THERM/XO_THERM readings are seen when
the XO clock is disabled.

The internal PMIC therm relies on the PMIC band gap
reference which in turn is enabled when any of the
PMIC clock buffers are enabled. The XO_THERM relies
on the VREF_XO as its reference source which gets
enabled when any of the PMIC clock buffers are
switched on. Therefore vote for a clock buffer when
a PMIC_THERM/XO_THERM is requested.

CRs-Fixed: 392602
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Change-Id: I2165f5d52b537c6b589a22a20feede61e88b5ec4
2013-09-04 15:20:30 -07:00
Siddartha Mohanadoss acd7e22447 hwmon: epm_adc: Fix incorrect SPI writes
Incorrect spi write transactions and incorrect readings
are seen. This is because of using incorrect SPI slave
address while initiating the SPI writes to the ADS ADC.
Also fix the incorrect scaling when converting the raw ADC
code to the appropriate physical result.

Change-Id: I0e16f210fa07e1ce1128f39b0f4e1d325ea7e7ef
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:19:54 -07:00
Siddartha Mohanadoss f8df238cbf hwmon: qpnp-adc: Support configurable pull-ups
VADC peripheral has internal support to select
configurable pull-ups through a configurable AMUX
100k and 150k pull-up. Clients who need the
configurable pull-up include PA_THERM's, XO_THERM's,
EMMC_THERM, MSM_THERM can select the appropriate
channel id to select the 100k/150k pull-up.

Change-Id: I8075b163fe23f0ee942929f0d7f712f3972b9619
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:19:10 -07:00
Siddartha Mohanadoss e64f504625 hwmon: epm_adc: Add EPM support using PSOC
Add support for communicating with the PSOC
using the supported protocol commands from
the PSOC.

The support includes communicating with the
controller to initiate and start the ADC
conversion for the selected channels. Start
and receive ADC conversion for single measurement,
buffered reads, averaging the samples and returning
the results over the set averaging period.

Other commands supported include setting/receiving
the timestamp, setting reference voltage, toggling
gpio to set triggers on set events.

Change-Id: I67ae4ab4378092b8f8de2b1a9d225df89fd0714f
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:17:09 -07:00
Siddartha Mohanadoss 058d389d98 hwmon: qpnp-adc: Add PMIC 2.0 ADC bringup fixes
VADC/IADC peripheral is supported from PMIC 2.0 onwards.
Add version check to allow VADC/IADC reads if the
version is supported. Add probe defereal api for clients
who need to know if the ADC driver is ready. There is a
bug where the completion is not initialized. Fix it
by initializing it. Add support to disable the peripheral
after the ADC is read and enable it before starting a
conversion.

Add scaling functions to support reading the die temperature,
XO_THERM, batt_therm and batt_id. Add the ratiometric
calibration routine that uses the vref/gnd for calibration.
The ratiometric calibration is used for calibrating xo_therm,
batt_therm, batt_id.

Update the gain value used for calibration on the IADC
peripheral. PMIC 2.0 IADC peripheral uses 17.857mV instead
of 25mV for its gain calibration.

Change-Id: I2427a0106920557e95fa630554a26b974e4e4e39
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:16:44 -07:00
Yan He d659426e7c hwmon: epm_adc: Update the physical result
The scaling function multiplies the ADC code with
a high scale factor to avoid rouding accuracy errors.
This results in a 32 bit integer not being sufficient
to store the result. Therefore use a 64 bit integer
type to process the result.

Change-Id: Iee5ec105d66012efef9e9674de2e8aa0c886d31f
Signed-off-by: Yan He <yanhe@codeaurora.org>
2013-09-04 15:14:41 -07:00
Siddartha Mohanadoss 572e1a52ac hwmon: qpnp-adc: Fix register read/writes
Fix reading/writing to the correct ADC peripheral offset
address during SPMI read/writes. While adding multiple
channels an incorrect channel index initialization causes
the ADC reads to occur only on one channel. Fix it by
initializing the channel index only once at init.

The configure api has few register read/writes done
without using the bit mask field. Fix it by reading
the register and updating only the concerned bits.
Also add more comments to the configure api to list
out the steps for each register configuration and
fix using the correct print statements on error.

Change-Id: I0ce67163c5f27021f5fb0905fe601f4b1e0ee8b8
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:08:07 -07:00
Siddartha Mohanadoss 7f88b73a0f hwmon: qpnp-adc: Add PMIC QPNP IADC driver
The QPNP IADC driver supports the user bank
peripheral of the current ADC(IADC).

IADC is a 16 bit ADC used for measuring current.
The single measurement mode is supported to read
current from upto seven channel configuration.

Clients can read the internal/external Rsense,
CSP_EX, CSN_RX along with gain and offset
calibraton channels.

Change-Id: I7e5ae3fc70878d16827d33705853a36bb0aa04f6
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:07:08 -07:00
Siddartha Mohanadoss 4ec3f02f08 hwmon: pm8xxx-adc: Remove wakelocks
The PM8xxx ADC interrupt is configured as a
wakeable interrupt. Therefore the system can suspend
and still have the end of conversion interrupt be
serviced.

Add a timeout in the wait_for_completion in case
the end of conversion event is not received. This
is to rule out any side affects if a missed interrupt
occurs.

Change-Id: Iad36ad4fb7e550e563f0bf7803d3e5e861b7aacd
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:05:48 -07:00
Siddartha Mohanadoss 7cdb79523b hwmon: qpnp-adc: Add PMIC QPNP VADC Driver
The QPNP VADC driver supports the User Bank Peripheral of
the voltage ADC(VADC).

VADC is a 15 bit ADC that measures signals through the
Main analog multiplexer (AMUX) and PREMUX. The driver
arbitrates the request to issue ADC read requests.

VADC driver includes support for the conversion sequencer.
The conversion sequencer is a HW triggered signal to start
ADC measurement on trigger events for PA ON,
camera flash and TX threshold.

The AMUX supports external pull-ups simultaneously. Clients
can select the appropriate AMUX input channel to measure the
ADC for the intended pull up configuration.

Change-Id: I8886968ccec54ad03334b113b4516d4d200e0da8
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:04:09 -07:00
Siddartha Mohanadoss e29a58b18c hwmon: pm8xxx-adc: Update pa_therm mapping table
Inaccurate temperature readings are reported for
pa_therm when read from the apps. This is because
an inaccurate B constant was used while calculating
the voltage to temperature mapping table. Fix it
by generating the table using the correct B constant
for the thermistor.

Change-Id: I13f5dde11e1a3f51b7579de1fe924c162f2b31a1
CRs-Fixed: 374589
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2013-09-04 15:01:03 -07:00
Stephen Boyd 5145dbc226 pm8xxx-adc: Fix lockdep warnings with key's not in .data
Devices attributes have lockdep keys and so they should exist in
the data section. Failure to do this results in lockdep turning
itself off and warnings such as:

	BUG: key eeb0883c not in .data!

Fix this problem in the pm8xxx-adc driver by initializing the
keys with sysfs_attr_init().

Change-Id: Ie42f9a28c343e32ef36ca3570d63a7bb557dfe64
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 15:00:07 -07:00
Stephen Boyd 3aa26a34f1 pm8xxx-adc: Remove dead debugfs code
These ops are not referenced by any code. Remove them.

Change-Id: I092b0fbb47d1d95524683b73472c04152c07a63d
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 15:00:05 -07:00
Stephen Boyd b8dc2f3404 epm-adc: Fix lockdep warnings with key's not in .data
Devices attributes have lockdep keys and so they should exist in
the data section. Failure to do this results in lockdep turning
itself off and warnings such as:

	BUG: key eeb0883c not in .data!

Fix this problem by statically allocating the devices attributes
and hardcoding the names instead of generating them dynamically.

Change-Id: I8db28768b3bdffab21db8c2ea2cfb21f0e4010c1
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 14:59:39 -07:00
Stephen Boyd cc76b148ff hwmon: Add MSM's epm ADC driver
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 14:47:24 -07:00
Stephen Boyd 3934abf514 hwmon: Add pm8xxx ADC driver
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 14:47:23 -07:00
Stephen Boyd 37d05847f1 hwmon: Add MSM adc driver
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-09-04 14:47:22 -07:00
Benson Leung f72d8ffc89 add EC bridge driver in st1.5
BUG=NONE
TEST=Built and ran on st1.5
Signed-off-by: Horace Fu <horace.fu@quantatw.com>

Change-Id: I137d4dd4296d2de22710a381707fb42b77071318
Signed-off-by: Karthik Parsha <kparsha@codeaurora.org>
2013-09-04 14:47:22 -07:00
Curt Brune 334428c3b3 hwmon: (adt7470) Fix incorrect return code check
commit 93d783bcca69bfacc8dc739d8a050498402587b5 upstream.

In adt7470_write_word_data(), which writes two bytes using
i2c_smbus_write_byte_data(), the return codes are incorrectly AND-ed
together when they should be OR-ed together.

The return code of i2c_smbus_write_byte_data() is zero for success.

The upshot is only the first byte was ever written to the hardware.
The 2nd byte was never written out.

I noticed that trying to set the fan speed limits was not working
correctly on my system.  Setting the fan speed limits is the only
code that uses adt7470_write_word_data().  After making the change
the limit settings work and the alarms work also.

Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-14 22:59:06 -07:00
Vivien Didelot 69325d97cb hwmon: (max6697) fix MAX6581 ideality
commit 5c52add19733eb36d8619713312f5604efef3502 upstream.

Without this patch, the values for ideality (register 0x4b) and ideality
selection mask (register 0x4c) are inverted.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-11 18:35:21 -07:00
Guenter Roeck bde3f4bb51 hwmon: (nct6775) Drop unsupported fan alarm attributes for NCT6775
commit 41fa9a944fce1d7efd5ee3d50ac85b92f42dcc3d upstream.

NCT6775 does not support alarms for fans 4 and 5. Drop the attributes.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-07-25 14:07:27 -07:00
Guenter Roeck e00354825e hwmon: (nct6775) Fix temperature alarm attributes
commit b1d2bff6a61140454b9d203519cc686a2e9ef32f upstream.

Driver displays wrong alarms for temperature attributes.

Turns out that temperature alarm bits are not fixed, but determined
by temperature source mapping. To fix the problem, walk through
the temperature sources to determine the correct alarm bit associated
with a given attribute.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-07-25 14:07:27 -07:00
Guenter Roeck 591bfcfc33 hwmon: (adm1021) Strengthen chip detection for ADM1021, LM84 and MAX1617
On a system with both MAX1617 and JC42 sensors, JC42 sensors can be misdetected
as LM84. Strengthen detection sufficiently enough to avoid this misdetection.
Also improve detection for ADM1021.

Modeled after chip detection code in sensors-detect command.

Cc: stable@vger.kernel.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Jean Delvare <khali@linux-fr.org>
2013-06-07 12:29:31 -07:00
Jean Delvare 4e2284d23b hwmon: (tmp401) Drop redundant safety on cache lifetime
time_after (as opposed to time_after_equal) already ensures that the
cache lifetime is at least as much as requested. There is no point in
manually adding another jiffy to that value, and this can confuse the
reader into wrong interpretation.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Imre Deak <imre.deak@intel.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-05-19 08:19:29 -07:00
Wei Yongjun ecacb0b17c hwmon: fix error return code in abituguru_probe()
Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Cc: stable@vger.kernel.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-05-13 08:07:13 -07:00
Axel Lin 159c8cddd9 hwmon: (iio_hwmon) Fix null pointer dereference
This patch fixes the null pointer dereference in goto error_release_channels
path when allocate memory for st fails.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-05-13 06:43:14 -07:00
Guenter Roeck 169c05cd54 hwmon: (nct6775) Do not create non-existing attributes
Overtemperature and hysteresis registers only exist for primary
temperature registers, not for alternates, so do not assign
those registers when initializing alternates.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-05-11 22:55:07 -07:00
Axel Lin 4510d198f9 hwmon: (iio_hwmon) Fix missing iio_channel_release_all call if devm_kzalloc fail
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-05-11 22:55:07 -07:00
Linus Torvalds e72a5d1ceb Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
Pull hwmon update from Jean Delvare:
 "Only lm75 driver updates this time"

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  hwmon: (lm75) Add support for the Dallas/Maxim DS7505
  hwmon: (lm75) Tune resolution and sample time per chip
  hwmon: (lm75) Prepare to support per-chip resolution and sample time
  hwmon: (lm75) Per-chip configuration register initialization
2013-05-04 13:44:38 -07:00
Al Viro 60b7bf4e61 more mode_t whack-a-mole...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-05-04 14:46:28 -04:00
Jean Delvare 3fbc81e3c0 hwmon: (lm75) Add support for the Dallas/Maxim DS7505
Basically it's the same as the original DS75 but much faster.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
2013-05-04 14:49:36 +02:00
Jean Delvare 0cd2c72d76 hwmon: (lm75) Tune resolution and sample time per chip
Most LM75-compatible chips can either sample much faster or with a
much better resolution than the original LM75 chip. So far the lm75
driver did not let the user take benefit of these improvements. Do it
now.

I decided to almost always configure the chip to use the best
resolution possible, which also means the longest sample time. The
only chips for which I didn't are the DS75, DS1775 and STDS75, because
they are really too slow in 12-bit mode (1.2 to 1.5 second worst case)
so I went for 11-bit mode as a more reasonable tradeoff. This choice is
dictated by the fact that the hwmon subsystem is meant for system
monitoring, it has never been supposed to be ultra-fast, and as a
matter of fact we do cache the sampled values in almost all drivers.

If anyone isn't pleased with these default settings, they can always
introduce a platform data structure or DT support for the lm75. That
being said, it seems nobody ever complained that the driver wouldn't
refresh the value faster than every 1.5 second, and the change made
it faster for all chips even in 12-bit mode, so I don't expect any
complaint.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
2013-05-04 14:49:36 +02:00
Jean Delvare 87d0621ae2 hwmon: (lm75) Prepare to support per-chip resolution and sample time
Prepare the lm75 driver to support per-chip resolution and sample
time. For now we only make the code generic enough to support it, but
we still use the same, unchanged resolution (9-bit) and sample time
(1.5 s) for all chips.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
2013-05-04 14:49:36 +02:00
Jean Delvare 8a5c5cc617 hwmon: (lm75) Per-chip configuration register initialization
There is no standard for the configuration register bits of LM75-like
chips. We shouldn't blindly clear bits setting the resolution as they
are either unused or used for something else on some of the supported
chips.

So, switch to per-chip configuration initialization. This will allow
for better tuning later, for example using more resolution bits when
available.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
2013-05-04 14:49:36 +02:00