Commit graph

2346 commits

Author SHA1 Message Date
Dipen Parmar
bc4b0965bd hwmon: qpnp-adc-voltage: Fix break statement in compensation API
Fix missing break statements in OCV and VBAT compensation
APIs for PM8026 v2.2 to avoid SOC and VBAT errors.

Change-Id: Idd2352c2cd9dad3b80a71f36a2947254792557bc
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2014-05-16 10:29:17 +05:30
Dipen Parmar
d90e1aba36 hwmon: qpnp-adc-voltage: Update default scaling API
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>
2014-05-15 18:07:38 +05:30
Linux Build Service Account
fcd3a7f739 Merge "hwmon: qpnp-adc-voltage: Add suspend_noirq support for VADC" 2014-05-09 01:05:40 -07:00
Dipen Parmar
2f2dcbf43c hwmon: qpnp-adc-voltage: Add suspend_noirq support for VADC
With wakeup_source APIs in VADC driver if the client
driver suspend call requests adc conversion then
suspend process will be aborted even if the wakeup
event released by VADC driver.

Add suspend_noirq support to allow the client
driver to read adc during their suspend call
and remove wakeup_source APIs.

Change-Id: I338463975de0eafd9c9e21e5f0ce8a0508ceeac2
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2014-05-08 17:37:17 +05:30
Linux Build Service Account
9276eaeda2 Merge "hwmon: qpnp-current-monitor: Add SMPS current monitoring driver" 2014-05-08 04:32:06 -07:00
Ashay Jaiswal
81d1aaf67f hwmon: qpnp-current-monitor: Add SMPS current monitoring driver
QPNP PMIC SMPS current monitoring driver provides sysfs interface to
user-space clients for configuring current threshold of the regulator.
It also notifies user-space client whenever load current crosses the
configured threshold limit.

Change-Id: Ic4e7210e262bddd3e1aae6f0ebda35fb54931737
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
2014-05-07 12:21:29 +05:30
Linux Build Service Account
16296e0178 Merge "Merge upstream linux-stable v3.10.36 into msm-3.10" 2014-05-05 15:09:00 -07:00
Ashay Jaiswal
c55724f021 hwmon: qpnp-adc: add PM8916 1.0/1.1/2.0 temperature compensation
Add temperature compensation coefficients for PM8916 VADC to improve
accuracy.

Change-Id: I578185c5c1d852b3f8bb02bb68ce460828369a5b
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
2014-04-29 19:14:17 +05:30
Ian Maund
356fb13538 Merge upstream linux-stable v3.10.36 into msm-3.10
* commit 'v3.10.36': (494 commits)
  Linux 3.10.36
  netfilter: nf_conntrack_dccp: fix skb_header_pointer API usages
  mm: close PageTail race
  net: mvneta: rename MVNETA_GMAC2_PSC_ENABLE to MVNETA_GMAC2_PCS_ENABLE
  x86: fix boot on uniprocessor systems
  Input: cypress_ps2 - don't report as a button pads
  Input: synaptics - add manual min/max quirk for ThinkPad X240
  Input: synaptics - add manual min/max quirk
  Input: mousedev - fix race when creating mixed device
  ext4: atomically set inode->i_flags in ext4_set_inode_flags()
  Linux 3.10.35
  sched/autogroup: Fix race with task_groups list
  e100: Fix "disabling already-disabled device" warning
  xhci: Fix resume issues on Renesas chips in Samsung laptops
  Input: wacom - make sure touch_max is set for touch devices
  KVM: VMX: fix use after free of vmx->loaded_vmcs
  KVM: x86: handle invalid root_hpa everywhere
  KVM: MMU: handle invalid root_hpa at __direct_map
  Input: elantech - improve clickpad detection
  ARM: highbank: avoid L2 cache smc calls when PL310 is not present
  ...

Change-Id: Ib68f565291702c53df09e914e637930c5d3e5310
Signed-off-by: Ian Maund <imaund@codeaurora.org>
2014-04-23 16:23:49 -07:00
Linux Build Service Account
afb845a8dd Merge "hwmon: qpnp-adc-current: Update fix for IADC RSENSE trim error" 2014-03-28 06:31:59 -07:00
Linux Build Service Account
b198cb9af1 Merge "Merge upstream linux-stable v3.10.28 into msm-3.10" 2014-03-26 23:36:07 -07:00
Dipen Parmar
210f50eb25 hwmon: qpnp-adc-current: Update fix for IADC RSENSE trim error
For PM8026 some parts are reporting incorrect RSENSE trim value.
This fix updates the existing RSENSE trim error workaround to
cover them.

