Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEF80C64EC7 for ; Tue, 28 Feb 2023 22:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjB1WjJ (ORCPT ); Tue, 28 Feb 2023 17:39:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjB1Wi7 (ORCPT ); Tue, 28 Feb 2023 17:38:59 -0500 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30CD1B326 for ; Tue, 28 Feb 2023 14:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1677623932; bh=KKArGEApjXBYAg0J0GNZwOaNh+WdVYCjGHfCqBUChNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=AWhW/jcbkzQdWr6roCxW88m/xDQMAJFmeVvtfsG8xnVsx76k3wZkEaKa2KmngLUav2yRH/uxAXIqoO0cUpdRpB1yBCg6dRPUStwlf/xpju/BdmudRibsFp9mHFIl55/L7TbtLJeGuITkBfO8Qx6MO+TV3Gf0ukMs3/YeFMH+jeT7YGrFCzTzgk5ni4obId+6T1u5WYh1l6GLsK23T/Vuo4g/+LpClnq5gHyaGEw5CgDKznSTXvnhzGwqr4za4pJlUJv2KKYJsMGHxfded1qDr4DcH/T/BuftAV63tu4fGWFUik0riSMFhyLVSFZBnNKcBPM2clh9RCwEpGoQs3pAOA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.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XXuxks9HV.12U O4LIY_sw8EcOz4.04MGYCT7S8PF2AKU3eAeyvQ58Gn2yx6UBbHKzOSo9lmerIZceilryOwS0XLaB WqSs8_Ar8PKAaOhHgZfGaOuSgaLKEDKnTM_iSyD.TDyXETmKY1dYf3v5Zni5rHMdwppxMCGey1ak wu49xeIAZqbSsdwNHK2J6i.O9imRZ3XA3TXjx1B91FTIheYraniXdY3GkWjlqfOYbJ1.XYn2BNwG Y8e8NFY3qB3o1E_h4V3fFncvGeI6fKpt8pQ2gZ30DBWEUK4u9oMdFDGBWIGNvA9d0.LwbhZtUank a5DS7VgJY1X8bRZwvchY7QlCt04oyhNgyqVFOQNUnOImOkR.xH.2gwsmk52mZ8dLcU58YdXFWTIh Qwicyvd77O7tU6Coz7YGECD_.LqPTVkh.f4AQcuhIX48RW5MhoyT48tXhm7XNBA_IvbgqA.Jm8NG zZj0IsCULZmAmc7FBfKG9_cfx78w61UWV2nnv7FhZG_zs_BIUIAKIV6rAWbOzMrUzII4tdTjGmWb CDczKLKp.ixTRfHiMnYL37xuG8_5yVrJhuCUIXgC.3xP7zWBXCoEI2JePd_6mWdhcP4I0n9Cxf4v 6y2mq9i7qJrkQ8qvcVJEOVcyF.swW6x2z3.VmkBZlBifMGf65bg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Tue, 28 Feb 2023 22:38:52 +0000 Received: by hermes--production-ir2-65c64dfd66-svnc4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1052c26ec2388683ab738a7f87fce466; Tue, 28 Feb 2023 22:38:49 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH 08/10] power: supply: rt5033_charger: Make use of high impedance mode Date: Tue, 28 Feb 2023 23:32:25 +0100 Message-Id: <6b474e64f752ca6802dfb0bfc5571eb1adad8449.1677620677.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jakob Hauser --- 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