acpi: Support writing a GPIO

Allowing writing out a reference to a GPIO within the ACPI output. This
can be used by ACPI code to access a GPIO at runtime.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff --git a/lib/acpi/acpi_dp.c b/lib/acpi/acpi_dp.c
index 32528e1..e8de565 100644
--- a/lib/acpi/acpi_dp.c
+++ b/lib/acpi/acpi_dp.c
@@ -321,3 +321,26 @@
 
 	return dp_array;
 }
+
+struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name,
+				 const char *ref, int index, int pin,
+				 enum acpi_irq_polarity polarity)
+{
+	struct acpi_dp *gpio;
+
+	assert(dp);
+	gpio = acpi_dp_new_table(name);
+	if (!gpio)
+		return NULL;
+
+	if (!acpi_dp_add_reference(gpio, NULL, ref) ||
+	    !acpi_dp_add_integer(gpio, NULL, index) ||
+	    !acpi_dp_add_integer(gpio, NULL, pin) ||
+	    !acpi_dp_add_integer(gpio, NULL, polarity == ACPI_IRQ_ACTIVE_LOW))
+		return NULL;
+
+	if (!acpi_dp_add_array(dp, gpio))
+		return NULL;
+
+	return gpio;
+}