From patchwork Mon Jul 15 12:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13733496 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 76AB6C3DA4B for ; Mon, 15 Jul 2024 12:56:35 +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=Hy8uXIYsKBTu0N7Z2wuBwfh2n1x8LDG4iwV5RA5Sikk=; b=OL2UXd31+LrvBVPAa5MdZQD73Y 9KQyclTWxYFGd15VU0EYdcbA3QuuQymbq502d9IQyQnVCtKsH2WVpWDHyH/IwGxiAlRxs7VCwkSD3 DtQuZABc7+ErLGW64FJWfIZi7MMNCQI0NJ2Efbe+OHeURa4cNWAYyNXzFdI8TnoJJ+fdq/HHVEYZU fvAf/IuVHk2zq6fJ/LH6G/5e+BeiPvJs/fVXxk54U0hKFljpZRYAbt42ydv9HGsz1EONWZBZUt2fu ZEMOCHtlUj3mUYX6DF4L7QRsczXdcmer29Zgat8i6pt642Vgv+OlVQlLe417wG+nIuuId/J7sCNnG 8s4QAD9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTLFe-000000076re-3P7a; Mon, 15 Jul 2024 12:56:22 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTLEc-000000076Rz-1s1i for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 12:55:19 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5854ac817afso5322434a12.2 for ; Mon, 15 Jul 2024 05:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721048117; x=1721652917; 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=Hy8uXIYsKBTu0N7Z2wuBwfh2n1x8LDG4iwV5RA5Sikk=; b=A45jFe+mMC4Vusn0AvDIZeKiIdMK/59ao/YgRUkl/m6ccBZeHw12KPDoQJ8DFNMXEn 5JZnT+n7t2noyy+CHMkziZgqvGVJIjGxTRt6b1U9JI9hjElvSPLTJpGKqJVlt3eNevXl xEi5nxn0y8aFQH7yjur5cOltciu0N64psE9tn409VXBq5owwCak4MEr/dZcVUX+secgE 12kyHaCQAWd2ujEGLo9PFlu0nGxyHBN2R3QlyhO67sxOgozn4paLhnE06KWTvQqpswGT 6jU0XFW996e8tkSzwM+PEbNE/OFt88oNoh54qvoM1iZMiwmwuRnlPSIL2dsn6Egy6RyP Ajmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721048117; x=1721652917; 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=Hy8uXIYsKBTu0N7Z2wuBwfh2n1x8LDG4iwV5RA5Sikk=; b=J1HRM8lSNpThg73ZsxlYYi/CUloKQoa/GwriXNp/QtYwZjlrej4yR9jifyc7yTsIn4 he1Obx9BI7eOWOWncvQeaRVC/hPK9ypMAzXzEE0PPNIw1Qdb9bLSe35X/48QkIfOgtwo sBoM3h5Irs7LeHMxgyq9gnX8bNBa9Sib0NAxMg4cHUewzUY0M3PDlRbWZdqkMJ6K8sdy 3MGmoECDmnLsLy9RWDt2vWxjKMjPMw0GFPQW8PxbCOHnFE8E7OUm6u7PEEkEp1ulk/bx 58nqGoYAiYZfDT9ShSOayWa2LG6Fu/yz+7aSLWj+kRNkTvvsRL5tfkxI7j6THTlBifhg BuSA== X-Forwarded-Encrypted: i=1; AJvYcCXjTP/BnNpLlXcUWcZ9HS7katc49RwhmtqaArH7O+sji8uNjMRl9FgAN4gBebB9/9PRo56+v6RELIjrP1eJPJ2EGmsL8IWpv13s999jkuc4C2rifxU= X-Gm-Message-State: AOJu0YzDjajcUWJ8fiwrEiIMhJQ9yT4MGVYcVIQ1TgazJu9HbkXdOjuM +6OAGVjx8Xl7od1SmTRgtFqseFANKf2k/nQA4iiga7od6ltC7qw6 X-Google-Smtp-Source: AGHT+IFSeOUQ4GQ0JktHokv589tUfaMihwOmd9W2rP3yeBHjQVzPLMNMNZgec2Vx5yIRh3tyCsIOBA== X-Received: by 2002:a05:6402:5bc6:b0:587:2dd0:93ec with SMTP id 4fb4d7f45d1cf-594bc7c7e36mr12494193a12.30.1721048116556; Mon, 15 Jul 2024 05:55:16 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 05:55:16 -0700 (PDT) From: Artur Weber Date: Mon, 15 Jul 2024 14:55:05 +0200 Subject: [PATCH v2 3/9] regulator: max77693: Set fast charge current in MAX77693 CHARGER regulator MIME-Version: 1.0 Message-Id: <20240715-max77693-charger-extcon-v2-3-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=3543; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=sa109WgAcykCnYFwcY2iDwvvtR/mCqo5hBu3QTu8IW4=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmlRwpIpRGh8YMXJ3XQOkQ2hUgOoJw/29UT+Po2 VR5KAyFJ3yJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZpUcKQAKCRCzu/ihE6BR aLY6EACF7ffTvprcNEbjAy1hgs2bevgEwN4A3e2ItBicKITTLCZFfKxd2+k4A4oXyjZ3N15Ewg3 VKas0dQ03e4EoTGGlT/HTcwhVR8tIkGM3367YU8ZdNXJsOK8O0X5AbQ5m6YEHag6w5hVnICJEGA VUUXnOYofTqM5FkphC/9RrYfSRTmAwDV43Ha71LP+up6hhgZPDZz/MJWhTkfiI29P31gOBQGvhz C9maOTwMswG7NlAmTFofooE/R8jZRQ+tHrPj81cNjI75K5x8rb8vkYOTQphbU5GNnKBOp3llefC C5SjiHEgMfqAj9wV5wKYEee7W4rDkwygXa0deHUjG+ng2+hNJlwmkKSlgYSrmbcR5pA8XWPna3i qqgU7bDA7PxzgCLSzs9SfBu7gzx7dbhfUKA8Z5HG2lCuOu8kkz9QMrDjG6KwGoZ36gxcyAU+t2s PyFm4pBN+P3+OcRG8DKyi5ix9NGO/p0qdyhr9vo1HW/dTPhygvgt8HGBsZxQFYoOb4oAaA5UbKT 7JbQhROiYfHM5L8kjqAc5yldv3OtB9rnKJNUA9DimrwQeAkbMuXK0i2nHfrlLTy0TbtJMFFmuR3 O++w5f3y5GPOMfSDo6/iNb2iWs0SWVBKVJD0F7YAHdjlh8uhEuyHpOnRkXiUrD6B5xh5tmFe8s2 tfe4E4tD1MEgblQ== 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_055518_525999_900CEA58 X-CRM114-Status: GOOD ( 19.32 ) 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 The MAX77693 CHARGER regulator only controlled the "charge input current", with fast charge current being listed as a TODO. Fix this by also setting the fast charge current when the CHARGER regulator limits are changed. Signed-off-by: Artur Weber --- Changes in v2: - Added this commit --- drivers/regulator/max77693-regulator.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/max77693-regulator.c b/drivers/regulator/max77693-regulator.c index 72a67d0c5f1e..3fee2e255fd0 100644 --- a/drivers/regulator/max77693-regulator.c +++ b/drivers/regulator/max77693-regulator.c @@ -36,6 +36,7 @@ enum max77843_regulator_type { /* Register differences between chargers: MAX77693 and MAX77843 */ struct chg_reg_data { + enum max77693_types type; unsigned int linear_reg; unsigned int linear_mask; unsigned int uA_step; @@ -46,11 +47,12 @@ struct chg_reg_data { * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA * 0x00, 0x01, 0x2, 0x03 = 60 mA * 0x04 ~ 0x7E = (60 + (X - 3) * 20) mA - * Actually for MAX77693 the driver manipulates the maximum input current, - * not the fast charge current (output). This should be fixed. * * On MAX77843 the calculation formula is the same (except values). * Fortunately it properly manipulates the fast charge current. + * + * On MAX77693 there is an additional "fast charge current" register: + * min: 0 mA, max: 2100mA, step: 0.1A / 3. */ static int max77693_chg_get_current_limit(struct regulator_dev *rdev) { @@ -86,6 +88,7 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev, const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev); unsigned int chg_min_uA = rdev->constraints->min_uA; int sel = 0; + int ret; while (chg_min_uA + reg_data->uA_step * sel < min_uA) sel++; @@ -96,7 +99,30 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev, /* the first four codes for charger current are all 60mA */ sel += reg_data->min_sel; - return regmap_write(rdev->regmap, reg_data->linear_reg, sel); + ret = regmap_write(rdev->regmap, reg_data->linear_reg, sel); + if (ret) + return ret; + + if (reg_data->type == TYPE_MAX77693) { + /* + * For MAX77693 we also have to set the fast charge current + * value. This value has a lower upper limit (2.1A), so we cap + * it at the highest possible value if it goes above the limit. + */ + + sel = (min_uA / 1000) * 10 / 333; /* 0.1A/3 steps */ + + if (sel > CHG_CNFG_02_CC_MASK) + sel = CHG_CNFG_02_CC_MASK; + + sel <<= CHG_CNFG_02_CC_SHIFT; + + return regmap_update_bits(rdev->regmap, + MAX77693_CHG_REG_CHG_CNFG_02, + CHG_CNFG_02_CC_MASK, sel); + } + + return 0; } /* end of CHARGER regulator ops */ @@ -179,6 +205,7 @@ static const struct regulator_desc max77693_supported_regulators[] = { }; static const struct chg_reg_data max77693_chg_reg_data = { + .type = TYPE_MAX77693, .linear_reg = MAX77693_CHG_REG_CHG_CNFG_09, .linear_mask = CHG_CNFG_09_CHGIN_ILIM_MASK, .uA_step = 20000, @@ -219,6 +246,7 @@ static const struct regulator_desc max77843_supported_regulators[] = { }; static const struct chg_reg_data max77843_chg_reg_data = { + .type = TYPE_MAX77843, .linear_reg = MAX77843_CHG_REG_CHG_CNFG_02, .linear_mask = MAX77843_CHG_FAST_CHG_CURRENT_MASK, .uA_step = MAX77843_CHG_FAST_CHG_CURRENT_STEP,