Change-Id: I80689e5da9294bee0afb9a83da2da787c4a1d6e7
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2014-03-27 10:12:17 +05:30
Ian Maund
f1b32d4e47 Merge upstream linux-stable v3.10.28 into msm-3.10
The following commits have been reverted from this merge, as they are
known to introduce new bugs and are currently incompatible with our
audio implementation. Investigation of these commits is ongoing, and
they are expected to be brought in at a later time:

86e6de7 ALSA: compress: fix drain calls blocking other compress functions (v6)
16442d4 ALSA: compress: fix drain calls blocking other compress functions

This merge commit also includes a change in block, necessary for
compilation. Upstream has modified elevator_init_fn to prevent race
conditions, requring updates to row_init_queue and test_init_queue.

* commit 'v3.10.28': (1964 commits)
  Linux 3.10.28
  ARM: 7938/1: OMAP4/highbank: Flush L2 cache before disabling
  drm/i915: Don't grab crtc mutexes in intel_modeset_gem_init()
  serial: amba-pl011: use port lock to guard control register access
  mm: Make {,set}page_address() static inline if WANT_PAGE_VIRTUAL
  md/raid5: Fix possible confusion when multiple write errors occur.
  md/raid10: fix two bugs in handling of known-bad-blocks.
  md/raid10: fix bug when raid10 recovery fails to recover a block.
  md: fix problem when adding device to read-only array with bitmap.
  drm/i915: fix DDI PLLs HW state readout code
  nilfs2: fix segctor bug that causes file system corruption
  thp: fix copy_page_rep GPF by testing is_huge_zero_pmd once only
  ftrace/x86: Load ftrace_ops in parameter not the variable holding it
  SELinux: Fix possible NULL pointer dereference in selinux_inode_permission()
  writeback: Fix data corruption on NFS
  hwmon: (coretemp) Fix truncated name of alarm attributes
  vfs: In d_path don't call d_dname on a mount point
  staging: comedi: adl_pci9111: fix incorrect irq passed to request_irq()
  staging: comedi: addi_apci_1032: fix subdevice type/flags bug
  mm/memory-failure.c: recheck PageHuge() after hugetlb page migrate successfully
  GFS2: Increase i_writecount during gfs2_setattr_chown
  perf/x86/amd/ibs: Fix waking up from S3 for AMD family 10h
  perf scripting perl: Fix build error on Fedora 12
  ARM: 7815/1: kexec: offline non panic CPUs on Kdump panic
  Linux 3.10.27
  sched: Guarantee new group-entities always have weight
  sched: Fix hrtimer_cancel()/rq->lock deadlock
  sched: Fix cfs_bandwidth misuse of hrtimer_expires_remaining
  sched: Fix race on toggling cfs_bandwidth_used
  x86, fpu, amd: Clear exceptions in AMD FXSAVE workaround
  netfilter: nf_nat: fix access to uninitialized buffer in IRC NAT helper
  SCSI: sd: Reduce buffer size for vpd request
  intel_pstate: Add X86_FEATURE_APERFMPERF to cpu match parameters.
  mac80211: move "bufferable MMPDU" check to fix AP mode scan
  ACPI / Battery: Add a _BIX quirk for NEC LZ750/LS
  ACPI / TPM: fix memory leak when walking ACPI namespace
  mfd: rtsx_pcr: Disable interrupts before cancelling delayed works
  clk: exynos5250: fix sysmmu_mfc{l,r} gate clocks
  clk: samsung: exynos5250: Add CLK_IGNORE_UNUSED flag for the sysreg clock
  clk: samsung: exynos4: Correct SRC_MFC register
  clk: clk-divider: fix divisor > 255 bug
  ahci: add PCI ID for Marvell 88SE9170 SATA controller
  parisc: Ensure full cache coherency for kmap/kunmap
  drm/nouveau/bios: make jump conditional
  ARM: shmobile: mackerel: Fix coherent DMA mask
  ARM: shmobile: armadillo: Fix coherent DMA mask
  ARM: shmobile: kzm9g: Fix coherent DMA mask
  ARM: dts: exynos5250: Fix MDMA0 clock number
  ARM: fix "bad mode in ... handler" message for undefined instructions
  ARM: fix footbridge clockevent device
  net: Loosen constraints for recalculating checksum in skb_segment()
  bridge: use spin_lock_bh() in br_multicast_set_hash_max
  netpoll: Fix missing TXQ unlock and and OOPS.
  net: llc: fix use after free in llc_ui_recvmsg
  virtio-net: fix refill races during restore
  virtio_net: don't leak memory or block when too many frags
  virtio-net: make all RX paths handle errors consistently
  virtio_net: fix error handling for mergeable buffers
  vlan: Fix header ops passthru when doing TX VLAN offload.
  net: rose: restore old recvmsg behavior
  rds: prevent dereference of a NULL device
  ipv6: always set the new created dst's from in ip6_rt_copy
  net: fec: fix potential use after free
  hamradio/yam: fix info leak in ioctl
  drivers/net/hamradio: Integer overflow in hdlcdrv_ioctl()
  net: inet_diag: zero out uninitialized idiag_{src,dst} fields
  ip_gre: fix msg_name parsing for recvfrom/recvmsg
  net: unix: allow bind to fail on mutex lock
  ipv6: fix illegal mac_header comparison on 32bit
  netvsc: don't flush peers notifying work during setting mtu
  tg3: Initialize REG_BASE_ADDR at PCI config offset 120 to 0
  net: unix: allow set_peek_off to fail
  net: drop_monitor: fix the value of maxattr
  ipv6: don't count addrconf generated routes against gc limit
  packet: fix send path when running with proto == 0
  virtio: delete napi structures from netdev before releasing memory
  macvtap: signal truncated packets
  tun: update file current position
  macvtap: update file current position
  macvtap: Do not double-count received packets
  rds: prevent BUG_ON triggered on congestion update to loopback
  net: do not pretend FRAGLIST support
  IPv6: Fixed support for blackhole and prohibit routes
  HID: Revert "Revert "HID: Fix logitech-dj: missing Unifying device issue""
  gpio-rcar: R-Car GPIO IRQ share interrupt
  clocksource: em_sti: Set cpu_possible_mask to fix SMP broadcast
  irqchip: renesas-irqc: Fix irqc_probe error handling
  Linux 3.10.26
  sh: add EXPORT_SYMBOL(min_low_pfn) and EXPORT_SYMBOL(max_low_pfn) to sh_ksyms_32.c
  ext4: fix bigalloc regression
  arm64: Use Normal NonCacheable memory for writecombine
  arm64: Do not flush the D-cache for anonymous pages
  arm64: Avoid cache flushing in flush_dcache_page()
  ARM: KVM: arch_timers: zero CNTVOFF upon return to host
  ARM: hyp: initialize CNTVOFF to zero
  clocksource: arch_timer: use virtual counters
  arm64: Remove unused cpu_name ascii in arch/arm64/mm/proc.S
  arm64: dts: Reserve the memory used for secondary CPU release address
  arm64: check for number of arguments in syscall_get/set_arguments()
  arm64: fix possible invalid FPSIMD initialization state
  ...

