All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>, Sebastian Reichel <sre@kernel.org>,
	Chen-Yu Tsai <wens@csie.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	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	[thread overview]
Message-ID: <20170316161601.32267-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20170316161601.32267-1-hdegoede@redhat.com>

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 <hdegoede@redhat.com>
---
 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 <linux/types.h>
 #include <linux/dmi.h>
 #include <linux/delay.h>
+#include <linux/mutex.h>
 #ifdef CONFIG_ACPI_PROCFS_POWER
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #endif
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
+#include <linux/power/acpi.h>
 #include <linux/acpi.h>
 #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
-- 
2.9.3


  parent reply	other threads:[~2017-03-16 16:24 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 16:15 [PATCH 0/4] Avoid duplicate registering of ACPI and native power-supplies Hans de Goede
2017-03-16 16:15 ` [PATCH 1/4] acpi: battery: Add acpi_battery_unregister() function Hans de Goede
2017-03-16 16:29   ` Andy Shevchenko
2017-03-20 13:03     ` Hans de Goede
2017-03-20 13:10       ` Andy Shevchenko
2017-03-20 13:11         ` Hans de Goede
2017-03-27  1:16   ` Zheng, Lv
2017-03-31  8:53     ` Hans de Goede
2017-03-31  9:00       ` Hans de Goede
2017-03-16 16:15 ` Hans de Goede [this message]
2017-03-16 16:31   ` [PATCH 2/4] acpi: ac: Add acpi_ac_unregister() function Andy Shevchenko
2017-03-16 16:16 ` [PATCH 3/4] power: supply: axp288_fuel_gauge: Unregister duplicate ACPI battery supply Hans de Goede
2017-03-16 16:33   ` Andy Shevchenko
2017-03-20 13:07     ` Hans de Goede
2017-03-29 20:31   ` Rafael J. Wysocki
2017-03-31  9:01     ` Hans de Goede
2017-03-31  9:05       ` Rafael J. Wysocki
2017-03-31  9:08         ` Hans de Goede
2017-03-31  9:11           ` Rafael J. Wysocki
2017-03-31  9:57             ` Hans de Goede
2017-03-31 22:30               ` Rafael J. Wysocki
2017-04-01 13:22                 ` Hans de Goede
2017-04-07  7:18               ` Hans de Goede
2017-04-10  7:31                 ` Hans de Goede
2017-04-10 18:13                   ` Hans de Goede
2017-04-10 20:01                     ` Rafael J. Wysocki
2017-04-11  9:18                       ` Hans de Goede
2017-04-11 13:51                         ` Rafael J. Wysocki
2017-03-16 16:16 ` [PATCH 4/4] power: supply: axp288_charger: Unregister duplicate ACPI ac supply Hans de Goede
2017-03-16 16:34   ` Andy Shevchenko
2017-03-20  1:33 ` [PATCH 0/4] Avoid duplicate registering of ACPI and native power-supplies Sebastian Reichel
2017-03-20 13:11   ` Hans de Goede
2017-03-20 13:18     ` Andy Shevchenko
2017-03-20 13:19       ` Hans de Goede
2017-03-20 21:55   ` 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=20170316161601.32267-3-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=sre@kernel.org \
    --cc=wens@csie.org \
    /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 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.