xref: /openbmc/linux/drivers/usb/cdns3/core.c (revision 50642709)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Cadence USBSS DRD Driver.
4  *
5  * Copyright (C) 2018-2019 Cadence.
6  * Copyright (C) 2017-2018 NXP
7  * Copyright (C) 2019 Texas Instruments
8  *
9  * Author: Peter Chen <peter.chen@nxp.com>
10  *         Pawel Laszczak <pawell@cadence.com>
11  *         Roger Quadros <rogerq@ti.com>
12  */
13 
14 #include <linux/dma-mapping.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18 #include <linux/interrupt.h>
19 #include <linux/io.h>
20 #include <linux/pm_runtime.h>
21 
22 #include "gadget.h"
23 #include "core.h"
24 #include "host-export.h"
25 #include "gadget-export.h"
26 #include "drd.h"
27 
28 static int cdns3_idle_init(struct cdns3 *cdns);
29 
30 static int cdns3_role_start(struct cdns3 *cdns, enum usb_role role)
31 {
32 	int ret;
33 
34 	if (WARN_ON(role > USB_ROLE_DEVICE))
35 		return 0;
36 
37 	mutex_lock(&cdns->mutex);
38 	cdns->role = role;
39 	mutex_unlock(&cdns->mutex);
40 
41 	if (!cdns->roles[role])
42 		return -ENXIO;
43 
44 	if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE)
45 		return 0;
46 
47 	mutex_lock(&cdns->mutex);
48 	ret = cdns->roles[role]->start(cdns);
49 	if (!ret)
50 		cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE;
51 	mutex_unlock(&cdns->mutex);
52 
53 	return ret;
54 }
55 
56 static void cdns3_role_stop(struct cdns3 *cdns)
57 {
58 	enum usb_role role = cdns->role;
59 
60 	if (WARN_ON(role > USB_ROLE_DEVICE))
61 		return;
62 
63 	if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE)
64 		return;
65 
66 	mutex_lock(&cdns->mutex);
67 	cdns->roles[role]->stop(cdns);
68 	cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE;
69 	mutex_unlock(&cdns->mutex);
70 }
71 
72 static void cdns3_exit_roles(struct cdns3 *cdns)
73 {
74 	cdns3_role_stop(cdns);
75 	cdns3_drd_exit(cdns);
76 }
77 
78 /**
79  * cdns3_core_init_role - initialize role of operation
80  * @cdns: Pointer to cdns3 structure
81  *
82  * Returns 0 on success otherwise negative errno
83  */
84 static int cdns3_core_init_role(struct cdns3 *cdns)
85 {
86 	struct device *dev = cdns->dev;
87 	enum usb_dr_mode best_dr_mode;
88 	enum usb_dr_mode dr_mode;
89 	int ret;
90 
91 	dr_mode = usb_get_dr_mode(dev);
92 	cdns->role = USB_ROLE_NONE;
93 
94 	/*
95 	 * If driver can't read mode by means of usb_get_dr_mode function then
96 	 * chooses mode according with Kernel configuration. This setting
97 	 * can be restricted later depending on strap pin configuration.
98 	 */
99 	if (dr_mode == USB_DR_MODE_UNKNOWN) {
100 		if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
101 		    IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
102 			dr_mode = USB_DR_MODE_OTG;
103 		else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
104 			dr_mode = USB_DR_MODE_HOST;
105 		else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
106 			dr_mode = USB_DR_MODE_PERIPHERAL;
107 	}
108 
109 	/*
110 	 * At this point cdns->dr_mode contains strap configuration.
111 	 * Driver try update this setting considering kernel configuration
112 	 */
113 	best_dr_mode = cdns->dr_mode;
114 
115 	ret = cdns3_idle_init(cdns);
116 	if (ret)
117 		return ret;
118 
119 	if (dr_mode == USB_DR_MODE_OTG) {
120 		best_dr_mode = cdns->dr_mode;
121 	} else if (cdns->dr_mode == USB_DR_MODE_OTG) {
122 		best_dr_mode = dr_mode;
123 	} else if (cdns->dr_mode != dr_mode) {
124 		dev_err(dev, "Incorrect DRD configuration\n");
125 		return -EINVAL;
126 	}
127 
128 	dr_mode = best_dr_mode;
129 
130 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
131 		ret = cdns3_host_init(cdns);
132 		if (ret) {
133 			dev_err(dev, "Host initialization failed with %d\n",
134 				ret);
135 			goto err;
136 		}
137 	}
138 
139 	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
140 		ret = cdns3_gadget_init(cdns);
141 		if (ret) {
142 			dev_err(dev, "Device initialization failed with %d\n",
143 				ret);
144 			goto err;
145 		}
146 	}
147 
148 	cdns->dr_mode = dr_mode;
149 
150 	ret = cdns3_drd_update_mode(cdns);
151 	if (ret)
152 		goto err;
153 
154 	/* Initialize idle role to start with */
155 	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
156 	if (ret)
157 		goto err;
158 
159 	switch (cdns->dr_mode) {
160 	case USB_DR_MODE_OTG:
161 		ret = cdns3_hw_role_switch(cdns);
162 		if (ret)
163 			goto err;
164 		break;
165 	case USB_DR_MODE_PERIPHERAL:
166 		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
167 		if (ret)
168 			goto err;
169 		break;
170 	case USB_DR_MODE_HOST:
171 		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
172 		if (ret)
173 			goto err;
174 		break;
175 	default:
176 		ret = -EINVAL;
177 		goto err;
178 	}
179 
180 	return 0;
181 err:
182 	cdns3_exit_roles(cdns);
183 	return ret;
184 }
185 
186 /**
187  * cdns3_hw_role_state_machine  - role switch state machine based on hw events.
188  * @cdns: Pointer to controller structure.
189  *
190  * Returns next role to be entered based on hw events.
191  */
192 static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns)
193 {
194 	enum usb_role role = USB_ROLE_NONE;
195 	int id, vbus;
196 
197 	if (cdns->dr_mode != USB_DR_MODE_OTG) {
198 		if (cdns3_is_host(cdns))
199 			role = USB_ROLE_HOST;
200 		if (cdns3_is_device(cdns))
201 			role = USB_ROLE_DEVICE;
202 
203 		return role;
204 	}
205 
206 	id = cdns3_get_id(cdns);
207 	vbus = cdns3_get_vbus(cdns);
208 
209 	/*
210 	 * Role change state machine
211 	 * Inputs: ID, VBUS
212 	 * Previous state: cdns->role
213 	 * Next state: role
214 	 */
215 	role = cdns->role;
216 
217 	switch (role) {
218 	case USB_ROLE_NONE:
219 		/*
220 		 * Driver treats USB_ROLE_NONE synonymous to IDLE state from
221 		 * controller specification.
222 		 */
223 		if (!id)
224 			role = USB_ROLE_HOST;
225 		else if (vbus)
226 			role = USB_ROLE_DEVICE;
227 		break;
228 	case USB_ROLE_HOST: /* from HOST, we can only change to NONE */
229 		if (id)
230 			role = USB_ROLE_NONE;
231 		break;
232 	case USB_ROLE_DEVICE: /* from GADGET, we can only change to NONE*/
233 		if (!vbus)
234 			role = USB_ROLE_NONE;
235 		break;
236 	}
237 
238 	dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role);
239 
240 	return role;
241 }
242 
243 static int cdns3_idle_role_start(struct cdns3 *cdns)
244 {
245 	return 0;
246 }
247 
248 static void cdns3_idle_role_stop(struct cdns3 *cdns)
249 {
250 	/* Program Lane swap and bring PHY out of RESET */
251 	phy_reset(cdns->usb3_phy);
252 }
253 
254 static int cdns3_idle_init(struct cdns3 *cdns)
255 {
256 	struct cdns3_role_driver *rdrv;
257 
258 	rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
259 	if (!rdrv)
260 		return -ENOMEM;
261 
262 	rdrv->start = cdns3_idle_role_start;
263 	rdrv->stop = cdns3_idle_role_stop;
264 	rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
265 	rdrv->suspend = NULL;
266 	rdrv->resume = NULL;
267 	rdrv->name = "idle";
268 
269 	cdns->roles[USB_ROLE_NONE] = rdrv;
270 
271 	return 0;
272 }
273 
274 /**
275  * cdns3_hw_role_switch - switch roles based on HW state
276  * @cdns: controller
277  */
278 int cdns3_hw_role_switch(struct cdns3 *cdns)
279 {
280 	enum usb_role real_role, current_role;
281 	int ret = 0;
282 
283 	/* Depends on role switch class */
284 	if (cdns->role_sw)
285 		return 0;
286 
287 	pm_runtime_get_sync(cdns->dev);
288 
289 	current_role = cdns->role;
290 	real_role = cdns3_hw_role_state_machine(cdns);
291 
292 	/* Do nothing if nothing changed */
293 	if (current_role == real_role)
294 		goto exit;
295 
296 	cdns3_role_stop(cdns);
297 
298 	dev_dbg(cdns->dev, "Switching role %d -> %d", current_role, real_role);
299 
300 	ret = cdns3_role_start(cdns, real_role);
301 	if (ret) {
302 		/* Back to current role */
303 		dev_err(cdns->dev, "set %d has failed, back to %d\n",
304 			real_role, current_role);
305 		ret = cdns3_role_start(cdns, current_role);
306 		if (ret)
307 			dev_err(cdns->dev, "back to %d failed too\n",
308 				current_role);
309 	}
310 exit:
311 	pm_runtime_put_sync(cdns->dev);
312 	return ret;
313 }
314 
315 /**
316  * cdsn3_role_get - get current role of controller.
317  *
318  * @sw: pointer to USB role switch structure
319  *
320  * Returns role
321  */
322 static enum usb_role cdns3_role_get(struct usb_role_switch *sw)
323 {
324 	struct cdns3 *cdns = usb_role_switch_get_drvdata(sw);
325 
326 	return cdns->role;
327 }
328 
329 /**
330  * cdns3_role_set - set current role of controller.
331  *
332  * @sw: pointer to USB role switch structure
333  * @role: the previous role
334  * Handles below events:
335  * - Role switch for dual-role devices
336  * - USB_ROLE_GADGET <--> USB_ROLE_NONE for peripheral-only devices
337  */
338 static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role)
339 {
340 	struct cdns3 *cdns = usb_role_switch_get_drvdata(sw);
341 	int ret = 0;
342 
343 	pm_runtime_get_sync(cdns->dev);
344 
345 	if (cdns->role == role)
346 		goto pm_put;
347 
348 	if (cdns->dr_mode == USB_DR_MODE_HOST) {
349 		switch (role) {
350 		case USB_ROLE_NONE:
351 		case USB_ROLE_HOST:
352 			break;
353 		default:
354 			goto pm_put;
355 		}
356 	}
357 
358 	if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL) {
359 		switch (role) {
360 		case USB_ROLE_NONE:
361 		case USB_ROLE_DEVICE:
362 			break;
363 		default:
364 			goto pm_put;
365 		}
366 	}
367 
368 	cdns3_role_stop(cdns);
369 	ret = cdns3_role_start(cdns, role);
370 	if (ret)
371 		dev_err(cdns->dev, "set role %d has failed\n", role);
372 
373 pm_put:
374 	pm_runtime_put_sync(cdns->dev);
375 	return ret;
376 }
377 
378 static int set_phy_power_on(struct cdns3 *cdns)
379 {
380 	int ret;
381 
382 	ret = phy_power_on(cdns->usb2_phy);
383 	if (ret)
384 		return ret;
385 
386 	ret = phy_power_on(cdns->usb3_phy);
387 	if (ret)
388 		phy_power_off(cdns->usb2_phy);
389 
390 	return ret;
391 }
392 
393 static void set_phy_power_off(struct cdns3 *cdns)
394 {
395 	phy_power_off(cdns->usb3_phy);
396 	phy_power_off(cdns->usb2_phy);
397 }
398 
399 /**
400  * cdns3_wakeup_irq - interrupt handler for wakeup events
401  * @irq: irq number for cdns3 core device
402  * @data: structure of cdns3
403  *
404  * Returns IRQ_HANDLED or IRQ_NONE
405  */
406 static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
407 {
408 	struct cdns3 *cdns = data;
409 
410 	if (cdns->in_lpm) {
411 		disable_irq_nosync(irq);
412 		cdns->wakeup_pending = true;
413 		if ((cdns->role == USB_ROLE_HOST) && cdns->host_dev)
414 			pm_request_resume(&cdns->host_dev->dev);
415 
416 		return IRQ_HANDLED;
417 	}
418 
419 	return IRQ_NONE;
420 }
421 
422 /**
423  * cdns3_probe - probe for cdns3 core device
424  * @pdev: Pointer to cdns3 core platform device
425  *
426  * Returns 0 on success otherwise negative errno
427  */
428 static int cdns3_probe(struct platform_device *pdev)
429 {
430 	struct usb_role_switch_desc sw_desc = { };
431 	struct device *dev = &pdev->dev;
432 	struct resource	*res;
433 	struct cdns3 *cdns;
434 	void __iomem *regs;
435 	int ret;
436 
437 	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
438 	if (ret) {
439 		dev_err(dev, "error setting dma mask: %d\n", ret);
440 		return ret;
441 	}
442 
443 	cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL);
444 	if (!cdns)
445 		return -ENOMEM;
446 
447 	cdns->dev = dev;
448 	cdns->pdata = dev_get_platdata(dev);
449 
450 	platform_set_drvdata(pdev, cdns);
451 
452 	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host");
453 	if (!res) {
454 		dev_err(dev, "missing host IRQ\n");
455 		return -ENODEV;
456 	}
457 
458 	cdns->xhci_res[0] = *res;
459 
460 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci");
461 	if (!res) {
462 		dev_err(dev, "couldn't get xhci resource\n");
463 		return -ENXIO;
464 	}
465 
466 	cdns->xhci_res[1] = *res;
467 
468 	cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral");
469 	if (cdns->dev_irq == -EPROBE_DEFER)
470 		return cdns->dev_irq;
471 
472 	if (cdns->dev_irq < 0)
473 		dev_err(dev, "couldn't get peripheral irq\n");
474 
475 	regs = devm_platform_ioremap_resource_byname(pdev, "dev");
476 	if (IS_ERR(regs))
477 		return PTR_ERR(regs);
478 	cdns->dev_regs	= regs;
479 
480 	cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
481 	if (cdns->otg_irq == -EPROBE_DEFER)
482 		return cdns->otg_irq;
483 
484 	if (cdns->otg_irq < 0) {
485 		dev_err(dev, "couldn't get otg irq\n");
486 		return cdns->otg_irq;
487 	}
488 
489 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
490 	if (!res) {
491 		dev_err(dev, "couldn't get otg resource\n");
492 		return -ENXIO;
493 	}
494 
495 	cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable");
496 
497 	cdns->otg_res = *res;
498 
499 	cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
500 	if (cdns->wakeup_irq == -EPROBE_DEFER)
501 		return cdns->wakeup_irq;
502 	else if (cdns->wakeup_irq == 0)
503 		return -EINVAL;
504 
505 	if (cdns->wakeup_irq < 0) {
506 		dev_dbg(dev, "couldn't get wakeup irq\n");
507 		cdns->wakeup_irq = 0x0;
508 	}
509 
510 	mutex_init(&cdns->mutex);
511 
512 	cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy");
513 	if (IS_ERR(cdns->usb2_phy))
514 		return PTR_ERR(cdns->usb2_phy);
515 
516 	ret = phy_init(cdns->usb2_phy);
517 	if (ret)
518 		return ret;
519 
520 	cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy");
521 	if (IS_ERR(cdns->usb3_phy))
522 		return PTR_ERR(cdns->usb3_phy);
523 
524 	ret = phy_init(cdns->usb3_phy);
525 	if (ret)
526 		goto err1;
527 
528 	ret = set_phy_power_on(cdns);
529 	if (ret)
530 		goto err2;
531 
532 	sw_desc.set = cdns3_role_set;
533 	sw_desc.get = cdns3_role_get;
534 	sw_desc.allow_userspace_control = true;
535 	sw_desc.driver_data = cdns;
536 	if (device_property_read_bool(dev, "usb-role-switch"))
537 		sw_desc.fwnode = dev->fwnode;
538 
539 	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
540 	if (IS_ERR(cdns->role_sw)) {
541 		ret = PTR_ERR(cdns->role_sw);
542 		dev_warn(dev, "Unable to register Role Switch\n");
543 		goto err3;
544 	}
545 
546 	if (cdns->wakeup_irq) {
547 		ret = devm_request_irq(cdns->dev, cdns->wakeup_irq,
548 						cdns3_wakeup_irq,
549 						IRQF_SHARED,
550 						dev_name(cdns->dev), cdns);
551 
552 		if (ret) {
553 			dev_err(cdns->dev, "couldn't register wakeup irq handler\n");
554 			goto err3;
555 		}
556 	}
557 
558 	ret = cdns3_drd_init(cdns);
559 	if (ret)
560 		goto err4;
561 
562 	ret = cdns3_core_init_role(cdns);
563 	if (ret)
564 		goto err4;
565 
566 	spin_lock_init(&cdns->lock);
567 	device_set_wakeup_capable(dev, true);
568 	pm_runtime_set_active(dev);
569 	pm_runtime_enable(dev);
570 	pm_runtime_forbid(dev);
571 
572 	/*
573 	 * The controller needs less time between bus and controller suspend,
574 	 * and we also needs a small delay to avoid frequently entering low
575 	 * power mode.
576 	 */
577 	pm_runtime_set_autosuspend_delay(dev, 20);
578 	pm_runtime_mark_last_busy(dev);
579 	pm_runtime_use_autosuspend(dev);
580 	dev_dbg(dev, "Cadence USB3 core: probe succeed\n");
581 
582 	return 0;
583 err4:
584 	cdns3_drd_exit(cdns);
585 	usb_role_switch_unregister(cdns->role_sw);
586 err3:
587 	set_phy_power_off(cdns);
588 err2:
589 	phy_exit(cdns->usb3_phy);
590 err1:
591 	phy_exit(cdns->usb2_phy);
592 
593 	return ret;
594 }
595 
596 /**
597  * cdns3_remove - unbind drd driver and clean up
598  * @pdev: Pointer to Linux platform device
599  *
600  * Returns 0 on success otherwise negative errno
601  */
602 static int cdns3_remove(struct platform_device *pdev)
603 {
604 	struct cdns3 *cdns = platform_get_drvdata(pdev);
605 
606 	pm_runtime_get_sync(&pdev->dev);
607 	pm_runtime_disable(&pdev->dev);
608 	pm_runtime_put_noidle(&pdev->dev);
609 	cdns3_exit_roles(cdns);
610 	usb_role_switch_unregister(cdns->role_sw);
611 	set_phy_power_off(cdns);
612 	phy_exit(cdns->usb2_phy);
613 	phy_exit(cdns->usb3_phy);
614 	return 0;
615 }
616 
617 #ifdef CONFIG_PM
618 
619 static int cdns3_set_platform_suspend(struct device *dev,
620 		bool suspend, bool wakeup)
621 {
622 	struct cdns3 *cdns = dev_get_drvdata(dev);
623 	int ret = 0;
624 
625 	if (cdns->pdata && cdns->pdata->platform_suspend)
626 		ret = cdns->pdata->platform_suspend(dev, suspend, wakeup);
627 
628 	return ret;
629 }
630 
631 static int cdns3_controller_suspend(struct device *dev, pm_message_t msg)
632 {
633 	struct cdns3 *cdns = dev_get_drvdata(dev);
634 	bool wakeup;
635 	unsigned long flags;
636 
637 	if (cdns->in_lpm)
638 		return 0;
639 
640 	if (PMSG_IS_AUTO(msg))
641 		wakeup = true;
642 	else
643 		wakeup = device_may_wakeup(dev);
644 
645 	cdns3_set_platform_suspend(cdns->dev, true, wakeup);
646 	set_phy_power_off(cdns);
647 	spin_lock_irqsave(&cdns->lock, flags);
648 	cdns->in_lpm = true;
649 	spin_unlock_irqrestore(&cdns->lock, flags);
650 	dev_dbg(cdns->dev, "%s ends\n", __func__);
651 
652 	return 0;
653 }
654 
655 static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
656 {
657 	struct cdns3 *cdns = dev_get_drvdata(dev);
658 	int ret;
659 	unsigned long flags;
660 
661 	if (!cdns->in_lpm)
662 		return 0;
663 
664 	ret = set_phy_power_on(cdns);
665 	if (ret)
666 		return ret;
667 
668 	cdns3_set_platform_suspend(cdns->dev, false, false);
669 
670 	spin_lock_irqsave(&cdns->lock, flags);
671 	if (cdns->roles[cdns->role]->resume && !PMSG_IS_AUTO(msg))
672 		cdns->roles[cdns->role]->resume(cdns, false);
673 
674 	cdns->in_lpm = false;
675 	spin_unlock_irqrestore(&cdns->lock, flags);
676 	if (cdns->wakeup_pending) {
677 		cdns->wakeup_pending = false;
678 		enable_irq(cdns->wakeup_irq);
679 	}
680 	dev_dbg(cdns->dev, "%s ends\n", __func__);
681 
682 	return ret;
683 }
684 
685 static int cdns3_runtime_suspend(struct device *dev)
686 {
687 	return cdns3_controller_suspend(dev, PMSG_AUTO_SUSPEND);
688 }
689 
690 static int cdns3_runtime_resume(struct device *dev)
691 {
692 	return cdns3_controller_resume(dev, PMSG_AUTO_RESUME);
693 }
694 #ifdef CONFIG_PM_SLEEP
695 
696 static int cdns3_suspend(struct device *dev)
697 {
698 	struct cdns3 *cdns = dev_get_drvdata(dev);
699 	unsigned long flags;
700 
701 	if (pm_runtime_status_suspended(dev))
702 		pm_runtime_resume(dev);
703 
704 	if (cdns->roles[cdns->role]->suspend) {
705 		spin_lock_irqsave(&cdns->lock, flags);
706 		cdns->roles[cdns->role]->suspend(cdns, false);
707 		spin_unlock_irqrestore(&cdns->lock, flags);
708 	}
709 
710 	return cdns3_controller_suspend(dev, PMSG_SUSPEND);
711 }
712 
713 static int cdns3_resume(struct device *dev)
714 {
715 	int ret;
716 
717 	ret = cdns3_controller_resume(dev, PMSG_RESUME);
718 	if (ret)
719 		return ret;
720 
721 	pm_runtime_disable(dev);
722 	pm_runtime_set_active(dev);
723 	pm_runtime_enable(dev);
724 
725 	return ret;
726 }
727 #endif /* CONFIG_PM_SLEEP */
728 #endif /* CONFIG_PM */
729 
730 static const struct dev_pm_ops cdns3_pm_ops = {
731 	SET_SYSTEM_SLEEP_PM_OPS(cdns3_suspend, cdns3_resume)
732 	SET_RUNTIME_PM_OPS(cdns3_runtime_suspend, cdns3_runtime_resume, NULL)
733 };
734 
735 #ifdef CONFIG_OF
736 static const struct of_device_id of_cdns3_match[] = {
737 	{ .compatible = "cdns,usb3" },
738 	{ },
739 };
740 MODULE_DEVICE_TABLE(of, of_cdns3_match);
741 #endif
742 
743 static struct platform_driver cdns3_driver = {
744 	.probe		= cdns3_probe,
745 	.remove		= cdns3_remove,
746 	.driver		= {
747 		.name	= "cdns-usb3",
748 		.of_match_table	= of_match_ptr(of_cdns3_match),
749 		.pm	= &cdns3_pm_ops,
750 	},
751 };
752 
753 module_platform_driver(cdns3_driver);
754 
755 MODULE_ALIAS("platform:cdns3");
756 MODULE_AUTHOR("Pawel Laszczak <pawell@cadence.com>");
757 MODULE_LICENSE("GPL v2");
758 MODULE_DESCRIPTION("Cadence USB3 DRD Controller Driver");
759