From patchwork Tue Mar 11 17:58:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mezin X-Patchwork-Id: 3813681 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D4F039F38E for ; Tue, 11 Mar 2014 18:01:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 043202021F for ; Tue, 11 Mar 2014 18:01:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 162FD2021A for ; Tue, 11 Mar 2014 18:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753861AbaCKSBo (ORCPT ); Tue, 11 Mar 2014 14:01:44 -0400 Received: from mail-lb0-f172.google.com ([209.85.217.172]:41291 "EHLO mail-lb0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753668AbaCKSBn (ORCPT ); Tue, 11 Mar 2014 14:01:43 -0400 Received: by mail-lb0-f172.google.com with SMTP id c11so5916589lbj.31 for ; Tue, 11 Mar 2014 11:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wMgmqBV3N/Jpt5KbGlycE/KIAN9XY9TZBr+1A86K25Y=; b=UCOhuF0pQxp2Uhz7+wmhI65HAOcUNvpu9mq16qyyjhMmDFJPtuMi7DvFPEF9Musvio 3BUvJXlAsJkZ6u69qMGZ8tCs1uiBrAiCD3UgM0W4GJWLD9MWZUMR8h2TM7C2/5S+It6j 6xZqO088wD50dUupNhMiglfVTQSGI+54p9rKuE9Iujsf3OO+z944MBShsdo//r3AF3I6 VX4I5lcJwWrO63FbBqbGzn7OjjpGnIpcY9zKfMsYxnAM7ubcZm1w0VRvImkfppG4hDBF /rxIqtM5zxMZjPxV3N/gmQiP9hjOSYW97C/XS997iqrImDUENAsE7vhF7ADZT3bb1nXY leWA== X-Received: by 10.112.171.1 with SMTP id aq1mr154475lbc.67.1394560902349; Tue, 11 Mar 2014 11:01:42 -0700 (PDT) Received: from localhost.localdomain ([188.232.137.148]) by mx.google.com with ESMTPSA id x4sm25908186lbn.2.2014.03.11.11.01.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Mar 2014 11:01:41 -0700 (PDT) From: Alexander Mezin To: linux-acpi@vger.kernel.org Cc: Alexander Mezin Subject: [PATCH v2 3/3] ACPI / AC: recheck adapter status upon battery status changes Date: Wed, 12 Mar 2014 00:58:48 +0700 Message-Id: <1394560728-14048-3-git-send-email-mezin.alexander@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394560728-14048-1-git-send-email-mezin.alexander@gmail.com> References: <1394560728-14048-1-git-send-email-mezin.alexander@gmail.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 ACPI_BATTERY_NOTIFY_STATUS notification. Signed-off-by: Alexander Mezin Acked-by: Lan Tianyu --- v2: watch only for ACPI_BATTERY_NOTIFY_STATUS, add comment drivers/acpi/ac.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 6f190bc..2c01c1d 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -33,6 +33,7 @@ #include #include #include +#include "battery.h" #define PREFIX "ACPI: " @@ -57,6 +58,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 +154,26 @@ 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; + + /* + * On HP Pavilion dv6-6179er AC status notifications aren't triggered + * when adapter is plugged/unplugged. However, battery status + * notifcations are triggered when battery starts charging or + * discharging. Re-reading AC status triggers lost AC notifications, + * if AC status has changed. + */ + if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0 && + event->type == ACPI_BATTERY_NOTIFY_STATUS) + 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 +237,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 +285,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);