Skip to contentSkip to conversation

ACPI / AC: Notify when state changes in get_ac_property

PATCH In review Alexander Mezin 2 participants 10 messages Feb 7, 2014 – Feb 10, 2014 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ACPI / AC: Notify when state changes in get_ac_property

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.

---
 drivers/acpi/ac.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/acpi/ac.c +4 -0
index e7515aa..cdba639 100644
@@ -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:
Signature · 1 line
1.8.5.4
#1 lore raw

PATCH 2/2 ACPI / battery: check AC adapter's state when battery state changes

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.

---
 drivers/acpi/battery.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/acpi/battery.c +22 -0
index 470e754..68b263c 100644
@@ -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;
 }
 
Signature · 1 line
1.8.5.4
#2 lore raw
In reply to Alexander Mezin

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 7 lines

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.

Quoted 5 lines

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.

Quoted 34 lines
---
 drivers/acpi/ac.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/acpi/ac.c +4 -1
index e7515aa..cdba639 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards
Tianyu Lan
#3 lore raw

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 14 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 7 lines

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.

Quoted 5 lines

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

Aforementioned commit could be reverted.

Quoted 7 lines

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?

#4 lore raw

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 23 lines

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 14 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 7 lines

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.

Quoted 5 lines

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

Aforementioned commit could be reverted.

Quoted 7 lines

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.

Quoted 4 lines

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.

Signature · 2 lines
Best regards
Tianyu Lan
#5 lore raw

2014-02-10 8:29 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 6 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 1 line

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

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.

#6 lore raw

2014-02-10 10:16 GMT+08:00 Alexander Mezin <[email protected]>:

Quoted 8 lines

2014-02-10 8:29 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 6 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 1 line

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

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.

Quoted 4 lines

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.

Signature · 2 lines
Best regards
Tianyu Lan
#7 lore raw

2014-02-10 Lan Tianyu <[email protected]>:

Quoted 11 lines

2014-02-10 10:16 GMT+08:00 Alexander Mezin <[email protected]>:

Quoted 8 lines

2014-02-10 8:29 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 6 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 1 line

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

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?

Quoted 11 lines
Quoted 5 lines

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

Signature · 2 lines
Best regards
Tianyu Lan
#8 lore raw

2014-02-10 9:34 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 5 lines

2014-02-10 Lan Tianyu <[email protected]>:

Quoted 4 lines

2014-02-10 10:16 GMT+08:00 Alexander Mezin <[email protected]>:

Quoted 3 lines

2014-02-10 8:29 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 2 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 1 line

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

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.

#9 lore raw

2014-02-10 Alexander Mezin <[email protected]>:

Quoted 10 lines

2014-02-10 9:34 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 9 lines

2014-02-10 Lan Tianyu <[email protected]>:

Quoted 8 lines

2014-02-10 10:16 GMT+08:00 Alexander Mezin <[email protected]>:

Quoted 7 lines

2014-02-10 8:29 GMT+07:00 Lan Tianyu <[email protected]>:

Quoted 6 lines

2014-02-08 Alexander Mezin <[email protected]>:

Quoted 1 line

2014-02-08 13:33 GMT+07:00 Lan Tianyu <[email protected]>:

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.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

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?

Signature · 2 lines
Best regards
Tianyu Lan