Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1160528lqb; Thu, 30 May 2024 01:58:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHASupdN2tcaXVYteRqrbgfubvlIwTmy4PbHDGfpVs5/e2sQSI3mXVjuA8dAg6d76sg+b0OskX+VtF3j97oSjXpd5jsIKtl4vDQZxppQ== X-Google-Smtp-Source: AGHT+IEEJAGxvzLC/jw80s1y6Pwk+vFosfQWysReq1KtfBQnna4ggwPHtDkoyEHR2wLhImDp9Y/B X-Received: by 2002:a50:cdc3:0:b0:572:a158:8a7c with SMTP id 4fb4d7f45d1cf-57a179492fbmr806493a12.42.1717059532281; Thu, 30 May 2024 01:58:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717059532; cv=pass; d=google.com; s=arc-20160816; b=EKbaledaRhbVZ3RBh/qZL9m+6RZ4n4XERssJxZUlSdpMlNTRqFgLyqCTp/ytm2quy9 sh5jnMvK8ZQnF/DO4ZsLv+BqA/bVzMZY8QRFDh52JJNg47fYTfaMz3+Y6Ho1ESSzzP/C GXG7B3pzcT1kxqwfb19Wf1t1rvXEfuLcMlCA873H+2Vrjp1aAi8tJtoP7Epv3p8Fou0Z 049AxXGf1sG96KdmmC1CZ9j8JLW+524C+THQ7f6CpHJVNyvOfcSnakAz11mgHXeyoZYK 96lEUP+Wmy4c+WrcYVECS1Lk559M4B3bMx/ZSxH8UI1xZVV9v3g305tf38ZbhaKbb69I pROg== 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=LsEhPfZvH2P+EpSo/CYGNbfVPmcN+fNIAQrFOTA/UcQ=; fh=7vWn4TQyVEX8DkgAXmO/wu7SsAw/Kq4iUneP7aVw5N4=; b=TbOnf39GH2FpdIijfEUp/868H/ZwHHiQtXPuKEfaL5/NyR8H8DjOJvT+1vrEogg+yl FL2IzN4l1qaGz7x+Y7nTGqxAJeTe9AX8tqjdAR/N/80/dbjKpCe6e2cs2JBWxFApbE+U lnJcrN/6fS0nFUqm2nZzobkZA8f+InJxsorVkRvQ0eJ1Z0d7Xs83GTGTmpTqQNFs+lXq hGhNosNdJ0O/akpQa14So6uOFU7FpWVvGNwNtmD3ezi/tILeP24He4hpqctquoZmRZeS kQ8UvQNVBaPlN+3kK63JjczhkMXRLfZljzrMCmSzSKqEqSOxyVXyLsGyWyA3ujLA9ngM A61g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UvaHsGpN; 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-195105-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195105-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-579c57c9281si5428982a12.217.2024.05.30.01.58.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195105-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UvaHsGpN; 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-195105-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195105-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 307081F23F51 for ; Thu, 30 May 2024 08:58:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A15C17D34F; Thu, 30 May 2024 08:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UvaHsGpN" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 5C5083DAC1E; Thu, 30 May 2024 08:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717059396; cv=none; b=A+iq+yKMnhXkGRJIzkP1fWhIh9iQx3CFiumGv6waLvDvMJ5imb1buWmDc1RWVuBBFd9In3cAUtaP2WeBVpR+QSScjNbHqnK21ovMzm9MSFOcpGuIm0bn1/28FX5ta6VhHfhv+pO0BwRpd4/aJ5GbFh+kTGzPBUISzoFfH+iC6oc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717059396; c=relaxed/simple; bh=8GrD+7N4WIECelsMnMsq1oOIcn8b/3kdBSwFTiT2G4s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=elTlJ/9iMR7eQTPhmFsgIiLtWl4qImq4rHFylsQASle6J+UxsPiB9y/wSnBDidrSa30MqB4UXIRudlmC7F5TXkrVyMj/vx8l3RNf7bvy8Wp1dnH343Oej48T17J2x72Ooj+zBZiAfJHj9pVGxEq1hYnKfvvRq9LDByXjAwsIyKU= 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=UvaHsGpN; arc=none smtp.client-ip=209.85.218.52 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-f52.google.com with SMTP id a640c23a62f3a-a667e104375so19044966b.1; Thu, 30 May 2024 01:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717059393; x=1717664193; 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=LsEhPfZvH2P+EpSo/CYGNbfVPmcN+fNIAQrFOTA/UcQ=; b=UvaHsGpNpYN4hTSJE3zUv0WWiyFfbI9JpeoFGD+30R9X/+QaYklGTqZzF750G48hOG otK66K6K4XPmQD7Ftkti/p+omXGkRoyny6YmuPUO0PJi6+NqmHdo5YU6BTQUH7YUTB41 dI+p+9Zrw1O7G9FQQdVS0x2HG/VPC+X+hSG3km5wJIZKNxO7/lnf7ZPuP2NETzGW8RgQ Q04JSECSo/G6kLOuHwOm6llAWGnJkysxluf/QdWYeSCTwbgLTqduZmnZPJw2hg9If7Mi Nt0leYf8LS58onx/FBFdut1rjTlneqCcZBECWQyaiPgRgWntVfRHPh3BcwjJLsvQ6C0S P9WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717059393; x=1717664193; 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=LsEhPfZvH2P+EpSo/CYGNbfVPmcN+fNIAQrFOTA/UcQ=; b=KOtp3GVu/FFbsEDPdJwup4lPVZz84r2IuRXw574hnvDDMGGHkWmrqQ6ShYHjI6CcVs 7RMGwgusGuSRBwcnTF/OF4rGgr/RqbWhIGHc54xNCUEzz5xqmt55ZzutXvWfjTpicZjj zAUuWowb4eXoKZ+g4D+Ix2lbkLSJlqgYIbFlGF8qHEAnKs9EOV1uktmJ94NlnsnDVTaf kMvH62hcpCqdMbvYW+qNKWqd38V6tgO5ld5cnMZ+DlwP9yWqJkdOUTiv93/oQOWjNTk8 OkRXKU5ZBvMQOOduh8o3T3cgX2sBe0kCYM5oDW8c5r9pdoc0yFNiizprodO8vb1wNSu3 E1zw== X-Forwarded-Encrypted: i=1; AJvYcCWGOO4woMbybOdkh4xxjBPzfJNZeghKS3xCsTs6ns/4Xj1EnKegPMbMYZl0gYFGTn8T0XjCgkqmgpOfGz5GB23rCCkZxqYM4EjSDKoGrw1/5tfTyLpNgwaltixBPywTyMTPeLi+SyxbQTY569ola60UY2pc4f68F4Gj6ZoR6M1KHb5S+izWoO7Fbw2RVQLmUbynxUq+dklKHLvnPwNtei0JbYxH0x8= X-Gm-Message-State: AOJu0YwVFTnbvfGfS0vazzYoQwVloaUopG7/GX98YrtN579/9N/WlEOu ZuMkBMqomKh2hDRzmVrI0dIJgRmh/jwLZ5oximwKT3wtqUZtzKoz X-Received: by 2002:a17:906:b49:b0:a65:1322:7a50 with SMTP id a640c23a62f3a-a65e8d3697fmr93332566b.9.1717059392542; Thu, 30 May 2024 01:56:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:56:32 -0700 (PDT) From: Artur Weber Date: Thu, 30 May 2024 10:55:55 +0200 Subject: [PATCH RFC 05/11] power: supply: max77693: Expose INPUT_CURRENT_LIMIT and CURRENT_MAX 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-5-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=3592; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=8GrD+7N4WIECelsMnMsq1oOIcn8b/3kdBSwFTiT2G4s=; b=ud87G1rB7IwJbUdifMoM61jeuoLZFMLcCeL8B+hk4HIHdhOhuibHT3a/ZGXSAduo063J7b0Ro VAw73uJI42YCzPX5EUaqQxsaOcV1p/fgEQgMkNjYBd6jUQMzRv6wmK2 X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= There are two charger current limit registers: - Fast charge current limit (which controls current going from the charger to the battery); - CHGIN input current limit (which controls current going into the charger through the cable, and is managed by the CHARGER regulator). Add the necessary functions to retrieve the CHGIN input limit (from CHARGER regulator) and maximum fast charge current values, and expose them as power supply properties. Signed-off-by: Artur Weber --- drivers/power/supply/max77693_charger.c | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 2001e12c9f7d..894c35b750b3 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ struct max77693_charger { struct device *dev; struct max77693_dev *max77693; struct power_supply *charger; + struct regulator *regu; u32 constant_volt; u32 min_system_volt; @@ -197,12 +199,51 @@ static int max77693_get_online(struct regmap *regmap, int *val) return 0; } +/* + * There are *two* current limit registers: + * - CHGIN limit, which limits the input current from the external charger; + * - Fast charge current limit, which limits the current going to the battery. + */ + +static int max77693_get_input_current_limit(struct max77693_charger *chg, + int *val) +{ + int ret; + + ret = regulator_get_current_limit(chg->regu); + if (ret < 0) + return ret; + + *val = ret; + + return 0; +} + +static int max77693_get_fast_charge_current(struct regmap *regmap, int *val) +{ + unsigned int data; + int ret; + + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_02, &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_02_CC_MASK; + data >>= CHG_CNFG_02_CC_SHIFT; + + *val = (data * 333 / 10) * 1000; /* 3 steps/0.1A */ + + return 0; +} + static enum power_supply_property max77693_charger_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_TYPE, POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; @@ -231,6 +272,12 @@ static int max77693_charger_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_ONLINE: ret = max77693_get_online(regmap, &val->intval); break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = max77693_get_input_current_limit(chg, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_MAX: + ret = max77693_get_fast_charge_current(regmap, &val->intval); + break; case POWER_SUPPLY_PROP_MODEL_NAME: val->strval = max77693_charger_model; break; @@ -680,6 +727,11 @@ static int max77693_charger_probe(struct platform_device *pdev) chg->dev = &pdev->dev; chg->max77693 = max77693; + chg->regu = devm_regulator_get(chg->dev, "CHARGER"); + if (IS_ERR(chg->regu)) + return dev_err_probe(&pdev->dev, PTR_ERR(chg->regu), + "failed to get charger regulator\n"); + ret = max77693_dt_init(&pdev->dev, chg); if (ret) return ret; -- 2.45.1