diff mbox series

[v2,03/35] acpi: Add a way to check device status

Message ID 20200510203409.203520-3-sjg@chromium.org
State Accepted
Commit 2715b3623c08bf1ad2dfe6076ad86c24e3138016
Headers show
Series dm: Add programmatic generation of ACPI tables (part B) | expand

Commit Message

Simon Glass May 10, 2020, 8:33 p.m. UTC
At present U-Boot does not support the different ACPI status values, but
it is best to put this logic in a central place. Add a function to get the
device status.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None
Changes in v1: None

 include/acpi/acpi_device.h | 28 ++++++++++++++++++++++++++++
 lib/acpi/acpi_device.c     |  5 +++++
 test/dm/acpi.c             | 12 ++++++++++++
 3 files changed, 45 insertions(+)

Comments

Wolfgang Wallner May 13, 2020, 12:18 p.m. UTC | #1
Hi Simon,

-----"Simon Glass" <sjg at chromium.org> schrieb: -----
>Betreff: [PATCH v2 03/35] acpi: Add a way to check device status
>
>At present U-Boot does not support the different ACPI status values,
>but
>it is best to put this logic in a central place. Add a function to
>get the
>device status.
>
>Signed-off-by: Simon Glass <sjg at chromium.org>
>---
>
>Changes in v2: None
>Changes in v1: None
>
> include/acpi/acpi_device.h | 28 ++++++++++++++++++++++++++++
> lib/acpi/acpi_device.c     |  5 +++++
> test/dm/acpi.c             | 12 ++++++++++++
> 3 files changed, 45 insertions(+)

Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>
diff mbox series

Patch

diff --git a/include/acpi/acpi_device.h b/include/acpi/acpi_device.h
index 37a675f101..09c227489a 100644
--- a/include/acpi/acpi_device.h
+++ b/include/acpi/acpi_device.h
@@ -9,11 +9,28 @@ 
 #ifndef __ACPI_DEVICE_H
 #define __ACPI_DEVICE_H
 
+#include <linux/bitops.h>
+
 struct udevice;
 
 /* Length of a full path to an ACPI device */
 #define ACPI_PATH_MAX		30
 
+/* Values that can be returned for ACPI device _STA method */
+enum acpi_dev_status {
+	ACPI_DSTATUS_PRESENT		= BIT(0),
+	ACPI_DSTATUS_ENABLED		= BIT(1),
+	ACPI_DSTATUS_SHOW_IN_UI		= BIT(2),
+	ACPI_DSTATUS_OK			= BIT(3),
+	ACPI_DSTATUS_HAS_BATTERY	= BIT(4),
+
+	ACPI_DSTATUS_ALL_OFF	= 0,
+	ACPI_DSTATUS_HIDDEN_ON	= ACPI_DSTATUS_PRESENT | ACPI_DSTATUS_ENABLED |
+		ACPI_DSTATUS_OK,
+	ACPI_DSTATUS_ALL_ON	= ACPI_DSTATUS_HIDDEN_ON |
+		ACPI_DSTATUS_SHOW_IN_UI,
+};
+
 /**
  * acpi_device_path() - Get the full path to an ACPI device
  *
@@ -41,4 +58,15 @@  int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
  */
 int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
 
+/**
+ * acpi_device_status() - Get the status of a device
+ *
+ * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support
+ * inactive or hidden devices.
+ *
+ * @dev: Device to check
+ * @return device status, as ACPI_DSTATUS_...
+ */
+enum acpi_dev_status acpi_device_status(const struct udevice *dev);
+
 #endif
diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
index f9af2343c1..7b18cbf148 100644
--- a/lib/acpi/acpi_device.c
+++ b/lib/acpi/acpi_device.c
@@ -81,3 +81,8 @@  int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen)
 
 	return 0;
 }
+
+enum acpi_dev_status acpi_device_status(const struct udevice *dev)
+{
+	return ACPI_DSTATUS_ALL_ON;
+}
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index c25fe805c4..0c2e12d170 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -384,3 +384,15 @@  static int dm_test_acpi_device_path(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_acpi_device_path, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_device_status() */
+static int dm_test_acpi_device_status(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
+	ut_asserteq(ACPI_DSTATUS_ALL_ON, acpi_device_status(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_acpi_device_status, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);