mtu3_plat.c (427c66422e14b8468ee005aa6edf76ef0c2a8fc2) mtu3_plat.c (6b587394c65c23d5ba05a33e5899e2ed8dab3c97)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2016 MediaTek Inc.
4 *
5 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
6 */
7
8#include <linux/dma-mapping.h>

--- 31 unchanged lines hidden (view full) ---

40 if (ret) {
41 dev_err(ssusb->dev, "mac2 clock is not stable\n");
42 return ret;
43 }
44
45 return 0;
46}
47
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2016 MediaTek Inc.
4 *
5 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
6 */
7
8#include <linux/dma-mapping.h>

--- 31 unchanged lines hidden (view full) ---

40 if (ret) {
41 dev_err(ssusb->dev, "mac2 clock is not stable\n");
42 return ret;
43 }
44
45 return 0;
46}
47
48static int wait_for_ip_sleep(struct ssusb_mtk *ssusb)
49{
50 bool sleep_check = true;
51 u32 value;
52 int ret;
53
54 if (!ssusb->is_host)
55 sleep_check = ssusb_gadget_ip_sleep_check(ssusb);
56
57 if (!sleep_check)
58 return 0;
59
60 /* wait for ip enter sleep mode */
61 ret = readl_poll_timeout(ssusb->ippc_base + U3D_SSUSB_IP_PW_STS1, value,
62 (value & SSUSB_IP_SLEEP_STS), 100, 100000);
63 if (ret) {
64 dev_err(ssusb->dev, "ip sleep failed!!!\n");
65 ret = -EBUSY;
66 }
67
68 return ret;
69}
70
48static int ssusb_phy_init(struct ssusb_mtk *ssusb)
49{
50 int i;
51 int ret;
52
53 for (i = 0; i < ssusb->num_phys; i++) {
54 ret = phy_init(ssusb->phys[i]);
55 if (ret)

--- 360 unchanged lines hidden (view full) ---

416 ssusb_debugfs_remove_root(ssusb);
417 pm_runtime_disable(&pdev->dev);
418 pm_runtime_put_noidle(&pdev->dev);
419 pm_runtime_set_suspended(&pdev->dev);
420
421 return 0;
422}
423
71static int ssusb_phy_init(struct ssusb_mtk *ssusb)
72{
73 int i;
74 int ret;
75
76 for (i = 0; i < ssusb->num_phys; i++) {
77 ret = phy_init(ssusb->phys[i]);
78 if (ret)

--- 360 unchanged lines hidden (view full) ---

439 ssusb_debugfs_remove_root(ssusb);
440 pm_runtime_disable(&pdev->dev);
441 pm_runtime_put_noidle(&pdev->dev);
442 pm_runtime_set_suspended(&pdev->dev);
443
444 return 0;
445}
446
447static int resume_ip_and_ports(struct ssusb_mtk *ssusb, pm_message_t msg)
448{
449 switch (ssusb->dr_mode) {
450 case USB_DR_MODE_PERIPHERAL:
451 ssusb_gadget_resume(ssusb, msg);
452 break;
453 case USB_DR_MODE_HOST:
454 ssusb_host_resume(ssusb, false);
455 break;
456 case USB_DR_MODE_OTG:
457 ssusb_host_resume(ssusb, !ssusb->is_host);
458 if (!ssusb->is_host)
459 ssusb_gadget_resume(ssusb, msg);
460
461 break;
462 default:
463 return -EINVAL;
464 }
465
466 return 0;
467}
468
424static int mtu3_suspend_common(struct device *dev, pm_message_t msg)
425{
426 struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
427 int ret = 0;
428
429 dev_dbg(dev, "%s\n", __func__);
430
431 switch (ssusb->dr_mode) {
432 case USB_DR_MODE_PERIPHERAL:
433 ret = ssusb_gadget_suspend(ssusb, msg);
434 if (ret)
469static int mtu3_suspend_common(struct device *dev, pm_message_t msg)
470{
471 struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
472 int ret = 0;
473
474 dev_dbg(dev, "%s\n", __func__);
475
476 switch (ssusb->dr_mode) {
477 case USB_DR_MODE_PERIPHERAL:
478 ret = ssusb_gadget_suspend(ssusb, msg);
479 if (ret)
435 return ret;
480 goto err;
436
437 break;
438 case USB_DR_MODE_HOST:
439 ssusb_host_suspend(ssusb);
440 break;
441 case USB_DR_MODE_OTG:
481
482 break;
483 case USB_DR_MODE_HOST:
484 ssusb_host_suspend(ssusb);
485 break;
486 case USB_DR_MODE_OTG:
442 if (!ssusb->is_host)
443 return 0;
444
487 if (!ssusb->is_host) {
488 ret = ssusb_gadget_suspend(ssusb, msg);
489 if (ret)
490 goto err;
491 }
445 ssusb_host_suspend(ssusb);
446 break;
447 default:
448 return -EINVAL;
449 }
492 ssusb_host_suspend(ssusb);
493 break;
494 default:
495 return -EINVAL;
496 }
497
498 ret = wait_for_ip_sleep(ssusb);
499 if (ret)
500 goto sleep_err;
501
450 ssusb_phy_power_off(ssusb);
451 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks);
452 ssusb_wakeup_set(ssusb, true);
453
502 ssusb_phy_power_off(ssusb);
503 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks);
504 ssusb_wakeup_set(ssusb, true);
505
454 return 0;
506sleep_err:
507 resume_ip_and_ports(ssusb, msg);
508err:
509 return ret;
455}
456
457static int mtu3_resume_common(struct device *dev, pm_message_t msg)
458{
459 struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
460 int ret;
461
462 dev_dbg(dev, "%s\n", __func__);
463
464 ssusb_wakeup_set(ssusb, false);
465 ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks);
466 if (ret)
467 goto clks_err;
468
469 ret = ssusb_phy_power_on(ssusb);
470 if (ret)
471 goto phy_err;
472
510}
511
512static int mtu3_resume_common(struct device *dev, pm_message_t msg)
513{
514 struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
515 int ret;
516
517 dev_dbg(dev, "%s\n", __func__);
518
519 ssusb_wakeup_set(ssusb, false);
520 ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks);
521 if (ret)
522 goto clks_err;
523
524 ret = ssusb_phy_power_on(ssusb);
525 if (ret)
526 goto phy_err;
527
473 switch (ssusb->dr_mode) {
474 case USB_DR_MODE_PERIPHERAL:
475 ssusb_gadget_resume(ssusb, msg);
476 break;
477 case USB_DR_MODE_HOST:
478 ssusb_host_resume(ssusb, false);
479 break;
480 case USB_DR_MODE_OTG:
481 if (!ssusb->is_host)
482 return 0;
528 return resume_ip_and_ports(ssusb, msg);
483
529
484 ssusb_host_resume(ssusb, true);
485 break;
486 default:
487 return -EINVAL;
488 }
489
490 return 0;
491
492phy_err:
493 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks);
494clks_err:
495 return ret;
496}
497
498static int __maybe_unused mtu3_suspend(struct device *dev)
499{

--- 53 unchanged lines hidden ---
530phy_err:
531 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks);
532clks_err:
533 return ret;
534}
535
536static int __maybe_unused mtu3_suspend(struct device *dev)
537{

--- 53 unchanged lines hidden ---