diff mbox series

power: supply: axp288-charger: Set Vhold to 4.4V

Message ID 20220208125147.512145-1-hdegoede@redhat.com
State Accepted
Commit 5ac121b81b4051e7fc83d5b3456a5e499d5bd147
Headers show
Series power: supply: axp288-charger: Set Vhold to 4.4V | expand

Commit Message

Hans de Goede Feb. 8, 2022, 12:51 p.m. UTC
The AXP288's recommended and factory default Vhold value (minimum
input voltage below which the input current draw will be reduced)
is 4.4V. This lines up with other charger IC's such as the TI
bq2419x/bq2429x series which use 4.36V or 4.44V.

For some reason some BIOS-es initialize Vhold to 4.6V or even 4.7V
which combined with the typical voltage drop over typically low
wire gauge micro-USB cables leads to the input-current getting
capped below 1A (with a 2A capable dedicated charger) based on Vhold.

This leads to slow charging, or even to the device slowly discharging
if the device is in heavy use.

As the Linux AXP288 drivers use the builtin BC1.2 charger detection
and send the input-current-limit according to the detected charger
there really is no reason not to use the recommended 4.4V Vhold.

Set Vhold to 4.4V to fix the slow charging issue on various devices.

There is one exception, the special-case of the HP X2 2-in-1s which
combine this BC1.2 capable PMIC with a Type-C port and a 5V/3A factory
provided charger with a Type-C plug which does not do BC1.2. These
have their input-current-limit hardcoded to 3A (like under Windows)
and use a higher Vhold on purpose to limit the current when used
with other chargers. To avoid touching Vhold on these HP X2 laptops
the code setting Vhold is added to an else branch of the if checking
for these models.

Note this also fixes the sofar unused VBUS_ISPOUT_VHOLD_SET_MASK
define, which was wrong.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/supply/axp288_charger.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Sebastian Reichel Feb. 11, 2022, 8:55 p.m. UTC | #1
Hi,

On Tue, Feb 08, 2022 at 01:51:47PM +0100, Hans de Goede wrote:
> The AXP288's recommended and factory default Vhold value (minimum
> input voltage below which the input current draw will be reduced)
> is 4.4V. This lines up with other charger IC's such as the TI
> bq2419x/bq2429x series which use 4.36V or 4.44V.
> 
> For some reason some BIOS-es initialize Vhold to 4.6V or even 4.7V
> which combined with the typical voltage drop over typically low
> wire gauge micro-USB cables leads to the input-current getting
> capped below 1A (with a 2A capable dedicated charger) based on Vhold.
> 
> This leads to slow charging, or even to the device slowly discharging
> if the device is in heavy use.
> 
> As the Linux AXP288 drivers use the builtin BC1.2 charger detection
> and send the input-current-limit according to the detected charger
> there really is no reason not to use the recommended 4.4V Vhold.
> 
> Set Vhold to 4.4V to fix the slow charging issue on various devices.
> 
> There is one exception, the special-case of the HP X2 2-in-1s which
> combine this BC1.2 capable PMIC with a Type-C port and a 5V/3A factory
> provided charger with a Type-C plug which does not do BC1.2. These
> have their input-current-limit hardcoded to 3A (like under Windows)
> and use a higher Vhold on purpose to limit the current when used
> with other chargers. To avoid touching Vhold on these HP X2 laptops
> the code setting Vhold is added to an else branch of the if checking
> for these models.
> 
> Note this also fixes the sofar unused VBUS_ISPOUT_VHOLD_SET_MASK
> define, which was wrong.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/axp288_charger.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/power/supply/axp288_charger.c b/drivers/power/supply/axp288_charger.c
> index ec41f6cd3f93..c498e62ab4e2 100644
> --- a/drivers/power/supply/axp288_charger.c
> +++ b/drivers/power/supply/axp288_charger.c
> @@ -42,11 +42,11 @@
>  #define VBUS_ISPOUT_CUR_LIM_1500MA	0x1	/* 1500mA */
>  #define VBUS_ISPOUT_CUR_LIM_2000MA	0x2	/* 2000mA */
>  #define VBUS_ISPOUT_CUR_NO_LIM		0x3	/* 2500mA */
> -#define VBUS_ISPOUT_VHOLD_SET_MASK	0x31
> +#define VBUS_ISPOUT_VHOLD_SET_MASK	0x38
>  #define VBUS_ISPOUT_VHOLD_SET_BIT_POS	0x3
>  #define VBUS_ISPOUT_VHOLD_SET_OFFSET	4000	/* 4000mV */
>  #define VBUS_ISPOUT_VHOLD_SET_LSB_RES	100	/* 100mV */
> -#define VBUS_ISPOUT_VHOLD_SET_4300MV	0x3	/* 4300mV */
> +#define VBUS_ISPOUT_VHOLD_SET_4400MV	0x4	/* 4400mV */
>  #define VBUS_ISPOUT_VBUS_PATH_DIS	BIT(7)
>  
>  #define CHRG_CCCV_CC_MASK		0xf		/* 4 bits */
> @@ -769,6 +769,16 @@ static int charger_init_hw_regs(struct axp288_chrg_info *info)
>  		ret = axp288_charger_vbus_path_select(info, true);
>  		if (ret < 0)
>  			return ret;
> +	} else {
> +		/* Set Vhold to the factory default / recommended 4.4V */
> +		val = VBUS_ISPOUT_VHOLD_SET_4400MV << VBUS_ISPOUT_VHOLD_SET_BIT_POS;
> +		ret = regmap_update_bits(info->regmap, AXP20X_VBUS_IPSOUT_MGMT,
> +					 VBUS_ISPOUT_VHOLD_SET_MASK, val);
> +		if (ret < 0) {
> +			dev_err(&info->pdev->dev, "register(%x) write error(%d)\n",
> +				AXP20X_VBUS_IPSOUT_MGMT, ret);
> +			return ret;
> +		}
>  	}
>  
>  	/* Read current charge voltage and current limit */
> -- 
> 2.33.1
>
diff mbox series

Patch

diff --git a/drivers/power/supply/axp288_charger.c b/drivers/power/supply/axp288_charger.c
index ec41f6cd3f93..c498e62ab4e2 100644
--- a/drivers/power/supply/axp288_charger.c
+++ b/drivers/power/supply/axp288_charger.c
@@ -42,11 +42,11 @@ 
 #define VBUS_ISPOUT_CUR_LIM_1500MA	0x1	/* 1500mA */
 #define VBUS_ISPOUT_CUR_LIM_2000MA	0x2	/* 2000mA */
 #define VBUS_ISPOUT_CUR_NO_LIM		0x3	/* 2500mA */
-#define VBUS_ISPOUT_VHOLD_SET_MASK	0x31
+#define VBUS_ISPOUT_VHOLD_SET_MASK	0x38
 #define VBUS_ISPOUT_VHOLD_SET_BIT_POS	0x3
 #define VBUS_ISPOUT_VHOLD_SET_OFFSET	4000	/* 4000mV */
 #define VBUS_ISPOUT_VHOLD_SET_LSB_RES	100	/* 100mV */
-#define VBUS_ISPOUT_VHOLD_SET_4300MV	0x3	/* 4300mV */
+#define VBUS_ISPOUT_VHOLD_SET_4400MV	0x4	/* 4400mV */
 #define VBUS_ISPOUT_VBUS_PATH_DIS	BIT(7)
 
 #define CHRG_CCCV_CC_MASK		0xf		/* 4 bits */
@@ -769,6 +769,16 @@  static int charger_init_hw_regs(struct axp288_chrg_info *info)
 		ret = axp288_charger_vbus_path_select(info, true);
 		if (ret < 0)
 			return ret;
+	} else {
+		/* Set Vhold to the factory default / recommended 4.4V */
+		val = VBUS_ISPOUT_VHOLD_SET_4400MV << VBUS_ISPOUT_VHOLD_SET_BIT_POS;
+		ret = regmap_update_bits(info->regmap, AXP20X_VBUS_IPSOUT_MGMT,
+					 VBUS_ISPOUT_VHOLD_SET_MASK, val);
+		if (ret < 0) {
+			dev_err(&info->pdev->dev, "register(%x) write error(%d)\n",
+				AXP20X_VBUS_IPSOUT_MGMT, ret);
+			return ret;
+		}
 	}
 
 	/* Read current charge voltage and current limit */