drivers/usb/acpi: add reset gpio to usb acpi driver

Add ability to define a reset gpio in acpi for a USB device.

BUG=b:119275094

Change-Id: Ife3ea43a1eadf2548aa52b8fbd792e691d7cc7f2
Signed-off-by: Nick Vaccaro <nvaccaro@google.com>
Reviewed-on: https://review.coreboot.org/c/29615
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Rajat Jain <rajatja@google.com>
diff --git a/src/drivers/usb/acpi/usb_acpi.c b/src/drivers/usb/acpi/usb_acpi.c
index 65f1f82..f049e68 100644
--- a/src/drivers/usb/acpi/usb_acpi.c
+++ b/src/drivers/usb/acpi/usb_acpi.c
@@ -23,6 +23,17 @@
 #include <string.h>
 #include "chip.h"
 
+static bool usb_acpi_add_gpios_to_crs(struct drivers_usb_acpi_config *cfg)
+{
+	/*
+	 * Return false if reset GPIO is not provided.
+	 */
+	if (cfg->reset_gpio.pin_count == 0)
+		return false;
+
+	return true;
+}
+
 static void usb_acpi_fill_ssdt_generator(struct device *dev)
 {
 	struct drivers_usb_acpi_config *config = dev->chip_info;
@@ -50,6 +61,21 @@
 		acpigen_write_pld(&pld);
 	}
 
+	/* Resources */
+	if (usb_acpi_add_gpios_to_crs(config) == true) {
+		struct acpi_dp *dsd;
+
+		acpigen_write_name("_CRS");
+		acpigen_write_resourcetemplate_header();
+		acpi_device_write_gpio(&config->reset_gpio);
+		acpigen_write_resourcetemplate_footer();
+
+		dsd = acpi_dp_new_table("_DSD");
+		acpi_dp_add_gpio(dsd, "reset-gpio", path, 0, 0,
+				config->reset_gpio.polarity);
+		acpi_dp_write(dsd);
+	}
+
 	acpigen_pop_len();
 
 	printk(BIOS_INFO, "%s: %s at %s\n", path,