mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events
@ 2024-11-28  8:57 Sicelo A. Mhlongo
  2024-11-28  8:57 ` [PATCH 2/2] power: supply: bq2415x_charger: report charging state changes to userspace Sicelo A. Mhlongo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sicelo A. Mhlongo @ 2024-11-28  8:57 UTC (permalink / raw)
  To: linux-pm
  Cc: pali, sre, linux-kernel, maemo-leste, Sicelo A. Mhlongo, Ivaylo Dimitrov

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.

Suggested-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
---
 drivers/power/supply/bq2415x_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c
index 25e28dac900d..1a02195769a3 100644
--- a/drivers/power/supply/bq2415x_charger.c
+++ b/drivers/power/supply/bq2415x_charger.c
@@ -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;
 }
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] power: supply: bq2415x_charger: report charging state changes to userspace
  2024-11-28  8:57 [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sicelo A. Mhlongo
@ 2024-11-28  8:57 ` Sicelo A. Mhlongo
  2024-12-19  0:08 ` [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sebastian Reichel
  2024-12-19  0:11 ` (subset) " Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sicelo A. Mhlongo @ 2024-11-28  8:57 UTC (permalink / raw)
  To: linux-pm; +Cc: pali, sre, linux-kernel, maemo-leste, Sicelo A. Mhlongo

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().

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
---
 drivers/power/supply/bq2415x_charger.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c
index 1a02195769a3..0234f7724872 100644
--- a/drivers/power/supply/bq2415x_charger.c
+++ b/drivers/power/supply/bq2415x_charger.c
@@ -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;
 
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events
  2024-11-28  8:57 [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sicelo A. Mhlongo
  2024-11-28  8:57 ` [PATCH 2/2] power: supply: bq2415x_charger: report charging state changes to userspace Sicelo A. Mhlongo
@ 2024-12-19  0:08 ` Sebastian Reichel
  2024-12-19  0:11 ` (subset) " Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2024-12-19  0:08 UTC (permalink / raw)
  To: Sicelo A. Mhlongo
  Cc: linux-pm, pali, linux-kernel, maemo-leste, Ivaylo Dimitrov

[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]

Hi,

On Thu, Nov 28, 2024 at 10:57:27AM +0200, Sicelo A. Mhlongo wrote:
> 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.
> 
> Suggested-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
> ---

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

>  drivers/power/supply/bq2415x_charger.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c
> index 25e28dac900d..1a02195769a3 100644
> --- a/drivers/power/supply/bq2415x_charger.c
> +++ b/drivers/power/supply/bq2415x_charger.c
> @@ -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;
>  }
> -- 
> 2.45.2
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (subset) [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events
  2024-11-28  8:57 [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sicelo A. Mhlongo
  2024-11-28  8:57 ` [PATCH 2/2] power: supply: bq2415x_charger: report charging state changes to userspace Sicelo A. Mhlongo
  2024-12-19  0:08 ` [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sebastian Reichel
@ 2024-12-19  0:11 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2024-12-19  0:11 UTC (permalink / raw)
  To: linux-pm, Sicelo A. Mhlongo
  Cc: pali, sre, linux-kernel, maemo-leste, Ivaylo Dimitrov


On Thu, 28 Nov 2024 10:57:27 +0200, Sicelo A. Mhlongo wrote:
> 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,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-19  0:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-28  8:57 [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sicelo A. Mhlongo
2024-11-28  8:57 ` [PATCH 2/2] power: supply: bq2415x_charger: report charging state changes to userspace Sicelo A. Mhlongo
2024-12-19  0:08 ` [PATCH 1/2] power: supply: bq2415x_charger: Immediately queue delayed work on supply change events Sebastian Reichel
2024-12-19  0:11 ` (subset) " Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®