linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: bq256xx: Support to disable charger
@ 2023-03-09  6:41 Hermes Zhang
  0 siblings, 0 replies; 61+ messages in thread
From: Hermes Zhang @ 2023-03-09  6:41 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: kernel, Hermes Zhang, linux-pm, linux-kernel

To be able to control the charging process flexible, we need to able to
disable the charger. This commit will allow to disable the charger by
"echo 1 > /sys/class/power_supply/bq256xx-charger/charge_type"
(1 = POWER_SUPPLY_CHARGE_TYPE_NONE) and enable the charger by set it to
2/3 (POWER_SUPPLY_CHARGE_TYPE_TRICKLE/POWER_SUPPLY_CHARGE_TYPE_FAST)

Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
---
 drivers/power/supply/bq256xx_charger.c | 40 ++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index 9cf4936440c9..e624834ae66c 100644
--- a/drivers/power/supply/bq256xx_charger.c
+++ b/drivers/power/supply/bq256xx_charger.c
@@ -70,6 +70,9 @@
 #define BQ25611D_VBATREG_THRESH_uV	4290000
 #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_STEP_uA		60000
 #define BQ256XX_ITERM_OFFSET_uA		60000
@@ -259,6 +262,7 @@ struct bq256xx_device {
  * @bq256xx_set_iterm: pointer to instance specific set_iterm function
  * @bq256xx_set_iprechg: pointer to instance specific set_iprechg 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_iindpm: default iindpm value in microamps
@@ -290,6 +294,7 @@ struct bq256xx_chip_info {
 	int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm);
 	int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg);
 	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_iindpm;
@@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq,
 	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)
 {
 	unsigned int charge_current_limit;
@@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy,
 			return ret;
 		break;
 
+	case POWER_SUPPLY_PROP_CHARGE_TYPE:
+		ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval);
+		if (ret)
+			return ret;
+		break;
+
 	default:
 		break;
 	}
@@ -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_STATUS:
 	case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
+	case POWER_SUPPLY_PROP_CHARGE_TYPE:
 		return true;
 	default:
 		return false;
@@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq256xx_set_term_curr,
 		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq256xx_set_term_curr,
 		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq256xx_set_term_curr,
 		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq256xx_set_term_curr,
 		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq256xx_set_term_curr,
 		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq25618_619_set_term_curr,
 		.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
 		.bq256xx_set_iterm = bq25618_619_set_term_curr,
 		.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
 		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 00/11] Add DT support for generic ADC battery
@ 2023-03-09 22:50 Sebastian Reichel
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
                   ` (10 more replies)
  0 siblings, 11 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Hi,

This series cleans up the generic ADC battery driver and adds
devicetree support. The plan is to use the driver to add upstream
support for a handheld thermal camera.

Instead of reading and exposing the monitored battery data manually
I started the series with an addition to the power-supply core,
which allows automatic handling of the static battery information.
It simplifies the generic-adc-battery driver a lot and should also
be useful for other battery drivers.

-- Sebastian

Sebastian Reichel (11):
  dt-bindings: power: supply: adc-battery: add binding
  power: supply: core: auto-exposure of simple-battery data
  power: supply: generic-adc-battery: convert to managed resources
  power: supply: generic-adc-battery: fix unit scaling
  power: supply: generic-adc-battery: drop jitter delay support
  power: supply: generic-adc-battery: drop charge now support
  power: supply: generic-adc-battery: drop memory alloc error message
  power: supply: generic-adc-battery: use simple-battery API
  power: supply: generic-adc-battery: simplify read_channel logic
  power: supply: generic-adc-battery: add DT support
  power: supply: generic-adc-battery: update copyright info

 .../bindings/power/supply/adc-battery.yaml    |  67 ++++++
 drivers/power/supply/generic-adc-battery.c    | 221 +++++-------------
 drivers/power/supply/power_supply_core.c      | 153 ++++++++++--
 drivers/power/supply/power_supply_sysfs.c     |  16 ++
 include/linux/power/generic-adc-battery.h     |  23 --
 include/linux/power_supply.h                  |  31 +++
 6 files changed, 301 insertions(+), 210 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/supply/adc-battery.yaml
 delete mode 100644 include/linux/power/generic-adc-battery.h

-- 
2.39.2


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:14   ` Linus Walleij
                     ` (2 more replies)
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
                   ` (9 subsequent siblings)
  10 siblings, 3 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Add binding for a battery that is only monitored via ADC
channels and simple status GPIOs.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 .../bindings/power/supply/adc-battery.yaml    | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/adc-battery.yaml

diff --git a/Documentation/devicetree/bindings/power/supply/adc-battery.yaml b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml
new file mode 100644
index 000000000000..9d478bf9d2ee
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml
@@ -0,0 +1,67 @@
+# 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, which only reports (in circuit) voltage and optionally
+  current via an ADC channel.
+
+allOf:
+  - $ref: power-supply.yaml#
+
+properties:
+  compatible:
+    const: adc-battery
+
+  charged-gpios:
+    description:
+      GPIO which signals that the battery is fully charged.
+    maxItems: 1
+
+  io-channels:
+    minItems: 1
+    maxItems: 3
+
+  io-channel-names:
+    oneOf:
+      - const: voltage
+      - items:
+          - const: voltage
+          - enum:
+              - current
+              - power
+      - items:
+          - const: voltage
+          - const: current
+          - const: power
+
+  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>;
+    };
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  1:36   ` kernel test robot
                     ` (3 more replies)
  2023-03-09 22:50 ` [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Sebastian Reichel
                   ` (8 subsequent siblings)
  10 siblings, 4 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Add support for automatically exposing data from the
simple-battery firmware node with a single configuration
option in the power-supply device.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/power_supply_core.c  | 153 +++++++++++++++++++---
 drivers/power/supply/power_supply_sysfs.c |  16 +++
 include/linux/power_supply.h              |  31 +++++
 3 files changed, 181 insertions(+), 19 deletions(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index f3d7c1da299f..c3684ec46b3f 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -388,7 +388,7 @@ static int __power_supply_get_supplier_property(struct device *dev, void *_data)
 	struct psy_get_supplier_prop_data *data = _data;
 
 	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 0; /* Continue iterating */
@@ -832,6 +832,111 @@ void power_supply_put_battery_info(struct power_supply *psy,
 }
 EXPORT_SYMBOL_GPL(power_supply_put_battery_info);
 
+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
  * percent from temperature
@@ -1046,6 +1151,22 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
 }
 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,
 			    enum power_supply_property psp,
 			    union power_supply_propval *val)
@@ -1056,9 +1177,13 @@ int power_supply_get_property(struct power_supply *psy,
 		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(psy->desc->expose_battery_info)
+		return power_supply_battery_info_get_prop(psy->battery_info, psp, val);
+	else
+		return -EINVAL;
 }
-EXPORT_SYMBOL_GPL(power_supply_get_property);
 
 int power_supply_set_property(struct power_supply *psy,
 			    enum power_supply_property psp,
@@ -1117,22 +1242,6 @@ void power_supply_unreg_notifier(struct notifier_block *nb)
 }
 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
 static int power_supply_read_temp(struct thermal_zone_device *tzd,
 		int *temp)
@@ -1255,6 +1364,12 @@ __power_supply_register(struct device *parent,
 		goto check_supplies_failed;
 	}
 
+	if (psy->desc->expose_battery_info) {
+		rc = power_supply_get_battery_info(psy, &psy->battery_info);
+		if (rc)
+			goto check_supplies_failed;
+	}
+
 	spin_lock_init(&psy->changed_lock);
 	rc = device_add(dev);
 	if (rc)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index c228205e0953..8822a17f9589 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -380,6 +380,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
 		}
 	}
 
+	if (psy->desc->expose_battery_info) {
+		if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
+			return mode;
+	}
+
 	return 0;
 }
 
@@ -488,6 +493,17 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
 			goto out;
 	}
 
+	if (psy->desc->expose_battery_info) {
+		for (j = 0; j < ARRAY_SIZE(power_supply_battery_info_properties); j++) {
+			if (!power_supply_battery_info_has_prop(psy->battery_info, power_supply_battery_info_properties[j]))
+				continue;
+			ret = add_prop_uevent(dev, env, power_supply_battery_info_properties[j],
+				      prop_buf);
+			if (ret)
+				goto out;
+		}
+	}
+
 out:
 	free_page((unsigned long)prop_buf);
 
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index aa2c4a7c4826..de0ea8320f3d 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -275,6 +275,13 @@ struct power_supply_desc {
 	 * sensors or other supplies.
 	 */
 	bool no_thermal;
+	/*
+	 * Set if constant battery information from firmware should be
+	 * exposed automatically. No driver specific code is required
+	 * in that case. If the driver also handles a property provided
+	 * by constant firmware data, the driver's handler is preferred.
+	 */
+	bool expose_battery_info;
 	/* For APM emulation, think legacy userspace. */
 	int use_for_apm;
 };
@@ -301,6 +308,7 @@ struct power_supply {
 	bool initialized;
 	bool removing;
 	atomic_t use_cnt;
+	struct power_supply_battery_info *battery_info;
 #ifdef CONFIG_THERMAL
 	struct thermal_zone_device *tzd;
 	struct thermal_cooling_device *tcd;
@@ -766,6 +774,24 @@ struct power_supply_battery_info {
 	int bti_resistance_tolerance;
 };
 
+static 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,
+};
+
 extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
