[PATCH 08/10] power: supply: rt5033_charger: Make use of high impedance mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Enable high impedance mode to reduce power consumption. However, it needs to be
disabled in case of charging or OTG mode.

Tested-by: Raymond Hackley <raymondhackley@xxxxxxxxxxxxxx>
Signed-off-by: Jakob Hauser <jahau@xxxxxxxxxxxxxx>
---
 drivers/power/supply/rt5033_charger.c | 47 ++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c
index 79e7f75fe634..ab406fc9fa19 100644
--- a/drivers/power/supply/rt5033_charger.c
+++ b/drivers/power/supply/rt5033_charger.c
@@ -298,6 +298,17 @@ static int rt5033_charger_reg_init(struct rt5033_charger *charger)
 		return -EINVAL;
 	}
 
+	/*
+	 * Enable high impedance mode. It stops charging or boosting and
+	 * operates at a low current sinking to reduce power consumption.
+	 */
+	ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1,
+			RT5033_CHGCTRL1_HZ_MASK, RT5033_CHARGER_HZ_ENABLE);
+	if (ret) {
+		dev_err(charger->dev, "Failed to enable high impedance mode.\n");
+		return -EINVAL;
+	}
+
 	ret = rt5033_init_pre_charge(charger);
 	if (ret)
 		return ret;
@@ -319,6 +330,14 @@ static int rt5033_charger_set_otg(struct rt5033_charger *charger)
 
 	mutex_lock(&charger->lock);
 
+	/* Disable high impedance mode to allow OTG mode */
+	ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1,
+			RT5033_CHGCTRL1_HZ_MASK, RT5033_CHARGER_HZ_DISABLE);
+	if (ret) {
+		dev_err(charger->dev, "Failed to disable high impedance mode.\n");
+		return -EINVAL;
+	}
+
 	/* Set OTG boost v_out to 5 volts */
 	ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL2,
 			RT5033_CHGCTRL2_CV_MASK,
@@ -381,6 +400,14 @@ static int rt5033_charger_set_charging(struct rt5033_charger *charger)
 
 	mutex_lock(&charger->lock);
 
+	/* Disable high impedance mode to allow charging mode */
+	ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1,
+			RT5033_CHGCTRL1_HZ_MASK, RT5033_CHARGER_HZ_DISABLE);
+	if (ret) {
+		dev_err(charger->dev, "Failed to disable high impedance mode.\n");
+		return -EINVAL;
+	}
+
 	/* In case someone switched from OTG to charging directly */
 	if (charger->otg) {
 		ret = rt5033_charger_unset_otg(charger);
@@ -431,6 +458,14 @@ static int rt5033_charger_set_disconnect(struct rt5033_charger *charger)
 
 	mutex_lock(&charger->lock);
 
+	/* Enable high impedance mode to reduce power consumption */
+	ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1,
+			RT5033_CHGCTRL1_HZ_MASK, RT5033_CHARGER_HZ_ENABLE);
+	if (ret) {
+		dev_err(charger->dev, "Failed to enable high impedance mode.\n");
+		return -EINVAL;
+	}
+
 	/* Disable MIVR if enabled */
 	if (charger->mivr_enabled) {
 		ret = regmap_update_bits(charger->rt5033->regmap,
@@ -671,11 +706,21 @@ static int rt5033_charger_probe(struct platform_device *pdev)
 
 	/*
 	 * Extcon support is not vital for the charger to work. If no extcon
-	 * is available, just emit a warning and leave the probe function.
+	 * is available, just emit a warning, disable high impedance mode and
+	 * leave the probe function.
 	 */
 	charger->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
 	if (IS_ERR(charger->edev)) {
 		dev_warn(&pdev->dev, "no extcon phandle found in device-tree\n");
+		ret = regmap_update_bits(charger->rt5033->regmap,
+					 RT5033_REG_CHG_CTRL1,
+					 RT5033_CHGCTRL1_HZ_MASK,
+					 RT5033_CHARGER_HZ_DISABLE);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to disable high impedance mode.\n");
+			return -EINVAL;
+		}
 		goto out;
 	}
 
-- 
2.39.1




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux