Commit 34fb2a95 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm Committed by Sebastian Reichel

power: supply: cpcap-battery: improve handling of 3rd party batteries.

Adds a module option to ignore a missing temperature sensor.
Useful for 3rd party batteries.
Signed-off-by: default avatarCarl Philipp Klemm <carl@uvos.xyz>
Acked-by: default avatarTony Lindgren <tony@atomide.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent 1027a42c
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/moduleparam.h>
#include <linux/iio/consumer.h> #include <linux/iio/consumer.h>
#include <linux/iio/types.h> #include <linux/iio/types.h>
...@@ -138,6 +139,9 @@ struct cpcap_battery_ddata { ...@@ -138,6 +139,9 @@ struct cpcap_battery_ddata {
#define CPCAP_NO_BATTERY -400 #define CPCAP_NO_BATTERY -400
static bool ignore_temperature_probe;
module_param(ignore_temperature_probe, bool, 0660);
static struct cpcap_battery_state_data * static struct cpcap_battery_state_data *
cpcap_battery_get_state(struct cpcap_battery_ddata *ddata, cpcap_battery_get_state(struct cpcap_battery_ddata *ddata,
enum cpcap_battery_state state) enum cpcap_battery_state state)
...@@ -169,7 +173,8 @@ static int cpcap_charger_battery_temperature(struct cpcap_battery_ddata *ddata, ...@@ -169,7 +173,8 @@ static int cpcap_charger_battery_temperature(struct cpcap_battery_ddata *ddata,
channel = ddata->channels[CPCAP_BATTERY_IIO_BATTDET]; channel = ddata->channels[CPCAP_BATTERY_IIO_BATTDET];
error = iio_read_channel_processed(channel, value); error = iio_read_channel_processed(channel, value);
if (error < 0) { if (error < 0) {
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error); if (!ignore_temperature_probe)
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
*value = CPCAP_NO_BATTERY; *value = CPCAP_NO_BATTERY;
return error; return error;
...@@ -450,7 +455,7 @@ static int cpcap_battery_get_property(struct power_supply *psy, ...@@ -450,7 +455,7 @@ static int cpcap_battery_get_property(struct power_supply *psy,
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_PRESENT:
if (latest->temperature > CPCAP_NO_BATTERY) if (latest->temperature > CPCAP_NO_BATTERY || ignore_temperature_probe)
val->intval = 1; val->intval = 1;
else else
val->intval = 0; val->intval = 0;
...@@ -536,6 +541,8 @@ static int cpcap_battery_get_property(struct power_supply *psy, ...@@ -536,6 +541,8 @@ static int cpcap_battery_get_property(struct power_supply *psy,
val->intval = POWER_SUPPLY_SCOPE_SYSTEM; val->intval = POWER_SUPPLY_SCOPE_SYSTEM;
break; break;
case POWER_SUPPLY_PROP_TEMP: case POWER_SUPPLY_PROP_TEMP:
if (ignore_temperature_probe)
return -ENODATA;
val->intval = latest->temperature; val->intval = latest->temperature;
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment