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