devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Artur Weber <aweber.kernel@gmail.com>
To: Krzysztof Kozlowski <krzk@kernel.org>,
	 Chanwoo Choi <cw00.choi@samsung.com>
Cc: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Alim Akhtar <alim.akhtar@samsung.com>,
	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 <henrik@grimler.se>,
	 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>,
	 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>,
	 Artur Weber <aweber.kernel@gmail.com>
Subject: [PATCH v2 4/9] power: supply: max77693: Expose CURRENT_MAX property
Date: Mon, 15 Jul 2024 14:55:06 +0200	[thread overview]
Message-ID: <20240715-max77693-charger-extcon-v2-4-0838ffbb18c3@gmail.com> (raw)
In-Reply-To: <20240715-max77693-charger-extcon-v2-0-0838ffbb18c3@gmail.com>

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 <aweber.kernel@gmail.com>
---
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 <linux/platform_device.h>
 #include <linux/power_supply.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/mfd/max77693.h>
 #include <linux/mfd/max77693-common.h>
 #include <linux/mfd/max77693-private.h>
@@ -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;

-- 
2.45.2


  parent reply	other threads:[~2024-07-15 12:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 12:55 [PATCH v2 0/9] power: supply: max77693: Toggle charging/OTG based on extcon status Artur Weber
2024-07-15 12:55 ` [PATCH v2 1/9] dt-bindings: power: supply: max77693: Add monitored-battery property Artur Weber
2024-07-22  5:48   ` Krzysztof Kozlowski
2024-07-15 12:55 ` [PATCH v2 2/9] dt-bindings: power: supply: max77693: Add maxim,usb-connector property Artur Weber
2024-07-22  5:49   ` Krzysztof Kozlowski
2024-07-15 12:55 ` [PATCH v2 3/9] regulator: max77693: Set fast charge current in MAX77693 CHARGER regulator Artur Weber
2024-07-15 12:55 ` Artur Weber [this message]
2024-07-15 12:55 ` [PATCH v2 5/9] power: supply: max77693: Set charge current limits during init Artur Weber
2024-07-25 15:37   ` Lee Jones
2024-07-15 12:55 ` [PATCH v2 6/9] power: supply: max77693: Add USB extcon detection for enabling charging Artur Weber
2024-07-20 20:59   ` Artur Weber
2024-07-15 12:55 ` [PATCH v2 7/9] power: supply: max77693: Add support for detecting and enabling OTG Artur Weber
2024-07-25 15:38   ` Lee Jones
2024-07-15 12:55 ` [PATCH v2 8/9] ARM: dts: samsung: exynos4212-tab3: Add battery node with charge current value Artur Weber
2024-07-15 12:55 ` [PATCH v2 9/9] ARM: dts: samsung: exynos4212-tab3: Add USB connector node Artur Weber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240715-max77693-charger-extcon-v2-4-0838ffbb18c3@gmail.com \
    --to=aweber.kernel@gmail.com \
    --cc=GNUtoo@cyberdimension.org \
    --cc=alim.akhtar@samsung.com \
    --cc=conor+dt@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=henrik@grimler.se \
    --cc=krzk+dt@kernel.org \
    --cc=krzk@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sre@kernel.org \
    --cc=wolfgit@wiedmeyer.de \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).