All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
@ 2014-02-07 19:28 Alexander Mezin
  2014-02-07 19:28 ` [PATCH 2/2] ACPI / battery: check AC adapter's state when battery state changes Alexander Mezin
  2014-02-08  6:33 ` [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Lan Tianyu
  0 siblings, 2 replies; 10+ messages in thread
From: Alexander Mezin @ 2014-02-07 19:28 UTC (permalink / raw)
  To: linux-acpi; +Cc: Alexander Mezin

Do the same thing as in acpi_ac_resume.

BIOS on my laptop (HP Pavilion dv6-6179er) don't send proper
notifications when AC adapter is plugged/unplugged.
This change makes it possible to workaround the problem by using
acpid and a shell script.

This patch has the same effect as
commit 50a2bc5429f07ec4d53df2d287b03bdbceb281bb
"ACPI / AC: change notification handler type to ACPI_ALL_NOTIFY"

Aforementioned commit could be reverted.

Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>
---
 drivers/acpi/ac.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index e7515aa..cdba639 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -90,12 +90,16 @@ static int get_ac_property(struct power_supply *psy,
 			   union power_supply_propval *val)
 {
 	struct acpi_ac *ac = to_acpi_ac(psy);
+	unsigned long long old_state;
 
 	if (!ac)
 		return -ENODEV;
 
+	old_state = ac->state;
 	if (acpi_ac_get_state(ac))
 		return -ENODEV;
+	if (old_state != ac->state)
+		kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_ONLINE:
-- 
1.8.5.4


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

* [PATCH 2/2] ACPI / battery: check AC adapter's state when battery state changes
  2014-02-07 19:28 [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Alexander Mezin
@ 2014-02-07 19:28 ` Alexander Mezin
  2014-02-08  6:33 ` [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Lan Tianyu
  1 sibling, 0 replies; 10+ messages in thread
From: Alexander Mezin @ 2014-02-07 19:28 UTC (permalink / raw)
  To: linux-acpi; +Cc: Alexander Mezin

When battery state changes (i. e. it starts to charge/discharge),
it could indicate that AC adapter has been plugged or unplugged.

When POWER_SUPPLY_PROP_ONLINE is read, AC driver should check actual
adapter state, and emit notification if the state has changed
(my previous patch).

This patch finally solves the problem with AC notifications on my
HP Pavilion dv6-6179er.

Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>
---
 drivers/acpi/battery.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 470e754..68b263c 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -671,9 +671,22 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
 	}
 }
 
+static int acpi_battery_check_ac_state(struct device *dev, void *unused)
+{
+	struct power_supply *ps = dev_get_drvdata(dev);
+	union power_supply_propval temp;
+
+	if (ps->type != POWER_SUPPLY_TYPE_MAINS)
+		return 0;
+
+	ps->get_property(ps, POWER_SUPPLY_PROP_ONLINE, &temp);
+	return 0;
+}
+
 static int acpi_battery_update(struct acpi_battery *battery)
 {
 	int result, old_present = acpi_battery_present(battery);
+	int old_state = battery->state;
 	result = acpi_battery_get_status(battery);
 	if (result)
 		return result;
@@ -696,6 +709,15 @@ static int acpi_battery_update(struct acpi_battery *battery)
 	}
 	result = acpi_battery_get_state(battery);
 	acpi_battery_quirks(battery);
+	if (old_state != battery->state)
+		/*
+		 * Some BIOSes don't send notifications when ac adapter
+		 * is plugged or unplugged.
+		 * If battery changes its state, this could indicate that
+		 * AC adapter's state has changed too.
+		 */
+		class_for_each_device(power_supply_class, NULL, NULL,
+				      &acpi_battery_check_ac_state);
 	return result;
 }
 
-- 
1.8.5.4


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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-07 19:28 [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Alexander Mezin
  2014-02-07 19:28 ` [PATCH 2/2] ACPI / battery: check AC adapter's state when battery state changes Alexander Mezin
@ 2014-02-08  6:33 ` Lan Tianyu
  2014-02-08  8:33   ` Alexander Mezin
  1 sibling, 1 reply; 10+ messages in thread
From: Lan Tianyu @ 2014-02-08  6:33 UTC (permalink / raw)
  To: Alexander Mezin; +Cc: linux-acpi

2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
> Do the same thing as in acpi_ac_resume.
>
> BIOS on my laptop (HP Pavilion dv6-6179er) don't send proper
> notifications when AC adapter is plugged/unplugged.
> This change makes it possible to workaround the problem by using
> acpid and a shell script.
>
> This patch has the same effect as
> commit 50a2bc5429f07ec4d53df2d287b03bdbceb281bb
> "ACPI / AC: change notification handler type to ACPI_ALL_NOTIFY"
>
> Aforementioned commit could be reverted.

Hi Alexander:
             I don't think the previous commit can be reverted. AC driver
should get system notify events(E,G bus check event) and  process them.
Some drivers(E,G radeon) also need to know AC event and AC driver's
notify handler sends the event to these drivers via block notifier call chain.
Further more, this patch only works when the related sysfs interfaces are
accessed. It's redundant with previous commit.

>
> Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>
> ---
>  drivers/acpi/ac.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
> index e7515aa..cdba639 100644
> --- a/drivers/acpi/ac.c
> +++ b/drivers/acpi/ac.c
> @@ -90,12 +90,16 @@ static int get_ac_property(struct power_supply *psy,
>                            union power_supply_propval *val)
>  {
>         struct acpi_ac *ac = to_acpi_ac(psy);
> +       unsigned long long old_state;
>
>         if (!ac)
>                 return -ENODEV;
>
> +       old_state = ac->state;
>         if (acpi_ac_get_state(ac))
>                 return -ENODEV;
> +       if (old_state != ac->state)
> +               kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
>
>         switch (psp) {
>         case POWER_SUPPLY_PROP_ONLINE:
> --
> 1.8.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best regards
Tianyu Lan

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-08  6:33 ` [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Lan Tianyu
@ 2014-02-08  8:33   ` Alexander Mezin
  2014-02-10  1:29     ` Lan Tianyu
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Mezin @ 2014-02-08  8:33 UTC (permalink / raw)
  To: Lan Tianyu; +Cc: linux-acpi

2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>> Do the same thing as in acpi_ac_resume.
>>
>> BIOS on my laptop (HP Pavilion dv6-6179er) don't send proper
>> notifications when AC adapter is plugged/unplugged.
>> This change makes it possible to workaround the problem by using
>> acpid and a shell script.
>>
>> This patch has the same effect as
>> commit 50a2bc5429f07ec4d53df2d287b03bdbceb281bb
>> "ACPI / AC: change notification handler type to ACPI_ALL_NOTIFY"
>>
>> Aforementioned commit could be reverted.
>
> Hi Alexander:
>              I don't think the previous commit can be reverted. AC driver
> should get system notify events(E,G bus check event) and  process them.
> Some drivers(E,G radeon) also need to know AC event and AC driver's
> notify handler sends the event to these drivers via block notifier call chain.
> Further more, this patch only works when the related sysfs interfaces are
> accessed. It's redundant with previous commit.

OK, I didn't think about other drivers and so.

Second patch works fine on its own (if old commit isn't reverted, of course),
I've tested it just now. Should I resend it as single patch?

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-08  8:33   ` Alexander Mezin
@ 2014-02-10  1:29     ` Lan Tianyu
  2014-02-10  2:16       ` Alexander Mezin
  0 siblings, 1 reply; 10+ messages in thread
From: Lan Tianyu @ 2014-02-10  1:29 UTC (permalink / raw)
  To: Alexander Mezin; +Cc: linux-acpi

2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>>> Do the same thing as in acpi_ac_resume.
>>>
>>> BIOS on my laptop (HP Pavilion dv6-6179er) don't send proper
>>> notifications when AC adapter is plugged/unplugged.
>>> This change makes it possible to workaround the problem by using
>>> acpid and a shell script.
>>>
>>> This patch has the same effect as
>>> commit 50a2bc5429f07ec4d53df2d287b03bdbceb281bb
>>> "ACPI / AC: change notification handler type to ACPI_ALL_NOTIFY"
>>>
>>> Aforementioned commit could be reverted.
>>
>> Hi Alexander:
>>              I don't think the previous commit can be reverted. AC driver
>> should get system notify events(E,G bus check event) and  process them.
>> Some drivers(E,G radeon) also need to know AC event and AC driver's
>> notify handler sends the event to these drivers via block notifier call chain.
>> Further more, this patch only works when the related sysfs interfaces are
>> accessed. It's redundant with previous commit.
>
> OK, I didn't think about other drivers and so.
>
> Second patch works fine on its own (if old commit isn't reverted, of course),
> I've tested it just now. Should I resend it as single patch?

Hi:
       What's the benefit of the second patch without this patch?
So far, bios sends the ACPI notify event of power change to AC driver and
the driver would change status and send uevent. That seems enough.

BTW, battery status update normally is also triggered by ACPI notify event.
-- 
Best regards
Tianyu Lan

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-10  1:29     ` Lan Tianyu
@ 2014-02-10  2:16       ` Alexander Mezin
  2014-02-10  2:27         ` Lan Tianyu
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Mezin @ 2014-02-10  2:16 UTC (permalink / raw)
  To: Lan Tianyu; +Cc: linux-acpi

2014-02-10 8:29 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
> Hi:
>        What's the benefit of the second patch without this patch?
> So far, bios sends the ACPI notify event of power change to AC driver and
> the driver would change status and send uevent. That seems enough.
Without second patch AC adapter's status isn't updated on my laptop.
AC status updates only if I run "acpi -a". I usually automated this
with acpid.
On my laptop only battery notifications are working fine.
With second patch (and without first) everything works as it should.

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-10  2:16       ` Alexander Mezin
@ 2014-02-10  2:27         ` Lan Tianyu
  2014-02-10  2:34           ` Lan Tianyu
  0 siblings, 1 reply; 10+ messages in thread
From: Lan Tianyu @ 2014-02-10  2:27 UTC (permalink / raw)
  To: Alexander Mezin; +Cc: linux-acpi

2014-02-10 10:16 GMT+08:00 Alexander Mezin <mezin.alexander@gmail.com>:
> 2014-02-10 8:29 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>>> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>> Hi:
>>        What's the benefit of the second patch without this patch?
>> So far, bios sends the ACPI notify event of power change to AC driver and
>> the driver would change status and send uevent. That seems enough.
> Without second patch AC adapter's status isn't updated on my laptop.

commit 50a2bc5429f can't fix this issue.

> AC status updates only if I run "acpi -a". I usually automated this
> with acpid.
> On my laptop only battery notifications are working fine.
> With second patch (and without first) everything works as it should.



-- 
Best regards
Tianyu Lan

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-10  2:27         ` Lan Tianyu
@ 2014-02-10  2:34           ` Lan Tianyu
  2014-02-10  2:47             ` Alexander Mezin
  0 siblings, 1 reply; 10+ messages in thread
From: Lan Tianyu @ 2014-02-10  2:34 UTC (permalink / raw)
  To: Alexander Mezin; +Cc: linux-acpi

2014-02-10 Lan Tianyu <lantianyu1986@gmail.com>:
> 2014-02-10 10:16 GMT+08:00 Alexander Mezin <mezin.alexander@gmail.com>:
>> 2014-02-10 8:29 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>>>> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>> Hi:
>>>        What's the benefit of the second patch without this patch?
>>> So far, bios sends the ACPI notify event of power change to AC driver and
>>> the driver would change status and send uevent. That seems enough.
>> Without second patch AC adapter's status isn't updated on my laptop.
>
> commit 50a2bc5429f can't fix this issue.
Sorry. commit 50a2bc5429f can't fix this issue?
>
>> AC status updates only if I run "acpi -a". I usually automated this
>> with acpid.
>> On my laptop only battery notifications are working fine.
>> With second patch (and without first) everything works as it should.
>
>
>
> --
> Best regards
> Tianyu Lan



-- 
Best regards
Tianyu Lan

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-10  2:34           ` Lan Tianyu
@ 2014-02-10  2:47             ` Alexander Mezin
  2014-02-10  3:15               ` Lan Tianyu
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Mezin @ 2014-02-10  2:47 UTC (permalink / raw)
  To: Lan Tianyu; +Cc: linux-acpi

2014-02-10 9:34 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
> 2014-02-10 Lan Tianyu <lantianyu1986@gmail.com>:
>> 2014-02-10 10:16 GMT+08:00 Alexander Mezin <mezin.alexander@gmail.com>:
>>> 2014-02-10 8:29 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>>> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>>>>> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>>> Hi:
>>>>        What's the benefit of the second patch without this patch?
>>>> So far, bios sends the ACPI notify event of power change to AC driver and
>>>> the driver would change status and send uevent. That seems enough.
>>> Without second patch AC adapter's status isn't updated on my laptop.
>>
>> commit 50a2bc5429f can't fix this issue.
> Sorry. commit 50a2bc5429f can't fix this issue?
No, it doesn't solve the problem. But before it AC state didn't update
even when I run "acpi -a". There was no way other than reboot.

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

* Re: [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property
  2014-02-10  2:47             ` Alexander Mezin
@ 2014-02-10  3:15               ` Lan Tianyu
  0 siblings, 0 replies; 10+ messages in thread
From: Lan Tianyu @ 2014-02-10  3:15 UTC (permalink / raw)
  To: Alexander Mezin; +Cc: linux-acpi

2014-02-10 Alexander Mezin <mezin.alexander@gmail.com>:
> 2014-02-10 9:34 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>> 2014-02-10 Lan Tianyu <lantianyu1986@gmail.com>:
>>> 2014-02-10 10:16 GMT+08:00 Alexander Mezin <mezin.alexander@gmail.com>:
>>>> 2014-02-10 8:29 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>>>> 2014-02-08 Alexander Mezin <mezin.alexander@gmail.com>:
>>>>>> 2014-02-08 13:33 GMT+07:00 Lan Tianyu <lantianyu1986@gmail.com>:
>>>>> Hi:
>>>>>        What's the benefit of the second patch without this patch?
>>>>> So far, bios sends the ACPI notify event of power change to AC driver and
>>>>> the driver would change status and send uevent. That seems enough.
>>>> Without second patch AC adapter's status isn't updated on my laptop.
>>>
>>> commit 50a2bc5429f can't fix this issue.
>> Sorry. commit 50a2bc5429f can't fix this issue?
> No, it doesn't solve the problem. But before it AC state didn't update
> even when I run "acpi -a". There was no way other than reboot.

Ok. You mean AC state didn't update before running "acpi -a" with commit
50a2bc5429f, right?

How do you check the AC state? via /sys/class/power_supply/ACXX/online?

What does acpi_listen show when plug or unplug adaptor?

-- 
Best regards
Tianyu Lan

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

end of thread, other threads:[~2014-02-10  3:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-07 19:28 [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Alexander Mezin
2014-02-07 19:28 ` [PATCH 2/2] ACPI / battery: check AC adapter's state when battery state changes Alexander Mezin
2014-02-08  6:33 ` [PATCH 1/2] ACPI / AC: Notify when state changes in get_ac_property Lan Tianyu
2014-02-08  8:33   ` Alexander Mezin
2014-02-10  1:29     ` Lan Tianyu
2014-02-10  2:16       ` Alexander Mezin
2014-02-10  2:27         ` Lan Tianyu
2014-02-10  2:34           ` Lan Tianyu
2014-02-10  2:47             ` Alexander Mezin
2014-02-10  3:15               ` Lan Tianyu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.