Commit 17d4ded2 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:

 - power-supply core support for automatic handling of constant battery
   data supplied by firmware

 - generic-adc-battery: major cleanup

 - axp288_charger: fix ACPI issues on x86 Android tablets

 - rk817: cleanup and fix handling for low state of charge

* tag 'for-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (26 commits)
  power: supply: rk817: Fix low SOC bugs
  power: supply: rk817: Drop unneeded debugging code
  power: supply: axp288_charger: Use alt usb-id extcon on some x86 android tablets
  power: supply: generic-adc-battery: style fixes
  power: supply: generic-adc-battery: improve error message
  power: supply: generic-adc-battery: update copyright info
  power: supply: generic-adc-battery: add DT support
  power: supply: generic-adc-battery: add temperature support
  power: supply: generic-adc-battery: simplify read_channel logic
  power: supply: generic-adc-battery: use simple-battery API
  power: supply: generic-adc-battery: drop memory alloc error message
  power: supply: generic-adc-battery: drop charge now support
  power: supply: generic-adc-battery: drop jitter delay support
  power: supply: generic-adc-battery: fix unit scaling
  power: supply: generic-adc-battery: convert to managed resources
  power: supply: core: auto-exposure of simple-battery data
  dt-bindings: power: supply: adc-battery: add binding
  power: supply: bq256xx: Support to disable charger
  power: supply: charger-manager: Use of_property_read_bool() for boolean properties
  power: reset: qcom-pon: drop of_match_ptr for ID table
  ...
