power: twl4030_charger: detect battery presence prior to enabling charger
authorNishanth Menon <nm@ti.com>
Wed, 28 May 2014 21:46:49 +0000 (16:46 -0500)
committerSebastian Reichel <sre@kernel.org>
Wed, 23 Jul 2014 11:58:33 +0000 (13:58 +0200)
commit61a7784efd3c89ffb6242f29bcee170dd7f55e6b
treeff9c71cb2d8978b2364d2ce968e9bfe1439f9b80
parent030494e75064cb4fcbeb609d845ae0c9ceade2b9
power: twl4030_charger: detect battery presence prior to enabling charger

TWL4030's Battery Charger seems to be designed for non-hotpluggable
batteries.

If battery is not present in the system, BATSTS is always set with the
expectation that software will take actions to move to a required safe
state (could be power down or disable various charger paths).

It does not seem possible even by manipulating the edge detection
of the event (using BCIEDR2 register) to have a consistent hotplug
handling. This seems to be the result of BATSTS interrupt generated
when the thermistor of the battery pack is disconnected from the
dedicated ADIN1 pin. Clearing the status just results in the status
being regenerated by the monitoring ADC(MADC) and disabling the
edges of event just makes hotplug no longer function. The only
other option is to disable the detection of the MADC by disabling
BCIMFEN4::BATSTSMCHGEN (battery presence detector) - but then, we can
never again detect battery reconnection.

So, detect battery presence based on precharge(which is hardware
automatic state) or default main charger configuration at the time of
probe and enable charger logic only if battery was present.

Reported-by: Russell King <linux@arm.linux.org.uk>
Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/twl4030_charger.c