From: Dzmitry Sankouski <dsankouski@gmail.com>
To: Chanwoo Choi <cw00.choi@samsung.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Lee Jones <lee@kernel.org>, Sebastian Reichel <sre@kernel.org>,
Luca Ceresoli <luca.ceresoli@bootlin.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Dzmitry Sankouski <dsankouski@gmail.com>
Subject: [PATCH 8/9] power: supply: max77705_charger: implement aicl feature
Date: Sat, 30 Aug 2025 23:45:21 +0300 [thread overview]
Message-ID: <20250830-max77705_77976_charger_improvement-v1-8-e976db3fd432@gmail.com> (raw)
In-Reply-To: <20250830-max77705_77976_charger_improvement-v1-0-e976db3fd432@gmail.com>
Adaptive input current allows charger to reduce it's current
consumption, when source is not able to provide enough power.
Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
---
drivers/power/supply/max77705_charger.c | 60 +++++++++++++++++++++++++++++++++
include/linux/power/max77705_charger.h | 5 +++
2 files changed, 65 insertions(+)
diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c
index aa0ffa1fde39..a82e32483ae5 100644
--- a/drivers/power/supply/max77705_charger.c
+++ b/drivers/power/supply/max77705_charger.c
@@ -40,6 +40,16 @@ static enum power_supply_property max77705_charger_props[] = {
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
};
+static irqreturn_t max77705_aicl_irq(int irq, void *irq_drv_data)
+{
+ struct max77705_charger_data *chg = irq_drv_data;
+
+ queue_delayed_work(chg->wqueue, &chg->aicl_work,
+ msecs_to_jiffies(AICL_WORK_DELAY));
+
+ return IRQ_HANDLED;
+}
+
static irqreturn_t max77705_chgin_irq(int irq, void *irq_drv_data)
{
struct max77705_charger_data *chg = irq_drv_data;
@@ -445,6 +455,40 @@ static const struct power_supply_desc max77705_charger_psy_desc = {
.set_property = max77705_set_property,
};
+static void max77705_aicl_isr_work(struct work_struct *work)
+{
+ unsigned int regval, irq_status;
+ int err;
+ struct max77705_charger_data *chg =
+ container_of(work, struct max77705_charger_data, aicl_work.work);
+
+ regmap_read(chg->regmap, MAX77705_CHG_REG_INT_OK, &irq_status);
+ if (!chg->is_aicl_irq_disabled) {
+ disable_irq(chg->aicl_irq);
+ chg->is_aicl_irq_disabled = true;
+ }
+
+ if (!(irq_status & BIT(MAX77705_AICL_I))) {
+ err = regmap_field_read(chg->rfield[MAX77705_CHG_CHGIN_LIM], ®val);
+ if (err < 0)
+ return;
+
+ regval--;
+
+ pr_info("aicl call. regval: %d\n", regval);
+ err = regmap_field_write(chg->rfield[MAX77705_CHG_CHGIN_LIM], regval);
+ if (err < 0)
+ return;
+
+ queue_delayed_work(chg->wqueue, &chg->aicl_work,
+ msecs_to_jiffies(AICL_WORK_DELAY));
+ } else {
+ pr_info("aicl finish\n");
+ enable_irq(chg->aicl_irq);
+ chg->is_aicl_irq_disabled = false;
+ }
+}
+
static void max77705_chgin_isr_work(struct work_struct *work)
{
struct max77705_charger_data *chg =
@@ -616,6 +660,16 @@ static int max77705_charger_probe(struct i2c_client *i2c)
return ret;
}
+ chg->aicl_irq = regmap_irq_get_virq(irq_data, MAX77705_AICL_I);
+ ret = devm_request_threaded_irq(dev, chg->aicl_irq,
+ NULL, max77705_aicl_irq,
+ IRQF_TRIGGER_HIGH,
+ "aicl-irq", chg);
+ if (ret) {
+ pr_err("%s: Failed to Request IRQ (%d)\n", __func__, ret);
+ return ret;
+ }
+
chg->wqueue = create_singlethread_workqueue(dev_name(dev));
if (!chg->wqueue)
return dev_err_probe(dev, -ENOMEM, "failed to create workqueue\n");
@@ -626,6 +680,12 @@ static int max77705_charger_probe(struct i2c_client *i2c)
goto destroy_wq;
}
+ ret = devm_delayed_work_autocancel(dev, &chg->aicl_work, max77705_aicl_isr_work);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to initialize interrupt work\n");
+ goto destroy_wq;
+ }
+
ret = max77705_charger_initialize(chg);
if (ret) {
dev_err_probe(dev, ret, "failed to initialize charger IC\n");
diff --git a/include/linux/power/max77705_charger.h b/include/linux/power/max77705_charger.h
index df1d46ff9527..da048dda4e44 100644
--- a/include/linux/power/max77705_charger.h
+++ b/include/linux/power/max77705_charger.h
@@ -124,6 +124,8 @@
#define MAX77705_DISABLE_SKIP 1
#define MAX77705_AUTO_SKIP 0
+#define AICL_WORK_DELAY 100
+
/* uA */
#define MAX77705_CURRENT_CHGIN_STEP 25000
#define MAX77705_CURRENT_CHG_STEP 50000
@@ -186,7 +188,10 @@ struct max77705_charger_data {
struct power_supply_battery_info *bat_info;
struct workqueue_struct *wqueue;
struct work_struct chgin_work;
+ struct delayed_work aicl_work;
struct power_supply *psy_chg;
+ int is_aicl_irq_disabled;
+ int aicl_irq;
};
#endif /* __MAX77705_CHARGER_H */
--
2.39.5
next prev parent reply other threads:[~2025-08-30 20:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-30 20:45 [PATCH 0/9] power: supply: fixes and improvements for max77(705,976) chargers Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 1/9] power: supply: max77705_charger: move active discharge setting to mfd parent Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 2/9] power: supply: max77705_charger: refactoring: rename charger to chg Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 3/9] power: supply: max77705_charger: use regfields for config registers Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 4/9] power: supply: max77705_charger: return error when config fails Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 5/9] power: supply: max77705_charger: add writable properties Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 6/9] power: supply: max77705_charger: rework interrupts Dzmitry Sankouski
2025-08-30 20:45 ` [PATCH 7/9] power: supply: max77705_charger: use REGMAP_IRQ_REG_LINE macro Dzmitry Sankouski
2025-08-30 20:45 ` Dzmitry Sankouski [this message]
2025-08-30 20:45 ` [PATCH 9/9] power: supply: max77976_charger: fix constant current reporting Dzmitry Sankouski
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=20250830-max77705_77976_charger_improvement-v1-8-e976db3fd432@gmail.com \
--to=dsankouski@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=krzk@kernel.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=sebastian.reichel@collabora.com \
--cc=sre@kernel.org \
/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