lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240715-max77693-charger-extcon-v2-3-0838ffbb18c3@gmail.com>
Date: Mon, 15 Jul 2024 14:55:05 +0200
From: Artur Weber <aweber.kernel@...il.com>
To: Krzysztof Kozlowski <krzk@...nel.org>, 
 Chanwoo Choi <cw00.choi@...sung.com>
Cc: Sebastian Reichel <sre@...nel.org>, Rob Herring <robh@...nel.org>, 
 Conor Dooley <conor+dt@...nel.org>, Lee Jones <lee@...nel.org>, 
 Krzysztof Kozlowski <krzk+dt@...nel.org>, 
 Alim Akhtar <alim.akhtar@...sung.com>, linux-pm@...r.kernel.org, 
 devicetree@...r.kernel.org, linux-kernel@...r.kernel.org, 
 linux-arm-kernel@...ts.infradead.org, linux-samsung-soc@...r.kernel.org, 
 ~postmarketos/upstreaming@...ts.sr.ht, Henrik Grimler <henrik@...mler.se>, 
 Wolfgang Wiedmeyer <wolfgit@...dmeyer.de>, 
 Denis 'GNUtoo' Carikli <GNUtoo@...erdimension.org>, 
 Artur Weber <aweber.kernel@...il.com>
Subject: [PATCH v2 3/9] regulator: max77693: Set fast charge current in
 MAX77693 CHARGER regulator

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 <aweber.kernel@...il.com>
---
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,

-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