172246da4SFelipe Balbi /** 272246da4SFelipe Balbi * dwc3-pci.c - PCI Specific glue layer 372246da4SFelipe Balbi * 472246da4SFelipe Balbi * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 572246da4SFelipe Balbi * 672246da4SFelipe Balbi * Authors: Felipe Balbi <balbi@ti.com>, 772246da4SFelipe Balbi * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 872246da4SFelipe Balbi * 95945f789SFelipe Balbi * This program is free software: you can redistribute it and/or modify 105945f789SFelipe Balbi * it under the terms of the GNU General Public License version 2 of 115945f789SFelipe Balbi * the License as published by the Free Software Foundation. 1272246da4SFelipe Balbi * 135945f789SFelipe Balbi * This program is distributed in the hope that it will be useful, 145945f789SFelipe Balbi * but WITHOUT ANY WARRANTY; without even the implied warranty of 155945f789SFelipe Balbi * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165945f789SFelipe Balbi * GNU General Public License for more details. 1772246da4SFelipe Balbi */ 1872246da4SFelipe Balbi 1972246da4SFelipe Balbi #include <linux/kernel.h> 2046a57283SStephen Rothwell #include <linux/module.h> 2172246da4SFelipe Balbi #include <linux/slab.h> 2272246da4SFelipe Balbi #include <linux/pci.h> 23e9af9229SFelipe Balbi #include <linux/pm_runtime.h> 2472246da4SFelipe Balbi #include <linux/platform_device.h> 25a89d977cSHeikki Krogerus #include <linux/gpio/consumer.h> 26a89d977cSHeikki Krogerus #include <linux/acpi.h> 27cf48305dSHeikki Krogerus #include <linux/delay.h> 288f317b47SHuang Rui 2972246da4SFelipe Balbi #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 3041adc59cSJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce 31e8095a25SJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf 32b62cd96dSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 3385601f8cSDavid Cohen #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e 349a5a0783SJohn Youn #define PCI_DEVICE_ID_INTEL_BSW 0x22b7 3584a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30 3684a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTH 0xa130 37b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT 0x0aaa 381ffb4d5cSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa 39b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_APL 0x5aaa 404491ed50SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 41*8f8983a5SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_GLK 0x31aa 4272246da4SFelipe Balbi 439cecca75SFelipe Balbi #define PCI_INTEL_BXT_DSM_UUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511" 449cecca75SFelipe Balbi #define PCI_INTEL_BXT_FUNC_PMU_PWR 4 459cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D0 0 469cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D3 3 479cecca75SFelipe Balbi 480f817ae6SFelipe Balbi /** 490f817ae6SFelipe Balbi * struct dwc3_pci - Driver private structure 500f817ae6SFelipe Balbi * @dwc3: child dwc3 platform_device 510f817ae6SFelipe Balbi * @pci: our link to PCI bus 529cecca75SFelipe Balbi * @uuid: _DSM UUID 539cecca75SFelipe Balbi * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM 540f817ae6SFelipe Balbi */ 550f817ae6SFelipe Balbi struct dwc3_pci { 560f817ae6SFelipe Balbi struct platform_device *dwc3; 570f817ae6SFelipe Balbi struct pci_dev *pci; 589cecca75SFelipe Balbi 599cecca75SFelipe Balbi u8 uuid[16]; 609cecca75SFelipe Balbi 619cecca75SFelipe Balbi unsigned int has_dsm_for_pm:1; 620f817ae6SFelipe Balbi }; 630f817ae6SFelipe Balbi 64a89d977cSHeikki Krogerus static const struct acpi_gpio_params reset_gpios = { 0, 0, false }; 65a89d977cSHeikki Krogerus static const struct acpi_gpio_params cs_gpios = { 1, 0, false }; 66a89d977cSHeikki Krogerus 67a89d977cSHeikki Krogerus static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = { 68a89d977cSHeikki Krogerus { "reset-gpios", &reset_gpios, 1 }, 69a89d977cSHeikki Krogerus { "cs-gpios", &cs_gpios, 1 }, 70a89d977cSHeikki Krogerus { }, 71a89d977cSHeikki Krogerus }; 72a89d977cSHeikki Krogerus 730f817ae6SFelipe Balbi static int dwc3_pci_quirks(struct dwc3_pci *dwc) 742cd9ddf7SHeikki Krogerus { 750f817ae6SFelipe Balbi struct platform_device *dwc3 = dwc->dwc3; 760f817ae6SFelipe Balbi struct pci_dev *pdev = dwc->pci; 770f817ae6SFelipe Balbi 782cd9ddf7SHeikki Krogerus if (pdev->vendor == PCI_VENDOR_ID_AMD && 792cd9ddf7SHeikki Krogerus pdev->device == PCI_DEVICE_ID_AMD_NL_USB) { 80cf48305dSHeikki Krogerus struct property_entry properties[] = { 81cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 82cf48305dSHeikki Krogerus PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf), 83cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"), 84cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"), 85cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"), 86cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"), 87cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"), 88cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"), 89cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"), 90cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"), 91cf48305dSHeikki Krogerus PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1), 922cd9ddf7SHeikki Krogerus /* 932cd9ddf7SHeikki Krogerus * FIXME these quirks should be removed when AMD NL 94cf48305dSHeikki Krogerus * tapes out 952cd9ddf7SHeikki Krogerus */ 96cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 97cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 98cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 990eae2fdeSJohn Youn PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 100cf48305dSHeikki Krogerus { }, 101cf48305dSHeikki Krogerus }; 1022cd9ddf7SHeikki Krogerus 103cf48305dSHeikki Krogerus return platform_device_add_properties(dwc3, properties); 1042cd9ddf7SHeikki Krogerus } 1052cd9ddf7SHeikki Krogerus 106e6fe66feSFelipe Balbi if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 107e6fe66feSFelipe Balbi int ret; 108e6fe66feSFelipe Balbi 109e6fe66feSFelipe Balbi struct property_entry properties[] = { 11051c1685dSHans de Goede PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 1110eae2fdeSJohn Youn PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 112e6fe66feSFelipe Balbi { } 113e6fe66feSFelipe Balbi }; 114e6fe66feSFelipe Balbi 115e6fe66feSFelipe Balbi ret = platform_device_add_properties(dwc3, properties); 116e6fe66feSFelipe Balbi if (ret < 0) 117e6fe66feSFelipe Balbi return ret; 118e6fe66feSFelipe Balbi 1199cecca75SFelipe Balbi if (pdev->device == PCI_DEVICE_ID_INTEL_BXT || 1209cecca75SFelipe Balbi pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) { 1219cecca75SFelipe Balbi acpi_str_to_uuid(PCI_INTEL_BXT_DSM_UUID, dwc->uuid); 1229cecca75SFelipe Balbi dwc->has_dsm_for_pm = true; 1239cecca75SFelipe Balbi } 1249cecca75SFelipe Balbi 125e6fe66feSFelipe Balbi if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 126a89d977cSHeikki Krogerus struct gpio_desc *gpio; 127a89d977cSHeikki Krogerus 128a89d977cSHeikki Krogerus acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev), 129a89d977cSHeikki Krogerus acpi_dwc3_byt_gpios); 130a89d977cSHeikki Krogerus 1312df033caSUwe Kleine-König /* 1322df033caSUwe Kleine-König * These GPIOs will turn on the USB2 PHY. Note that we have to 1332df033caSUwe Kleine-König * put the gpio descriptors again here because the phy driver 1342df033caSUwe Kleine-König * might want to grab them, too. 1352df033caSUwe Kleine-König */ 1362df033caSUwe Kleine-König gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW); 1372df033caSUwe Kleine-König if (IS_ERR(gpio)) 1382df033caSUwe Kleine-König return PTR_ERR(gpio); 1392df033caSUwe Kleine-König 140a89d977cSHeikki Krogerus gpiod_set_value_cansleep(gpio, 1); 141a89d977cSHeikki Krogerus gpiod_put(gpio); 142a89d977cSHeikki Krogerus 1432df033caSUwe Kleine-König gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); 1442df033caSUwe Kleine-König if (IS_ERR(gpio)) 1452df033caSUwe Kleine-König return PTR_ERR(gpio); 1462df033caSUwe Kleine-König 1472df033caSUwe Kleine-König if (gpio) { 148a89d977cSHeikki Krogerus gpiod_set_value_cansleep(gpio, 1); 149a89d977cSHeikki Krogerus gpiod_put(gpio); 150a89d977cSHeikki Krogerus usleep_range(10000, 11000); 151a89d977cSHeikki Krogerus } 152a89d977cSHeikki Krogerus } 153e6fe66feSFelipe Balbi } 154a89d977cSHeikki Krogerus 155bb7f3d6dSJohn Youn if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS && 156bb7f3d6dSJohn Youn (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 || 157bb7f3d6dSJohn Youn pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI || 158bb7f3d6dSJohn Youn pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) { 159cf48305dSHeikki Krogerus struct property_entry properties[] = { 160cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 161cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 162cf48305dSHeikki Krogerus PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 1630eae2fdeSJohn Youn PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 164cf48305dSHeikki Krogerus { }, 165cf48305dSHeikki Krogerus }; 166bb7f3d6dSJohn Youn 167cf48305dSHeikki Krogerus return platform_device_add_properties(dwc3, properties); 168bb7f3d6dSJohn Youn } 169bb7f3d6dSJohn Youn 1702cd9ddf7SHeikki Krogerus return 0; 1712cd9ddf7SHeikki Krogerus } 17272246da4SFelipe Balbi 17341ac7b3aSBill Pemberton static int dwc3_pci_probe(struct pci_dev *pci, 17472246da4SFelipe Balbi const struct pci_device_id *id) 17572246da4SFelipe Balbi { 1760f817ae6SFelipe Balbi struct dwc3_pci *dwc; 17772246da4SFelipe Balbi struct resource res[2]; 178b09e99eeSAndy Shevchenko int ret; 179802ca850SChanho Park struct device *dev = &pci->dev; 18072246da4SFelipe Balbi 181f1c7e710SAndy Shevchenko ret = pcim_enable_device(pci); 18272246da4SFelipe Balbi if (ret) { 183802ca850SChanho Park dev_err(dev, "failed to enable pci device\n"); 184802ca850SChanho Park return -ENODEV; 18572246da4SFelipe Balbi } 18672246da4SFelipe Balbi 18772246da4SFelipe Balbi pci_set_master(pci); 18872246da4SFelipe Balbi 1890f817ae6SFelipe Balbi dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); 1900f817ae6SFelipe Balbi if (!dwc) 191f1c7e710SAndy Shevchenko return -ENOMEM; 1920f817ae6SFelipe Balbi 1930f817ae6SFelipe Balbi dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 1940f817ae6SFelipe Balbi if (!dwc->dwc3) 1950f817ae6SFelipe Balbi return -ENOMEM; 19672246da4SFelipe Balbi 19772246da4SFelipe Balbi memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 19872246da4SFelipe Balbi 19972246da4SFelipe Balbi res[0].start = pci_resource_start(pci, 0); 20072246da4SFelipe Balbi res[0].end = pci_resource_end(pci, 0); 20172246da4SFelipe Balbi res[0].name = "dwc_usb3"; 20272246da4SFelipe Balbi res[0].flags = IORESOURCE_MEM; 20372246da4SFelipe Balbi 20472246da4SFelipe Balbi res[1].start = pci->irq; 20572246da4SFelipe Balbi res[1].name = "dwc_usb3"; 20672246da4SFelipe Balbi res[1].flags = IORESOURCE_IRQ; 20772246da4SFelipe Balbi 2080f817ae6SFelipe Balbi ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res)); 20972246da4SFelipe Balbi if (ret) { 210802ca850SChanho Park dev_err(dev, "couldn't add resources to dwc3 device\n"); 211f1c7e710SAndy Shevchenko return ret; 21272246da4SFelipe Balbi } 21372246da4SFelipe Balbi 2140f817ae6SFelipe Balbi dwc->pci = pci; 2150f817ae6SFelipe Balbi dwc->dwc3->dev.parent = dev; 2160f817ae6SFelipe Balbi ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev)); 21772246da4SFelipe Balbi 2180f817ae6SFelipe Balbi ret = dwc3_pci_quirks(dwc); 219474799f0SHeikki Krogerus if (ret) 220474799f0SHeikki Krogerus goto err; 221474799f0SHeikki Krogerus 2220f817ae6SFelipe Balbi ret = platform_device_add(dwc->dwc3); 22372246da4SFelipe Balbi if (ret) { 224802ca850SChanho Park dev_err(dev, "failed to register dwc3 device\n"); 2252cd9ddf7SHeikki Krogerus goto err; 22672246da4SFelipe Balbi } 22772246da4SFelipe Balbi 228e9af9229SFelipe Balbi device_init_wakeup(dev, true); 229e9af9229SFelipe Balbi device_set_run_wake(dev, true); 2300f817ae6SFelipe Balbi pci_set_drvdata(pci, dwc); 231e9af9229SFelipe Balbi pm_runtime_put(dev); 232e9af9229SFelipe Balbi 23372246da4SFelipe Balbi return 0; 2342cd9ddf7SHeikki Krogerus err: 2350f817ae6SFelipe Balbi platform_device_put(dwc->dwc3); 23672246da4SFelipe Balbi return ret; 23772246da4SFelipe Balbi } 23872246da4SFelipe Balbi 239fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci) 24072246da4SFelipe Balbi { 2410f817ae6SFelipe Balbi struct dwc3_pci *dwc = pci_get_drvdata(pci); 2420f817ae6SFelipe Balbi 243e9af9229SFelipe Balbi device_init_wakeup(&pci->dev, false); 244e9af9229SFelipe Balbi pm_runtime_get(&pci->dev); 245a89d977cSHeikki Krogerus acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev)); 2460f817ae6SFelipe Balbi platform_device_unregister(dwc->dwc3); 24772246da4SFelipe Balbi } 24872246da4SFelipe Balbi 249782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = { 25072246da4SFelipe Balbi { 25172246da4SFelipe Balbi PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 25272246da4SFelipe Balbi PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 25372246da4SFelipe Balbi }, 25441adc59cSJohn Youn { 25541adc59cSJohn Youn PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 25641adc59cSJohn Youn PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI), 25741adc59cSJohn Youn }, 258e8095a25SJohn Youn { 259e8095a25SJohn Youn PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 260e8095a25SJohn Youn PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31), 261e8095a25SJohn Youn }, 2627d643664SAlan Cox { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, 263b62cd96dSHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, 26485601f8cSDavid Cohen { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, 26584a2b61bSHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), }, 26684a2b61bSHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), }, 267b4c580a4SHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, 2681ffb4d5cSHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, 269b4c580a4SHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, 2704491ed50SHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, 271*8f8983a5SHeikki Krogerus { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, 2729755449dSHuang Rui { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, 27372246da4SFelipe Balbi { } /* Terminating Entry */ 27472246da4SFelipe Balbi }; 27572246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 27672246da4SFelipe Balbi 27736daf3aaSFelipe Balbi #if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP) 27836daf3aaSFelipe Balbi static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param) 27936daf3aaSFelipe Balbi { 28036daf3aaSFelipe Balbi union acpi_object *obj; 28136daf3aaSFelipe Balbi union acpi_object tmp; 28236daf3aaSFelipe Balbi union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp); 28336daf3aaSFelipe Balbi 28436daf3aaSFelipe Balbi if (!dwc->has_dsm_for_pm) 28536daf3aaSFelipe Balbi return 0; 28636daf3aaSFelipe Balbi 28736daf3aaSFelipe Balbi tmp.type = ACPI_TYPE_INTEGER; 28836daf3aaSFelipe Balbi tmp.integer.value = param; 28936daf3aaSFelipe Balbi 29036daf3aaSFelipe Balbi obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), dwc->uuid, 29136daf3aaSFelipe Balbi 1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4); 29236daf3aaSFelipe Balbi if (!obj) { 29336daf3aaSFelipe Balbi dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n"); 29436daf3aaSFelipe Balbi return -EIO; 29536daf3aaSFelipe Balbi } 29636daf3aaSFelipe Balbi 29736daf3aaSFelipe Balbi ACPI_FREE(obj); 29836daf3aaSFelipe Balbi 29936daf3aaSFelipe Balbi return 0; 30036daf3aaSFelipe Balbi } 30136daf3aaSFelipe Balbi #endif /* CONFIG_PM || CONFIG_PM_SLEEP */ 30236daf3aaSFelipe Balbi 303e9af9229SFelipe Balbi #ifdef CONFIG_PM 304e9af9229SFelipe Balbi static int dwc3_pci_runtime_suspend(struct device *dev) 305e9af9229SFelipe Balbi { 3069cecca75SFelipe Balbi struct dwc3_pci *dwc = dev_get_drvdata(dev); 3079cecca75SFelipe Balbi 308e9af9229SFelipe Balbi if (device_run_wake(dev)) 3099cecca75SFelipe Balbi return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3); 310e9af9229SFelipe Balbi 311e9af9229SFelipe Balbi return -EBUSY; 312e9af9229SFelipe Balbi } 313e9af9229SFelipe Balbi 314f6c274e1SFelipe Balbi static int dwc3_pci_runtime_resume(struct device *dev) 315f6c274e1SFelipe Balbi { 3160f817ae6SFelipe Balbi struct dwc3_pci *dwc = dev_get_drvdata(dev); 3170f817ae6SFelipe Balbi struct platform_device *dwc3 = dwc->dwc3; 3189cecca75SFelipe Balbi int ret; 3199cecca75SFelipe Balbi 3209cecca75SFelipe Balbi ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0); 3219cecca75SFelipe Balbi if (ret) 3229cecca75SFelipe Balbi return ret; 323f6c274e1SFelipe Balbi 324f6c274e1SFelipe Balbi return pm_runtime_get(&dwc3->dev); 325f6c274e1SFelipe Balbi } 326696118c0SFelipe Balbi #endif /* CONFIG_PM */ 327f6c274e1SFelipe Balbi 328696118c0SFelipe Balbi #ifdef CONFIG_PM_SLEEP 3299cecca75SFelipe Balbi static int dwc3_pci_suspend(struct device *dev) 330e9af9229SFelipe Balbi { 3319cecca75SFelipe Balbi struct dwc3_pci *dwc = dev_get_drvdata(dev); 3329cecca75SFelipe Balbi 3339cecca75SFelipe Balbi return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3); 3349cecca75SFelipe Balbi } 3359cecca75SFelipe Balbi 3369cecca75SFelipe Balbi static int dwc3_pci_resume(struct device *dev) 3379cecca75SFelipe Balbi { 3389cecca75SFelipe Balbi struct dwc3_pci *dwc = dev_get_drvdata(dev); 3399cecca75SFelipe Balbi 3409cecca75SFelipe Balbi return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0); 341e9af9229SFelipe Balbi } 342696118c0SFelipe Balbi #endif /* CONFIG_PM_SLEEP */ 343e9af9229SFelipe Balbi 344e9af9229SFelipe Balbi static struct dev_pm_ops dwc3_pci_dev_pm_ops = { 3459cecca75SFelipe Balbi SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume) 346f6c274e1SFelipe Balbi SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume, 347e9af9229SFelipe Balbi NULL) 348e9af9229SFelipe Balbi }; 349e9af9229SFelipe Balbi 35072246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = { 3510949e99bSFelipe Balbi .name = "dwc3-pci", 35272246da4SFelipe Balbi .id_table = dwc3_pci_id_table, 35372246da4SFelipe Balbi .probe = dwc3_pci_probe, 3547690417dSBill Pemberton .remove = dwc3_pci_remove, 355e9af9229SFelipe Balbi .driver = { 356e9af9229SFelipe Balbi .pm = &dwc3_pci_dev_pm_ops, 357e9af9229SFelipe Balbi } 35872246da4SFelipe Balbi }; 35972246da4SFelipe Balbi 36072246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 3615945f789SFelipe Balbi MODULE_LICENSE("GPL v2"); 36272246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer"); 36372246da4SFelipe Balbi 36495656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver); 365