Linux Power Management development
 help / color / mirror / Atom feed
* [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; 59+ 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] 59+ 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; 59+ 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] 59+ 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; 59+ 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] 59+ 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; 59+ 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] 59+ messages in thread
* [PATCH] power: supply: bq256xx: Support to disable charger
@ 2023-03-09  6:41 Hermes Zhang
  0 siblings, 0 replies; 59+ 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] 59+ messages in thread

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

Thread overview: 59+ 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 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 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