* [PATCH v3 00/11] Add support for the TI BQ25792 battery charger
@ 2026-03-10 9:28 Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 01/11] dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792 Alexey Charkov
` (10 more replies)
0 siblings, 11 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov, Krzysztof Kozlowski, stable
This adds support for the TI BQ25792 battery charger, which is similar in
overall logic to the BQ25703A, but has a different register layout and
slightly different lower-level programming logic.
The series is organized as follows:
- Patch 1 adds the new variant to the existing DT binding, including the
changes in electrical characteristics
- Patches 2-4 are minor cleanups to the existing BQ25703A OTG regulator
driver, slimming down the code and making it more reusable for the new
BQ25792 variant
- Patch 5 is a logical fix to the BQ25703A clamping logic for VSYSMIN
(this is a standalone fix which can be applied independently and may be
backported to stable)
- Patches 6-8 are slight refactoring of the existing BQ25703A charger
driver to make it more reusable for the new BQ25792 variant
- Patch 9 adds platform data to distinguish between the two variants in
the parent MFD driver, and binds it to the new compatible string
- Patches 10-11 add variant-specific code to support the new BQ25792
variant in the regulator part and the charger part respectively,
selected by the platform data added in patch 9
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
Changes in v3:
- Move MFD cell definitions back out of the probe function (Lee Jones)
- Collect tags from Mark Brown, Krzysztof Kozlowski and Chris Morgan (thanks!)
- Enable ship FET functionality at init for BQ25792
- Link to v2: https://lore.kernel.org/r/20260306-bq25792-v2-0-6595249d6e6f@flipper.net
Changes in v2:
- Fix an error in DT schema (thanks Rob's bot)
- Ensure the broadest constraints for all variants remain in the common
part of the schema, per writing-schema doc (thanks Krzysztof)
- Link to v1: https://lore.kernel.org/r/20260303-bq25792-v1-0-e6e5e0033458@flipper.net
---
Alexey Charkov (11):
dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792
regulator: bq257xx: Remove reference to the parent MFD's dev
regulator: bq257xx: Drop the regulator_dev from the driver data
regulator: bq257xx: Make OTG enable GPIO really optional
power: supply: bq257xx: Fix VSYSMIN clamping logic
power: supply: bq257xx: Make the default current limit a per-chip attribute
power: supply: bq257xx: Consistently use indirect get/set helpers
power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states
mfd: bq257xx: Add BQ25792 support
regulator: bq257xx: Add support for BQ25792
power: supply: bq257xx: Add support for BQ25792
.../devicetree/bindings/mfd/ti,bq25703a.yaml | 73 ++-
drivers/mfd/bq257xx.c | 64 ++-
drivers/power/supply/bq257xx_charger.c | 535 ++++++++++++++++++++-
drivers/regulator/bq257xx-regulator.c | 123 ++++-
include/linux/mfd/bq257xx.h | 415 ++++++++++++++++
5 files changed, 1170 insertions(+), 40 deletions(-)
---
base-commit: a0ae2a256046c0c5d3778d1a194ff2e171f16e5f
change-id: 20260303-bq25792-0132ac86846d
Best regards,
--
Alexey Charkov <alchark@flipper.net>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 01/11] dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 02/11] regulator: bq257xx: Remove reference to the parent MFD's dev Alexey Charkov
` (9 subsequent siblings)
10 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov, Krzysztof Kozlowski
TI BQ25792 is similar in operation to BQ25703A, but has a different
register layout and different current/voltage capabilities.
Expand the existing BQ25703A binding to include BQ25792, and move the
voltage and current limits into per-variant conditional statements.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
.../devicetree/bindings/mfd/ti,bq25703a.yaml | 73 +++++++++++++++++++---
1 file changed, 63 insertions(+), 10 deletions(-)
diff --git a/Documentation/devicetree/bindings/mfd/ti,bq25703a.yaml b/Documentation/devicetree/bindings/mfd/ti,bq25703a.yaml
index ba14663c9266..cdce83f05804 100644
--- a/Documentation/devicetree/bindings/mfd/ti,bq25703a.yaml
+++ b/Documentation/devicetree/bindings/mfd/ti,bq25703a.yaml
@@ -4,17 +4,16 @@
$id: http://devicetree.org/schemas/mfd/ti,bq25703a.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
-title: BQ25703A Charger Manager/Buck/Boost Converter
+title: BQ257xx Charger Manager/Buck/Boost Converter
maintainers:
- Chris Morgan <macromorgan@hotmail.com>
-allOf:
- - $ref: /schemas/power/supply/power-supply.yaml#
-
properties:
compatible:
- const: ti,bq25703a
+ enum:
+ - ti,bq25703a
+ - ti,bq25792
reg:
const: 0x6b
@@ -25,7 +24,6 @@ properties:
powering the device.
minimum: 50000
maximum: 6400000
- default: 3250000
interrupts:
maxItems: 1
@@ -57,11 +55,11 @@ properties:
minimum: 0
maximum: 6350000
regulator-min-microvolt:
- minimum: 4480000
- maximum: 20800000
+ minimum: 2800000
+ maximum: 22000000
regulator-max-microvolt:
- minimum: 4480000
- maximum: 20800000
+ minimum: 2800000
+ maximum: 22000000
enable-gpios:
description:
The BQ25703 may require both a register write and a GPIO
@@ -74,6 +72,61 @@ properties:
- regulator-min-microvolt
- regulator-max-microvolt
+allOf:
+ - $ref: /schemas/power/supply/power-supply.yaml#
+ - if:
+ properties:
+ compatible:
+ const: ti,bq25703a
+ then:
+ properties:
+ input-current-limit-microamp:
+ minimum: 50000
+ maximum: 6400000
+ default: 3250000
+ regulators:
+ properties:
+ vbus:
+ properties:
+ regulator-min-microamp:
+ minimum: 0
+ maximum: 6350000
+ regulator-max-microamp:
+ minimum: 0
+ maximum: 6350000
+ regulator-min-microvolt:
+ minimum: 4480000
+ maximum: 20800000
+ regulator-max-microvolt:
+ minimum: 4480000
+ maximum: 20800000
+ - if:
+ properties:
+ compatible:
+ const: ti,bq25792
+ then:
+ properties:
+ input-current-limit-microamp:
+ minimum: 100000
+ maximum: 3300000
+ default: 3000000
+ regulators:
+ properties:
+ vbus:
+ properties:
+ regulator-min-microamp:
+ minimum: 0
+ maximum: 3320000
+ regulator-max-microamp:
+ minimum: 0
+ maximum: 3320000
+ regulator-min-microvolt:
+ minimum: 2800000
+ maximum: 22000000
+ regulator-max-microvolt:
+ minimum: 2800000
+ maximum: 22000000
+
unevaluatedProperties: false
required:
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 02/11] regulator: bq257xx: Remove reference to the parent MFD's dev
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 01/11] dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792 Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 03/11] regulator: bq257xx: Drop the regulator_dev from the driver data Alexey Charkov
` (8 subsequent siblings)
10 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Drop the ->bq field from the platform data of the bq257xx regulator driver,
which was only used to get the regmap of the parent MFD device, and use the
regmap from the regulator_dev instead, slimming down the code a bit.
Acked-by: Mark Brown <broonie@kernel.org>
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/regulator/bq257xx-regulator.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c
index dab8f1ab4450..812938e565e3 100644
--- a/drivers/regulator/bq257xx-regulator.c
+++ b/drivers/regulator/bq257xx-regulator.c
@@ -15,7 +15,6 @@
#include <linux/regulator/of_regulator.h>
struct bq257xx_reg_data {
- struct bq257xx_device *bq;
struct regulator_dev *bq257xx_reg;
struct gpio_desc *otg_en_gpio;
struct regulator_desc desc;
@@ -23,11 +22,11 @@ struct bq257xx_reg_data {
static int bq25703_vbus_get_cur_limit(struct regulator_dev *rdev)
{
- struct bq257xx_reg_data *pdata = rdev_get_drvdata(rdev);
+ struct regmap *regmap = rdev_get_regmap(rdev);
int ret;
unsigned int reg;
- ret = regmap_read(pdata->bq->regmap, BQ25703_OTG_CURRENT, ®);
+ ret = regmap_read(regmap, BQ25703_OTG_CURRENT, ®);
if (ret)
return ret;
return FIELD_GET(BQ25703_OTG_CUR_MASK, reg) * BQ25703_OTG_CUR_STEP_UA;
@@ -40,7 +39,7 @@ static int bq25703_vbus_get_cur_limit(struct regulator_dev *rdev)
static int bq25703_vbus_set_cur_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
- struct bq257xx_reg_data *pdata = rdev_get_drvdata(rdev);
+ struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int reg;
if ((min_uA > BQ25703_OTG_CUR_MAX_UA) || (max_uA < 0))
@@ -52,7 +51,7 @@ static int bq25703_vbus_set_cur_limit(struct regulator_dev *rdev,
if ((reg * BQ25703_OTG_CUR_STEP_UA) < min_uA)
return -EINVAL;
- return regmap_write(pdata->bq->regmap, BQ25703_OTG_CURRENT,
+ return regmap_write(regmap, BQ25703_OTG_CURRENT,
FIELD_PREP(BQ25703_OTG_CUR_MASK, reg));
}
@@ -137,7 +136,6 @@ static void bq257xx_reg_dt_parse_gpio(struct platform_device *pdev)
static int bq257xx_regulator_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct bq257xx_device *bq = dev_get_drvdata(pdev->dev.parent);
struct bq257xx_reg_data *pdata;
struct device_node *np = dev->of_node;
struct regulator_config cfg = {};
@@ -149,7 +147,6 @@ static int bq257xx_regulator_probe(struct platform_device *pdev)
if (!pdata)
return -ENOMEM;
- pdata->bq = bq;
pdata->desc = bq25703_vbus_desc;
platform_set_drvdata(pdev, pdata);
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 03/11] regulator: bq257xx: Drop the regulator_dev from the driver data
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 01/11] dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792 Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 02/11] regulator: bq257xx: Remove reference to the parent MFD's dev Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 04/11] regulator: bq257xx: Make OTG enable GPIO really optional Alexey Charkov
` (7 subsequent siblings)
10 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
The field was not used anywhere in the driver, so just drop it. This helps
further slim down the platform data structure.
Acked-by: Mark Brown <broonie@kernel.org>
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/regulator/bq257xx-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c
index 812938e565e3..674dae6109e9 100644
--- a/drivers/regulator/bq257xx-regulator.c
+++ b/drivers/regulator/bq257xx-regulator.c
@@ -15,7 +15,6 @@
#include <linux/regulator/of_regulator.h>
struct bq257xx_reg_data {
- struct regulator_dev *bq257xx_reg;
struct gpio_desc *otg_en_gpio;
struct regulator_desc desc;
};
@@ -139,6 +138,7 @@ static int bq257xx_regulator_probe(struct platform_device *pdev)
struct bq257xx_reg_data *pdata;
struct device_node *np = dev->of_node;
struct regulator_config cfg = {};
+ struct regulator_dev *rdev;
pdev->dev.of_node = pdev->dev.parent->of_node;
pdev->dev.of_node_reused = true;
@@ -159,9 +159,9 @@ static int bq257xx_regulator_probe(struct platform_device *pdev)
if (!cfg.regmap)
return -ENODEV;
- pdata->bq257xx_reg = devm_regulator_register(dev, &pdata->desc, &cfg);
- if (IS_ERR(pdata->bq257xx_reg)) {
- return dev_err_probe(&pdev->dev, PTR_ERR(pdata->bq257xx_reg),
+ rdev = devm_regulator_register(dev, &pdata->desc, &cfg);
+ if (IS_ERR(rdev)) {
+ return dev_err_probe(&pdev->dev, PTR_ERR(rdev),
"error registering bq257xx regulator");
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 04/11] regulator: bq257xx: Make OTG enable GPIO really optional
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (2 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 03/11] regulator: bq257xx: Drop the regulator_dev from the driver data Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic Alexey Charkov
` (6 subsequent siblings)
10 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
The bindings describe the OTG enable GPIO as optional, but the driver
gets upset if it's not provided in the device tree.
Make the driver accept the absence of the GPIO, and just use register
writes to handle OTG mode in that case, skipping the error message for
-ENOENT.
Acked-by: Mark Brown <broonie@kernel.org>
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/regulator/bq257xx-regulator.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c
index 674dae6109e9..0bb58ab4b8d4 100644
--- a/drivers/regulator/bq257xx-regulator.c
+++ b/drivers/regulator/bq257xx-regulator.c
@@ -126,6 +126,12 @@ static void bq257xx_reg_dt_parse_gpio(struct platform_device *pdev)
of_node_put(subchild);
if (IS_ERR(pdata->otg_en_gpio)) {
+ if (PTR_ERR(pdata->otg_en_gpio) == -ENOENT) {
+ /* No GPIO, will only use register writes for OTG */
+ pdata->otg_en_gpio = NULL;
+ return;
+ }
+
dev_err(&pdev->dev, "Error getting enable gpio: %ld\n",
PTR_ERR(pdata->otg_en_gpio));
return;
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (3 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 04/11] regulator: bq257xx: Make OTG enable GPIO really optional Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-11 7:08 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute Alexey Charkov
` (5 subsequent siblings)
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov, stable
The minimal system voltage (VSYSMIN) is meant to protect the battery from
dangerous over-discharge. When the device tree provides a value for the
minimum design voltage of the battery, the user should not be allowed to
set a lower VSYSMIN, as that would defeat the purpose of this protection.
Flip the clamping logic when setting VSYSMIN to ensure that battery design
voltage is respected.
Cc: stable@vger.kernel.org
Fixes: 1cc017b7f9c7 ("power: supply: bq257xx: Add support for BQ257XX charger")
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/power/supply/bq257xx_charger.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
index 02c7d8b61e82..7ca4ae610902 100644
--- a/drivers/power/supply/bq257xx_charger.c
+++ b/drivers/power/supply/bq257xx_charger.c
@@ -128,9 +128,8 @@ static int bq25703_get_min_vsys(struct bq257xx_chg *pdata, int *intval)
* @vsys: voltage value to set in uV.
*
* This function takes a requested minimum system voltage value, clamps
- * it between the minimum supported value by the charger and a user
- * defined minimum system value, and then writes the value to the
- * appropriate register.
+ * it between the user defined minimum system value and the maximum supported
+ * value by the charger, and then writes the value to the appropriate register.
*
* Return: Returns 0 on success or error if an error occurs.
*/
@@ -139,7 +138,7 @@ static int bq25703_set_min_vsys(struct bq257xx_chg *pdata, int vsys)
unsigned int reg;
int vsys_min = pdata->vsys_min;
- vsys = clamp(vsys, BQ25703_MINVSYS_MIN_UV, vsys_min);
+ vsys = clamp(vsys, vsys_min, BQ25703_MINVSYS_MAX_UV);
reg = ((vsys - BQ25703_MINVSYS_MIN_UV) / BQ25703_MINVSYS_STEP_UV);
reg = FIELD_PREP(BQ25703_MINVSYS_MASK, reg);
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (4 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-11 7:08 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers Alexey Charkov
` (4 subsequent siblings)
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Add a field for the default current limit to the bq257xx_info structure and
use it instead of the hardcoded value in the probe function.
This prepares the driver for allowing different electrical constraints for
different chip variants.
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/power/supply/bq257xx_charger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
index 7ca4ae610902..e14dd16f9d08 100644
--- a/drivers/power/supply/bq257xx_charger.c
+++ b/drivers/power/supply/bq257xx_charger.c
@@ -26,6 +26,7 @@ struct bq257xx_chg;
* @bq257xx_set_iindpm: set maximum input current (in uA)
*/
struct bq257xx_chip_info {
+ int default_iindpm_uA;
int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
@@ -627,6 +628,7 @@ static const struct power_supply_desc bq257xx_power_supply_desc = {
};
static const struct bq257xx_chip_info bq25703_chip_info = {
+ .default_iindpm_uA = BQ25703_IINDPM_DEFAULT_UA,
.bq257xx_hw_init = &bq25703_hw_init,
.bq257xx_hw_shutdown = &bq25703_hw_shutdown,
.bq257xx_get_state = &bq25703_get_state,
@@ -675,7 +677,7 @@ static int bq257xx_parse_dt(struct bq257xx_chg *pdata,
"input-current-limit-microamp",
&pdata->iindpm_max);
if (ret)
- pdata->iindpm_max = BQ25703_IINDPM_DEFAULT_UA;
+ pdata->iindpm_max = pdata->chip->default_iindpm_uA;
return 0;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (5 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-11 7:09 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states Alexey Charkov
` (3 subsequent siblings)
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Move the remaining get/set helper functions to indirect calls via the
per-chip bq257xx_chip_info struct.
This improves the consistency of the code and prepares the driver to
support multiple chip variants with different register layouts and bit
definitions.
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/power/supply/bq257xx_charger.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
index e14dd16f9d08..deb60a9bd222 100644
--- a/drivers/power/supply/bq257xx_charger.c
+++ b/drivers/power/supply/bq257xx_charger.c
@@ -30,9 +30,15 @@ struct bq257xx_chip_info {
int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
+ int (*bq257xx_get_ichg)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_ichg)(struct bq257xx_chg *pdata, int ichg);
+ int (*bq257xx_get_vbatreg)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_vbatreg)(struct bq257xx_chg *pdata, int vbatreg);
+ int (*bq257xx_get_iindpm)(struct bq257xx_chg *pdata, int *intval);
int (*bq257xx_set_iindpm)(struct bq257xx_chg *pdata, int iindpm);
+ int (*bq257xx_get_cur)(struct bq257xx_chg *pdata, int *intval);
+ int (*bq257xx_get_vbat)(struct bq257xx_chg *pdata, int *intval);
+ int (*bq257xx_get_min_vsys)(struct bq257xx_chg *pdata, int *intval);
};
/**
@@ -489,22 +495,22 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
break;
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
- return bq25703_get_iindpm(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_iindpm(pdata, &val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
- return bq25703_get_chrg_volt(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_vbatreg(pdata, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
- return bq25703_get_cur(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_cur(pdata, &val->intval);
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- return bq25703_get_vbat(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_vbat(pdata, &val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
- return bq25703_get_ichg_cur(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_ichg(pdata, &val->intval);
case POWER_SUPPLY_PROP_VOLTAGE_MIN:
- return bq25703_get_min_vsys(pdata, &val->intval);
+ return pdata->chip->bq257xx_get_min_vsys(pdata, &val->intval);
case POWER_SUPPLY_PROP_USB_TYPE:
val->intval = pdata->usb_type;
@@ -632,9 +638,15 @@ static const struct bq257xx_chip_info bq25703_chip_info = {
.bq257xx_hw_init = &bq25703_hw_init,
.bq257xx_hw_shutdown = &bq25703_hw_shutdown,
.bq257xx_get_state = &bq25703_get_state,
+ .bq257xx_get_ichg = &bq25703_get_ichg_cur,
.bq257xx_set_ichg = &bq25703_set_ichg_cur,
+ .bq257xx_get_vbatreg = &bq25703_get_chrg_volt,
.bq257xx_set_vbatreg = &bq25703_set_chrg_volt,
+ .bq257xx_get_iindpm = &bq25703_get_iindpm,
.bq257xx_set_iindpm = &bq25703_set_iindpm,
+ .bq257xx_get_cur = &bq25703_get_cur,
+ .bq257xx_get_vbat = &bq25703_get_vbat,
+ .bq257xx_get_min_vsys = &bq25703_get_min_vsys,
};
/**
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (6 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-11 7:09 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support Alexey Charkov
` (2 subsequent siblings)
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
The driver currently reports the 'charging' and 'overvoltage' states based
on a logical expression in the get_charger_property() wrapper function.
This doesn't scale well to other chip variants, which may have a different
number and type of hardware reported conditions which fall into these
broad power supply states.
Move the logic for determining 'charging' and 'overvoltage' states into
chip-specific accessors, which can be overridden by each variant as
needed.
This helps keep the get_charger_property() wrapper function chip-agnostic
while allowing for new chip variants to be added bringing their own logic.
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/power/supply/bq257xx_charger.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
index deb60a9bd222..951abd035fc5 100644
--- a/drivers/power/supply/bq257xx_charger.c
+++ b/drivers/power/supply/bq257xx_charger.c
@@ -64,8 +64,10 @@ struct bq257xx_chg {
struct bq257xx_device *bq;
struct power_supply *charger;
bool online;
+ bool charging;
bool fast_charge;
bool pre_charge;
+ bool overvoltage;
bool ov_fault;
bool batoc_fault;
bool oc_fault;
@@ -99,8 +101,10 @@ static int bq25703_get_state(struct bq257xx_chg *pdata)
pdata->online = reg & BQ25703_STS_AC_STAT;
pdata->fast_charge = reg & BQ25703_STS_IN_FCHRG;
pdata->pre_charge = reg & BQ25703_STS_IN_PCHRG;
+ pdata->charging = pdata->fast_charge || pdata->pre_charge;
pdata->ov_fault = reg & BQ25703_STS_FAULT_ACOV;
pdata->batoc_fault = reg & BQ25703_STS_FAULT_BATOC;
+ pdata->overvoltage = pdata->ov_fault || pdata->batoc_fault;
pdata->oc_fault = reg & BQ25703_STS_FAULT_ACOC;
return 0;
@@ -471,14 +475,14 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_STATUS:
if (!pdata->online)
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
- else if (pdata->fast_charge || pdata->pre_charge)
+ else if (pdata->charging)
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
break;
case POWER_SUPPLY_PROP_HEALTH:
- if (pdata->ov_fault || pdata->batoc_fault)
+ if (pdata->overvoltage)
val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
else if (pdata->oc_fault)
val->intval = POWER_SUPPLY_HEALTH_OVERCURRENT;
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (7 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 13:03 ` Lee Jones
2026-03-10 9:28 ` [PATCH v3 10/11] regulator: bq257xx: Add support for BQ25792 Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 11/11] power: supply: " Alexey Charkov
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Add register definitions and a new 'type' enum to be passed in MFD
platform data to support the BQ25792, which is a newer variant of the
BQ257xx family.
BQ25792 shares similar logic of operation with the already supported
BQ25703A but has a completely different register map and different
electrical constraints.
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/mfd/bq257xx.c | 64 ++++++-
include/linux/mfd/bq257xx.h | 417 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 477 insertions(+), 4 deletions(-)
diff --git a/drivers/mfd/bq257xx.c b/drivers/mfd/bq257xx.c
index e9d49dac0a16..7516e2ec00e6 100644
--- a/drivers/mfd/bq257xx.c
+++ b/drivers/mfd/bq257xx.c
@@ -10,6 +10,11 @@
#include <linux/mfd/core.h>
#include <linux/regmap.h>
+struct bq257xx_match_data {
+ const struct bq257xx_plat plat;
+ const struct regmap_config *regmap_config;
+};
+
static const struct regmap_range bq25703_readonly_reg_ranges[] = {
regmap_reg_range(BQ25703_CHARGER_STATUS, BQ25703_MANUFACT_DEV_ID),
};
@@ -39,15 +44,64 @@ static const struct regmap_config bq25703_regmap_config = {
.val_format_endian = REGMAP_ENDIAN_LITTLE,
};
-static const struct mfd_cell cells[] = {
+static const struct bq257xx_match_data bq25703a_match_data = {
+ .plat = { .type = BQ25703A },
+ .regmap_config = &bq25703_regmap_config,
+};
+
+static const struct regmap_range bq25792_writeable_reg_ranges[] = {
+ regmap_reg_range(BQ25792_REG00_MIN_SYS_VOLTAGE,
+ BQ25792_REG18_NTC_CONTROL_1),
+ regmap_reg_range(BQ25792_REG28_CHARGER_MASK_0,
+ BQ25792_REG30_ADC_FUNCTION_DISABLE_1),
+};
+
+static const struct regmap_access_table bq25792_writeable_regs = {
+ .yes_ranges = bq25792_writeable_reg_ranges,
+ .n_yes_ranges = ARRAY_SIZE(bq25792_writeable_reg_ranges),
+};
+
+static const struct regmap_range bq25792_volatile_reg_ranges[] = {
+ regmap_reg_range(BQ25792_REG19_ICO_CURRENT_LIMIT,
+ BQ25792_REG27_FAULT_FLAG_1),
+ regmap_reg_range(BQ25792_REG31_IBUS_ADC,
+ BQ25792_REG47_DPDM_DRIVER),
+};
+
+static const struct regmap_access_table bq25792_volatile_regs = {
+ .yes_ranges = bq25792_volatile_reg_ranges,
+ .n_yes_ranges = ARRAY_SIZE(bq25792_volatile_reg_ranges),
+};
+
+static const struct regmap_config bq25792_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = BQ25792_REG48_PART_INFORMATION,
+ .cache_type = REGCACHE_MAPLE,
+ .wr_table = &bq25792_writeable_regs,
+ .volatile_table = &bq25792_volatile_regs,
+};
+
+static const struct bq257xx_match_data bq25792_match_data = {
+ .plat = { .type = BQ25792 },
+ .regmap_config = &bq25792_regmap_config,
+};
+
+static struct mfd_cell cells[] = {
MFD_CELL_NAME("bq257xx-regulator"),
MFD_CELL_NAME("bq257xx-charger"),
};
static int bq257xx_probe(struct i2c_client *client)
{
+ const struct bq257xx_match_data *md = device_get_match_data(&client->dev);
struct bq257xx_device *ddata;
- int ret;
+ int i, ret;
+
+ for (i = 0; i < ARRAY_SIZE(cells); i++) {
+ cells[i].platform_data = &md->plat;
+ cells[i].pdata_size = sizeof(md->plat);
+ }
ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
if (!ddata)
@@ -55,7 +109,7 @@ static int bq257xx_probe(struct i2c_client *client)
ddata->client = client;
- ddata->regmap = devm_regmap_init_i2c(client, &bq25703_regmap_config);
+ ddata->regmap = devm_regmap_init_i2c(client, md->regmap_config);
if (IS_ERR(ddata->regmap)) {
return dev_err_probe(&client->dev, PTR_ERR(ddata->regmap),
"Failed to allocate register map\n");
@@ -74,12 +128,14 @@ static int bq257xx_probe(struct i2c_client *client)
static const struct i2c_device_id bq257xx_i2c_ids[] = {
{ "bq25703a" },
+ { "bq25792" },
{}
};
MODULE_DEVICE_TABLE(i2c, bq257xx_i2c_ids);
static const struct of_device_id bq257xx_of_match[] = {
- { .compatible = "ti,bq25703a" },
+ { .compatible = "ti,bq25703a", .data = &bq25703a_match_data },
+ { .compatible = "ti,bq25792", .data = &bq25792_match_data },
{}
};
MODULE_DEVICE_TABLE(of, bq257xx_of_match);
diff --git a/include/linux/mfd/bq257xx.h b/include/linux/mfd/bq257xx.h
index 1d6ddc7fb09f..b2e38a4a4738 100644
--- a/include/linux/mfd/bq257xx.h
+++ b/include/linux/mfd/bq257xx.h
@@ -98,7 +98,424 @@
#define BQ25703_EN_OTG_MASK BIT(12)
+#define BQ25792_REG00_MIN_SYS_VOLTAGE 0x00
+#define BQ25792_REG01_CHARGE_VOLTAGE_LIMIT 0x01
+#define BQ25792_REG03_CHARGE_CURRENT_LIMIT 0x03
+#define BQ25792_REG05_INPUT_VOLTAGE_LIMIT 0x05
+#define BQ25792_REG06_INPUT_CURRENT_LIMIT 0x06
+#define BQ25792_REG08_PRECHARGE_CONTROL 0x08
+#define BQ25792_REG09_TERMINATION_CONTROL 0x09
+#define BQ25792_REG0A_RECHARGE_CONTROL 0x0a
+#define BQ25792_REG0B_VOTG_REGULATION 0x0b
+#define BQ25792_REG0D_IOTG_REGULATION 0x0d
+#define BQ25792_REG0E_TIMER_CONTROL 0x0e
+#define BQ25792_REG0F_CHARGER_CONTROL_0 0x0f
+#define BQ25792_REG10_CHARGER_CONTROL_1 0x10
+#define BQ25792_REG11_CHARGER_CONTROL_2 0x11
+#define BQ25792_REG12_CHARGER_CONTROL_3 0x12
+#define BQ25792_REG13_CHARGER_CONTROL_4 0x13
+#define BQ25792_REG14_CHARGER_CONTROL_5 0x14
+/* REG15 reserved */
+#define BQ25792_REG16_TEMPERATURE_CONTROL 0x16
+#define BQ25792_REG17_NTC_CONTROL_0 0x17
+#define BQ25792_REG18_NTC_CONTROL_1 0x18
+#define BQ25792_REG19_ICO_CURRENT_LIMIT 0x19
+#define BQ25792_REG1B_CHARGER_STATUS_0 0x1b
+#define BQ25792_REG1C_CHARGER_STATUS_1 0x1c
+#define BQ25792_REG1D_CHARGER_STATUS_2 0x1d
+#define BQ25792_REG1E_CHARGER_STATUS_3 0x1e
+#define BQ25792_REG1F_CHARGER_STATUS_4 0x1f
+#define BQ25792_REG20_FAULT_STATUS_0 0x20
+#define BQ25792_REG21_FAULT_STATUS_1 0x21
+#define BQ25792_REG22_CHARGER_FLAG_0 0x22
+#define BQ25792_REG23_CHARGER_FLAG_1 0x23
+#define BQ25792_REG24_CHARGER_FLAG_2 0x24
+#define BQ25792_REG25_CHARGER_FLAG_3 0x25
+#define BQ25792_REG26_FAULT_FLAG_0 0x26
+#define BQ25792_REG27_FAULT_FLAG_1 0x27
+#define BQ25792_REG28_CHARGER_MASK_0 0x28
+#define BQ25792_REG29_CHARGER_MASK_1 0x29
+#define BQ25792_REG2A_CHARGER_MASK_2 0x2a
+#define BQ25792_REG2B_CHARGER_MASK_3 0x2b
+#define BQ25792_REG2C_FAULT_MASK_0 0x2c
+#define BQ25792_REG2D_FAULT_MASK_1 0x2d
+#define BQ25792_REG2E_ADC_CONTROL 0x2e
+#define BQ25792_REG2F_ADC_FUNCTION_DISABLE_0 0x2f
+#define BQ25792_REG30_ADC_FUNCTION_DISABLE_1 0x30
+#define BQ25792_REG31_IBUS_ADC 0x31
+#define BQ25792_REG33_IBAT_ADC 0x33
+#define BQ25792_REG35_VBUS_ADC 0x35
+#define BQ25792_REG37_VAC1_ADC 0x37
+#define BQ25792_REG39_VAC2_ADC 0x39
+#define BQ25792_REG3B_VBAT_ADC 0x3b
+#define BQ25792_REG3D_VSYS_ADC 0x3d
+#define BQ25792_REG3F_TS_ADC 0x3f
+#define BQ25792_REG41_TDIE_ADC 0x41
+#define BQ25792_REG43_DP_ADC 0x43
+#define BQ25792_REG45_DM_ADC 0x45
+#define BQ25792_REG47_DPDM_DRIVER 0x47
+#define BQ25792_REG48_PART_INFORMATION 0x48
+
+/* Minimal System Voltage */
+#define BQ25792_REG00_VSYSMIN_MASK GENMASK(5, 0)
+
+#define BQ25792_MINVSYS_MIN_UV 2500000
+#define BQ25792_MINVSYS_STEP_UV 250000
+#define BQ25792_MINVSYS_MAX_UV 16000000
+
+/* Charge Voltage Limit */
+#define BQ25792_REG01_VREG_MASK GENMASK(10, 0)
+
+#define BQ25792_VBATREG_MIN_UV 3000000
+#define BQ25792_VBATREG_STEP_UV 10000
+#define BQ25792_VBATREG_MAX_UV 18800000
+
+/* Charge Current Limit */
+#define BQ25792_REG03_ICHG_MASK GENMASK(8, 0)
+
+#define BQ25792_ICHG_MIN_UA 50000
+#define BQ25792_ICHG_STEP_UA 10000
+#define BQ25792_ICHG_MAX_UA 5000000
+
+/* Input Voltage Limit */
+#define BQ25792_REG05_VINDPM_MASK GENMASK(7, 0)
+
+/* Input Current Limit */
+#define BQ25792_REG06_IINDPM_MASK GENMASK(8, 0)
+#define BQ25792_IINDPM_DEFAULT_UA 3000000
+#define BQ25792_IINDPM_STEP_UA 10000
+#define BQ25792_IINDPM_MIN_UA 100000
+#define BQ25792_IINDPM_MAX_UA 3300000
+
+/* Precharge Control */
+#define BQ25792_REG08_VBAT_LOWV_MASK GENMASK(7, 6)
+#define BQ25792_REG08_IPRECHG_MASK GENMASK(5, 0)
+
+/* Termination Control */
+#define BQ25792_REG09_REG_RST BIT(6)
+#define BQ25792_REG09_ITERM_MASK GENMASK(4, 0)
+
+/* Re-charge Control */
+#define BQ25792_REG0A_CELL_MASK GENMASK(7, 6)
+#define BQ25792_REG0A_TRECHG_MASK GENMASK(5, 4)
+#define BQ25792_REG0A_VRECHG_MASK GENMASK(3, 0)
+
+/* VOTG regulation */
+#define BQ25792_REG0B_VOTG_MASK GENMASK(10, 0)
+
+#define BQ25792_OTG_VOLT_MIN_UV 2800000
+#define BQ25792_OTG_VOLT_STEP_UV 10000
+#define BQ25792_OTG_VOLT_MAX_UV 22000000
+#define BQ25792_OTG_VOLT_NUM_VOLT ((BQ25792_OTG_VOLT_MAX_UV \
+ - BQ25792_OTG_VOLT_MIN_UV) \
+ / BQ25792_OTG_VOLT_STEP_UV + 1)
+
+/* IOTG regulation */
+#define BQ25792_REG0D_PRECHG_TMR BIT(7)
+#define BQ25792_REG0D_IOTG_MASK GENMASK(6, 0)
+
+#define BQ25792_OTG_CUR_MIN_UA 120000
+#define BQ25792_OTG_CUR_STEP_UA 40000
+#define BQ25792_OTG_CUR_MAX_UA 3320000
+
+/* Timer Control */
+#define BQ25792_REG0E_TOPOFF_TMR_MASK GENMASK(7, 6)
+#define BQ25792_REG0E_EN_TRICHG_TMR BIT(5)
+#define BQ25792_REG0E_EN_PRECHG_TMR BIT(4)
+#define BQ25792_REG0E_EN_CHG_TMR BIT(3)
+#define BQ25792_REG0E_CHG_TMR_MASK GENMASK(2, 1)
+#define BQ25792_REG0E_TMR2X_EN BIT(0)
+
+/* Charger Control 0 */
+#define BQ25792_REG0F_EN_AUTO_IBATDIS BIT(7)
+#define BQ25792_REG0F_FORCE_IBATDIS BIT(6)
+#define BQ25792_REG0F_EN_CHG BIT(5)
+#define BQ25792_REG0F_EN_ICO BIT(4)
+#define BQ25792_REG0F_FORCE_ICO BIT(3)
+#define BQ25792_REG0F_EN_HIZ BIT(2)
+#define BQ25792_REG0F_EN_TERM BIT(1)
+/* bit0 reserved */
+
+/* Charger Control 1 */
+#define BQ25792_REG10_VAC_OVP_MASK GENMASK(5, 4)
+#define BQ25792_REG10_WD_RST BIT(3)
+#define BQ25792_REG10_WATCHDOG_MASK GENMASK(2, 0)
+
+/* Charger Control 2 */
+#define BQ25792_REG11_FORCE_INDET BIT(7)
+#define BQ25792_REG11_AUTO_INDET_EN BIT(6)
+#define BQ25792_REG11_EN_12V BIT(5)
+#define BQ25792_REG11_EN_9V BIT(4)
+#define BQ25792_REG11_HVDCP_EN BIT(3)
+#define BQ25792_REG11_SDRV_CTRL_MASK GENMASK(2, 1)
+#define BQ25792_REG11_SDRV_DLY BIT(0)
+
+/* Charger Control 3 */
+#define BQ25792_REG12_DIS_ACDRV BIT(7)
+#define BQ25792_REG12_EN_OTG BIT(6)
+#define BQ25792_REG12_PFM_OTG_DIS BIT(5)
+#define BQ25792_REG12_PFM_FWD_DIS BIT(4)
+#define BQ25792_REG12_WKUP_DLY BIT(3)
+#define BQ25792_REG12_DIS_LDO BIT(2)
+#define BQ25792_REG12_DIS_OTG_OOA BIT(1)
+#define BQ25792_REG12_DIS_FWD_OOA BIT(0)
+
+/* Charger Control 4 */
+#define BQ25792_REG13_EN_ACDRV2 BIT(7)
+#define BQ25792_REG13_EN_ACDRV1 BIT(6)
+#define BQ25792_REG13_PWM_FREQ BIT(5)
+#define BQ25792_REG13_DIS_STAT BIT(4)
+#define BQ25792_REG13_DIS_VSYS_SHORT BIT(3)
+#define BQ25792_REG13_DIS_VOTG_UVP BIT(2)
+#define BQ25792_REG13_FORCE_VINDPM_DET BIT(1)
+#define BQ25792_REG13_EN_IBUS_OCP BIT(0)
+
+/* Charger Control 5 */
+#define BQ25792_REG14_SFET_PRESENT BIT(7)
+/* bit6 reserved */
+#define BQ25792_REG14_EN_IBAT BIT(5)
+#define BQ25792_REG14_IBAT_REG_MASK GENMASK(4, 3)
+#define BQ25792_REG14_EN_IINDPM BIT(2)
+#define BQ25792_REG14_EN_EXTILIM BIT(1)
+#define BQ25792_REG14_EN_BATOC BIT(0)
+
+#define BQ25792_IBAT_3A FIELD_PREP(BQ25792_REG14_IBAT_REG_MASK, 0)
+#define BQ25792_IBAT_4A FIELD_PREP(BQ25792_REG14_IBAT_REG_MASK, 1)
+#define BQ25792_IBAT_5A FIELD_PREP(BQ25792_REG14_IBAT_REG_MASK, 2)
+#define BQ25792_IBAT_UNLIM FIELD_PREP(BQ25792_REG14_IBAT_REG_MASK, 3)
+
+/* Temperature Control */
+#define BQ25792_REG16_TREG_MASK GENMASK(7, 6)
+#define BQ25792_REG16_TSHUT_MASK GENMASK(5, 4)
+#define BQ25792_REG16_VBUS_PD_EN BIT(3)
+#define BQ25792_REG16_VAC1_PD_EN BIT(2)
+#define BQ25792_REG16_VAC2_PD_EN BIT(1)
+
+/* NTC Control 0 */
+#define BQ25792_REG17_JEITA_VSET_MASK GENMASK(7, 5)
+#define BQ25792_REG17_JEITA_ISETH_MASK GENMASK(4, 3)
+#define BQ25792_REG17_JEITA_ISETC_MASK GENMASK(2, 1)
+
+/* NTC Control 1 */
+#define BQ25792_REG18_TS_COOL_MASK GENMASK(7, 6)
+#define BQ25792_REG18_TS_WARM_MASK GENMASK(5, 4)
+#define BQ25792_REG18_BHOT_MASK GENMASK(3, 2)
+#define BQ25792_REG18_BCOLD BIT(1)
+#define BQ25792_REG18_TS_IGNORE BIT(0)
+
+/* ICO Current Limit */
+#define BQ25792_REG19_ICO_ILIM_MASK GENMASK(8, 0)
+
+/* Charger Status 0 */
+#define BQ25792_REG1B_IINDPM_STAT BIT(7)
+#define BQ25792_REG1B_VINDPM_STAT BIT(6)
+#define BQ25792_REG1B_WD_STAT BIT(5)
+#define BQ25792_REG1B_POORSRC_STAT BIT(4)
+#define BQ25792_REG1B_PG_STAT BIT(3)
+#define BQ25792_REG1B_AC2_PRESENT_STAT BIT(2)
+#define BQ25792_REG1B_AC1_PRESENT_STAT BIT(1)
+#define BQ25792_REG1B_VBUS_PRESENT_STAT BIT(0)
+
+/* Charger Status 1 */
+#define BQ25792_REG1C_CHG_STAT_MASK GENMASK(7, 5)
+#define BQ25792_REG1C_VBUS_STAT_MASK GENMASK(4, 1)
+#define BQ25792_REG1C_BC12_DONE_STAT BIT(0)
+
+/* Charger Status 2 */
+#define BQ25792_REG1D_ICO_STAT_MASK GENMASK(7, 6)
+#define BQ25792_REG1D_TREG_STAT BIT(2)
+#define BQ25792_REG1D_DPDM_STAT BIT(1)
+#define BQ25792_REG1D_VBAT_PRESENT_STAT BIT(0)
+
+/* Charger Status 3 */
+#define BQ25792_REG1E_ACRB2_STAT BIT(7)
+#define BQ25792_REG1E_ACRB1_STAT BIT(6)
+#define BQ25792_REG1E_ADC_DONE_STAT BIT(5)
+#define BQ25792_REG1E_VSYS_STAT BIT(4)
+#define BQ25792_REG1E_CHG_TMR_STAT BIT(3)
+#define BQ25792_REG1E_TRICHG_TMR_STAT BIT(2)
+#define BQ25792_REG1E_PRECHG_TMR_STAT BIT(1)
+
+/* Charger Status 4 */
+#define BQ25792_REG1F_VBATOTG_LOW_STAT BIT(4)
+#define BQ25792_REG1F_TS_COLD_STAT BIT(3)
+#define BQ25792_REG1F_TS_COOL_STAT BIT(2)
+#define BQ25792_REG1F_TS_WARM_STAT BIT(1)
+#define BQ25792_REG1F_TS_HOT_STAT BIT(0)
+
+/* FAULT Status 0 */
+#define BQ25792_REG20_IBAT_REG_STAT BIT(7)
+#define BQ25792_REG20_VBUS_OVP_STAT BIT(6)
+#define BQ25792_REG20_VBAT_OVP_STAT BIT(5)
+#define BQ25792_REG20_IBUS_OCP_STAT BIT(4)
+#define BQ25792_REG20_IBAT_OCP_STAT BIT(3)
+#define BQ25792_REG20_CONV_OCP_STAT BIT(2)
+#define BQ25792_REG20_VAC2_OVP_STAT BIT(1)
+#define BQ25792_REG20_VAC1_OVP_STAT BIT(0)
+
+#define BQ25792_REG20_OVERVOLTAGE_MASK (BQ25792_REG20_VBUS_OVP_STAT | \
+ BQ25792_REG20_VBAT_OVP_STAT | \
+ BQ25792_REG20_VAC2_OVP_STAT | \
+ BQ25792_REG20_VAC1_OVP_STAT)
+#define BQ25792_REG20_OVERCURRENT_MASK (BQ25792_REG20_IBUS_OCP_STAT | \
+ BQ25792_REG20_IBAT_OCP_STAT | \
+ BQ25792_REG20_CONV_OCP_STAT)
+
+/* FAULT Status 1 */
+#define BQ25792_REG21_VSYS_SHORT_STAT BIT(7)
+#define BQ25792_REG21_VSYS_OVP_STAT BIT(6)
+#define BQ25792_REG21_OTG_OVP_STAT BIT(5)
+#define BQ25792_REG21_OTG_UVP_STAT BIT(4)
+#define BQ25792_REG21_TSHUT_STAT BIT(2)
+
+
+/* Charger Flag 0 */
+#define BQ25792_REG22_IINDPM_FLAG BIT(7)
+#define BQ25792_REG22_VINDPM_FLAG BIT(6)
+#define BQ25792_REG22_WD_FLAG BIT(5)
+#define BQ25792_REG22_POORSRC_FLAG BIT(4)
+#define BQ25792_REG22_PG_FLAG BIT(3)
+#define BQ25792_REG22_AC2_PRESENT_FLAG BIT(2)
+#define BQ25792_REG22_AC1_PRESENT_FLAG BIT(1)
+#define BQ25792_REG22_VBUS_PRESENT_FLAG BIT(0)
+
+/* Charger Flag 1 */
+#define BQ25792_REG23_CHG_FLAG BIT(7)
+#define BQ25792_REG23_ICO_FLAG BIT(6)
+#define BQ25792_REG23_VBUS_FLAG BIT(4)
+#define BQ25792_REG23_TREG_FLAG BIT(2)
+#define BQ25792_REG23_VBAT_PRESENT_FLAG BIT(1)
+#define BQ25792_REG23_BC12_DONE_FLAG BIT(0)
+
+/* Charger Flag 2 */
+#define BQ25792_REG24_DPDM_DONE_FLAG BIT(6)
+#define BQ25792_REG24_ADC_DONE_FLAG BIT(5)
+#define BQ25792_REG24_VSYS_FLAG BIT(4)
+#define BQ25792_REG24_CHG_TMR_FLAG BIT(3)
+#define BQ25792_REG24_TRICHG_TMR_FLAG BIT(2)
+#define BQ25792_REG24_PRECHG_TMR_FLAG BIT(1)
+#define BQ25792_REG24_TOPOFF_TMR_FLAG BIT(0)
+
+/* Charger Flag 3 */
+#define BQ25792_REG25_VBATOTG_LOW_FLAG BIT(4)
+#define BQ25792_REG25_TS_COLD_FLAG BIT(3)
+#define BQ25792_REG25_TS_COOL_FLAG BIT(2)
+#define BQ25792_REG25_TS_WARM_FLAG BIT(1)
+#define BQ25792_REG25_TS_HOT_FLAG BIT(0)
+
+/* FAULT Flag 0 */
+#define BQ25792_REG26_IBAT_REG_FLAG BIT(7)
+#define BQ25792_REG26_VBUS_OVP_FLAG BIT(6)
+#define BQ25792_REG26_VBAT_OVP_FLAG BIT(5)
+#define BQ25792_REG26_IBUS_OCP_FLAG BIT(4)
+#define BQ25792_REG26_IBAT_OCP_FLAG BIT(3)
+#define BQ25792_REG26_CONV_OCP_FLAG BIT(2)
+#define BQ25792_REG26_VAC2_OVP_FLAG BIT(1)
+#define BQ25792_REG26_VAC1_OVP_FLAG BIT(0)
+
+/* FAULT Flag 1 */
+#define BQ25792_REG27_VSYS_SHORT_FLAG BIT(7)
+#define BQ25792_REG27_VSYS_OVP_FLAG BIT(6)
+#define BQ25792_REG27_OTG_OVP_FLAG BIT(5)
+#define BQ25792_REG27_OTG_UVP_FLAG BIT(4)
+#define BQ25792_REG27_TSHUT_FLAG BIT(2)
+
+/* Charger Mask 0 */
+#define BQ25792_REG28_IINDPM_MASK BIT(7)
+#define BQ25792_REG28_VINDPM_MASK BIT(6)
+#define BQ25792_REG28_WD_MASK BIT(5)
+#define BQ25792_REG28_POORSRC_MASK BIT(4)
+#define BQ25792_REG28_PG_MASK BIT(3)
+#define BQ25792_REG28_AC2_PRESENT_MASK BIT(2)
+#define BQ25792_REG28_AC1_PRESENT_MASK BIT(1)
+#define BQ25792_REG28_VBUS_PRESENT_MASK BIT(0)
+
+/* Charger Mask 1 */
+#define BQ25792_REG29_CHG_MASK BIT(7)
+#define BQ25792_REG29_ICO_MASK BIT(6)
+#define BQ25792_REG29_VBUS_MASK BIT(4)
+#define BQ25792_REG29_TREG_MASK BIT(2)
+#define BQ25792_REG29_VBAT_PRESENT_MASK BIT(1)
+#define BQ25792_REG29_BC12_DONE_MASK BIT(0)
+
+/* Charger Mask 2 */
+#define BQ25792_REG2A_DPDM_DONE_MASK BIT(6)
+#define BQ25792_REG2A_ADC_DONE_MASK BIT(5)
+#define BQ25792_REG2A_VSYS_MASK BIT(4)
+#define BQ25792_REG2A_CHG_TMR_MASK BIT(3)
+#define BQ25792_REG2A_TRICHG_TMR_MASK BIT(2)
+#define BQ25792_REG2A_PRECHG_TMR_MASK BIT(1)
+#define BQ25792_REG2A_TOPOFF_TMR_MASK BIT(0)
+
+/* Charger Mask 3 */
+#define BQ25792_REG2B_VBATOTG_LOW_MASK BIT(4)
+#define BQ25792_REG2B_TS_COLD_MASK BIT(3)
+#define BQ25792_REG2B_TS_COOL_MASK BIT(2)
+#define BQ25792_REG2B_TS_WARM_MASK BIT(1)
+#define BQ25792_REG2B_TS_HOT_MASK BIT(0)
+
+/* FAULT Mask 0 */
+#define BQ25792_REG2C_IBAT_REG_MASK BIT(7)
+#define BQ25792_REG2C_VBUS_OVP_MASK BIT(6)
+#define BQ25792_REG2C_VBAT_OVP_MASK BIT(5)
+#define BQ25792_REG2C_IBUS_OCP_MASK BIT(4)
+#define BQ25792_REG2C_IBAT_OCP_MASK BIT(3)
+#define BQ25792_REG2C_CONV_OCP_MASK BIT(2)
+#define BQ25792_REG2C_VAC2_OVP_MASK BIT(1)
+#define BQ25792_REG2C_VAC1_OVP_MASK BIT(0)
+
+/* FAULT Mask 1 */
+#define BQ25792_REG2D_VSYS_SHORT_MASK BIT(7)
+#define BQ25792_REG2D_VSYS_OVP_MASK BIT(6)
+#define BQ25792_REG2D_OTG_OVP_MASK BIT(5)
+#define BQ25792_REG2D_OTG_UVP_MASK BIT(4)
+#define BQ25792_REG2D_TSHUT_MASK BIT(2)
+
+/* ADC Control */
+#define BQ25792_REG2E_ADC_EN BIT(7)
+#define BQ25792_REG2E_ADC_RATE BIT(6)
+#define BQ25792_REG2E_ADC_SAMPLE_MASK GENMASK(5, 4)
+#define BQ25792_REG2E_ADC_AVG BIT(3)
+#define BQ25792_REG2E_ADC_AVG_INIT BIT(2)
+
+/* ADC Function Disable 0 */
+#define BQ25792_REG2F_IBUS_ADC_DIS BIT(7)
+#define BQ25792_REG2F_IBAT_ADC_DIS BIT(6)
+#define BQ25792_REG2F_VBUS_ADC_DIS BIT(5)
+#define BQ25792_REG2F_VBAT_ADC_DIS BIT(4)
+#define BQ25792_REG2F_VSYS_ADC_DIS BIT(3)
+#define BQ25792_REG2F_TS_ADC_DIS BIT(2)
+#define BQ25792_REG2F_TDIE_ADC_DIS BIT(1)
+
+/* ADC Function Disable 1 */
+#define BQ25792_REG30_DP_ADC_DIS BIT(7)
+#define BQ25792_REG30_DM_ADC_DIS BIT(6)
+#define BQ25792_REG30_VAC2_ADC_DIS BIT(5)
+#define BQ25792_REG30_VAC1_ADC_DIS BIT(4)
+
+/* 0x31-0x45: ADC result registers (16-bit, RO): single full-width field */
+
+#define BQ25792_ADCVSYSVBAT_STEP_UV 1000
+#define BQ25792_ADCIBAT_STEP_UA 1000
+
+/* DPDM Driver */
+#define BQ25792_REG47_DPLUS_DAC_MASK GENMASK(7, 5)
+#define BQ25792_REG47_DMINUS_DAC_MASK GENMASK(4, 2)
+
+/* Part Information */
+#define BQ25792_REG48_PN_MASK GENMASK(5, 3)
+#define BQ25792_REG48_DEV_REV_MASK GENMASK(2, 0)
+
struct bq257xx_device {
struct i2c_client *client;
struct regmap *regmap;
};
+
+enum bq257xx_type {
+ BQ25703A,
+ BQ25792,
+};
+
+struct bq257xx_plat {
+ enum bq257xx_type type;
+};
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 10/11] regulator: bq257xx: Add support for BQ25792
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (8 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 11/11] power: supply: " Alexey Charkov
10 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Add support for TI BQ25792, an integrated battery charger and buck/boost
regulator. This enables VBUS output from the charger's boost converter
for use in USB OTG applications, supporting 2.8-22V output at up to 3.32A
with 10mV and 40mA resolution.
Acked-by: Mark Brown <broonie@kernel.org>
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/regulator/bq257xx-regulator.c | 98 ++++++++++++++++++++++++++++++++++-
1 file changed, 97 insertions(+), 1 deletion(-)
diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c
index 0bb58ab4b8d4..61911ac8613a 100644
--- a/drivers/regulator/bq257xx-regulator.c
+++ b/drivers/regulator/bq257xx-regulator.c
@@ -31,6 +31,32 @@ static int bq25703_vbus_get_cur_limit(struct regulator_dev *rdev)
return FIELD_GET(BQ25703_OTG_CUR_MASK, reg) * BQ25703_OTG_CUR_STEP_UA;
}
+static int bq25792_vbus_get_cur_limit(struct regulator_dev *rdev)
+{
+ struct regmap *regmap = rdev_get_regmap(rdev);
+ int ret;
+ unsigned int reg;
+
+ ret = regmap_read(regmap, BQ25792_REG0D_IOTG_REGULATION, ®);
+ if (ret)
+ return ret;
+ return FIELD_GET(BQ25792_REG0D_IOTG_MASK, reg) * BQ25792_OTG_CUR_STEP_UA;
+}
+
+static int bq25792_vbus_get_voltage_sel(struct regulator_dev *rdev)
+{
+ struct regmap *regmap = rdev_get_regmap(rdev);
+ __be16 reg;
+ int ret;
+
+ ret = regmap_raw_read(regmap, BQ25792_REG0B_VOTG_REGULATION,
+ ®, sizeof(reg));
+ if (ret)
+ return ret;
+
+ return FIELD_GET(BQ25792_REG0B_VOTG_MASK, be16_to_cpu(reg));
+}
+
/*
* Check if the minimum current and maximum current requested are
* sane values, then set the register accordingly.
@@ -54,6 +80,37 @@ static int bq25703_vbus_set_cur_limit(struct regulator_dev *rdev,
FIELD_PREP(BQ25703_OTG_CUR_MASK, reg));
}
+static int bq25792_vbus_set_cur_limit(struct regulator_dev *rdev,
+ int min_uA, int max_uA)
+{
+ struct regmap *regmap = rdev_get_regmap(rdev);
+ unsigned int reg;
+
+ if ((min_uA > BQ25792_OTG_CUR_MAX_UA) ||
+ (max_uA < BQ25792_OTG_CUR_MIN_UA))
+ return -EINVAL;
+
+ reg = (max_uA / BQ25792_OTG_CUR_STEP_UA);
+
+ /* Catch rounding errors since our step is 40000uA. */
+ if ((reg * BQ25792_OTG_CUR_STEP_UA) < min_uA)
+ return -EINVAL;
+
+ return regmap_write(regmap, BQ25792_REG0D_IOTG_REGULATION,
+ FIELD_PREP(BQ25792_REG0D_IOTG_MASK, reg));
+}
+
+static int bq25792_vbus_set_voltage_sel(struct regulator_dev *rdev,
+ unsigned int sel)
+{
+ struct regmap *regmap = rdev_get_regmap(rdev);
+ __be16 reg;
+
+ reg = cpu_to_be16(FIELD_PREP(BQ25792_REG0B_VOTG_MASK, sel));
+ return regmap_raw_write(regmap, BQ25792_REG0B_VOTG_REGULATION,
+ ®, sizeof(reg));
+}
+
static int bq25703_vbus_enable(struct regulator_dev *rdev)
{
struct bq257xx_reg_data *pdata = rdev_get_drvdata(rdev);
@@ -101,6 +158,34 @@ static const struct regulator_desc bq25703_vbus_desc = {
.vsel_mask = BQ25703_OTG_VOLT_MASK,
};
+static const struct regulator_ops bq25792_vbus_ops = {
+ /* No GPIO for enabling the OTG regulator */
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .is_enabled = regulator_is_enabled_regmap,
+ .list_voltage = regulator_list_voltage_linear,
+ .get_voltage_sel = bq25792_vbus_get_voltage_sel,
+ .set_voltage_sel = bq25792_vbus_set_voltage_sel,
+ .get_current_limit = bq25792_vbus_get_cur_limit,
+ .set_current_limit = bq25792_vbus_set_cur_limit,
+};
+
+static const struct regulator_desc bq25792_vbus_desc = {
+ .name = "vbus",
+ .of_match = of_match_ptr("vbus"),
+ .regulators_node = of_match_ptr("regulators"),
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .ops = &bq25792_vbus_ops,
+ .min_uV = BQ25792_OTG_VOLT_MIN_UV,
+ .uV_step = BQ25792_OTG_VOLT_STEP_UV,
+ .n_voltages = BQ25792_OTG_VOLT_NUM_VOLT,
+ .enable_mask = BQ25792_REG12_EN_OTG,
+ .enable_reg = BQ25792_REG12_CHARGER_CONTROL_3,
+ .enable_val = BQ25792_REG12_EN_OTG,
+ .disable_val = 0,
+};
+
/* Get optional GPIO for OTG regulator enable. */
static void bq257xx_reg_dt_parse_gpio(struct platform_device *pdev)
{
@@ -141,6 +226,7 @@ static void bq257xx_reg_dt_parse_gpio(struct platform_device *pdev)
static int bq257xx_regulator_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ struct bq257xx_plat *plat = dev_get_platdata(dev);
struct bq257xx_reg_data *pdata;
struct device_node *np = dev->of_node;
struct regulator_config cfg = {};
@@ -153,7 +239,17 @@ static int bq257xx_regulator_probe(struct platform_device *pdev)
if (!pdata)
return -ENOMEM;
- pdata->desc = bq25703_vbus_desc;
+ switch (plat->type) {
+ case BQ25703A:
+ pdata->desc = bq25703_vbus_desc;
+ break;
+ case BQ25792:
+ pdata->desc = bq25792_vbus_desc;
+ break;
+ default:
+ return dev_err_probe(&pdev->dev, -EINVAL,
+ "Unsupported device type\n");
+ }
platform_set_drvdata(pdev, pdata);
bq257xx_reg_dt_parse_gpio(pdev);
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v3 11/11] power: supply: bq257xx: Add support for BQ25792
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
` (9 preceding siblings ...)
2026-03-10 9:28 ` [PATCH v3 10/11] regulator: bq257xx: Add support for BQ25792 Alexey Charkov
@ 2026-03-10 9:28 ` Alexey Charkov
2026-03-11 8:52 ` Sebastian Reichel
10 siblings, 1 reply; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 9:28 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, Sebastian Reichel
Cc: devicetree, linux-kernel, Sebastian Reichel, linux-pm,
Alexey Charkov
Add support for TI BQ25792 integrated battery charger and buck-boost
converter.
It shares high-level logic of operation with the already supported
BQ25703A, but has a different register map, bit definitions and some of
the lower-level hardware states.
Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
drivers/power/supply/bq257xx_charger.c | 492 ++++++++++++++++++++++++++++++++-
include/linux/mfd/bq257xx.h | 6 +-
2 files changed, 493 insertions(+), 5 deletions(-)
diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
index 951abd035fc5..0bbb0a8b5f55 100644
--- a/drivers/power/supply/bq257xx_charger.c
+++ b/drivers/power/supply/bq257xx_charger.c
@@ -5,6 +5,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/byteorder/generic.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/mfd/bq257xx.h>
@@ -18,12 +19,19 @@ struct bq257xx_chg;
/**
* struct bq257xx_chip_info - chip specific routines
+ * @default_iindpm_uA: default input current limit in microamps
* @bq257xx_hw_init: init function for hw
* @bq257xx_hw_shutdown: shutdown function for hw
* @bq257xx_get_state: get and update state of hardware
+ * @bq257xx_get_ichg: get maximum charge current (in uA)
* @bq257xx_set_ichg: set maximum charge current (in uA)
+ * @bq257xx_get_vbatreg: get maximum charge voltage (in uV)
* @bq257xx_set_vbatreg: set maximum charge voltage (in uV)
+ * @bq257xx_get_iindpm: get maximum input current (in uA)
* @bq257xx_set_iindpm: set maximum input current (in uA)
+ * @bq257xx_get_cur: get battery current from ADC (in uA)
+ * @bq257xx_get_vbat: get battery voltage from ADC (in uV)
+ * @bq257xx_get_min_vsys: get minimum system voltage (in uV)
*/
struct bq257xx_chip_info {
int default_iindpm_uA;
@@ -47,8 +55,10 @@ struct bq257xx_chip_info {
* @bq: parent MFD device
* @charger: power supply device
* @online: charger input is present
+ * @charging: charger is actively charging the battery
* @fast_charge: charger is in fast charge mode
* @pre_charge: charger is in pre-charge mode
+ * @overvoltage: overvoltage fault detected
* @ov_fault: charger reports over voltage fault
* @batoc_fault: charger reports battery over current fault
* @oc_fault: charger reports over current fault
@@ -79,6 +89,53 @@ struct bq257xx_chg {
u32 vsys_min;
};
+/**
+ * bq25792_read16() - Read a 16-bit value from device register
+ * @pdata: driver platform data
+ * @reg: register address to read from
+ * @val: pointer to store the register value
+ *
+ * Read a 16-bit big-endian value from the BQ25792 device via regmap
+ * and convert to CPU byte order.
+ *
+ * Return: Returns 0 on success or error on failure to read.
+ */
+static int bq25792_read16(struct bq257xx_chg *pdata, unsigned int reg, u16 *val)
+{
+ __be16 regval;
+ int ret;
+
+ ret = regmap_raw_read(pdata->bq->regmap, reg, ®val, sizeof(regval));
+ if (ret)
+ return ret;
+
+ *val = be16_to_cpu(regval);
+ return 0;
+}
+
+/**
+ * bq25792_write16() - Write a 16-bit value to device register
+ * @pdata: driver platform data
+ * @reg: register address to write to
+ * @val: 16-bit value to write in CPU byte order
+ *
+ * Convert the value to big-endian and write a 16-bit value to the
+ * BQ25792 device via regmap.
+ *
+ * Return: Returns 0 on success or error on failure to write.
+ */
+static int bq25792_write16(struct bq257xx_chg *pdata, unsigned int reg, u16 val)
+{
+ __be16 regval = cpu_to_be16(val);
+ int ret;
+
+ ret = regmap_raw_write(pdata->bq->regmap, reg, ®val, sizeof(regval));
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
/**
* bq25703_get_state() - Get the current state of the device
* @pdata: driver platform data
@@ -110,6 +167,43 @@ static int bq25703_get_state(struct bq257xx_chg *pdata)
return 0;
}
+/**
+ * bq25792_get_state() - Get the current state of the device
+ * @pdata: driver platform data
+ *
+ * Get the current state of the BQ25792 charger by reading status
+ * registers. Updates the online, charging, overvoltage, and fault
+ * status fields in the driver data structure.
+ *
+ * Return: Returns 0 on success or error on failure to read device.
+ */
+static int bq25792_get_state(struct bq257xx_chg *pdata)
+{
+ unsigned int reg;
+ int ret;
+
+ ret = regmap_read(pdata->bq->regmap, BQ25792_REG1B_CHARGER_STATUS_0, ®);
+ if (ret)
+ return ret;
+
+ pdata->online = reg & BQ25792_REG1B_PG_STAT;
+
+ ret = regmap_read(pdata->bq->regmap, BQ25792_REG1C_CHARGER_STATUS_1, ®);
+ if (ret)
+ return ret;
+
+ pdata->charging = reg & BQ25792_REG1C_CHG_STAT_MASK;
+
+ ret = regmap_read(pdata->bq->regmap, BQ25792_REG20_FAULT_STATUS_0, ®);
+ if (ret)
+ return ret;
+
+ pdata->overvoltage = reg & BQ25792_REG20_OVERVOLTAGE_MASK;
+ pdata->oc_fault = reg & BQ25792_REG20_OVERCURRENT_MASK;
+
+ return 0;
+}
+
/**
* bq25703_get_min_vsys() - Get the minimum system voltage
* @pdata: driver platform data
@@ -133,6 +227,31 @@ static int bq25703_get_min_vsys(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_min_vsys() - Get the minimum system voltage
+ * @pdata: driver platform data
+ * @intval: pointer to store the minimum voltage value
+ *
+ * Read the current minimum system voltage setting from the device
+ * and return it in microvolts.
+ *
+ * Return: Returns 0 on success or error on failure to read.
+ */
+static int bq25792_get_min_vsys(struct bq257xx_chg *pdata, int *intval)
+{
+ unsigned int reg;
+ int ret;
+
+ ret = regmap_read(pdata->bq->regmap, BQ25792_REG00_MIN_SYS_VOLTAGE, ®);
+ if (ret)
+ return ret;
+
+ reg = FIELD_GET(BQ25792_REG00_VSYSMIN_MASK, reg);
+ *intval = (reg * BQ25792_MINVSYS_STEP_UV) + BQ25792_MINVSYS_MIN_UV;
+
+ return ret;
+}
+
/**
* bq25703_set_min_vsys() - Set the minimum system voltage
* @pdata: driver platform data
@@ -157,6 +276,29 @@ static int bq25703_set_min_vsys(struct bq257xx_chg *pdata, int vsys)
reg);
}
+/**
+ * bq25792_set_min_vsys() - Set the minimum system voltage
+ * @pdata: driver platform data
+ * @vsys: voltage value to set in uV
+ *
+ * Set the minimum system voltage by clamping the requested value
+ * between device limits and writing to the appropriate register.
+ *
+ * Return: Returns 0 on success or error on failure to write.
+ */
+static int bq25792_set_min_vsys(struct bq257xx_chg *pdata, int vsys)
+{
+ unsigned int reg;
+ int vsys_min = pdata->vsys_min;
+
+ vsys = clamp(vsys, vsys_min, BQ25792_MINVSYS_MAX_UV);
+ reg = ((vsys - BQ25792_MINVSYS_MIN_UV) / BQ25792_MINVSYS_STEP_UV);
+ reg = FIELD_PREP(BQ25792_REG00_VSYSMIN_MASK, reg);
+
+ return regmap_write(pdata->bq->regmap,
+ BQ25792_REG00_MIN_SYS_VOLTAGE, reg);
+}
+
/**
* bq25703_get_cur() - Get the reported current from the battery
* @pdata: driver platform data
@@ -186,6 +328,30 @@ static int bq25703_get_cur(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_cur() - Get the reported current from the battery
+ * @pdata: driver platform data
+ * @intval: pointer to store the battery current value
+ *
+ * Read the current ADC value from the device representing the battery
+ * charge or discharge current and return it in microamps.
+ *
+ * Return: Returns 0 on success or error on failure to read.
+ */
+static int bq25792_get_cur(struct bq257xx_chg *pdata, int *intval)
+{
+ u16 reg;
+ int ret;
+
+ ret = bq25792_read16(pdata, BQ25792_REG33_IBAT_ADC, ®);
+ if (ret < 0)
+ return ret;
+
+ *intval = (s16)reg * BQ25792_ADCIBAT_STEP_UA;
+
+ return ret;
+}
+
/**
* bq25703_get_ichg_cur() - Get the maximum reported charge current
* @pdata: driver platform data
@@ -209,6 +375,30 @@ static int bq25703_get_ichg_cur(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_ichg_cur() - Get the maximum reported charge current
+ * @pdata: driver platform data
+ * @intval: pointer to store the maximum charge current value
+ *
+ * Read the programmed maximum charge current limit from the device.
+ *
+ * Return: Returns 0 on success or error on failure to read value.
+ */
+static int bq25792_get_ichg_cur(struct bq257xx_chg *pdata, int *intval)
+{
+ u16 reg;
+ int ret;
+
+ ret = bq25792_read16(pdata, BQ25792_REG03_CHARGE_CURRENT_LIMIT, ®);
+ if (ret)
+ return ret;
+
+ *intval = FIELD_GET(BQ25792_REG03_ICHG_MASK, reg) *
+ BQ25792_ICHG_STEP_UA;
+
+ return ret;
+}
+
/**
* bq25703_set_ichg_cur() - Set the maximum charge current
* @pdata: driver platform data
@@ -233,6 +423,28 @@ static int bq25703_set_ichg_cur(struct bq257xx_chg *pdata, int ichg)
reg);
}
+/**
+ * bq25792_set_ichg_cur() - Set the maximum charge current
+ * @pdata: driver platform data
+ * @ichg: current value to set in uA
+ *
+ * Set the maximum charge current by clamping the requested value
+ * between device limits and writing to the appropriate register.
+ *
+ * Return: Returns 0 on success or error on failure to write.
+ */
+static int bq25792_set_ichg_cur(struct bq257xx_chg *pdata, int ichg)
+{
+ int ichg_max = pdata->ichg_max;
+ u16 reg;
+
+ ichg = clamp(ichg, BQ25792_ICHG_MIN_UA, ichg_max);
+ reg = FIELD_PREP(BQ25792_REG03_ICHG_MASK,
+ (ichg / BQ25792_ICHG_STEP_UA));
+
+ return bq25792_write16(pdata, BQ25792_REG03_CHARGE_CURRENT_LIMIT, reg);
+}
+
/**
* bq25703_get_chrg_volt() - Get the maximum set charge voltage
* @pdata: driver platform data
@@ -256,6 +468,30 @@ static int bq25703_get_chrg_volt(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_chrg_volt() - Get the maximum set charge voltage
+ * @pdata: driver platform data
+ * @intval: pointer to store the maximum charge voltage value
+ *
+ * Read the current charge voltage limit from the device.
+ *
+ * Return: Returns 0 on success or error on failure to read value.
+ */
+static int bq25792_get_chrg_volt(struct bq257xx_chg *pdata, int *intval)
+{
+ u16 reg;
+ int ret;
+
+ ret = bq25792_read16(pdata, BQ25792_REG01_CHARGE_VOLTAGE_LIMIT, ®);
+ if (ret)
+ return ret;
+
+ *intval = FIELD_GET(BQ25792_REG01_VREG_MASK, reg) *
+ BQ25792_VBATREG_STEP_UV;
+
+ return ret;
+}
+
/**
* bq25703_set_chrg_volt() - Set the maximum charge voltage
* @pdata: driver platform data
@@ -282,6 +518,29 @@ static int bq25703_set_chrg_volt(struct bq257xx_chg *pdata, int vbat)
reg);
}
+/**
+ * bq25792_set_chrg_volt() - Set the maximum charge voltage
+ * @pdata: driver platform data
+ * @vbat: voltage value to set in uV
+ *
+ * Set the maximum charge voltage by clamping the requested value
+ * between device limits and writing to the appropriate register.
+ *
+ * Return: Returns 0 on success or error on failure to write.
+ */
+static int bq25792_set_chrg_volt(struct bq257xx_chg *pdata, int vbat)
+{
+ int vbat_max = pdata->vbat_max;
+ u16 reg;
+
+ vbat = clamp(vbat, BQ25792_VBATREG_MIN_UV, vbat_max);
+
+ reg = FIELD_PREP(BQ25792_REG01_VREG_MASK,
+ (vbat / BQ25792_VBATREG_STEP_UV));
+
+ return bq25792_write16(pdata, BQ25792_REG01_CHARGE_VOLTAGE_LIMIT, reg);
+}
+
/**
* bq25703_get_iindpm() - Get the maximum set input current
* @pdata: driver platform data
@@ -310,6 +569,30 @@ static int bq25703_get_iindpm(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_iindpm() - Get the maximum set input current
+ * @pdata: driver platform data
+ * @intval: pointer to store the maximum input current value
+ *
+ * Read the current input current limit from the device.
+ *
+ * Return: Returns 0 on success or error on failure to read value.
+ */
+static int bq25792_get_iindpm(struct bq257xx_chg *pdata, int *intval)
+{
+ u16 reg;
+ int ret;
+
+ ret = bq25792_read16(pdata, BQ25792_REG06_INPUT_CURRENT_LIMIT, ®);
+ if (ret)
+ return ret;
+
+ reg = FIELD_GET(BQ25792_REG06_IINDPM_MASK, reg);
+ *intval = reg * BQ25792_IINDPM_STEP_UA;
+
+ return ret;
+}
+
/**
* bq25703_set_iindpm() - Set the maximum input current
* @pdata: driver platform data
@@ -335,6 +618,29 @@ static int bq25703_set_iindpm(struct bq257xx_chg *pdata, int iindpm)
FIELD_PREP(BQ25703_IINDPM_MASK, reg));
}
+/**
+ * bq25792_set_iindpm() - Set the maximum input current
+ * @pdata: driver platform data
+ * @iindpm: current value in uA
+ *
+ * Set the maximum input current by clamping the requested value
+ * between device limits and writing to the appropriate register.
+ *
+ * Return: Returns 0 on success or error on failure to write.
+ */
+static int bq25792_set_iindpm(struct bq257xx_chg *pdata, int iindpm)
+{
+ u16 reg;
+ int iindpm_max = pdata->iindpm_max;
+
+ iindpm = clamp(iindpm, BQ25792_IINDPM_MIN_UA, iindpm_max);
+
+ reg = iindpm / BQ25792_IINDPM_STEP_UA;
+
+ return bq25792_write16(pdata, BQ25792_REG06_INPUT_CURRENT_LIMIT,
+ FIELD_PREP(BQ25792_REG06_IINDPM_MASK, reg));
+}
+
/**
* bq25703_get_vbat() - Get the reported voltage from the battery
* @pdata: driver platform data
@@ -359,6 +665,30 @@ static int bq25703_get_vbat(struct bq257xx_chg *pdata, int *intval)
return ret;
}
+/**
+ * bq25792_get_vbat() - Get the reported voltage from the battery
+ * @pdata: driver platform data
+ * @intval: pointer to store the battery voltage value
+ *
+ * Read the current ADC value representing the battery voltage
+ * and return it in microvolts.
+ *
+ * Return: Returns 0 on success or error on failure to read value.
+ */
+static int bq25792_get_vbat(struct bq257xx_chg *pdata, int *intval)
+{
+ u16 reg;
+ int ret;
+
+ ret = bq25792_read16(pdata, BQ25792_REG3B_VBAT_ADC, ®);
+ if (ret)
+ return ret;
+
+ *intval = reg * BQ25792_ADCVSYSVBAT_STEP_UV;
+
+ return ret;
+}
+
/**
* bq25703_hw_init() - Set all the required registers to init the charger
* @pdata: driver platform data
@@ -425,6 +755,62 @@ static int bq25703_hw_init(struct bq257xx_chg *pdata)
return ret;
}
+/**
+ * bq25792_hw_init() - Initialize BQ25792 hardware
+ * @pdata: driver platform data
+ *
+ * Initialize the BQ25792 by disabling the watchdog, enabling discharge
+ * current sensing with 5A limit, and configuring input current regulation.
+ * Set the charge current, charge voltage, minimum system voltage, and
+ * input current limit from platform data. Enable and configure the ADC
+ * to measure all available channels.
+ *
+ * Return: Returns 0 on success or error code on error.
+ */
+static int bq25792_hw_init(struct bq257xx_chg *pdata)
+{
+ struct regmap *regmap = pdata->bq->regmap;
+ int ret = 0;
+
+ /* Disable watchdog (TODO: make it work instead) */
+ regmap_write(regmap, BQ25792_REG10_CHARGER_CONTROL_1, 0);
+
+ /*
+ * Enable battery discharge current sensing, 5A discharge current
+ * limit, input current regulation and ship FET functions
+ */
+ regmap_write(regmap, BQ25792_REG14_CHARGER_CONTROL_5,
+ BQ25792_REG14_SFET_PRESENT |
+ BQ25792_REG14_EN_IBAT |
+ BQ25792_IBAT_5A |
+ BQ25792_REG14_EN_IINDPM);
+
+ ret = pdata->chip->bq257xx_set_ichg(pdata, pdata->ichg_max);
+ if (ret)
+ return ret;
+
+ ret = pdata->chip->bq257xx_set_vbatreg(pdata, pdata->vbat_max);
+ if (ret)
+ return ret;
+
+ ret = bq25792_set_min_vsys(pdata, pdata->vsys_min);
+ if (ret)
+ return ret;
+
+ ret = pdata->chip->bq257xx_set_iindpm(pdata, pdata->iindpm_max);
+ if (ret)
+ return ret;
+
+ /* Enable the ADC. */
+ regmap_write(regmap, BQ25792_REG2E_ADC_CONTROL, BQ25792_REG2E_ADC_EN);
+
+ /* Clear per-channel ADC disable bits - enable all channels */
+ regmap_write(regmap, BQ25792_REG2F_ADC_FUNCTION_DISABLE_0, 0);
+ regmap_write(regmap, BQ25792_REG30_ADC_FUNCTION_DISABLE_1, 0);
+
+ return ret;
+}
+
/**
* bq25703_hw_shutdown() - Set registers for shutdown
* @pdata: driver platform data
@@ -437,6 +823,30 @@ static void bq25703_hw_shutdown(struct bq257xx_chg *pdata)
BQ25703_EN_LWPWR, BQ25703_EN_LWPWR);
}
+/**
+ * bq25792_hw_shutdown() - Shutdown BQ25792 hardware
+ * @pdata: driver platform data
+ *
+ * Perform hardware shutdown for the BQ25792. Currently a no-op
+ * as the device does not require special shutdown configuration.
+ */
+static void bq25792_hw_shutdown(struct bq257xx_chg *pdata)
+{
+ /* Nothing to do here */
+}
+
+/**
+ * bq257xx_set_charger_property() - Set a power supply property
+ * @psy: power supply device
+ * @prop: power supply property to set
+ * @val: value to set for the property
+ *
+ * Handle requests to set power supply properties such as input current
+ * limit, constant charge voltage, and constant charge current. Routes
+ * the request to the chip-specific implementation.
+ *
+ * Return: Returns 0 on success or -EINVAL if property is not supported.
+ */
static int bq257xx_set_charger_property(struct power_supply *psy,
enum power_supply_property prop,
const union power_supply_propval *val)
@@ -460,6 +870,19 @@ static int bq257xx_set_charger_property(struct power_supply *psy,
return -EINVAL;
}
+/**
+ * bq257xx_get_charger_property() - Get a power supply property
+ * @psy: power supply device
+ * @psp: power supply property to get
+ * @val: pointer to store the property value
+ *
+ * Handle requests to get power supply properties, including status,
+ * health, manufacturer, online state, and various voltage/current
+ * measurements. Reads current device state and routes chip-specific
+ * property requests to appropriate handlers.
+ *
+ * Return: Returns 0 on success or -EINVAL if property is not supported.
+ */
static int bq257xx_get_charger_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -541,6 +964,17 @@ static enum power_supply_property bq257xx_power_supply_props[] = {
POWER_SUPPLY_PROP_USB_TYPE,
};
+/**
+ * bq257xx_property_is_writeable() - Check if a property is writeable
+ * @psy: power supply device
+ * @prop: power supply property to check
+ *
+ * Determines which power supply properties can be written to. Only
+ * charge current limit, charge voltage limit, and input current
+ * limit are writeable.
+ *
+ * Return: Returns 1 if property is writeable, 0 otherwise.
+ */
static int bq257xx_property_is_writeable(struct power_supply *psy,
enum power_supply_property prop)
{
@@ -613,6 +1047,17 @@ static void bq257xx_external_power_changed(struct power_supply *psy)
power_supply_changed(psy);
}
+/**
+ * bq257xx_irq_handler_thread() - Handle charger interrupt
+ * @irq: interrupt number
+ * @private: pointer to driver private data
+ *
+ * Thread handler for charger interrupts. Triggers re-evaluation of
+ * external power status and updates power supply state in response
+ * to charger events.
+ *
+ * Return: Returns IRQ_HANDLED if interrupt was processed.
+ */
static irqreturn_t bq257xx_irq_handler_thread(int irq, void *private)
{
struct bq257xx_chg *pdata = private;
@@ -653,6 +1098,22 @@ static const struct bq257xx_chip_info bq25703_chip_info = {
.bq257xx_get_min_vsys = &bq25703_get_min_vsys,
};
+static const struct bq257xx_chip_info bq25792_chip_info = {
+ .default_iindpm_uA = BQ25792_IINDPM_DEFAULT_UA,
+ .bq257xx_hw_init = &bq25792_hw_init,
+ .bq257xx_hw_shutdown = &bq25792_hw_shutdown,
+ .bq257xx_get_state = &bq25792_get_state,
+ .bq257xx_get_ichg = &bq25792_get_ichg_cur,
+ .bq257xx_set_ichg = &bq25792_set_ichg_cur,
+ .bq257xx_get_vbatreg = &bq25792_get_chrg_volt,
+ .bq257xx_set_vbatreg = &bq25792_set_chrg_volt,
+ .bq257xx_get_iindpm = &bq25792_get_iindpm,
+ .bq257xx_set_iindpm = &bq25792_set_iindpm,
+ .bq257xx_get_cur = &bq25792_get_cur,
+ .bq257xx_get_vbat = &bq25792_get_vbat,
+ .bq257xx_get_min_vsys = &bq25792_get_min_vsys,
+};
+
/**
* bq257xx_parse_dt() - Parse the device tree for required properties
* @pdata: driver platform data
@@ -698,10 +1159,22 @@ static int bq257xx_parse_dt(struct bq257xx_chg *pdata,
return 0;
}
+/**
+ * bq257xx_charger_probe() - Probe routine for charger platform device
+ * @pdev: platform device
+ *
+ * Probe the charger device, allocate driver data structure, select the
+ * appropriate chip-specific function pointers, register the power supply,
+ * parse device tree properties for battery limits, initialize hardware,
+ * and set up the interrupt handler if available.
+ *
+ * Return: Returns 0 on success or error code on failure.
+ */
static int bq257xx_charger_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct bq257xx_device *bq = dev_get_drvdata(pdev->dev.parent);
+ struct bq257xx_plat *plat = dev_get_platdata(dev);
struct bq257xx_chg *pdata;
struct power_supply_config psy_cfg = { };
int ret;
@@ -713,7 +1186,17 @@ static int bq257xx_charger_probe(struct platform_device *pdev)
return -ENOMEM;
pdata->bq = bq;
- pdata->chip = &bq25703_chip_info;
+
+ switch (plat->type) {
+ case BQ25703A:
+ pdata->chip = &bq25703_chip_info;
+ break;
+ case BQ25792:
+ pdata->chip = &bq25792_chip_info;
+ break;
+ default:
+ return dev_err_probe(dev, -EINVAL, "Unknown chip type\n");
+ }
platform_set_drvdata(pdev, pdata);
@@ -751,6 +1234,13 @@ static int bq257xx_charger_probe(struct platform_device *pdev)
return ret;
}
+/**
+ * bq257xx_charger_shutdown() - Shutdown routine for charger platform device
+ * @pdev: platform device
+ *
+ * Called during system shutdown to perform charger cleanup, including
+ * disabling watchdog timers or other chip-specific shutdown procedures.
+ */
static void bq257xx_charger_shutdown(struct platform_device *pdev)
{
struct bq257xx_chg *pdata = platform_get_drvdata(pdev);
diff --git a/include/linux/mfd/bq257xx.h b/include/linux/mfd/bq257xx.h
index b2e38a4a4738..0d568e8b1835 100644
--- a/include/linux/mfd/bq257xx.h
+++ b/include/linux/mfd/bq257xx.h
@@ -353,12 +353,10 @@
#define BQ25792_REG20_VAC2_OVP_STAT BIT(1)
#define BQ25792_REG20_VAC1_OVP_STAT BIT(0)
-#define BQ25792_REG20_OVERVOLTAGE_MASK (BQ25792_REG20_VBUS_OVP_STAT | \
- BQ25792_REG20_VBAT_OVP_STAT | \
+#define BQ25792_REG20_OVERVOLTAGE_MASK (BQ25792_REG20_VBAT_OVP_STAT | \
BQ25792_REG20_VAC2_OVP_STAT | \
BQ25792_REG20_VAC1_OVP_STAT)
-#define BQ25792_REG20_OVERCURRENT_MASK (BQ25792_REG20_IBUS_OCP_STAT | \
- BQ25792_REG20_IBAT_OCP_STAT | \
+#define BQ25792_REG20_OVERCURRENT_MASK (BQ25792_REG20_IBAT_OCP_STAT | \
BQ25792_REG20_CONV_OCP_STAT)
/* FAULT Status 1 */
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support
2026-03-10 9:28 ` [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support Alexey Charkov
@ 2026-03-10 13:03 ` Lee Jones
2026-03-10 13:49 ` Alexey Charkov
0 siblings, 1 reply; 20+ messages in thread
From: Lee Jones @ 2026-03-10 13:03 UTC (permalink / raw)
To: Alexey Charkov
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chris Morgan,
Liam Girdwood, Mark Brown, Sebastian Reichel, devicetree,
linux-kernel, Sebastian Reichel, linux-pm
On Tue, 10 Mar 2026, Alexey Charkov wrote:
> Add register definitions and a new 'type' enum to be passed in MFD
> platform data to support the BQ25792, which is a newer variant of the
> BQ257xx family.
>
> BQ25792 shares similar logic of operation with the already supported
> BQ25703A but has a completely different register map and different
> electrical constraints.
>
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
> drivers/mfd/bq257xx.c | 64 ++++++-
> include/linux/mfd/bq257xx.h | 417 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 477 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mfd/bq257xx.c b/drivers/mfd/bq257xx.c
> index e9d49dac0a16..7516e2ec00e6 100644
> --- a/drivers/mfd/bq257xx.c
> +++ b/drivers/mfd/bq257xx.c
> @@ -10,6 +10,11 @@
> #include <linux/mfd/core.h>
> #include <linux/regmap.h>
>
> +struct bq257xx_match_data {
> + const struct bq257xx_plat plat;
> + const struct regmap_config *regmap_config;
> +};
> +
> static const struct regmap_range bq25703_readonly_reg_ranges[] = {
> regmap_reg_range(BQ25703_CHARGER_STATUS, BQ25703_MANUFACT_DEV_ID),
> };
> @@ -39,15 +44,64 @@ static const struct regmap_config bq25703_regmap_config = {
> .val_format_endian = REGMAP_ENDIAN_LITTLE,
> };
>
> -static const struct mfd_cell cells[] = {
> +static const struct bq257xx_match_data bq25703a_match_data = {
> + .plat = { .type = BQ25703A },
> + .regmap_config = &bq25703_regmap_config,
> +};
> +
> +static const struct regmap_range bq25792_writeable_reg_ranges[] = {
> + regmap_reg_range(BQ25792_REG00_MIN_SYS_VOLTAGE,
> + BQ25792_REG18_NTC_CONTROL_1),
> + regmap_reg_range(BQ25792_REG28_CHARGER_MASK_0,
> + BQ25792_REG30_ADC_FUNCTION_DISABLE_1),
> +};
> +
> +static const struct regmap_access_table bq25792_writeable_regs = {
> + .yes_ranges = bq25792_writeable_reg_ranges,
> + .n_yes_ranges = ARRAY_SIZE(bq25792_writeable_reg_ranges),
> +};
> +
> +static const struct regmap_range bq25792_volatile_reg_ranges[] = {
> + regmap_reg_range(BQ25792_REG19_ICO_CURRENT_LIMIT,
> + BQ25792_REG27_FAULT_FLAG_1),
> + regmap_reg_range(BQ25792_REG31_IBUS_ADC,
> + BQ25792_REG47_DPDM_DRIVER),
> +};
> +
> +static const struct regmap_access_table bq25792_volatile_regs = {
> + .yes_ranges = bq25792_volatile_reg_ranges,
> + .n_yes_ranges = ARRAY_SIZE(bq25792_volatile_reg_ranges),
> +};
> +
> +static const struct regmap_config bq25792_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = BQ25792_REG48_PART_INFORMATION,
> + .cache_type = REGCACHE_MAPLE,
> + .wr_table = &bq25792_writeable_regs,
> + .volatile_table = &bq25792_volatile_regs,
> +};
> +
> +static const struct bq257xx_match_data bq25792_match_data = {
> + .plat = { .type = BQ25792 },
> + .regmap_config = &bq25792_regmap_config,
> +};
> +
> +static struct mfd_cell cells[] = {
> MFD_CELL_NAME("bq257xx-regulator"),
> MFD_CELL_NAME("bq257xx-charger"),
> };
>
> static int bq257xx_probe(struct i2c_client *client)
> {
> + const struct bq257xx_match_data *md = device_get_match_data(&client->dev);
> struct bq257xx_device *ddata;
> - int ret;
> + int i, ret;
> +
> + for (i = 0; i < ARRAY_SIZE(cells); i++) {
> + cells[i].platform_data = &md->plat;
> + cells[i].pdata_size = sizeof(md->plat);
> + }
>
> ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
> if (!ddata)
> @@ -55,7 +109,7 @@ static int bq257xx_probe(struct i2c_client *client)
>
> ddata->client = client;
>
> - ddata->regmap = devm_regmap_init_i2c(client, &bq25703_regmap_config);
> + ddata->regmap = devm_regmap_init_i2c(client, md->regmap_config);
> if (IS_ERR(ddata->regmap)) {
> return dev_err_probe(&client->dev, PTR_ERR(ddata->regmap),
> "Failed to allocate register map\n");
> @@ -74,12 +128,14 @@ static int bq257xx_probe(struct i2c_client *client)
>
> static const struct i2c_device_id bq257xx_i2c_ids[] = {
> { "bq25703a" },
> + { "bq25792" },
> {}
> };
> MODULE_DEVICE_TABLE(i2c, bq257xx_i2c_ids);
>
> static const struct of_device_id bq257xx_of_match[] = {
> - { .compatible = "ti,bq25703a" },
> + { .compatible = "ti,bq25703a", .data = &bq25703a_match_data },
> + { .compatible = "ti,bq25792", .data = &bq25792_match_data },
Instead of passing through the data structure, pass an identifier to
match on, like:
{ .compatible = "ti,bq25703a", .data = (void *)BQ25703A },
Then add the ID to ddata which is already obtainable from the child
devices via i2c_set_clientdata(). This saves passing it as separate
platform data.
ddata->type = device_get_match_data(&client->dev);
Then use that to initialise a local 'struct regmap_config'.
switch(ddata->type) {
case BQ25703A:
regmap_config = &bq25703_regmap_config
break;
[...]
By doing so, you save on a lot of additional complexity and mitigate the
introduction of some unnecessary data structures.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support
2026-03-10 13:03 ` Lee Jones
@ 2026-03-10 13:49 ` Alexey Charkov
0 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-10 13:49 UTC (permalink / raw)
To: Lee Jones
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chris Morgan,
Liam Girdwood, Mark Brown, Sebastian Reichel, devicetree,
linux-kernel, Sebastian Reichel, linux-pm
On Tue, Mar 10, 2026 at 5:03 PM Lee Jones <lee@kernel.org> wrote:
>
> On Tue, 10 Mar 2026, Alexey Charkov wrote:
>
> > Add register definitions and a new 'type' enum to be passed in MFD
> > platform data to support the BQ25792, which is a newer variant of the
> > BQ257xx family.
> >
> > BQ25792 shares similar logic of operation with the already supported
> > BQ25703A but has a completely different register map and different
> > electrical constraints.
> >
> > Tested-by: Chris Morgan <macromorgan@hotmail.com>
> > Signed-off-by: Alexey Charkov <alchark@flipper.net>
> > ---
> > drivers/mfd/bq257xx.c | 64 ++++++-
> > include/linux/mfd/bq257xx.h | 417 ++++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 477 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/mfd/bq257xx.c b/drivers/mfd/bq257xx.c
> > index e9d49dac0a16..7516e2ec00e6 100644
> > --- a/drivers/mfd/bq257xx.c
> > +++ b/drivers/mfd/bq257xx.c
> > @@ -10,6 +10,11 @@
> > #include <linux/mfd/core.h>
> > #include <linux/regmap.h>
> >
> > +struct bq257xx_match_data {
> > + const struct bq257xx_plat plat;
> > + const struct regmap_config *regmap_config;
> > +};
> > +
> > static const struct regmap_range bq25703_readonly_reg_ranges[] = {
> > regmap_reg_range(BQ25703_CHARGER_STATUS, BQ25703_MANUFACT_DEV_ID),
> > };
> > @@ -39,15 +44,64 @@ static const struct regmap_config bq25703_regmap_config = {
> > .val_format_endian = REGMAP_ENDIAN_LITTLE,
> > };
> >
> > -static const struct mfd_cell cells[] = {
> > +static const struct bq257xx_match_data bq25703a_match_data = {
> > + .plat = { .type = BQ25703A },
> > + .regmap_config = &bq25703_regmap_config,
> > +};
> > +
> > +static const struct regmap_range bq25792_writeable_reg_ranges[] = {
> > + regmap_reg_range(BQ25792_REG00_MIN_SYS_VOLTAGE,
> > + BQ25792_REG18_NTC_CONTROL_1),
> > + regmap_reg_range(BQ25792_REG28_CHARGER_MASK_0,
> > + BQ25792_REG30_ADC_FUNCTION_DISABLE_1),
> > +};
> > +
> > +static const struct regmap_access_table bq25792_writeable_regs = {
> > + .yes_ranges = bq25792_writeable_reg_ranges,
> > + .n_yes_ranges = ARRAY_SIZE(bq25792_writeable_reg_ranges),
> > +};
> > +
> > +static const struct regmap_range bq25792_volatile_reg_ranges[] = {
> > + regmap_reg_range(BQ25792_REG19_ICO_CURRENT_LIMIT,
> > + BQ25792_REG27_FAULT_FLAG_1),
> > + regmap_reg_range(BQ25792_REG31_IBUS_ADC,
> > + BQ25792_REG47_DPDM_DRIVER),
> > +};
> > +
> > +static const struct regmap_access_table bq25792_volatile_regs = {
> > + .yes_ranges = bq25792_volatile_reg_ranges,
> > + .n_yes_ranges = ARRAY_SIZE(bq25792_volatile_reg_ranges),
> > +};
> > +
> > +static const struct regmap_config bq25792_regmap_config = {
> > + .reg_bits = 8,
> > + .val_bits = 8,
> > + .max_register = BQ25792_REG48_PART_INFORMATION,
> > + .cache_type = REGCACHE_MAPLE,
> > + .wr_table = &bq25792_writeable_regs,
> > + .volatile_table = &bq25792_volatile_regs,
> > +};
> > +
> > +static const struct bq257xx_match_data bq25792_match_data = {
> > + .plat = { .type = BQ25792 },
> > + .regmap_config = &bq25792_regmap_config,
> > +};
> > +
> > +static struct mfd_cell cells[] = {
> > MFD_CELL_NAME("bq257xx-regulator"),
> > MFD_CELL_NAME("bq257xx-charger"),
> > };
> >
> > static int bq257xx_probe(struct i2c_client *client)
> > {
> > + const struct bq257xx_match_data *md = device_get_match_data(&client->dev);
> > struct bq257xx_device *ddata;
> > - int ret;
> > + int i, ret;
> > +
> > + for (i = 0; i < ARRAY_SIZE(cells); i++) {
> > + cells[i].platform_data = &md->plat;
> > + cells[i].pdata_size = sizeof(md->plat);
> > + }
> >
> > ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
> > if (!ddata)
> > @@ -55,7 +109,7 @@ static int bq257xx_probe(struct i2c_client *client)
> >
> > ddata->client = client;
> >
> > - ddata->regmap = devm_regmap_init_i2c(client, &bq25703_regmap_config);
> > + ddata->regmap = devm_regmap_init_i2c(client, md->regmap_config);
> > if (IS_ERR(ddata->regmap)) {
> > return dev_err_probe(&client->dev, PTR_ERR(ddata->regmap),
> > "Failed to allocate register map\n");
> > @@ -74,12 +128,14 @@ static int bq257xx_probe(struct i2c_client *client)
> >
> > static const struct i2c_device_id bq257xx_i2c_ids[] = {
> > { "bq25703a" },
> > + { "bq25792" },
> > {}
> > };
> > MODULE_DEVICE_TABLE(i2c, bq257xx_i2c_ids);
> >
> > static const struct of_device_id bq257xx_of_match[] = {
> > - { .compatible = "ti,bq25703a" },
> > + { .compatible = "ti,bq25703a", .data = &bq25703a_match_data },
> > + { .compatible = "ti,bq25792", .data = &bq25792_match_data },
>
> Instead of passing through the data structure, pass an identifier to
> match on, like:
>
> { .compatible = "ti,bq25703a", .data = (void *)BQ25703A },
>
> Then add the ID to ddata which is already obtainable from the child
> devices via i2c_set_clientdata(). This saves passing it as separate
> platform data.
>
> ddata->type = device_get_match_data(&client->dev);
>
> Then use that to initialise a local 'struct regmap_config'.
>
> switch(ddata->type) {
> case BQ25703A:
> regmap_config = &bq25703_regmap_config
> break;
> [...]
>
> By doing so, you save on a lot of additional complexity and mitigate the
> introduction of some unnecessary data structures.
Thanks for the suggestion Lee, it does indeed make the code leaner.
Will wait for any additional feedback and send v4.
Best regards,
Alexey
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic
2026-03-10 9:28 ` [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic Alexey Charkov
@ 2026-03-11 7:08 ` Sebastian Reichel
0 siblings, 0 replies; 20+ messages in thread
From: Sebastian Reichel @ 2026-03-11 7:08 UTC (permalink / raw)
To: Alexey Charkov
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm, stable
[-- Attachment #1: Type: text/plain, Size: 2216 bytes --]
Hi,
On Tue, Mar 10, 2026 at 01:28:29PM +0400, Alexey Charkov wrote:
> The minimal system voltage (VSYSMIN) is meant to protect the battery from
> dangerous over-discharge. When the device tree provides a value for the
> minimum design voltage of the battery, the user should not be allowed to
> set a lower VSYSMIN, as that would defeat the purpose of this protection.
>
> Flip the clamping logic when setting VSYSMIN to ensure that battery design
> voltage is respected.
>
> Cc: stable@vger.kernel.org
> Fixes: 1cc017b7f9c7 ("power: supply: bq257xx: Add support for BQ257XX charger")
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
> drivers/power/supply/bq257xx_charger.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> index 02c7d8b61e82..7ca4ae610902 100644
> --- a/drivers/power/supply/bq257xx_charger.c
> +++ b/drivers/power/supply/bq257xx_charger.c
> @@ -128,9 +128,8 @@ static int bq25703_get_min_vsys(struct bq257xx_chg *pdata, int *intval)
> * @vsys: voltage value to set in uV.
> *
> * This function takes a requested minimum system voltage value, clamps
> - * it between the minimum supported value by the charger and a user
> - * defined minimum system value, and then writes the value to the
> - * appropriate register.
> + * it between the user defined minimum system value and the maximum supported
> + * value by the charger, and then writes the value to the appropriate register.
> *
> * Return: Returns 0 on success or error if an error occurs.
> */
> @@ -139,7 +138,7 @@ static int bq25703_set_min_vsys(struct bq257xx_chg *pdata, int vsys)
> unsigned int reg;
> int vsys_min = pdata->vsys_min;
>
> - vsys = clamp(vsys, BQ25703_MINVSYS_MIN_UV, vsys_min);
> + vsys = clamp(vsys, vsys_min, BQ25703_MINVSYS_MAX_UV);
> reg = ((vsys - BQ25703_MINVSYS_MIN_UV) / BQ25703_MINVSYS_STEP_UV);
> reg = FIELD_PREP(BQ25703_MINVSYS_MASK, reg);
>
>
> --
> 2.52.0
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute
2026-03-10 9:28 ` [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute Alexey Charkov
@ 2026-03-11 7:08 ` Sebastian Reichel
0 siblings, 0 replies; 20+ messages in thread
From: Sebastian Reichel @ 2026-03-11 7:08 UTC (permalink / raw)
To: Alexey Charkov
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm
[-- Attachment #1: Type: text/plain, Size: 1920 bytes --]
Hi,
On Tue, Mar 10, 2026 at 01:28:30PM +0400, Alexey Charkov wrote:
> Add a field for the default current limit to the bq257xx_info structure and
> use it instead of the hardcoded value in the probe function.
>
> This prepares the driver for allowing different electrical constraints for
> different chip variants.
>
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
> drivers/power/supply/bq257xx_charger.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> index 7ca4ae610902..e14dd16f9d08 100644
> --- a/drivers/power/supply/bq257xx_charger.c
> +++ b/drivers/power/supply/bq257xx_charger.c
> @@ -26,6 +26,7 @@ struct bq257xx_chg;
> * @bq257xx_set_iindpm: set maximum input current (in uA)
> */
> struct bq257xx_chip_info {
> + int default_iindpm_uA;
> int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
> void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
> int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
> @@ -627,6 +628,7 @@ static const struct power_supply_desc bq257xx_power_supply_desc = {
> };
>
> static const struct bq257xx_chip_info bq25703_chip_info = {
> + .default_iindpm_uA = BQ25703_IINDPM_DEFAULT_UA,
> .bq257xx_hw_init = &bq25703_hw_init,
> .bq257xx_hw_shutdown = &bq25703_hw_shutdown,
> .bq257xx_get_state = &bq25703_get_state,
> @@ -675,7 +677,7 @@ static int bq257xx_parse_dt(struct bq257xx_chg *pdata,
> "input-current-limit-microamp",
> &pdata->iindpm_max);
> if (ret)
> - pdata->iindpm_max = BQ25703_IINDPM_DEFAULT_UA;
> + pdata->iindpm_max = pdata->chip->default_iindpm_uA;
>
> return 0;
> }
>
> --
> 2.52.0
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers
2026-03-10 9:28 ` [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers Alexey Charkov
@ 2026-03-11 7:09 ` Sebastian Reichel
0 siblings, 0 replies; 20+ messages in thread
From: Sebastian Reichel @ 2026-03-11 7:09 UTC (permalink / raw)
To: Alexey Charkov
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm
[-- Attachment #1: Type: text/plain, Size: 3739 bytes --]
Hi,
On Tue, Mar 10, 2026 at 01:28:31PM +0400, Alexey Charkov wrote:
> Move the remaining get/set helper functions to indirect calls via the
> per-chip bq257xx_chip_info struct.
>
> This improves the consistency of the code and prepares the driver to
> support multiple chip variants with different register layouts and bit
> definitions.
>
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
> drivers/power/supply/bq257xx_charger.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> index e14dd16f9d08..deb60a9bd222 100644
> --- a/drivers/power/supply/bq257xx_charger.c
> +++ b/drivers/power/supply/bq257xx_charger.c
> @@ -30,9 +30,15 @@ struct bq257xx_chip_info {
> int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
> void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
> int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
> + int (*bq257xx_get_ichg)(struct bq257xx_chg *pdata, int *intval);
> int (*bq257xx_set_ichg)(struct bq257xx_chg *pdata, int ichg);
> + int (*bq257xx_get_vbatreg)(struct bq257xx_chg *pdata, int *intval);
> int (*bq257xx_set_vbatreg)(struct bq257xx_chg *pdata, int vbatreg);
> + int (*bq257xx_get_iindpm)(struct bq257xx_chg *pdata, int *intval);
> int (*bq257xx_set_iindpm)(struct bq257xx_chg *pdata, int iindpm);
> + int (*bq257xx_get_cur)(struct bq257xx_chg *pdata, int *intval);
> + int (*bq257xx_get_vbat)(struct bq257xx_chg *pdata, int *intval);
> + int (*bq257xx_get_min_vsys)(struct bq257xx_chg *pdata, int *intval);
> };
>
> /**
> @@ -489,22 +495,22 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
> break;
>
> case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> - return bq25703_get_iindpm(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_iindpm(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
> - return bq25703_get_chrg_volt(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_vbatreg(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_CURRENT_NOW:
> - return bq25703_get_cur(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_cur(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> - return bq25703_get_vbat(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_vbat(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
> - return bq25703_get_ichg_cur(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_ichg(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> - return bq25703_get_min_vsys(pdata, &val->intval);
> + return pdata->chip->bq257xx_get_min_vsys(pdata, &val->intval);
>
> case POWER_SUPPLY_PROP_USB_TYPE:
> val->intval = pdata->usb_type;
> @@ -632,9 +638,15 @@ static const struct bq257xx_chip_info bq25703_chip_info = {
> .bq257xx_hw_init = &bq25703_hw_init,
> .bq257xx_hw_shutdown = &bq25703_hw_shutdown,
> .bq257xx_get_state = &bq25703_get_state,
> + .bq257xx_get_ichg = &bq25703_get_ichg_cur,
> .bq257xx_set_ichg = &bq25703_set_ichg_cur,
> + .bq257xx_get_vbatreg = &bq25703_get_chrg_volt,
> .bq257xx_set_vbatreg = &bq25703_set_chrg_volt,
> + .bq257xx_get_iindpm = &bq25703_get_iindpm,
> .bq257xx_set_iindpm = &bq25703_set_iindpm,
> + .bq257xx_get_cur = &bq25703_get_cur,
> + .bq257xx_get_vbat = &bq25703_get_vbat,
> + .bq257xx_get_min_vsys = &bq25703_get_min_vsys,
> };
>
> /**
>
> --
> 2.52.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states
2026-03-10 9:28 ` [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states Alexey Charkov
@ 2026-03-11 7:09 ` Sebastian Reichel
0 siblings, 0 replies; 20+ messages in thread
From: Sebastian Reichel @ 2026-03-11 7:09 UTC (permalink / raw)
To: Alexey Charkov
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm
[-- Attachment #1: Type: text/plain, Size: 2813 bytes --]
Hi,
On Tue, Mar 10, 2026 at 01:28:32PM +0400, Alexey Charkov wrote:
> The driver currently reports the 'charging' and 'overvoltage' states based
> on a logical expression in the get_charger_property() wrapper function.
> This doesn't scale well to other chip variants, which may have a different
> number and type of hardware reported conditions which fall into these
> broad power supply states.
>
> Move the logic for determining 'charging' and 'overvoltage' states into
> chip-specific accessors, which can be overridden by each variant as
> needed.
>
> This helps keep the get_charger_property() wrapper function chip-agnostic
> while allowing for new chip variants to be added bringing their own logic.
>
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
> drivers/power/supply/bq257xx_charger.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> index deb60a9bd222..951abd035fc5 100644
> --- a/drivers/power/supply/bq257xx_charger.c
> +++ b/drivers/power/supply/bq257xx_charger.c
> @@ -64,8 +64,10 @@ struct bq257xx_chg {
> struct bq257xx_device *bq;
> struct power_supply *charger;
> bool online;
> + bool charging;
> bool fast_charge;
> bool pre_charge;
> + bool overvoltage;
> bool ov_fault;
> bool batoc_fault;
> bool oc_fault;
> @@ -99,8 +101,10 @@ static int bq25703_get_state(struct bq257xx_chg *pdata)
> pdata->online = reg & BQ25703_STS_AC_STAT;
> pdata->fast_charge = reg & BQ25703_STS_IN_FCHRG;
> pdata->pre_charge = reg & BQ25703_STS_IN_PCHRG;
> + pdata->charging = pdata->fast_charge || pdata->pre_charge;
> pdata->ov_fault = reg & BQ25703_STS_FAULT_ACOV;
> pdata->batoc_fault = reg & BQ25703_STS_FAULT_BATOC;
> + pdata->overvoltage = pdata->ov_fault || pdata->batoc_fault;
> pdata->oc_fault = reg & BQ25703_STS_FAULT_ACOC;
>
> return 0;
> @@ -471,14 +475,14 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
> case POWER_SUPPLY_PROP_STATUS:
> if (!pdata->online)
> val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> - else if (pdata->fast_charge || pdata->pre_charge)
> + else if (pdata->charging)
> val->intval = POWER_SUPPLY_STATUS_CHARGING;
> else
> val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
> break;
>
> case POWER_SUPPLY_PROP_HEALTH:
> - if (pdata->ov_fault || pdata->batoc_fault)
> + if (pdata->overvoltage)
> val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
> else if (pdata->oc_fault)
> val->intval = POWER_SUPPLY_HEALTH_OVERCURRENT;
>
> --
> 2.52.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 11/11] power: supply: bq257xx: Add support for BQ25792
2026-03-10 9:28 ` [PATCH v3 11/11] power: supply: " Alexey Charkov
@ 2026-03-11 8:52 ` Sebastian Reichel
2026-03-11 9:22 ` Alexey Charkov
0 siblings, 1 reply; 20+ messages in thread
From: Sebastian Reichel @ 2026-03-11 8:52 UTC (permalink / raw)
To: Alexey Charkov
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm
[-- Attachment #1: Type: text/plain, Size: 4376 bytes --]
Hello Alexey,
On Tue, Mar 10, 2026 at 01:28:35PM +0400, Alexey Charkov wrote:
> Add support for TI BQ25792 integrated battery charger and buck-boost
> converter.
>
> It shares high-level logic of operation with the already supported
> BQ25703A, but has a different register map, bit definitions and some of
> the lower-level hardware states.
>
> Tested-by: Chris Morgan <macromorgan@hotmail.com>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---
> drivers/power/supply/bq257xx_charger.c | 492 ++++++++++++++++++++++++++++++++-
> include/linux/mfd/bq257xx.h | 6 +-
> 2 files changed, 493 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> index 951abd035fc5..0bbb0a8b5f55 100644
> --- a/drivers/power/supply/bq257xx_charger.c
> +++ b/drivers/power/supply/bq257xx_charger.c
> @@ -5,6 +5,7 @@
> */
>
> #include <linux/bitfield.h>
> +#include <linux/byteorder/generic.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/mfd/bq257xx.h>
> @@ -18,12 +19,19 @@ struct bq257xx_chg;
>
> /**
> * struct bq257xx_chip_info - chip specific routines
> + * @default_iindpm_uA: default input current limit in microamps
> * @bq257xx_hw_init: init function for hw
> * @bq257xx_hw_shutdown: shutdown function for hw
> * @bq257xx_get_state: get and update state of hardware
> + * @bq257xx_get_ichg: get maximum charge current (in uA)
> * @bq257xx_set_ichg: set maximum charge current (in uA)
> + * @bq257xx_get_vbatreg: get maximum charge voltage (in uV)
> * @bq257xx_set_vbatreg: set maximum charge voltage (in uV)
> + * @bq257xx_get_iindpm: get maximum input current (in uA)
> * @bq257xx_set_iindpm: set maximum input current (in uA)
> + * @bq257xx_get_cur: get battery current from ADC (in uA)
> + * @bq257xx_get_vbat: get battery voltage from ADC (in uV)
> + * @bq257xx_get_min_vsys: get minimum system voltage (in uV)
> */
> struct bq257xx_chip_info {
> int default_iindpm_uA;
> @@ -47,8 +55,10 @@ struct bq257xx_chip_info {
> * @bq: parent MFD device
> * @charger: power supply device
> * @online: charger input is present
> + * @charging: charger is actively charging the battery
> * @fast_charge: charger is in fast charge mode
> * @pre_charge: charger is in pre-charge mode
> + * @overvoltage: overvoltage fault detected
> * @ov_fault: charger reports over voltage fault
> * @batoc_fault: charger reports battery over current fault
> * @oc_fault: charger reports over current fault
> @@ -79,6 +89,53 @@ struct bq257xx_chg {
> u32 vsys_min;
> };
The above belong into the previous patches that actually added the
fields to the structs :)
> +/**
> + * bq25792_read16() - Read a 16-bit value from device register
> + * @pdata: driver platform data
> + * @reg: register address to read from
> + * @val: pointer to store the register value
> + *
> + * Read a 16-bit big-endian value from the BQ25792 device via regmap
> + * and convert to CPU byte order.
> + *
> + * Return: Returns 0 on success or error on failure to read.
> + */
> +static int bq25792_read16(struct bq257xx_chg *pdata, unsigned int reg, u16 *val)
> +{
> + __be16 regval;
> + int ret;
> +
> + ret = regmap_raw_read(pdata->bq->regmap, reg, ®val, sizeof(regval));
> + if (ret)
> + return ret;
> +
> + *val = be16_to_cpu(regval);
> + return 0;
> +}
> +
> +/**
> + * bq25792_write16() - Write a 16-bit value to device register
> + * @pdata: driver platform data
> + * @reg: register address to write to
> + * @val: 16-bit value to write in CPU byte order
> + *
> + * Convert the value to big-endian and write a 16-bit value to the
> + * BQ25792 device via regmap.
> + *
> + * Return: Returns 0 on success or error on failure to write.
> + */
> +static int bq25792_write16(struct bq257xx_chg *pdata, unsigned int reg, u16 val)
> +{
> + __be16 regval = cpu_to_be16(val);
> + int ret;
> +
> + ret = regmap_raw_write(pdata->bq->regmap, reg, ®val, sizeof(regval));
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
Are there big _and_ little endian registers on the bq25792? Otherwise I
would expect this to be done by properly configuring regmap.
> [...]
The remaining part looks fine.
Greetings,
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 11/11] power: supply: bq257xx: Add support for BQ25792
2026-03-11 8:52 ` Sebastian Reichel
@ 2026-03-11 9:22 ` Alexey Charkov
0 siblings, 0 replies; 20+ messages in thread
From: Alexey Charkov @ 2026-03-11 9:22 UTC (permalink / raw)
To: Sebastian Reichel
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Chris Morgan, Liam Girdwood, Mark Brown, devicetree, linux-kernel,
linux-pm
On Wed, Mar 11, 2026 at 12:52 PM Sebastian Reichel
<sebastian.reichel@collabora.com> wrote:
>
> Hello Alexey,
>
> On Tue, Mar 10, 2026 at 01:28:35PM +0400, Alexey Charkov wrote:
> > Add support for TI BQ25792 integrated battery charger and buck-boost
> > converter.
> >
> > It shares high-level logic of operation with the already supported
> > BQ25703A, but has a different register map, bit definitions and some of
> > the lower-level hardware states.
> >
> > Tested-by: Chris Morgan <macromorgan@hotmail.com>
> > Signed-off-by: Alexey Charkov <alchark@flipper.net>
> > ---
> > drivers/power/supply/bq257xx_charger.c | 492 ++++++++++++++++++++++++++++++++-
> > include/linux/mfd/bq257xx.h | 6 +-
> > 2 files changed, 493 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c
> > index 951abd035fc5..0bbb0a8b5f55 100644
> > --- a/drivers/power/supply/bq257xx_charger.c
> > +++ b/drivers/power/supply/bq257xx_charger.c
> > @@ -5,6 +5,7 @@
> > */
> >
> > #include <linux/bitfield.h>
> > +#include <linux/byteorder/generic.h>
> > #include <linux/i2c.h>
> > #include <linux/interrupt.h>
> > #include <linux/mfd/bq257xx.h>
> > @@ -18,12 +19,19 @@ struct bq257xx_chg;
> >
> > /**
> > * struct bq257xx_chip_info - chip specific routines
> > + * @default_iindpm_uA: default input current limit in microamps
> > * @bq257xx_hw_init: init function for hw
> > * @bq257xx_hw_shutdown: shutdown function for hw
> > * @bq257xx_get_state: get and update state of hardware
> > + * @bq257xx_get_ichg: get maximum charge current (in uA)
> > * @bq257xx_set_ichg: set maximum charge current (in uA)
> > + * @bq257xx_get_vbatreg: get maximum charge voltage (in uV)
> > * @bq257xx_set_vbatreg: set maximum charge voltage (in uV)
> > + * @bq257xx_get_iindpm: get maximum input current (in uA)
> > * @bq257xx_set_iindpm: set maximum input current (in uA)
> > + * @bq257xx_get_cur: get battery current from ADC (in uA)
> > + * @bq257xx_get_vbat: get battery voltage from ADC (in uV)
> > + * @bq257xx_get_min_vsys: get minimum system voltage (in uV)
> > */
> > struct bq257xx_chip_info {
> > int default_iindpm_uA;
> > @@ -47,8 +55,10 @@ struct bq257xx_chip_info {
> > * @bq: parent MFD device
> > * @charger: power supply device
> > * @online: charger input is present
> > + * @charging: charger is actively charging the battery
> > * @fast_charge: charger is in fast charge mode
> > * @pre_charge: charger is in pre-charge mode
> > + * @overvoltage: overvoltage fault detected
> > * @ov_fault: charger reports over voltage fault
> > * @batoc_fault: charger reports battery over current fault
> > * @oc_fault: charger reports over current fault
> > @@ -79,6 +89,53 @@ struct bq257xx_chg {
> > u32 vsys_min;
> > };
>
> The above belong into the previous patches that actually added the
> fields to the structs :)
Fair enough, will move it there. Thanks for spotting!
> > + * bq25792_read16() - Read a 16-bit value from device register
> > + * @pdata: driver platform data
> > + * @reg: register address to read from
> > + * @val: pointer to store the register value
> > + *
> > + * Read a 16-bit big-endian value from the BQ25792 device via regmap
> > + * and convert to CPU byte order.
> > + *
> > + * Return: Returns 0 on success or error on failure to read.
> > + */
> > +static int bq25792_read16(struct bq257xx_chg *pdata, unsigned int reg, u16 *val)
> > +{
> > + __be16 regval;
> > + int ret;
> > +
> > + ret = regmap_raw_read(pdata->bq->regmap, reg, ®val, sizeof(regval));
> > + if (ret)
> > + return ret;
> > +
> > + *val = be16_to_cpu(regval);
> > + return 0;
> > +}
> > +
> > +/**
> > + * bq25792_write16() - Write a 16-bit value to device register
> > + * @pdata: driver platform data
> > + * @reg: register address to write to
> > + * @val: 16-bit value to write in CPU byte order
> > + *
> > + * Convert the value to big-endian and write a 16-bit value to the
> > + * BQ25792 device via regmap.
> > + *
> > + * Return: Returns 0 on success or error on failure to write.
> > + */
> > +static int bq25792_write16(struct bq257xx_chg *pdata, unsigned int reg, u16 val)
> > +{
> > + __be16 regval = cpu_to_be16(val);
> > + int ret;
> > +
> > + ret = regmap_raw_write(pdata->bq->regmap, reg, ®val, sizeof(regval));
> > + if (ret)
> > + return ret;
> > +
> > + return 0;
> > +}
>
> Are there big _and_ little endian registers on the bq25792? Otherwise I
> would expect this to be done by properly configuring regmap.
Oh it's such a pain actually. Most of its registers are 8-bit, but
select few are 16-bit big endian. So if one tries to configure the
regmap for 16-bit big-endian, it incorrectly accesses the 8-bit ones,
as the least significant byte is then not at the right address (and it
also spoils unrelated registers at write). Setting big endian with
8-bit registers in the regmap doesn't make much sense as there is no
endianness with bytes. So I ended up setting the regmap to 8-bit
registers without any endianness flags, and dealing with the
big-endian 16-bit ones manually as above.
If there is a more elegant way to do that please let me know, because
I'm not a fan of that manual endianness trickery myself.
Thanks a lot,
Alexey
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2026-03-11 9:22 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 9:28 [PATCH v3 00/11] Add support for the TI BQ25792 battery charger Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 01/11] dt-bindings: mfd: ti,bq25703a: Expand to include BQ25792 Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 02/11] regulator: bq257xx: Remove reference to the parent MFD's dev Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 03/11] regulator: bq257xx: Drop the regulator_dev from the driver data Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 04/11] regulator: bq257xx: Make OTG enable GPIO really optional Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 05/11] power: supply: bq257xx: Fix VSYSMIN clamping logic Alexey Charkov
2026-03-11 7:08 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 06/11] power: supply: bq257xx: Make the default current limit a per-chip attribute Alexey Charkov
2026-03-11 7:08 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 07/11] power: supply: bq257xx: Consistently use indirect get/set helpers Alexey Charkov
2026-03-11 7:09 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 08/11] power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states Alexey Charkov
2026-03-11 7:09 ` Sebastian Reichel
2026-03-10 9:28 ` [PATCH v3 09/11] mfd: bq257xx: Add BQ25792 support Alexey Charkov
2026-03-10 13:03 ` Lee Jones
2026-03-10 13:49 ` Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 10/11] regulator: bq257xx: Add support for BQ25792 Alexey Charkov
2026-03-10 9:28 ` [PATCH v3 11/11] power: supply: " Alexey Charkov
2026-03-11 8:52 ` Sebastian Reichel
2026-03-11 9:22 ` Alexey Charkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox