From patchwork Mon Jul 15 12:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13733501 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 7334BC3DA4B for ; Mon, 15 Jul 2024 12:58:15 +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=2dnrbGKaoLS2/r35L01fJO0wiCmLb/VBCvJttZm/KZE=; b=AznDnaToV4FrQk2v8c82fZ0rU9 oblw8oXDa6YVk2ejl6Ki3hFxu34/KakIplwYHv7z9TbGfyVyBjfoxpLeYs5ySdkdnX/1XzIEGG18Y iF6FTcl/lDCuaC7zI6IOc9sv/0SX3G0hhdxnAMEsaEJrVuLADo+aQRj50gPvGUpz8alQhUbHs+5RI Ub01UOmkHNp+mNLLse/tkOg7o78yDbYAwE3OAC/mVikcIIKNuLPgo2HANVFLZBuw4MreQoBby/203 h7BtQA+6hwLp54jmQxpYzYKCDzmgc8wWPYRblY3eEUrTFlQL9XhHQoUF/Df0O27ilWYnACmxFTVOY dTWEeo3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTLHK-000000077YW-2qh5; Mon, 15 Jul 2024 12:58:06 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTLEe-000000076Si-3ZYR for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 12:55:22 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-59a47d5c22aso4263627a12.1 for ; Mon, 15 Jul 2024 05:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721048119; x=1721652919; 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=2dnrbGKaoLS2/r35L01fJO0wiCmLb/VBCvJttZm/KZE=; b=NUWDXIA2O3qDBsHOt3ISB2CDit9FVx4klZxPfVfqHHSC8F2qTpFzBcpAvwGdcEsNRO b2gVhfRVouLuF/jP6yYXyCY40kTJ5tqk/LUXPl1VIBNutL+pkgbEMk4ZQKqDCvCeU+yw b6Jxs6RcPCD3x5Xifu0omNrH8KrT6f2Ds72fZ9cPkU/ESlZ4iz1VcpABgkYeldRQH78C y9zCz+Xd7+LkW5ZIiwJJA21V1Pym5a6spSx5sRMPeVmj9zxq6XSSb6CulWvBiMmDbkZg EapD4P36QbDHkih7KkvuMkM8EdEFxZVmnOo31eXBmL3JPjC2d/m4kzDs7/HkzDyBCx8C ftuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721048119; x=1721652919; 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=2dnrbGKaoLS2/r35L01fJO0wiCmLb/VBCvJttZm/KZE=; b=pEdsB8e1CxODoDzpLuIYm0kJQn0HSjTdWHO2LqDHLBGhUPVQ9y+EDpyA4MLzisZYhZ dwt1LlLlGjsCzrazO8RqA1JraayjXyoassaIhZcid12Dt2stopO6ep4L1Ry38WPm4Q/R HAwKN4Zkv1iDG6/qnQkAV/BeUopfhwNQ3X2HI7DDLFUiqFHEKOkpdFUBb2rXvADGj3S2 0H3ccwrZgExiQw6S+3oTytkulz/OCrAkpbyInA/ZoWhhhPYnx8mcIvs6aVNgSCfpNeJO ZzxYIod8OFxs9acDPmhxSKff57ZsONWn9fvKTfB8vuLC8OoaZHKbaZBqFKc7BeatGr+e WTkA== X-Forwarded-Encrypted: i=1; AJvYcCWhB2A6VMi+0OkckGAbOahUqia14qy25zdmzf5hQdMejYEvaV1zDK4DjO3zJcnzSJs8koDoJVSHmZGwvtraA4y9ugtX9BstMN73zqRJb5d9hyqDqg0= X-Gm-Message-State: AOJu0YzPJEjDsHSLSpZK0emDEsHMgGudEcxoge/MV7R1c2AwyZFLxr7v bRjwLep0KglOD/oHyYstXM8mbQ7DjkluvrqpxBmiA+KFAKpEW+QV X-Google-Smtp-Source: AGHT+IGKYmXJeIOPB/b6vl4yOzL3ahdkEu80vW0kNZgFlL4bFu7UcYPpvXzfkUGFqZN0xjUW9B6bFA== X-Received: by 2002:a50:bb04:0:b0:59e:65d1:a573 with SMTP id 4fb4d7f45d1cf-59e65d1a75fmr199688a12.21.1721048118746; Mon, 15 Jul 2024 05:55:18 -0700 (PDT) Received: from tablet.my.domain (ip-37-248-157-210.multi.internet.cyfrowypolsat.pl. [37.248.157.210]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-59b26f62165sm3333307a12.87.2024.07.15.05.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 05:55:18 -0700 (PDT) From: Artur Weber Date: Mon, 15 Jul 2024 14:55:06 +0200 Subject: [PATCH v2 4/9] power: supply: max77693: Expose CURRENT_MAX property MIME-Version: 1.0 Message-Id: <20240715-max77693-charger-extcon-v2-4-0838ffbb18c3@gmail.com> References: <20240715-max77693-charger-extcon-v2-0-0838ffbb18c3@gmail.com> In-Reply-To: <20240715-max77693-charger-extcon-v2-0-0838ffbb18c3@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=openpgp-sha256; l=3161; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=1lV+PvQs9RkMQaB50b7Zw5vUCqbzy36VnOEmeBWappo=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmlRwpt1JLmGw3JWwB62NBhkT4suEV7QjKcBC3M zVBlzxGAFmJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZpUcKQAKCRCzu/ihE6BR aLeJD/9Ef/NUzUm3MsA+/2pPGkUkhL4zfMZx//VessDpHA5cioDs6pX5hk4kbkfKTFwVBiGE9+l EtoTOt7Jjqigf63T6WidXghkyjcY7IZ2KIL8Qr6ZhuJESM0BWmoafPQNmwHO8w0euZHLDknW0T5 M1inRVJynstVx/a1k2yM1peHB/oijHfPRKINmUFleDSURUVhxH0nBmj8eQ5YjV/CwA9p07EZ7MX cG9e8pl1Er379lWOc4NcT88omRw/aFz/znEfmJ8i+/lCm8rJV4LYdTes9Nx3/T+PTzrL9xj3y5s abiRw7f9JpQuuDJr3NVzIc0OxMEUPMFFIY7+ao8O7rmHE1A5bpzED45+VBiDCe1+ydTN9uOQO6f w+mt8u2Hx73aQjfQRymE710Uer8XBajg9hZTt3I27sb+3U8OL0n/+sJeRcOrf/w59rnrsx5j1xf OX1zwrxS5WkHkiaO5cMMcCkTazQmGAoG6/15v4ioJSP60+5fnQCGbkWLRT9EZJ435HWc1GFZWD6 JjhE2KqJ1NV2wzBfyDJxn4IbO0ymKzLikJ1i0lE0oXVHSy1j1Hvp/UVGTgy8kbonCtg4FS+Jzr7 WrLCMN9+Eol+lAmkfVn4DW0fTNicVqY0dnMcCbKs+QkQ6VUICLKz5mj8N4CbH1uC9wU3dXksxAp UnGHu9AqNxsyt7A== 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-20240715_055520_933084_3E4E6983 X-CRM114-Status: GOOD ( 17.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 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). Both of them are aggregated in the CHARGER regulator. Add a property that allows for reading the current limit from userspace. Signed-off-by: Artur Weber --- Changes in v2: - Adapted to both current limits being managed in the CHARGER regulator --- drivers/power/supply/max77693_charger.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 2001e12c9f7d..0d53f61d58ba 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,33 @@ 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. + * Both are managed by the CHARGER regulator. + */ + +static int max77693_get_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 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_CURRENT_MAX, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; @@ -231,6 +254,9 @@ 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_CURRENT_MAX: + ret = max77693_get_current_limit(chg, &val->intval); + break; case POWER_SUPPLY_PROP_MODEL_NAME: val->strval = max77693_charger_model; break; @@ -680,6 +706,12 @@ static int max77693_charger_probe(struct platform_device *pdev) chg->dev = &pdev->dev; chg->max77693 = max77693; + /* This gets the CHARGER regulator from the parent MAX77693 device */ + 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;