xref: /linux/drivers/usb/dwc3/dwc3-pci.c (revision de3ef1eb1cd0cc3a75f7a3661e10ed827f370ab8)
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
418f8983a5SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_GLK			0x31aa
4268217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPLP		0x9dee
4368217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPH		0xa36e
4472246da4SFelipe Balbi 
4594116f81SAndy Shevchenko #define PCI_INTEL_BXT_DSM_GUID		"732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
469cecca75SFelipe Balbi #define PCI_INTEL_BXT_FUNC_PMU_PWR	4
479cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D0		0
489cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D3		3
499cecca75SFelipe Balbi 
500f817ae6SFelipe Balbi /**
510f817ae6SFelipe Balbi  * struct dwc3_pci - Driver private structure
520f817ae6SFelipe Balbi  * @dwc3: child dwc3 platform_device
530f817ae6SFelipe Balbi  * @pci: our link to PCI bus
5494116f81SAndy Shevchenko  * @guid: _DSM GUID
559cecca75SFelipe Balbi  * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
560f817ae6SFelipe Balbi  */
570f817ae6SFelipe Balbi struct dwc3_pci {
580f817ae6SFelipe Balbi 	struct platform_device *dwc3;
590f817ae6SFelipe Balbi 	struct pci_dev *pci;
609cecca75SFelipe Balbi 
6194116f81SAndy Shevchenko 	guid_t guid;
629cecca75SFelipe Balbi 
639cecca75SFelipe Balbi 	unsigned int has_dsm_for_pm:1;
640f817ae6SFelipe Balbi };
650f817ae6SFelipe Balbi 
66a89d977cSHeikki Krogerus static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
67a89d977cSHeikki Krogerus static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
68a89d977cSHeikki Krogerus 
69a89d977cSHeikki Krogerus static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
70a89d977cSHeikki Krogerus 	{ "reset-gpios", &reset_gpios, 1 },
71a89d977cSHeikki Krogerus 	{ "cs-gpios", &cs_gpios, 1 },
72a89d977cSHeikki Krogerus 	{ },
73a89d977cSHeikki Krogerus };
74a89d977cSHeikki Krogerus 
750f817ae6SFelipe Balbi static int dwc3_pci_quirks(struct dwc3_pci *dwc)
762cd9ddf7SHeikki Krogerus {
770f817ae6SFelipe Balbi 	struct platform_device		*dwc3 = dwc->dwc3;
780f817ae6SFelipe Balbi 	struct pci_dev			*pdev = dwc->pci;
790f817ae6SFelipe Balbi 
802cd9ddf7SHeikki Krogerus 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
812cd9ddf7SHeikki Krogerus 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
82cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
83cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
84cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf),
85cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"),
86cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"),
87cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"),
88cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"),
89cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"),
90cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"),
91cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"),
92cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"),
93cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1),
942cd9ddf7SHeikki Krogerus 			/*
952cd9ddf7SHeikki Krogerus 			 * FIXME these quirks should be removed when AMD NL
96cf48305dSHeikki Krogerus 			 * tapes out
972cd9ddf7SHeikki Krogerus 			 */
98cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
99cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
100cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
1010eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
102cf48305dSHeikki Krogerus 			{ },
103cf48305dSHeikki Krogerus 		};
1042cd9ddf7SHeikki Krogerus 
105cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
1062cd9ddf7SHeikki Krogerus 	}
1072cd9ddf7SHeikki Krogerus 
108e6fe66feSFelipe Balbi 	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
109e6fe66feSFelipe Balbi 		int ret;
110e6fe66feSFelipe Balbi 
111e6fe66feSFelipe Balbi 		struct property_entry properties[] = {
11251c1685dSHans de Goede 			PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
1130eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
114e6fe66feSFelipe Balbi 			{ }
115e6fe66feSFelipe Balbi 		};
116e6fe66feSFelipe Balbi 
117e6fe66feSFelipe Balbi 		ret = platform_device_add_properties(dwc3, properties);
118e6fe66feSFelipe Balbi 		if (ret < 0)
119e6fe66feSFelipe Balbi 			return ret;
120e6fe66feSFelipe Balbi 
1219cecca75SFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
1229cecca75SFelipe Balbi 				pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
12394116f81SAndy Shevchenko 			guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid);
1249cecca75SFelipe Balbi 			dwc->has_dsm_for_pm = true;
1259cecca75SFelipe Balbi 		}
1269cecca75SFelipe Balbi 
127e6fe66feSFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
128a89d977cSHeikki Krogerus 			struct gpio_desc *gpio;
129a89d977cSHeikki Krogerus 
1304a56e413SAndy Shevchenko 			ret = devm_acpi_dev_add_driver_gpios(&pdev->dev,
131a89d977cSHeikki Krogerus 					acpi_dwc3_byt_gpios);
1324a56e413SAndy Shevchenko 			if (ret)
1334a56e413SAndy Shevchenko 				dev_dbg(&pdev->dev, "failed to add mapping table\n");
134a89d977cSHeikki Krogerus 
1352df033caSUwe Kleine-König 			/*
1362df033caSUwe Kleine-König 			 * These GPIOs will turn on the USB2 PHY. Note that we have to
1372df033caSUwe Kleine-König 			 * put the gpio descriptors again here because the phy driver
1382df033caSUwe Kleine-König 			 * might want to grab them, too.
1392df033caSUwe Kleine-König 			 */
1402df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
1412df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1422df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1432df033caSUwe Kleine-König 
144a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
145a89d977cSHeikki Krogerus 			gpiod_put(gpio);
146a89d977cSHeikki Krogerus 
1472df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
1482df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1492df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1502df033caSUwe Kleine-König 
1512df033caSUwe Kleine-König 			if (gpio) {
152a89d977cSHeikki Krogerus 				gpiod_set_value_cansleep(gpio, 1);
153a89d977cSHeikki Krogerus 				gpiod_put(gpio);
154a89d977cSHeikki Krogerus 				usleep_range(10000, 11000);
155a89d977cSHeikki Krogerus 			}
156a89d977cSHeikki Krogerus 		}
157e6fe66feSFelipe Balbi 	}
158a89d977cSHeikki Krogerus 
159bb7f3d6dSJohn Youn 	if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
160bb7f3d6dSJohn Youn 	    (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
161bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
162bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
163cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
164cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
165cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
166cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
1670eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
168cf48305dSHeikki Krogerus 			{ },
169cf48305dSHeikki Krogerus 		};
170bb7f3d6dSJohn Youn 
171cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
172bb7f3d6dSJohn Youn 	}
173bb7f3d6dSJohn Youn 
1742cd9ddf7SHeikki Krogerus 	return 0;
1752cd9ddf7SHeikki Krogerus }
17672246da4SFelipe Balbi 
17741ac7b3aSBill Pemberton static int dwc3_pci_probe(struct pci_dev *pci,
17872246da4SFelipe Balbi 		const struct pci_device_id *id)
17972246da4SFelipe Balbi {
1800f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc;
18172246da4SFelipe Balbi 	struct resource		res[2];
182b09e99eeSAndy Shevchenko 	int			ret;
183802ca850SChanho Park 	struct device		*dev = &pci->dev;
18472246da4SFelipe Balbi 
185f1c7e710SAndy Shevchenko 	ret = pcim_enable_device(pci);
18672246da4SFelipe Balbi 	if (ret) {
187802ca850SChanho Park 		dev_err(dev, "failed to enable pci device\n");
188802ca850SChanho Park 		return -ENODEV;
18972246da4SFelipe Balbi 	}
19072246da4SFelipe Balbi 
19172246da4SFelipe Balbi 	pci_set_master(pci);
19272246da4SFelipe Balbi 
1930f817ae6SFelipe Balbi 	dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
1940f817ae6SFelipe Balbi 	if (!dwc)
195f1c7e710SAndy Shevchenko 		return -ENOMEM;
1960f817ae6SFelipe Balbi 
1970f817ae6SFelipe Balbi 	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
1980f817ae6SFelipe Balbi 	if (!dwc->dwc3)
1990f817ae6SFelipe Balbi 		return -ENOMEM;
20072246da4SFelipe Balbi 
20172246da4SFelipe Balbi 	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
20272246da4SFelipe Balbi 
20372246da4SFelipe Balbi 	res[0].start	= pci_resource_start(pci, 0);
20472246da4SFelipe Balbi 	res[0].end	= pci_resource_end(pci, 0);
20572246da4SFelipe Balbi 	res[0].name	= "dwc_usb3";
20672246da4SFelipe Balbi 	res[0].flags	= IORESOURCE_MEM;
20772246da4SFelipe Balbi 
20872246da4SFelipe Balbi 	res[1].start	= pci->irq;
20972246da4SFelipe Balbi 	res[1].name	= "dwc_usb3";
21072246da4SFelipe Balbi 	res[1].flags	= IORESOURCE_IRQ;
21172246da4SFelipe Balbi 
2120f817ae6SFelipe Balbi 	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
21372246da4SFelipe Balbi 	if (ret) {
214802ca850SChanho Park 		dev_err(dev, "couldn't add resources to dwc3 device\n");
215f1c7e710SAndy Shevchenko 		return ret;
21672246da4SFelipe Balbi 	}
21772246da4SFelipe Balbi 
2180f817ae6SFelipe Balbi 	dwc->pci = pci;
2190f817ae6SFelipe Balbi 	dwc->dwc3->dev.parent = dev;
2200f817ae6SFelipe Balbi 	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
22172246da4SFelipe Balbi 
2220f817ae6SFelipe Balbi 	ret = dwc3_pci_quirks(dwc);
223474799f0SHeikki Krogerus 	if (ret)
224474799f0SHeikki Krogerus 		goto err;
225474799f0SHeikki Krogerus 
2260f817ae6SFelipe Balbi 	ret = platform_device_add(dwc->dwc3);
22772246da4SFelipe Balbi 	if (ret) {
228802ca850SChanho Park 		dev_err(dev, "failed to register dwc3 device\n");
2292cd9ddf7SHeikki Krogerus 		goto err;
23072246da4SFelipe Balbi 	}
23172246da4SFelipe Balbi 
232e9af9229SFelipe Balbi 	device_init_wakeup(dev, true);
2330f817ae6SFelipe Balbi 	pci_set_drvdata(pci, dwc);
234e9af9229SFelipe Balbi 	pm_runtime_put(dev);
235e9af9229SFelipe Balbi 
23672246da4SFelipe Balbi 	return 0;
2372cd9ddf7SHeikki Krogerus err:
2380f817ae6SFelipe Balbi 	platform_device_put(dwc->dwc3);
23972246da4SFelipe Balbi 	return ret;
24072246da4SFelipe Balbi }
24172246da4SFelipe Balbi 
242fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci)
24372246da4SFelipe Balbi {
2440f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = pci_get_drvdata(pci);
2450f817ae6SFelipe Balbi 
246e9af9229SFelipe Balbi 	device_init_wakeup(&pci->dev, false);
247e9af9229SFelipe Balbi 	pm_runtime_get(&pci->dev);
2480f817ae6SFelipe Balbi 	platform_device_unregister(dwc->dwc3);
24972246da4SFelipe Balbi }
25072246da4SFelipe Balbi 
251782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = {
25272246da4SFelipe Balbi 	{
25372246da4SFelipe Balbi 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
25472246da4SFelipe Balbi 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
25572246da4SFelipe Balbi 	},
25641adc59cSJohn Youn 	{
25741adc59cSJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
25841adc59cSJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
25941adc59cSJohn Youn 	},
260e8095a25SJohn Youn 	{
261e8095a25SJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
262e8095a25SJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
263e8095a25SJohn Youn 	},
2647d643664SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
265b62cd96dSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
26685601f8cSDavid Cohen 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
26784a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
26884a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
269b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
2701ffb4d5cSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
271b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
2724491ed50SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
2738f8983a5SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
27468217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), },
27568217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), },
2769755449dSHuang Rui 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
27772246da4SFelipe Balbi 	{  }	/* Terminating Entry */
27872246da4SFelipe Balbi };
27972246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
28072246da4SFelipe Balbi 
28136daf3aaSFelipe Balbi #if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP)
28236daf3aaSFelipe Balbi static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
28336daf3aaSFelipe Balbi {
28436daf3aaSFelipe Balbi 	union acpi_object *obj;
28536daf3aaSFelipe Balbi 	union acpi_object tmp;
28636daf3aaSFelipe Balbi 	union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
28736daf3aaSFelipe Balbi 
28836daf3aaSFelipe Balbi 	if (!dwc->has_dsm_for_pm)
28936daf3aaSFelipe Balbi 		return 0;
29036daf3aaSFelipe Balbi 
29136daf3aaSFelipe Balbi 	tmp.type = ACPI_TYPE_INTEGER;
29236daf3aaSFelipe Balbi 	tmp.integer.value = param;
29336daf3aaSFelipe Balbi 
29494116f81SAndy Shevchenko 	obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), &dwc->guid,
29536daf3aaSFelipe Balbi 			1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
29636daf3aaSFelipe Balbi 	if (!obj) {
29736daf3aaSFelipe Balbi 		dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
29836daf3aaSFelipe Balbi 		return -EIO;
29936daf3aaSFelipe Balbi 	}
30036daf3aaSFelipe Balbi 
30136daf3aaSFelipe Balbi 	ACPI_FREE(obj);
30236daf3aaSFelipe Balbi 
30336daf3aaSFelipe Balbi 	return 0;
30436daf3aaSFelipe Balbi }
30536daf3aaSFelipe Balbi #endif /* CONFIG_PM || CONFIG_PM_SLEEP */
30636daf3aaSFelipe Balbi 
307e9af9229SFelipe Balbi #ifdef CONFIG_PM
308e9af9229SFelipe Balbi static int dwc3_pci_runtime_suspend(struct device *dev)
309e9af9229SFelipe Balbi {
3109cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3119cecca75SFelipe Balbi 
312*de3ef1ebSRafael J. Wysocki 	if (device_can_wakeup(dev))
3139cecca75SFelipe Balbi 		return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
314e9af9229SFelipe Balbi 
315e9af9229SFelipe Balbi 	return -EBUSY;
316e9af9229SFelipe Balbi }
317e9af9229SFelipe Balbi 
318f6c274e1SFelipe Balbi static int dwc3_pci_runtime_resume(struct device *dev)
319f6c274e1SFelipe Balbi {
3200f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3210f817ae6SFelipe Balbi 	struct platform_device	*dwc3 = dwc->dwc3;
3229cecca75SFelipe Balbi 	int			ret;
3239cecca75SFelipe Balbi 
3249cecca75SFelipe Balbi 	ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
3259cecca75SFelipe Balbi 	if (ret)
3269cecca75SFelipe Balbi 		return ret;
327f6c274e1SFelipe Balbi 
328f6c274e1SFelipe Balbi 	return pm_runtime_get(&dwc3->dev);
329f6c274e1SFelipe Balbi }
330696118c0SFelipe Balbi #endif /* CONFIG_PM */
331f6c274e1SFelipe Balbi 
332696118c0SFelipe Balbi #ifdef CONFIG_PM_SLEEP
3339cecca75SFelipe Balbi static int dwc3_pci_suspend(struct device *dev)
334e9af9229SFelipe Balbi {
3359cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3369cecca75SFelipe Balbi 
3379cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
3389cecca75SFelipe Balbi }
3399cecca75SFelipe Balbi 
3409cecca75SFelipe Balbi static int dwc3_pci_resume(struct device *dev)
3419cecca75SFelipe Balbi {
3429cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3439cecca75SFelipe Balbi 
3449cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
345e9af9229SFelipe Balbi }
346696118c0SFelipe Balbi #endif /* CONFIG_PM_SLEEP */
347e9af9229SFelipe Balbi 
348e9af9229SFelipe Balbi static struct dev_pm_ops dwc3_pci_dev_pm_ops = {
3499cecca75SFelipe Balbi 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
350f6c274e1SFelipe Balbi 	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
351e9af9229SFelipe Balbi 		NULL)
352e9af9229SFelipe Balbi };
353e9af9229SFelipe Balbi 
35472246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = {
3550949e99bSFelipe Balbi 	.name		= "dwc3-pci",
35672246da4SFelipe Balbi 	.id_table	= dwc3_pci_id_table,
35772246da4SFelipe Balbi 	.probe		= dwc3_pci_probe,
3587690417dSBill Pemberton 	.remove		= dwc3_pci_remove,
359e9af9229SFelipe Balbi 	.driver		= {
360e9af9229SFelipe Balbi 		.pm	= &dwc3_pci_dev_pm_ops,
361e9af9229SFelipe Balbi 	}
36272246da4SFelipe Balbi };
36372246da4SFelipe Balbi 
36472246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
3655945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
36672246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
36772246da4SFelipe Balbi 
36895656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver);
369