From: Jiang Liu <liuj97@gmail.com>
To: "Rafael J . Wysocki" <rjw@sisk.pl>
Cc: liuj97@gmail.com, Jiang Liu <jiang.liu@huawei.com>,
Yijing Wang <wangyijing@huawei.com>,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Len Brown <lenb@kernel.org>
Subject: [PATCH v2 5/9] ACPI: introduce three helper functions
Date: Thu, 27 Jun 2013 00:30:57 +0800 [thread overview]
Message-ID: <1372264261-17442-6-git-send-email-liuj97@gmail.com> (raw)
In-Reply-To: <1372264261-17442-1-git-send-email-liuj97@gmail.com>
From: Jiang Liu <jiang.liu@huawei.com>
Introduce three helper functions, which will be used to simplify code.
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Jiang Liu <liuj97@gmail.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: linux-acpi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/acpi/utils.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
include/acpi/acpi_bus.h | 5 ++++
2 files changed, 77 insertions(+)
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 74437130..5bcf068 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -495,3 +495,75 @@ acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
kfree(buffer.pointer);
}
EXPORT_SYMBOL(acpi_handle_printk);
+
+static acpi_status
+acpi_evaluate_object_with_int_arg(acpi_handle handle, char *method, u64 val)
+{
+ union acpi_object arg;
+ struct acpi_object_list arg_list;
+
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = val;
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+
+ return acpi_evaluate_object(handle, method, &arg_list, NULL);
+}
+
+/**
+ * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
+ * @handle: ACPI device handle
+ *
+ * Evaluate device's _EJ0 method for hotplug operations.
+ */
+acpi_status acpi_evaluate_ej0(acpi_handle handle)
+{
+ acpi_status status;
+
+ status = acpi_evaluate_object_with_int_arg(handle, "_EJ0", 1);
+ if (status == AE_NOT_FOUND)
+ acpi_handle_warn(handle, "No _EJ0 support for device\n");
+ else if (ACPI_FAILURE(status))
+ acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
+
+ return status;
+}
+
+/**
+ * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
+ * @handle: ACPI device handle
+ * @lock: lock device if non-zero, otherwise unlock device
+ *
+ * Evaluate device's _LCK method if present to lock/unlock device
+ */
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
+{
+ acpi_status status;
+
+ status = acpi_evaluate_object_with_int_arg(handle, "_LCK", !!lock);
+ if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+ if (lock)
+ acpi_handle_warn(handle,
+ "Locking device failed (0x%x)\n", status);
+ else
+ acpi_handle_warn(handle,
+ "Unlocking device failed (0x%x)\n", status);
+ }
+
+ return status;
+}
+
+/**
+ * acpi_has_method: Check whether @handle has a method named @name
+ * @handle: ACPI device handle
+ * @name: name of object or method
+ *
+ * Check whether @handle has a method named @name.
+ */
+bool acpi_has_method(acpi_handle handle, char *name)
+{
+ acpi_handle tmp;
+
+ return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
+}
+EXPORT_SYMBOL(acpi_has_method);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ca081ac..3db3b97 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -56,6 +56,11 @@ acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event,
acpi_status
acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
+
+acpi_status acpi_evaluate_ej0(acpi_handle handle);
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
+bool acpi_has_method(acpi_handle handle, char *name);
+
#ifdef CONFIG_ACPI
#include <linux/proc_fs.h>
--
1.8.1.2
next prev parent reply other threads:[~2013-06-26 16:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
2013-06-26 16:30 ` [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times Jiang Liu
2013-06-26 16:30 ` [PATCH v2 2/9] ACPI, DOCK: kill redundant spin lock in dock station object Jiang Liu
2013-06-26 16:30 ` [PATCH v2 3/9] ACPI, DOCK: mark initialization functions with __init Jiang Liu
2013-06-26 16:30 ` [PATCH v2 4/9] ACPI, DOCK: simplify implementation of dock_create_acpi_device() Jiang Liu
2013-06-26 16:30 ` Jiang Liu [this message]
2013-06-26 18:49 ` [PATCH v2 5/9] ACPI: introduce three helper functions Rafael J. Wysocki
2013-06-26 23:46 ` Rafael J. Wysocki
2013-06-26 16:30 ` [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions Jiang Liu
2013-06-26 16:30 ` [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces Jiang Liu
2013-06-26 23:12 ` Bjorn Helgaas
2013-06-26 16:31 ` [PATCH v2 8/9] ACPI: simpilify scan.c " Jiang Liu
2013-06-26 16:31 ` [PATCH v2 9/9] ACPI: simplify acpiphp driver " Jiang Liu
2013-06-26 18:34 ` [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers 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=1372264261-17442-6-git-send-email-liuj97@gmail.com \
--to=liuj97@gmail.com \
--cc=jiang.liu@huawei.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@sisk.pl \
--cc=wangyijing@huawei.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;
as well as URLs for NNTP newsgroup(s).