ACPU: Remove some freqs
power: pm8921-charger: use SoC % value for charging stop and resume

Current pm8921 charger code doesn't consider the SoC % to determine
end of charging and recharging state. This can cause weird UI display
on SoC % and charging state.
For example, charging is completed when SoC % is not reached 100% or
charging is not completed even if SoC % is already 100%.
So this patch change how to determine end of charging and recharging.

Change-Id: Ice658488744d71117fedb64e0fa0eb7ad34c6573
power: pm8921-charger: implement ir compensation

The charger hardware has a +/-30mv error for vdd_max settings. This
means that when vdd_max is set to 4200mV the actual voltage on vph_pwr
line could range from 4170mV to 4230mV. This further means that when
constant current to constant voltage transition happens, the battery
may not be charged up to 4200mV - leading to an premature end of charge.

Fix this by implementing periodic IR compensation. On a device measure the
resistance from the vbat terminal to the ground by shorting the +ve and
-ve of the battery terminals (without a battery), this will be referred to
as rconn in the description. In the code it is rconn_mohm to reflect the
units.

The voltage at battery terminal will be
Vbat(terminal) = Vbat(xoadc) + Ibat * rconn
where Ibat is the current flowing out of (or into if -ve) of the battery.

Vbat(xoadc) and Ibat can be obtained by using the override mode of the
bms. So Vbat(terminal) can be deduced and compensated by increasing
vdd_max. This also helps in increasing constant current mode thereby
decreasing constant voltage mode and decreasing the overall charging time.

The value of rconn will be specific to a PCB layout, it is
passed in from platform_data.

Change-Id: If8df93333ca6b0bad35505895a4fc5577562fadd
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: fix reverse boosting

The reverse boosting of PM8921 may cause the USB to be
deemed as present even though it has been unplugged. This
causes unplug detection to fail and also break charging.

Fix this by disabling input regulation (vin_min) as well
as opening the OVP fets to allow capacitors to discharge.

Disabling input regulation nullifies reverse boosting. The usbin
voltage then is stuck at vph_pwr minus some diode drop across
fets. The CHG_GONE_IRQ is indicative of this condition.
This voltage is further reduced by opening up the ovp fets.

Note that before disabling input regulation we reduce the current
drawn from the usb to 500mA. It is expected that at such low current
the charger will not drop its voltage while input regulation remains
disabled.

The condition for detecting reverse boosting remains the same - input
regulation is active and the battery is supplying current instead of
getting charged.

Parameters allowing this workaround to be fine tuned:

param_vin_disable_counter:
max number of times vin_min is disabled, each iteration disables
input regulation for 20 milliseconds. The loop is exited if a
successful usb removal is detected.

param_open_ovp_counter:
number of times OVP fet is forced opened in steps of 20 millisecond.
The loop exits if a valid usb removal is detected.

Change-Id: Ic9e9ca4ef8585f70700053153c825e4f0df645b3
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: remove obsolete wakelock

Remove an obsolete wakelock which used to be part of
the reverse boost fix. The wakelock is not required
because the reverse boost fix relies on the loop
change interrupt when the device is suspended.

Change-Id: Ieea5bcfa76727486a76e238ff1568904170d8545
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
USB: OTG: remove pm8921_set_usb_power_supply_type

This custom notifier is no longer required to determine
wether a wall charger is connected to the PM8921 charger
or not.

The pm8921-charger driver determines AC charging solely
dependent upon maximum input current from the charging
device.

CRs-Fixed: 339841
Change-Id: I564fa01c61286d013be6b263d038e87568a297f2
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: remove set_usb_power_supply_type

This custom API is no longer required since AC charging
reporting to userspace is solely dependent on the maximum
current supplied by the USB rather than the connector
type.

CRs-Fixed: 339841
Change-Id: Id542b083dd4f0ba5679d64f9e20d3b04cf14d972
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: avoid schedule while atomic bug

If the loop_change interrupt handler directly invokes the
unplug_check_worker which uses msleep causing a bug.

Fix this by scheduling the work directly rather than invoking
the work function.

Change-Id: Id1ce75eddc1b7f09b7476af12b68ec8ae8ff1f24
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: adjust vdd max earlier

The charger hardware decides Constant Current VS Constant Voltage based
on the VPH_PWR voltage and not on battery voltage (vbatt) as it should.

The problem is, becuase of IR drop between VPH_PWR and VBATT,  VPH_PWR
reaches the voltage programmed in vdd_max earlier while the VBATT stays
lower causing the charger hardware switch to constant voltage mode
prematurely.

To fix this issue, adjust the vdd_max early.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: Iliyan Malchev <malchev@google.com>
proc: Consider NO_HZ when printing idle and iowait times

show_stat handler of the /proc/stat file relies on kstat_cpu(cpu)
statistics when priting information about idle and iowait times.
This is OK if we are not using tickless kernel (CONFIG_NO_HZ) because
counters are updated periodically.
With NO_HZ things got more tricky because we are not doing idle/iowait
accounting while we are tickless so the value might get outdated.
Users of /proc/stat will notice that by unchanged idle/iowait values
which is then interpreted as 0% idle/iowait time. From the user space
POV this is an unexpected behavior and a change of the interface.

Let's fix this by using get_cpu_{idle,iowait}_time_us which accounts the
total idle/iowait time since boot and it doesn't rely on sampling or any
other periodic activity. Fall back to the previous behavior if NO_HZ is
disabled or not configured.

Signed-off-by: Michal Hocko <mhocko@suse.cz>
Cc: Dave Jones <davej@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Link: http://lkml.kernel.org/r/39181366adac1b39cb6aa3cd53ff0f7c78d32676.1314172057.git.mhocko@suse.cz
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
sched/accounting: Change cpustat fields to an array

This patch changes fields in cpustat from a structure, to an
u64 array. Math gets easier, and the code is more flexible.

Signed-off-by: Glauber Costa <glommer@parallels.com>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Paul Tuner <pjt@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1322498719-2255-2-git-send-email-glommer@parallels.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
GOV: Some tweaks to conserve battery
AUTOPLUG: Tweaks to conserve battery
SCHED: Updates to reflect changes from "sched/accounting: Change cpustat fields to an array"