Change-Id: Ia0e5d71b536ab49ec3a1179d59238c05bdd03106
Signed-off-by: Ian Maund <imaund@codeaurora.org>
2014-03-24 14:28:34 -07:00
Dipen Parmar
4c3c5b31f4 hwmon: qpnp-adc: Add smb batt_therm reverse scaling
Add reverse scaling function for smb batt_therm.

Change-Id: Ic81078b9738ee5ee60f505316dd9dbebea8c58fc
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
2014-03-24 17:47:39 +05:30
Siddartha Mohanadoss
0c910d0e7a hwmon: qpnp-adc-current: Fix specifying batfet status
For the condition when PM8941 is true use the BATFET status
that is passed to the calibration api. Ignore the BATFET
status for all other PMIC versions.

For PM8941 when BATFET is open, the reads on channel 0 for
Internal RSENSE are redirected in HW to channel 0x5:
 EXTRSNS_OFFSET. Recalibrate based on this channel.

Change-Id: Ib0d477c5fb4537379b31faf1676d5956317b06a7
CRs-Fixed: 629758
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2014-03-17 22:42:15 -07:00
Siddartha Mohanadoss
d9e1a21bb1 hwmon: qpnp-adc-current: Fix offset channel selection
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>
2014-03-12 19:27:56 -07:00
Guenter Roeck
755ac7af96 hwmon: (max1668) Fix writing the minimum temperature
commit 500a91571f0a5d0d3242d83802ea2fd1faccc66e upstream.

When trying to set the minimum temperature, the driver was erroneously
writing the maximum temperature into the chip.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-03-06 21:30:11 -08:00
Siddartha Mohanadoss
b5311d7a6b hwmon: qpnp-adc-voltage: Show ADC code in hex format
Update the raw code shown for VADC while printing the buffer
in hex format instead of decimal format to maintain the
format that is in the register.

Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Change-Id: I57f39e1d32925a51ca2bc6e848cc897caf565c6c
2014-03-05 18:54:32 -08:00
Siddartha Mohanadoss
ea8cd32a7c thermal: qpnp-adc-tm: Add reverse scaling
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>
2014-03-05 18:43:08 -08:00
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