summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/supply')
-rw-r--r--drivers/power/supply/ab8500_charger.c16
-rw-r--r--drivers/power/supply/bq27xxx_battery.c118
-rw-r--r--drivers/power/supply/cros_peripheral_charger.c11
-rw-r--r--drivers/power/supply/ingenic-battery.c10
-rw-r--r--drivers/power/supply/sbs-manager.c2
-rw-r--r--drivers/power/supply/test_power.c36
6 files changed, 129 insertions, 64 deletions
diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index 9b34d1a60f..4b0ad1b4b4 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -488,8 +488,10 @@ static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di)
/* Only measure voltage if the charger is connected */
if (di->ac.charger_connected) {
ret = iio_read_channel_processed(di->adc_main_charger_v, &vch);
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
+ return ret;
+ }
} else {
vch = 0;
}
@@ -540,8 +542,10 @@ static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di)
/* Only measure voltage if the charger is connected */
if (di->usb.charger_connected) {
ret = iio_read_channel_processed(di->adc_vbus_v, &vch);
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
+ return ret;
+ }
} else {
vch = 0;
}
@@ -563,8 +567,10 @@ static int ab8500_charger_get_usb_current(struct ab8500_charger *di)
/* Only measure current if the charger is online */
if (di->usb.charger_online) {
ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich);
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
+ return ret;
+ }
} else {
ich = 0;
}
@@ -586,8 +592,10 @@ static int ab8500_charger_get_ac_current(struct ab8500_charger *di)
/* Only measure current if the charger is online */
if (di->ac.charger_online) {
ret = iio_read_channel_processed(di->adc_main_charger_c, &ich);
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
+ return ret;
+ }
} else {
ich = 0;
}
diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index abca568344..750fda5433 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -1545,7 +1545,8 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
* Return a battery charge value in µAh
* Or < 0 if something fails.
*/
-static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
+static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg,
+ union power_supply_propval *val)
{
int charge;
@@ -1561,34 +1562,39 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
else
charge *= 1000;
- return charge;
+ val->intval = charge;
+
+ return 0;
}
/*
* Return the battery Nominal available capacity in µAh
* Or < 0 if something fails.
*/
-static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di)
+static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
- return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC);
+ return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC, val);
}
/*
* Return the battery Remaining Capacity in µAh
* Or < 0 if something fails.
*/
-static inline int bq27xxx_battery_read_rc(struct bq27xxx_device_info *di)
+static inline int bq27xxx_battery_read_rc(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
- return bq27xxx_battery_read_charge(di, BQ27XXX_REG_RC);
+ return bq27xxx_battery_read_charge(di, BQ27XXX_REG_RC, val);
}
/*
* Return the battery Full Charge Capacity in µAh
* Or < 0 if something fails.
*/
-static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di)
+static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
- return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC);
+ return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC, val);
}
/*
@@ -1633,7 +1639,8 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di,
* Return the battery Available energy in µWh
* Or < 0 if something fails.
*/
-static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
+static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
int ae;
@@ -1648,14 +1655,17 @@ static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
else
ae *= 1000;
- return ae;
+ val->intval = ae;
+
+ return 0;
}
/*
- * Return the battery temperature in tenths of degree Kelvin
+ * Return the battery temperature in tenths of degree Celsius
* Or < 0 if something fails.
*/
-static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
+static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
int temp;
@@ -1668,14 +1678,20 @@ static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
if (di->opts & BQ27XXX_O_ZERO)
temp = 5 * temp / 2;
- return temp;
+ /* Convert decidegree Kelvin to Celsius */
+ temp -= 2731;
+
+ val->intval = temp;
+
+ return 0;
}
/*
* Return the battery Cycle count total
* Or < 0 if something fails.
*/
-static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
+static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
int cyct;
@@ -1683,14 +1699,17 @@ static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
if (cyct < 0)
dev_err(di->dev, "error reading cycle count total\n");
- return cyct;
+ val->intval = cyct;
+
+ return 0;
}
/*
* Read a time register.
* Return < 0 if something fails.
*/
-static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
+static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg,
+ union power_supply_propval *val)
{
int tval;
@@ -1704,7 +1723,9 @@ static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
if (tval == 65535)
return -ENODATA;
- return tval * 60;
+ val->intval = tval * 60;
+
+ return 0;
}
/*
@@ -1756,19 +1777,26 @@ static bool bq27xxx_battery_capacity_inaccurate(struct bq27xxx_device_info *di,
return false;
}
-static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
+static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di,
+ union power_supply_propval *val)
{
+ int health;
+
/* Unlikely but important to return first */
if (unlikely(bq27xxx_battery_overtemp(di, di->cache.flags)))
- return POWER_SUPPLY_HEALTH_OVERHEAT;
- if (unlikely(bq27xxx_battery_undertemp(di, di->cache.flags)))
- return POWER_SUPPLY_HEALTH_COLD;
- if (unlikely(bq27xxx_battery_dead(di, di->cache.flags)))
- return POWER_SUPPLY_HEALTH_DEAD;
- if (unlikely(bq27xxx_battery_capacity_inaccurate(di, di->cache.flags)))
- return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
-
- return POWER_SUPPLY_HEALTH_GOOD;
+ health = POWER_SUPPLY_HEALTH_OVERHEAT;
+ else if (unlikely(bq27xxx_battery_undertemp(di, di->cache.flags)))
+ health = POWER_SUPPLY_HEALTH_COLD;
+ else if (unlikely(bq27xxx_battery_dead(di, di->cache.flags)))
+ health = POWER_SUPPLY_HEALTH_DEAD;
+ else if (unlikely(bq27xxx_battery_capacity_inaccurate(di, di->cache.flags)))
+ health = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
+ else
+ health = POWER_SUPPLY_HEALTH_GOOD;
+
+ val->intval = health;
+
+ return 0;
}
static bool bq27xxx_battery_is_full(struct bq27xxx_device_info *di, int flags)
@@ -1851,22 +1879,8 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
if ((cache.flags & 0xff) == 0xff)
cache.flags = -1; /* read error */
if (cache.flags >= 0) {
- cache.temperature = bq27xxx_battery_read_temperature(di);
- if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR)
- cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE);
- if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR)
- cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
- if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
- cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
-
- cache.charge_full = bq27xxx_battery_read_fcc(di);
cache.capacity = bq27xxx_battery_read_soc(di);
- if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
- cache.energy = bq27xxx_battery_read_energy(di);
di->cache.flags = cache.flags;
- cache.health = bq27xxx_battery_read_health(di);
- if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
- cache.cycle_count = bq27xxx_battery_read_cyct(di);
/*
* On gauges with signed current reporting the current must be
@@ -2038,18 +2052,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
ret = bq27xxx_battery_capacity_level(di, val);
break;
case POWER_SUPPLY_PROP_TEMP:
- ret = bq27xxx_simple_value(di->cache.temperature, val);
- if (ret == 0)
- val->intval -= 2731; /* convert decidegree k to c */
+ ret = bq27xxx_battery_read_temperature(di, val);
break;
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
- ret = bq27xxx_simple_value(di->cache.time_to_empty, val);
+ ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE, val);
break;
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
- ret = bq27xxx_simple_value(di->cache.time_to_empty_avg, val);
+ ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP, val);
break;
case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
- ret = bq27xxx_simple_value(di->cache.time_to_full, val);
+ ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF, val);
break;
case POWER_SUPPLY_PROP_TECHNOLOGY:
if (di->opts & BQ27XXX_O_MUL_CHEM)
@@ -2059,12 +2071,12 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
break;
case POWER_SUPPLY_PROP_CHARGE_NOW:
if (di->regs[BQ27XXX_REG_NAC] != INVALID_REG_ADDR)
- ret = bq27xxx_simple_value(bq27xxx_battery_read_nac(di), val);
+ ret = bq27xxx_battery_read_nac(di, val);
else
- ret = bq27xxx_simple_value(bq27xxx_battery_read_rc(di), val);
+ ret = bq27xxx_battery_read_rc(di, val);
break;
case POWER_SUPPLY_PROP_CHARGE_FULL:
- ret = bq27xxx_simple_value(di->cache.charge_full, val);
+ ret = bq27xxx_battery_read_fcc(di, val);
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
ret = bq27xxx_battery_read_dcap(di, val);
@@ -2077,16 +2089,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
return -EINVAL;
case POWER_SUPPLY_PROP_CYCLE_COUNT:
- ret = bq27xxx_simple_value(di->cache.cycle_count, val);
+ ret = bq27xxx_battery_read_cyct(di, val);
break;
case POWER_SUPPLY_PROP_ENERGY_NOW:
- ret = bq27xxx_simple_value(di->cache.energy, val);
+ ret = bq27xxx_battery_read_energy(di, val);
break;
case POWER_SUPPLY_PROP_POWER_AVG:
ret = bq27xxx_battery_pwr_avg(di, val);
break;
case POWER_SUPPLY_PROP_HEALTH:
- ret = bq27xxx_simple_value(di->cache.health, val);
+ ret = bq27xxx_battery_read_health(di, val);
break;
case POWER_SUPPLY_PROP_MANUFACTURER:
val->strval = BQ27XXX_MANUFACTURER;
diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
index a204f2355b..d406f2a784 100644
--- a/drivers/power/supply/cros_peripheral_charger.c
+++ b/drivers/power/supply/cros_peripheral_charger.c
@@ -5,6 +5,7 @@
* Copyright 2020 Google LLC.
*/
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/platform_data/cros_ec_commands.h>
@@ -367,16 +368,22 @@ static int __maybe_unused cros_pchg_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(cros_pchg_pm_ops, NULL, cros_pchg_resume);
+static const struct platform_device_id cros_pchg_id[] = {
+ { DRV_NAME, 0 },
+ {}
+};
+MODULE_DEVICE_TABLE(platform, cros_pchg_id);
+
static struct platform_driver cros_pchg_driver = {
.driver = {
.name = DRV_NAME,
.pm = &cros_pchg_pm_ops,
},
- .probe = cros_pchg_probe
+ .probe = cros_pchg_probe,
+ .id_table = cros_pchg_id,
};
module_platform_driver(cros_pchg_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ChromeOS EC peripheral device charger");
-MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c
index 2e7fdfde47..0a40f425c2 100644
--- a/drivers/power/supply/ingenic-battery.c
+++ b/drivers/power/supply/ingenic-battery.c
@@ -31,8 +31,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
switch (psp) {
case POWER_SUPPLY_PROP_HEALTH:
- ret = iio_read_channel_processed(bat->channel, &val->intval);
- val->intval *= 1000;
+ ret = iio_read_channel_processed_scale(bat->channel,
+ &val->intval,
+ 1000);
if (val->intval < info->voltage_min_design_uv)
val->intval = POWER_SUPPLY_HEALTH_DEAD;
else if (val->intval > info->voltage_max_design_uv)
@@ -41,8 +42,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
val->intval = POWER_SUPPLY_HEALTH_GOOD;
return ret;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- ret = iio_read_channel_processed(bat->channel, &val->intval);
- val->intval *= 1000;
+ ret = iio_read_channel_processed_scale(bat->channel,
+ &val->intval,
+ 1000);
return ret;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
val->intval = info->voltage_min_design_uv;
diff --git a/drivers/power/supply/sbs-manager.c b/drivers/power/supply/sbs-manager.c
index 9e4141cffb..933b04806d 100644
--- a/drivers/power/supply/sbs-manager.c
+++ b/drivers/power/supply/sbs-manager.c
@@ -358,7 +358,7 @@ static int sbsm_probe(struct i2c_client *client)
/* register muxed i2c channels. One for each supported battery */
for (i = 0; i < SBSM_MAX_BATS; ++i) {
if (data->supported_bats & BIT(i)) {
- ret = i2c_mux_add_adapter(data->muxc, 0, i + 1, 0);
+ ret = i2c_mux_add_adapter(data->muxc, 0, i + 1);
if (ret)
break;
}
diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 0d0a77584c..442ceb7795 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -35,6 +35,8 @@ static int battery_capacity = 50;
static int battery_voltage = 3300;
static int battery_charge_counter = -1000;
static int battery_current = -1600;
+static enum power_supply_charge_behaviour battery_charge_behaviour =
+ POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
static bool module_initialized;
@@ -123,6 +125,9 @@ static int test_power_get_battery_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CURRENT_NOW:
val->intval = battery_current;
break;
+ case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
+ val->intval = battery_charge_behaviour;
+ break;
default:
pr_info("%s: some properties deliberately report errors.\n",
__func__);
@@ -131,6 +136,31 @@ static int test_power_get_battery_property(struct power_supply *psy,
return 0;
}
+static int test_power_battery_property_is_writeable(struct power_supply *psy,
+ enum power_supply_property psp)
+{
+ return psp == POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR;
+}
+
+static int test_power_set_battery_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ const union power_supply_propval *val)
+{
+ switch (psp) {
+ case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
+ if (val->intval < 0 ||
+ val->intval >= BITS_PER_TYPE(typeof(psy->desc->charge_behaviours)) ||
+ !(BIT(val->intval) & psy->desc->charge_behaviours)) {
+ return -EINVAL;
+ }
+ battery_charge_behaviour = val->intval;
+ break;
+ default:
+ return -EINVAL;
+ }
+ return 0;
+}
+
static enum power_supply_property test_power_ac_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
@@ -156,6 +186,7 @@ static enum power_supply_property test_power_battery_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_AVG,
POWER_SUPPLY_PROP_CURRENT_NOW,
+ POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
};
static char *test_power_ac_supplied_to[] = {
@@ -178,6 +209,11 @@ static const struct power_supply_desc test_power_desc[] = {
.properties = test_power_battery_props,
.num_properties = ARRAY_SIZE(test_power_battery_props),
.get_property = test_power_get_battery_property,
+ .set_property = test_power_set_battery_property,
+ .property_is_writeable = test_power_battery_property_is_writeable,
+ .charge_behaviours = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO)
+ | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE)
+ | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE),
},
[TEST_USB] = {
.name = "test_usb",