parents e81507ac baba1315
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/power/supply/adc-battery.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: ADC battery
maintainers:
- Sebastian Reichel <sre@kernel.org>
description:
Basic battery capacity meter, which only reports basic battery data
via ADC channels and optionally indicate that the battery is full by
polling a GPIO line.
The voltage is expected to be measured between the battery terminals
and mandatory. The optional current/power channel is expected to
monitor the current/power flowing out of the battery. Last but not
least the temperature channel is supposed to measure the battery
temperature.
allOf:
- $ref: power-supply.yaml#
properties:
compatible:
const: adc-battery
charged-gpios:
description:
GPIO which signals that the battery is fully charged. The GPIO is
often provided by charger ICs, that are not software controllable.
maxItems: 1
io-channels:
minItems: 1
maxItems: 4
io-channel-names:
minItems: 1
items:
- const: voltage
- enum: [ current, power, temperature ]
- enum: [ power, temperature ]
- const: temperature
monitored-battery: true
required:
- compatible
- io-channels
- io-channel-names
- monitored-battery
unevaluatedProperties: false
examples:
- |
#include <dt-bindings/gpio/gpio.h>
fuel-gauge {
compatible = "adc-battery";
charged-gpios = <&gpio 42 GPIO_ACTIVE_HIGH>;
io-channels = <&adc 13>, <&adc 37>;
io-channel-names = "voltage", "current";
power-supplies = <&charger>;
monitored-battery = <&battery>;
};
...@@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = { ...@@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = {
.probe = pm8916_pon_probe, .probe = pm8916_pon_probe,
.driver = { .driver = {
.name = "pm8916-pon", .name = "pm8916-pon",
.of_match_table = of_match_ptr(pm8916_pon_id_table), .of_match_table = pm8916_pon_id_table,
}, },
}; };
module_platform_driver(pm8916_pon_driver); module_platform_driver(pm8916_pon_driver);
......
...@@ -836,6 +836,7 @@ static int axp288_charger_probe(struct platform_device *pdev) ...@@ -836,6 +836,7 @@ static int axp288_charger_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
struct power_supply_config charger_cfg = {}; struct power_supply_config charger_cfg = {};
const char *extcon_name = NULL;
unsigned int val; unsigned int val;
/* /*
...@@ -872,8 +873,18 @@ static int axp288_charger_probe(struct platform_device *pdev) ...@@ -872,8 +873,18 @@ static int axp288_charger_probe(struct platform_device *pdev)
return PTR_ERR(info->cable.edev); return PTR_ERR(info->cable.edev);
} }
if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) { /*
info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME); * On devices with broken ACPI GPIO event handlers there also is no ACPI
* "INT3496" (USB_HOST_EXTCON_HID) device. x86-android-tablets.ko
* instantiates an "intel-int3496" extcon on these devs as a workaround.
*/
if (acpi_quirk_skip_gpio_event_handlers())
extcon_name = "intel-int3496";
else if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1))
extcon_name = USB_HOST_EXTCON_NAME;
if (extcon_name) {
info->otg.cable = extcon_get_extcon_dev(extcon_name);
if (IS_ERR(info->otg.cable)) { if (IS_ERR(info->otg.cable)) {
dev_err_probe(dev, PTR_ERR(info->otg.cable), dev_err_probe(dev, PTR_ERR(info->otg.cable),
"extcon_get_extcon_dev(%s) failed\n", "extcon_get_extcon_dev(%s) failed\n",
......
...@@ -1140,7 +1140,7 @@ static const struct i2c_device_id bq24257_i2c_ids[] = { ...@@ -1140,7 +1140,7 @@ static const struct i2c_device_id bq24257_i2c_ids[] = {
}; };
MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids); MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids);
static const struct of_device_id bq24257_of_match[] = { static const struct of_device_id bq24257_of_match[] __maybe_unused = {
{ .compatible = "ti,bq24250", }, { .compatible = "ti,bq24250", },
{ .compatible = "ti,bq24251", }, { .compatible = "ti,bq24251", },
{ .compatible = "ti,bq24257", }, { .compatible = "ti,bq24257", },
......
...@@ -70,6 +70,9 @@ ...@@ -70,6 +70,9 @@
#define BQ25611D_VBATREG_THRESH_uV 4290000 #define BQ25611D_VBATREG_THRESH_uV 4290000
#define BQ25618_VBATREG_THRESH_uV 4300000 #define BQ25618_VBATREG_THRESH_uV 4300000
#define BQ256XX_CHG_CONFIG_MASK BIT(4)
#define BQ256XX_CHG_CONFIG_BIT_SHIFT 4
#define BQ256XX_ITERM_MASK GENMASK(3, 0) #define BQ256XX_ITERM_MASK GENMASK(3, 0)
#define BQ256XX_ITERM_STEP_uA 60000 #define BQ256XX_ITERM_STEP_uA 60000
#define BQ256XX_ITERM_OFFSET_uA 60000 #define BQ256XX_ITERM_OFFSET_uA 60000
...@@ -259,6 +262,7 @@ struct bq256xx_device { ...@@ -259,6 +262,7 @@ struct bq256xx_device {
* @bq256xx_set_iterm: pointer to instance specific set_iterm function * @bq256xx_set_iterm: pointer to instance specific set_iterm function
* @bq256xx_set_iprechg: pointer to instance specific set_iprechg function * @bq256xx_set_iprechg: pointer to instance specific set_iprechg function
* @bq256xx_set_vindpm: pointer to instance specific set_vindpm function * @bq256xx_set_vindpm: pointer to instance specific set_vindpm function
* @bq256xx_set_charge_type: pointer to instance specific set_charge_type function
* *
* @bq256xx_def_ichg: default ichg value in microamps * @bq256xx_def_ichg: default ichg value in microamps
* @bq256xx_def_iindpm: default iindpm value in microamps * @bq256xx_def_iindpm: default iindpm value in microamps
...@@ -290,6 +294,7 @@ struct bq256xx_chip_info { ...@@ -290,6 +294,7 @@ struct bq256xx_chip_info {
int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm); int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm);
int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg); int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg);
int (*bq256xx_set_vindpm)(struct bq256xx_device *bq, int vindpm); int (*bq256xx_set_vindpm)(struct bq256xx_device *bq, int vindpm);
int (*bq256xx_set_charge_type)(struct bq256xx_device *bq, int type);
int bq256xx_def_ichg; int bq256xx_def_ichg;
int bq256xx_def_iindpm; int bq256xx_def_iindpm;
...@@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq, ...@@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq,
return 0; return 0;
} }
static int bq256xx_set_charge_type(struct bq256xx_device *bq, int type)
{
int chg_config = 0;
switch (type) {
case POWER_SUPPLY_CHARGE_TYPE_NONE:
chg_config = 0x0;
break;
case POWER_SUPPLY_CHARGE_TYPE_TRICKLE:
case POWER_SUPPLY_CHARGE_TYPE_FAST:
chg_config = 0x1;
break;
default:
return -EINVAL;
}
return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_0,
BQ256XX_CHG_CONFIG_MASK,
(chg_config ? 1 : 0) << BQ256XX_CHG_CONFIG_BIT_SHIFT);
}
static int bq256xx_get_ichg_curr(struct bq256xx_device *bq) static int bq256xx_get_ichg_curr(struct bq256xx_device *bq)
{ {
unsigned int charge_current_limit; unsigned int charge_current_limit;
...@@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy, ...@@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy,
return ret; return ret;
break; break;
case POWER_SUPPLY_PROP_CHARGE_TYPE:
ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval);
if (ret)
return ret;
break;
default: default:
break; break;
} }
...@@ -1197,6 +1229,7 @@ static int bq256xx_property_is_writeable(struct power_supply *psy, ...@@ -1197,6 +1229,7 @@ static int bq256xx_property_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
case POWER_SUPPLY_PROP_STATUS: case POWER_SUPPLY_PROP_STATUS:
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
case POWER_SUPPLY_PROP_CHARGE_TYPE:
return true; return true;
default: default:
return false; return false;
...@@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iterm = bq256xx_set_term_curr,
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iterm = bq256xx_set_term_curr,
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iterm = bq256xx_set_term_curr,
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iterm = bq256xx_set_term_curr,
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA, .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq256xx_set_term_curr, .bq256xx_set_iterm = bq256xx_set_term_curr,
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr, .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA, .bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq25618_619_set_term_curr, .bq256xx_set_iterm = bq25618_619_set_term_curr,
.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr, .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
...@@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = { ...@@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
.bq256xx_set_iterm = bq25618_619_set_term_curr, .bq256xx_set_iterm = bq25618_619_set_term_curr,
.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr, .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim, .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
.bq256xx_set_charge_type = bq256xx_set_charge_type,
.bq256xx_def_ichg = BQ25618_ICHG_DEF_uA, .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA, .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
......
...@@ -1622,7 +1622,7 @@ static const struct i2c_device_id bq25890_i2c_ids[] = { ...@@ -1622,7 +1622,7 @@ static const struct i2c_device_id bq25890_i2c_ids[] = {
}; };
MODULE_DEVICE_TABLE(i2c, bq25890_i2c_ids); MODULE_DEVICE_TABLE(i2c, bq25890_i2c_ids);
static const struct of_device_id bq25890_of_match[] = { static const struct of_device_id bq25890_of_match[] __maybe_unused = {
{ .compatible = "ti,bq25890", }, { .compatible = "ti,bq25890", },
{ .compatible = "ti,bq25892", }, { .compatible = "ti,bq25892", },
{ .compatible = "ti,bq25895", }, { .compatible = "ti,bq25895", },
......
...@@ -1331,7 +1331,7 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) ...@@ -1331,7 +1331,7 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
of_property_read_string(np, "cm-thermal-zone", &desc->thermal_zone); of_property_read_string(np, "cm-thermal-zone", &desc->thermal_zone);
of_property_read_u32(np, "cm-battery-cold", &desc->temp_min); of_property_read_u32(np, "cm-battery-cold", &desc->temp_min);
if (of_get_property(np, "cm-battery-cold-in-minus", NULL)) if (of_property_read_bool(np, "cm-battery-cold-in-minus"))
desc->temp_min *= -1; desc->temp_min *= -1;
of_property_read_u32(np, "cm-battery-hot", &desc->temp_max); of_property_read_u32(np, "cm-battery-hot", &desc->temp_max);
of_property_read_u32(np, "cm-battery-temp-diff", &desc->temp_diff); of_property_read_u32(np, "cm-battery-temp-diff", &desc->temp_diff);
......
This diff is collapsed.
...@@ -598,7 +598,7 @@ static void lp8727_remove(struct i2c_client *cl) ...@@ -598,7 +598,7 @@ static void lp8727_remove(struct i2c_client *cl)
lp8727_unregister_psy(pchg); lp8727_unregister_psy(pchg);
} }
static const struct of_device_id lp8727_dt_ids[] = { static const struct of_device_id lp8727_dt_ids[] __maybe_unused = {
{ .compatible = "ti,lp8727", }, { .compatible = "ti,lp8727", },
{ } { }
}; };
......
...@@ -908,7 +908,7 @@ static const struct i2c_device_id ltc4162l_i2c_id_table[] = { ...@@ -908,7 +908,7 @@ static const struct i2c_device_id ltc4162l_i2c_id_table[] = {
}; };
MODULE_DEVICE_TABLE(i2c, ltc4162l_i2c_id_table); MODULE_DEVICE_TABLE(i2c, ltc4162l_i2c_id_table);
static const struct of_device_id ltc4162l_of_match[] = { static const struct of_device_id ltc4162l_of_match[] __maybe_unused = {
{ .compatible = "lltc,ltc4162-l", }, { .compatible = "lltc,ltc4162-l", },
{ }, { },
}; };
......
...@@ -388,7 +388,7 @@ static int __power_supply_get_supplier_property(struct device *dev, void *_data) ...@@ -388,7 +388,7 @@ static int __power_supply_get_supplier_property(struct device *dev, void *_data)
struct psy_get_supplier_prop_data *data = _data; struct psy_get_supplier_prop_data *data = _data;
if (__power_supply_is_supplied_by(epsy, data->psy)) if (__power_supply_is_supplied_by(epsy, data->psy))
if (!epsy->desc->get_property(epsy, data->psp, data->val)) if (!power_supply_get_property(epsy, data->psp, data->val))
return 1; /* Success */ return 1; /* Success */
return 0; /* Continue iterating */ return 0; /* Continue iterating */
...@@ -832,6 +832,133 @@ void power_supply_put_battery_info(struct power_supply *psy, ...@@ -832,6 +832,133 @@ void power_supply_put_battery_info(struct power_supply *psy,
} }
EXPORT_SYMBOL_GPL(power_supply_put_battery_info); EXPORT_SYMBOL_GPL(power_supply_put_battery_info);
const enum power_supply_property power_supply_battery_info_properties[] = {
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
POWER_SUPPLY_PROP_TEMP_MIN,
POWER_SUPPLY_PROP_TEMP_MAX,
};
EXPORT_SYMBOL_GPL(power_supply_battery_info_properties);
const size_t power_supply_battery_info_properties_size = ARRAY_SIZE(power_supply_battery_info_properties);
EXPORT_SYMBOL_GPL(power_supply_battery_info_properties_size);
bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info,
enum power_supply_property psp)
{
if (!info)
return false;
switch (psp) {
case POWER_SUPPLY_PROP_TECHNOLOGY:
return info->technology != POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
return info->energy_full_design_uwh >= 0;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
return info->charge_full_design_uah >= 0;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
return info->voltage_min_design_uv >= 0;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
return info->voltage_max_design_uv >= 0;
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
return info->precharge_current_ua >= 0;
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return info->charge_term_current_ua >= 0;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
return info->constant_charge_current_max_ua >= 0;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
return info->constant_charge_voltage_max_uv >= 0;
case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN:
return info->temp_ambient_alert_min > INT_MIN;
case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX:
return info->temp_ambient_alert_max < INT_MAX;
case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
return info->temp_alert_min > INT_MIN;
case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
return info->temp_alert_max < INT_MAX;
case POWER_SUPPLY_PROP_TEMP_MIN:
return info->temp_min > INT_MIN;
case POWER_SUPPLY_PROP_TEMP_MAX:
return info->temp_max < INT_MAX;
default:
return false;
}
}
EXPORT_SYMBOL_GPL(power_supply_battery_info_has_prop);
int power_supply_battery_info_get_prop(struct power_supply_battery_info *info,
enum power_supply_property psp,
union power_supply_propval *val)
{
if (!info)
return -EINVAL;
if (!power_supply_battery_info_has_prop(info, psp))
return -EINVAL;
switch (psp) {
case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = info->technology;
return 0;
case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
val->intval = info->energy_full_design_uwh;
return 0;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
val->intval = info->charge_full_design_uah;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
val->intval = info->voltage_min_design_uv;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
val->intval = info->voltage_max_design_uv;
return 0;
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
val->intval = info->precharge_current_ua;
return 0;
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
val->intval = info->charge_term_current_ua;
return 0;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
val->intval = info->constant_charge_current_max_ua;
return 0;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
val->intval = info->constant_charge_voltage_max_uv;
return 0;
case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN:
val->intval = info->temp_ambient_alert_min;
return 0;
case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX:
val->intval = info->temp_ambient_alert_max;
return 0;
case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
val->intval = info->temp_alert_min;
return 0;
case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
val->intval = info->temp_alert_max;
return 0;
case POWER_SUPPLY_PROP_TEMP_MIN:
val->intval = info->temp_min;
return 0;
case POWER_SUPPLY_PROP_TEMP_MAX:
val->intval = info->temp_max;
return 0;
default:
return -EINVAL;
}
}
EXPORT_SYMBOL_GPL(power_supply_battery_info_get_prop);
/** /**
* power_supply_temp2resist_simple() - find the battery internal resistance * power_supply_temp2resist_simple() - find the battery internal resistance
* percent from temperature * percent from temperature
...@@ -1046,6 +1173,22 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info, ...@@ -1046,6 +1173,22 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
} }
EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range); EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range);
static bool psy_has_property(const struct power_supply_desc *psy_desc,
enum power_supply_property psp)
{
bool found = false;
int i;
for (i = 0; i < psy_desc->num_properties; i++) {
if (psy_desc->properties[i] == psp) {
found = true;
break;
}
}
return found;
}
int power_supply_get_property(struct power_supply *psy, int power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp, enum power_supply_property psp,
union power_supply_propval *val) union power_supply_propval *val)
...@@ -1056,7 +1199,12 @@ int power_supply_get_property(struct power_supply *psy, ...@@ -1056,7 +1199,12 @@ int power_supply_get_property(struct power_supply *psy,
return -ENODEV; return -ENODEV;
} }
return psy->desc->get_property(psy, psp, val); if (psy_has_property(psy->desc, psp))
return psy->desc->get_property(psy, psp, val);
else if (power_supply_battery_info_has_prop(psy->battery_info, psp))
return power_supply_battery_info_get_prop(psy->battery_info, psp, val);
else
return -EINVAL;
} }
EXPORT_SYMBOL_GPL(power_supply_get_property); EXPORT_SYMBOL_GPL(power_supply_get_property);
...@@ -1117,22 +1265,6 @@ void power_supply_unreg_notifier(struct notifier_block *nb) ...@@ -1117,22 +1265,6 @@ void power_supply_unreg_notifier(struct notifier_block *nb)
} }
EXPORT_SYMBOL_GPL(power_supply_unreg_notifier); EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
static bool psy_has_property(const struct power_supply_desc *psy_desc,
enum power_supply_property psp)
{
bool found = false;
int i;
for (i = 0; i < psy_desc->num_properties; i++) {
if (psy_desc->properties[i] == psp) {
found = true;
break;
}
}
return found;
}
#ifdef CONFIG_THERMAL #ifdef CONFIG_THERMAL
static int power_supply_read_temp(struct thermal_zone_device *tzd, static int power_supply_read_temp(struct thermal_zone_device *tzd,
int *temp) int *temp)
...@@ -1255,6 +1387,17 @@ __power_supply_register(struct device *parent, ...@@ -1255,6 +1387,17 @@ __power_supply_register(struct device *parent,
goto check_supplies_failed; goto check_supplies_failed;
} }
/*
* Expose constant battery info, if it is available. While there are
* some chargers accessing constant battery data, we only want to
* expose battery data to userspace for battery devices.
*/
if (desc->type == POWER_SUPPLY_TYPE_BATTERY) {
rc = power_supply_get_battery_info(psy, &psy->battery_info);
if (rc && rc != -ENODEV && rc != -ENOENT)
goto check_supplies_failed;
}
spin_lock_init(&psy->changed_lock); spin_lock_init(&psy->changed_lock);
rc = device_add(dev); rc = device_add(dev);
if (rc) if (rc)
......
...@@ -221,9 +221,10 @@ static struct power_supply_attr power_supply_attrs[] = { ...@@ -221,9 +221,10 @@ static struct power_supply_attr power_supply_attrs[] = {
POWER_SUPPLY_ATTR(MANUFACTURER), POWER_SUPPLY_ATTR(MANUFACTURER),
POWER_SUPPLY_ATTR(SERIAL_NUMBER), POWER_SUPPLY_ATTR(SERIAL_NUMBER),
}; };
#define POWER_SUPPLY_ATTR_CNT ARRAY_SIZE(power_supply_attrs)
static struct attribute * static struct attribute *
__power_supply_attrs[ARRAY_SIZE(power_supply_attrs) + 1]; __power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1];
static struct power_supply_attr *to_ps_attr(struct device_attribute *attr) static struct power_supply_attr *to_ps_attr(struct device_attribute *attr)
{ {
...@@ -380,6 +381,9 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj, ...@@ -380,6 +381,9 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
} }
} }
if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
return mode;
return 0; return 0;
} }
...@@ -461,6 +465,10 @@ static int add_prop_uevent(const struct device *dev, struct kobj_uevent_env *env ...@@ -461,6 +465,10 @@ static int add_prop_uevent(const struct device *dev, struct kobj_uevent_env *env
int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env) int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
{ {
const struct power_supply *psy = dev_get_drvdata(dev); const struct power_supply *psy = dev_get_drvdata(dev);
const enum power_supply_property *battery_props =
power_supply_battery_info_properties;
unsigned long psy_drv_properties[POWER_SUPPLY_ATTR_CNT /
sizeof(unsigned long) + 1] = {0};
int ret = 0, j; int ret = 0, j;
char *prop_buf; char *prop_buf;
...@@ -482,12 +490,25 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env) ...@@ -482,12 +490,25 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
goto out; goto out;
for (j = 0; j < psy->desc->num_properties; j++) { for (j = 0; j < psy->desc->num_properties; j++) {
set_bit(psy->desc->properties[j], psy_drv_properties);
ret = add_prop_uevent(dev, env, psy->desc->properties[j], ret = add_prop_uevent(dev, env, psy->desc->properties[j],
prop_buf); prop_buf);
if (ret) if (ret)
goto out; goto out;
} }
for (j = 0; j < power_supply_battery_info_properties_size; j++) {
if (test_bit(battery_props[j], psy_drv_properties))
continue;
if (!power_supply_battery_info_has_prop(psy->battery_info,
battery_props[j]))
continue;
ret = add_prop_uevent(dev, env, battery_props[j],
prop_buf);
if (ret)
goto out;
}
out: out:
free_page((unsigned long)prop_buf); free_page((unsigned long)prop_buf);
......
...@@ -335,6 +335,20 @@ static int rk817_bat_calib_cap(struct rk817_charger *charger) ...@@ -335,6 +335,20 @@ static int rk817_bat_calib_cap(struct rk817_charger *charger)
charger->fcc_mah * 1000); charger->fcc_mah * 1000);
} }
/*
* Set the SOC to 0 if we are below the minimum system voltage.
*/
if (volt_avg <= charger->bat_voltage_min_design_uv) {
charger->soc = 0;
charge_now_adc = CHARGE_TO_ADC(0, charger->res_div);
put_unaligned_be32(charge_now_adc, bulk_reg);
regmap_bulk_write(rk808->regmap,
RK817_GAS_GAUGE_Q_INIT_H3, bulk_reg, 4);
dev_warn(charger->dev,
"Battery voltage %d below minimum voltage %d\n",
volt_avg, charger->bat_voltage_min_design_uv);
}
rk817_record_battery_nvram_values(charger); rk817_record_battery_nvram_values(charger);
return 0; return 0;
...@@ -710,9 +724,10 @@ static int rk817_read_battery_nvram_values(struct rk817_charger *charger) ...@@ -710,9 +724,10 @@ static int rk817_read_battery_nvram_values(struct rk817_charger *charger)
/* /*
* Read the nvram for state of charge. Sanity check for values greater * Read the nvram for state of charge. Sanity check for values greater
* than 100 (10000). If the value is off it should get corrected * than 100 (10000) or less than 0, because other things (BSP kernels,
* automatically when the voltage drops to the min (soc is 0) or when * U-Boot, or even i2cset) can write to this register. If the value is
* the battery is full (soc is 100). * off it should get corrected automatically when the voltage drops to
* the min (soc is 0) or when the battery is full (soc is 100).
*/ */
ret = regmap_bulk_read(charger->rk808->regmap, ret = regmap_bulk_read(charger->rk808->regmap,
RK817_GAS_GAUGE_BAT_R1, bulk_reg, 3); RK817_GAS_GAUGE_BAT_R1, bulk_reg, 3);
...@@ -721,6 +736,8 @@ static int rk817_read_battery_nvram_values(struct rk817_charger *charger) ...@@ -721,6 +736,8 @@ static int rk817_read_battery_nvram_values(struct rk817_charger *charger)
charger->soc = get_unaligned_le24(bulk_reg); charger->soc = get_unaligned_le24(bulk_reg);
if (charger->soc > 10000) if (charger->soc > 10000)
charger->soc = 10000; charger->soc = 10000;
if (charger->soc < 0)
charger->soc = 0;
return 0; return 0;
} }
...@@ -731,8 +748,8 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger, ...@@ -731,8 +748,8 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger,
{ {
struct rk808 *rk808 = charger->rk808; struct rk808 *rk808 = charger->rk808;
u8 bulk_reg[4]; u8 bulk_reg[4];
u32 boot_voltage, boot_charge_mah, tmp; u32 boot_voltage, boot_charge_mah;
int ret, reg, off_time; int ret, reg, off_time, tmp;
bool first_boot; bool first_boot;
/* /*
...@@ -785,10 +802,12 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger, ...@@ -785,10 +802,12 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger,
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3,
bulk_reg, 4); bulk_reg, 4);
tmp = get_unaligned_be32(bulk_reg); tmp = get_unaligned_be32(bulk_reg);
if (tmp < 0)
tmp = 0;
boot_charge_mah = ADC_TO_CHARGE_UAH(tmp, boot_charge_mah = ADC_TO_CHARGE_UAH(tmp,
charger->res_div) / 1000; charger->res_div) / 1000;
/* /*
* Check if the columb counter has been off for more than 300 * Check if the columb counter has been off for more than 30
* minutes as it tends to drift downward. If so, re-init soc * minutes as it tends to drift downward. If so, re-init soc
* with the boot voltage instead. Note the unit values for the * with the boot voltage instead. Note the unit values for the
* OFF_CNT register appear to be in decaminutes and stops * OFF_CNT register appear to be in decaminutes and stops
...@@ -799,7 +818,7 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger, ...@@ -799,7 +818,7 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger,
* than 0 on a reboot anyway. * than 0 on a reboot anyway.
*/ */
regmap_read(rk808->regmap, RK817_GAS_GAUGE_OFF_CNT, &off_time); regmap_read(rk808->regmap, RK817_GAS_GAUGE_OFF_CNT, &off_time);
if (off_time >= 30) { if (off_time >= 3) {
regmap_bulk_read(rk808->regmap, regmap_bulk_read(rk808->regmap,
RK817_GAS_GAUGE_PWRON_VOL_H, RK817_GAS_GAUGE_PWRON_VOL_H,
bulk_reg, 2); bulk_reg, 2);
...@@ -816,19 +835,6 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger, ...@@ -816,19 +835,6 @@ rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger,
} }
} }
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_PWRON_VOL_H,
bulk_reg, 2);
tmp = get_unaligned_be16(bulk_reg);
boot_voltage = (charger->voltage_k * tmp) + 1000 * charger->voltage_b;
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3,
bulk_reg, 4);
tmp = get_unaligned_be32(bulk_reg);
boot_charge_mah = ADC_TO_CHARGE_UAH(tmp, charger->res_div) / 1000;
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_OCV_VOL_H,
bulk_reg, 2);
tmp = get_unaligned_be16(bulk_reg);
boot_voltage = (charger->voltage_k * tmp) + 1000 * charger->voltage_b;
/* /*
* Now we have our full charge capacity and soc, init the columb * Now we have our full charge capacity and soc, init the columb
* counter. * counter.
......
...@@ -1722,7 +1722,7 @@ static const struct i2c_device_id rt9455_i2c_id_table[] = { ...@@ -1722,7 +1722,7 @@ static const struct i2c_device_id rt9455_i2c_id_table[] = {
}; };
MODULE_DEVICE_TABLE(i2c, rt9455_i2c_id_table); MODULE_DEVICE_TABLE(i2c, rt9455_i2c_id_table);
static const struct of_device_id rt9455_of_match[] = { static const struct of_device_id rt9455_of_match[] __maybe_unused = {
{ .compatible = "richtek,rt9455", }, { .compatible = "richtek,rt9455", },
{ }, { },
}; };
......
...@@ -1126,7 +1126,7 @@ static int twl4030_bci_remove(struct platform_device *pdev) ...@@ -1126,7 +1126,7 @@ static int twl4030_bci_remove(struct platform_device *pdev)
return 0; return 0;
} }
static const struct of_device_id twl_bci_of_match[] = { static const struct of_device_id twl_bci_of_match[] __maybe_unused = {
{.compatible = "ti,twl4030-bci", }, {.compatible = "ti,twl4030-bci", },
{ } { }
}; };
......
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2012, Anish Kumar <anish198519851985@gmail.com>
*/
#ifndef GENERIC_ADC_BATTERY_H
#define GENERIC_ADC_BATTERY_H
/**
* struct gab_platform_data - platform_data for generic adc iio battery driver.
* @battery_info: recommended structure to specify static power supply
* parameters
* @cal_charge: calculate charge level.
* @jitter_delay: delay required after the interrupt to check battery
* status.Default set is 10ms.
*/
struct gab_platform_data {
struct power_supply_info battery_info;
int (*cal_charge)(long value);
int jitter_delay;
};
#endif /* GENERIC_ADC_BATTERY_H */
...@@ -301,6 +301,7 @@ struct power_supply { ...@@ -301,6 +301,7 @@ struct power_supply {
bool initialized; bool initialized;
bool removing; bool removing;
atomic_t use_cnt; atomic_t use_cnt;
struct power_supply_battery_info *battery_info;
#ifdef CONFIG_THERMAL #ifdef CONFIG_THERMAL
struct thermal_zone_device *tzd; struct thermal_zone_device *tzd;
struct thermal_cooling_device *tcd; struct thermal_cooling_device *tcd;
...@@ -791,10 +792,17 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property) ...@@ -791,10 +792,17 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property)
{ return NULL; } { return NULL; }
#endif /* CONFIG_OF */ #endif /* CONFIG_OF */
extern const enum power_supply_property power_supply_battery_info_properties[];
extern const size_t power_supply_battery_info_properties_size;
extern int power_supply_get_battery_info(struct power_supply *psy, extern int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info **info_out); struct power_supply_battery_info **info_out);
extern void power_supply_put_battery_info(struct power_supply *psy, extern void power_supply_put_battery_info(struct power_supply *psy,
struct power_supply_battery_info *info); struct power_supply_battery_info *info);
extern bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info,
enum power_supply_property psp);
extern int power_supply_battery_info_get_prop(struct power_supply_battery_info *info,
enum power_supply_property psp,
union power_supply_propval *val);
extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
int table_len, int ocv); int table_len, int ocv);
extern struct power_supply_battery_ocv_table * extern struct power_supply_battery_ocv_table *
......
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