[coreboot-gerrit] Change in coreboot[master]: drivers/usb/acpi: Add a driver for generating USB ACPI

Duncan Laurie (Code Review) gerrit at coreboot.org
Tue May 8 23:16:47 CEST 2018


Duncan Laurie has uploaded this change for review. ( https://review.coreboot.org/26173


Change subject: drivers/usb/acpi: Add a driver for generating USB ACPI
......................................................................

drivers/usb/acpi: Add a driver for generating USB ACPI

Add a support for generating USB port descriptors for ACPI based
on their definition by the board in devicetree.cb.  This will
generate a _UPC and _PLD for each port, using a generic _PLD by
default.  The _PLD can also be customized for more accurate
descriptions if necessary.

This sample devictree.cb shows a USB 2.0 type-A port behind a root
hub connected to an xHCI controller:

device pci 14.0 on
  chip drivers/usb/acpi
    register "desc" = ""Root Hub""
    register "type" = "UPC_TYPE_HUB"
    device usb 0.0 on
      chip drivers/usb/acpi
        register "desc" = ""USB 2.0 Type-A""
        register "type" = "UPC_TYPE_A"
        device usb 2.0 on end
      end
    end
  end
end

It will generate the following ACPI code in the SSDT:

Scope (\_SB.PCI0.XHCI.RHUB.HS01)
{
  Name (_DDN, "USB 2.0 Type-A")
  Name (_UPC, Package (0x04)
  {
    0xFF,
    0x00,
    Zero,
    Zero
  })
  Name (_PLD, ToPLD (
    PLD_Revision           = 0x2,
    PLD_IgnoreColor        = 0x1,
    PLD_Red                = 0x0,
    PLD_Green              = 0x0,
    PLD_Blue               = 0x0,
    PLD_Width              = 0x0,
    PLD_Height             = 0x0,
    PLD_UserVisible        = 0x1,
    PLD_Dock               = 0x0,
    PLD_Lid                = 0x0,
    PLD_Panel              = "UNKNOWN",
    PLD_VerticalPosition   = "CENTER",
    PLD_HorizontalPosition = "CENTER",
    PLD_Shape              = "RECTANGLE",
    PLD_GroupOrientation   = 0x0,
    PLD_GroupToken         = 0x0,
    PLD_GroupPosition      = 0x0,
    PLD_Bay                = 0x0,
    PLD_Ejectable          = 0x0,
    PLD_EjectRequired      = 0x0,
    PLD_CabinetNumber      = 0x0,
    PLD_CardCageNumber     = 0x0,
    PLD_Reference          = 0x0,
    PLD_Rotation           = 0x0,
    PLD_Order              = 0x0,
    PLD_VerticalOffset     = 0x0,
    PLD_HorizontalOffset   = 0x0)
  )
}

Change-Id: I7024390e407fda4b195211bd4755bb5ca53b2b37
Signed-off-by: Duncan Laurie <dlaurie at google.com>
---
A src/drivers/usb/acpi/Kconfig
A src/drivers/usb/acpi/Makefile.inc
A src/drivers/usb/acpi/chip.h
A src/drivers/usb/acpi/usb_acpi.c
4 files changed, 131 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/26173/1

diff --git a/src/drivers/usb/acpi/Kconfig b/src/drivers/usb/acpi/Kconfig
new file mode 100644
index 0000000..6650324
--- /dev/null
+++ b/src/drivers/usb/acpi/Kconfig
@@ -0,0 +1,2 @@
+config DRIVERS_USB_ACPI
+	bool
diff --git a/src/drivers/usb/acpi/Makefile.inc b/src/drivers/usb/acpi/Makefile.inc
new file mode 100644
index 0000000..2e11107
--- /dev/null
+++ b/src/drivers/usb/acpi/Makefile.inc
@@ -0,0 +1 @@
+ramstage-$(CONFIG_DRIVERS_USB_ACPI) += usb_acpi.c
diff --git a/src/drivers/usb/acpi/chip.h b/src/drivers/usb/acpi/chip.h
new file mode 100644
index 0000000..7e89bac
--- /dev/null
+++ b/src/drivers/usb/acpi/chip.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __USB_ACPI_CHIP_H__
+#define __USB_ACPI_CHIP_H__
+
+#include <arch/acpi.h>
+#include <arch/acpi_pld.h>
+
+struct drivers_usb_acpi_config {
+	const char *desc;
+
+	/*
+	 * Physical ports that are user visible
+	 *
+	 * UPC_TYPE_A
+	 * UPC_TYPE_MINI_AB
+	 * UPC_TYPE_EXPRESSCARD
+	 * UPC_TYPE_USB3_A
+	 * UPC_TYPE_USB3_B
+	 * UPC_TYPE_USB3_MICRO_B
+	 * UPC_TYPE_USB3_MICRO_AB
+	 * UPC_TYPE_USB3_POWER_B
+	 * UPC_TYPE_C_USB2_ONLY
+	 * UPC_TYPE_C_USB2_SS_SWITCH
+	 * UPC_TYPE_C_USB2_SS
+	 *
+	 * Non-visible ports or special devices
+	 *
+	 * UPC_TYPE_INTERNAL
+	 * UPC_TYPE_UNUSED
+	 * UPC_TYPE_HUB
+	 */
+	enum acpi_upc_type type;
+
+	/* Define a custom physical location for the port */
+	int custom_pld;
+	struct acpi_pld pld;
+};
+
+#endif /* __USB_ACPI_CHIP_H__ */
diff --git a/src/drivers/usb/acpi/usb_acpi.c b/src/drivers/usb/acpi/usb_acpi.c
new file mode 100644
index 0000000..60ebe93
--- /dev/null
+++ b/src/drivers/usb/acpi/usb_acpi.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <arch/acpi_device.h>
+#include <arch/acpi_pld.h>
+#include <arch/acpigen.h>
+#include <console/console.h>
+#include <device/device.h>
+#include <device/path.h>
+#include <stdint.h>
+#include <string.h>
+#include "chip.h"
+
+static void usb_acpi_fill_ssdt_generator(struct device *dev)
+{
+	struct drivers_usb_acpi_config *config = dev->chip_info;
+	const char *path = acpi_device_path(dev);
+
+	if (!dev->enabled || !path || !config)
+		return;
+
+	/* Don't generate output for hubs, only ports */
+	if (config->type == UPC_TYPE_HUB)
+		return;
+
+	acpigen_write_scope(path);
+	if (config->desc)
+		acpigen_write_name_string("_DDN", config->desc);
+	acpigen_write_upc(config->type);
+
+	if (config->custom_pld) {
+		/* Use board defined PLD */
+		acpigen_write_pld(&config->pld);
+	} else {
+		/* Fill PLD strucutre based on port type */
+		struct acpi_pld pld;
+		acpi_pld_fill_usb(&pld, config->type);
+		acpigen_write_pld(&pld);
+	}
+
+	acpigen_pop_len();
+
+	printk(BIOS_INFO, "%s: %s at %s\n", path,
+	       config->desc ? : dev->chip_ops->name, dev_path(dev));
+}
+
+static struct device_operations usb_acpi_ops = {
+	.read_resources		  = DEVICE_NOOP,
+	.set_resources		  = DEVICE_NOOP,
+	.enable_resources	  = DEVICE_NOOP,
+	.scan_bus                 = &scan_usb_bus,
+	.acpi_fill_ssdt_generator = &usb_acpi_fill_ssdt_generator,
+};
+
+static void usb_acpi_enable(struct device *dev)
+{
+	dev->ops = &usb_acpi_ops;
+}
+
+struct chip_operations drivers_usb_acpi_ops = {
+	CHIP_NAME("USB ACPI Device")
+	.enable_dev = &usb_acpi_enable
+};

-- 
To view, visit https://review.coreboot.org/26173
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7024390e407fda4b195211bd4755bb5ca53b2b37
Gerrit-Change-Number: 26173
Gerrit-PatchSet: 1
Gerrit-Owner: Duncan Laurie <dlaurie at chromium.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180508/78c7b471/attachment-0001.html>


More information about the coreboot-gerrit mailing list