From patchwork Fri Aug 16 08:19:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13765690 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 BB72CC531DC for ; Fri, 16 Aug 2024 08:24:48 +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=vXcN+4MSX/QcUPqVj1wMQhGhi1WKb399yNI1f64c3To=; b=jwXT9gJ03HuoSq4MoHEqTjPoXw P2OF2UCH2JLGWB/V7uMaeAm8hRBH289ykFYVEkI5lDTEICFX76oML7V1I02QWFmLrgtqliLZFj0Bf foOYdE8jQ1VyYpSMYSWBXiWQoVk/13TflCRszG/JHBA1lYuPNnnn86wxebRADvJ25H+sbZPyf2+wN CjywmQiEIcIl+KEoIvXyYhe0uVPzaOhEaYWuo8rMvNK+7V5dvPIMy+M1ger9Grv4xnXQDXuCOfajI XggEJ2aeVgkoBv2rH4T4/2tko8quuLBW287tx5froG7U3gzLGVggldeZUlp/FdbWB5gk3zL697XeJ SBlT+rqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesG9-0000000CGSo-13dX; Fri, 16 Aug 2024 08:24:33 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesBF-0000000CF2X-1Fjd for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 08:19:30 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-428e3129851so12417505e9.3 for ; Fri, 16 Aug 2024 01:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723796368; x=1724401168; 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=vXcN+4MSX/QcUPqVj1wMQhGhi1WKb399yNI1f64c3To=; b=nEbx4ZXnpw86v4ny6oCcwuJt1Q4kgsFwJDwfEGFTeyy1FWtAD5qjTib8f9TUUAAveD UpESvLvUFyDJVe/Vdc2xN1dtg20yXl/41pnqPHddArHBWvqNCp7Tp69dpLR1avBxMa01 xW8h7pJs2uGENmwY8RKYKiu8YLOvb+aZlr2vx93bSd/MJN8JKXzkH1p37X+6NtywAeYn pZfWl2CPFC1HCK9e+Zo2Zj4K0wEkMCPuTi88AcbeFGkebeZqGprrtYmKQdO2bWJ0syC+ xwa+sQ42R2MsPddoCklfWN6lvJtQgGGWdCIIjceP9NWWyiP8jouRbo91lSoBDxzqfCqI HhbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723796368; x=1724401168; 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=vXcN+4MSX/QcUPqVj1wMQhGhi1WKb399yNI1f64c3To=; b=Hd0llqvVK23aroC5s1TkA+3BVTh92cddCCI3WbveoJWkMShSD+nYzo4KCSzpkA2Ggw cHjDh5UWqmpBF0C+tOENZqDE6XQUmpQk7+a7zAzOJC/MATkmuBo5T/FfHiu8DhuxokDe qBoLJmSXP6iXwoR92si+oFdP3c07h86tqkmePhf1rBVVbwE43FH5SDJuhpw+zNrRWDC7 4qEgoWahlR+UnWzcmJYC3aFGQPdHdGpIYaNKTRjfIV+MoCCLH1NgYnE9OoF56MSjXuKS ffswGvNuKVMvC/mL8Sbqbfd9bBJwy7kInr9LsqYcsuMOLWAc29WRyj4Ob5v/0JPfbI6l 5UeA== X-Forwarded-Encrypted: i=1; AJvYcCW4MGMC0C2pBh68tSeIv0N1XI2Pt2gFRvl6hG/GUqOZLZDVUvRdtxf9hEovIaUfrfGAdYqygXx3hbi7acGCB4be+3MVet9myVj9lohA1fjjJKuIeaY= X-Gm-Message-State: AOJu0YxBQVYlLY0uHjtVazephdRuf3itwyJ5TqLGjyagqbIGNV6XYfmB NH6p7JIZ5sPlzC38bv3TBilmeWe74+c5hjED1JUS53XvU++U4Jig X-Google-Smtp-Source: AGHT+IHcp7XnLYvNLhbNQnLEg3KjGHkjXNOAnHLq2tZHnyLDVXPWGzMQ/tM7Ng9t/D3Pn35IE9GwdQ== X-Received: by 2002:a05:600c:3c9e:b0:427:98b4:624b with SMTP id 5b1f17b1804b1-429ed7e4314mr13528225e9.24.1723796367650; Fri, 16 Aug 2024 01:19:27 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 01:19:27 -0700 (PDT) From: Artur Weber Date: Fri, 16 Aug 2024 10:19:13 +0200 Subject: [PATCH v4 07/10] power: supply: max77693: Set up charge/input current according to cable type MIME-Version: 1.0 Message-Id: <20240816-max77693-charger-extcon-v4-7-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=2794; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=OEUMcNEwb5KpCYbBVGa/9sqAXNJSzG3pMkHYL8I03Hs=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmvwt+pTyoecftSlWocNm7S26aezVV4rEMO+uPW 6mo/bs4DKKJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZr8LfgAKCRCzu/ihE6BR aPA9EACUf+9CzArgSMlfX70XD47zElr1ycVHjU3iVpni38eeLaboCWaOWLue0lUp8vJc+z72T2A l73u4b4NAsTtECVS7yt5TGx351I4glu00VE0m6+3Ia10dPOos/IEcl7fgYYcZbwusGlqBdOUs8P 0Vpox3q33iJTI51mwM1TULoUkJ0cC8j1P/Ca7WCL8/+G0j9cUBI7PY2+nz1aYKqhLuJ2LsTGFz/ eDRZVBkC9uAeG93rfr9m4+HCmtFs7EjNrCa64aIjJb92JNeuDGXs+N8De/pA7BQ7V9/BdnJ1FAk eMp5Oeddtnipbd/1xRH6Gk+yBWHaY6wZTITPnqxhvkT+SjK2D9ItoVZ6jvNbWn7ml+BT9HmXFPV Os4WUQ7otla0t2IiYWVlMMp1UQ6XaYDCNMEQX9IYf124mMhJIXAc1iJnFt//SwG3Cdx7e5KOhiZ vMNRJhz779zLSo+/LpCXFL4Pr8URHMfDDnZHgX+EW9e3Ay0YkBl76+pV6iar8s6DZ/ka6C4SRpf 4LMmudret0Nn/sogjbBkLJl1s6aiGOTT5xi9P5QrzjuhbfOB1dKd90HtlEEZQGVsz5zGAxP3WIm /dTutI6AoeolshZSPXSwh6W25o9Yy2a9FzVeO6uMv96T+JfDOQMRMFssG2SizCy5AAvwFZZbwGA W80OZ31JEeXliRQ== 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_011929_379875_29B3AF1F X-CRM114-Status: GOOD ( 15.84 ) 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 This behavior was observed on a downstream kernel - for chargers, the current would be set to a fast charge current value, and it would be bumped down for all other cable types. If we leave only the fast charge current value applied, peripheral mode stops working. If we stick to 500mA, charging becomes too slow. So, set the charge input current limit accordingly to the cable type. Tested-by: Henrik Grimler Signed-off-by: Artur Weber --- Changes in v3: - Re-introduced this commit from v1. It seems to have been accidentally rolled into the previous commit in v2. --- drivers/power/supply/max77693_charger.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index bf156544fe1b..908fd2a178ee 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -716,6 +716,7 @@ static void max77693_charger_extcon_work(struct work_struct *work) cable.work); struct extcon_dev *edev = chg->cable.edev; bool set_charging, set_otg; + unsigned int input_current; int connector, state; int ret; @@ -728,19 +729,28 @@ static void max77693_charger_extcon_work(struct work_struct *work) switch (connector) { case EXTCON_CHG_USB_SDP: - case EXTCON_CHG_USB_DCP: case EXTCON_CHG_USB_CDP: + case EXTCON_CHG_USB_SLOW: + input_current = 500000; /* 500 mA */ + set_charging = true; + set_otg = false; + + dev_info(chg->dev, "slow charging. connector type: %d\n", + connector); + break; + case EXTCON_CHG_USB_DCP: case EXTCON_CHG_USB_ACA: case EXTCON_CHG_USB_FAST: - case EXTCON_CHG_USB_SLOW: case EXTCON_CHG_USB_PD: + input_current = chg->fast_charge_current; set_charging = true; set_otg = false; - dev_info(chg->dev, "charging. connector type: %d\n", + dev_info(chg->dev, "fast charging. connector type: %d\n", connector); break; case EXTCON_USB_HOST: + input_current = 500000; /* 500 mA */ set_charging = false; set_otg = true; @@ -748,6 +758,7 @@ static void max77693_charger_extcon_work(struct work_struct *work) connector); break; default: + input_current = 500000; /* 500 mA */ set_charging = false; set_otg = false; @@ -756,6 +767,12 @@ static void max77693_charger_extcon_work(struct work_struct *work) break; } + ret = max77693_set_input_current_limit(chg, input_current); + if (ret) { + dev_err(chg->dev, "failed to set input current (%d)\n", ret); + goto out; + } + ret = max77693_set_charging(chg, set_charging); if (ret) { dev_err(chg->dev, "failed to set charging (%d)\n", ret);