From patchwork Fri Aug 16 08:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13765686 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 10A4EC531DC for ; Fri, 16 Aug 2024 08:22:11 +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=ATiloHsMDaf4CMk8cdUWOTXJanYqTe2+ZJJOm0eYxfI=; b=MAw15zaUp7Fzqjsut9XR4u2JE1 KqZUCHqLb2PXAEzdvajFgByqtGOBrOk+/GnVy6vSe6g3c3MbdiglUGfsE3IVxT7xfAgH9TF5kPVK/ JGmXf6b0/emoOE+YJAwSEMbCICtG6zORlm7hh4j6fgjSmktUCekZdvt+3lflkfw5cD8vAsU+k4O/l 42DLd8kwlum+6P1APg43+3k1XcGlgxtTCBZ5sNgxLF79Bqtq4k4iQTsXbPSzJAPt39raimc0z5AJS MaWB3DUohhcBXykIHPme3v/g4zNK9KizhUMGqUO8xuSyPjdXhTf796FxFnnQxTSiBZI1+KQoBlhJX 6ObD5Krw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesDf-0000000CFjo-0L0n; Fri, 16 Aug 2024 08:21:59 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sesB6-0000000CEzi-3fNn for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 08:19:22 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-429ec9f2155so6356795e9.2 for ; Fri, 16 Aug 2024 01:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723796359; x=1724401159; 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=ATiloHsMDaf4CMk8cdUWOTXJanYqTe2+ZJJOm0eYxfI=; b=DVCMVwZ1aAGhtKeS8vr/hzbU9PLj0tgU2NuTNCmriedPZfZvu99qgBmJn7qr5qCRDd 2TpKNch0GmZ6ZnQG67Lu1ZrR5S4lfYJC27/nqb/bbo60vuYSDKCsyDauwa1zyPVIt82e rZ6GdxdwlU0kasvkAk5Ry1L1TrHIC3sHCJMcAjiEHjePKDUqxCvVVPHuW4ADOBDdhbEC l4twAFoAe6jtZGtKmfCIJO2fKootsk/HYU0+1T5d3+NpS5wGKPUtRX7wx5jyMI96ce85 Rw1prZjWmEDqX/lG6gD8A9R1PoVsrh7SzixYH8wj0yaILBmtZ3cEt8jopDe6hTAhua6n qqaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723796359; x=1724401159; 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=ATiloHsMDaf4CMk8cdUWOTXJanYqTe2+ZJJOm0eYxfI=; b=Nr4gLaeSO/xu/dwjRYw+ZY6jrb1Qp9BWbms/hiiji9QEPvse0HbathAgn1ojGG+rqy xX+DxeHctphXNAxBhtEaUltqRfBjrE/kN6vaKDNVKy8PsLiTlGgrMZlkz/KVsi03pPq6 eV23WlZFgpNddnoN2Y4piYmw6FswF8RcHKFPDQgVp2zdLvV6tXUDtdNzSlOXDEB7WZl6 K0mxONqngUYKRTglN1/glJ/CMrs3WQ4TxwrK3FAbciXbABiLbSYbfgBO+kNSS6zRqWSq gbAYY/jcL65x9F5R0ye6fX18WmWsMg2KWvy/cqKMglK78/e6BRJJnsum4FeylgoAaIu7 10Aw== X-Forwarded-Encrypted: i=1; AJvYcCWAOxJo4HX1nD3ytqcfwXgoMwo+7N3hOM1xtu0Foo4eBPTABswSTEfQ+Doc5PqRsTKxeYPBPOSPew/qEuzcrID/g9AB4ijTvtGMuxDFl7zH2ljsuyI= X-Gm-Message-State: AOJu0YxRVYI6quJEA1CkqaoF4mvKFUkhKw97T8T5LKzLIUafPXpJwbIM y0fp/t1hvrjqJcoD/Vn2LRVt3df6rw8t/M9iyTEmYBUlgGrG88Ea X-Google-Smtp-Source: AGHT+IFZVBfIxeRRQQdYKBVbIL/LlcK8Xckk0mrM3X9pjm13/8U5f09VuGWp1dTEiDNUiNzFSTW+1w== X-Received: by 2002:a05:600c:5254:b0:426:622d:9e6b with SMTP id 5b1f17b1804b1-429ed7cce32mr12561705e9.23.1723796359212; Fri, 16 Aug 2024 01:19:19 -0700 (PDT) Received: from tablet.my.domain ([37.30.8.221]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded35991sm69732645e9.21.2024.08.16.01.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 01:19:18 -0700 (PDT) From: Artur Weber Date: Fri, 16 Aug 2024 10:19:09 +0200 Subject: [PATCH v4 03/10] power: supply: max77693: Expose input current limit and CC current properties MIME-Version: 1.0 Message-Id: <20240816-max77693-charger-extcon-v4-3-050a0a9bfea0@gmail.com> References: <20240816-max77693-charger-extcon-v4-0-050a0a9bfea0@gmail.com> In-Reply-To: <20240816-max77693-charger-extcon-v4-0-050a0a9bfea0@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.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4267; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=9IYOJ5Si+LfLkVCi/KMBWfaO4SAQ49FCSsDSX2k02RU=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmvwt+B9dItojtyq9JMOVXfTV0Y4E6HJELeVrGz 5L6JIMqdPaJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZr8LfgAKCRCzu/ihE6BR aN/1D/44BbqpiUrmya2u3MQKsTMDcLUdMN1u7gjA0nVafkmQycc9654R/GBZ2Qc8fC6eLbFVvsB dhn7slD9g8dHpE4drqkTLFnceu70q519uo0ZXz/Jzv9EqYGOsHsGUjaqbolJeiWrYsqOlNxjV7X 2QdHze/Szy+NbdYxDTKzc6osxPLV49CylDodw8SDt6+xUNZDSRmC591KLSBtKjcHQMIJ2W0nluG YI47KKnt2gIMlpv4DjM33BRKVSlC129QunHtWLyDkVLdVjyU/ZKE4BAbkKLegvrcxWaA2TwD+Ar KtHiMx80shyu0bytyFB9BomXdFkRcI+FnQh0EpbzaupxcUA9EuGgcXV0isZ58CZrtI4iNSI0355 js19HfYVkZet2KcBO2+1eSZfC5V/5Tqk7xbbFisItCHDCmypocICWAOaVoXSHa1vCCIrMDbgz8V Mc4EVG61GuLi7dgDebwmagpTLDNrEuLnMf7X8iNiNEM5hFUdiuUn7YIOiR4lV/Csj9tfwJD/vmy 8fnO89flT2asT+YGPp9K9piIEf51CD9Otv/e1ZreqjM/5VcQnK4chCWE/9z0L25aJTWqtLAOMXJ xP+kkoiYYQFENRzGThOaVu4gG24BnA4amHOmgOMhan8AlvzOBUaFsLgOpP4vnbnttdrjg/TNlAr ipZLSuvMlGMuL6w== 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-20240816_011920_959321_6C56A4D9 X-CRM114-Status: GOOD ( 16.35 ) 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). 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. Tested-by: Henrik Grimler Signed-off-by: Artur Weber Reviewed-by: Krzysztof Kozlowski --- Changes in v3: - Dropped CHARGER reg reference in favor of managing the registers directly - Changed to use CONSTANT_CHARGE_CURRENT_MAX instead of CURRENT_MAX for fast charge/CC current property Changes in v2: - Adapted to both current limits being managed in the CHARGER regulator --- drivers/power/supply/max77693_charger.c | 52 +++++++++++++++++++++++++++++++++ include/linux/mfd/max77693-private.h | 5 ++++ 2 files changed, 57 insertions(+) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 2001e12c9f7d..4caac142c428 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -197,12 +197,58 @@ 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 regmap *regmap, int *val) +{ + unsigned int data; + int ret; + + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_09, &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_09_CHGIN_ILIM_MASK; + data >>= CHG_CNFG_09_CHGIN_ILIM_SHIFT; + + if (data <= 0x03) + /* The first four values (0x00..0x03) are 60mA */ + *val = 60000; + else + *val = data * 20000; /* 20mA steps */ + + 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 * 33300; /* 33.3mA steps */ + + 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_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; @@ -231,6 +277,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(regmap, &val->intval); + break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + ret = max77693_get_fast_charge_current(regmap, &val->intval); + break; case POWER_SUPPLY_PROP_MODEL_NAME: val->strval = max77693_charger_model; break; diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h index 54444ff2a5de..20c5e02ed9da 100644 --- a/include/linux/mfd/max77693-private.h +++ b/include/linux/mfd/max77693-private.h @@ -217,6 +217,10 @@ enum max77693_charger_battery_state { #define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT) #define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT) +/* MAX77693_CHG_REG_CHG_CNFG_02 register */ +#define CHG_CNFG_02_CC_SHIFT 0 +#define CHG_CNFG_02_CC_MASK 0x3F + /* MAX77693_CHG_REG_CHG_CNFG_03 register */ #define CHG_CNFG_03_TOITH_SHIFT 0 #define CHG_CNFG_03_TOTIME_SHIFT 3 @@ -244,6 +248,7 @@ enum max77693_charger_battery_state { #define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT) /* MAX77693 CHG_CNFG_09 Register */ +#define CHG_CNFG_09_CHGIN_ILIM_SHIFT 0 #define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F /* MAX77693 CHG_CTRL Register */