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 1/2] acpi: utils: Add new acpi_dev_present helper
Date: Thu, 16 Mar 2017 17:17:35 +0100	[thread overview]
Message-ID: <20170316161736.339-2-hdegoede@redhat.com> (raw)
In-Reply-To: <20170316161736.339-1-hdegoede@redhat.com>

acpi_dev_found just iterates over all acpi-ids and sees if one matches.
This means that it will return true for devices which are in the dsdt
but disabled (their _STA method returns 0).

For some drivers it is useful to be able to check if a certain hid
is not only present in the namespace, but also actually present as in
acpi_device_is_present() will return true for the device. For example
because if a certain device is present then the driver will want to use
an extcon or IIO adc channel provided by that device.

This commit adds a new acpi_dev_present helper which drivers can use
to this end.

Arguably acpi_dev_present is what acpi_dev_found should have been, but
there are too many users to just change acpi_dev_found without the risk
of breaking something.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/acpi/utils.c    | 34 ++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  1 +
 include/linux/acpi.h    |  5 +++++
 3 files changed, 40 insertions(+)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 22c0995..40f8953 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -736,6 +736,40 @@ bool acpi_dev_found(const char *hid)
 }
 EXPORT_SYMBOL(acpi_dev_found);
 
+static acpi_status acpi_dev_present_cb(acpi_handle ah, u32 level, void *ctx,
+				     void **retval)
+{
+	/*
+	 * acpi_get_devices() does all the work for us, if we get called
+	 * a device with a matching hid has been found and its _STA indicates
+	 * it is present.
+	 */
+	*(bool *)ctx = true;
+	return AE_CTRL_TERMINATE;
+}
+
+/**
+ * acpi_dev_present - Detect that a given ACPI device is present
+ * @hid: Hardware ID of the device.
+ *
+ * Return %true if the device was present at the moment of invocation.
+ * Note that if the device is pluggable, it may since have disappeared.
+ *
+ * Note that unlike acpi_dev_found() this function checks the status
+ * of the device so for devices which are present in the dsdt, but
+ * which are disabled (their _STA callback returns 0) this function
+ * will return false.
+ */
+bool acpi_dev_present(const char *hid)
+{
+	bool present = false;
+
+	acpi_get_devices(hid, acpi_dev_present_cb, &present, NULL);
+
+	return present;
+}
+EXPORT_SYMBOL(acpi_dev_present);
+
 /*
  * acpi_backlight= handling, this is done here rather then in video_detect.c
  * because __setup cannot be used in modules.
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ef0ae8a..29f6b5f 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -88,6 +88,7 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const u8 *uuid, u64 rev, u64 func,
 	}
 
 bool acpi_dev_found(const char *hid);
+bool acpi_dev_present(const char *hid);
 
 #ifdef CONFIG_ACPI
 
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 673acda..059ffdc 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -614,6 +614,11 @@ static inline bool acpi_dev_found(const char *hid)
 	return false;
 }
 
+static inline bool acpi_dev_present(const char *hid)
+{
+	return false;
+}
+
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
 	return false;
-- 
2.9.3


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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 16:17 [PATCH 0/2] Only wait for INT3394 extcon to show ip if enabled Hans de Goede
2017-03-16 16:17 ` Hans de Goede [this message]
2017-03-28 21:42   ` [PATCH 1/2] acpi: utils: Add new acpi_dev_present helper Rafael J. Wysocki
2017-03-29  9:26     ` Mika Westerberg
2017-03-29 16:50       ` Andy Shevchenko
2017-03-30  8:33         ` Lukas Wunner
2017-03-30 20:04           ` Rafael J. Wysocki
2017-04-07 10:39           ` Hans de Goede
2017-03-16 16:17 ` [PATCH 2/2] power: supply: axp288_charger: Only wait for INT3496 device if present Hans de Goede
2017-03-20  1:30   ` Sebastian Reichel
2017-03-20  8:56     ` Chen-Yu Tsai
2017-03-20  9:19       ` Sebastian Reichel

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=20170316161736.339-2-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.