@@ -795,6 +821,11 @@ extern int power_supply_get_battery_info(struct power_supply *psy,
 					 struct power_supply_battery_info **info_out);
 extern void power_supply_put_battery_info(struct power_supply *psy,
 					  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,
 				       int table_len, int ocv);
 extern struct power_supply_battery_ocv_table *
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:21   ` Linus Walleij
  2023-03-13  7:14   ` Matti Vaittinen
  2023-03-09 22:50 ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
                   ` (7 subsequent siblings)
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Convert driver to use managed resources to simplify driver code.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 81 ++++++----------------
 1 file changed, 23 insertions(+), 58 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 66039c665dd1..917bd2a6cc52 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -23,6 +23,7 @@
 #include <linux/iio/consumer.h>
 #include <linux/iio/types.h>
 #include <linux/power/generic-adc-battery.h>
+#include <linux/devm-helpers.h>
 
 #define JITTER_DEFAULT 10 /* hope 10ms is enough */
 
@@ -266,14 +267,13 @@ static int gab_probe(struct platform_device *pdev)
 	 * copying the static properties and allocating extra memory for holding
 	 * the extra configurable properties received from platform data.
 	 */
-	properties = kcalloc(ARRAY_SIZE(gab_props) +
-			     ARRAY_SIZE(gab_chan_name),
-			     sizeof(*properties),
-			     GFP_KERNEL);
-	if (!properties) {
-		ret = -ENOMEM;
-		goto first_mem_fail;
-	}
+	properties = devm_kcalloc(&pdev->dev,
+				  ARRAY_SIZE(gab_props) +
+				  ARRAY_SIZE(gab_chan_name),
+				  sizeof(*properties),
+				  GFP_KERNEL);
+	if (!properties)
+		return -ENOMEM;
 
 	memcpy(properties, gab_props, sizeof(gab_props));
 
@@ -282,12 +282,13 @@ static int gab_probe(struct platform_device *pdev)
 	 * based on the channel supported by consumer device.
 	 */
 	for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
-		adc_bat->channel[chan] = iio_channel_get(&pdev->dev,
-							 gab_chan_name[chan]);
+		adc_bat->channel[chan] = devm_iio_channel_get(&pdev->dev, gab_chan_name[chan]);
 		if (IS_ERR(adc_bat->channel[chan])) {
 			ret = PTR_ERR(adc_bat->channel[chan]);
+			if (ret != -ENODEV)
+				return dev_err_probe(&pdev->dev, ret, "Failed to get ADC channel %s\n", gab_chan_name[chan]);
 			adc_bat->channel[chan] = NULL;
-		} else {
+		} else if (adc_bat->channel[chan]) {
 			/* copying properties for supported channels only */
 			int index2;
 
@@ -302,10 +303,8 @@ static int gab_probe(struct platform_device *pdev)
 	}
 
 	/* none of the channels are supported so let's bail out */
-	if (!any) {
-		ret = -ENODEV;
-		goto second_mem_fail;
-	}
+	if (!any)
+		return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get any ADC channel\n");
 
 	/*
 	 * Total number of properties is equal to static properties
@@ -316,25 +315,24 @@ static int gab_probe(struct platform_device *pdev)
 	psy_desc->properties = properties;
 	psy_desc->num_properties = index;
 
-	adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
-	if (IS_ERR(adc_bat->psy)) {
-		ret = PTR_ERR(adc_bat->psy);
-		goto err_reg_fail;
-	}
+	adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
+	if (IS_ERR(adc_bat->psy))
+		return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->psy), "Failed to register power-supply device\n");
 
-	INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
+	ret = devm_delayed_work_autocancel(&pdev->dev, &adc_bat->bat_work, gab_work);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work\n");
 
-	adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev,
-							   "charged", GPIOD_IN);
+	adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, "charged", GPIOD_IN);
 	if (adc_bat->charge_finished) {
 		int irq;
 
 		irq = gpiod_to_irq(adc_bat->charge_finished);
-		ret = request_any_context_irq(irq, gab_charged,
+		ret = devm_request_any_context_irq(&pdev->dev, irq, gab_charged,
 				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
 				"battery charged", adc_bat);
 		if (ret < 0)
-			goto gpio_req_fail;
+			return dev_err_probe(&pdev->dev, ret, "Failed to register irq\n");
 	}
 
 	platform_set_drvdata(pdev, adc_bat);
@@ -343,38 +341,6 @@ static int gab_probe(struct platform_device *pdev)
 	schedule_delayed_work(&adc_bat->bat_work,
 			msecs_to_jiffies(0));
 	return 0;
-
-gpio_req_fail:
-	power_supply_unregister(adc_bat->psy);
-err_reg_fail:
-	for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
-		if (adc_bat->channel[chan])
-			iio_channel_release(adc_bat->channel[chan]);
-	}
-second_mem_fail:
-	kfree(properties);
-first_mem_fail:
-	return ret;
-}
-
-static int gab_remove(struct platform_device *pdev)
-{
-	int chan;
-	struct gab *adc_bat = platform_get_drvdata(pdev);
-
-	power_supply_unregister(adc_bat->psy);
-
-	if (adc_bat->charge_finished)
-		free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat);
-
-	for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
-		if (adc_bat->channel[chan])
-			iio_channel_release(adc_bat->channel[chan]);
-	}
-
-	kfree(adc_bat->psy_desc.properties);
-	cancel_delayed_work_sync(&adc_bat->bat_work);
-	return 0;
 }
 
 static int __maybe_unused gab_suspend(struct device *dev)
@@ -408,7 +374,6 @@ static struct platform_driver gab_driver = {
 		.pm	= &gab_pm_ops,
 	},
 	.probe		= gab_probe,
-	.remove		= gab_remove,
 };
 module_platform_driver(gab_driver);
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (2 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:23   ` Linus Walleij
  2023-03-13  7:52   ` Matti Vaittinen
  2023-03-09 22:50 ` [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support Sebastian Reichel
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

power-supply properties are reported in µV, µA and µW.
The IIO API provides mV, mA, mW, so the values need to
be multiplied by 1000.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 917bd2a6cc52..535972a332b3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -136,6 +136,9 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
 			result);
 	if (ret < 0)
 		pr_err("read channel error\n");
