xref: /linux/drivers/usb/dwc3/dwc3-pci.c (revision 5fd54ace4721fc5ce2bb5aef6318fcf17f421460)
1*5fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
272246da4SFelipe Balbi /**
372246da4SFelipe Balbi  * dwc3-pci.c - PCI Specific glue layer
472246da4SFelipe Balbi  *
572246da4SFelipe Balbi  * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
672246da4SFelipe Balbi  *
772246da4SFelipe Balbi  * Authors: Felipe Balbi <balbi@ti.com>,
872246da4SFelipe Balbi  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
972246da4SFelipe Balbi  *
105945f789SFelipe Balbi  * This program is free software: you can redistribute it and/or modify
115945f789SFelipe Balbi  * it under the terms of the GNU General Public License version 2  of
125945f789SFelipe Balbi  * the License as published by the Free Software Foundation.
1372246da4SFelipe Balbi  *
145945f789SFelipe Balbi  * This program is distributed in the hope that it will be useful,
155945f789SFelipe Balbi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
165945f789SFelipe Balbi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
175945f789SFelipe Balbi  * GNU General Public License for more details.
1872246da4SFelipe Balbi  */
1972246da4SFelipe Balbi 
2072246da4SFelipe Balbi #include <linux/kernel.h>
2146a57283SStephen Rothwell #include <linux/module.h>
2272246da4SFelipe Balbi #include <linux/slab.h>
2372246da4SFelipe Balbi #include <linux/pci.h>
248eed00b2SManu Gautam #include <linux/workqueue.h>
25e9af9229SFelipe Balbi #include <linux/pm_runtime.h>
2672246da4SFelipe Balbi #include <linux/platform_device.h>
27a89d977cSHeikki Krogerus #include <linux/gpio/consumer.h>
28a89d977cSHeikki Krogerus #include <linux/acpi.h>
29cf48305dSHeikki Krogerus #include <linux/delay.h>
308f317b47SHuang Rui 
3172246da4SFelipe Balbi #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3		0xabcd
3241adc59cSJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI	0xabce
33e8095a25SJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31	0xabcf
34b62cd96dSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BYT			0x0f37
3585601f8cSDavid Cohen #define PCI_DEVICE_ID_INTEL_MRFLD		0x119e
369a5a0783SJohn Youn #define PCI_DEVICE_ID_INTEL_BSW			0x22b7
3784a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTLP		0x9d30
3884a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTH		0xa130
39b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT			0x0aaa
401ffb4d5cSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT_M		0x1aaa
41b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_APL			0x5aaa
424491ed50SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_KBP			0xa2b0
438f8983a5SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_GLK			0x31aa
4468217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPLP		0x9dee
4568217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPH		0xa36e
4672246da4SFelipe Balbi 
4794116f81SAndy Shevchenko #define PCI_INTEL_BXT_DSM_GUID		"732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
489cecca75SFelipe Balbi #define PCI_INTEL_BXT_FUNC_PMU_PWR	4
499cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D0		0
509cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D3		3
519cecca75SFelipe Balbi 
520f817ae6SFelipe Balbi /**
530f817ae6SFelipe Balbi  * struct dwc3_pci - Driver private structure
540f817ae6SFelipe Balbi  * @dwc3: child dwc3 platform_device
550f817ae6SFelipe Balbi  * @pci: our link to PCI bus
5694116f81SAndy Shevchenko  * @guid: _DSM GUID
579cecca75SFelipe Balbi  * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
580f817ae6SFelipe Balbi  */
590f817ae6SFelipe Balbi struct dwc3_pci {
600f817ae6SFelipe Balbi 	struct platform_device *dwc3;
610f817ae6SFelipe Balbi 	struct pci_dev *pci;
629cecca75SFelipe Balbi 
6394116f81SAndy Shevchenko 	guid_t guid;
649cecca75SFelipe Balbi 
659cecca75SFelipe Balbi 	unsigned int has_dsm_for_pm:1;
668eed00b2SManu Gautam 	struct work_struct wakeup_work;
670f817ae6SFelipe Balbi };
680f817ae6SFelipe Balbi 
69a89d977cSHeikki Krogerus static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
70a89d977cSHeikki Krogerus static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
71a89d977cSHeikki Krogerus 
72a89d977cSHeikki Krogerus static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
73a89d977cSHeikki Krogerus 	{ "reset-gpios", &reset_gpios, 1 },
74a89d977cSHeikki Krogerus 	{ "cs-gpios", &cs_gpios, 1 },
75a89d977cSHeikki Krogerus 	{ },
76a89d977cSHeikki Krogerus };
77a89d977cSHeikki Krogerus 
780f817ae6SFelipe Balbi static int dwc3_pci_quirks(struct dwc3_pci *dwc)
792cd9ddf7SHeikki Krogerus {
800f817ae6SFelipe Balbi 	struct platform_device		*dwc3 = dwc->dwc3;
810f817ae6SFelipe Balbi 	struct pci_dev			*pdev = dwc->pci;
820f817ae6SFelipe Balbi 
832cd9ddf7SHeikki Krogerus 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
842cd9ddf7SHeikki Krogerus 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
85cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
86cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
87cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf),
88cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"),
89cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"),
90cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"),
91cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"),
92cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"),
93cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"),
94cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"),
95cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"),
96cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1),
972cd9ddf7SHeikki Krogerus 			/*
982cd9ddf7SHeikki Krogerus 			 * FIXME these quirks should be removed when AMD NL
99cf48305dSHeikki Krogerus 			 * tapes out
1002cd9ddf7SHeikki Krogerus 			 */
101cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
102cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
103cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
1040eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
105cf48305dSHeikki Krogerus 			{ },
106cf48305dSHeikki Krogerus 		};
1072cd9ddf7SHeikki Krogerus 
108cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
1092cd9ddf7SHeikki Krogerus 	}
1102cd9ddf7SHeikki Krogerus 
111e6fe66feSFelipe Balbi 	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
112e6fe66feSFelipe Balbi 		int ret;
113e6fe66feSFelipe Balbi 
114e6fe66feSFelipe Balbi 		struct property_entry properties[] = {
11551c1685dSHans de Goede 			PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
1160eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
117e6fe66feSFelipe Balbi 			{ }
118e6fe66feSFelipe Balbi 		};
119e6fe66feSFelipe Balbi 
120e6fe66feSFelipe Balbi 		ret = platform_device_add_properties(dwc3, properties);
121e6fe66feSFelipe Balbi 		if (ret < 0)
122e6fe66feSFelipe Balbi 			return ret;
123e6fe66feSFelipe Balbi 
1249cecca75SFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
1259cecca75SFelipe Balbi 				pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
12694116f81SAndy Shevchenko 			guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid);
1279cecca75SFelipe Balbi 			dwc->has_dsm_for_pm = true;
1289cecca75SFelipe Balbi 		}
1299cecca75SFelipe Balbi 
130e6fe66feSFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
131a89d977cSHeikki Krogerus 			struct gpio_desc *gpio;
132a89d977cSHeikki Krogerus 
1334a56e413SAndy Shevchenko 			ret = devm_acpi_dev_add_driver_gpios(&pdev->dev,
134a89d977cSHeikki Krogerus 					acpi_dwc3_byt_gpios);
1354a56e413SAndy Shevchenko 			if (ret)
1364a56e413SAndy Shevchenko 				dev_dbg(&pdev->dev, "failed to add mapping table\n");
137a89d977cSHeikki Krogerus 
1382df033caSUwe Kleine-König 			/*
1392df033caSUwe Kleine-König 			 * These GPIOs will turn on the USB2 PHY. Note that we have to
1402df033caSUwe Kleine-König 			 * put the gpio descriptors again here because the phy driver
1412df033caSUwe Kleine-König 			 * might want to grab them, too.
1422df033caSUwe Kleine-König 			 */
1432df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
1442df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1452df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1462df033caSUwe Kleine-König 
147a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
148a89d977cSHeikki Krogerus 			gpiod_put(gpio);
149a89d977cSHeikki Krogerus 
1502df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
1512df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1522df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1532df033caSUwe Kleine-König 
1542df033caSUwe Kleine-König 			if (gpio) {
155a89d977cSHeikki Krogerus 				gpiod_set_value_cansleep(gpio, 1);
156a89d977cSHeikki Krogerus 				gpiod_put(gpio);
157a89d977cSHeikki Krogerus 				usleep_range(10000, 11000);
158a89d977cSHeikki Krogerus 			}
159a89d977cSHeikki Krogerus 		}
160e6fe66feSFelipe Balbi 	}
161a89d977cSHeikki Krogerus 
162bb7f3d6dSJohn Youn 	if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
163bb7f3d6dSJohn Youn 	    (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
164bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
165bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
166cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
167cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
168cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
169cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
1700eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
171cf48305dSHeikki Krogerus 			{ },
172cf48305dSHeikki Krogerus 		};
173bb7f3d6dSJohn Youn 
174cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
175bb7f3d6dSJohn Youn 	}
176bb7f3d6dSJohn Youn 
1772cd9ddf7SHeikki Krogerus 	return 0;
1782cd9ddf7SHeikki Krogerus }
17972246da4SFelipe Balbi 
1808eed00b2SManu Gautam #ifdef CONFIG_PM
1818eed00b2SManu Gautam static void dwc3_pci_resume_work(struct work_struct *work)
1828eed00b2SManu Gautam {
1838eed00b2SManu Gautam 	struct dwc3_pci *dwc = container_of(work, struct dwc3_pci, wakeup_work);
1848eed00b2SManu Gautam 	struct platform_device *dwc3 = dwc->dwc3;
1858eed00b2SManu Gautam 	int ret;
1868eed00b2SManu Gautam 
1878eed00b2SManu Gautam 	ret = pm_runtime_get_sync(&dwc3->dev);
1888eed00b2SManu Gautam 	if (ret)
1898eed00b2SManu Gautam 		return;
1908eed00b2SManu Gautam 
1918eed00b2SManu Gautam 	pm_runtime_mark_last_busy(&dwc3->dev);
1928eed00b2SManu Gautam 	pm_runtime_put_sync_autosuspend(&dwc3->dev);
1938eed00b2SManu Gautam }
1948eed00b2SManu Gautam #endif
1958eed00b2SManu Gautam 
19641ac7b3aSBill Pemberton static int dwc3_pci_probe(struct pci_dev *pci,
19772246da4SFelipe Balbi 		const struct pci_device_id *id)
19872246da4SFelipe Balbi {
1990f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc;
20072246da4SFelipe Balbi 	struct resource		res[2];
201b09e99eeSAndy Shevchenko 	int			ret;
202802ca850SChanho Park 	struct device		*dev = &pci->dev;
20372246da4SFelipe Balbi 
204f1c7e710SAndy Shevchenko 	ret = pcim_enable_device(pci);
20572246da4SFelipe Balbi 	if (ret) {
206802ca850SChanho Park 		dev_err(dev, "failed to enable pci device\n");
207802ca850SChanho Park 		return -ENODEV;
20872246da4SFelipe Balbi 	}
20972246da4SFelipe Balbi 
21072246da4SFelipe Balbi 	pci_set_master(pci);
21172246da4SFelipe Balbi 
2120f817ae6SFelipe Balbi 	dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
2130f817ae6SFelipe Balbi 	if (!dwc)
214f1c7e710SAndy Shevchenko 		return -ENOMEM;
2150f817ae6SFelipe Balbi 
2160f817ae6SFelipe Balbi 	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
2170f817ae6SFelipe Balbi 	if (!dwc->dwc3)
2180f817ae6SFelipe Balbi 		return -ENOMEM;
21972246da4SFelipe Balbi 
22072246da4SFelipe Balbi 	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
22172246da4SFelipe Balbi 
22272246da4SFelipe Balbi 	res[0].start	= pci_resource_start(pci, 0);
22372246da4SFelipe Balbi 	res[0].end	= pci_resource_end(pci, 0);
22472246da4SFelipe Balbi 	res[0].name	= "dwc_usb3";
22572246da4SFelipe Balbi 	res[0].flags	= IORESOURCE_MEM;
22672246da4SFelipe Balbi 
22772246da4SFelipe Balbi 	res[1].start	= pci->irq;
22872246da4SFelipe Balbi 	res[1].name	= "dwc_usb3";
22972246da4SFelipe Balbi 	res[1].flags	= IORESOURCE_IRQ;
23072246da4SFelipe Balbi 
2310f817ae6SFelipe Balbi 	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
23272246da4SFelipe Balbi 	if (ret) {
233802ca850SChanho Park 		dev_err(dev, "couldn't add resources to dwc3 device\n");
234f1c7e710SAndy Shevchenko 		return ret;
23572246da4SFelipe Balbi 	}
23672246da4SFelipe Balbi 
2370f817ae6SFelipe Balbi 	dwc->pci = pci;
2380f817ae6SFelipe Balbi 	dwc->dwc3->dev.parent = dev;
2390f817ae6SFelipe Balbi 	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
24072246da4SFelipe Balbi 
2410f817ae6SFelipe Balbi 	ret = dwc3_pci_quirks(dwc);
242474799f0SHeikki Krogerus 	if (ret)
243474799f0SHeikki Krogerus 		goto err;
244474799f0SHeikki Krogerus 
2450f817ae6SFelipe Balbi 	ret = platform_device_add(dwc->dwc3);
24672246da4SFelipe Balbi 	if (ret) {
247802ca850SChanho Park 		dev_err(dev, "failed to register dwc3 device\n");
2482cd9ddf7SHeikki Krogerus 		goto err;
24972246da4SFelipe Balbi 	}
25072246da4SFelipe Balbi 
251e9af9229SFelipe Balbi 	device_init_wakeup(dev, true);
2520f817ae6SFelipe Balbi 	pci_set_drvdata(pci, dwc);
253e9af9229SFelipe Balbi 	pm_runtime_put(dev);
2548eed00b2SManu Gautam #ifdef CONFIG_PM
2558eed00b2SManu Gautam 	INIT_WORK(&dwc->wakeup_work, dwc3_pci_resume_work);
2568eed00b2SManu Gautam #endif
257e9af9229SFelipe Balbi 
25872246da4SFelipe Balbi 	return 0;
2592cd9ddf7SHeikki Krogerus err:
2600f817ae6SFelipe Balbi 	platform_device_put(dwc->dwc3);
26172246da4SFelipe Balbi 	return ret;
26272246da4SFelipe Balbi }
26372246da4SFelipe Balbi 
264fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci)
26572246da4SFelipe Balbi {
2660f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = pci_get_drvdata(pci);
2670f817ae6SFelipe Balbi 
2688eed00b2SManu Gautam #ifdef CONFIG_PM
2698eed00b2SManu Gautam 	cancel_work_sync(&dwc->wakeup_work);
2708eed00b2SManu Gautam #endif
271e9af9229SFelipe Balbi 	device_init_wakeup(&pci->dev, false);
272e9af9229SFelipe Balbi 	pm_runtime_get(&pci->dev);
2730f817ae6SFelipe Balbi 	platform_device_unregister(dwc->dwc3);
27472246da4SFelipe Balbi }
27572246da4SFelipe Balbi 
276782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = {
27772246da4SFelipe Balbi 	{
27872246da4SFelipe Balbi 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
27972246da4SFelipe Balbi 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
28072246da4SFelipe Balbi 	},
28141adc59cSJohn Youn 	{
28241adc59cSJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
28341adc59cSJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
28441adc59cSJohn Youn 	},
285e8095a25SJohn Youn 	{
286e8095a25SJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
287e8095a25SJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
288e8095a25SJohn Youn 	},
2897d643664SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
290b62cd96dSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
29185601f8cSDavid Cohen 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
29284a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
29384a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
294b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
2951ffb4d5cSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
296b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
2974491ed50SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
2988f8983a5SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
29968217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), },
30068217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), },
3019755449dSHuang Rui 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
30272246da4SFelipe Balbi 	{  }	/* Terminating Entry */
30372246da4SFelipe Balbi };
30472246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
30572246da4SFelipe Balbi 
30636daf3aaSFelipe Balbi #if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP)
30736daf3aaSFelipe Balbi static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
30836daf3aaSFelipe Balbi {
30936daf3aaSFelipe Balbi 	union acpi_object *obj;
31036daf3aaSFelipe Balbi 	union acpi_object tmp;
31136daf3aaSFelipe Balbi 	union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
31236daf3aaSFelipe Balbi 
31336daf3aaSFelipe Balbi 	if (!dwc->has_dsm_for_pm)
31436daf3aaSFelipe Balbi 		return 0;
31536daf3aaSFelipe Balbi 
31636daf3aaSFelipe Balbi 	tmp.type = ACPI_TYPE_INTEGER;
31736daf3aaSFelipe Balbi 	tmp.integer.value = param;
31836daf3aaSFelipe Balbi 
31994116f81SAndy Shevchenko 	obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), &dwc->guid,
32036daf3aaSFelipe Balbi 			1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
32136daf3aaSFelipe Balbi 	if (!obj) {
32236daf3aaSFelipe Balbi 		dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
32336daf3aaSFelipe Balbi 		return -EIO;
32436daf3aaSFelipe Balbi 	}
32536daf3aaSFelipe Balbi 
32636daf3aaSFelipe Balbi 	ACPI_FREE(obj);
32736daf3aaSFelipe Balbi 
32836daf3aaSFelipe Balbi 	return 0;
32936daf3aaSFelipe Balbi }
33036daf3aaSFelipe Balbi #endif /* CONFIG_PM || CONFIG_PM_SLEEP */
33136daf3aaSFelipe Balbi 
332e9af9229SFelipe Balbi #ifdef CONFIG_PM
333e9af9229SFelipe Balbi static int dwc3_pci_runtime_suspend(struct device *dev)
334e9af9229SFelipe Balbi {
3359cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3369cecca75SFelipe Balbi 
337de3ef1ebSRafael J. Wysocki 	if (device_can_wakeup(dev))
3389cecca75SFelipe Balbi 		return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
339e9af9229SFelipe Balbi 
340e9af9229SFelipe Balbi 	return -EBUSY;
341e9af9229SFelipe Balbi }
342e9af9229SFelipe Balbi 
343f6c274e1SFelipe Balbi static int dwc3_pci_runtime_resume(struct device *dev)
344f6c274e1SFelipe Balbi {
3450f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3469cecca75SFelipe Balbi 	int			ret;
3479cecca75SFelipe Balbi 
3489cecca75SFelipe Balbi 	ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
3499cecca75SFelipe Balbi 	if (ret)
3509cecca75SFelipe Balbi 		return ret;
351f6c274e1SFelipe Balbi 
3528eed00b2SManu Gautam 	queue_work(pm_wq, &dwc->wakeup_work);
3538eed00b2SManu Gautam 
3548eed00b2SManu Gautam 	return 0;
355f6c274e1SFelipe Balbi }
356696118c0SFelipe Balbi #endif /* CONFIG_PM */
357f6c274e1SFelipe Balbi 
358696118c0SFelipe Balbi #ifdef CONFIG_PM_SLEEP
3599cecca75SFelipe Balbi static int dwc3_pci_suspend(struct device *dev)
360e9af9229SFelipe Balbi {
3619cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3629cecca75SFelipe Balbi 
3639cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
3649cecca75SFelipe Balbi }
3659cecca75SFelipe Balbi 
3669cecca75SFelipe Balbi static int dwc3_pci_resume(struct device *dev)
3679cecca75SFelipe Balbi {
3689cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3699cecca75SFelipe Balbi 
3709cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
371e9af9229SFelipe Balbi }
372696118c0SFelipe Balbi #endif /* CONFIG_PM_SLEEP */
373e9af9229SFelipe Balbi 
37495aa932cSDoug Wilson static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
3759cecca75SFelipe Balbi 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
376f6c274e1SFelipe Balbi 	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
377e9af9229SFelipe Balbi 		NULL)
378e9af9229SFelipe Balbi };
379e9af9229SFelipe Balbi 
38072246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = {
3810949e99bSFelipe Balbi 	.name		= "dwc3-pci",
38272246da4SFelipe Balbi 	.id_table	= dwc3_pci_id_table,
38372246da4SFelipe Balbi 	.probe		= dwc3_pci_probe,
3847690417dSBill Pemberton 	.remove		= dwc3_pci_remove,
385e9af9229SFelipe Balbi 	.driver		= {
386e9af9229SFelipe Balbi 		.pm	= &dwc3_pci_dev_pm_ops,
387e9af9229SFelipe Balbi 	}
38872246da4SFelipe Balbi };
38972246da4SFelipe Balbi 
39072246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
3915945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
39272246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
39372246da4SFelipe Balbi 
39495656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver);
395