From patchwork Thu Mar 16 16:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9628899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C225D60522 for ; Thu, 16 Mar 2017 16:24:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFC7C28532 for ; Thu, 16 Mar 2017 16:24:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A43A628644; Thu, 16 Mar 2017 16:24:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E31C28532 for ; Thu, 16 Mar 2017 16:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754745AbdCPQYd (ORCPT ); Thu, 16 Mar 2017 12:24:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45320 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754621AbdCPQYd (ORCPT ); Thu, 16 Mar 2017 12:24:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64548437F7D; Thu, 16 Mar 2017 16:16:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 64548437F7D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=hdegoede@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 64548437F7D Received: from shalem.localdomain.com (ovpn-117-127.ams2.redhat.com [10.36.117.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4ABD183DE; Thu, 16 Mar 2017 16:16:07 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Sebastian Reichel , Chen-Yu Tsai Cc: Hans de Goede , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 2/4] acpi: ac: Add acpi_ac_unregister() function Date: Thu, 16 Mar 2017 17:15:59 +0100 Message-Id: <20170316161601.32267-3-hdegoede@redhat.com> In-Reply-To: <20170316161601.32267-1-hdegoede@redhat.com> References: <20170316161601.32267-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 16 Mar 2017 16:16:09 +0000 (UTC) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On some systems we have a native pmic driver which provides Mains monitoring, while the acpi ac driver is broken on these systems due to bad dstds or because of missing vendor specific acpi opregion (e.g. BMOP opregion) support, which the acpi ac device in the dsdt relies on. This leads for example to a ADP1 power_supply which reports itself as always online even if no mains are connected. This commit adds an acpi_ac_unregister() function which native pmic drivers can call after successfully registering their own power_supply to unregister the (potentially broken) acpi-ac power_supply. Signed-off-by: Hans de Goede --- drivers/acpi/ac.c | 42 +++++++++++++++++++++++++++++++++++++----- include/linux/power/acpi.h | 6 ++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index f71b756..1c60e18 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -26,12 +26,14 @@ #include #include #include +#include #ifdef CONFIG_ACPI_PROCFS_POWER #include #include #endif #include #include +#include #include #include "battery.h" @@ -422,17 +424,27 @@ static int acpi_ac_remove(struct acpi_device *device) return 0; } +enum init_state_enum { AC_NONE, AC_INITIALIZED, AC_EXITED }; + +static enum init_state_enum init_state; +static DEFINE_MUTEX(init_state_mutex); + static int __init acpi_ac_init(void) { - int result; + int result, ret = -ENODEV; if (acpi_disabled) return -ENODEV; + /* Check if acpi_ac_unregister got called before _init() */ + mutex_lock(&init_state_mutex); + if (init_state != AC_NONE) + goto out_unlock; + #ifdef CONFIG_ACPI_PROCFS_POWER acpi_ac_dir = acpi_lock_ac_dir(); if (!acpi_ac_dir) - return -ENODEV; + goto out_unlock; #endif @@ -441,18 +453,38 @@ static int __init acpi_ac_init(void) #ifdef CONFIG_ACPI_PROCFS_POWER acpi_unlock_ac_dir(acpi_ac_dir); #endif - return -ENODEV; + goto out_unlock; } - return 0; + init_state = AC_INITIALIZED; + ret = 0; +out_unlock: + mutex_unlock(&init_state_mutex); + return ret; } -static void __exit acpi_ac_exit(void) +void acpi_ac_unregister(void) { + /* Check if _init() is done and only do unregister once */ + mutex_lock(&init_state_mutex); + if (init_state != AC_INITIALIZED) + goto out_exit; + acpi_bus_unregister_driver(&acpi_ac_driver); #ifdef CONFIG_ACPI_PROCFS_POWER acpi_unlock_ac_dir(acpi_ac_dir); #endif + +out_exit: + init_state = AC_EXITED; + mutex_unlock(&init_state_mutex); } +EXPORT_SYMBOL_GPL(acpi_ac_unregister); + +static void __exit acpi_ac_exit(void) +{ + acpi_ac_unregister(); +} + module_init(acpi_ac_init); module_exit(acpi_ac_exit); diff --git a/include/linux/power/acpi.h b/include/linux/power/acpi.h index 83bdfb9..b50ae69 100644 --- a/include/linux/power/acpi.h +++ b/include/linux/power/acpi.h @@ -15,4 +15,10 @@ void acpi_battery_unregister(void); static inline void acpi_battery_unregister(void) {} #endif +#if IS_ENABLED(CONFIG_ACPI_AC) +void acpi_ac_unregister(void); +#else +static inline void acpi_ac_unregister(void) {} +#endif + #endif