90e2aed441913786df1029fdf5ebd92f616f9386
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0129-usb-xhci-mtk-support-option-to-disable-usb3-ports.patch
1 From 13a1b2e927893cbb046a1ec5a55ec3516873a3f6 Mon Sep 17 00:00:00 2001
2 From: Chunfeng Yun <chunfeng.yun@mediatek.com>
3 Date: Fri, 13 Oct 2017 16:26:36 +0800
4 Subject: [PATCH 129/224] usb: xhci-mtk: support option to disable usb3 ports
5
6 Add support to disable specific usb3 ports, it's useful when
7 usb3 phy is shared with PCIe or SATA, because we should disable
8 the corresponding usb3 port if the phy is used by PCIe or SATA.
9 Sometimes it's helpful to analyse and solve problems.
10
11 Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
12 Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 ---
15 drivers/usb/host/xhci-mtk.c | 18 +++++++++++++++---
16 drivers/usb/host/xhci-mtk.h | 1 +
17 2 files changed, 16 insertions(+), 3 deletions(-)
18
19 diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
20 index 7a92bb782e5c..97ba51e4e149 100644
21 --- a/drivers/usb/host/xhci-mtk.c
22 +++ b/drivers/usb/host/xhci-mtk.c
23 @@ -92,6 +92,7 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
24 {
25 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
26 u32 value, check_val;
27 + int u3_ports_disabed = 0;
28 int ret;
29 int i;
30
31 @@ -103,8 +104,13 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
32 value &= ~CTRL1_IP_HOST_PDN;
33 writel(value, &ippc->ip_pw_ctr1);
34
35 - /* power on and enable all u3 ports */
36 + /* power on and enable u3 ports except skipped ones */
37 for (i = 0; i < mtk->num_u3_ports; i++) {
38 + if ((0x1 << i) & mtk->u3p_dis_msk) {
39 + u3_ports_disabed++;
40 + continue;
41 + }
42 +
43 value = readl(&ippc->u3_ctrl_p[i]);
44 value &= ~(CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS);
45 value |= CTRL_U3_PORT_HOST_SEL;
46 @@ -126,7 +132,7 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
47 check_val = STS1_SYSPLL_STABLE | STS1_REF_RST |
48 STS1_SYS125_RST | STS1_XHCI_RST;
49
50 - if (mtk->num_u3_ports)
51 + if (mtk->num_u3_ports > u3_ports_disabed)
52 check_val |= STS1_U3_MAC_RST;
53
54 ret = readl_poll_timeout(&ippc->ip_pw_sts1, value,
55 @@ -149,8 +155,11 @@ static int xhci_mtk_host_disable(struct xhci_hcd_mtk *mtk)
56 if (!mtk->has_ippc)
57 return 0;
58
59 - /* power down all u3 ports */
60 + /* power down u3 ports except skipped ones */
61 for (i = 0; i < mtk->num_u3_ports; i++) {
62 + if ((0x1 << i) & mtk->u3p_dis_msk)
63 + continue;
64 +
65 value = readl(&ippc->u3_ctrl_p[i]);
66 value |= CTRL_U3_PORT_PDN;
67 writel(value, &ippc->u3_ctrl_p[i]);
68 @@ -573,6 +582,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
69 }
70
71 mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
72 + /* optional property, ignore the error if it does not exist */
73 + of_property_read_u32(node, "mediatek,u3p-dis-msk",
74 + &mtk->u3p_dis_msk);
75
76 ret = usb_wakeup_of_property_parse(mtk, node);
77 if (ret)
78 diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
79 index 3aa5e1d25064..db55a12f1585 100644
80 --- a/drivers/usb/host/xhci-mtk.h
81 +++ b/drivers/usb/host/xhci-mtk.h
82 @@ -121,6 +121,7 @@ struct xhci_hcd_mtk {
83 bool has_ippc;
84 int num_u2_ports;
85 int num_u3_ports;
86 + int u3p_dis_msk;
87 struct regulator *vusb33;
88 struct regulator *vbus;
89 struct clk *sys_clk; /* sys and mac clock */
90 --
91 2.11.0
92