From patchwork Mon Jul 29 17:47:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13745518 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 B0C82C3DA4A for ; Mon, 29 Jul 2024 17:51:22 +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=VpdY2w7Ol8tWjnklayT84Hbch6eCd/qeKmcHW5pT54o=; b=kRIbcay3hEEPFX+0nUzClTVBdd R/VDNZcNy6wAwV55Mj2XSYu0zlOnkH2bX7+bzsgQ0CGrRM8q9a0GqosqI3BteDPPIt4W9uW528w8q k1D58jWtVHhn01BLZCxJMbPRcWpFLD3flHo2PBJGOwQ7qGJ1OXuhMTGbG34O5voDVUIBLMPWxFSWL J7Dy5VgKhKAYKumJ9SEEgUoJHsUdzo7W+bkZhnhnIDsmj9NQuoyapyAKZqfjXczwCuWsJ6/qErBYP JBT3wFcqws37z4T6TgQ4uM4s0QV+LijxkomWpZbXuO2WaHx+cdVW7sl2ooJRqAhMftStTaJpHvfof ZyGzRg3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUWd-0000000CGKL-2RPG; Mon, 29 Jul 2024 17:51:11 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUTa-0000000CFGQ-2lUt for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 17:48:03 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-427fc97a88cso19492395e9.0 for ; Mon, 29 Jul 2024 10:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722275280; x=1722880080; 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=VpdY2w7Ol8tWjnklayT84Hbch6eCd/qeKmcHW5pT54o=; b=AwJ0hpNhRr1lbtDB6sy4/1zp7652Tz6a7oy8Cq6aD/mkfNE2M8EtkNTjYS+1FMQcIo gLiCNLac6pk8Hm2dPomDopY0Ag7yR8VC+7RSCUnGgtaIii1/2j6zYQ87svMWaaz3P75b sicYIT8c4+loNuLo4947QkVAGTy1czuLc8HrQxTod2QeUOt779AYSESUbbERmaVqdBfg D1HrIAZcxlfiejru48RfeQm7kX+2GFyolYoXH9uEU9s7m468DiSeGkoYky8Uwa3VlFFF MYePeL1grv6hmKVMkEHLcPWRxSVl0HlMNPPWzi6Q+ZUL1bA2jt/VodoNC6Q00evxXQ6s jpVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722275280; x=1722880080; 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=VpdY2w7Ol8tWjnklayT84Hbch6eCd/qeKmcHW5pT54o=; b=qlpmQc19f60K9PAhiVw1w/S1aJIek2agIp4ezflWYW7DeTbwyumQKRPPDBdhf+bsUt G9JaPprZJuO6Njc5HlHHv7740co2WTnuKDCmI1ucJ/efJZOBjtAnn8/mHgWVDAKiy2vC RmnfFjpfmHf8m8gJHFdkMqDnPxPQoUOFIOPxpbZPzUyXchFc/UYUs9VW9uYodKjtRv01 Az/LHiMtzMk3VJfaSUvpnM1e03wMlo+CvMQi4y3c4WlYUG+YW/YXqIKnMkRhd9ienYEz AhPiCi1TtxrnkZGYrHj/uaWmYTbrm2lkqYMoRajf7jt4qTDBWvxOJTZEFBDZOpYJUbuf QuIg== X-Forwarded-Encrypted: i=1; AJvYcCUWteSaIpf2vRJqG34wLqIvrIGQi22uIER232f+piq+UbLc2PZyt6HkFqwjKh0QlLFDCQVu8p5mnqdN27oEim7ZPq+zutjFn4XRiq7QAzEpaF6h2Jg= X-Gm-Message-State: AOJu0Yxiw56mFefXV9FzBrzzuma1By/MWCvlhSDY55u+gTLYsmT6HjOK HQQ1Jd6SDzedFKvyGd6e1rFAXW/TslU0a3PdV/flzmNTdSLV5yPW X-Google-Smtp-Source: AGHT+IG/etUYMRG6EQg3R1Ca5UxAVuYa4JhLhQk6wFKPKMSpy23CLMxyZ6mlKsFnXrd8dFDFYq+WEA== X-Received: by 2002:a05:6000:bc8:b0:368:7883:d14a with SMTP id ffacd0b85a97d-36b5d0444c5mr5780214f8f.33.1722275280385; Mon, 29 Jul 2024 10:48:00 -0700 (PDT) Received: from tablet.my.domain ([37.30.0.99]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm12716550f8f.59.2024.07.29.10.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 10:48:00 -0700 (PDT) From: Artur Weber Date: Mon, 29 Jul 2024 19:47:41 +0200 Subject: [PATCH v3 07/10] power: supply: max77693: Set up charge/input current according to cable type MIME-Version: 1.0 Message-Id: <20240729-max77693-charger-extcon-v3-7-02315a6869d4@gmail.com> References: <20240729-max77693-charger-extcon-v3-0-02315a6869d4@gmail.com> In-Reply-To: <20240729-max77693-charger-extcon-v3-0-02315a6869d4@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=2747; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=tNiZCBQ9vI1N19lL0qdAjIhq26icJW5eSTf6NBMnkgo=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmp9W/eTAFqhVcvrxPcQ+i1t+kITIAHn3E7QU9A CeM1wmLctSJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZqfVvwAKCRCzu/ihE6BR aDvyD/wNx5ko3xSL7orlI3cGVCD7U32mrcClUQ68x7NQswffpG0Xf42NfKJ8oRTLad7pBGhNMBS VeljVGA0BFvNoydBZEcxuoQok5SaS0V/dQCQfCYNmy7HskdQ98iyLl2GJnjKsumqHGpvmUnLgoA GoDSfu9hYvLNIfySqjyTdA7l7+FGS9o90jhszRGoyA/z66fhIvaz45oNM1nzWTBiIsTRjh2KPS7 7+0HIiFDBwO5z88Xc4dMYZNDg/T4lWImqom440DIcBexUlI7QYYHywaY/sb48GmZaYfj6To/o+T V/MwFb/7YCAVhfGJ9Ks/tS92cKe6MNanINbFKJpRPIdA4dByoe9PDg5KHauA5yONue1JWIKPHuk uD36E1hP38Vqgpg3JexTR0ftothf6Skw2U7EVNM1rpQuIMHg5rtKly0pQb1Y+xmcpJmxfxxZ4E+ y33Gcwt6y6Y36cnKrCAKTYvDL8Q/TfNlKncnbhWpy4s1eAXwRdonGlfUWvANnYmVApYkflTBo6E R8r0JOQ8PwZYUvg7iIWtQMU9cSX823LV2P5JIzH7A3KoqxBdRg66NXl9+HTEwNcpp/tJIzSutdd BZ835HurQGvaCglBdfyT0eOQOQw9DBHqKC1ezht/u50LgujCzsMox/GoaqUVN5jv2/QqdeM8C3t luoi1jeXZvpb48w== 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-20240729_104802_737256_016CDC64 X-CRM114-Status: GOOD ( 15.97 ) 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. 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 4ff402941d72..a3aeaba77309 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);