Skip to contentSkip to conversation

power: supply: bq25980 Apply datasheet revision changes

PATCH In review Ricardo Rivera-Matos 3 participants 6 messages Feb 10, 2021 – Apr 5, 2021 Power supply

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 power: supply: bq25980 Apply datasheet revision changes

The latest datasheet revision for BQ25980, BQ25975, and BQ25960 changed

various register step sizes and offset values.

This patch changes the following header file

values for POWER_SUPPLY_PROP_CURRENT_NOW,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,

POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,

POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, and POWER_SUPPLY_PROP_VOLTAGE_NOW.

Additionally, this patch adjusts bq25980_get_input_curr_lim(),

bq25980_set_input_curr_lim(), bq25980_get_const_charge_curr(), and

bq25980_set_const_charge_curr() to perform the get/set math correctly.

Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 141 ++++++++++++++++++++-----
 drivers/power/supply/bq25980_charger.h |  77 ++++++++++----
 2 files changed, 173 insertions(+), 45 deletions(-)
drivers/power/supply/bq25980_charger.c +115 -26
index 530ff4025b31..7c489a9e8877 100644
@@ -52,6 +52,10 @@ struct bq25980_chip_info {
 	int busocp_byp_max;
 	int busocp_sc_min;
 	int busocp_byp_min;
+	int busocp_sc_step;
+	int busocp_byp_step;
+	int busocp_sc_offset;
+	int busocp_byp_offset;
 
 	int busovp_sc_def;
 	int busovp_byp_def;
@@ -73,6 +77,20 @@ struct bq25980_chip_info {
 
 	int batocp_def;
 	int batocp_max;
+	int batocp_min;
+	int batocp_step;
+
+	int vbus_adc_step;
+	int vbus_adc_offset;
+
+	int ibus_adc_step;
+	int ibus_adc_offset;
+
+	int vbat_adc_step;
+	int vbat_adc_offset;
+
+	int ibat_adc_step;
+	int ibat_adc_offset;
 };
 
 struct bq25980_init_data {
@@ -275,13 +293,22 @@ static int bq25980_watchdog_time[BQ25980_NUM_WD_VAL] = {5000, 10000, 50000,
 static int bq25980_get_input_curr_lim(struct bq25980_device *bq)
 {
 	unsigned int busocp_reg_code;
+	int offset, step;
 	int ret;
 
+	if (bq->state.bypass) {
+		step = bq->chip_info->busocp_byp_step;
+		offset = bq->chip_info->busocp_byp_offset;
+	} else {
+		step = bq->chip_info->busocp_sc_step;
+		offset = bq->chip_info->busocp_sc_offset;
+	}
+
 	ret = regmap_read(bq->regmap, BQ25980_BUSOCP, &busocp_reg_code);
 	if (ret)
 		return ret;
 
-	return (busocp_reg_code * BQ25980_BUSOCP_STEP_uA) + BQ25980_BUSOCP_OFFSET_uA;
+	return (busocp_reg_code * step) + offset;
 }
 
 static int bq25980_set_hiz(struct bq25980_device *bq, int setting)
@@ -293,6 +320,7 @@ static int bq25980_set_hiz(struct bq25980_device *bq, int setting)
 static int bq25980_set_input_curr_lim(struct bq25980_device *bq, int busocp)
 {
 	unsigned int busocp_reg_code;
+	int step, offset;
 	int ret;
 
 	if (!busocp)
@@ -303,13 +331,17 @@ static int bq25980_set_input_curr_lim(struct bq25980_device *bq, int busocp)
 	if (busocp < BQ25980_BUSOCP_MIN_uA)
 		busocp = BQ25980_BUSOCP_MIN_uA;
 
-	if (bq->state.bypass)
+	if (bq->state.bypass) {
 		busocp = min(busocp, bq->chip_info->busocp_sc_max);
-	else
+		step = bq->chip_info->busocp_byp_step;
+		offset = bq->chip_info->busocp_byp_offset;
+	} else {
 		busocp = min(busocp, bq->chip_info->busocp_byp_max);
+		step = bq->chip_info->busocp_sc_step;
+		offset = bq->chip_info->busocp_sc_offset;
+	}
 
-	busocp_reg_code = (busocp - BQ25980_BUSOCP_OFFSET_uA)
-						/ BQ25980_BUSOCP_STEP_uA;
+	busocp_reg_code = (busocp - offset) / step;
 
 	ret = regmap_write(bq->regmap, BQ25980_BUSOCP, busocp_reg_code);
 	if (ret)
@@ -374,6 +406,7 @@ static int bq25980_set_input_volt_lim(struct bq25980_device *bq, int busovp)
 
 static int bq25980_get_const_charge_curr(struct bq25980_device *bq)
 {
+	int step = bq->chip_info->batocp_step;
 	unsigned int batocp_reg_code;
 	int ret;
 
@@ -381,19 +414,20 @@ static int bq25980_get_const_charge_curr(struct bq25980_device *bq)
 	if (ret)
 		return ret;
 
-	return (batocp_reg_code & BQ25980_BATOCP_MASK) *
-						BQ25980_BATOCP_STEP_uA;
+	return (batocp_reg_code & BQ25980_BATOCP_MASK) * step;
 }
 
 static int bq25980_set_const_charge_curr(struct bq25980_device *bq, int batocp)
 {
+	int step = bq->chip_info->batocp_step;
+	int max = bq->chip_info->batocp_max;
+	int min = bq->chip_info->batocp_min;
 	unsigned int batocp_reg_code;
 	int ret;
 
-	batocp = max(batocp, BQ25980_BATOCP_MIN_uA);
-	batocp = min(batocp, bq->chip_info->batocp_max);
+	batocp = clamp(batocp, min, max);
 
-	batocp_reg_code = batocp / BQ25980_BATOCP_STEP_uA;
+	batocp_reg_code = batocp / step;
 
 	ret = regmap_update_bits(bq->regmap, BQ25980_BATOCP,
 				BQ25980_BATOCP_MASK, batocp_reg_code);
@@ -490,10 +524,8 @@ static int bq25980_get_adc_ibus(struct bq25980_device *bq)
 
 	ibus_adc = (ibus_adc_msb << 8) | ibus_adc_lsb;
 
-	if (ibus_adc_msb & BQ25980_ADC_POLARITY_BIT)
-		return ((ibus_adc ^ 0xffff) + 1) * BQ25980_ADC_CURR_STEP_uA;
-
-	return ibus_adc * BQ25980_ADC_CURR_STEP_uA;
+	return (ibus_adc * bq->chip_info->ibus_adc_step) +
+					bq->chip_info->ibus_adc_offset;
 }
 
 static int bq25980_get_adc_vbus(struct bq25980_device *bq)
@@ -512,7 +544,8 @@ static int bq25980_get_adc_vbus(struct bq25980_device *bq)
 
 	vbus_adc = (vbus_adc_msb << 8) | vbus_adc_lsb;
 
-	return vbus_adc * BQ25980_ADC_VOLT_STEP_uV;
+	return (vbus_adc * bq->chip_info->vbus_adc_step) +
+					bq->chip_info->vbus_adc_offset;
 }
 
 static int bq25980_get_ibat_adc(struct bq25980_device *bq)
@@ -531,29 +564,31 @@ static int bq25980_get_ibat_adc(struct bq25980_device *bq)
 
 	ibat_adc = (ibat_adc_msb << 8) | ibat_adc_lsb;
 
-	if (ibat_adc_msb & BQ25980_ADC_POLARITY_BIT)
-		return ((ibat_adc ^ 0xffff) + 1) * BQ25980_ADC_CURR_STEP_uA;
+	ibat_adc = clamp(ibat_adc, BQ25960_ADC_IBAT_MIN_CODE,
+					BQ25960_ADC_IBAT_MAX_CODE);
 
-	return ibat_adc * BQ25980_ADC_CURR_STEP_uA;
+	return (ibat_adc * bq->chip_info->ibat_adc_step) +
+					bq->chip_info->ibat_adc_offset;
 }
 
 static int bq25980_get_adc_vbat(struct bq25980_device *bq)
 {
-	int vsys_adc_lsb, vsys_adc_msb;
-	u16 vsys_adc;
+	int vbat_adc_lsb, vbat_adc_msb;
+	u16 vbat_adc;
 	int ret;
 
-	ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_MSB, &vsys_adc_msb);
+	ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_MSB, &vbat_adc_msb);
 	if (ret)
 		return ret;
 
-	ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_LSB, &vsys_adc_lsb);
+	ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_LSB, &vbat_adc_lsb);
 	if (ret)
 		return ret;
 