+	else
+		*result *= 1000;
+
 	return ret;
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (3 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:24   ` Linus Walleij
  2023-03-09 22:50 ` [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support Sebastian Reichel
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Drop support for configuring IRQ jitter delay by using big
enough fixed value.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 13 ++++---------
 include/linux/power/generic-adc-battery.h  |  3 ---
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 535972a332b3..e20894460d7f 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -227,12 +227,10 @@ static void gab_work(struct work_struct *work)
 static irqreturn_t gab_charged(int irq, void *dev_id)
 {
 	struct gab *adc_bat = dev_id;
-	struct gab_platform_data *pdata = adc_bat->pdata;
-	int delay;
 
-	delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
 	schedule_delayed_work(&adc_bat->bat_work,
-			msecs_to_jiffies(delay));
+			      msecs_to_jiffies(JITTER_DEFAULT));
+
 	return IRQ_HANDLED;
 }
 
@@ -358,14 +356,11 @@ static int __maybe_unused gab_suspend(struct device *dev)
 static int __maybe_unused gab_resume(struct device *dev)
 {
 	struct gab *adc_bat = dev_get_drvdata(dev);
-	struct gab_platform_data *pdata = adc_bat->pdata;
-	int delay;
-
-	delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
 
 	/* Schedule timer to check current status */
 	schedule_delayed_work(&adc_bat->bat_work,
-			msecs_to_jiffies(delay));
+			      msecs_to_jiffies(JITTER_DEFAULT));
+
 	return 0;
 }
 
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index c68cbf34cd34..50eb4bf28286 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -11,13 +11,10 @@
  * @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 */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (4 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:29   ` Linus Walleij
  2023-03-09 22:50 ` [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Sebastian Reichel
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Drop CHARGE_NOW support, which requires a platform specific
calculation method.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 4 ----
 include/linux/power/generic-adc-battery.h  | 2 --
 2 files changed, 6 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index e20894460d7f..d07eeb7d46d3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -72,7 +72,6 @@ static const enum power_supply_property gab_props[] = {
 	POWER_SUPPLY_PROP_STATUS,
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
-	POWER_SUPPLY_PROP_CHARGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -166,9 +165,6 @@ static int gab_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
 		val->intval = 0;
 		break;
-	case POWER_SUPPLY_PROP_CHARGE_NOW:
-		val->intval = pdata->cal_charge(result);
-		break;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 	case POWER_SUPPLY_PROP_POWER_NOW:
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index 50eb4bf28286..54434e4304d3 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -10,11 +10,9 @@
  * 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.
  */
 struct gab_platform_data {
 	struct power_supply_info battery_info;
-	int	(*cal_charge)(long value);
 };
 
 #endif /* GENERIC_ADC_BATTERY_H */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (5 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:29   ` Linus Walleij
  2023-03-13  7:50   ` Matti Vaittinen
  2023-03-09 22:50 ` [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API Sebastian Reichel
                   ` (3 subsequent siblings)
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Error printing happens automatically for memory allocation problems.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index d07eeb7d46d3..771e5cfc49c3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -243,10 +243,8 @@ static int gab_probe(struct platform_device *pdev)
 	bool any = false;
 
 	adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
-	if (!adc_bat) {
-		dev_err(&pdev->dev, "failed to allocate memory\n");
+	if (!adc_bat)
 		return -ENOMEM;
-	}
 
 	psy_cfg.drv_data = adc_bat;
 	psy_desc = &adc_bat->psy_desc;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (6 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:30   ` Linus Walleij
  2023-03-09 22:50 ` [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Sebastian Reichel
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Use standard simple-battery API for constant battery
information like min and max voltage. This simplifies
the driver a lot and brings automatic support for DT.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 65 ++--------------------
 include/linux/power/generic-adc-battery.h  | 18 ------
 2 files changed, 5 insertions(+), 78 deletions(-)
 delete mode 100644 include/linux/power/generic-adc-battery.h

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 771e5cfc49c3..fc6fcfda1ef2 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -22,7 +22,6 @@
 #include <linux/slab.h>
 #include <linux/iio/consumer.h>
 #include <linux/iio/types.h>
-#include <linux/power/generic-adc-battery.h>
 #include <linux/devm-helpers.h>
 
 #define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -48,9 +47,7 @@ struct gab {
 	struct power_supply		*psy;
 	struct power_supply_desc	psy_desc;
 	struct iio_channel	*channel[GAB_MAX_CHAN_TYPE];
-	struct gab_platform_data	*pdata;
 	struct delayed_work bat_work;
-	int	level;
 	int	status;
 	bool cable_plugged;
 	struct gpio_desc *charge_finished;
@@ -70,14 +67,6 @@ static void gab_ext_power_changed(struct power_supply *psy)
 
 static const enum power_supply_property gab_props[] = {
 	POWER_SUPPLY_PROP_STATUS,
-	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
-	POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
-	POWER_SUPPLY_PROP_VOLTAGE_NOW,
-	POWER_SUPPLY_PROP_CURRENT_NOW,
-	POWER_SUPPLY_PROP_TECHNOLOGY,
-	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
-	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
-	POWER_SUPPLY_PROP_MODEL_NAME,
 };
 
 /*
@@ -97,17 +86,6 @@ static bool gab_charge_finished(struct gab *adc_bat)
 	return gpiod_get_value(adc_bat->charge_finished);
 }
 
-static int gab_get_status(struct gab *adc_bat)
-{
-	struct gab_platform_data *pdata = adc_bat->pdata;
-	struct power_supply_info *bat_info;
-
-	bat_info = &pdata->battery_info;
-	if (adc_bat->level == bat_info->charge_full_design)
-		return POWER_SUPPLY_STATUS_FULL;
-	return adc_bat->status;
-}
-
 static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
 {
 	switch (psp) {
@@ -144,27 +122,12 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
 static int gab_get_property(struct power_supply *psy,
 		enum power_supply_property psp, union power_supply_propval *val)
 {
-	struct gab *adc_bat;
-	struct gab_platform_data *pdata;
-	struct power_supply_info *bat_info;
-	int result = 0;
-	int ret = 0;
-
-	adc_bat = to_generic_bat(psy);
-	if (!adc_bat) {
-		dev_err(&psy->dev, "no battery infos ?!\n");
-		return -EINVAL;
-	}
-	pdata = adc_bat->pdata;
-	bat_info = &pdata->battery_info;
+	struct gab *adc_bat = to_generic_bat(psy);
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS:
-		val->intval = gab_get_status(adc_bat);
-		break;
-	case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
-		val->intval = 0;
-		break;
+		val->intval = adc_bat->status;
+		return 0;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 	case POWER_SUPPLY_PROP_POWER_NOW:
@@ -173,26 +136,9 @@ static int gab_get_property(struct power_supply *psy,
 			goto err;
 		val->intval = result;
 		break;
-	case POWER_SUPPLY_PROP_TECHNOLOGY:
-		val->intval = bat_info->technology;
-		break;
-	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
-		val->intval = bat_info->voltage_min_design;
-		break;
-	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
-		val->intval = bat_info->voltage_max_design;
-		break;
-	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
-		val->intval = bat_info->charge_full_design;
-		break;
-	case POWER_SUPPLY_PROP_MODEL_NAME:
-		val->strval = bat_info->name;
-		break;
 	default:
 		return -EINVAL;
 	}
-err:
-	return ret;
 }
 
 static void gab_work(struct work_struct *work)
@@ -235,7 +181,6 @@ static int gab_probe(struct platform_device *pdev)
 	struct gab *adc_bat;
 	struct power_supply_desc *psy_desc;
 	struct power_supply_config psy_cfg = {};
-	struct gab_platform_data *pdata = pdev->dev.platform_data;
 	enum power_supply_property *properties;
 	int ret = 0;
 	int chan;
@@ -248,7 +193,7 @@ static int gab_probe(struct platform_device *pdev)
 
 	psy_cfg.drv_data = adc_bat;
 	psy_desc = &adc_bat->psy_desc;
-	psy_desc->name = pdata->battery_info.name;
+	psy_desc->name = dev_name(&pdev->dev);
 
 	/* bootup default values for the battery */
 	adc_bat->cable_plugged = false;
@@ -256,7 +201,6 @@ static int gab_probe(struct platform_device *pdev)
 	psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
 	psy_desc->get_property = gab_get_property;
 	psy_desc->external_power_changed = gab_ext_power_changed;
-	adc_bat->pdata = pdata;
 
 	/*
 	 * copying the static properties and allocating extra memory for holding
@@ -309,6 +253,7 @@ static int gab_probe(struct platform_device *pdev)
 	 */
 	psy_desc->properties = properties;
 	psy_desc->num_properties = index;
+	psy_desc->expose_battery_info = true;
 
 	adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
 	if (IS_ERR(adc_bat->psy))
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
deleted file mode 100644
index 54434e4304d3..000000000000
--- a/include/linux/power/generic-adc-battery.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* 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
- */
-struct gab_platform_data {
-	struct power_supply_info battery_info;
-};
-
-#endif /* GENERIC_ADC_BATTERY_H */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (7 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:31   ` Linus Walleij
  2023-03-13  8:19   ` Matti Vaittinen
  2023-03-09 22:50 ` [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Sebastian Reichel
  2023-03-09 22:50 ` [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Sebastian Reichel
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

Drop mostly useless gab_prop_to_chan() function by directly
supplying the correct enum value to read_channel().

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 31 ++++------------------
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index fc6fcfda1ef2..7bc54566664f 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat)
 	return gpiod_get_value(adc_bat->charge_finished);
 }
 
-static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
-{
-	switch (psp) {
-	case POWER_SUPPLY_PROP_POWER_NOW:
-		return GAB_POWER;
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		return GAB_VOLTAGE;
-	case POWER_SUPPLY_PROP_CURRENT_NOW:
-		return GAB_CURRENT;
-	default:
-		WARN_ON(1);
-		break;
-	}
-	return GAB_POWER;
-}
-
-static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
+static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
 		int *result)
 {
 	int ret;
-	int chan_index;
 
-	chan_index = gab_prop_to_chan(psp);
-	ret = iio_read_channel_processed(adc_bat->channel[chan_index],
-			result);
+	ret = iio_read_channel_processed(adc_bat->channel[channel], result);
 	if (ret < 0)
 		pr_err("read channel error\n");
 	else
@@ -129,13 +110,11 @@ static int gab_get_property(struct power_supply *psy,
 		val->intval = adc_bat->status;
 		return 0;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+		return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
+		return read_channel(adc_bat, GAB_CURRENT, &val->intval);
 	case POWER_SUPPLY_PROP_POWER_NOW:
-		ret = read_channel(adc_bat, psp, &result);
-		if (ret < 0)
-			goto err;
-		val->intval = result;
-		break;
+		return read_channel(adc_bat, GAB_POWER, &val->intval);
 	default:
 		return -EINVAL;
 	}
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (8 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:32   ` Linus Walleij
  2023-03-13  8:22   ` Matti Vaittinen
  2023-03-09 22:50 ` [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Sebastian Reichel
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

This adds full DT support to the driver. Because of the previous
changes just adding a compatible value is enough.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 7bc54566664f..436e75d226ed 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/iio/consumer.h>
 #include <linux/iio/types.h>
+#include <linux/of.h>
 #include <linux/devm-helpers.h>
 
 #define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -170,6 +171,7 @@ static int gab_probe(struct platform_device *pdev)
 	if (!adc_bat)
 		return -ENOMEM;
 
+	psy_cfg.of_node = pdev->dev.of_node;
 	psy_cfg.drv_data = adc_bat;
 	psy_desc = &adc_bat->psy_desc;
 	psy_desc->name = dev_name(&pdev->dev);
@@ -284,10 +286,17 @@ static int __maybe_unused gab_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gab_pm_ops, gab_suspend, gab_resume);
 
+static const struct of_device_id gab_match[] = {
+	{ .compatible = "adc-battery" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, gab_match);
+
 static struct platform_driver gab_driver = {
 	.driver		= {
 		.name	= "generic-adc-battery",
 		.pm	= &gab_pm_ops,
+		.of_match_table = gab_match,
 	},
 	.probe		= gab_probe,
 };
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info
  2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
                   ` (9 preceding siblings ...)
  2023-03-09 22:50 ` [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Sebastian Reichel
@ 2023-03-09 22:50 ` Sebastian Reichel
  2023-03-10  8:33   ` Linus Walleij
  2023-03-13  8:25   ` Matti Vaittinen
  10 siblings, 2 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-09 22:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

jz4740-battery.c and s3c_adc_battery.c have been removed
from the tree and after all of my restructuring the driver
is basically no longer based on them.

Thus update the copyright information and switch to SPDX
license identifier while being at it.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 436e75d226ed..ac72140dc136 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -1,13 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * Generic battery driver code using IIO
+ * Generic battery driver using IIO
  * Copyright (C) 2012, Anish Kumar <anish198519851985@gmail.com>
- * based on jz4740-battery.c
- * based on s3c_adc_battery.c
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file COPYING in the main directory of this archive for
- * more details.
- *
+ * Copyright (c) 2023, Sebastian Reichel <sre@kernel.org>
  */
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
@ 2023-03-10  1:36   ` kernel test robot
  2023-03-10  5:10   ` kernel test robot
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 61+ messages in thread
From: kernel test robot @ 2023-03-10  1:36 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: oe-kbuild-all, Linus Walleij, Matti Vaittinen, Matti Vaittinen,
	Rob Herring, Krzysztof Kozlowski, linux-kernel, linux-pm,
	devicetree

Hi Sebastian,

I love your patch! Perhaps something to improve:

[auto build test WARNING on sre-power-supply/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sebastian-Reichel/dt-bindings-power-supply-adc-battery-add-binding/20230310-065229
base:   https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
patch link:    https://lore.kernel.org/r/20230309225041.477440-3-sre%40kernel.org
patch subject: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230310/202303100854.V2YFWYZu-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/83ec4c841d68a66bc95f5e534a805e765785f934
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Sebastian-Reichel/dt-bindings-power-supply-adc-battery-add-binding/20230310-065229
        git checkout 83ec4c841d68a66bc95f5e534a805e765785f934
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/power/supply/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303100854.V2YFWYZu-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/power/supply/power_supply_core.c:21:
>> include/linux/power_supply.h:777:41: warning: 'power_supply_battery_info_properties' defined but not used [-Wunused-const-variable=]
     777 | static const enum power_supply_property power_supply_battery_info_properties[] = {
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/power_supply_battery_info_properties +777 include/linux/power_supply.h

   776	
 > 777	static const enum power_supply_property power_supply_battery_info_properties[] = {
   778		POWER_SUPPLY_PROP_TECHNOLOGY,
   779		POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
   780		POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
   781		POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
   782		POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
   783		POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
   784		POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
   785		POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
   786		POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
   787		POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
   788		POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
   789		POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
   790		POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
   791		POWER_SUPPLY_PROP_TEMP_MIN,
   792		POWER_SUPPLY_PROP_TEMP_MAX,
   793	};
   794	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
  2023-03-10  1:36   ` kernel test robot
@ 2023-03-10  5:10   ` kernel test robot
  2023-03-10  8:20   ` Linus Walleij
  2023-03-13  6:45   ` Matti Vaittinen
  3 siblings, 0 replies; 61+ messages in thread
From: kernel test robot @ 2023-03-10  5:10 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: oe-kbuild-all, Linus Walleij, Matti Vaittinen, Matti Vaittinen,
	Rob Herring, Krzysztof Kozlowski, linux-kernel, linux-pm,
	devicetree

Hi Sebastian,

I love your patch! Yet something to improve:

[auto build test ERROR on sre-power-supply/for-next]
[also build test ERROR on robh/for-next linus/master v6.3-rc1 next-20230310]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sebastian-Reichel/dt-bindings-power-supply-adc-battery-add-binding/20230310-065229
base:   https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
patch link:    https://lore.kernel.org/r/20230309225041.477440-3-sre%40kernel.org
patch subject: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
config: x86_64-randconfig-a002 (https://download.01.org/0day-ci/archive/20230310/202303101236.fqHwh3Tt-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/83ec4c841d68a66bc95f5e534a805e765785f934
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Sebastian-Reichel/dt-bindings-power-supply-adc-battery-add-binding/20230310-065229
        git checkout 83ec4c841d68a66bc95f5e534a805e765785f934
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303101236.fqHwh3Tt-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "power_supply_get_property" [drivers/phy/ti/phy-tusb1210.ko] undefined!
>> ERROR: modpost: "power_supply_get_property" [drivers/power/supply/88pm860x_charger.ko] undefined!
>> ERROR: modpost: "power_supply_get_property" [drivers/power/supply/charger-manager.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
@ 2023-03-10  8:14   ` Linus Walleij
  2023-03-11 17:54     ` Sebastian Reichel
  2023-03-12 11:29   ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Krzysztof Kozlowski
  2023-03-13  6:13   ` Matti Vaittinen
  2 siblings, 1 reply; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:14 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

Hi Sebastian,

thanks for your patches!

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Add binding for a battery that is only monitored via ADC
> channels and simple status GPIOs.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

This does look very useful.

> +title: ADC battery
> +
> +maintainers:
> +  - Sebastian Reichel <sre@kernel.org>
> +
> +description: |
> +  Basic Battery, which only reports (in circuit) voltage and optionally
> +  current via an ADC channel.

I would over-specify: "voltage over the terminals" and
"current out of the battery" so this cannot be misunderstood.

+ this text:

It can also optionally indicate that the battery is full by pulling a GPIO
line.

> +  charged-gpios:
> +    description:
> +      GPIO which signals that the battery is fully charged.

It doesn't say how, I guess either this is an analog circuit (!) or
a charger IC? If it doesn't matter, no big deal, but if something is
implicit here, then spell it out please.

> +    fuel-gauge {

This techno-lingo/slang term is a bit unfortunate, but if there are
precedents then stick with it.

The correct term could be something like battery-capacity-meter
I suppose.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
  2023-03-10  1:36   ` kernel test robot
  2023-03-10  5:10   ` kernel test robot
@ 2023-03-10  8:20   ` Linus Walleij
  2023-03-13  6:45   ` Matti Vaittinen
  3 siblings, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:20 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

Hi Sebastian,

thanks for your patch!

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> +       /*
> +        * Set if constant battery information from firmware should be
> +        * exposed automatically. No driver specific code is required
> +        * in that case. If the driver also handles a property provided
> +        * by constant firmware data, the driver's handler is preferred.
> +        */
> +       bool expose_battery_info;

Playing it safe with opt-in I see! But I would probably invert it and add
a hide_battery_info for those that don't wanna expose it. It seems
pretty useful to just expose this in general.

However I have no insight in what happens on laptops etc for this
so I guess you have your reasons, either way:

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

> +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);

I think the build robots complain because you need to add some stubs
for the not enabled case.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources
  2023-03-09 22:50 ` [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Sebastian Reichel
@ 2023-03-10  8:21   ` Linus Walleij
  2023-03-13  7:14   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:21 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Convert driver to use managed resources to simplify driver code.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Excellent
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
  2023-03-09 22:50 ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
@ 2023-03-10  8:23   ` Linus Walleij
  2023-03-13  7:52   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:23 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> power-supply properties are reported in µV, µA and µW.
> The IIO API provides mV, mA, mW, so the values need to
> be multiplied by 1000.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Fixes: tag?
Cc: stable@vger.kernel.org

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

This code can not have seen much testing.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support
  2023-03-09 22:50 ` [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support Sebastian Reichel
@ 2023-03-10  8:24   ` Linus Walleij
  0 siblings, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:24 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Drop support for configuring IRQ jitter delay by using big
> enough fixed value.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support
  2023-03-09 22:50 ` [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support Sebastian Reichel
@ 2023-03-10  8:29   ` Linus Walleij
  2023-03-13  7:49     ` Matti Vaittinen
  0 siblings, 1 reply; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:29 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Drop CHARGE_NOW support, which requires a platform specific
> calculation method.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

I agree. If we want to support this, we should use the generic
methods with interpolation tables defined in DT as well, and it also
ideally requires load compensated resistance calculation to figure
out Ri so this can bring any kind of reasonable precision.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message
  2023-03-09 22:50 ` [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Sebastian Reichel
@ 2023-03-10  8:29   ` Linus Walleij
  2023-03-13  7:50   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:29 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Error printing happens automatically for memory allocation problems.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API
  2023-03-09 22:50 ` [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API Sebastian Reichel
@ 2023-03-10  8:30   ` Linus Walleij
  0 siblings, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:30 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Use standard simple-battery API for constant battery
> information like min and max voltage. This simplifies
> the driver a lot and brings automatic support for DT.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

That's neat.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic
  2023-03-09 22:50 ` [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Sebastian Reichel
@ 2023-03-10  8:31   ` Linus Walleij
  2023-03-13  8:19   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:31 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> Drop mostly useless gab_prop_to_chan() function by directly
> supplying the correct enum value to read_channel().
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Looks correct.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support
  2023-03-09 22:50 ` [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Sebastian Reichel
@ 2023-03-10  8:32   ` Linus Walleij
  2023-03-13  8:22   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:32 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> This adds full DT support to the driver. Because of the previous
> changes just adding a compatible value is enough.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info
  2023-03-09 22:50 ` [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Sebastian Reichel
@ 2023-03-10  8:33   ` Linus Walleij
  2023-03-13  8:25   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-10  8:33 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> jz4740-battery.c and s3c_adc_battery.c have been removed
> from the tree and after all of my restructuring the driver
> is basically no longer based on them.
>
> Thus update the copyright information and switch to SPDX
> license identifier while being at it.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties
@ 2023-03-10 14:47 Rob Herring
  0 siblings, 0 replies; 61+ messages in thread
From: Rob Herring @ 2023-03-10 14:47 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: devicetree, linux-pm, linux-kernel

It is preferred to use typed property access functions (i.e.
of_property_read_<type> functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/power/supply/charger-manager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index c9e8450c646f..5fa6ba7f41e1 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -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_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;
 	of_property_read_u32(np, "cm-battery-hot", &desc->temp_max);
 	of_property_read_u32(np, "cm-battery-temp-diff", &desc->temp_diff);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types)
@ 2023-03-10 17:04 kernel test robot
  0 siblings, 0 replies; 61+ messages in thread
From: kernel test robot @ 2023-03-10 17:04 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: oe-kbuild-all, linux-kernel, Geert Uytterhoeven, Konrad Dybcio

Hi Arnd,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   44889ba56cbb3d51154660ccd15818bc77276696
commit: 92304df83b943776492309f42452effea0cc1089 power: supply: qcom_battmgr: remove bogus do_div()
date:   9 days ago
config: openrisc-randconfig-s042-20230310 (https://download.01.org/0day-ci/archive/20230311/202303110050.1EF6YVC5-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 12.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=92304df83b943776492309f42452effea0cc1089
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout 92304df83b943776492309f42452effea0cc1089
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=openrisc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/power/supply/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303110050.1EF6YVC5-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned int [usertype] battery_id @@     got restricted __le32 [usertype] @@
   drivers/power/supply/qcom_battmgr.c:357:31: sparse:     expected unsigned int [usertype] battery_id
   drivers/power/supply/qcom_battmgr.c:357:31: sparse:     got restricted __le32 [usertype]
   drivers/power/supply/qcom_battmgr.c:369:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned int [usertype] battery_id @@     got restricted __le32 [usertype] @@
   drivers/power/supply/qcom_battmgr.c:369:31: sparse:     expected unsigned int [usertype] battery_id
   drivers/power/supply/qcom_battmgr.c:369:31: sparse:     got restricted __le32 [usertype]
>> drivers/power/supply/qcom_battmgr.c:1285:30: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] owner @@     got int @@
   drivers/power/supply/qcom_battmgr.c:1285:30: sparse:     expected restricted __le32 [usertype] owner
   drivers/power/supply/qcom_battmgr.c:1285:30: sparse:     got int
>> drivers/power/supply/qcom_battmgr.c:1286:29: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] type @@     got int @@
   drivers/power/supply/qcom_battmgr.c:1286:29: sparse:     expected restricted __le32 [usertype] type
   drivers/power/supply/qcom_battmgr.c:1286:29: sparse:     got int
>> drivers/power/supply/qcom_battmgr.c:1287:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] opcode @@     got int @@
   drivers/power/supply/qcom_battmgr.c:1287:31: sparse:     expected restricted __le32 [usertype] opcode
   drivers/power/supply/qcom_battmgr.c:1287:31: sparse:     got int

vim +357 drivers/power/supply/qcom_battmgr.c

29e8142b5623b5 Bjorn Andersson 2023-02-07  350  
29e8142b5623b5 Bjorn Andersson 2023-02-07  351  static int qcom_battmgr_update_status(struct qcom_battmgr *battmgr)
29e8142b5623b5 Bjorn Andersson 2023-02-07  352  {
29e8142b5623b5 Bjorn Andersson 2023-02-07  353  	struct qcom_battmgr_update_request request = {
29e8142b5623b5 Bjorn Andersson 2023-02-07  354  		.hdr.owner = cpu_to_le32(PMIC_GLINK_OWNER_BATTMGR),
29e8142b5623b5 Bjorn Andersson 2023-02-07  355  		.hdr.type = cpu_to_le32(PMIC_GLINK_REQ_RESP),
29e8142b5623b5 Bjorn Andersson 2023-02-07  356  		.hdr.opcode = cpu_to_le32(BATTMGR_BAT_STATUS),
29e8142b5623b5 Bjorn Andersson 2023-02-07 @357  		.battery_id = cpu_to_le32(0),
29e8142b5623b5 Bjorn Andersson 2023-02-07  358  	};
29e8142b5623b5 Bjorn Andersson 2023-02-07  359  
29e8142b5623b5 Bjorn Andersson 2023-02-07  360  	return qcom_battmgr_request(battmgr, &request, sizeof(request));
29e8142b5623b5 Bjorn Andersson 2023-02-07  361  }
29e8142b5623b5 Bjorn Andersson 2023-02-07  362  

:::::: The code at line 357 was first introduced by commit
:::::: 29e8142b5623b5949587bcc4f591c4e6595c4aca power: supply: Introduce Qualcomm PMIC GLINK power supply

:::::: TO: Bjorn Andersson <bjorn.andersson@linaro.org>
:::::: CC: Bjorn Andersson <andersson@kernel.org>

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table
@ 2023-03-10 20:06 Krzysztof Kozlowski
  2023-03-10 20:10 ` Konrad Dybcio
  2023-03-10 20:48 ` Marijn Suijten
  0 siblings, 2 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-10 20:06 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
	linux-arm-msm, linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

The Qualcomm SoC power-on driver is specific to ARCH_QCOM which depends
on OF thus the driver is OF-only.  It's of_device_id table is built
unconditionally, thus of_match_ptr() for ID table does not make sense.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/reset/qcom-pon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
index 16bc01738be9..ebdcfb28c4a0 100644
--- a/drivers/power/reset/qcom-pon.c
+++ b/drivers/power/reset/qcom-pon.c
@@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = {
 	.probe = pm8916_pon_probe,
 	.driver = {
 		.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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table
  2023-03-10 20:06 [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Krzysztof Kozlowski
@ 2023-03-10 20:10 ` Konrad Dybcio
  2023-03-10 20:48 ` Marijn Suijten
  1 sibling, 0 replies; 61+ messages in thread
From: Konrad Dybcio @ 2023-03-10 20:10 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andy Gross, Bjorn Andersson,
	Sebastian Reichel, linux-arm-msm, linux-pm, linux-kernel



On 10.03.2023 21:06, Krzysztof Kozlowski wrote:
> The Qualcomm SoC power-on driver is specific to ARCH_QCOM which depends
> on OF thus the driver is OF-only.  It's of_device_id table is built
> unconditionally, thus of_match_ptr() for ID table does not make sense.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  drivers/power/reset/qcom-pon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
> index 16bc01738be9..ebdcfb28c4a0 100644
> --- a/drivers/power/reset/qcom-pon.c
> +++ b/drivers/power/reset/qcom-pon.c
> @@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = {
>  	.probe = pm8916_pon_probe,
>  	.driver = {
>  		.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);

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table
  2023-03-10 20:06 [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Krzysztof Kozlowski
  2023-03-10 20:10 ` Konrad Dybcio
@ 2023-03-10 20:48 ` Marijn Suijten
  2023-03-10 20:54   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 61+ messages in thread
From: Marijn Suijten @ 2023-03-10 20:48 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
	linux-arm-msm, linux-pm, linux-kernel

On 2023-03-10 21:06:52, Krzysztof Kozlowski wrote:
> The Qualcomm SoC power-on driver is specific to ARCH_QCOM which depends
> on OF thus the driver is OF-only.  It's of_device_id table is built

Its*

> unconditionally, thus of_match_ptr() for ID table does not make sense.

Agreed.  Searching for of_match_ptr on any *qcom* file yields 25 results
on a few-weeks-old tree, are you planning on assessing those too?

> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Marijn Suijten <marijn.suijten@somainline.org>

> ---
>  drivers/power/reset/qcom-pon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
> index 16bc01738be9..ebdcfb28c4a0 100644
> --- a/drivers/power/reset/qcom-pon.c
> +++ b/drivers/power/reset/qcom-pon.c
> @@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = {
>  	.probe = pm8916_pon_probe,
>  	.driver = {
>  		.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);
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table
  2023-03-10 20:48 ` Marijn Suijten
@ 2023-03-10 20:54   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-10 20:54 UTC (permalink / raw)
  To: Marijn Suijten
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
	linux-arm-msm, linux-pm, linux-kernel

On 10/03/2023 21:48, Marijn Suijten wrote:
> On 2023-03-10 21:06:52, Krzysztof Kozlowski wrote:
>> The Qualcomm SoC power-on driver is specific to ARCH_QCOM which depends
>> on OF thus the driver is OF-only.  It's of_device_id table is built
> 
> Its*
> 
>> unconditionally, thus of_match_ptr() for ID table does not make sense.
> 
> Agreed.  Searching for of_match_ptr on any *qcom* file yields 25 results
> on a few-weeks-old tree, are you planning on assessing those too?
> 

There are just few incorrect usages, I'll fix these. Rest has proper
maybe_unused or ifdef.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused
@ 2023-03-11 11:15 Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 2/6] power: supply: twl4030_charger: " Krzysztof Kozlowski
                   ` (4 more replies)
  0 siblings, 5 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/rt9455_charger.c:1725:34: error: ‘rt9455_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/rt9455_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/rt9455_charger.c b/drivers/power/supply/rt9455_charger.c
index 31fb6526a1fd..0149e00f2bf8 100644
--- a/drivers/power/supply/rt9455_charger.c
+++ b/drivers/power/supply/rt9455_charger.c
@@ -1722,7 +1722,7 @@ static const struct i2c_device_id 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", },
 	{ },
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH 2/6] power: supply: twl4030_charger: mark OF related data as maybe unused
  2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
@ 2023-03-11 11:15 ` Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 3/6] power: supply: lp8727_charger: " Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/twl4030_charger.c:1129:34: error: ‘twl_bci_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/twl4030_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 53a0ea5a61da..7adfd69fe649 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -1126,7 +1126,7 @@ static int twl4030_bci_remove(struct platform_device *pdev)
 	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", },
 	{ }
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH 3/6] power: supply: lp8727_charger: mark OF related data as maybe unused
  2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 2/6] power: supply: twl4030_charger: " Krzysztof Kozlowski
@ 2023-03-11 11:15 ` Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 4/6] power: supply: ltc4162-l-charger: " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/lp8727_charger.c:601:34: error: ‘lp8727_dt_ids’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/lp8727_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/lp8727_charger.c b/drivers/power/supply/lp8727_charger.c
index e6c21377d53c..dc42d354b892 100644
--- a/drivers/power/supply/lp8727_charger.c
+++ b/drivers/power/supply/lp8727_charger.c
@@ -598,7 +598,7 @@ static void lp8727_remove(struct i2c_client *cl)
 	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", },
 	{ }
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH 4/6] power: supply: ltc4162-l-charger: mark OF related data as maybe unused
  2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 2/6] power: supply: twl4030_charger: " Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 3/6] power: supply: lp8727_charger: " Krzysztof Kozlowski
@ 2023-03-11 11:15 ` Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 5/6] power: supply: bq24257_charger: " Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 6/6] power: supply: bq25890_charger: " Krzysztof Kozlowski
  4 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/ltc4162-l-charger.c:911:34: error: ‘ltc4162l_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/ltc4162-l-charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/ltc4162-l-charger.c b/drivers/power/supply/ltc4162-l-charger.c
index 0e95c65369b8..285580845e2f 100644
--- a/drivers/power/supply/ltc4162-l-charger.c
+++ b/drivers/power/supply/ltc4162-l-charger.c
@@ -908,7 +908,7 @@ static const struct i2c_device_id 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", },
 	{ },
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH 5/6] power: supply: bq24257_charger: mark OF related data as maybe unused
  2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2023-03-11 11:15 ` [PATCH 4/6] power: supply: ltc4162-l-charger: " Krzysztof Kozlowski
@ 2023-03-11 11:15 ` Krzysztof Kozlowski
  2023-03-11 11:15 ` [PATCH 6/6] power: supply: bq25890_charger: " Krzysztof Kozlowski
  4 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/bq24257_charger.c:1143:34: error: ‘bq24257_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/bq24257_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 103ddc2b3def..45e4ba30da98 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -1140,7 +1140,7 @@ static const struct i2c_device_id 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,bq24251", },
 	{ .compatible = "ti,bq24257", },
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH 6/6] power: supply: bq25890_charger: mark OF related data as maybe unused
  2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2023-03-11 11:15 ` [PATCH 5/6] power: supply: bq24257_charger: " Krzysztof Kozlowski
@ 2023-03-11 11:15 ` Krzysztof Kozlowski
  4 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-11 11:15 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel; +Cc: Krzysztof Kozlowski

The driver can be compile tested with !CONFIG_OF making certain data
unused:

  drivers/power/supply/bq25890_charger.c:1625:34: error: ‘bq25890_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/bq25890_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index bfe08d7bfaf3..22cde35eb144 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -1622,7 +1622,7 @@ static const struct i2c_device_id 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,bq25892", },
 	{ .compatible = "ti,bq25895", },
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* [PATCH v2] power: supply: da9150: Fix use after free bug in  da9150_charger_remove due to race condition
@ 2023-03-11 17:46 Zheng Wang
  0 siblings, 0 replies; 61+ messages in thread
From: Zheng Wang @ 2023-03-11 17:46 UTC (permalink / raw)
  To: njavali
  Cc: sebastian.reichel, mrangankar, GR-QLogic-Storage-Upstream, jejb,
	martin.petersen, linux-scsi, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young, Zheng Wang

In da9150_charger_probe, &charger->otg_work is bound with
da9150_charger_otg_work. da9150_charger_otg_ncb may be
called to start the work.

If we remove the module which will call da9150_charger_remove
to make cleanup, there may be a unfinished work. The possible
sequence is as follows:

Fix it by canceling the work before cleanup in the da9150_charger_remove

CPU0                  CPUc1

                    |da9150_charger_otg_work
da9150_charger_remove      |
power_supply_unregister  |
device_unregister   |
power_supply_dev_release|
kfree(psy)          |
                    |
                    | 	power_supply_changed(charger->usb);
                    |   //use

Fixes: c1a281e34dae ("power: Add support for DA9150 Charger")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- fix wrong description in commit message and mov cancel_work_sync
after usb_unregister_notifier suggested by Sebastian Reichel
---
 drivers/power/supply/da9150-charger.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c
index 14da5c595dd9..a87aeaea38e1 100644
--- a/drivers/power/supply/da9150-charger.c
+++ b/drivers/power/supply/da9150-charger.c
@@ -657,6 +657,7 @@ static int da9150_charger_remove(struct platform_device *pdev)
 
 	if (!IS_ERR_OR_NULL(charger->usb_phy))
 		usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
+	cancel_work_sync(&charger->otg_work);
 
 	power_supply_unregister(charger->battery);
 	power_supply_unregister(charger->usb);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding
  2023-03-10  8:14   ` Linus Walleij
@ 2023-03-11 17:54     ` Sebastian Reichel
  2023-03-12 17:07       ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
                         ` (9 more replies)
  0 siblings, 10 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-11 17:54 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

[-- Attachment #1: Type: text/plain, Size: 2038 bytes --]

Hi Linus,

On Fri, Mar 10, 2023 at 09:14:39AM +0100, Linus Walleij wrote:
> Hi Sebastian,
> 
> thanks for your patches!
> 
> On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:
> 
> > Add binding for a battery that is only monitored via ADC
> > channels and simple status GPIOs.
> >
> > Signed-off-by: Sebastian Reichel <sre@kernel.org>
> 
> This does look very useful.

:)

> > +title: ADC battery
> > +
> > +maintainers:
> > +  - Sebastian Reichel <sre@kernel.org>
> > +
> > +description: |
> > +  Basic Battery, which only reports (in circuit) voltage and optionally
> > +  current via an ADC channel.
> 
> I would over-specify: "voltage over the terminals" and
> "current out of the battery" so this cannot be misunderstood.
> 
> + this text:
> 
> It can also optionally indicate that the battery is full by pulling a GPIO
> line.

Ack.

> 
> > +  charged-gpios:
> > +    description:
> > +      GPIO which signals that the battery is fully charged.
> 
> It doesn't say how, I guess either this is an analog circuit (!) or
> a charger IC? If it doesn't matter, no big deal, but if something is
> implicit here, then spell it out please.

In my case the GPIO is provided by a charger chip, that is not
software controllable (just reports charge-done & charger-connected
via GPIOs). I've seen something similar in a customer device some
years ago. I will add a sentence:

The GPIO is often provided by charger ICs, that are not software
controllable.

> > +    fuel-gauge {
> 
> This techno-lingo/slang term is a bit unfortunate, but if there are
> precedents then stick with it.
> 
> The correct term could be something like battery-capacity-meter
> I suppose.

Right now in DT we have

 - specific node name (e.g. chip names) that should be changed :)
 - smart-battery
 - battery
 - fuel-gauge

I think fuel-gauge is the most sensible of that list, considering
hardware vendors usually call their chips battery fuel gauge.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
  2023-03-10  8:14   ` Linus Walleij
@ 2023-03-12 11:29   ` Krzysztof Kozlowski
  2023-03-13  6:13   ` Matti Vaittinen
  2 siblings, 0 replies; 61+ messages in thread
From: Krzysztof Kozlowski @ 2023-03-12 11:29 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Matti Vaittinen, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

On 09/03/2023 23:50, Sebastian Reichel wrote:
> Add binding for a battery that is only monitored via ADC
> channels and simple status GPIOs.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Thank you for your patch. There is something to discuss/improve.


> +
> +maintainers:
> +  - Sebastian Reichel <sre@kernel.org>
> +
> +description: |

Don't need '|'.

> +  Basic Battery, which only reports (in circuit) voltage and optionally
> +  current via an ADC channel.
> +
> +allOf:
> +  - $ref: power-supply.yaml#
> +
> +properties:
> +  compatible:
> +    const: adc-battery
> +
> +  charged-gpios:
> +    description:
> +      GPIO which signals that the battery is fully charged.
> +    maxItems: 1
> +
> +  io-channels:
> +    minItems: 1
> +    maxItems: 3
> +
> +  io-channel-names:

Simpler:

minItems: 1
items:
  - const: voltage
  - enum: [ current, power ]
  - const: power

> +    oneOf:
> +      - const: voltage
> +      - items:
> +          - const: voltage
> +          - enum:
> +              - current
> +              - power
> +      - items:
> +          - const: voltage
> +          - const: current
> +          - const: power
> +

What about temperature? For max17040 this was recently proposed and I
wonder whether it is desirable.

https://lore.kernel.org/all/74ba115e-9838-4983-7b93-188a8260dd8a@linaro.org/

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-11 17:54     ` Sebastian Reichel
@ 2023-03-12 17:07       ` Sebastian Reichel
  2023-03-12 22:27       ` [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Sebastian Reichel
                         ` (8 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 17:07 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

[-- Attachment #1: Type: text/plain, Size: 2263 bytes --]

Hi,

On Fri, Mar 10, 2023 at 09:20:09AM +0100, Linus Walleij wrote:
> On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:
> 
> > +       /*
> > +        * Set if constant battery information from firmware should be
> > +        * exposed automatically. No driver specific code is required
> > +        * in that case. If the driver also handles a property provided
> > +        * by constant firmware data, the driver's handler is preferred.
> > +        */
> > +       bool expose_battery_info;
> 
> Playing it safe with opt-in I see! But I would probably invert it and
> add a hide_battery_info for those that don't wanna expose it. It seems
> pretty useful to just expose this in general.

I just did not yet spend the time to understand if there are any
issues. I guess I can do it now and then remove the opt-in part.

> However I have no insight in what happens on laptops etc for this
> so I guess you have your reasons, either way:

ACPI based systems should be fine, since battery info does not
yet support ACPI and thus nothing changes for them.

> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> > +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);
> 
> I think the build robots complain because you need to add some stubs
> for the not enabled case.

I don't think so. They are only used from code needing POWER_SUPPLY
being enabled.

One reported error is about the array of battery_info properties not
being used when POWER_SUPPLY is disabled. I will move that array to a
better place.

The other error is about power_supply_get_property(), because I
accidently removed the EXPORT_SYMBOL_GPL(power_supply_get_property).
I did not notice myself, because I compiled a monolithic kernel for
the thermal camera for easy deployment.

Thanks for the review, much appreciated!

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused
  2023-03-11 17:54     ` Sebastian Reichel
  2023-03-12 17:07       ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
@ 2023-03-12 22:27       ` Sebastian Reichel
  2023-03-12 22:31       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Sebastian Reichel
                         ` (7 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:27 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

Hi,

Thanks, I queued all 6 patches to power-supply's for-next queue.

-- Sebastian

On Sat, Mar 11, 2023 at 12:15:27PM +0100, Krzysztof Kozlowski wrote:
> The driver can be compile tested with !CONFIG_OF making certain data
> unused:
> 
>   drivers/power/supply/rt9455_charger.c:1725:34: error: ‘rt9455_of_match’ defined but not used [-Werror=unused-const-variable=]
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/power/supply/rt9455_charger.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/rt9455_charger.c b/drivers/power/supply/rt9455_charger.c
> index 31fb6526a1fd..0149e00f2bf8 100644
> --- a/drivers/power/supply/rt9455_charger.c
> +++ b/drivers/power/supply/rt9455_charger.c
> @@ -1722,7 +1722,7 @@ static const struct i2c_device_id 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", },
>  	{ },
>  };
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition
  2023-03-11 17:54     ` Sebastian Reichel
  2023-03-12 17:07       ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
  2023-03-12 22:27       ` [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Sebastian Reichel
@ 2023-03-12 22:31       ` Sebastian Reichel
  2023-03-12 22:33       ` [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Sebastian Reichel
                         ` (6 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:31 UTC (permalink / raw)
  To: Zheng Wang
  Cc: njavali, mrangankar, GR-QLogic-Storage-Upstream, jejb,
	martin.petersen, linux-pm, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young

[-- Attachment #1: Type: text/plain, Size: 1938 bytes --]

Hi,

On Sun, Mar 12, 2023 at 01:46:50AM +0800, Zheng Wang wrote:
> In da9150_charger_probe, &charger->otg_work is bound with
> da9150_charger_otg_work. da9150_charger_otg_ncb may be
> called to start the work.
> 
> If we remove the module which will call da9150_charger_remove
> to make cleanup, there may be a unfinished work. The possible
> sequence is as follows:
> 
> Fix it by canceling the work before cleanup in the da9150_charger_remove
> 
> CPU0                  CPUc1
> 
>                     |da9150_charger_otg_work
> da9150_charger_remove      |
> power_supply_unregister  |
> device_unregister   |
> power_supply_dev_release|
> kfree(psy)          |
>                     |
>                     | 	power_supply_changed(charger->usb);
>                     |   //use
> 
> Fixes: c1a281e34dae ("power: Add support for DA9150 Charger")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> ---
> v2:
> - fix wrong description in commit message and mov cancel_work_sync
> after usb_unregister_notifier suggested by Sebastian Reichel
> ---

Thanks, queued to power-supply's fixes branch. Please make sure you
send your patches to the correct destination next time (linux-scsi
should be linux-pm).

-- Sebastian

>  drivers/power/supply/da9150-charger.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c
> index 14da5c595dd9..a87aeaea38e1 100644
> --- a/drivers/power/supply/da9150-charger.c
> +++ b/drivers/power/supply/da9150-charger.c
> @@ -657,6 +657,7 @@ static int da9150_charger_remove(struct platform_device *pdev)
>  
>  	if (!IS_ERR_OR_NULL(charger->usb_phy))
>  		usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
> +	cancel_work_sync(&charger->otg_work);
>  
>  	power_supply_unregister(charger->battery);
>  	power_supply_unregister(charger->usb);
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (2 preceding siblings ...)
  2023-03-12 22:31       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Sebastian Reichel
@ 2023-03-12 22:33       ` Sebastian Reichel
  2023-03-12 22:36       ` [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties Sebastian Reichel
                         ` (5 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:33 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]

Hi,

On Fri, Mar 10, 2023 at 09:06:52PM +0100, Krzysztof Kozlowski wrote:
> The Qualcomm SoC power-on driver is specific to ARCH_QCOM which depends
> on OF thus the driver is OF-only.  It's of_device_id table is built
> unconditionally, thus of_match_ptr() for ID table does not make sense.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---

Thanks, queued to power-supply's for next branch.

-- Sebastian

>  drivers/power/reset/qcom-pon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
> index 16bc01738be9..ebdcfb28c4a0 100644
> --- a/drivers/power/reset/qcom-pon.c
> +++ b/drivers/power/reset/qcom-pon.c
> @@ -91,7 +91,7 @@ static struct platform_driver pm8916_pon_driver = {
>  	.probe = pm8916_pon_probe,
>  	.driver = {
>  		.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);
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (3 preceding siblings ...)
  2023-03-12 22:33       ` [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Sebastian Reichel
@ 2023-03-12 22:36       ` Sebastian Reichel
  2023-03-12 22:46       ` drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) Sebastian Reichel
                         ` (4 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:36 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]

Hi,

On Fri, Mar 10, 2023 at 08:47:35AM -0600, Rob Herring wrote:
> It is preferred to use typed property access functions (i.e.
> of_property_read_<type> functions) rather than low-level
> of_get_property/of_find_property functions for reading properties.
> Convert reading boolean properties to to of_property_read_bool().
> 
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/charger-manager.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
> index c9e8450c646f..5fa6ba7f41e1 100644
> --- a/drivers/power/supply/charger-manager.c
> +++ b/drivers/power/supply/charger-manager.c
> @@ -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_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;
>  	of_property_read_u32(np, "cm-battery-hot", &desc->temp_max);
>  	of_property_read_u32(np, "cm-battery-temp-diff", &desc->temp_diff);
> -- 
> 2.39.2
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types)
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (4 preceding siblings ...)
  2023-03-12 22:36       ` [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties Sebastian Reichel
@ 2023-03-12 22:46       ` Sebastian Reichel
  2023-03-12 22:50       ` [PATCH] power: supply: bq256xx: Support to disable charger Sebastian Reichel
                         ` (3 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:46 UTC (permalink / raw)
  To: Bjorn Andersson, Bjorn Andersson
  Cc: Arnd Bergmann, oe-kbuild-all, linux-kernel, Geert Uytterhoeven,
	Konrad Dybcio, linux-pm

[-- Attachment #1: Type: text/plain, Size: 2350 bytes --]

Hi Bjorn,

Can you please send a follow up patch for the sparse warnings in
qcom_battmgr [0]? It looks like there are two issues:

1. qcom_battmgr_update_request.battery_id is u32 instead of __le32

2. qcom_battmgr_enable_worker is missing cpu_to_le32() when building
   struct qcom_battmgr_enable_request

[0] https://lore.kernel.org/all/202303110050.1EF6YVC5-lkp@intel.com/

> sparse warnings: (new ones prefixed by >>)
> >> drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned int [usertype] battery_id @@     got restricted __le32 [usertype] @@
>    drivers/power/supply/qcom_battmgr.c:357:31: sparse:     expected unsigned int [usertype] battery_id
>    drivers/power/supply/qcom_battmgr.c:357:31: sparse:     got restricted __le32 [usertype]
>    drivers/power/supply/qcom_battmgr.c:369:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned int [usertype] battery_id @@     got restricted __le32 [usertype] @@
>    drivers/power/supply/qcom_battmgr.c:369:31: sparse:     expected unsigned int [usertype] battery_id
>    drivers/power/supply/qcom_battmgr.c:369:31: sparse:     got restricted __le32 [usertype]
> >> drivers/power/supply/qcom_battmgr.c:1285:30: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] owner @@     got int @@
>    drivers/power/supply/qcom_battmgr.c:1285:30: sparse:     expected restricted __le32 [usertype] owner
>    drivers/power/supply/qcom_battmgr.c:1285:30: sparse:     got int
> >> drivers/power/supply/qcom_battmgr.c:1286:29: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] type @@     got int @@
>    drivers/power/supply/qcom_battmgr.c:1286:29: sparse:     expected restricted __le32 [usertype] type
>    drivers/power/supply/qcom_battmgr.c:1286:29: sparse:     got int
> >> drivers/power/supply/qcom_battmgr.c:1287:31: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __le32 [usertype] opcode @@     got int @@
>    drivers/power/supply/qcom_battmgr.c:1287:31: sparse:     expected restricted __le32 [usertype] opcode
>    drivers/power/supply/qcom_battmgr.c:1287:31: sparse:     got int

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH] power: supply: bq256xx: Support to disable charger
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (5 preceding siblings ...)
  2023-03-12 22:46       ` drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) Sebastian Reichel
@ 2023-03-12 22:50       ` Sebastian Reichel
  2023-03-13  2:50       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Zheng Hacker
                         ` (2 subsequent siblings)
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-12 22:50 UTC (permalink / raw)
  To: Hermes Zhang; +Cc: kernel, linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6458 bytes --]

Hi,

On Thu, Mar 09, 2023 at 02:41:03PM +0800, Hermes Zhang wrote:
> To be able to control the charging process flexible, we need to able to
> disable the charger. This commit will allow to disable the charger by
> "echo 1 > /sys/class/power_supply/bq256xx-charger/charge_type"
> (1 = POWER_SUPPLY_CHARGE_TYPE_NONE) and enable the charger by set it to
> 2/3 (POWER_SUPPLY_CHARGE_TYPE_TRICKLE/POWER_SUPPLY_CHARGE_TYPE_FAST)
> 
> Signed-off-by: Hermes Zhang <chenhuiz@axis.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/bq256xx_charger.c | 40 ++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
> index 9cf4936440c9..e624834ae66c 100644
> --- a/drivers/power/supply/bq256xx_charger.c
> +++ b/drivers/power/supply/bq256xx_charger.c
> @@ -70,6 +70,9 @@
>  #define BQ25611D_VBATREG_THRESH_uV	4290000
>  #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_STEP_uA		60000
>  #define BQ256XX_ITERM_OFFSET_uA		60000
> @@ -259,6 +262,7 @@ struct bq256xx_device {
>   * @bq256xx_set_iterm: pointer to instance specific set_iterm function
>   * @bq256xx_set_iprechg: pointer to instance specific set_iprechg 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_iindpm: default iindpm value in microamps
> @@ -290,6 +294,7 @@ struct bq256xx_chip_info {
>  	int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm);
>  	int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg);
>  	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_iindpm;
> @@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq,
>  	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)
>  {
>  	unsigned int charge_current_limit;
> @@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy,
>  			return ret;
>  		break;
>  
> +	case POWER_SUPPLY_PROP_CHARGE_TYPE:
> +		ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval);
> +		if (ret)
> +			return ret;
> +		break;
> +
>  	default:
>  		break;
>  	}
> @@ -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_STATUS:
>  	case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
> +	case POWER_SUPPLY_PROP_CHARGE_TYPE:
>  		return true;
>  	default:
>  		return false;
> @@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq256xx_set_term_curr,
>  		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq256xx_set_term_curr,
>  		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq256xx_set_term_curr,
>  		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq256xx_set_term_curr,
>  		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq256xx_set_term_curr,
>  		.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq25618_619_set_term_curr,
>  		.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> @@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
>  		.bq256xx_set_iterm = bq25618_619_set_term_curr,
>  		.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
>  		.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_iindpm = BQ256XX_IINDPM_DEF_uA,
> -- 
> 2.30.2
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (6 preceding siblings ...)
  2023-03-12 22:50       ` [PATCH] power: supply: bq256xx: Support to disable charger Sebastian Reichel
@ 2023-03-13  2:50       ` Zheng Hacker
  2023-03-13 23:17       ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
  2023-03-14  8:14       ` Linus Walleij
  9 siblings, 0 replies; 61+ messages in thread
From: Zheng Hacker @ 2023-03-13  2:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Zheng Wang, njavali, mrangankar, GR-QLogic-Storage-Upstream,
	jejb, martin.petersen, linux-pm, linux-kernel, 1395428693sheep,
	alex000young

Sebastian Reichel <sebastian.reichel@collabora.com> 于2023年3月13日周一 06:31写道:
>
> Hi,
>
> On Sun, Mar 12, 2023 at 01:46:50AM +0800, Zheng Wang wrote:
> > In da9150_charger_probe, &charger->otg_work is bound with
> > da9150_charger_otg_work. da9150_charger_otg_ncb may be
> > called to start the work.
> >
> > If we remove the module which will call da9150_charger_remove
> > to make cleanup, there may be a unfinished work. The possible
> > sequence is as follows:
> >
> > Fix it by canceling the work before cleanup in the da9150_charger_remove
> >
> > CPU0                  CPUc1
> >
> >                     |da9150_charger_otg_work
> > da9150_charger_remove      |
> > power_supply_unregister  |
> > device_unregister   |
> > power_supply_dev_release|
> > kfree(psy)          |
> >                     |
> >                     |         power_supply_changed(charger->usb);
> >                     |   //use
> >
> > Fixes: c1a281e34dae ("power: Add support for DA9150 Charger")
> > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> > ---
> > v2:
> > - fix wrong description in commit message and mov cancel_work_sync
> > after usb_unregister_notifier suggested by Sebastian Reichel
> > ---
>
> Thanks, queued to power-supply's fixes branch. Please make sure you
> send your patches to the correct destination next time (linux-scsi
> should be linux-pm).

Thanks for your effort. I'll keep that in mind :)

Best regards,
Zheng

>
> >  drivers/power/supply/da9150-charger.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c
> > index 14da5c595dd9..a87aeaea38e1 100644
> > --- a/drivers/power/supply/da9150-charger.c
> > +++ b/drivers/power/supply/da9150-charger.c
> > @@ -657,6 +657,7 @@ static int da9150_charger_remove(struct platform_device *pdev)
> >
> >       if (!IS_ERR_OR_NULL(charger->usb_phy))
> >               usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
> > +     cancel_work_sync(&charger->otg_work);
> >
> >       power_supply_unregister(charger->battery);
> >       power_supply_unregister(charger->usb);
> > --
> > 2.25.1
> >

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding
  2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
  2023-03-10  8:14   ` Linus Walleij
  2023-03-12 11:29   ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Krzysztof Kozlowski
@ 2023-03-13  6:13   ` Matti Vaittinen
  2 siblings, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  6:13 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

Hi Sebastian,

On 3/10/23 00:50, Sebastian Reichel wrote:
> Add binding for a battery that is only monitored via ADC
> channels and simple status GPIOs.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>
> ---
>   .../bindings/power/supply/adc-battery.yaml    | 67 +++++++++++++++++++
>   1 file changed, 67 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/power/supply/adc-battery.yaml
> 
> diff --git a/Documentation/devicetree/bindings/power/supply/adc-battery.yaml b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml
> new file mode 100644
> index 000000000000..9d478bf9d2ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml
> @@ -0,0 +1,67 @@
> +# 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, which only reports (in circuit) voltage and optionally
> +  current via an ADC channel.
> +
> +allOf:
> +  - $ref: power-supply.yaml#
> +
> +properties:
> +  compatible:
> +    const: adc-battery
> +
> +  charged-gpios:
> +    description:
> +      GPIO which signals that the battery is fully charged.
> +    maxItems: 1
> +
> +  io-channels:
> +    minItems: 1
> +    maxItems: 3
> +
> +  io-channel-names:
> +    oneOf:
> +      - const: voltage
> +      - items:
> +          - const: voltage
> +          - enum:
> +              - current
> +              - power
> +      - items:
> +          - const: voltage
> +          - const: current
> +          - const: power

Good side of not knowing things is being able to asking for more 
information ;)

So, just by judging these bindings, we have a battery which provides 
fuel-gauge information via analog line connected to ADC(?)

Reading the description you have here and comments by Linus allows me to 
assume the line can represent current flowing out of the battery, or the 
battery voltage.

My guess then is that the io-channel-names property is going to tell 
which if these properties is being informed by the specific lines, 
right(?). Do you think you could add some small description for 
io-channel-names if you respin the series? I'd like to be more certain I 
"guessed" things right. ;) Maybe also add the 'power' option in the main 
description which currently just states voltage and power. (Assuming 
some devices do actually "expose" power levels via these "channels"?

> +
> +  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>;
> +    };

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data
  2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
                     ` (2 preceding siblings ...)
  2023-03-10  8:20   ` Linus Walleij
@ 2023-03-13  6:45   ` Matti Vaittinen
  3 siblings, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  6:45 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On 3/10/23 00:50, Sebastian Reichel wrote:
> Add support for automatically exposing data from the
> simple-battery firmware node with a single configuration
> option in the power-supply device.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>
> ---
>   drivers/power/supply/power_supply_core.c  | 153 +++++++++++++++++++---
>   drivers/power/supply/power_supply_sysfs.c |  16 +++
>   include/linux/power_supply.h              |  31 +++++
>   3 files changed, 181 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index f3d7c1da299f..c3684ec46b3f 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -388,7 +388,7 @@ static int __power_supply_get_supplier_property(struct device *dev, void *_data)
>   	struct psy_get_supplier_prop_data *data = _data;
>   
>   	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 0; /* Continue iterating */
> @@ -832,6 +832,111 @@ void power_supply_put_battery_info(struct power_supply *psy,
>   }
>   EXPORT_SYMBOL_GPL(power_supply_put_battery_info);
>   
> +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);

This is not really relevant for the series. Just speaking it as it came 
into my mind - I am not expecting changes to this series.

I do very much like the way you have these battery-info APIs not 
requiring the "struct power_supply *psy". It may be useful for drivers 
to get the stuff from battery-node prior registering to the power-supply 
core. I think it'd be nice to have a 'power-supply-info getter API like 
power_supply_get_battery_info() - which does not require the struct 
power_supply * but just a device pointer or fwnode pointer. I think it 
might also be reasonable to pull the battery-info parsing APIs in own 
file. Or maybe not - definitely up-to you guys. I don't have any active 
psy-stuff at my hands right now :)

> +
>   /**
>    * power_supply_temp2resist_simple() - find the battery internal resistance
>    * percent from temperature
> @@ -1046,6 +1151,22 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
>   }
>   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,
>   			    enum power_supply_property psp,
>   			    union power_supply_propval *val)
> @@ -1056,9 +1177,13 @@ int power_supply_get_property(struct power_supply *psy,
>   		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(psy->desc->expose_battery_info)
> +		return power_supply_battery_info_get_prop(psy->battery_info, psp, val);
> +	else
> +		return -EINVAL;
>   }
> -EXPORT_SYMBOL_GPL(power_supply_get_property);
>   
>   int power_supply_set_property(struct power_supply *psy,
>   			    enum power_supply_property psp,
> @@ -1117,22 +1242,6 @@ void power_supply_unreg_notifier(struct notifier_block *nb)
>   }
>   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
>   static int power_supply_read_temp(struct thermal_zone_device *tzd,
>   		int *temp)
> @@ -1255,6 +1364,12 @@ __power_supply_register(struct device *parent,
>   		goto check_supplies_failed;
>   	}
>   
> +	if (psy->desc->expose_battery_info) {
> +		rc = power_supply_get_battery_info(psy, &psy->battery_info);
> +		if (rc)
> +			goto check_supplies_failed;
> +	}
> +
>   	spin_lock_init(&psy->changed_lock);
>   	rc = device_add(dev);
>   	if (rc)
> diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> index c228205e0953..8822a17f9589 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -380,6 +380,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
>   		}
>   	}
>   
> +	if (psy->desc->expose_battery_info) {
> +		if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
> +			return mode;
> +	}
> +
>   	return 0;
>   }
>   
> @@ -488,6 +493,17 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
>   			goto out;
>   	}
>   
> +	if (psy->desc->expose_battery_info) {
> +		for (j = 0; j < ARRAY_SIZE(power_supply_battery_info_properties); j++) {
> +			if (!power_supply_battery_info_has_prop(psy->battery_info, power_supply_battery_info_properties[j]))
> +				continue;
> +			ret = add_prop_uevent(dev, env, power_supply_battery_info_properties[j],
> +				      prop_buf);

Usually I do not spot styling things like this - but for some reason it 
now caught my attention. If you for some reason respin, then you might 
want to either do this an oneliner - or split the longer line 
"power_supply_battery_info_has_prop(..." just above.

With or without that:
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>



-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources
  2023-03-09 22:50 ` [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Sebastian Reichel
  2023-03-10  8:21   ` Linus Walleij
@ 2023-03-13  7:14   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  7:14 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

Hi Sebastian, All

To me this does look like a great simplification :)

On 3/10/23 00:50, Sebastian Reichel wrote:
> Convert driver to use managed resources to simplify driver code.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>



-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support
  2023-03-10  8:29   ` Linus Walleij
@ 2023-03-13  7:49     ` Matti Vaittinen
  2023-03-13  8:33       ` Linus Walleij
  0 siblings, 1 reply; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  7:49 UTC (permalink / raw)
  To: Linus Walleij, Sebastian Reichel
  Cc: Rob Herring, Krzysztof Kozlowski, linux-kernel, linux-pm, devicetree

Hi dee Ho all,

On 3/10/23 10:29, Linus Walleij wrote:
> On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:
> 
>> Drop CHARGE_NOW support, which requires a platform specific
>> calculation method.
>>
>> Signed-off-by: Sebastian Reichel <sre@kernel.org>
> 
> I agree. If we want to support this, we should use the generic
> methods with interpolation tables defined in DT as well, and it also
> ideally requires load compensated resistance calculation to figure
> out Ri so this can bring any kind of reasonable precision.

I guess you have your reasons, besides you have far better insight to 
things than I do - hence I am not really objecting this - just asking a 
question ;)

Do we have generic facilities of computing this based on the DT tables / 
Ri in place(?) I guess that we do need/see platform specific 
implementations as long as there is no generic "de-facto" way of doing 
this available...

Well, maybe this helps kicking things to that direction :)

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>


-- Matti


-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message
  2023-03-09 22:50 ` [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Sebastian Reichel
  2023-03-10  8:29   ` Linus Walleij
@ 2023-03-13  7:50   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  7:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On 3/10/23 00:50, Sebastian Reichel wrote:
> Error printing happens automatically for memory allocation problems.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

> ---
>   drivers/power/supply/generic-adc-battery.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index d07eeb7d46d3..771e5cfc49c3 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -243,10 +243,8 @@ static int gab_probe(struct platform_device *pdev)
>   	bool any = false;
>   
>   	adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
> -	if (!adc_bat) {
> -		dev_err(&pdev->dev, "failed to allocate memory\n");
> +	if (!adc_bat)
>   		return -ENOMEM;
> -	}
>   
>   	psy_cfg.drv_data = adc_bat;
>   	psy_desc = &adc_bat->psy_desc;

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
  2023-03-09 22:50 ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
  2023-03-10  8:23   ` Linus Walleij
@ 2023-03-13  7:52   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  7:52 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On 3/10/23 00:50, Sebastian Reichel wrote:
> power-supply properties are reported in µV, µA and µW.
> The IIO API provides mV, mA, mW, so the values need to
> be multiplied by 1000.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

As Linus wrote, Fixes-tag would be good. With that remark:
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

> ---
>   drivers/power/supply/generic-adc-battery.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index 917bd2a6cc52..535972a332b3 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -136,6 +136,9 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
>   			result);
>   	if (ret < 0)
>   		pr_err("read channel error\n");
> +	else
> +		*result *= 1000;
> +
>   	return ret;
>   }
>   

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic
  2023-03-09 22:50 ` [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Sebastian Reichel
  2023-03-10  8:31   ` Linus Walleij
@ 2023-03-13  8:19   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  8:19 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

Hi,

Looks good to me.

On 3/10/23 00:50, Sebastian Reichel wrote:
> Drop mostly useless gab_prop_to_chan() function by directly
> supplying the correct enum value to read_channel().
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support
  2023-03-09 22:50 ` [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Sebastian Reichel
  2023-03-10  8:32   ` Linus Walleij
@ 2023-03-13  8:22   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  8:22 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On 3/10/23 00:50, Sebastian Reichel wrote:
> This adds full DT support to the driver. Because of the previous
> changes just adding a compatible value is enough.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

Best Regards,
	-- Matti

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info
  2023-03-09 22:50 ` [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Sebastian Reichel
  2023-03-10  8:33   ` Linus Walleij
@ 2023-03-13  8:25   ` Matti Vaittinen
  1 sibling, 0 replies; 61+ messages in thread
From: Matti Vaittinen @ 2023-03-13  8:25 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Linus Walleij, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On 3/10/23 00:50, Sebastian Reichel wrote:
> jz4740-battery.c and s3c_adc_battery.c have been removed
> from the tree and after all of my restructuring the driver
> is basically no longer based on them.
> 
> Thus update the copyright information and switch to SPDX
> license identifier while being at it.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

> ---
>   drivers/power/supply/generic-adc-battery.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index 436e75d226ed..ac72140dc136 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -1,13 +1,8 @@
> +// SPDX-License-Identifier: GPL-2.0
>   /*
> - * Generic battery driver code using IIO
> + * Generic battery driver using IIO
>    * Copyright (C) 2012, Anish Kumar <anish198519851985@gmail.com>
> - * based on jz4740-battery.c
> - * based on s3c_adc_battery.c
> - *
> - * This file is subject to the terms and conditions of the GNU General Public
> - * License.  See the file COPYING in the main directory of this archive for
> - * more details.
> - *
> + * Copyright (c) 2023, Sebastian Reichel <sre@kernel.org>
>    */
>   #include <linux/interrupt.h>
>   #include <linux/platform_device.h>

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support
  2023-03-13  7:49     ` Matti Vaittinen
@ 2023-03-13  8:33       ` Linus Walleij
  0 siblings, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-13  8:33 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	linux-kernel, linux-pm, devicetree

On Mon, Mar 13, 2023 at 8:49 AM Matti Vaittinen
<mazziesaccount@gmail.com> wrote:
> On 3/10/23 10:29, Linus Walleij wrote:
> > On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:
> >
> >> Drop CHARGE_NOW support, which requires a platform specific
> >> calculation method.
> >>
> >> Signed-off-by: Sebastian Reichel <sre@kernel.org>
> >
> > I agree. If we want to support this, we should use the generic
> > methods with interpolation tables defined in DT as well, and it also
> > ideally requires load compensated resistance calculation to figure
> > out Ri so this can bring any kind of reasonable precision.
>
> I guess you have your reasons, besides you have far better insight to
> things than I do - hence I am not really objecting this - just asking a
> question ;)
>
> Do we have generic facilities of computing this based on the DT tables /
> Ri in place(?)

Not yet, for the Samsung batteries I used a static look-up table
derived from the compatible string for calculating Ri from VBAT
and from that calculate the capacity from estimated open
circuit voltage, see
drivers/power/supply/samsung-sdi-battery.c

> I guess that we do need/see platform specific
> implementations as long as there is no generic "de-facto" way of doing
> this available...

The method I used with Samsung batteries is fine as long as all you
need to know to know everything about a battery is the compatible
string. Pretty much any Lion battery with a clearly defined product
name can be done this way.

The only reason to put the interpolation tables into the device
tree would be to support any random battery, such as one
that you do not know the model or this can change.

I am however mildly sceptic about adding that: if you know the
VBAT-to-Ri and OCV-to-capacity tables, you must have a
datasheet, and then you know the name of the battery product
and hence you know the right compatible string...

I think the right way to handle any capacity curves for any battery
would be to create static data like I did for the Samsung batteries.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (7 preceding siblings ...)
  2023-03-13  2:50       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Zheng Hacker
@ 2023-03-13 23:17       ` Sebastian Reichel
  2023-03-14  8:14       ` Linus Walleij
  9 siblings, 0 replies; 61+ messages in thread
From: Sebastian Reichel @ 2023-03-13 23:17 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

Hi,

On Fri, Mar 10, 2023 at 09:23:06AM +0100, Linus Walleij wrote:
> On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:
> 
> > power-supply properties are reported in µV, µA and µW.
> > The IIO API provides mV, mA, mW, so the values need to
> > be multiplied by 1000.
> >
> > Signed-off-by: Sebastian Reichel <sre@kernel.org>
> 
> Fixes: tag?
> Cc: stable@vger.kernel.org
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> This code can not have seen much testing.

There is no mainline board using this driver and I think there
never was one. I did add a Fixes tag now, but its probably not worth
any backporting trouble considering it has no users.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
  2023-03-11 17:54     ` Sebastian Reichel
                         ` (8 preceding siblings ...)
  2023-03-13 23:17       ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
@ 2023-03-14  8:14       ` Linus Walleij
  9 siblings, 0 replies; 61+ messages in thread
From: Linus Walleij @ 2023-03-14  8:14 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Matti Vaittinen, Rob Herring, Krzysztof Kozlowski, linux-kernel,
	linux-pm, devicetree

On Tue, Mar 14, 2023 at 12:17 AM Sebastian Reichel <sre@kernel.org> wrote:

> There is no mainline board using this driver and I think there
> never was one. I did add a Fixes tag now, but its probably not worth
> any backporting trouble considering it has no users.

Good point. If a tree falls in the wood an no-one is there to hear it,
it doesn't make a sound.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2023-03-14  8:17 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 22:50 [PATCHv1 00/11] Add DT support for generic ADC battery Sebastian Reichel
2023-03-09 22:50 ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Sebastian Reichel
2023-03-10  8:14   ` Linus Walleij
2023-03-11 17:54     ` Sebastian Reichel
2023-03-12 17:07       ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
2023-03-12 22:27       ` [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Sebastian Reichel
2023-03-12 22:31       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Sebastian Reichel
2023-03-12 22:33       ` [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Sebastian Reichel
2023-03-12 22:36       ` [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties Sebastian Reichel
2023-03-12 22:46       ` drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) Sebastian Reichel
2023-03-12 22:50       ` [PATCH] power: supply: bq256xx: Support to disable charger Sebastian Reichel
2023-03-13  2:50       ` [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Zheng Hacker
2023-03-13 23:17       ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
2023-03-14  8:14       ` Linus Walleij
2023-03-12 11:29   ` [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Krzysztof Kozlowski
2023-03-13  6:13   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Sebastian Reichel
2023-03-10  1:36   ` kernel test robot
2023-03-10  5:10   ` kernel test robot
2023-03-10  8:20   ` Linus Walleij
2023-03-13  6:45   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Sebastian Reichel
2023-03-10  8:21   ` Linus Walleij
2023-03-13  7:14   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Sebastian Reichel
2023-03-10  8:23   ` Linus Walleij
2023-03-13  7:52   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support Sebastian Reichel
2023-03-10  8:24   ` Linus Walleij
2023-03-09 22:50 ` [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support Sebastian Reichel
2023-03-10  8:29   ` Linus Walleij
2023-03-13  7:49     ` Matti Vaittinen
2023-03-13  8:33       ` Linus Walleij
2023-03-09 22:50 ` [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Sebastian Reichel
2023-03-10  8:29   ` Linus Walleij
2023-03-13  7:50   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API Sebastian Reichel
2023-03-10  8:30   ` Linus Walleij
2023-03-09 22:50 ` [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Sebastian Reichel
2023-03-10  8:31   ` Linus Walleij
2023-03-13  8:19   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Sebastian Reichel
2023-03-10  8:32   ` Linus Walleij
2023-03-13  8:22   ` Matti Vaittinen
2023-03-09 22:50 ` [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Sebastian Reichel
2023-03-10  8:33   ` Linus Walleij
2023-03-13  8:25   ` Matti Vaittinen
  -- strict thread matches above, loose matches on Subject: below --
2023-03-11 17:46 [PATCH v2] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Zheng Wang
2023-03-11 11:15 [PATCH 1/6] power: supply: rt9455_charger: mark OF related data as maybe unused Krzysztof Kozlowski
2023-03-11 11:15 ` [PATCH 2/6] power: supply: twl4030_charger: " Krzysztof Kozlowski
2023-03-11 11:15 ` [PATCH 3/6] power: supply: lp8727_charger: " Krzysztof Kozlowski
2023-03-11 11:15 ` [PATCH 4/6] power: supply: ltc4162-l-charger: " Krzysztof Kozlowski
2023-03-11 11:15 ` [PATCH 5/6] power: supply: bq24257_charger: " Krzysztof Kozlowski
2023-03-11 11:15 ` [PATCH 6/6] power: supply: bq25890_charger: " Krzysztof Kozlowski
2023-03-10 20:06 [PATCH] power: reset: qcom-pon: drop of_match_ptr for ID table Krzysztof Kozlowski
2023-03-10 20:10 ` Konrad Dybcio
2023-03-10 20:48 ` Marijn Suijten
2023-03-10 20:54   ` Krzysztof Kozlowski
2023-03-10 17:04 drivers/power/supply/qcom_battmgr.c:357:31: sparse: sparse: incorrect type in initializer (different base types) kernel test robot
2023-03-10 14:47 [PATCH] power: supply: charger-manager: Use of_property_read_bool() for boolean properties Rob Herring
2023-03-09  6:41 [PATCH] power: supply: bq256xx: Support to disable charger Hermes Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).