blob: c961a94d136b5248a5e242a6ab3370b22f3fa360 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Felipe Balbi72246da2011-08-19 18:10:58 +03002/**
3 * dwc3-pci.c - PCI Specific glue layer
4 *
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03006 *
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Felipe Balbi72246da2011-08-19 18:10:58 +03009 */
10
11#include <linux/kernel.h>
Stephen Rothwell46a57282011-08-23 15:08:54 +100012#include <linux/module.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030013#include <linux/slab.h>
14#include <linux/pci.h>
Manu Gautam8eed00b2017-09-27 16:49:21 +053015#include <linux/workqueue.h>
Felipe Balbie9af9222016-05-17 10:15:02 +030016#include <linux/pm_runtime.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030017#include <linux/platform_device.h>
Heikki Krogerusa89d9772015-05-13 15:26:50 +030018#include <linux/gpio/consumer.h>
19#include <linux/acpi.h>
Heikki Krogeruscf483052016-04-22 11:17:39 +030020#include <linux/delay.h>
Huang Rui8f317b42014-10-28 19:54:24 +080021
John Youn9a5a0782015-09-25 23:47:53 -070022#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
23#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
24#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
25#define PCI_DEVICE_ID_INTEL_BYT 0x0f37
26#define PCI_DEVICE_ID_INTEL_MRFLD 0x119e
27#define PCI_DEVICE_ID_INTEL_BSW 0x22b7
28#define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30
29#define PCI_DEVICE_ID_INTEL_SPTH 0xa130
Heikki Krogerusb4c580a2015-10-21 14:37:04 +030030#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa
Heikki Krogerus1ffb4d52016-04-01 17:13:10 +030031#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa
Heikki Krogerusb4c580a2015-10-21 14:37:04 +030032#define PCI_DEVICE_ID_INTEL_APL 0x5aaa
Heikki Krogerus4491ed52016-04-01 17:13:11 +030033#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0
Heikki Krogerus8f8983a2016-04-01 17:13:12 +030034#define PCI_DEVICE_ID_INTEL_GLK 0x31aa
Heikki Krogerus68217952016-04-01 17:13:13 +030035#define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee
36#define PCI_DEVICE_ID_INTEL_CNPH 0xa36e
Felipe Balbi72246da2011-08-19 18:10:58 +030037
Andy Shevchenko94116f82017-06-05 19:40:46 +030038#define PCI_INTEL_BXT_DSM_GUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
Felipe Balbi9cecca72016-10-24 10:40:18 +030039#define PCI_INTEL_BXT_FUNC_PMU_PWR 4
40#define PCI_INTEL_BXT_STATE_D0 0
41#define PCI_INTEL_BXT_STATE_D3 3
42
Felipe Balbi0f817ae2016-10-24 10:29:01 +030043/**
44 * struct dwc3_pci - Driver private structure
45 * @dwc3: child dwc3 platform_device
46 * @pci: our link to PCI bus
Andy Shevchenko94116f82017-06-05 19:40:46 +030047 * @guid: _DSM GUID
Felipe Balbi9cecca72016-10-24 10:40:18 +030048 * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
Felipe Balbi0f817ae2016-10-24 10:29:01 +030049 */
50struct dwc3_pci {
51 struct platform_device *dwc3;
52 struct pci_dev *pci;
Felipe Balbi9cecca72016-10-24 10:40:18 +030053
Andy Shevchenko94116f82017-06-05 19:40:46 +030054 guid_t guid;
Felipe Balbi9cecca72016-10-24 10:40:18 +030055
56 unsigned int has_dsm_for_pm:1;
Manu Gautam8eed00b2017-09-27 16:49:21 +053057 struct work_struct wakeup_work;
Felipe Balbi0f817ae2016-10-24 10:29:01 +030058};
59
Heikki Krogerusa89d9772015-05-13 15:26:50 +030060static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
61static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
62
63static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
64 { "reset-gpios", &reset_gpios, 1 },
65 { "cs-gpios", &cs_gpios, 1 },
66 { },
67};
68
Felipe Balbi0f817ae2016-10-24 10:29:01 +030069static int dwc3_pci_quirks(struct dwc3_pci *dwc)
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +020070{
Felipe Balbi0f817ae2016-10-24 10:29:01 +030071 struct platform_device *dwc3 = dwc->dwc3;
72 struct pci_dev *pdev = dwc->pci;
73
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +020074 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
75 pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
Heikki Krogeruscf483052016-04-22 11:17:39 +030076 struct property_entry properties[] = {
77 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
78 PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf),
79 PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"),
80 PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"),
81 PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"),
82 PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"),
83 PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"),
84 PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"),
85 PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"),
86 PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"),
87 PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1),
88 /*
89 * FIXME these quirks should be removed when AMD NL
90 * tapes out
91 */
92 PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
93 PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
94 PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
John Youn0eae2fd2016-11-28 16:30:58 -080095 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
Heikki Krogeruscf483052016-04-22 11:17:39 +030096 { },
97 };
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +020098
Heikki Krogeruscf483052016-04-22 11:17:39 +030099 return platform_device_add_properties(dwc3, properties);
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +0200100 }
101
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300102 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
103 int ret;
Heikki Krogerusa89d9772015-05-13 15:26:50 +0300104
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300105 struct property_entry properties[] = {
Hans de Goede51c16852016-12-27 13:13:42 +0200106 PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
John Youn0eae2fd2016-11-28 16:30:58 -0800107 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300108 { }
109 };
Heikki Krogerusa89d9772015-05-13 15:26:50 +0300110
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300111 ret = platform_device_add_properties(dwc3, properties);
112 if (ret < 0)
113 return ret;
Heikki Krogerusa89d9772015-05-13 15:26:50 +0300114
Felipe Balbi9cecca72016-10-24 10:40:18 +0300115 if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
116 pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
Andy Shevchenko94116f82017-06-05 19:40:46 +0300117 guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid);
Felipe Balbi9cecca72016-10-24 10:40:18 +0300118 dwc->has_dsm_for_pm = true;
119 }
120
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300121 if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
122 struct gpio_desc *gpio;
Uwe Kleine-König2df033c2015-07-06 11:09:48 +0200123
Andy Shevchenko4a56e412017-03-22 16:08:07 +0200124 ret = devm_acpi_dev_add_driver_gpios(&pdev->dev,
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300125 acpi_dwc3_byt_gpios);
Andy Shevchenko4a56e412017-03-22 16:08:07 +0200126 if (ret)
127 dev_dbg(&pdev->dev, "failed to add mapping table\n");
Uwe Kleine-König2df033c2015-07-06 11:09:48 +0200128
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300129 /*
130 * These GPIOs will turn on the USB2 PHY. Note that we have to
131 * put the gpio descriptors again here because the phy driver
132 * might want to grab them, too.
133 */
134 gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
135 if (IS_ERR(gpio))
136 return PTR_ERR(gpio);
137
Heikki Krogerusa89d9772015-05-13 15:26:50 +0300138 gpiod_set_value_cansleep(gpio, 1);
139 gpiod_put(gpio);
Felipe Balbie6fe66f2016-06-07 12:49:52 +0300140
141 gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
142 if (IS_ERR(gpio))
143 return PTR_ERR(gpio);
144
145 if (gpio) {
146 gpiod_set_value_cansleep(gpio, 1);
147 gpiod_put(gpio);
148 usleep_range(10000, 11000);
149 }
Heikki Krogerusa89d9772015-05-13 15:26:50 +0300150 }
151 }
152
John Younbb7f3d62015-09-26 00:11:15 -0700153 if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
154 (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
155 pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
156 pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
Heikki Krogeruscf483052016-04-22 11:17:39 +0300157 struct property_entry properties[] = {
158 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
159 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
160 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
John Youn0eae2fd2016-11-28 16:30:58 -0800161 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
Heikki Krogeruscf483052016-04-22 11:17:39 +0300162 { },
163 };
John Younbb7f3d62015-09-26 00:11:15 -0700164
Heikki Krogeruscf483052016-04-22 11:17:39 +0300165 return platform_device_add_properties(dwc3, properties);
John Younbb7f3d62015-09-26 00:11:15 -0700166 }
167
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +0200168 return 0;
169}
Felipe Balbi72246da2011-08-19 18:10:58 +0300170
Manu Gautam8eed00b2017-09-27 16:49:21 +0530171#ifdef CONFIG_PM
172static void dwc3_pci_resume_work(struct work_struct *work)
173{
174 struct dwc3_pci *dwc = container_of(work, struct dwc3_pci, wakeup_work);
175 struct platform_device *dwc3 = dwc->dwc3;
176 int ret;
177
178 ret = pm_runtime_get_sync(&dwc3->dev);
179 if (ret)
180 return;
181
182 pm_runtime_mark_last_busy(&dwc3->dev);
183 pm_runtime_put_sync_autosuspend(&dwc3->dev);
184}
185#endif
186
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500187static int dwc3_pci_probe(struct pci_dev *pci,
Felipe Balbi72246da2011-08-19 18:10:58 +0300188 const struct pci_device_id *id)
189{
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300190 struct dwc3_pci *dwc;
Felipe Balbi72246da2011-08-19 18:10:58 +0300191 struct resource res[2];
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300192 int ret;
Chanho Park802ca852012-02-15 18:27:55 +0900193 struct device *dev = &pci->dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300194
Andy Shevchenkof1c7e712014-05-15 15:53:33 +0300195 ret = pcim_enable_device(pci);
Felipe Balbi72246da2011-08-19 18:10:58 +0300196 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900197 dev_err(dev, "failed to enable pci device\n");
198 return -ENODEV;
Felipe Balbi72246da2011-08-19 18:10:58 +0300199 }
200
Felipe Balbi72246da2011-08-19 18:10:58 +0300201 pci_set_master(pci);
202
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300203 dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
204 if (!dwc)
Andy Shevchenkof1c7e712014-05-15 15:53:33 +0300205 return -ENOMEM;
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300206
207 dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
208 if (!dwc->dwc3)
209 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300210
211 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
212
213 res[0].start = pci_resource_start(pci, 0);
214 res[0].end = pci_resource_end(pci, 0);
215 res[0].name = "dwc_usb3";
216 res[0].flags = IORESOURCE_MEM;
217
218 res[1].start = pci->irq;
219 res[1].name = "dwc_usb3";
220 res[1].flags = IORESOURCE_IRQ;
221
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300222 ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
Felipe Balbi72246da2011-08-19 18:10:58 +0300223 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900224 dev_err(dev, "couldn't add resources to dwc3 device\n");
Thinh Nguyencabdf832018-03-19 13:07:35 -0700225 goto err;
Felipe Balbi72246da2011-08-19 18:10:58 +0300226 }
227
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300228 dwc->pci = pci;
229 dwc->dwc3->dev.parent = dev;
230 ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
Felipe Balbi72246da2011-08-19 18:10:58 +0300231
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300232 ret = dwc3_pci_quirks(dwc);
Heikki Krogerus474799f2016-04-22 11:17:37 +0300233 if (ret)
234 goto err;
235
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300236 ret = platform_device_add(dwc->dwc3);
Felipe Balbi72246da2011-08-19 18:10:58 +0300237 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900238 dev_err(dev, "failed to register dwc3 device\n");
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +0200239 goto err;
Felipe Balbi72246da2011-08-19 18:10:58 +0300240 }
241
Felipe Balbie9af9222016-05-17 10:15:02 +0300242 device_init_wakeup(dev, true);
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300243 pci_set_drvdata(pci, dwc);
Felipe Balbie9af9222016-05-17 10:15:02 +0300244 pm_runtime_put(dev);
Manu Gautam8eed00b2017-09-27 16:49:21 +0530245#ifdef CONFIG_PM
246 INIT_WORK(&dwc->wakeup_work, dwc3_pci_resume_work);
247#endif
Felipe Balbie9af9222016-05-17 10:15:02 +0300248
Felipe Balbi72246da2011-08-19 18:10:58 +0300249 return 0;
Heikki Krogerus2cd9ddf2015-01-12 14:20:14 +0200250err:
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300251 platform_device_put(dwc->dwc3);
Felipe Balbi72246da2011-08-19 18:10:58 +0300252 return ret;
253}
254
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500255static void dwc3_pci_remove(struct pci_dev *pci)
Felipe Balbi72246da2011-08-19 18:10:58 +0300256{
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300257 struct dwc3_pci *dwc = pci_get_drvdata(pci);
258
Manu Gautam8eed00b2017-09-27 16:49:21 +0530259#ifdef CONFIG_PM
260 cancel_work_sync(&dwc->wakeup_work);
261#endif
Felipe Balbie9af9222016-05-17 10:15:02 +0300262 device_init_wakeup(&pci->dev, false);
263 pm_runtime_get(&pci->dev);
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300264 platform_device_unregister(dwc->dwc3);
Felipe Balbi72246da2011-08-19 18:10:58 +0300265}
266
Jingoo Han782df202013-11-28 14:15:46 +0900267static const struct pci_device_id dwc3_pci_id_table[] = {
Felipe Balbi72246da2011-08-19 18:10:58 +0300268 {
269 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
270 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
271 },
John Youn41adc592015-08-07 11:04:14 -0700272 {
273 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
274 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
275 },
John Youne8095a22015-08-07 11:47:25 -0700276 {
277 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
278 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
279 },
Alan Cox7d643662014-09-24 10:40:25 +0300280 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
Heikki Krogerusb62cd962013-09-17 10:38:13 +0300281 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
David Cohen85601f82013-09-26 13:01:44 -0700282 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
Heikki Krogerus84a2b612014-12-18 16:39:14 +0200283 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
284 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
Heikki Krogerusb4c580a2015-10-21 14:37:04 +0300285 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
Heikki Krogerus1ffb4d52016-04-01 17:13:10 +0300286 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
Heikki Krogerusb4c580a2015-10-21 14:37:04 +0300287 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
Heikki Krogerus4491ed52016-04-01 17:13:11 +0300288 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
Heikki Krogerus8f8983a2016-04-01 17:13:12 +0300289 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
Heikki Krogerus68217952016-04-01 17:13:13 +0300290 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPLP), },
291 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CNPH), },
Huang Rui97554492014-10-31 11:11:17 +0800292 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
Felipe Balbi72246da2011-08-19 18:10:58 +0300293 { } /* Terminating Entry */
294};
295MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
296
Felipe Balbi36daf3a2016-11-16 13:16:22 +0200297#if defined(CONFIG_PM) || defined(CONFIG_PM_SLEEP)
298static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
299{
300 union acpi_object *obj;
301 union acpi_object tmp;
302 union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp);
303
304 if (!dwc->has_dsm_for_pm)
305 return 0;
306
307 tmp.type = ACPI_TYPE_INTEGER;
308 tmp.integer.value = param;
309
Andy Shevchenko94116f82017-06-05 19:40:46 +0300310 obj = acpi_evaluate_dsm(ACPI_HANDLE(&dwc->pci->dev), &dwc->guid,
Felipe Balbi36daf3a2016-11-16 13:16:22 +0200311 1, PCI_INTEL_BXT_FUNC_PMU_PWR, &argv4);
312 if (!obj) {
313 dev_err(&dwc->pci->dev, "failed to evaluate _DSM\n");
314 return -EIO;
315 }
316
317 ACPI_FREE(obj);
318
319 return 0;
320}
321#endif /* CONFIG_PM || CONFIG_PM_SLEEP */
322
Felipe Balbie9af9222016-05-17 10:15:02 +0300323#ifdef CONFIG_PM
324static int dwc3_pci_runtime_suspend(struct device *dev)
325{
Felipe Balbi9cecca72016-10-24 10:40:18 +0300326 struct dwc3_pci *dwc = dev_get_drvdata(dev);
327
Rafael J. Wysockide3ef1e2017-06-24 01:58:53 +0200328 if (device_can_wakeup(dev))
Felipe Balbi9cecca72016-10-24 10:40:18 +0300329 return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
Felipe Balbie9af9222016-05-17 10:15:02 +0300330
331 return -EBUSY;
332}
333
Felipe Balbif6c274e2016-07-28 10:16:12 +0300334static int dwc3_pci_runtime_resume(struct device *dev)
335{
Felipe Balbi0f817ae2016-10-24 10:29:01 +0300336 struct dwc3_pci *dwc = dev_get_drvdata(dev);
Felipe Balbi9cecca72016-10-24 10:40:18 +0300337 int ret;
338
339 ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
340 if (ret)
341 return ret;
Felipe Balbif6c274e2016-07-28 10:16:12 +0300342
Manu Gautam8eed00b2017-09-27 16:49:21 +0530343 queue_work(pm_wq, &dwc->wakeup_work);
344
345 return 0;
Felipe Balbif6c274e2016-07-28 10:16:12 +0300346}
Felipe Balbi696118c2016-09-07 13:39:37 +0300347#endif /* CONFIG_PM */
Felipe Balbif6c274e2016-07-28 10:16:12 +0300348
Felipe Balbi696118c2016-09-07 13:39:37 +0300349#ifdef CONFIG_PM_SLEEP
Felipe Balbi9cecca72016-10-24 10:40:18 +0300350static int dwc3_pci_suspend(struct device *dev)
Felipe Balbie9af9222016-05-17 10:15:02 +0300351{
Felipe Balbi9cecca72016-10-24 10:40:18 +0300352 struct dwc3_pci *dwc = dev_get_drvdata(dev);
353
354 return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
355}
356
357static int dwc3_pci_resume(struct device *dev)
358{
359 struct dwc3_pci *dwc = dev_get_drvdata(dev);
360
361 return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
Felipe Balbie9af9222016-05-17 10:15:02 +0300362}
Felipe Balbi696118c2016-09-07 13:39:37 +0300363#endif /* CONFIG_PM_SLEEP */
Felipe Balbie9af9222016-05-17 10:15:02 +0300364
Doug Wilson95aa9322017-08-08 16:50:16 +0530365static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
Felipe Balbi9cecca72016-10-24 10:40:18 +0300366 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
Felipe Balbif6c274e2016-07-28 10:16:12 +0300367 SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
Felipe Balbie9af9222016-05-17 10:15:02 +0300368 NULL)
369};
370
Felipe Balbi72246da2011-08-19 18:10:58 +0300371static struct pci_driver dwc3_pci_driver = {
Felipe Balbi0949e992011-10-12 10:44:56 +0300372 .name = "dwc3-pci",
Felipe Balbi72246da2011-08-19 18:10:58 +0300373 .id_table = dwc3_pci_id_table,
374 .probe = dwc3_pci_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500375 .remove = dwc3_pci_remove,
Felipe Balbie9af9222016-05-17 10:15:02 +0300376 .driver = {
377 .pm = &dwc3_pci_dev_pm_ops,
378 }
Felipe Balbi72246da2011-08-19 18:10:58 +0300379};
380
381MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
Felipe Balbi5945f782013-06-30 14:15:11 +0300382MODULE_LICENSE("GPL v2");
Felipe Balbi72246da2011-08-19 18:10:58 +0300383MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
384
Greg Kroah-Hartman95656332011-11-18 10:14:24 -0800385module_pci_driver(dwc3_pci_driver);