-	vsys_adc = (vsys_adc_msb << 8) | vsys_adc_lsb;
+	vbat_adc = (vbat_adc_msb << 8) | vbat_adc_lsb;
 
-	return vsys_adc * BQ25980_ADC_VOLT_STEP_uV;
+	return (vbat_adc * bq->chip_info->vbat_adc_step) +
+					bq->chip_info->vbat_adc_offset;
 }
 
 static int bq25980_get_state(struct bq25980_device *bq,
@@ -984,6 +1019,10 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 		.busocp_sc_max = BQ25980_BUSOCP_SC_MAX_uA,
 		.busocp_byp_max = BQ25980_BUSOCP_BYP_MAX_uA,
 		.busocp_byp_min = BQ25980_BUSOCP_MIN_uA,
+		.busocp_sc_step = BQ25980_BUSOCP_STEP_uA,
+		.busocp_byp_step = BQ25980_BUSOCP_STEP_uA,
+		.busocp_sc_offset = BQ25980_BUSOCP_OFFSET_uA,
+		.busocp_byp_offset = BQ25980_BUSOCP_OFFSET_uA,
 
 		.busovp_sc_def = BQ25980_BUSOVP_DFLT_uV,
 		.busovp_byp_def = BQ25980_BUSOVP_BYPASS_DFLT_uV,
@@ -1004,6 +1043,20 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 
 		.batocp_def = BQ25980_BATOCP_DFLT_uA,
 		.batocp_max = BQ25980_BATOCP_MAX_uA,
+		.batocp_min = BQ25980_BATOCP_MIN_uA,
+		.batocp_step = BQ25980_BATOCP_STEP_uA,
+
+		.vbus_adc_step = BQ25980_ADC_VBUS_STEP_uV,
+		.vbus_adc_offset = BQ25980_ADC_VBUS_OFFSET_uV,
+
+		.ibus_adc_step = BQ25980_ADC_IBUS_STEP_uA,
+		.ibus_adc_offset = BQ25980_ADC_IBUS_OFFSET_uA,
+
+		.vbat_adc_step = BQ25980_ADC_VBAT_STEP_uV,
+		.vbat_adc_offset = BQ25980_ADC_VBAT_OFFSET_uV,
+
+		.ibat_adc_step = BQ25980_ADC_IBAT_STEP_uA,
+		.ibat_adc_offset = BQ25980_ADC_IBAT_OFFSET_uA,
 	},
 
 	[BQ25975] = {
@@ -1015,6 +1068,10 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 		.busocp_sc_max = BQ25975_BUSOCP_SC_MAX_uA,
 		.busocp_byp_min = BQ25980_BUSOCP_MIN_uA,
 		.busocp_byp_max = BQ25975_BUSOCP_BYP_MAX_uA,
+		.busocp_sc_step = BQ25980_BUSOCP_STEP_uA,
+		.busocp_byp_step = BQ25980_BUSOCP_STEP_uA,
+		.busocp_sc_offset = BQ25980_BUSOCP_OFFSET_uA,
+		.busocp_byp_offset = BQ25980_BUSOCP_OFFSET_uA,
 
 		.busovp_sc_def = BQ25975_BUSOVP_DFLT_uV,
 		.busovp_byp_def = BQ25975_BUSOVP_BYPASS_DFLT_uV,
@@ -1035,6 +1092,20 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 
 		.batocp_def = BQ25980_BATOCP_DFLT_uA,
 		.batocp_max = BQ25980_BATOCP_MAX_uA,
+		.batocp_min = BQ25980_BATOCP_MIN_uA,
+		.batocp_step = BQ25980_BATOCP_STEP_uA,
+
+		.vbus_adc_step = BQ25975_ADC_VBUS_STEP_uV,
+		.vbus_adc_offset = BQ25975_ADC_VBUS_OFFSET_uV,
+
+		.ibus_adc_step = BQ25975_ADC_IBUS_STEP_uA,
+		.ibus_adc_offset = BQ25975_ADC_IBUS_OFFSET_uA,
+
+		.vbat_adc_step = BQ25975_ADC_VBAT_STEP_uV,
+		.vbat_adc_offset = BQ25975_ADC_VBAT_OFFSET_uV,
+
+		.ibat_adc_step = BQ25975_ADC_IBAT_STEP_uA,
+		.ibat_adc_offset = BQ25975_ADC_IBAT_OFFSET_uA,
 	},
 
 	[BQ25960] = {
@@ -1042,10 +1113,14 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 		.regmap_config = &bq25960_regmap_config,
 
 		.busocp_def = BQ25960_BUSOCP_DFLT_uA,
-		.busocp_sc_min = BQ25960_BUSOCP_SC_MAX_uA,
+		.busocp_sc_min = BQ25960_BUSOCP_SC_MIN_uA,
 		.busocp_sc_max = BQ25960_BUSOCP_SC_MAX_uA,
-		.busocp_byp_min = BQ25960_BUSOCP_SC_MAX_uA,
+		.busocp_byp_min = BQ25960_BUSOCP_BYP_MIN_uA,
 		.busocp_byp_max = BQ25960_BUSOCP_BYP_MAX_uA,
+		.busocp_sc_step = BQ25960_BUSOCP_SC_STEP_uA,
+		.busocp_byp_step = BQ25960_BUSOCP_BYP_STEP_uA,
+		.busocp_sc_offset = BQ25960_BUSOCP_SC_OFFSET_uA,
+		.busocp_byp_offset = BQ25960_BUSOCP_BYP_OFFSET_uA,
 
 		.busovp_sc_def = BQ25975_BUSOVP_DFLT_uV,
 		.busovp_byp_def = BQ25975_BUSOVP_BYPASS_DFLT_uV,
@@ -1066,6 +1141,20 @@ static const struct bq25980_chip_info bq25980_chip_info_tbl[] = {
 
 		.batocp_def = BQ25960_BATOCP_DFLT_uA,
 		.batocp_max = BQ25960_BATOCP_MAX_uA,
+		.batocp_min = BQ25960_BATOCP_MIN_uA,
+		.batocp_step = BQ25960_BATOCP_STEP_uA,
+
+		.vbus_adc_step = BQ25960_ADC_VBUS_STEP_uV,
+		.vbus_adc_offset = BQ25960_ADC_VBUS_OFFSET_uV,
+
+		.ibus_adc_step = BQ25960_ADC_IBUS_STEP_uA,
+		.ibus_adc_offset = BQ25960_ADC_IBUS_OFFSET_uA,
+
+		.vbat_adc_step = BQ25960_ADC_VBAT_STEP_uV,
+		.vbat_adc_offset = BQ25960_ADC_VBAT_OFFSET_uV,
+
+		.ibat_adc_step = BQ25960_ADC_IBAT_STEP_uA,
+		.ibat_adc_offset = BQ25960_ADC_IBAT_OFFSET_uA,
 	},
 };
 
