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