From: Alexander Mezin <mezin.alexander@gmail.com>
To: linux-acpi@vger.kernel.org
Cc: Lan Tianyu <tianyu.lan@intel.com>,
Alexander Mezin <mezin.alexander@gmail.com>
Subject: [PATCH 2/2] ACPI / AC: recheck adapter status upon battery notifications
Date: Mon, 10 Mar 2014 05:37:32 +0700 [thread overview]
Message-ID: <1394404652-5873-2-git-send-email-mezin.alexander@gmail.com> (raw)
In-Reply-To: <1394404652-5873-1-git-send-email-mezin.alexander@gmail.com>
On HP Pavilion dv6-6179er there are no notifications when AC adapter
is plugged/unplugged.
However, when AC status is read (acpi_ac_get_state), and if AC status
has changed, AML code triggers the notification.
This patch solves the problem by re-reading AC adapter status upon
battery notifications.
Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>
---
drivers/acpi/ac.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 6f190bc..1d3903e 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -44,6 +44,8 @@
#define ACPI_AC_STATUS_ONLINE 0x01
#define ACPI_AC_STATUS_UNKNOWN 0xFF
+#define ACPI_BATTERY_CLASS "battery"
+
#define _COMPONENT ACPI_AC_COMPONENT
ACPI_MODULE_NAME("ac");
@@ -57,6 +59,7 @@ struct acpi_ac {
struct power_supply charger;
struct platform_device *pdev;
unsigned long long state;
+ struct notifier_block battery_nb;
};
#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)
@@ -152,6 +155,18 @@ static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
return;
}
+static int acpi_ac_battery_notify(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct acpi_ac *ac = container_of(nb, struct acpi_ac, battery_nb);
+ struct acpi_bus_event *event = (struct acpi_bus_event *)data;
+
+ if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0)
+ acpi_ac_get_state(ac);
+
+ return NOTIFY_OK;
+}
+
static int thinkpad_e530_quirk(const struct dmi_system_id *d)
{
ac_sleep_before_get_state_ms = 1000;
@@ -215,6 +230,8 @@ static int acpi_ac_probe(struct platform_device *pdev)
acpi_device_name(adev), acpi_device_bid(adev),
ac->state ? "on-line" : "off-line");
+ ac->battery_nb.notifier_call = acpi_ac_battery_notify;
+ register_acpi_notifier(&ac->battery_nb);
end:
if (result)
kfree(ac);
@@ -261,6 +278,7 @@ static int acpi_ac_remove(struct platform_device *pdev)
ac = platform_get_drvdata(pdev);
if (ac->charger.dev)
power_supply_unregister(&ac->charger);
+ unregister_acpi_notifier(&ac->battery_nb);
kfree(ac);
--
1.9.0
next prev parent reply other threads:[~2014-03-09 22:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-09 22:37 [PATCH 1/2] ACPI / battery: call ACPI notifier chain in acpi_battery_notify Alexander Mezin
2014-03-09 22:37 ` Alexander Mezin [this message]
2014-03-09 23:11 ` [PATCH 2/2] ACPI / AC: recheck adapter status upon battery notifications Rafael J. Wysocki
2014-03-09 23:21 ` Alexander Mezin
2014-03-10 0:17 ` Rafael J. Wysocki
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=1394404652-5873-2-git-send-email-mezin.alexander@gmail.com \
--to=mezin.alexander@gmail.com \
--cc=linux-acpi@vger.kernel.org \
--cc=tianyu.lan@intel.com \
/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