drivers/power/supply/bq25980_charger.h +58 -19

125 lines not on this page · raw message

Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 2/2 power: supply: bq25980: Move props from battery node

Currently POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE are exposed on the battery node

and this is incorrect.

This patch exposes POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE on the charger node rather

than the battery node.

Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 40 ++++++++------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/power/supply/bq25980_charger.c +12 -28
index 7c489a9e8877..ac73e2c19238 100644
@@ -641,33 +641,6 @@ static int bq25980_get_state(struct bq25980_device *bq,
 	return 0;
 }
 
-static int bq25980_set_battery_property(struct power_supply *psy,
-				enum power_supply_property psp,
-				const union power_supply_propval *val)
-{
-	struct bq25980_device *bq = power_supply_get_drvdata(psy);
-	int ret = 0;
-
-	switch (psp) {
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
-		ret = bq25980_set_const_charge_curr(bq, val->intval);
-		if (ret)
-			return ret;
-		break;
-
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
-		ret = bq25980_set_const_charge_volt(bq, val->intval);
-		if (ret)
-			return ret;
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	return ret;
-}
-
 static int bq25980_get_battery_property(struct power_supply *psy,
 				enum power_supply_property psp,
 				union power_supply_propval *val)
@@ -736,6 +709,18 @@ static int bq25980_set_charger_property(struct power_supply *psy,
 			return ret;
 		break;
 
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+		ret = bq25980_set_const_charge_curr(bq, val->intval);
+		if (ret)
+			return ret;
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
+		ret = bq25980_set_const_charge_volt(bq, val->intval);
+		if (ret)
+			return ret;
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -957,7 +942,6 @@ static struct power_supply_desc bq25980_battery_desc = {
 	.name			= "bq25980-battery",
 	.type			= POWER_SUPPLY_TYPE_BATTERY,
 	.get_property		= bq25980_get_battery_property,
-	.set_property		= bq25980_set_battery_property,
 	.properties		= bq25980_battery_props,
 	.num_properties		= ARRAY_SIZE(bq25980_battery_props),
 	.property_is_writeable	= bq25980_property_is_writeable,
Signature · 1 line
2.30.0
#2 lore raw

Re: [PATCH v2 2/2] power: supply: bq25980: Move props from battery node

Quoted 11 lines · Ricardo Rivera-Matos

Currently POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE are exposed on the battery node

and this is incorrect.

This patch exposes POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE on the charger node rather

than the battery node.

Now it makes sense if you only formatted it in human-readable way. Please fix your git/editor/email client/desktop unless you used such formatting intentionally. If it was intentional, then please don't - do like everyone else in Linux kernel (git log will help).

Best regards,
Krzysztof

Quoted 6 lines
Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 40 ++++++++------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
#3 lore raw

Re: [PATCH v2 2/2] power: supply: bq25980: Move props from battery node

Hi,

Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines · Ricardo Rivera-Matos

Currently POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE are exposed on the battery node and this is incorrect.

Quoted 8 lines
Quoted 3 lines

This patch exposes POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE on the charger node rather than the battery node.

Now it makes sense if you only formatted it in human-readable way. Please fix your git/editor/email client/desktop unless you used such formatting intentionally. If it was intentional, then please don't - do like everyone else in Linux kernel (git log will help).

Thanks, queued to the power-supply tree (I fixed up the broken commit message).

-- Sebastian

Quoted 10 lines

Best regards,
Krzysztof

Quoted 6 lines
Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 40 ++++++++------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
#4 lore raw
In reply to Ricardo Rivera-Matos
Quoted 14 lines · Ricardo Rivera-Matos

The latest datasheet revision for BQ25980, BQ25975, and BQ25960 changed

various register step sizes and offset values.

This patch changes the following header file

values for POWER_SUPPLY_PROP_CURRENT_NOW,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,

POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,

Quoted 7 lines

POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, and POWER_SUPPLY_PROP_VOLTAGE_NOW.

Additionally, this patch adjusts bq25980_get_input_curr_lim(),

bq25980_set_input_curr_lim(), bq25980_get_const_charge_curr(), and

bq25980_set_const_charge_curr() to perform the get/set math correctly.

Your formatting is so odd, it is not readable. Please open "git log" and try to write something similar to existing commits, e.g. without additional blank line between lines.

Quoted 13 lines
Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 141 ++++++++++++++++++++-----
 drivers/power/supply/bq25980_charger.h |  77 ++++++++++----
 2 files changed, 173 insertions(+), 45 deletions(-)
drivers/power/supply/bq25980_charger.c +0 -0
index 530ff4025b31..7c489a9e8877 100644

drivers/power/supply/bq25980_charger.c struct bq25980_chip_info { · line 58

Quoted 7 lines
drivers/power/supply/bq25980_charger.c +4 -0
@@ -52,6 +52,10 @@ struct bq25980_chip_info {
 	int busocp_byp_max;
 	int busocp_sc_min;
 	int busocp_byp_min;
+	int busocp_sc_step;
+	int busocp_byp_step;
+	int busocp_sc_offset;
+	int busocp_byp_offset;

Does not look like related to changing offsets of register values in header.

Quoted 13 lines
drivers/power/supply/bq25980_charger.c +6 -0
 	int busovp_sc_def;
 	int busovp_byp_def;
@@ -73,6 +77,20 @@ struct bq25980_chip_info {
 
 	int batocp_def;
 	int batocp_max;
+	int batocp_min;
+	int batocp_step;
+
+	int vbus_adc_step;
+	int vbus_adc_offset;
+

drivers/power/supply/bq25980_charger.c struct bq25980_chip_info { · line 95

Quoted 10 lines
drivers/power/supply/bq25980_charger.c +8 -0
+	int ibus_adc_step;
+	int ibus_adc_offset;
+
+	int vbat_adc_step;
+	int vbat_adc_offset;
+
+	int ibat_adc_step;
+	int ibat_adc_offset;
 };
 

Does not look like related to changing offsets of register values in header.

Quoted 6 lines
drivers/power/supply/bq25980_charger.c +1 -0
 struct bq25980_init_data {
@@ -275,13 +293,22 @@ static int bq25980_watchdog_time[BQ25980_NUM_WD_VAL] = {5000, 10000, 50000,
 static int bq25980_get_input_curr_lim(struct bq25980_device *bq)
 {
 	unsigned int busocp_reg_code;
+	int offset, step;

drivers/power/supply/bq25980_charger.c static int bq25980_watchdog_time[BQ25980_NUM_WD_VAL] = {5000, 10000, 50000, · line 306

Quoted 10 lines
drivers/power/supply/bq25980_charger.c +8 -0
 	int ret;
 
+	if (bq->state.bypass) {
+		step = bq->chip_info->busocp_byp_step;
+		offset = bq->chip_info->busocp_byp_offset;
+	} else {
+		step = bq->chip_info->busocp_sc_step;
+		offset = bq->chip_info->busocp_sc_offset;
+	}
+

Does not look like related to changing offsets of register values in header.

and so on... Fix one thing at a time.

Best regards,
Krzysztof

#5 lore raw

Hi,

Quoted 19 lines · Krzysztof Kozlowski
Quoted 18 lines · Ricardo Rivera-Matos

The latest datasheet revision for BQ25980, BQ25975, and BQ25960 changed

various register step sizes and offset values.

This patch changes the following header file

values for POWER_SUPPLY_PROP_CURRENT_NOW,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,

POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,

POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,

POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, and POWER_SUPPLY_PROP_VOLTAGE_NOW.

Additionally, this patch adjusts bq25980_get_input_curr_lim(),

Quoted 7 lines
Quoted 3 lines

bq25980_set_input_curr_lim(), bq25980_get_const_charge_curr(), and

bq25980_set_const_charge_curr() to perform the get/set math correctly.

Your formatting is so odd, it is not readable. Please open "git log" and try to write something similar to existing commits, e.g. without additional blank line between lines.

Ack. This is a paint to read.

Quoted 9 lines
Quoted 9 lines
Fixes 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
---
 drivers/power/supply/bq25980_charger.c | 141 ++++++++++++++++++++-----
 drivers/power/supply/bq25980_charger.h |  77 ++++++++++----
 2 files changed, 173 insertions(+), 45 deletions(-)
Quoted 15 lines

drivers/power/supply/bq25980_charger.c struct bq25980_chip_info { · line 58

Quoted 12 lines
drivers/power/supply/bq25980_charger.c +4 -0
index 530ff4025b31..7c489a9e8877 100644
@@ -52,6 +52,10 @@ struct bq25980_chip_info {
 	int busocp_byp_max;
 	int busocp_sc_min;
 	int busocp_byp_min;
+	int busocp_sc_step;
+	int busocp_byp_step;
+	int busocp_sc_offset;
+	int busocp_byp_offset;

Does not look like related to changing offsets of register values in header.

well looking at the change as a whole the problem is that each chip has different offset/step size now. Arguably this is an atomic change. I would have queued it (fixing the commit message while applying), but the patch also does some unrelated changes:

- introduced usage of clamp instead of min()/max() checks (which is great, but should be separate commit!)
- rename variables to something more sensible in bq25980_get_adc_vbat (again a great change, but should be separate commit)

Ricardo, please submit a new version with these changes splitted out.

-- Sebastian