From: Hans de Goede <hdegoede@redhat.com>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
Len Brown <lenb@kernel.org>, Sebastian Reichel <sre@kernel.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 v2 1/4] ACPI: battery: Add acpi_battery_unregister() function
Date: Mon, 20 Mar 2017 14:21:47 +0100 [thread overview]
Message-ID: <20170320132150.18771-1-hdegoede@redhat.com> (raw)
On some systems we have a native PMIC driver which provides battery
monitoring, while the ACPI battery 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 battery device in the
dsdt relies on.
This leads to there being 2 battery power_supply-s registed like this:
~$ acpi
Battery 0: Charging, 84%, 00:49:39 until charged
Battery 1: Unknown, 0%, rate information unavailable
Even if the ACPI battery where to function fine (which on systems
where we have a native PMIC driver it often doesn't) we still do not
want to export the same battery to userspace twice.
This commit adds an acpi_battery_unregister() function which native
PMIC drivers can call to tell the ACPI-battery driver to unregister
itself so that we do not end up with 2 power_supply-s for the same
battery device.
BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=194811
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Sergei Trusov <t.rus76@ya.ru>
---
Changes in v2:
-Fix capitalization in commit msg
-Minor style cleanups
---
drivers/acpi/battery.c | 33 ++++++++++++++++++++++++++++++++-
include/linux/power/acpi.h | 18 ++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 include/linux/power/acpi.h
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 4ef1e46..b26a2b7 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -29,6 +29,7 @@
#include <linux/async.h>
#include <linux/dmi.h>
#include <linux/delay.h>
+#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/suspend.h>
#include <asm/unaligned.h>
@@ -40,6 +41,7 @@
#endif
#include <linux/acpi.h>
+#include <linux/power/acpi.h>
#include <linux/power_supply.h>
#include "battery.h"
@@ -66,6 +68,10 @@ MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>");
MODULE_DESCRIPTION("ACPI Battery Driver");
MODULE_LICENSE("GPL");
+enum init_state_enum { BAT_NONE, BAT_INITIALIZED, BAT_EXITED };
+
+static enum init_state_enum init_state;
+static DEFINE_MUTEX(init_state_mutex);
static async_cookie_t async_cookie;
static int battery_bix_broken_package;
static int battery_notification_delay_ms;
@@ -1336,17 +1342,42 @@ static int __init acpi_battery_init(void)
if (acpi_disabled)
return -ENODEV;
+ /* Check if acpi_battery_unregister() got called before _init() */
+ mutex_lock(&init_state_mutex);
+ if (init_state != BAT_NONE)
+ goto out_unlock;
+
async_cookie = async_schedule(acpi_battery_init_async, NULL);
+ init_state = BAT_INITIALIZED;
+
+out_unlock:
+ mutex_unlock(&init_state_mutex);
+
return 0;
}
-static void __exit acpi_battery_exit(void)
+void acpi_battery_unregister(void)
{
+ /* Check if _init() is done and only do unregister once */
+ mutex_lock(&init_state_mutex);
+ if (init_state != BAT_INITIALIZED)
+ goto out_exit;
+
async_synchronize_cookie(async_cookie + 1);
acpi_bus_unregister_driver(&acpi_battery_driver);
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_unlock_battery_dir(acpi_battery_dir);
#endif
+
+out_exit:
+ init_state = BAT_EXITED;
+ mutex_unlock(&init_state_mutex);
+}
+EXPORT_SYMBOL_GPL(acpi_battery_unregister);
+
+static void __exit acpi_battery_exit(void)
+{
+ acpi_battery_unregister();
}
module_init(acpi_battery_init);
diff --git a/include/linux/power/acpi.h b/include/linux/power/acpi.h
new file mode 100644
index 0000000..83bdfb9
--- /dev/null
+++ b/include/linux/power/acpi.h
@@ -0,0 +1,18 @@
+/*
+ * Functions exported by the acpi power_supply drivers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_POWER_ACPI_H_
+#define __LINUX_POWER_ACPI_H_
+
+#if IS_ENABLED(CONFIG_ACPI_BATTERY)
+void acpi_battery_unregister(void);
+#else
+static inline void acpi_battery_unregister(void) {}
+#endif
+
+#endif
--
2.9.3
next reply other threads:[~2017-03-20 13:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 13:21 Hans de Goede [this message]
2017-03-20 13:21 ` [PATCH v2 2/4] ACPI: ac: Add acpi_ac_unregister() function Hans de Goede
2017-03-20 13:21 ` [PATCH v2 3/4] power: supply: axp288_fuel_gauge: Unregister duplicate ACPI battery supply Hans de Goede
2017-03-20 13:21 ` [PATCH v2 4/4] power: supply: axp288_charger: Unregister duplicate ACPI ac supply Hans de Goede
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=20170320132150.18771-1-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 \
/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;
as well as URLs for NNTP newsgroup(s).