xref: /linux/drivers/usb/dwc3/dwc3-pci.c (revision 00908693c481f7298adf8cf4d2ff3dfbea8c375f)
15fd54aceSGreg 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  */
1072246da4SFelipe Balbi 
1172246da4SFelipe Balbi #include <linux/kernel.h>
1246a57283SStephen Rothwell #include <linux/module.h>
1372246da4SFelipe Balbi #include <linux/slab.h>
1472246da4SFelipe Balbi #include <linux/pci.h>
158eed00b2SManu Gautam #include <linux/workqueue.h>
16e9af9229SFelipe Balbi #include <linux/pm_runtime.h>
1772246da4SFelipe Balbi #include <linux/platform_device.h>
18a89d977cSHeikki Krogerus #include <linux/gpio/consumer.h>
19a89d977cSHeikki Krogerus #include <linux/acpi.h>
20cf48305dSHeikki Krogerus #include <linux/delay.h>
218f317b47SHuang Rui 
2272246da4SFelipe Balbi #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3		0xabcd
2341adc59cSJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI	0xabce
24e8095a25SJohn Youn #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31	0xabcf
25b62cd96dSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BYT			0x0f37
2685601f8cSDavid Cohen #define PCI_DEVICE_ID_INTEL_MRFLD		0x119e
279a5a0783SJohn Youn #define PCI_DEVICE_ID_INTEL_BSW			0x22b7
2884a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTLP		0x9d30
2984a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTH		0xa130
30b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT			0x0aaa
311ffb4d5cSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT_M		0x1aaa
32b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_APL			0x5aaa
334491ed50SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_KBP			0xa2b0
348f8983a5SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_GLK			0x31aa
3568217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPLP		0x9dee
3668217959SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPH		0xa36e
37*00908693SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_ICLLP		0x34ee
3872246da4SFelipe Balbi 
3994116f81SAndy Shevchenko #define PCI_INTEL_BXT_DSM_GUID		"732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
409cecca75SFelipe Balbi #define PCI_INTEL_BXT_FUNC_PMU_PWR	4
419cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D0		0
429cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D3		3
439cecca75SFelipe Balbi 
440f817ae6SFelipe Balbi /**
450f817ae6SFelipe Balbi  * struct dwc3_pci - Driver private structure
460f817ae6SFelipe Balbi  * @dwc3: child dwc3 platform_device
470f817ae6SFelipe Balbi  * @pci: our link to PCI bus
4894116f81SAndy Shevchenko  * @guid: _DSM GUID
499cecca75SFelipe Balbi  * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
500f817ae6SFelipe Balbi  */
510f817ae6SFelipe Balbi struct dwc3_pci {
520f817ae6SFelipe Balbi 	struct platform_device *dwc3;
530f817ae6SFelipe Balbi 	struct pci_dev *pci;
549cecca75SFelipe Balbi 
5594116f81SAndy Shevchenko 	guid_t guid;
569cecca75SFelipe Balbi 
579cecca75SFelipe Balbi 	unsigned int has_dsm_for_pm:1;
588eed00b2SManu Gautam 	struct work_struct wakeup_work;
590f817ae6SFelipe Balbi };
600f817ae6SFelipe Balbi 
61a89d977cSHeikki Krogerus static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
62a89d977cSHeikki Krogerus static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
63a89d977cSHeikki Krogerus 
64a89d977cSHeikki Krogerus static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
65a89d977cSHeikki Krogerus 	{ "reset-gpios", &reset_gpios, 1 },
66a89d977cSHeikki Krogerus 	{ "cs-gpios", &cs_gpios, 1 },
67a89d977cSHeikki Krogerus 	{ },
68a89d977cSHeikki Krogerus };
69a89d977cSHeikki Krogerus 
700f817ae6SFelipe Balbi static int dwc3_pci_quirks(struct dwc3_pci *dwc)
712cd9ddf7SHeikki Krogerus {
720f817ae6SFelipe Balbi 	struct platform_device		*dwc3 = dwc->dwc3;
730f817ae6SFelipe Balbi 	struct pci_dev			*pdev = dwc->pci;
740f817ae6SFelipe Balbi 
752cd9ddf7SHeikki Krogerus 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
762cd9ddf7SHeikki Krogerus 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
77cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
78cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
79cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf),
80cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"),
81cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"),
82cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"),
83cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"),
84cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"),
85cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"),
86cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"),
87cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"),
88cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1),
892cd9ddf7SHeikki Krogerus 			/*
902cd9ddf7SHeikki Krogerus 			 * FIXME these quirks should be removed when AMD NL
91cf48305dSHeikki Krogerus 			 * tapes out
922cd9ddf7SHeikki Krogerus 			 */
93cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
94cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
95cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
960eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
97cf48305dSHeikki Krogerus 			{ },
98cf48305dSHeikki Krogerus 		};
992cd9ddf7SHeikki Krogerus 
100cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
1012cd9ddf7SHeikki Krogerus 	}
1022cd9ddf7SHeikki Krogerus 
103e6fe66feSFelipe Balbi 	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
104e6fe66feSFelipe Balbi 		int ret;
105e6fe66feSFelipe Balbi 
106e6fe66feSFelipe Balbi 		struct property_entry properties[] = {
10751c1685dSHans de Goede 			PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
1080eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
109e6fe66feSFelipe Balbi 			{ }
110e6fe66feSFelipe Balbi 		};
111e6fe66feSFelipe Balbi 
112e6fe66feSFelipe Balbi 		ret = platform_device_add_properties(dwc3, properties);
113e6fe66feSFelipe Balbi 		if (ret < 0)
114e6fe66feSFelipe Balbi 			return ret;
115e6fe66feSFelipe Balbi 
1169cecca75SFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
1179cecca75SFelipe Balbi 				pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
11894116f81SAndy Shevchenko 			guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid);
1199cecca75SFelipe Balbi 			dwc->has_dsm_for_pm = true;
1209cecca75SFelipe Balbi 		}
1219cecca75SFelipe Balbi 
122e6fe66feSFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
123a89d977cSHeikki Krogerus 			struct gpio_desc *gpio;
124a89d977cSHeikki Krogerus 
1254a56e413SAndy Shevchenko 			ret = devm_acpi_dev_add_driver_gpios(&pdev->dev,
126a89d977cSHeikki Krogerus 					acpi_dwc3_byt_gpios);
1274a56e413SAndy Shevchenko 			if (ret)
1284a56e413SAndy Shevchenko 				dev_dbg(&pdev->dev, "failed to add mapping table\n");
129a89d977cSHeikki Krogerus 
1302df033caSUwe Kleine-König 			/*
1312df033caSUwe Kleine-König 			 * These GPIOs will turn on the USB2 PHY. Note that we have to
1322df033caSUwe Kleine-König 			 * put the gpio descriptors again here because the phy driver
1332df033caSUwe Kleine-König 			 * might want to grab them, too.
1342df033caSUwe Kleine-König 			 */
1352df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
1362df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1372df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1382df033caSUwe Kleine-König 
139a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
140a89d977cSHeikki Krogerus 			gpiod_put(gpio);
141a89d977cSHeikki Krogerus 
1422df033caSUwe Kleine-König 			gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
1432df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1442df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1452df033caSUwe Kleine-König 
1462df033caSUwe Kleine-König 			if (gpio) {
147a89d977cSHeikki Krogerus 				gpiod_set_value_cansleep(gpio, 1);
148a89d977cSHeikki Krogerus 				gpiod_put(gpio);
149a89d977cSHeikki Krogerus 				usleep_range(10000, 11000);
150a89d977cSHeikki Krogerus 			}
151a89d977cSHeikki Krogerus 		}
152e6fe66feSFelipe Balbi 	}
153a89d977cSHeikki Krogerus 
154bb7f3d6dSJohn Youn 	if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
155bb7f3d6dSJohn Youn 	    (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
156bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
157bb7f3d6dSJohn Youn 	     pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
158cf48305dSHeikki Krogerus 		struct property_entry properties[] = {
159cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
160cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
161cf48305dSHeikki Krogerus 			PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
1620eae2fdeSJohn Youn 			PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
163cf48305dSHeikki Krogerus 			{ },
164cf48305dSHeikki Krogerus 		};
165bb7f3d6dSJohn Youn 
166cf48305dSHeikki Krogerus 		return platform_device_add_properties(dwc3, properties);
167bb7f3d6dSJohn Youn 	}
168bb7f3d6dSJohn Youn 
1692cd9ddf7SHeikki Krogerus 	return 0;
1702cd9ddf7SHeikki Krogerus }
17172246da4SFelipe Balbi 
1728eed00b2SManu Gautam #ifdef CONFIG_PM
1738eed00b2SManu Gautam static void dwc3_pci_resume_work(struct work_struct *work)
1748eed00b2SManu Gautam {
1758eed00b2SManu Gautam 	struct dwc3_pci *dwc = container_of(work, struct dwc3_pci, wakeup_work);
1768eed00b2SManu Gautam 	struct platform_device *dwc3 = dwc->dwc3;
1778eed00b2SManu Gautam 	int ret;
1788eed00b2SManu Gautam 
1798eed00b2SManu Gautam 	ret = pm_runtime_get_sync(&dwc3->dev);
1808eed00b2SManu Gautam 	if (ret)
1818eed00b2SManu Gautam 		return;
1828eed00b2SManu Gautam 
1838eed00b2SManu Gautam 	pm_runtime_mark_last_busy(&dwc3->dev);
1848eed00b2SManu Gautam 	pm_runtime_put_sync_autosuspend(&dwc3->dev);
1858eed00b2SManu Gautam }
1868eed00b2SManu Gautam #endif
1878eed00b2SManu Gautam 
18841ac7b3aSBill Pemberton static int dwc3_pci_probe(struct pci_dev *pci,
18972246da4SFelipe Balbi 		const struct pci_device_id *id)
19072246da4SFelipe Balbi {
1910f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc;
19272246da4SFelipe Balbi 	struct resource		res[2];
193b09e99eeSAndy Shevchenko 	int			ret;
194802ca850SChanho Park 	struct device		*dev = &pci->dev;
19572246da4SFelipe Balbi 
196f1c7e710SAndy Shevchenko 	ret = pcim_enable_device(pci);
19772246da4SFelipe Balbi 	if (ret) {
198802ca850SChanho Park 		dev_err(dev, "failed to enable pci device\n");
199802ca850SChanho Park 		return -ENODEV;
20072246da4SFelipe Balbi 	}
20172246da4SFelipe Balbi 
20272246da4SFelipe Balbi 	pci_set_master(pci);
20372246da4SFelipe Balbi 
2040f817ae6SFelipe Balbi 	dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
2050f817ae6SFelipe Balbi 	if (!dwc)
206f1c7e710SAndy Shevchenko 		return -ENOMEM;
2070f817ae6SFelipe Balbi 
2080f817ae6SFelipe Balbi 	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
2090f817ae6SFelipe Balbi 	if (!dwc->dwc3)
2100f817ae6SFelipe Balbi 		return -ENOMEM;
21172246da4SFelipe Balbi 
21272246da4SFelipe Balbi 	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
21372246da4SFelipe Balbi 
21472246da4SFelipe Balbi 	res[0].start	= pci_resource_start(pci, 0);
21572246da4SFelipe Balbi 	res[0].end	= pci_resource_end(pci, 0);
21672246da4SFelipe Balbi 	res[0].name	= "dwc_usb3";
21772246da4SFelipe Balbi 	res[0].flags	= IORESOURCE_MEM;
21872246da4SFelipe Balbi 
21972246da4SFelipe Balbi 	res[1].start	= pci->irq;
22072246da4SFelipe Balbi 	res[1].name	= "dwc_usb3";
22172246da4SFelipe Balbi 	res[1].flags	= IORESOURCE_IRQ;
22272246da4SFelipe Balbi 
2230f817ae6SFelipe Balbi 	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
22472246da4SFelipe Balbi 	if (ret) {
225802ca850SChanho Park 		dev_err(dev, "couldn't add resources to dwc3 device\n");
226cabdf83dSThinh Nguyen 		goto err;
22772246da4SFelipe Balbi 	}
22872246da4SFelipe Balbi 
2290f817ae6SFelipe Balbi 	dwc->pci = pci;
2300f817ae6SFelipe Balbi 	dwc->dwc3->dev.parent = dev;
2310f817ae6SFelipe Balbi 	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
23272246da4SFelipe Balbi 
2330f817ae6SFelipe Balbi 	ret = dwc3_pci_quirks(dwc);
234474799f0SHeikki Krogerus 	if (ret)
235474799f0SHeikki Krogerus 		goto err;
236474799f0SHeikki Krogerus 
2370f817ae6SFelipe Balbi 	ret = platform_device_add(dwc->dwc3);
23872246da4SFelipe Balbi 	if (ret) {
239802ca850SChanho Park 		dev_err(dev, "failed to register dwc3 device\n");
2402cd9ddf7SHeikki Krogerus 		goto err;
24172246da4SFelipe Balbi 	}
24272246da4SFelipe Balbi 
243e9af9229SFelipe Balbi 	device_init_wakeup(dev, true);
2440f817ae6SFelipe Balbi 	pci_set_drvdata(pci, dwc);
245e9af9229SFelipe Balbi 	pm_runtime_put(dev);
2468eed00b2SManu Gautam #ifdef CONFIG_PM
2478eed00b2SManu Gautam 	INIT_WORK(&dwc->wakeup_work, dwc3_pci_resume_work);
2488eed00b2SManu Gautam #endif
249e9af9229SFelipe Balbi 
25072246da4SFelipe Balbi 	return 0;
2512cd9ddf7SHeikki Krogerus err:
2520f817ae6SFelipe Balbi 	platform_device_put(dwc->dwc3);
25372246da4SFelipe Balbi 	return ret;
25472246da4SFelipe Balbi }
25572246da4SFelipe Balbi 
256fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci)
25772246da4SFelipe Balbi {
2580f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = pci_get_drvdata(pci);
2590f817ae6SFelipe Balbi 
2608eed00b2SManu Gautam #ifdef CONFIG_PM
2618eed00b2SManu Gautam 	cancel_work_sync(&dwc->wakeup_work);
2628eed00b2SManu Gautam #endif
263e9af9229SFelipe Balbi 	device_init_wakeup(&pci->dev, false);
264e9af9229SFelipe Balbi 	pm_runtime_get(&pci->dev);
2650f817ae6SFelipe Balbi 	platform_device_unregister(dwc->dwc3);
26672246da4SFelipe Balbi }
26772246da4SFelipe Balbi 
268782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = {
26972246da4SFelipe Balbi 	{
27072246da4SFelipe Balbi 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
27172246da4SFelipe Balbi 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
27272246da4SFelipe Balbi 	},
27341adc59cSJohn Youn 	{
27441adc59cSJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
27541adc59cSJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
27641adc59cSJohn Youn 	},
277e8095a25SJohn Youn 	{
278e8095a25SJohn Youn 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
279e8095a25SJohn Youn 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
280e8095a25SJohn Youn 	},
2817d643664SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
282b62cd96dSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
28385601f8cSDavid Cohen 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
28484a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
28584a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
286b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
2871ffb4d5cSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
288b4c580a4SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
2894491ed50SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
2908f8983a5SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
29168217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), },
29268217959SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), },
293*00908693SHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICLLP), },
2949755449dSHuang Rui 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
29572246da4SFelipe Balbi 	{  }	/* Terminating Entry */
29672246da4SFelipe Balbi };
29772246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
29872246da4SFelipe Balbi 
29936daf3aaSFelipe Balbi #if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP)
30036daf3aaSFelipe Balbi static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
30136daf3aaSFelipe Balbi {
30236daf3aaSFelipe Balbi 	union acpi_object *obj;
30336daf3aaSFelipe Balbi 	union acpi_object tmp;
30436daf3aaSFelipe Balbi 	union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
30536daf3aaSFelipe Balbi 
30636daf3aaSFelipe Balbi 	if (!dwc->has_dsm_for_pm)
30736daf3aaSFelipe Balbi 		return 0;
30836daf3aaSFelipe Balbi 
30936daf3aaSFelipe Balbi 	tmp.type = ACPI_TYPE_INTEGER;
31036daf3aaSFelipe Balbi 	tmp.integer.value = param;
31136daf3aaSFelipe Balbi 
31294116f81SAndy Shevchenko 	obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), &dwc->guid,
31336daf3aaSFelipe Balbi 			1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
31436daf3aaSFelipe Balbi 	if (!obj) {
31536daf3aaSFelipe Balbi 		dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
31636daf3aaSFelipe Balbi 		return -EIO;
31736daf3aaSFelipe Balbi 	}
31836daf3aaSFelipe Balbi 
31936daf3aaSFelipe Balbi 	ACPI_FREE(obj);
32036daf3aaSFelipe Balbi 
32136daf3aaSFelipe Balbi 	return 0;
32236daf3aaSFelipe Balbi }
32336daf3aaSFelipe Balbi #endif /* CONFIG_PM || CONFIG_PM_SLEEP */
32436daf3aaSFelipe Balbi 
325e9af9229SFelipe Balbi #ifdef CONFIG_PM
326e9af9229SFelipe Balbi static int dwc3_pci_runtime_suspend(struct device *dev)
327e9af9229SFelipe Balbi {
3289cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3299cecca75SFelipe Balbi 
330de3ef1ebSRafael J. Wysocki 	if (device_can_wakeup(dev))
3319cecca75SFelipe Balbi 		return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
332e9af9229SFelipe Balbi 
333e9af9229SFelipe Balbi 	return -EBUSY;
334e9af9229SFelipe Balbi }
335e9af9229SFelipe Balbi 
336f6c274e1SFelipe Balbi static int dwc3_pci_runtime_resume(struct device *dev)
337f6c274e1SFelipe Balbi {
3380f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3399cecca75SFelipe Balbi 	int			ret;
3409cecca75SFelipe Balbi 
3419cecca75SFelipe Balbi 	ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
3429cecca75SFelipe Balbi 	if (ret)
3439cecca75SFelipe Balbi 		return ret;
344f6c274e1SFelipe Balbi 
3458eed00b2SManu Gautam 	queue_work(pm_wq, &dwc->wakeup_work);
3468eed00b2SManu Gautam 
3478eed00b2SManu Gautam 	return 0;
348f6c274e1SFelipe Balbi }
349696118c0SFelipe Balbi #endif /* CONFIG_PM */
350f6c274e1SFelipe Balbi 
351696118c0SFelipe Balbi #ifdef CONFIG_PM_SLEEP
3529cecca75SFelipe Balbi static int dwc3_pci_suspend(struct device *dev)
353e9af9229SFelipe Balbi {
3549cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3559cecca75SFelipe Balbi 
3569cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
3579cecca75SFelipe Balbi }
3589cecca75SFelipe Balbi 
3599cecca75SFelipe Balbi static int dwc3_pci_resume(struct device *dev)
3609cecca75SFelipe Balbi {
3619cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3629cecca75SFelipe Balbi 
3639cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
364e9af9229SFelipe Balbi }
365696118c0SFelipe Balbi #endif /* CONFIG_PM_SLEEP */
366e9af9229SFelipe Balbi 
36795aa932cSDoug Wilson static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
3689cecca75SFelipe Balbi 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
369f6c274e1SFelipe Balbi 	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
370e9af9229SFelipe Balbi 		NULL)
371e9af9229SFelipe Balbi };
372e9af9229SFelipe Balbi 
37372246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = {
3740949e99bSFelipe Balbi 	.name		= "dwc3-pci",
37572246da4SFelipe Balbi 	.id_table	= dwc3_pci_id_table,
37672246da4SFelipe Balbi 	.probe		= dwc3_pci_probe,
3777690417dSBill Pemberton 	.remove		= dwc3_pci_remove,
378e9af9229SFelipe Balbi 	.driver		= {
379e9af9229SFelipe Balbi 		.pm	= &dwc3_pci_dev_pm_ops,
380e9af9229SFelipe Balbi 	}
38172246da4SFelipe Balbi };
38272246da4SFelipe Balbi 
38372246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
3845945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
38572246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
38672246da4SFelipe Balbi 
38795656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver);
388