xref: /linux/drivers/usb/dwc3/dwc3-pci.c (revision 2655971ad4b34e97dd921df16bb0b08db9449df7)
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>
195741022cSHans de Goede #include <linux/gpio/machine.h>
20a89d977cSHeikki Krogerus #include <linux/acpi.h>
21cf48305dSHeikki Krogerus #include <linux/delay.h>
228f317b47SHuang Rui 
23b62cd96dSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BYT			0x0f37
2485601f8cSDavid Cohen #define PCI_DEVICE_ID_INTEL_MRFLD		0x119e
259a5a0783SJohn Youn #define PCI_DEVICE_ID_INTEL_BSW			0x22b7
2684a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTLP		0x9d30
2784a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTH		0xa130
28b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT			0x0aaa
291ffb4d5cSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BXT_M		0x1aaa
30b4c580a4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_APL			0x5aaa
314491ed50SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_KBP			0xa2b0
323c3caae4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CMLLP		0x02ee
333c3caae4SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CMLH		0x06ee
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
37f5ae8869SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_CNPV		0xa3b0
3800908693SHeikki Krogerus #define PCI_DEVICE_ID_INTEL_ICLLP		0x34ee
39dbb0569dSFelipe Balbi #define PCI_DEVICE_ID_INTEL_EHLLP		0x4b7e
40b3649deeSFelipe Balbi #define PCI_DEVICE_ID_INTEL_TGPLP		0xa0ee
4172246da4SFelipe Balbi 
4294116f81SAndy Shevchenko #define PCI_INTEL_BXT_DSM_GUID		"732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
439cecca75SFelipe Balbi #define PCI_INTEL_BXT_FUNC_PMU_PWR	4
449cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D0		0
459cecca75SFelipe Balbi #define PCI_INTEL_BXT_STATE_D3		3
469cecca75SFelipe Balbi 
477740d04dSHans de Goede #define GP_RWBAR			1
487740d04dSHans de Goede #define GP_RWREG1			0xa0
497740d04dSHans de Goede #define GP_RWREG1_ULPI_REFCLK_DISABLE	(1 << 17)
507740d04dSHans de Goede 
510f817ae6SFelipe Balbi /**
520f817ae6SFelipe Balbi  * struct dwc3_pci - Driver private structure
530f817ae6SFelipe Balbi  * @dwc3: child dwc3 platform_device
540f817ae6SFelipe Balbi  * @pci: our link to PCI bus
5594116f81SAndy Shevchenko  * @guid: _DSM GUID
569cecca75SFelipe Balbi  * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
5787d852deSAndy Shevchenko  * @wakeup_work: work for asynchronous resume
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 
785741022cSHans de Goede static struct gpiod_lookup_table platform_bytcr_gpios = {
795741022cSHans de Goede 	.dev_id		= "0000:00:16.0",
805741022cSHans de Goede 	.table		= {
815741022cSHans de Goede 		GPIO_LOOKUP("INT33FC:00", 54, "reset", GPIO_ACTIVE_HIGH),
825741022cSHans de Goede 		GPIO_LOOKUP("INT33FC:02", 14, "cs", GPIO_ACTIVE_HIGH),
835741022cSHans de Goede 		{}
845741022cSHans de Goede 	},
855741022cSHans de Goede };
865741022cSHans de Goede 
877740d04dSHans de Goede static int dwc3_byt_enable_ulpi_refclock(struct pci_dev *pci)
887740d04dSHans de Goede {
897740d04dSHans de Goede 	void __iomem	*reg;
907740d04dSHans de Goede 	u32		value;
917740d04dSHans de Goede 
927740d04dSHans de Goede 	reg = pcim_iomap(pci, GP_RWBAR, 0);
93b497fff6SWei Yongjun 	if (!reg)
94b497fff6SWei Yongjun 		return -ENOMEM;
957740d04dSHans de Goede 
967740d04dSHans de Goede 	value = readl(reg + GP_RWREG1);
977740d04dSHans de Goede 	if (!(value & GP_RWREG1_ULPI_REFCLK_DISABLE))
987740d04dSHans de Goede 		goto unmap; /* ULPI refclk already enabled */
997740d04dSHans de Goede 
1007740d04dSHans de Goede 	value &= ~GP_RWREG1_ULPI_REFCLK_DISABLE;
1017740d04dSHans de Goede 	writel(value, reg + GP_RWREG1);
1027740d04dSHans de Goede 	/* This comes from the Intel Android x86 tree w/o any explanation */
1037740d04dSHans de Goede 	msleep(100);
1047740d04dSHans de Goede unmap:
1057740d04dSHans de Goede 	pcim_iounmap(pci, reg);
1067740d04dSHans de Goede 	return 0;
1077740d04dSHans de Goede }
1087740d04dSHans de Goede 
1091a7b12f6SAndy Shevchenko static const struct property_entry dwc3_pci_intel_properties[] = {
1101a7b12f6SAndy Shevchenko 	PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
1111a7b12f6SAndy Shevchenko 	PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
1121a7b12f6SAndy Shevchenko 	{}
1131a7b12f6SAndy Shevchenko };
1140f817ae6SFelipe Balbi 
115c31d983bSAndy Shevchenko static const struct property_entry dwc3_pci_mrfld_properties[] = {
116c31d983bSAndy Shevchenko 	PROPERTY_ENTRY_STRING("dr_mode", "otg"),
117066c0959SAndy Shevchenko 	PROPERTY_ENTRY_STRING("linux,extcon-name", "mrfld_bcove_pwrsrc"),
118c31d983bSAndy Shevchenko 	PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
119c31d983bSAndy Shevchenko 	{}
120c31d983bSAndy Shevchenko };
121c31d983bSAndy Shevchenko 
1221a7b12f6SAndy Shevchenko static const struct property_entry dwc3_pci_amd_properties[] = {
123cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
124cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf),
125cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"),
126cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"),
127cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"),
128cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"),
129cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"),
130cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"),
131cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"),
132cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"),
133cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1),
1341a7b12f6SAndy Shevchenko 	/* FIXME these quirks should be removed when AMD NL tapes out */
135cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
136cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
137cf48305dSHeikki Krogerus 	PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
1380eae2fdeSJohn Youn 	PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
139e6fe66feSFelipe Balbi 	{}
140e6fe66feSFelipe Balbi };
141e6fe66feSFelipe Balbi 
1421a7b12f6SAndy Shevchenko static int dwc3_pci_quirks(struct dwc3_pci *dwc)
1431a7b12f6SAndy Shevchenko {
1441a7b12f6SAndy Shevchenko 	struct pci_dev			*pdev = dwc->pci;
145e6fe66feSFelipe Balbi 
1461a7b12f6SAndy Shevchenko 	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
1479cecca75SFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
1489cecca75SFelipe Balbi 				pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
14994116f81SAndy Shevchenko 			guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid);
1509cecca75SFelipe Balbi 			dwc->has_dsm_for_pm = true;
1519cecca75SFelipe Balbi 		}
1529cecca75SFelipe Balbi 
153e6fe66feSFelipe Balbi 		if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
154a89d977cSHeikki Krogerus 			struct gpio_desc *gpio;
1551a7b12f6SAndy Shevchenko 			int ret;
156a89d977cSHeikki Krogerus 
1577740d04dSHans de Goede 			/* On BYT the FW does not always enable the refclock */
1587740d04dSHans de Goede 			ret = dwc3_byt_enable_ulpi_refclock(pdev);
1597740d04dSHans de Goede 			if (ret)
1607740d04dSHans de Goede 				return ret;
1617740d04dSHans de Goede 
1624a56e413SAndy Shevchenko 			ret = devm_acpi_dev_add_driver_gpios(&pdev->dev,
163a89d977cSHeikki Krogerus 					acpi_dwc3_byt_gpios);
1644a56e413SAndy Shevchenko 			if (ret)
1654a56e413SAndy Shevchenko 				dev_dbg(&pdev->dev, "failed to add mapping table\n");
166a89d977cSHeikki Krogerus 
1672df033caSUwe Kleine-König 			/*
1685741022cSHans de Goede 			 * A lot of BYT devices lack ACPI resource entries for
1695741022cSHans de Goede 			 * the GPIOs, add a fallback mapping to the reference
1705741022cSHans de Goede 			 * design GPIOs which all boards seem to use.
1715741022cSHans de Goede 			 */
1725741022cSHans de Goede 			gpiod_add_lookup_table(&platform_bytcr_gpios);
1735741022cSHans de Goede 
1745741022cSHans de Goede 			/*
1752df033caSUwe Kleine-König 			 * These GPIOs will turn on the USB2 PHY. Note that we have to
1762df033caSUwe Kleine-König 			 * put the gpio descriptors again here because the phy driver
1772df033caSUwe Kleine-König 			 * might want to grab them, too.
1782df033caSUwe Kleine-König 			 */
1793004cfd6SStephan Gerhold 			gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
1802df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1812df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1822df033caSUwe Kleine-König 
183a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
1843004cfd6SStephan Gerhold 			gpiod_put(gpio);
185a89d977cSHeikki Krogerus 
1863004cfd6SStephan Gerhold 			gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
1872df033caSUwe Kleine-König 			if (IS_ERR(gpio))
1882df033caSUwe Kleine-König 				return PTR_ERR(gpio);
1892df033caSUwe Kleine-König 
1902df033caSUwe Kleine-König 			if (gpio) {
191a89d977cSHeikki Krogerus 				gpiod_set_value_cansleep(gpio, 1);
1923004cfd6SStephan Gerhold 				gpiod_put(gpio);
193a89d977cSHeikki Krogerus 				usleep_range(10000, 11000);
194a89d977cSHeikki Krogerus 			}
195a89d977cSHeikki Krogerus 		}
196e6fe66feSFelipe Balbi 	}
197a89d977cSHeikki Krogerus 
1982cd9ddf7SHeikki Krogerus 	return 0;
1992cd9ddf7SHeikki Krogerus }
20072246da4SFelipe Balbi 
2018eed00b2SManu Gautam #ifdef CONFIG_PM
2028eed00b2SManu Gautam static void dwc3_pci_resume_work(struct work_struct *work)
2038eed00b2SManu Gautam {
2048eed00b2SManu Gautam 	struct dwc3_pci *dwc = container_of(work, struct dwc3_pci, wakeup_work);
2058eed00b2SManu Gautam 	struct platform_device *dwc3 = dwc->dwc3;
2068eed00b2SManu Gautam 	int ret;
2078eed00b2SManu Gautam 
2088eed00b2SManu Gautam 	ret = pm_runtime_get_sync(&dwc3->dev);
209*2655971aSAditya Pakki 	if (ret) {
210*2655971aSAditya Pakki 		pm_runtime_put_sync_autosuspend(&dwc3->dev);
2118eed00b2SManu Gautam 		return;
212*2655971aSAditya Pakki 	}
2138eed00b2SManu Gautam 
2148eed00b2SManu Gautam 	pm_runtime_mark_last_busy(&dwc3->dev);
2158eed00b2SManu Gautam 	pm_runtime_put_sync_autosuspend(&dwc3->dev);
2168eed00b2SManu Gautam }
2178eed00b2SManu Gautam #endif
2188eed00b2SManu Gautam 
2191a7b12f6SAndy Shevchenko static int dwc3_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
22072246da4SFelipe Balbi {
2211a7b12f6SAndy Shevchenko 	struct property_entry *p = (struct property_entry *)id->driver_data;
2220f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc;
22372246da4SFelipe Balbi 	struct resource		res[2];
224b09e99eeSAndy Shevchenko 	int			ret;
225802ca850SChanho Park 	struct device		*dev = &pci->dev;
22672246da4SFelipe Balbi 
227f1c7e710SAndy Shevchenko 	ret = pcim_enable_device(pci);
22872246da4SFelipe Balbi 	if (ret) {
229802ca850SChanho Park 		dev_err(dev, "failed to enable pci device\n");
230802ca850SChanho Park 		return -ENODEV;
23172246da4SFelipe Balbi 	}
23272246da4SFelipe Balbi 
23372246da4SFelipe Balbi 	pci_set_master(pci);
23472246da4SFelipe Balbi 
2350f817ae6SFelipe Balbi 	dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
2360f817ae6SFelipe Balbi 	if (!dwc)
237f1c7e710SAndy Shevchenko 		return -ENOMEM;
2380f817ae6SFelipe Balbi 
2390f817ae6SFelipe Balbi 	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
2400f817ae6SFelipe Balbi 	if (!dwc->dwc3)
2410f817ae6SFelipe Balbi 		return -ENOMEM;
24272246da4SFelipe Balbi 
24372246da4SFelipe Balbi 	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
24472246da4SFelipe Balbi 
24572246da4SFelipe Balbi 	res[0].start	= pci_resource_start(pci, 0);
24672246da4SFelipe Balbi 	res[0].end	= pci_resource_end(pci, 0);
24772246da4SFelipe Balbi 	res[0].name	= "dwc_usb3";
24872246da4SFelipe Balbi 	res[0].flags	= IORESOURCE_MEM;
24972246da4SFelipe Balbi 
25072246da4SFelipe Balbi 	res[1].start	= pci->irq;
25172246da4SFelipe Balbi 	res[1].name	= "dwc_usb3";
25272246da4SFelipe Balbi 	res[1].flags	= IORESOURCE_IRQ;
25372246da4SFelipe Balbi 
2540f817ae6SFelipe Balbi 	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
25572246da4SFelipe Balbi 	if (ret) {
256802ca850SChanho Park 		dev_err(dev, "couldn't add resources to dwc3 device\n");
257cabdf83dSThinh Nguyen 		goto err;
25872246da4SFelipe Balbi 	}
25972246da4SFelipe Balbi 
2600f817ae6SFelipe Balbi 	dwc->pci = pci;
2610f817ae6SFelipe Balbi 	dwc->dwc3->dev.parent = dev;
2620f817ae6SFelipe Balbi 	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
26372246da4SFelipe Balbi 
2641a7b12f6SAndy Shevchenko 	ret = platform_device_add_properties(dwc->dwc3, p);
2651a7b12f6SAndy Shevchenko 	if (ret < 0)
2669bbfceeaSNavid Emamdoost 		goto err;
2671a7b12f6SAndy Shevchenko 
2680f817ae6SFelipe Balbi 	ret = dwc3_pci_quirks(dwc);
269474799f0SHeikki Krogerus 	if (ret)
270474799f0SHeikki Krogerus 		goto err;
271474799f0SHeikki Krogerus 
2720f817ae6SFelipe Balbi 	ret = platform_device_add(dwc->dwc3);
27372246da4SFelipe Balbi 	if (ret) {
274802ca850SChanho Park 		dev_err(dev, "failed to register dwc3 device\n");
2752cd9ddf7SHeikki Krogerus 		goto err;
27672246da4SFelipe Balbi 	}
27772246da4SFelipe Balbi 
278e9af9229SFelipe Balbi 	device_init_wakeup(dev, true);
2790f817ae6SFelipe Balbi 	pci_set_drvdata(pci, dwc);
280e9af9229SFelipe Balbi 	pm_runtime_put(dev);
2818eed00b2SManu Gautam #ifdef CONFIG_PM
2828eed00b2SManu Gautam 	INIT_WORK(&dwc->wakeup_work, dwc3_pci_resume_work);
2838eed00b2SManu Gautam #endif
284e9af9229SFelipe Balbi 
28572246da4SFelipe Balbi 	return 0;
2862cd9ddf7SHeikki Krogerus err:
2870f817ae6SFelipe Balbi 	platform_device_put(dwc->dwc3);
28872246da4SFelipe Balbi 	return ret;
28972246da4SFelipe Balbi }
29072246da4SFelipe Balbi 
291fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci)
29272246da4SFelipe Balbi {
2930f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = pci_get_drvdata(pci);
2947b412b04SKuppuswamy Sathyanarayanan 	struct pci_dev		*pdev = dwc->pci;
2950f817ae6SFelipe Balbi 
2967b412b04SKuppuswamy Sathyanarayanan 	if (pdev->device == PCI_DEVICE_ID_INTEL_BYT)
2975741022cSHans de Goede 		gpiod_remove_lookup_table(&platform_bytcr_gpios);
2988eed00b2SManu Gautam #ifdef CONFIG_PM
2998eed00b2SManu Gautam 	cancel_work_sync(&dwc->wakeup_work);
3008eed00b2SManu Gautam #endif
301e9af9229SFelipe Balbi 	device_init_wakeup(&pci->dev, false);
302e9af9229SFelipe Balbi 	pm_runtime_get(&pci->dev);
3030f817ae6SFelipe Balbi 	platform_device_unregister(dwc->dwc3);
30472246da4SFelipe Balbi }
30572246da4SFelipe Balbi 
306782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = {
3071a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BSW),
3081a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties },
3091a7b12f6SAndy Shevchenko 
3101a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BYT),
3111a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3121a7b12f6SAndy Shevchenko 
3131a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MRFLD),
314c31d983bSAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_mrfld_properties, },
3151a7b12f6SAndy Shevchenko 
3163c3caae4SHeikki Krogerus 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CMLLP),
3173c3caae4SHeikki Krogerus 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3183c3caae4SHeikki Krogerus 
3197ae622c9SFelipe Balbi 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CMLH),
3207ae622c9SFelipe Balbi 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3217ae622c9SFelipe Balbi 
3221a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SPTLP),
3231a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3241a7b12f6SAndy Shevchenko 
3251a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SPTH),
3261a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3271a7b12f6SAndy Shevchenko 
3281a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BXT),
3291a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3301a7b12f6SAndy Shevchenko 
3311a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BXT_M),
3321a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3331a7b12f6SAndy Shevchenko 
3341a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_APL),
3351a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3361a7b12f6SAndy Shevchenko 
3371a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_KBP),
3381a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3391a7b12f6SAndy Shevchenko 
3401a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_GLK),
3411a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3421a7b12f6SAndy Shevchenko 
3431a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CNPLP),
3441a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3451a7b12f6SAndy Shevchenko 
3461a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CNPH),
3471a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3481a7b12f6SAndy Shevchenko 
349f5ae8869SHeikki Krogerus 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_CNPV),
350f5ae8869SHeikki Krogerus 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
351f5ae8869SHeikki Krogerus 
3521a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICLLP),
3531a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
3541a7b12f6SAndy Shevchenko 
355dbb0569dSFelipe Balbi 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_EHLLP),
356dbb0569dSFelipe Balbi 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
357dbb0569dSFelipe Balbi 
358b3649deeSFelipe Balbi 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGPLP),
359b3649deeSFelipe Balbi 	  (kernel_ulong_t) &dwc3_pci_intel_properties, },
360b3649deeSFelipe Balbi 
3611a7b12f6SAndy Shevchenko 	{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_NL_USB),
3621a7b12f6SAndy Shevchenko 	  (kernel_ulong_t) &dwc3_pci_amd_properties, },
36372246da4SFelipe Balbi 	{  }	/* Terminating Entry */
36472246da4SFelipe Balbi };
36572246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
36672246da4SFelipe Balbi 
36736daf3aaSFelipe Balbi #if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP)
36836daf3aaSFelipe Balbi static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
36936daf3aaSFelipe Balbi {
37036daf3aaSFelipe Balbi 	union acpi_object *obj;
37136daf3aaSFelipe Balbi 	union acpi_object tmp;
37236daf3aaSFelipe Balbi 	union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
37336daf3aaSFelipe Balbi 
37436daf3aaSFelipe Balbi 	if (!dwc->has_dsm_for_pm)
37536daf3aaSFelipe Balbi 		return 0;
37636daf3aaSFelipe Balbi 
37736daf3aaSFelipe Balbi 	tmp.type = ACPI_TYPE_INTEGER;
37836daf3aaSFelipe Balbi 	tmp.integer.value = param;
37936daf3aaSFelipe Balbi 
38094116f81SAndy Shevchenko 	obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), &dwc->guid,
38136daf3aaSFelipe Balbi 			1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
38236daf3aaSFelipe Balbi 	if (!obj) {
38336daf3aaSFelipe Balbi 		dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
38436daf3aaSFelipe Balbi 		return -EIO;
38536daf3aaSFelipe Balbi 	}
38636daf3aaSFelipe Balbi 
38736daf3aaSFelipe Balbi 	ACPI_FREE(obj);
38836daf3aaSFelipe Balbi 
38936daf3aaSFelipe Balbi 	return 0;
39036daf3aaSFelipe Balbi }
39136daf3aaSFelipe Balbi #endif /* CONFIG_PM || CONFIG_PM_SLEEP */
39236daf3aaSFelipe Balbi 
393e9af9229SFelipe Balbi #ifdef CONFIG_PM
394e9af9229SFelipe Balbi static int dwc3_pci_runtime_suspend(struct device *dev)
395e9af9229SFelipe Balbi {
3969cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
3979cecca75SFelipe Balbi 
398de3ef1ebSRafael J. Wysocki 	if (device_can_wakeup(dev))
3999cecca75SFelipe Balbi 		return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
400e9af9229SFelipe Balbi 
401e9af9229SFelipe Balbi 	return -EBUSY;
402e9af9229SFelipe Balbi }
403e9af9229SFelipe Balbi 
404f6c274e1SFelipe Balbi static int dwc3_pci_runtime_resume(struct device *dev)
405f6c274e1SFelipe Balbi {
4060f817ae6SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
4079cecca75SFelipe Balbi 	int			ret;
4089cecca75SFelipe Balbi 
4099cecca75SFelipe Balbi 	ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
4109cecca75SFelipe Balbi 	if (ret)
4119cecca75SFelipe Balbi 		return ret;
412f6c274e1SFelipe Balbi 
4138eed00b2SManu Gautam 	queue_work(pm_wq, &dwc->wakeup_work);
4148eed00b2SManu Gautam 
4158eed00b2SManu Gautam 	return 0;
416f6c274e1SFelipe Balbi }
417696118c0SFelipe Balbi #endif /* CONFIG_PM */
418f6c274e1SFelipe Balbi 
419696118c0SFelipe Balbi #ifdef CONFIG_PM_SLEEP
4209cecca75SFelipe Balbi static int dwc3_pci_suspend(struct device *dev)
421e9af9229SFelipe Balbi {
4229cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
4239cecca75SFelipe Balbi 
4249cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
4259cecca75SFelipe Balbi }
4269cecca75SFelipe Balbi 
4279cecca75SFelipe Balbi static int dwc3_pci_resume(struct device *dev)
4289cecca75SFelipe Balbi {
4299cecca75SFelipe Balbi 	struct dwc3_pci		*dwc = dev_get_drvdata(dev);
4309cecca75SFelipe Balbi 
4319cecca75SFelipe Balbi 	return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
432e9af9229SFelipe Balbi }
433696118c0SFelipe Balbi #endif /* CONFIG_PM_SLEEP */
434e9af9229SFelipe Balbi 
43595aa932cSDoug Wilson static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
4369cecca75SFelipe Balbi 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
437f6c274e1SFelipe Balbi 	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
438e9af9229SFelipe Balbi 		NULL)
439e9af9229SFelipe Balbi };
440e9af9229SFelipe Balbi 
44172246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = {
4420949e99bSFelipe Balbi 	.name		= "dwc3-pci",
44372246da4SFelipe Balbi 	.id_table	= dwc3_pci_id_table,
44472246da4SFelipe Balbi 	.probe		= dwc3_pci_probe,
4457690417dSBill Pemberton 	.remove		= dwc3_pci_remove,
446e9af9229SFelipe Balbi 	.driver		= {
447e9af9229SFelipe Balbi 		.pm	= &dwc3_pci_dev_pm_ops,
448e9af9229SFelipe Balbi 	}
44972246da4SFelipe Balbi };
45072246da4SFelipe Balbi 
45172246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
4525945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
45372246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
45472246da4SFelipe Balbi 
45595656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver);
456