power: supply: cpcap-charger: Improve battery detection

We are currently using a wrong ADC range for the battery detection.
The ADC returns the battery temperature if connected.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Tony Lindgren 2019-10-16 15:30:05 -07:00 коммит произвёл Sebastian Reichel
Родитель 639c1524da
Коммит 50fc99f83f
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -176,20 +176,21 @@ static enum power_supply_property cpcap_charger_props[] = {
POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_NOW,
}; };
/* No battery always shows temperature of -40000 */
static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata) static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
{ {
struct iio_channel *channel; struct iio_channel *channel;
int error, value; int error, temperature;
channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET]; channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
error = iio_read_channel_raw(channel, &value); error = iio_read_channel_processed(channel, &temperature);
if (error < 0) { if (error < 0) {
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error); dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
return false; return false;
} }
return value == 1; return temperature > -20000 && temperature < 60000;
} }
static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata) static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)