Skip to contentSkip to conversation

power: supply: bq2415x_charger: Immediately queue delayed work on supply change events

PATCH Applied Sicelo A. Mhlongo 2 participants 4 messages Nov 28, 2024 – Dec 19, 2024

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 power: supply: bq2415x_charger: Immediately queue delayed work on supply change events

bq2415x_notifier_call is called asynchronously, when a change is notified from the external notify device. Therefore, reschedule the work item to run as soon as possible thereafter.

---
 drivers/power/supply/bq2415x_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/bq2415x_charger.c +1 -1
index 25e28dac900d..1a02195769a3 100644
@@ -839,7 +839,7 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
 	if (bq->automode < 1)
 		return NOTIFY_OK;
 
-	schedule_delayed_work(&bq->work, 0);
+	mod_delayed_work(system_wq, &bq->work, 0);
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 power: supply: bq2415x_charger: report charging state changes to userspace

Continuously track the charging status register in order to send uevents whenever the state changes. Generate an uevent also when the chip's OTG line is toggled, in bq2415x_notifier_call().

---
 drivers/power/supply/bq2415x_charger.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/power/supply/bq2415x_charger.c +10 -0
index 1a02195769a3..0234f7724872 100644
@@ -171,6 +171,7 @@ struct bq2415x_device {
 	char *name;
 	int autotimer;	/* 1 - if driver automatically reset timer, 0 - not */
 	int automode;	/* 1 - enabled, 0 - disabled; -1 - not supported */
+	int charge_status;
 	int id;
 };
 
@@ -835,6 +836,8 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
 	if (!bq2415x_update_reported_mode(bq, prop.intval))
 		return NOTIFY_OK;
 
+	power_supply_changed(bq->charger);
+
 	/* if automode is not enabled do not tell about reported_mode */
 	if (bq->automode < 1)
 		return NOTIFY_OK;
@@ -889,12 +892,19 @@ static void bq2415x_timer_work(struct work_struct *work)
 	int ret;
 	int error;
 	int boost;
+	int charge;
 
 	if (bq->automode > 0 && (bq->reported_mode != bq->mode)) {
 		sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode");
 		bq2415x_set_mode(bq, bq->reported_mode);
 	}
 
+	charge = bq2415x_exec_command(bq, BQ2415X_CHARGE_STATUS);
+	if (bq->charge_status != charge) {
+		power_supply_changed(bq->charger);
+		bq->charge_status = charge;
+	}
+
 	if (!bq->autotimer)
 		return;
 
Signature · 1 line
2.45.2
#2 lore raw
In reply to Sicelo A. Mhlongo

Hi,

Quoted 7 lines · Sicelo A. Mhlongo

bq2415x_notifier_call is called asynchronously, when a change is notified from the external notify device. Therefore, reschedule the work item to run as soon as possible thereafter.

---

The commit message reads quite weird, but the code change makes sense to me. I think something like this commit message makes more sense:

When the notifier is called we want to schedule the worker as soon as possible. Thus it makes sense to reschedule any waiting work and only queue a new one if there is none.

Greetings,

-- Sebastian

Quoted 20 lines
 drivers/power/supply/bq2415x_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/bq2415x_charger.c +1 -1
index 25e28dac900d..1a02195769a3 100644
@@ -839,7 +839,7 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
 	if (bq->automode < 1)
 		return NOTIFY_OK;
 
-	schedule_delayed_work(&bq->work, 0);
+	mod_delayed_work(system_wq, &bq->work, 0);
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.45.2
#3 lore raw

Re: (subset) [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events

In reply to Sicelo A. Mhlongo
Quoted 5 lines · Sicelo A. Mhlongo

bq2415x_notifier_call is called asynchronously, when a change is notified from the external notify device. Therefore, reschedule the work item to run as soon as possible thereafter.

Applied, thanks!

[2/2] power: supply: bq2415x_charger: report charging state changes to userspace

      commit: 5972da73f75af6002b72e5cd61002855b6b4eda3

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>