diff options
author | Kishon Vijay Abraham I <kishon@ti.com> | 2014-03-03 06:38:11 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-03-05 15:40:05 -0500 |
commit | 57303488cd37da58263e842de134dc65f7c626d5 (patch) | |
tree | a685fd9127863c2bc7519407e022b8750325518f | |
parent | 122f06e60f90a43d9b2fb30662af688dfb759379 (diff) |
usb: dwc3: adapt dwc3 core to use Generic PHY Framework
Adapted dwc3 core to use the Generic PHY Framework. So for init, exit,
power_on and power_off the following APIs are used phy_init(), phy_exit(),
phy_power_on() and phy_power_off().
However using the old USB phy library wont be removed till the PHYs of all
other SoC's using dwc3 core is adapted to the Generic PHY Framework.
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | Documentation/devicetree/bindings/usb/dwc3.txt | 6 | ||||
-rw-r--r-- | drivers/usb/dwc3/core.c | 80 | ||||
-rw-r--r-- | drivers/usb/dwc3/core.h | 7 |
3 files changed, 88 insertions, 5 deletions
diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index e807635f9e1c..471366d6a129 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt | |||
@@ -6,11 +6,13 @@ Required properties: | |||
6 | - compatible: must be "snps,dwc3" | 6 | - compatible: must be "snps,dwc3" |
7 | - reg : Address and length of the register set for the device | 7 | - reg : Address and length of the register set for the device |
8 | - interrupts: Interrupts used by the dwc3 controller. | 8 | - interrupts: Interrupts used by the dwc3 controller. |
9 | |||
10 | Optional properties: | ||
9 | - usb-phy : array of phandle for the PHY device. The first element | 11 | - usb-phy : array of phandle for the PHY device. The first element |
10 | in the array is expected to be a handle to the USB2/HS PHY and | 12 | in the array is expected to be a handle to the USB2/HS PHY and |
11 | the second element is expected to be a handle to the USB3/SS PHY | 13 | the second element is expected to be a handle to the USB3/SS PHY |
12 | 14 | - phys: from the *Generic PHY* bindings | |
13 | Optional properties: | 15 | - phy-names: from the *Generic PHY* bindings |
14 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. | 16 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. |
15 | 17 | ||
16 | This is usually a subnode to DWC3 glue to which it is connected. | 18 | This is usually a subnode to DWC3 glue to which it is connected. |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index c89570cc0689..d001417e8e37 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -61,9 +61,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode) | |||
61 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset | 61 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset |
62 | * @dwc: pointer to our context structure | 62 | * @dwc: pointer to our context structure |
63 | */ | 63 | */ |
64 | static void dwc3_core_soft_reset(struct dwc3 *dwc) | 64 | static int dwc3_core_soft_reset(struct dwc3 *dwc) |
65 | { | 65 | { |
66 | u32 reg; | 66 | u32 reg; |
67 | int ret; | ||
67 | 68 | ||
68 | /* Before Resetting PHY, put Core in Reset */ | 69 | /* Before Resetting PHY, put Core in Reset */ |
69 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 70 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
@@ -82,6 +83,15 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc) | |||
82 | 83 | ||
83 | usb_phy_init(dwc->usb2_phy); | 84 | usb_phy_init(dwc->usb2_phy); |
84 | usb_phy_init(dwc->usb3_phy); | 85 | usb_phy_init(dwc->usb3_phy); |
86 | ret = phy_init(dwc->usb2_generic_phy); | ||
87 | if (ret < 0) | ||
88 | return ret; | ||
89 | |||
90 | ret = phy_init(dwc->usb3_generic_phy); | ||
91 | if (ret < 0) { | ||
92 | phy_exit(dwc->usb2_generic_phy); | ||
93 | return ret; | ||
94 | } | ||
85 | mdelay(100); | 95 | mdelay(100); |
86 | 96 | ||
87 | /* Clear USB3 PHY reset */ | 97 | /* Clear USB3 PHY reset */ |
@@ -100,6 +110,8 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc) | |||
100 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 110 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
101 | reg &= ~DWC3_GCTL_CORESOFTRESET; | 111 | reg &= ~DWC3_GCTL_CORESOFTRESET; |
102 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | 112 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
113 | |||
114 | return 0; | ||
103 | } | 115 | } |
104 | 116 | ||
105 | /** | 117 | /** |
@@ -391,7 +403,9 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
391 | cpu_relax(); | 403 | cpu_relax(); |
392 | } while (true); | 404 | } while (true); |
393 | 405 | ||
394 | dwc3_core_soft_reset(dwc); | 406 | ret = dwc3_core_soft_reset(dwc); |
407 | if (ret) | ||
408 | goto err0; | ||
395 | 409 | ||
396 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 410 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
397 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; | 411 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
@@ -456,6 +470,8 @@ err2: | |||
456 | err1: | 470 | err1: |
457 | usb_phy_shutdown(dwc->usb2_phy); | 471 | usb_phy_shutdown(dwc->usb2_phy); |
458 | usb_phy_shutdown(dwc->usb3_phy); | 472 | usb_phy_shutdown(dwc->usb3_phy); |
473 | phy_exit(dwc->usb2_generic_phy); | ||
474 | phy_exit(dwc->usb3_generic_phy); | ||
459 | 475 | ||
460 | err0: | 476 | err0: |
461 | return ret; | 477 | return ret; |
@@ -466,6 +482,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) | |||
466 | dwc3_free_scratch_buffers(dwc); | 482 | dwc3_free_scratch_buffers(dwc); |
467 | usb_phy_shutdown(dwc->usb2_phy); | 483 | usb_phy_shutdown(dwc->usb2_phy); |
468 | usb_phy_shutdown(dwc->usb3_phy); | 484 | usb_phy_shutdown(dwc->usb3_phy); |
485 | phy_exit(dwc->usb2_generic_phy); | ||
486 | phy_exit(dwc->usb3_generic_phy); | ||
469 | } | 487 | } |
470 | 488 | ||
471 | #define DWC3_ALIGN_MASK (16 - 1) | 489 | #define DWC3_ALIGN_MASK (16 - 1) |
@@ -556,6 +574,32 @@ static int dwc3_probe(struct platform_device *pdev) | |||
556 | } | 574 | } |
557 | } | 575 | } |
558 | 576 | ||
577 | dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); | ||
578 | if (IS_ERR(dwc->usb2_generic_phy)) { | ||
579 | ret = PTR_ERR(dwc->usb2_generic_phy); | ||
580 | if (ret == -ENOSYS || ret == -ENODEV) { | ||
581 | dwc->usb2_generic_phy = NULL; | ||
582 | } else if (ret == -EPROBE_DEFER) { | ||
583 | return ret; | ||
584 | } else { | ||
585 | dev_err(dev, "no usb2 phy configured\n"); | ||
586 | return ret; | ||
587 | } | ||
588 | } | ||
589 | |||
590 | dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); | ||
591 | if (IS_ERR(dwc->usb3_generic_phy)) { | ||
592 | ret = PTR_ERR(dwc->usb3_generic_phy); | ||
593 | if (ret == -ENOSYS || ret == -ENODEV) { | ||
594 | dwc->usb3_generic_phy = NULL; | ||
595 | } else if (ret == -EPROBE_DEFER) { | ||
596 | return ret; | ||
597 | } else { | ||
598 | dev_err(dev, "no usb3 phy configured\n"); | ||
599 | return ret; | ||
600 | } | ||
601 | } | ||
602 | |||
559 | dwc->xhci_resources[0].start = res->start; | 603 | dwc->xhci_resources[0].start = res->start; |
560 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + | 604 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + |
561 | DWC3_XHCI_REGS_END; | 605 | DWC3_XHCI_REGS_END; |
@@ -612,11 +656,18 @@ static int dwc3_probe(struct platform_device *pdev) | |||
612 | 656 | ||
613 | usb_phy_set_suspend(dwc->usb2_phy, 0); | 657 | usb_phy_set_suspend(dwc->usb2_phy, 0); |
614 | usb_phy_set_suspend(dwc->usb3_phy, 0); | 658 | usb_phy_set_suspend(dwc->usb3_phy, 0); |
659 | ret = phy_power_on(dwc->usb2_generic_phy); | ||
660 | if (ret < 0) | ||
661 | goto err1; | ||
662 | |||
663 | ret = phy_power_on(dwc->usb3_generic_phy); | ||
664 | if (ret < 0) | ||
665 | goto err_usb2phy_power; | ||
615 | 666 | ||
616 | ret = dwc3_event_buffers_setup(dwc); | 667 | ret = dwc3_event_buffers_setup(dwc); |
617 | if (ret) { | 668 | if (ret) { |
618 | dev_err(dwc->dev, "failed to setup event buffers\n"); | 669 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
619 | goto err1; | 670 | goto err_usb3phy_power; |
620 | } | 671 | } |
621 | 672 | ||
622 | switch (dwc->dr_mode) { | 673 | switch (dwc->dr_mode) { |
@@ -685,6 +736,12 @@ err3: | |||
685 | err2: | 736 | err2: |
686 | dwc3_event_buffers_cleanup(dwc); | 737 | dwc3_event_buffers_cleanup(dwc); |
687 | 738 | ||
739 | err_usb3phy_power: | ||
740 | phy_power_off(dwc->usb3_generic_phy); | ||
741 | |||
742 | err_usb2phy_power: | ||
743 | phy_power_off(dwc->usb2_generic_phy); | ||
744 | |||
688 | err1: | 745 | err1: |
689 | usb_phy_set_suspend(dwc->usb2_phy, 1); | 746 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
690 | usb_phy_set_suspend(dwc->usb3_phy, 1); | 747 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
@@ -702,6 +759,8 @@ static int dwc3_remove(struct platform_device *pdev) | |||
702 | 759 | ||
703 | usb_phy_set_suspend(dwc->usb2_phy, 1); | 760 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
704 | usb_phy_set_suspend(dwc->usb3_phy, 1); | 761 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
762 | phy_power_off(dwc->usb2_generic_phy); | ||
763 | phy_power_off(dwc->usb3_generic_phy); | ||
705 | 764 | ||
706 | pm_runtime_put_sync(&pdev->dev); | 765 | pm_runtime_put_sync(&pdev->dev); |
707 | pm_runtime_disable(&pdev->dev); | 766 | pm_runtime_disable(&pdev->dev); |
@@ -799,6 +858,8 @@ static int dwc3_suspend(struct device *dev) | |||
799 | 858 | ||
800 | usb_phy_shutdown(dwc->usb3_phy); | 859 | usb_phy_shutdown(dwc->usb3_phy); |
801 | usb_phy_shutdown(dwc->usb2_phy); | 860 | usb_phy_shutdown(dwc->usb2_phy); |
861 | phy_exit(dwc->usb2_generic_phy); | ||
862 | phy_exit(dwc->usb3_generic_phy); | ||
802 | 863 | ||
803 | return 0; | 864 | return 0; |
804 | } | 865 | } |
@@ -807,9 +868,17 @@ static int dwc3_resume(struct device *dev) | |||
807 | { | 868 | { |
808 | struct dwc3 *dwc = dev_get_drvdata(dev); | 869 | struct dwc3 *dwc = dev_get_drvdata(dev); |
809 | unsigned long flags; | 870 | unsigned long flags; |
871 | int ret; | ||
810 | 872 | ||
811 | usb_phy_init(dwc->usb3_phy); | 873 | usb_phy_init(dwc->usb3_phy); |
812 | usb_phy_init(dwc->usb2_phy); | 874 | usb_phy_init(dwc->usb2_phy); |
875 | ret = phy_init(dwc->usb2_generic_phy); | ||
876 | if (ret < 0) | ||
877 | return ret; | ||
878 | |||
879 | ret = phy_init(dwc->usb3_generic_phy); | ||
880 | if (ret < 0) | ||
881 | goto err_usb2phy_init; | ||
813 | 882 | ||
814 | spin_lock_irqsave(&dwc->lock, flags); | 883 | spin_lock_irqsave(&dwc->lock, flags); |
815 | 884 | ||
@@ -833,6 +902,11 @@ static int dwc3_resume(struct device *dev) | |||
833 | pm_runtime_enable(dev); | 902 | pm_runtime_enable(dev); |
834 | 903 | ||
835 | return 0; | 904 | return 0; |
905 | |||
906 | err_usb2phy_init: | ||
907 | phy_exit(dwc->usb2_generic_phy); | ||
908 | |||
909 | return ret; | ||
836 | } | 910 | } |
837 | 911 | ||
838 | static const struct dev_pm_ops dwc3_dev_pm_ops = { | 912 | static const struct dev_pm_ops dwc3_dev_pm_ops = { |
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 535bb6e1f2b8..57332e3768e4 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -31,6 +31,8 @@ | |||
31 | #include <linux/usb/gadget.h> | 31 | #include <linux/usb/gadget.h> |
32 | #include <linux/usb/otg.h> | 32 | #include <linux/usb/otg.h> |
33 | 33 | ||
34 | #include <linux/phy/phy.h> | ||
35 | |||
34 | /* Global constants */ | 36 | /* Global constants */ |
35 | #define DWC3_EP0_BOUNCE_SIZE 512 | 37 | #define DWC3_EP0_BOUNCE_SIZE 512 |
36 | #define DWC3_ENDPOINTS_NUM 32 | 38 | #define DWC3_ENDPOINTS_NUM 32 |
@@ -619,6 +621,8 @@ struct dwc3_scratchpad_array { | |||
619 | * @dr_mode: requested mode of operation | 621 | * @dr_mode: requested mode of operation |
620 | * @usb2_phy: pointer to USB2 PHY | 622 | * @usb2_phy: pointer to USB2 PHY |
621 | * @usb3_phy: pointer to USB3 PHY | 623 | * @usb3_phy: pointer to USB3 PHY |
624 | * @usb2_generic_phy: pointer to USB2 PHY | ||
625 | * @usb3_generic_phy: pointer to USB3 PHY | ||
622 | * @dcfg: saved contents of DCFG register | 626 | * @dcfg: saved contents of DCFG register |
623 | * @gctl: saved contents of GCTL register | 627 | * @gctl: saved contents of GCTL register |
624 | * @isoch_delay: wValue from Set Isochronous Delay request; | 628 | * @isoch_delay: wValue from Set Isochronous Delay request; |
@@ -679,6 +683,9 @@ struct dwc3 { | |||
679 | struct usb_phy *usb2_phy; | 683 | struct usb_phy *usb2_phy; |
680 | struct usb_phy *usb3_phy; | 684 | struct usb_phy *usb3_phy; |
681 | 685 | ||
686 | struct phy *usb2_generic_phy; | ||
687 | struct phy *usb3_generic_phy; | ||
688 | |||
682 | void __iomem *regs; | 689 | void __iomem *regs; |
683 | size_t regs_size; | 690 | size_t regs_size; |
684 | 691 | ||