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 || !platform_get_drvdata(misc_pdev))
143 		return ERR_PTR(-EPROBE_DEFER);
144 
145 	data->dev = &misc_pdev->dev;
146 
147 	/*
148 	 * Check the various over current related properties. If over current
149 	 * detection is disabled we're not interested in the polarity.
150 	 */
151 	if (of_find_property(np, "disable-over-current", NULL)) {
152 		data->disable_oc = 1;
153 	} else if (of_find_property(np, "over-current-active-high", NULL)) {
154 		data->oc_pol_active_low = 0;
155 		data->oc_pol_configured = 1;
156 	} else if (of_find_property(np, "over-current-active-low", NULL)) {
157 		data->oc_pol_active_low = 1;
158 		data->oc_pol_configured = 1;
159 	} else {
160 		dev_warn(dev, "No over current polarity defined\n");
161 	}
162 
163 	data->pwr_pol = of_property_read_bool(np, "power-active-high");
164 	data->evdo = of_property_read_bool(np, "external-vbus-divider");
165 
166 	if (of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI)
167 		data->ulpi = 1;
168 
169 	of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control",
170 			&data->emp_curr_control);
171 	of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust",
172 			&data->dc_vol_level_adjust);
173 
174 	return data;
175 }
176 
177 /* End of common functions shared by usbmisc drivers*/
178 static int imx_get_clks(struct device *dev)
179 {
180 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
181 	int ret = 0;
182 
183 	data->clk_ipg = devm_clk_get(dev, "ipg");
184 	if (IS_ERR(data->clk_ipg)) {
185 		/* If the platform only needs one clocks */
186 		data->clk = devm_clk_get(dev, NULL);
187 		if (IS_ERR(data->clk)) {
188 			ret = PTR_ERR(data->clk);
189 			dev_err(dev,
190 				"Failed to get clks, err=%ld,%ld\n",
191 				PTR_ERR(data->clk), PTR_ERR(data->clk_ipg));
192 			return ret;
193 		}
194 		return ret;
195 	}
196 
197 	data->clk_ahb = devm_clk_get(dev, "ahb");
198 	if (IS_ERR(data->clk_ahb)) {
199 		ret = PTR_ERR(data->clk_ahb);
200 		dev_err(dev,
201 			"Failed to get ahb clock, err=%d\n", ret);
202 		return ret;
203 	}
204 
205 	data->clk_per = devm_clk_get(dev, "per");
206 	if (IS_ERR(data->clk_per)) {
207 		ret = PTR_ERR(data->clk_per);
208 		dev_err(dev,
209 			"Failed to get per clock, err=%d\n", ret);
210 		return ret;
211 	}
212 
213 	data->need_three_clks = true;
214 	return ret;
215 }
216 
217 static int imx_prepare_enable_clks(struct device *dev)
218 {
219 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
220 	int ret = 0;
221 
222 	if (data->need_three_clks) {
223 		ret = clk_prepare_enable(data->clk_ipg);
224 		if (ret) {
225 			dev_err(dev,
226 				"Failed to prepare/enable ipg clk, err=%d\n",
227 				ret);
228 			return ret;
229 		}
230 
231 		ret = clk_prepare_enable(data->clk_ahb);
232 		if (ret) {
233 			dev_err(dev,
234 				"Failed to prepare/enable ahb clk, err=%d\n",
235 				ret);
236 			clk_disable_unprepare(data->clk_ipg);
237 			return ret;
238 		}
239 
240 		ret = clk_prepare_enable(data->clk_per);
241 		if (ret) {
242 			dev_err(dev,
243 				"Failed to prepare/enable per clk, err=%d\n",
244 				ret);
245 			clk_disable_unprepare(data->clk_ahb);
246 			clk_disable_unprepare(data->clk_ipg);
247 			return ret;
248 		}
249 	} else {
250 		ret = clk_prepare_enable(data->clk);
251 		if (ret) {
252 			dev_err(dev,
253 				"Failed to prepare/enable clk, err=%d\n",
254 				ret);
255 			return ret;
256 		}
257 	}
258 
259 	return ret;
260 }
261 
262 static void imx_disable_unprepare_clks(struct device *dev)
263 {
264 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
265 
266 	if (data->need_three_clks) {
267 		clk_disable_unprepare(data->clk_per);
268 		clk_disable_unprepare(data->clk_ahb);
269 		clk_disable_unprepare(data->clk_ipg);
270 	} else {
271 		clk_disable_unprepare(data->clk);
272 	}
273 }
274 
275 static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int event)
276 {
277 	struct device *dev = ci->dev->parent;
278 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
279 	int ret = 0;
280 	struct imx_usbmisc_data *mdata = data->usbmisc_data;
281 
282 	switch (event) {
283 	case CI_HDRC_IMX_HSIC_ACTIVE_EVENT:
284 		if (data->pinctrl) {
285 			ret = pinctrl_select_state(data->pinctrl,
286 					data->pinctrl_hsic_active);
287 			if (ret)
288 				dev_err(dev,
289 					"hsic_active select failed, err=%d\n",
290 					ret);
291 		}
292 		break;
293 	case CI_HDRC_IMX_HSIC_SUSPEND_EVENT:
294 		ret = imx_usbmisc_hsic_set_connect(mdata);
295 		if (ret)
296 			dev_err(dev,
297 				"hsic_set_connect failed, err=%d\n", ret);
298 		break;
299 	case CI_HDRC_CONTROLLER_VBUS_EVENT:
300 		if (ci->vbus_active)
301 			ret = imx_usbmisc_charger_detection(mdata, true);
302 		else
303 			ret = imx_usbmisc_charger_detection(mdata, false);
304 		if (ci->usb_phy)
305 			schedule_work(&ci->usb_phy->chg_work);
306 		break;
307 	default:
308 		break;
309 	}
310 
311 	return ret;
312 }
313 
314 static int ci_hdrc_imx_probe(struct platform_device *pdev)
315 {
316 	struct ci_hdrc_imx_data *data;
317 	struct ci_hdrc_platform_data pdata = {
318 		.name		= dev_name(&pdev->dev),
319 		.capoffset	= DEF_CAPOFFSET,
320 		.notify_event	= ci_hdrc_imx_notify_event,
321 	};
322 	int ret;
323 	const struct of_device_id *of_id;
324 	const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
325 	struct device_node *np = pdev->dev.of_node;
326 	struct device *dev = &pdev->dev;
327 
328 	of_id = of_match_device(ci_hdrc_imx_dt_ids, dev);
329 	if (!of_id)
330 		return -ENODEV;
331 
332 	imx_platform_flag = of_id->data;
333 
334 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
335 	if (!data)
336 		return -ENOMEM;
337 
338 	data->plat_data = imx_platform_flag;
339 	pdata.flags |= imx_platform_flag->flags;
340 	platform_set_drvdata(pdev, data);
341 	data->usbmisc_data = usbmisc_get_init_data(dev);
342 	if (IS_ERR(data->usbmisc_data))
343 		return PTR_ERR(data->usbmisc_data);
344 
345 	if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
346 		&& data->usbmisc_data) {
347 		pdata.flags |= CI_HDRC_IMX_IS_HSIC;
348 		data->usbmisc_data->hsic = 1;
349 		data->pinctrl = devm_pinctrl_get(dev);
350 		if (PTR_ERR(data->pinctrl) == -ENODEV)
351 			data->pinctrl = NULL;
352 		else if (IS_ERR(data->pinctrl)) {
353 			if (PTR_ERR(data->pinctrl) != -EPROBE_DEFER)
354 				dev_err(dev, "pinctrl get failed, err=%ld\n",
355 					PTR_ERR(data->pinctrl));
356 			return PTR_ERR(data->pinctrl);
357 		}
358 
359 		data->hsic_pad_regulator =
360 				devm_regulator_get_optional(dev, "hsic");
361 		if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) {
362 			/* no pad regualator is needed */
363 			data->hsic_pad_regulator = NULL;
364 		} else if (IS_ERR(data->hsic_pad_regulator)) {
365 			if (PTR_ERR(data->hsic_pad_regulator) != -EPROBE_DEFER)
366 				dev_err(dev,
367 					"Get HSIC pad regulator error: %ld\n",
368 					PTR_ERR(data->hsic_pad_regulator));
369 			return PTR_ERR(data->hsic_pad_regulator);
370 		}
371 
372 		if (data->hsic_pad_regulator) {
373 			ret = regulator_enable(data->hsic_pad_regulator);
374 			if (ret) {
375 				dev_err(dev,
376 					"Failed to enable HSIC pad regulator\n");
377 				return ret;
378 			}
379 		}
380 	}
381 
382 	/* HSIC pinctrl handling */
383 	if (data->pinctrl) {
384 		struct pinctrl_state *pinctrl_hsic_idle;
385 
386 		pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle");
387 		if (IS_ERR(pinctrl_hsic_idle)) {
388 			dev_err(dev,
389 				"pinctrl_hsic_idle lookup failed, err=%ld\n",
390 					PTR_ERR(pinctrl_hsic_idle));
391 			return PTR_ERR(pinctrl_hsic_idle);
392 		}
393 
394 		ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle);
395 		if (ret) {
396 			dev_err(dev, "hsic_idle select failed, err=%d\n", ret);
397 			return ret;
398 		}
399 
400 		data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl,
401 								"active");
402 		if (IS_ERR(data->pinctrl_hsic_active)) {
403 			dev_err(dev,
404 				"pinctrl_hsic_active lookup failed, err=%ld\n",
405 					PTR_ERR(data->pinctrl_hsic_active));
406 			return PTR_ERR(data->pinctrl_hsic_active);
407 		}
408 	}
409 
410 	if (pdata.flags & CI_HDRC_PMQOS)
411 		cpu_latency_qos_add_request(&data->pm_qos_req, 0);
412 
413 	ret = imx_get_clks(dev);
414 	if (ret)
415 		goto disable_hsic_regulator;
416 
417 	ret = imx_prepare_enable_clks(dev);
418 	if (ret)
419 		goto disable_hsic_regulator;
420 
421 	data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0);
422 	if (IS_ERR(data->phy)) {
423 		ret = PTR_ERR(data->phy);
424 		/* Return -EINVAL if no usbphy is available */
425 		if (ret == -ENODEV)
426 			data->phy = NULL;
427 		else
428 			goto err_clk;
429 	}
430 
431 	pdata.usb_phy = data->phy;
432 	if (data->usbmisc_data)
433 		data->usbmisc_data->usb_phy = data->phy;
434 
435 	if ((of_device_is_compatible(np, "fsl,imx53-usb") ||
436 	     of_device_is_compatible(np, "fsl,imx51-usb")) && pdata.usb_phy &&
437 	    of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) {
438 		pdata.flags |= CI_HDRC_OVERRIDE_PHY_CONTROL;
439 		data->override_phy_control = true;
440 		usb_phy_init(pdata.usb_phy);
441 	}
442 
443 	if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM)
444 		data->supports_runtime_pm = true;
445 
446 	ret = imx_usbmisc_init(data->usbmisc_data);
447 	if (ret) {
448 		dev_err(dev, "usbmisc init failed, ret=%d\n", ret);
449 		goto err_clk;
450 	}
451 
452 	data->ci_pdev = ci_hdrc_add_device(dev,
453 				pdev->resource, pdev->num_resources,
454 				&pdata);
455 	if (IS_ERR(data->ci_pdev)) {
456 		ret = PTR_ERR(data->ci_pdev);
457 		if (ret != -EPROBE_DEFER)
458 			dev_err(dev, "ci_hdrc_add_device failed, err=%d\n",
459 					ret);
460 		goto err_clk;
461 	}
462 
463 	if (data->usbmisc_data) {
464 		if (!IS_ERR(pdata.id_extcon.edev) ||
465 		    of_property_read_bool(np, "usb-role-switch"))
466 			data->usbmisc_data->ext_id = 1;
467 
468 		if (!IS_ERR(pdata.vbus_extcon.edev) ||
469 		    of_property_read_bool(np, "usb-role-switch"))
470 			data->usbmisc_data->ext_vbus = 1;
471 
472 		/* usbmisc needs to know dr mode to choose wakeup setting */
473 		data->usbmisc_data->available_role =
474 			ci_hdrc_query_available_role(data->ci_pdev);
475 	}
476 
477 	ret = imx_usbmisc_init_post(data->usbmisc_data);
478 	if (ret) {
479 		dev_err(dev, "usbmisc post failed, ret=%d\n", ret);
480 		goto disable_device;
481 	}
482 
483 	if (data->supports_runtime_pm) {
484 		pm_runtime_set_active(dev);
485 		pm_runtime_enable(dev);
486 	}
487 
488 	device_set_wakeup_capable(dev, true);
489 
490 	return 0;
491 
492 disable_device:
493 	ci_hdrc_remove_device(data->ci_pdev);
494 err_clk:
495 	imx_disable_unprepare_clks(dev);
496 disable_hsic_regulator:
497 	if (data->hsic_pad_regulator)
498 		/* don't overwrite original ret (cf. EPROBE_DEFER) */
499 		regulator_disable(data->hsic_pad_regulator);
500 	if (pdata.flags & CI_HDRC_PMQOS)
501 		cpu_latency_qos_remove_request(&data->pm_qos_req);
502 	data->ci_pdev = NULL;
503 	return ret;
504 }
505 
506 static int ci_hdrc_imx_remove(struct platform_device *pdev)
507 {
508 	struct ci_hdrc_imx_data *data = platform_get_drvdata(pdev);
509 
510 	if (data->supports_runtime_pm) {
511 		pm_runtime_get_sync(&pdev->dev);
512 		pm_runtime_disable(&pdev->dev);
513 		pm_runtime_put_noidle(&pdev->dev);
514 	}
515 	if (data->ci_pdev)
516 		ci_hdrc_remove_device(data->ci_pdev);
517 	if (data->override_phy_control)
518 		usb_phy_shutdown(data->phy);
519 	if (data->ci_pdev) {
520 		imx_disable_unprepare_clks(&pdev->dev);
521 		if (data->plat_data->flags & CI_HDRC_PMQOS)
522 			cpu_latency_qos_remove_request(&data->pm_qos_req);
523 		if (data->hsic_pad_regulator)
524 			regulator_disable(data->hsic_pad_regulator);
525 	}
526 
527 	return 0;
528 }
529 
530 static void ci_hdrc_imx_shutdown(struct platform_device *pdev)
531 {
532 	ci_hdrc_imx_remove(pdev);
533 }
534 
535 static int __maybe_unused imx_controller_suspend(struct device *dev)
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_hsic_set_clk(data->usbmisc_data, false);
543 	if (ret) {
544 		dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret);
545 		return ret;
546 	}
547 
548 	imx_disable_unprepare_clks(dev);
549 	if (data->plat_data->flags & CI_HDRC_PMQOS)
550 		cpu_latency_qos_remove_request(&data->pm_qos_req);
551 
552 	data->in_lpm = true;
553 
554 	return 0;
555 }
556 
557 static int __maybe_unused imx_controller_resume(struct device *dev)
558 {
559 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
560 	int ret = 0;
561 
562 	dev_dbg(dev, "at %s\n", __func__);
563 
564 	if (!data->in_lpm) {
565 		WARN_ON(1);
566 		return 0;
567 	}
568 
569 	if (data->plat_data->flags & CI_HDRC_PMQOS)
570 		cpu_latency_qos_add_request(&data->pm_qos_req, 0);
571 
572 	ret = imx_prepare_enable_clks(dev);
573 	if (ret)
574 		return ret;
575 
576 	data->in_lpm = false;
577 
578 	ret = imx_usbmisc_set_wakeup(data->usbmisc_data, false);
579 	if (ret) {
580 		dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret);
581 		goto clk_disable;
582 	}
583 
584 	ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, true);
585 	if (ret) {
586 		dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret);
587 		goto hsic_set_clk_fail;
588 	}
589 
590 	return 0;
591 
592 hsic_set_clk_fail:
593 	imx_usbmisc_set_wakeup(data->usbmisc_data, true);
594 clk_disable:
595 	imx_disable_unprepare_clks(dev);
596 	return ret;
597 }
598 
599 static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev)
600 {
601 	int ret;
602 
603 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
604 
605 	if (data->in_lpm)
606 		/* The core's suspend doesn't run */
607 		return 0;
608 
609 	if (device_may_wakeup(dev)) {
610 		ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true);
611 		if (ret) {
612 			dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n",
613 					ret);
614 			return ret;
615 		}
616 	}
617 
618 	ret = imx_controller_suspend(dev);
619 	if (ret)
620 		return ret;
621 
622 	pinctrl_pm_select_sleep_state(dev);
623 	return ret;
624 }
625 
626 static int __maybe_unused ci_hdrc_imx_resume(struct device *dev)
627 {
628 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
629 	int ret;
630 
631 	pinctrl_pm_select_default_state(dev);
632 	ret = imx_controller_resume(dev);
633 	if (!ret && data->supports_runtime_pm) {
634 		pm_runtime_disable(dev);
635 		pm_runtime_set_active(dev);
636 		pm_runtime_enable(dev);
637 	}
638 
639 	return ret;
640 }
641 
642 static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev)
643 {
644 	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
645 	int ret;
646 
647 	if (data->in_lpm) {
648 		WARN_ON(1);
649 		return 0;
650 	}
651 
652 	ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true);
653 	if (ret) {
654 		dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret);
655 		return ret;
656 	}
657 
658 	return imx_controller_suspend(dev);
659 }
660 
661 static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev)
662 {
663 	return imx_controller_resume(dev);
664 }
665 
666 static const struct dev_pm_ops ci_hdrc_imx_pm_ops = {
667 	SET_SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume)
668 	SET_RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend,
669 			ci_hdrc_imx_runtime_resume, NULL)
670 };
671 static struct platform_driver ci_hdrc_imx_driver = {
672 	.probe = ci_hdrc_imx_probe,
673 	.remove = ci_hdrc_imx_remove,
674 	.shutdown = ci_hdrc_imx_shutdown,
675 	.driver = {
676 		.name = "imx_usb",
677 		.of_match_table = ci_hdrc_imx_dt_ids,
678 		.pm = &ci_hdrc_imx_pm_ops,
679 	 },
680 };
681 
682 module_platform_driver(ci_hdrc_imx_driver);
683 
684 MODULE_ALIAS("platform:imx-usb");
685 MODULE_LICENSE("GPL");
686 MODULE_DESCRIPTION("CI HDRC i.MX USB binding");
687 MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
688 MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
689