Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1160655lqb; Thu, 30 May 2024 01:59:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzwkPEeXrmL8DFMREADjhJCvAEWR6AP+knEvWOCAUlQysNfmELEsLGJFPRUHgJvWPniDLrFykp1V97zc+VgxzRSeUFa69Sdeh6XUUIoA== X-Google-Smtp-Source: AGHT+IGAEanC1j2f/lzfGwbbCUTPmGdV0+h+J2FfrWeS0fkBM5U5hplZZXxPj2ITmQxh2pw/HV1+ X-Received: by 2002:a05:6a00:4206:b0:6f3:c10a:7bdd with SMTP id d2e1a72fcca58-7023112f91fmr2031372b3a.18.1717059555637; Thu, 30 May 2024 01:59:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717059555; cv=pass; d=google.com; s=arc-20160816; b=WKakVXhCWB9O3/NgzQK7ChRE2IwHqB7vRX3o9r6oZNDM2M/PfJDFYt4wBO+5od2Hvp 6IJ05IieTzVF8x05nLQJKxkQWe+zlZe2frn2pr2g7JK81VE0fklGTzt25D2kVfsyuMYG myo9UzJY7V4MhgL2Dm0EgJB/5Mo5adqJkbITZdILNEohLBNSsXU5yMZgyuja+Fk/511n QP4Ra79C7xkN2ldk1yn48V9hnA6Ynn1MVSnoIFVhUUs7QgxcUQ9aBBzYwc4fIpFlAt+x 5sYExEz0kerRlkvw0/9uSOsZvzlllEhPfmvOUfToYNRimH31a8IVxVAx0qpxKEpgnrws MOtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=y515HyBE05tinjYLW0X+UrEG/VkT72f1VOdrq3/W9HM=; fh=At8PUKlDbLmLKuvQ64R7fEdHyaOu8YcBS6xbk2nVMLw=; b=ywF8imsz/zCwPv8VP13JVDdCaaIVRHlv8tBvObushLq4rqJeD5+YX3JDSDEKGHyg9a lW1BnDQX6VIWkcIzIbfQ3ElF2xEar0vT2Ktm/EY1DodsXRTxFLICiDggW8Rs8s0NKzyi Zq5xBsDUl7gS87Maw6+Cqxj9Z0aqL2safNh1a3OYpMzTooA6YSPwkhwWG/gx7E8J4JGs lKzUtxgg60wX3VEHK3MxFTXYDSx9wfPaRKTu9B51r63S0eAykF+SF0PntB7iW84heSEi FAmQbDJybdDcmtA/lP+ALP2udnHSwPMejh9niftU2o8ZYGFojkIRMxXOnxjgdeA1P3eA 1Scg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mOVRgl1o; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-195108-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-70226bdf665si1976661b3a.302.2024.05.30.01.59.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195108-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mOVRgl1o; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-195108-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 456BE284BF7 for ; Thu, 30 May 2024 08:59:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1192917E477; Thu, 30 May 2024 08:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mOVRgl1o" Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6533C17D375; Thu, 30 May 2024 08:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717059400; cv=none; b=RYYLHSu4Ss/aF23cOW87iP5fP/svQ7JlRLhh3oL3WU4L9nJvMmAMywEWb7WkhInWREumtoJnimVC/M2rqAUUxSVBV+2zMdPaup5DhoAHjOu5NoVPolNs5vJP9LwKHEE8oRm7NgKodT0k3tcESwjKletj9uxb7TKL0y6167lk+zs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717059400; c=relaxed/simple; bh=ASIwzdEZQZXRm8Gyc8ivplNNZTHwY1NZ3AUZqjW/FCw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TTVgWy3HR6muIgITT4E2fTCumWeK/D73vEjxIvHP145cAQTZYdEkWN+cr7FFzXqejz+YJzltQWt3RFXgfd3m8QgppDwNltuSijr5sHLPSmUG7hxgYTGIx9ejOz0slHLMhmXByrWgbl4p7xTGFm6mnrB/Fy+8/thUONPtLuVlWMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mOVRgl1o; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a6267778b3aso33079766b.3; Thu, 30 May 2024 01:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717059397; x=1717664197; darn=vger.kernel.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=y515HyBE05tinjYLW0X+UrEG/VkT72f1VOdrq3/W9HM=; b=mOVRgl1olq2CDAl4zvIKpGg+63kOXWkrTFaDOx00QQpT4Y6oj85dXdu/MhXVWh/Wra kt0IXAuA8GgDawuMTXZ2rtQRy5DFwlNlVpwlwH7NyVJ/VLdVs/nzCNrZfk8FOuRoYJln AaEpWPoDWqlIWkwA1cJLvluznoSddr/yn9fBUTpi2h2yl7LENGPJ8n8aFzbzZzOSLsox nVliYdDmO+EPLapQ8EcxVBe80bmhPE+xP1qMUZe51Khk7H//IDXl9PdEW8M2ZYWH4ksv cw3H1LMeepVOwvyeJplSC2BXLUbVAQKCfYRMdhpRJA5MV/77pGDNiWSEPsu2ngFtKmsU rjEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717059397; x=1717664197; 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=y515HyBE05tinjYLW0X+UrEG/VkT72f1VOdrq3/W9HM=; b=dg4pAlH/cjZC1UH+xHySiyOpV34C01CqkcVHJ86yTKvgFFJd4ZQ946OC2Fy9QY3bBH 4QEEdmf5OxiP8Ura73RCnO8CY4OGjU9sp7soHaq2BkhZcQyqYMLruzjSNTIxO0TDB/l6 sqYIft02o2KUp0OtFAY6n2NLd98d3dLeI++otyzUtfVW6gIProReYHVtWZmNcbasvzkR 61tNQmyHKegluckHry2lWZb6yDsaITFLPN8I+1umPzjWxmajX28BXV0qc1KiY06YiNTx G05cp0B0+7tWCdpewH8Q6LOZtxGDPMwSyvCdUwFA2BUp4aqBLzxHkHIAISleiQCMfcKB uu4g== X-Forwarded-Encrypted: i=1; AJvYcCW9Oxfi3SGyL0cuRJ4AM+y9QvU9lyxjXeP7xxHxUCJ+21LSnP0FjwAsIB7XaeNvcPW4GWRaSfBgoJCZjZWXGP7a/H+NYc7WGOo2ftBxnkErr9eg2DXm7jOvmv8eM8RqOPBc9IPBglPOHTqSpXA9ayoTFx95iAFDTAfe+hh7v3TkyDIr5WOvBRopa8NJMKm2MESXMaUOy2/nMmcxIIqtdrgOHI9AAzw= X-Gm-Message-State: AOJu0YzurNM/GQGi03YNXOlTMv4dGWPRASd3Uv4S9to/zlDUOYSB2bkK +65OmIkEzJo7o2KiGcfJXnzL5k2Kdy0hEoFdICKxcIOFnnf+ykVx X-Received: by 2002:a17:906:bcf1:b0:a62:1ac8:5752 with SMTP id a640c23a62f3a-a65e8e317e8mr84844066b.8.1717059396642; Thu, 30 May 2024 01:56:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:56:36 -0700 (PDT) From: Artur Weber Date: Thu, 30 May 2024 10:55:58 +0200 Subject: [PATCH RFC 08/11] power: supply: max77693: Add support for detecting and enabling OTG Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240530-max77693-charger-extcon-v1-8-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=3575; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=ASIwzdEZQZXRm8Gyc8ivplNNZTHwY1NZ3AUZqjW/FCw=; b=MXc4Bb2/SN4z7AvEEeeSSMbRT9iuCtg3ixSez6kz6cE5oO+N08S58aiJ0Lfic/PE6EWcO4BIc Q+aEXmRvbfFDSMFAdElLbXdf7WM0IdllawF8Jzg0BN+OKcPfhzte9rM X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= 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. Signed-off-by: Artur Weber --- Downstream also sets "CHGIN output current limit in OTG mode" to 900mA by writing (1 << 7) to the CHG_CNFG_02 register; while I would try to add this here, I do not know which exact bits control the current limit and how their value affects it (downstream has no docs other than what I just mentioned), so it's impossible for me to know what the mask is. --- drivers/power/supply/max77693_charger.c | 70 +++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index c2e8ae367381..e548fd420e78 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -737,11 +737,41 @@ static int max77693_set_charging(struct max77693_charger *chg, bool enable) return ret; } +static int max77693_set_otg(struct max77693_charger *chg, bool enable) +{ + struct regmap *regmap = chg->max77693->regmap; + unsigned int data; + bool is_enabled; + int ret; + + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_00, &data); + if (ret) + return ret; + + is_enabled = !!(data & CHG_CNFG_00_OTG_MASK); + + if (enable && !is_enabled) { + /* OTG on, boost on, DIS_MUIC_CTRL on */ + data |= CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK \ + | CHG_CNFG_00_DIS_MUIC_CTRL_MASK; + + } else if (!enable && is_enabled) { + /* OTG off, boost off, DIS_MUIC_CTRL off */ + data &= ~(CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK \ + | CHG_CNFG_00_DIS_MUIC_CTRL_MASK); + } + + return regmap_write(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_00, + 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; @@ -760,25 +790,43 @@ 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; - } - dev_info(chg->dev, "charging. connector type: %d\n", + set_charging = false; + set_otg = false; + + dev_info(chg->dev, "disconnected. connector type: %d\n", connector); break; } + /* + * The functions below already check if the change is necessary, + * so we don't need to do so here. + */ + 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); } -- 2.45.1