]> git.karo-electronics.de Git - linux-beck.git/commitdiff
usb: dwc3: pci: call _DSM for suspend/resume
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 24 Oct 2016 07:40:18 +0000 (10:40 +0300)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 3 Nov 2016 08:38:42 +0000 (10:38 +0200)
Intel's BXT devices need to execute a _DSM method
during {runtime_,}{suspend,resume} in order to get a
chunk of dwc3 to power gate and save some extra
power.

Let's do that now.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/Kconfig
drivers/usb/dwc3/dwc3-pci.c

index a45b4f1ba689fef006b0bf6193084f0cc7921df1..c5aa235863e8c7e88b30544f8e1aba98c9a18d03 100644 (file)
@@ -70,7 +70,7 @@ config USB_DWC3_EXYNOS
 
 config USB_DWC3_PCI
        tristate "PCIe-based Platforms"
-       depends on PCI
+       depends on PCI && ACPI
        default USB_DWC3
        help
          If you're using the DesignWare Core IP with a PCIe, please say
index 0f54b8166e5439db686bac7bda06a3a06a7504d9..8c39ec6522fd0f435b07e300f379e32d40688c09 100644 (file)
 #define PCI_DEVICE_ID_INTEL_APL                        0x5aaa
 #define PCI_DEVICE_ID_INTEL_KBP                        0xa2b0
 
+#define PCI_INTEL_BXT_DSM_UUID         "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
+#define PCI_INTEL_BXT_FUNC_PMU_PWR     4
+#define PCI_INTEL_BXT_STATE_D0         0
+#define PCI_INTEL_BXT_STATE_D3         3
+
 /**
  * struct dwc3_pci - Driver private structure
  * @dwc3: child dwc3 platform_device
  * @pci: our link to PCI bus
+ * @uuid: _DSM UUID
+ * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
  */
 struct dwc3_pci {
        struct platform_device *dwc3;
        struct pci_dev *pci;
+
+       u8 uuid[16];
+
+       unsigned int has_dsm_for_pm:1;
 };
 
 static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
@@ -102,6 +113,12 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
                if (ret < 0)
                        return ret;
 
+               if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
+                               pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
+                       acpi_str_to_uuid(PCI_INTEL_BXT_DSM_UUID, dwc->uuid);
+                       dwc->has_dsm_for_pm = true;
+               }
+
                if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
                        struct gpio_desc *gpio;
 
@@ -149,6 +166,30 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
        return 0;
 }
 
+static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
+{
+       union acpi_object *obj;
+       union acpi_object tmp;
+       union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
+
+       if (!dwc->has_dsm_for_pm)
+               return 0;
+
+       tmp.type = ACPI_TYPE_INTEGER;
+       tmp.integer.value = param;
+
+       obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), dwc->uuid,
+                       1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
+       if (!obj) {
+               dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
+               return -EIO;
+       }
+
+       ACPI_FREE(obj);
+
+       return 0;
+}
+
 static int dwc3_pci_probe(struct pci_dev *pci,
                const struct pci_device_id *id)
 {
@@ -255,8 +296,10 @@ MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
 #ifdef CONFIG_PM
 static int dwc3_pci_runtime_suspend(struct device *dev)
 {
+       struct dwc3_pci         *dwc = dev_get_drvdata(dev);
+
        if (device_run_wake(dev))
-               return 0;
+               return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
 
        return -EBUSY;
 }
@@ -265,28 +308,34 @@ static int dwc3_pci_runtime_resume(struct device *dev)
 {
        struct dwc3_pci         *dwc = dev_get_drvdata(dev);
        struct platform_device  *dwc3 = dwc->dwc3;
+       int                     ret;
+
+       ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
+       if (ret)
+               return ret;
 
        return pm_runtime_get(&dwc3->dev);
 }
 #endif /* CONFIG_PM */
 
 #ifdef CONFIG_PM_SLEEP
-static int dwc3_pci_pm_dummy(struct device *dev)
+static int dwc3_pci_suspend(struct device *dev)
 {
-       /*
-        * There's nothing to do here. No, seriously. Everything is either taken
-        * care either by PCI subsystem or dwc3/core.c, so we have nothing
-        * missing here.
-        *
-        * So you'd think we didn't need this at all, but PCI subsystem will
-        * bail out if we don't have a valid callback :-s
-        */
-       return 0;
+       struct dwc3_pci         *dwc = dev_get_drvdata(dev);
+
+       return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
+}
+
+static int dwc3_pci_resume(struct device *dev)
+{
+       struct dwc3_pci         *dwc = dev_get_drvdata(dev);
+
+       return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
 }
 #endif /* CONFIG_PM_SLEEP */
 
 static struct dev_pm_ops dwc3_pci_dev_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_pm_dummy, dwc3_pci_pm_dummy)
+       SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
        SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
                NULL)
 };