From patchwork Fri Aug 16 08:19:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13765689 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E262AC3DA4A for ; Fri, 16 Aug 2024 08:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qaOD3rKusxi0zQqgiaHpgdf4b2i/F2QB75S2grdzC44=; b=KOiZ36iUrFulSowKGygGPuAMAB nCYYhV7PUGSq3byElUcGCfEtbamIeBmaagg6zh0V6l98IKL/YJiStN0AQoQbEI2uTXJnLHIVScrHr IN3gCyPXwdXTaibHwhIF09pZ2FH5X1tPm8YMX5y+pz1pZMR89pEAQmiOGH3e6V96N8OvNS4NvWe9w QD+GtcS+GGXDg8jRPWk7hUzTixq6w3TDMV1vwpBzSewK7JvPcFekjKGRHVBCQ6arKgQGKEX5nxz2h qeXvLIG3/T1iJ+pzOp41EGVwDGWtfbZqZoODgNsXXKift3ofX+2QPYye5WHvNdpNW4UAAeW7BLX6u dCbHxMew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesFX-0000000CGJy-2LTH; Fri, 16 Aug 2024 08:23:55 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesBD-0000000CF1d-0WwT for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 08:19:28 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-428243f928fso17389095e9.0 for ; Fri, 16 Aug 2024 01:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723796366; x=1724401166; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qaOD3rKusxi0zQqgiaHpgdf4b2i/F2QB75S2grdzC44=; b=DRvSTryuR7hU3i8cr5xHA9Nh0TgfnaG6UKKdUKTYVvS3aJZI2vRH/x+AKNBF2kEqRN j13zualpN+ywoAQpeb7PuZGSfZRmbGU84cah+yABi8kdmTUjVwzIxQhCI/0+hoCX2aaV 9k08WC3IP5367PCHT4mCCW9EiEXiz0CTZW1Sd2jD/VW2Xzub9Wp1K5i13eUk8nqwjQ4z 1wbvC2j71Qbm2nldlFWvTKrQWwHcUfVwLnpHu/9ZwuI25KMCSiRSc6Gc2mnIouhkDZJN XhEFeOuaVQAxv5X1l1IgvflXIPGtZ8iKgPVSJkIgZVZM5j0mbTrb+JvxypXGFApAfAe/ Fn4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723796366; x=1724401166; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qaOD3rKusxi0zQqgiaHpgdf4b2i/F2QB75S2grdzC44=; b=JLYPA1v3kaRWIOMgBCIZSaD3ypF3kRB5PtDSc1Xohc45s2g1GTEaQd4LSmy634jqMk kNey1Iw0ExGT+UYP0TH6XMdqab9qTcpNsjbzwBuu+8Xg68CtliFcDH/kgspYFbgLbmR9 AkizJYBQ1b3aZZoM3hHOOUHX0K59qu41MfhFczt7OHP1vEfZxHNaSJQtTmrYWjPNk5jG fAh+GAm+dMOdDJZ2L461QgQ73n0+UFvdo4KdfXUYxXTVkWA7yVAL5+9jJ585CuPtfpjx qHVCaodh3dfFfNTJADus6ZdXOsRPxuyMa5pghA0bh21Lwh6Zx8GSXtktEDp/gmEyWohs 0ZUw== X-Forwarded-Encrypted: i=1; AJvYcCW/Uv525hNY1GmYoqzoKCJVA0kiorPxI4W2ZE54bOUM86oPpxcPeWdlYg7sHjGsi7qL3427zWA3efL0LlSvUb6KKTBMtVW51dT6q3oqnNcvU50crDE= X-Gm-Message-State: AOJu0YxFBNyXQIrJEMLimtUZHWqWFGDWdvScmAXatzErW/cc4DNXG+B7 7SS0GblmfHyay5+E6Td9aOqHL9RcOZ9+IjDJRx6oK29sTYfAmcpp X-Google-Smtp-Source: AGHT+IGqwtVcXQKNh8O0fbem1eWcZ1w8RFD4cuHCIdxMrfHUkdXEj31Hz43gXqKgPdNZM9R7oJ2C5Q== X-Received: by 2002:a05:600c:1394:b0:426:5f09:cf53 with SMTP id 5b1f17b1804b1-429ed794da8mr14540675e9.15.1723796365560; Fri, 16 Aug 2024 01:19:25 -0700 (PDT) Received: from tablet.my.domain ([37.30.8.221]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded35991sm69732645e9.21.2024.08.16.01.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 01:19:25 -0700 (PDT) From: Artur Weber Date: Fri, 16 Aug 2024 10:19:12 +0200 Subject: [PATCH v4 06/10] power: supply: max77693: Add support for detecting and enabling OTG MIME-Version: 1.0 Message-Id: <20240816-max77693-charger-extcon-v4-6-050a0a9bfea0@gmail.com> References: <20240816-max77693-charger-extcon-v4-0-050a0a9bfea0@gmail.com> In-Reply-To: <20240816-max77693-charger-extcon-v4-0-050a0a9bfea0@gmail.com> To: Krzysztof Kozlowski , Chanwoo Choi Cc: Sebastian Reichel , Rob Herring , Conor Dooley , Lee Jones , Krzysztof Kozlowski , Alim Akhtar , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Henrik Grimler , Wolfgang Wiedmeyer , Denis 'GNUtoo' Carikli , Artur Weber X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4023; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=9tKk8IBY8YUSIH0ECZT8vZVS+bk8IwZ/nsbmqbh0O0A=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmvwt+vqva+BUdawrIWvIhu5Ymj2S8KArA+aJpi ZgwlobFry6JAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZr8LfgAKCRCzu/ihE6BR aI83D/9G8dZ+ucjhexcdplvfoufCG6KhhAaDCFIUp726bzqD5GVi+fZs4B79aN/Mb64+uQ3kLOi 4AGNaVVUYQUQSlbbpSdBVApMt87xdZ0z97SPD2EVICrpnF9fQvPT5eRRC+sMvDyFjt+8zaGFNOr Mry4BHCr/Gg/hWOo0BQf8mNt+Gwx9JJ5vbMUcXu7fZczfJ9Yp8XzuCZXvbR+LFLlql+5mhoFWx3 vajC6Vqelc0EyTG6oDn9tVv2EdDd4MSH0sSQykAl/Ga5xRq+uRERJIp5ghHdIi71AkHBYDN6AeT apQh4kWhFQSKGV4iYBzqwRN1PdTo3gIsfDuZDl4XpWa5ywFUUh2C2LY8RBDsHtc7Fh9a4BpHWfR cE7lFyIovOIkVsPncshvXV66P1yeZ7SVqhVtnIgPonGSLpeunYdngSu5XcWtAcvZoqq5eBuGlpY yikxUEH1zSGpociurXOnBHI0xVv/nXfrlSLu7nhCQJ9ubxpyND3sAsB7Vgt/0qsqcbz6svA8/51 e6kXpVr3VP75rl7dfgu5vffEXRfk7drftWvk1/ukI8b6AZ2cOvLBnG7Gssq3PzEKaKlwV19qu/P M9kfJPQzDHKDFZF+K8ijapLYsahc48JGkO9zbG7TP7dD5u2WypM4GxD9PVF/3c6wOCTQ+PX/ije hy3lLpIabe/i8QQ== X-Developer-Key: i=aweber.kernel@gmail.com; a=openpgp; fpr=E663000EAC1DECCD6AD2890DB3BBF8A113A05168 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_011927_234621_240F8346 X-CRM114-Status: GOOD ( 17.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Building upon the newly added extcon detection support, add detection for USB OTG cables (EXTCON_USB_HOST type), and enable/disable the OTG bits as needed. Acked-by: Lee Jones Tested-by: Henrik Grimler Signed-off-by: Artur Weber --- Changes in v3: - Dropped CHARGER regulator in favor of enabling charging directly Changes in v2: - Added CHGIN OTG current limit value - Squashed MFD header register changes into this commit --- drivers/power/supply/max77693_charger.c | 53 ++++++++++++++++++++++++++------- include/linux/mfd/max77693-private.h | 5 ++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index d67857d2aa0b..bf156544fe1b 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -692,11 +692,30 @@ static int max77693_set_charging(struct max77693_charger *chg, bool enable) data); } +static int max77693_set_otg(struct max77693_charger *chg, bool enable) +{ + unsigned int data; + + if (enable) + data = CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK | + CHG_CNFG_00_DIS_MUIC_CTRL_MASK; + else + data = ~(CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK | + CHG_CNFG_00_DIS_MUIC_CTRL_MASK); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_00, + CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK | + CHG_CNFG_00_DIS_MUIC_CTRL_MASK, + data); +} + static void max77693_charger_extcon_work(struct work_struct *work) { struct max77693_charger *chg = container_of(work, struct max77693_charger, cable.work); struct extcon_dev *edev = chg->cable.edev; + bool set_charging, set_otg; int connector, state; int ret; @@ -715,25 +734,39 @@ static void max77693_charger_extcon_work(struct work_struct *work) case EXTCON_CHG_USB_FAST: case EXTCON_CHG_USB_SLOW: case EXTCON_CHG_USB_PD: - ret = max77693_set_charging(chg, true); - if (ret) { - dev_err(chg->dev, "failed to enable charging\n"); - break; - } + set_charging = true; + set_otg = false; + dev_info(chg->dev, "charging. connector type: %d\n", connector); break; + case EXTCON_USB_HOST: + set_charging = false; + set_otg = true; + + dev_info(chg->dev, "USB host. connector type: %d\n", + connector); + break; default: - ret = max77693_set_charging(chg, false); - if (ret) { - dev_err(chg->dev, "failed to disable charging\n"); - break; - } + set_charging = false; + set_otg = false; + dev_info(chg->dev, "not charging. connector type: %d\n", connector); break; } + ret = max77693_set_charging(chg, set_charging); + if (ret) { + dev_err(chg->dev, "failed to set charging (%d)\n", ret); + goto out; + } + + ret = max77693_set_otg(chg, set_otg); + if (ret) + dev_err(chg->dev, "failed to set OTG (%d)\n", ret); + +out: power_supply_changed(chg->charger); } diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h index 0819cf0a4f5f..1fd93bfbf3dc 100644 --- a/include/linux/mfd/max77693-private.h +++ b/include/linux/mfd/max77693-private.h @@ -209,7 +209,10 @@ enum max77693_charger_battery_state { /* MAX77693 CHG_CNFG_00 register */ #define CHG_CNFG_00_CHG_MASK 0x1 +#define CHG_CNFG_00_OTG_MASK 0x2 #define CHG_CNFG_00_BUCK_MASK 0x4 +#define CHG_CNFG_00_BOOST_MASK 0x8 +#define CHG_CNFG_00_DIS_MUIC_CTRL_MASK 0x20 /* MAX77693_CHG_REG_CHG_CNFG_01 register */ #define CHG_CNFG_01_FCHGTIME_SHIFT 0 @@ -222,6 +225,8 @@ enum max77693_charger_battery_state { /* MAX77693_CHG_REG_CHG_CNFG_02 register */ #define CHG_CNFG_02_CC_SHIFT 0 #define CHG_CNFG_02_CC_MASK 0x3F +#define CHG_CNFG_02_OTG_ILIM_SHIFT 7 +#define CHG_CNFG_02_OTG_ILIM_MASK 0x80 /* MAX77693_CHG_REG_CHG_CNFG_03 register */ #define CHG_CNFG_03_TOITH_SHIFT 0