diff mbox series

[3/3] power: supply: cpcap-charger: Improve battery detection

Message ID 20190917213501.16907-4-tony@atomide.com (mailing list archive)
State New, archived
Headers show
Series cpcap charger and battery fixes | expand

Commit Message

Tony Lindgren Sept. 17, 2019, 9:35 p.m. UTC
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>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-charger.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Pavel Machek Sept. 19, 2019, 9:19 a.m. UTC | #1
Hi!

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

This one looks good.

> Cc: Merlijn Wajer <merlijn@wizzup.org>

Acked-by: Pavel Machek <pavel@ucw.cz>

Would it also make sense to publish battery temperature somewhere? It
is somehow important for checking "what is going on" and it should
also be used to control charging. (Normal charging should only be
allowed in normal temperatures, like >10C and <30C or so..)

Thanks and best regards,
								Pavel


> Signed-off-by: Tony Lindgren <tony@atomide.com>
> ---
>  drivers/power/supply/cpcap-charger.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
> --- a/drivers/power/supply/cpcap-charger.c
> +++ b/drivers/power/supply/cpcap-charger.c
> @@ -166,20 +166,21 @@ static enum power_supply_property cpcap_charger_props[] = {
>  	POWER_SUPPLY_PROP_CURRENT_NOW,
>  };
>  
> +/* No battery always shows temperature of -40000 */
>  static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
>  {
>  	struct iio_channel *channel;
> -	int error, value;
> +	int error, temperature;
>  
>  	channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
> -	error = iio_read_channel_raw(channel, &value);
> +	error = iio_read_channel_processed(channel, &temperature);
>  	if (error < 0) {
>  		dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
>  
>  		return false;
>  	}
>  
> -	return value == 1;
> +	return temperature > -20000 && temperature < 60000;
>  }
>  
>  static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
Tony Lindgren Sept. 20, 2019, 2:18 p.m. UTC | #2
* Pavel Machek <pavel@ucw.cz> [190919 09:20]:
> Would it also make sense to publish battery temperature somewhere? It
> is somehow important for checking "what is going on" and it should
> also be used to control charging. (Normal charging should only be
> allowed in normal temperatures, like >10C and <30C or so..)

We have it show up for battery already, not for usb charger
since it's battery value. The usb charger just uses it for
battery detection.

Regards,

Tony
diff mbox series

Patch

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