1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2012 Freescale Semiconductor, Inc.
4  * Copyright (C) 2012 Marek Vasut <marex@denx.de>
5  * on behalf of DENX Software Engineering GmbH
6  */
7 
8 #include <linux/module.h>
9 #include <linux/of_platform.h>
10 #include <linux/platform_device.h>
11 #include <linux/pm_runtime.h>
12 #include <linux/usb/chipidea.h>
13 #include <linux/usb/of.h>
14 #include <linux/clk.h>
15 #include <linux/pinctrl/consumer.h>
16 #include <linux/pm_qos.h>
17 
18 #include "ci.h"
19 #include "ci_hdrc_imx.h"
20 
21 struct ci_hdrc_imx_platform_flag {
22 	unsigned int flags;
23 };
24 
25 static const struct ci_hdrc_imx_platform_flag imx23_usb_data = {
26 	.flags = CI_HDRC_TURN_VBUS_EARLY_ON |
27 		CI_HDRC_DISABLE_STREAMING,
28 };
29 
30 static const struct ci_hdrc_imx_platform_flag imx27_usb_data = {
31 	.flags = CI_HDRC_DISABLE_STREAMING,
32 };
33 
34 static const struct ci_hdrc_imx_platform_flag imx28_usb_data = {
35 	.flags = CI_HDRC_IMX28_WRITE_FIX |
36 		CI_HDRC_TURN_VBUS_EARLY_ON |
37 		CI_HDRC_DISABLE_STREAMING,
38 };
39 
40 static const struct ci_hdrc_imx_platform_flag imx6q_usb_data = {
41 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM |
42 		CI_HDRC_TURN_VBUS_EARLY_ON |
43 		CI_HDRC_DISABLE_STREAMING,
44 };
45 
46 static const struct ci_hdrc_imx_platform_flag imx6sl_usb_data = {
47 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM |
48 		CI_HDRC_TURN_VBUS_EARLY_ON |
49 		CI_HDRC_DISABLE_HOST_STREAMING,
50 };
51 
52 static const struct ci_hdrc_imx_platform_flag imx6sx_usb_data = {
53 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM |
54 		CI_HDRC_TURN_VBUS_EARLY_ON |
55 		CI_HDRC_DISABLE_HOST_STREAMING,
56 };
57 
58 static const struct ci_hdrc_imx_platform_flag imx6ul_usb_data = {
59 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM |
60 		CI_HDRC_TURN_VBUS_EARLY_ON |
61 		CI_HDRC_DISABLE_DEVICE_STREAMING,
62 };
63 
64 static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = {
65 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM,
66 };
67 
68 static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = {
69 	.flags = CI_HDRC_SUPPORTS_RUNTIME_PM |
70 		CI_HDRC_PMQOS,
71 };
72 
73 static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
74 	{ .compatible = "fsl,imx23-usb", .data = &imx23_usb_data},
75 	{ .compatible = "fsl,imx28-usb", .data = &imx28_usb_data},
76 	{ .compatible = "fsl,imx27-usb", .data = &imx27_usb_data},
77 	{ .compatible = "fsl,imx6q-usb", .data = &imx6q_usb_data},
78 	{ .compatible = "fsl,imx6sl-usb", .data = &imx6sl_usb_data},
79 	{ .compatible = "fsl,imx6sx-usb", .data = &imx6sx_usb_data},
80 	{ .compatible = "fsl,imx6ul-usb", .data = &imx6ul_usb_data},
81 	{ .compatible = "fsl,imx7d-usb", .data = &imx7d_usb_data},
82 	{ .compatible = "fsl,imx7ulp-usb", .data = &imx7ulp_usb_data},
83 	{ /* sentinel */ }
84 };
85 MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids);
86 
87 struct ci_hdrc_imx_data {
88 	struct usb_phy *phy;
89 	struct platform_device *ci_pdev;
90 	struct clk *clk;
91 	struct imx_usbmisc_data *usbmisc_data;
92 	bool supports_runtime_pm;
93 	bool override_phy_control;
94 	bool in_lpm;
95 	struct pinctrl *pinctrl;
96 	struct pinctrl_state *pinctrl_hsic_active;
97 	struct regulator *hsic_pad_regulator;
98 	/* SoC before i.mx6 (except imx23/imx28) needs three clks */
99 	bool need_three_clks;
100 	struct clk *clk_ipg;
101 	struct clk *clk_ahb;
102 	struct clk *clk_per;
103 	/* --------------------------------- */
104 	struct pm_qos_request pm_qos_req;
105 	const struct ci_hdrc_imx_platform_flag *plat_data;
106 };
107 
108 /* Common functions shared by usbmisc drivers */
109 
110 static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
111 {
112 	struct platform_device *misc_pdev;
113 	struct device_node *np = dev->of_node;
114 	struct of_phandle_args args;
115 	struct imx_usbmisc_data *data;
116 	int ret;
117 
118 	/*
119 	 * In case the fsl,usbmisc property is not present this device doesn't
120 	 * need usbmisc. Return NULL (which is no error here)
121 	 */
122 	if (!of_get_property(np, "fsl,usbmisc", NULL))
123 		return NULL;
124 
125 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
126 	if (!data)
127 		return ERR_PTR(-ENOMEM);
128 
129 	ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
130 					0, &args);
131 	if (ret) {
132 		dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
133 			ret);
134 		return ERR_PTR(ret);
135 	}
136 
137 	data->index = args.args[0];
138 
139 	misc_pdev = of_find_device_by_node(args.np);
140 	of_node_put(args.np);
141 
142 	if (!misc_pdev)
143 		return ERR_PTR(-EPROBE_DEFER);
144 
145 	if (!platform_get_drvdata(misc_pdev)) {
146 		put_device(&misc_pdev->dev);
147 		return ERR_PTR(-EPROBE_DEFER);
148 	}
149 	data->dev = &misc_pdev->dev;
150 
151 	/*
152 	 * Check the various over current related properties. If over current
153 	 * detection is disabled we're not interested in the polarity.
154 	 */
155 	if (of_find_property(np, "disable-over-current", NULL)) {
156 		data->disable_oc = 1;
157 	} else if (of_find_property(np, "over-current-active-high", NULL)) {
158 		data->oc_pol_active_low = 0;
159 		data->oc_pol_configured = 1;
160 	} else if (of_find_property(np, "over-current-active-low", NULL)) {
161 		data->oc_pol_active_low = 1;
162 		data->oc_pol_configured = 1;
163 	} else {
164 		dev_warn(dev, "No over current polarity defined\n");
165 	}
166 
167 	data->pwr_pol = of_property_read_bool(np, "power-active-high");
168 	data->evdo = of_property_read_bool(np, "external-vbus-divider");
169 
170 	if (of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI)
171 		data->ulpi = 1;
172 
173 	of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control",
174 			&data->emp_curr_control);
175 	of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust",
176 			&data->dc_vol_level_adjust);
177 
178 	return data;
179 }
180 
181 /* End of common functions shared by usbmisc drivers*/
182 static int imx_get_clks(struct device *dev)
183 {
184 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
185 	int ret = 0;
186 
187 	data->clk_ipg = devm_clk_get(dev, "ipg");
188 	if (IS_ERR(data->clk_ipg)) {
189 		/* If the platform only needs one clocks */
190 		data->clk = devm_clk_get(dev, NULL);
191 		if (IS_ERR(data->clk)) {
192 			ret = PTR_ERR(data->clk);
193 			dev_err(dev,
194 				"Failed to get clks, err=%ld,%ld\n",
195 				PTR_ERR(data->clk), PTR_ERR(data->clk_ipg));
196 			return ret;
197 		}
198 		return ret;
199 	}
200 
201 	data->clk_ahb = devm_clk_get(dev, "ahb");
202 	if (IS_ERR(data->clk_ahb)) {
203 		ret = PTR_ERR(data->clk_ahb);
204 		dev_err(dev,
205 			"Failed to get ahb clock, err=%d\n", ret);
206 		return ret;
207 	}
208 
209 	data->clk_per = devm_clk_get(dev, "per");
210 	if (IS_ERR(data->clk_per)) {
211 		ret = PTR_ERR(data->clk_per);
212 		dev_err(dev,
213 			"Failed to get per clock, err=%d\n", ret);
214 		return ret;
215 	}
216 
217 	data->need_three_clks = true;
218 	return ret;
219 }
220 
221 static int imx_prepare_enable_clks(struct device *dev)
222 {
223 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
224 	int ret = 0;
225 
226 	if (data->need_three_clks) {
227 		ret = clk_prepare_enable(data->clk_ipg);
228 		if (ret) {
229 			dev_err(dev,
230 				"Failed to prepare/enable ipg clk, err=%d\n",
231 				ret);
232 			return ret;
233 		}
234 
235 		ret = clk_prepare_enable(data->clk_ahb);
236 		if (ret) {
237 			dev_err(dev,
238 				"Failed to prepare/enable ahb clk, err=%d\n",
239 				ret);
240 			clk_disable_unprepare(data->clk_ipg);
241 			return ret;
242 		}
243 
244 		ret = clk_prepare_enable(data->clk_per);
245 		if (ret) {
246 			dev_err(dev,
247 				"Failed to prepare/enable per clk, err=%d\n",
248 				ret);
249 			clk_disable_unprepare(data->clk_ahb);
250 			clk_disable_unprepare(data->clk_ipg);
251 			return ret;
252 		}
253 	} else {
254 		ret = clk_prepare_enable(data->clk);
255 		if (ret) {
256 			dev_err(dev,
257 				"Failed to prepare/enable clk, err=%d\n",
258 				ret);
259 			return ret;
260 		}
261 	}
262 
263 	return ret;
264 }
265 
266 static void imx_disable_unprepare_clks(struct device *dev)
267 {
268 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
269 
270 	if (data->need_three_clks) {
271 		clk_disable_unprepare(data->clk_per);
272 		clk_disable_unprepare(data->clk_ahb);
273 		clk_disable_unprepare(data->clk_ipg);
274 	} else {
275 		clk_disable_unprepare(data->clk);
276 	}
277 }
278 
279 static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int event)
280 {
281 	struct device *dev = ci->dev->parent;
282 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
283 	int ret = 0;
284 	struct imx_usbmisc_data *mdata = data->usbmisc_data;
285 
286 	switch (event) {
287 	case CI_HDRC_IMX_HSIC_ACTIVE_EVENT:
288 		if (data->pinctrl) {
289 			ret = pinctrl_select_state(data->pinctrl,
290 					data->pinctrl_hsic_active);
291 			if (ret)
292 				dev_err(dev,
293 					"hsic_active select failed, err=%d\n",
294 					ret);
295 		}
296 		break;
297 	case CI_HDRC_IMX_HSIC_SUSPEND_EVENT:
298 		ret = imx_usbmisc_hsic_set_connect(mdata);
299 		if (ret)
300 			dev_err(dev,
301 				"hsic_set_connect failed, err=%d\n", ret);
302 		break;
303 	case CI_HDRC_CONTROLLER_VBUS_EVENT:
304 		if (ci->vbus_active)
305 			ret = imx_usbmisc_charger_detection(mdata, true);
306 		else
307 			ret = imx_usbmisc_charger_detection(mdata, false);
308 		if (ci->usb_phy)
309 			schedule_work(&ci->usb_phy->chg_work);
310 		break;
311 	default:
312 		break;
313 	}
314 
315 	return ret;
316 }
317 
318 static int ci_hdrc_imx_probe(struct platform_device *pdev)
319 {
320 	struct ci_hdrc_imx_data *data;
321 	struct ci_hdrc_platform_data pdata = {
322 		.name		= dev_name(&pdev->dev),
323 		.capoffset	= DEF_CAPOFFSET,
324 		.notify_event	= ci_hdrc_imx_notify_event,
325 	};
326 	int ret;
327 	const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
328 	struct device_node *np = pdev->dev.of_node;
329 	struct device *dev = &pdev->dev;
330 
331 	imx_platform_flag = of_device_get_match_data(&pdev->dev);
332 
333 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
334 	if (!data)
335 		return -ENOMEM;
336 
337 	data->plat_data = imx_platform_flag;
338 	pdata.flags |= imx_platform_flag->flags;
339 	platform_set_drvdata(pdev, data);
340 	data->usbmisc_data = usbmisc_get_init_data(dev);
341 	if (IS_ERR(data->usbmisc_data))
342 		return PTR_ERR(data->usbmisc_data);
343 
344 	if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
345 		&& data->usbmisc_data) {
346 		pdata.flags |= CI_HDRC_IMX_IS_HSIC;
347 		data->usbmisc_data->hsic = 1;
348 		data->pinctrl = devm_pinctrl_get(dev);
349 		if (PTR_ERR(data->pinctrl) == -ENODEV)
350 			data->pinctrl = NULL;
351 		else if (IS_ERR(data->pinctrl))
352 			return dev_err_probe(dev, PTR_ERR(data->pinctrl),
353 					     "pinctrl get failed\n");
354 
355 		data->hsic_pad_regulator =
356 				devm_regulator_get_optional(dev, "hsic");
357 		if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) {
358 			/* no pad regulator is needed */
359 			data->hsic_pad_regulator = NULL;
360 		} else if (IS_ERR(data->hsic_pad_regulator))
361 			return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator),
362 					     "Get HSIC pad regulator error\n");
363 
364 		if (data->hsic_pad_regulator) {
365 			ret = regulator_enable(data->hsic_pad_regulator);
366 			if (ret) {
367 				dev_err(dev,
368 					"Failed to enable HSIC pad regulator\n");
369 				return ret;
370 			}
371 		}
372 	}
373 
374 	/* HSIC pinctrl handling */
375 	if (data->pinctrl) {
376 		struct pinctrl_state *pinctrl_hsic_idle;
377 
378 		pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle");
379 		if (IS_ERR(pinctrl_hsic_idle)) {
380 			dev_err(dev,
381 				"pinctrl_hsic_idle lookup failed, err=%ld\n",
382 					PTR_ERR(pinctrl_hsic_idle));
383 			return PTR_ERR(pinctrl_hsic_idle);
384 		}
385 
386 		ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle);
387 		if (ret) {
388 			dev_err(dev, "hsic_idle select failed, err=%d\n", ret);
389 			return ret;
390 		}
391 
392 		data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl,
393 								"active");
394 		if (IS_ERR(data->pinctrl_hsic_active)) {
395 			dev_err(dev,
396 				"pinctrl_hsic_active lookup failed, err=%ld\n",
397 					PTR_ERR(data->pinctrl_hsic_active));
398 			return PTR_ERR(data->pinctrl_hsic_active);
399 		}
400 	}
401 
402 	if (pdata.flags & CI_HDRC_PMQOS)
403 		cpu_latency_qos_add_request(&data->pm_qos_req, 0);
404 
405 	ret = imx_get_clks(dev);
406 	if (ret)
407 		goto disable_hsic_regulator;
408 
409 	ret = imx_prepare_enable_clks(dev);
410 	if (ret)
411 		goto disable_hsic_regulator;
412 
413 	data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0);
414 	if (IS_ERR(data->phy)) {
415 		ret = PTR_ERR(data->phy);
416 		if (ret != -ENODEV) {
417 			dev_err_probe(dev, ret, "Failed to parse fsl,usbphy\n");
418 			goto err_clk;
419 		}
420 		data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
421 		if (IS_ERR(data->phy)) {
422 			ret = PTR_ERR(data->phy);
423 			if (ret == -ENODEV) {
424 				data->phy = NULL;
425 			} else {
426 				dev_err_probe(dev, ret, "Failed to parse phys\n");
427 				goto err_clk;
428 			}
429 		}
430 	}
431 
432 	pdata.usb_phy = data->phy;
433 	if (data->usbmisc_data)
434 		data->usbmisc_data->usb_phy = data->phy;
435 
436 	if ((of_device_is_compatible(np, "fsl,imx53-usb") ||
437 	     of_device_is_compatible(np, "fsl,imx51-usb")) && pdata.usb_phy &&
438 	    of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) {
439 		pdata.flags |= CI_HDRC_OVERRIDE_PHY_CONTROL;
440 		data->override_phy_control = true;
441 		usb_phy_init(pdata.usb_phy);
442 	}
443 
444 	if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM)
445 		data->supports_runtime_pm = true;
446 
447 	ret = imx_usbmisc_init(data->usbmisc_data);
448 	if (ret) {
449 		dev_err(dev, "usbmisc init failed, ret=%d\n", ret);
450 		goto err_clk;
451 	}
452 
453 	data->ci_pdev = ci_hdrc_add_device(dev,
454 				pdev->resource, pdev->num_resources,
455 				&pdata);
456 	if (IS_ERR(data->ci_pdev)) {
457 		ret = PTR_ERR(data->ci_pdev);
458 		dev_err_probe(dev, ret, "ci_hdrc_add_device failed\n");
459 		goto err_clk;
460 	}
461 
462 	if (data->usbmisc_data) {
463 		if (!IS_ERR(pdata.id_extcon.edev) ||
464 		    of_property_read_bool(np, "usb-role-switch"))
465 			data->usbmisc_data->ext_id = 1;
466 
467 		if (!IS_ERR(pdata.vbus_extcon.edev) ||
468 		    of_property_read_bool(np, "usb-role-switch"))
469 			data->usbmisc_data->ext_vbus = 1;
470 
471 		/* usbmisc needs to know dr mode to choose wakeup setting */
472 		data->usbmisc_data->available_role =
473 			ci_hdrc_query_available_role(data->ci_pdev);
474 	}
475 
476 	ret = imx_usbmisc_init_post(data->usbmisc_data);
477 	if (ret) {
478 		dev_err(dev, "usbmisc post failed, ret=%d\n", ret);
479 		goto disable_device;
480 	}
481 
482 	if (data->supports_runtime_pm) {
483 		pm_runtime_set_active(dev);
484 		pm_runtime_enable(dev);
485 	}
486 
487 	device_set_wakeup_capable(dev, true);
488 
489 	return 0;
490 
491 disable_device:
492 	ci_hdrc_remove_device(data->ci_pdev);
493 err_clk:
494 	imx_disable_unprepare_clks(dev);
495 disable_hsic_regulator:
496 	if (data->hsic_pad_regulator)
497 		/* don't overwrite original ret (cf. EPROBE_DEFER) */
498 		regulator_disable(data->hsic_pad_regulator);
499 	if (pdata.flags & CI_HDRC_PMQOS)
500 		cpu_latency_qos_remove_request(&data->pm_qos_req);
501 	data->ci_pdev = NULL;
502 	return ret;
503 }
504 
505 static int ci_hdrc_imx_remove(struct platform_device *pdev)
506 {
507 	struct ci_hdrc_imx_data *data = platform_get_drvdata(pdev);
508 
509 	if (data->supports_runtime_pm) {
510 		pm_runtime_get_sync(&pdev->dev);
511 		pm_runtime_disable(&pdev->dev);
512 		pm_runtime_put_noidle(&pdev->dev);
513 	}
514 	if (data->ci_pdev)
515 		ci_hdrc_remove_device(data->ci_pdev);
516 	if (data->override_phy_control)
517 		usb_phy_shutdown(data->phy);
518 	if (data->ci_pdev) {
519 		imx_disable_unprepare_clks(&pdev->dev);
520 		if (data->plat_data->flags & CI_HDRC_PMQOS)
521 			cpu_latency_qos_remove_request(&data->pm_qos_req);
522 		if (data->hsic_pad_regulator)
523 			regulator_disable(data->hsic_pad_regulator);
524 	}
525 
526 	return 0;
527 }
528 
529 static void ci_hdrc_imx_shutdown(struct platform_device *pdev)
530 {
531 	ci_hdrc_imx_remove(pdev);
532 }
533 
534 static int __maybe_unused imx_controller_suspend(struct device *dev,
535 						 pm_message_t msg)
536 {
537 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
538 	int ret = 0;
539 
540 	dev_dbg(dev, "at %s\n", __func__);
541 
542 	ret = imx_usbmisc_suspend(data->usbmisc_data,
543 				  PMSG_IS_AUTO(msg) || device_may_wakeup(dev));
544 	if (ret) {
545 		dev_err(dev,
546 			"usbmisc suspend failed, ret=%d\n", ret);
547 		return ret;
548 	}
549 
550 	imx_disable_unprepare_clks(dev);
551 	if (data->plat_data->flags & CI_HDRC_PMQOS)
552 		cpu_latency_qos_remove_request(&data->pm_qos_req);
553 
554 	data->in_lpm = true;
555 
556 	return 0;
557 }
558 
559 static int __maybe_unused imx_controller_resume(struct device *dev,
560 						pm_message_t msg)
561 {
562 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
563 	int ret = 0;
564 
565 	dev_dbg(dev, "at %s\n", __func__);
566 
567 	if (!data->in_lpm) {
568 		WARN_ON(1);
569 		return 0;
570 	}
571 
572 	if (data->plat_data->flags & CI_HDRC_PMQOS)
573 		cpu_latency_qos_add_request(&data->pm_qos_req, 0);
574 
575 	ret = imx_prepare_enable_clks(dev);
576 	if (ret)
577 		return ret;
578 
579 	data->in_lpm = false;
580 
581 	ret = imx_usbmisc_resume(data->usbmisc_data,
582 				 PMSG_IS_AUTO(msg) || device_may_wakeup(dev));
583 	if (ret) {
584 		dev_err(dev, "usbmisc resume failed, ret=%d\n", ret);
585 		goto clk_disable;
586 	}
587 
588 	return 0;
589 
590 clk_disable:
591 	imx_disable_unprepare_clks(dev);
592 	return ret;
593 }
594 
595 static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev)
596 {
597 	int ret;
598 
599 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
600 
601 	if (data->in_lpm)
602 		/* The core's suspend doesn't run */
603 		return 0;
604 
605 	ret = imx_controller_suspend(dev, PMSG_SUSPEND);
606 	if (ret)
607 		return ret;
608 
609 	pinctrl_pm_select_sleep_state(dev);
610 	return ret;
611 }
612 
613 static int __maybe_unused ci_hdrc_imx_resume(struct device *dev)
614 {
615 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
616 	int ret;
617 
618 	pinctrl_pm_select_default_state(dev);
619 	ret = imx_controller_resume(dev, PMSG_RESUME);
620 	if (!ret && data->supports_runtime_pm) {
621 		pm_runtime_disable(dev);
622 		pm_runtime_set_active(dev);
623 		pm_runtime_enable(dev);
624 	}
625 
626 	return ret;
627 }
628 
629 static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev)
630 {
631 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
632 
633 	if (data->in_lpm) {
634 		WARN_ON(1);
635 		return 0;
636 	}
637 
638 	return imx_controller_suspend(dev, PMSG_AUTO_SUSPEND);
639 }
640 
641 static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev)
642 {
643 	return imx_controller_resume(dev, PMSG_AUTO_RESUME);
644 }
645 
646 static const struct dev_pm_ops ci_hdrc_imx_pm_ops = {
647 	SET_SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume)
648 	SET_RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend,
649 			ci_hdrc_imx_runtime_resume, NULL)
650 };
651 static struct platform_driver ci_hdrc_imx_driver = {
652 	.probe = ci_hdrc_imx_probe,
653 	.remove = ci_hdrc_imx_remove,
654 	.shutdown = ci_hdrc_imx_shutdown,
655 	.driver = {
656 		.name = "imx_usb",
657 		.of_match_table = ci_hdrc_imx_dt_ids,
658 		.pm = &ci_hdrc_imx_pm_ops,
659 	 },
660 };
661 
662 module_platform_driver(ci_hdrc_imx_driver);
663 
664 MODULE_ALIAS("platform:imx-usb");
665 MODULE_LICENSE("GPL");
666 MODULE_DESCRIPTION("CI HDRC i.MX USB binding");
667 MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
668 MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
669