From patchwork Thu May 30 08:55:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13679978 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 77A29C25B78 for ; Thu, 30 May 2024 08:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :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=3P+2MdYXLgL24yJC+Q6vE4E8xge5ppS6umvn4t1wg0M=; b=ZrdRLluFJUl1jS EVS0vp6kJcGthW6W+hXXXRE7/uvEJ0zL9SKQSPtr8xQQFD8Zu+L8EKW54zMwkWZaPwo02/naqarPa KTGDwVwabR/8Ngl6nyNWi53ZeuPMTsbBD0COH35Ap7QNcT32DA6o502TlzBdvm3gacVEZn5j+NkOb xvp9x2KCtEh4nihDrrOOlv808KKnlgxzZ8tYZGzhZLwNrZT+NZwepYniEMS1PMBNCRwPYT2thG5Nk RlkaD1B6IYTH7vLxdlpq2nBIh50axKRlk8K3Kn/cm6ckNg/edbPhv+/yZmjTgl9ZNvzwdRnx0zXPZ Ln0OLv5DEf+rv8NQPNgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCbbI-00000006i2N-1qkg; Thu, 30 May 2024 08:57:32 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCbaR-00000006hbh-2tI0 for linux-arm-kernel@lists.infradead.org; Thu, 30 May 2024 08:56:41 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52b7a3c19b0so624731e87.3 for ; Thu, 30 May 2024 01:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717059398; x=1717664198; 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=8DVL7HMaLdGimcENmoBF+IUgjRnKXHAyyw7ouZ5rrWU=; b=OeDOL9FSpwHBdRkvIsyHQ7RxdQNVAfSGuLpTsCEpnTrl1ji1xGug8iuCv0rpv4rNaY AMr5lgjaD438LIxJnkNYOUzqSjUngfzK5tYSo/q1qu0+WIH0BmRUuGZvF2ENoMsq8cyG WMj2K17DjRHbDSs0JIn+JOqNmJeh/osLgU5r6eoofEI9cgsyLsgWqb2I59LU+qjFE8Uc n+NiSidfzR2jy//syaTICsO6PBH8OmYCPrHaTxpG/mBnc1McLz6Bz7igWK3apeQ7QhrD tzWehjJQIftYKjWdssjQyBK/0hUaCURZ77fQz6c/IYvQqe2s2LzW0WxeuEeDLTx3H8wy vYHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717059398; x=1717664198; 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=8DVL7HMaLdGimcENmoBF+IUgjRnKXHAyyw7ouZ5rrWU=; b=jH1201fYjBEb2ZlbpNc+F8MrCve4I6HGGuLbtFVIXprl355Xyx/3IlMrg4keKuZZyo wSFfynmv+EJV09nZw6kNrwvLyjfR0orBx8aS28/c2mSEBPK+aC4DlC7MDRgdA3sfNE9Y UMYP9TZE8PS1nXx1mVCGf02I5xeOTEKuXsdR5qDL+zf2ELAlnvQImVl2u/Mzf/Lm2pMv FLCfdlIIguWINTuENAFgGteK3CZ5rYEyDogXRjTNAW63Fv2DKKKFAyDmSrZtmaALefV1 vx0hUEWECnenMr+ZznWjeaRq0S2YfDSJUkt3wKUHJpYQpRcAexgf/YoidlDIpbJKv9F0 z1VA== X-Forwarded-Encrypted: i=1; AJvYcCWvJUMUYC7sJkk2OyopyWGoTKfsGKxex7cD/UyhP6IJCPwz6n61kFjDIwvz+92XDm/kwaDhhOeWQPsTJ00LrCcOLvNQHln675YvNzvCwhQA5oIq9Js= X-Gm-Message-State: AOJu0YxMKA6wxv8XXCfIwGaenODs1gkLGL1kg9dt6KBjU75gUMA+Nv2A pvxIzcQucVoeMCVix3t1XoeAA8k9ySh3doxnRRCb9pc2rb2RNA+O X-Google-Smtp-Source: AGHT+IFTjYlQv7nU3izoblFm7KSETkxELCqItOAh1GiFE325pUNk9/sXgkbtI+fA8666ss/SUq+7Mg== X-Received: by 2002:ac2:48b3:0:b0:52a:9db1:9d7a with SMTP id 2adb3069b0e04-52b7d48e0f0mr947365e87.58.1717059397940; Thu, 30 May 2024 01:56:37 -0700 (PDT) Received: from hex.my.domain (83.8.128.191.ipv4.supernova.orange.pl. [83.8.128.191]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626cc500a1sm798430166b.125.2024.05.30.01.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:56:37 -0700 (PDT) From: Artur Weber Date: Thu, 30 May 2024 10:55:59 +0200 Subject: [PATCH RFC 09/11] power: supply: max77693: Set up charge/input current according to cable type MIME-Version: 1.0 Message-Id: <20240530-max77693-charger-extcon-v1-9-dc2a9e5bdf30@gmail.com> References: <20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@gmail.com> In-Reply-To: <20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@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.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717059384; l=3617; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=bu/D7bMK1QFCZGMzfQmpKpoYUdwQ8o3XZkg5O1eFV1U=; b=dN1Vyib5+v40zVBQAXRIRNpvfeNVaScau4zaQVfODXVKPuwbfQ2kYHfUVagNu2vj924k+RYYV 0064bxnp3XVDKfVveClxYOyfb363quWai75IRNCdcxJ614xDPFpSopX X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240530_015639_882931_A828F7EB X-CRM114-Status: GOOD ( 17.55 ) 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 --- drivers/power/supply/max77693_charger.c | 35 ++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index e548fd420e78..76e08775f796 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -711,6 +711,10 @@ static int max77693_reg_init(struct max77693_charger *chg) if (ret) return ret; + /* + * Set it to a lower value by default; the DT fast charge current + * property is applied later, in the charger detection mechanism. + */ ret = max77693_set_input_current_limit(chg, DEFAULT_FAST_CHARGE_CURRENT); if (ret) @@ -772,6 +776,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; @@ -784,19 +789,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; @@ -804,6 +818,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; @@ -812,10 +827,12 @@ static void max77693_charger_extcon_work(struct work_struct *work) break; } - /* - * The functions below already check if the change is necessary, - * so we don't need to do so here. - */ + 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); @@ -887,6 +904,10 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg) &chg->batttery_overcurrent)) chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT; + if (of_property_read_u32(np, "maxim,fast-charge-current-microamp", + &chg->fast_charge_current)) + chg->fast_charge_current = DEFAULT_FAST_CHARGE_CURRENT; + if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt", &chg->charge_input_threshold_volt)) chg->charge_input_threshold_volt =