mediatek: backport upstream mediatek patches
[openwrt/staging/hauke.git] / target / linux / mediatek / patches-4.14 / 0104-usb-mtu3-support-option-to-disable-usb3-ports.patch
1 From 7a46c3488c48a0fbe313ed25c12af3fb3af48a01 Mon Sep 17 00:00:00 2001
2 From: Chunfeng Yun <chunfeng.yun@mediatek.com>
3 Date: Fri, 13 Oct 2017 17:10:38 +0800
4 Subject: [PATCH 104/224] usb: mtu3: 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
10 Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
11 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
12 ---
13 drivers/usb/mtu3/mtu3.h | 3 +++
14 drivers/usb/mtu3/mtu3_host.c | 16 +++++++++++++---
15 drivers/usb/mtu3/mtu3_plat.c | 8 ++++++--
16 3 files changed, 22 insertions(+), 5 deletions(-)
17
18 diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
19 index b26fffc58446..112723d6e7bc 100644
20 --- a/drivers/usb/mtu3/mtu3.h
21 +++ b/drivers/usb/mtu3/mtu3.h
22 @@ -210,6 +210,8 @@ struct otg_switch_mtk {
23 * host only, device only or dual-role mode
24 * @u2_ports: number of usb2.0 host ports
25 * @u3_ports: number of usb3.0 host ports
26 + * @u3p_dis_msk: mask of disabling usb3 ports, for example, bit0==1 to
27 + * disable u3port0, bit1==1 to disable u3port1,... etc
28 * @dbgfs_root: only used when supports manual dual-role switch via debugfs
29 * @wakeup_en: it's true when supports remote wakeup in host mode
30 * @wk_deb_p0: port0's wakeup debounce clock
31 @@ -232,6 +234,7 @@ struct ssusb_mtk {
32 bool is_host;
33 int u2_ports;
34 int u3_ports;
35 + int u3p_dis_msk;
36 struct dentry *dbgfs_root;
37 /* usb wakeup for host mode */
38 bool wakeup_en;
39 diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
40 index e42d308b8dc2..4dd9508a60b5 100644
41 --- a/drivers/usb/mtu3/mtu3_host.c
42 +++ b/drivers/usb/mtu3/mtu3_host.c
43 @@ -151,6 +151,7 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
44 void __iomem *ibase = ssusb->ippc_base;
45 int num_u3p = ssusb->u3_ports;
46 int num_u2p = ssusb->u2_ports;
47 + int u3_ports_disabed;
48 u32 check_clk;
49 u32 value;
50 int i;
51 @@ -158,8 +159,14 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
52 /* power on host ip */
53 mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN);
54
55 - /* power on and enable all u3 ports */
56 + /* power on and enable u3 ports except skipped ones */
57 + u3_ports_disabed = 0;
58 for (i = 0; i < num_u3p; i++) {
59 + if ((0x1 << i) & ssusb->u3p_dis_msk) {
60 + u3_ports_disabed++;
61 + continue;
62 + }
63 +
64 value = mtu3_readl(ibase, SSUSB_U3_CTRL(i));
65 value &= ~(SSUSB_U3_PORT_PDN | SSUSB_U3_PORT_DIS);
66 value |= SSUSB_U3_PORT_HOST_SEL;
67 @@ -175,7 +182,7 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
68 }
69
70 check_clk = SSUSB_XHCI_RST_B_STS;
71 - if (num_u3p)
72 + if (num_u3p > u3_ports_disabed)
73 check_clk = SSUSB_U3_MAC_RST_B_STS;
74
75 return ssusb_check_clocks(ssusb, check_clk);
76 @@ -190,8 +197,11 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend)
77 int ret;
78 int i;
79
80 - /* power down and disable all u3 ports */
81 + /* power down and disable u3 ports except skipped ones */
82 for (i = 0; i < num_u3p; i++) {
83 + if ((0x1 << i) & ssusb->u3p_dis_msk)
84 + continue;
85 +
86 value = mtu3_readl(ibase, SSUSB_U3_CTRL(i));
87 value |= SSUSB_U3_PORT_PDN;
88 value |= suspend ? 0 : SSUSB_U3_PORT_DIS;
89 diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
90 index 088e3e685c4f..9edad30c8ae5 100644
91 --- a/drivers/usb/mtu3/mtu3_plat.c
92 +++ b/drivers/usb/mtu3/mtu3_plat.c
93 @@ -276,6 +276,10 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb)
94 if (ret)
95 return ret;
96
97 + /* optional property, ignore the error if it does not exist */
98 + of_property_read_u32(node, "mediatek,u3p-dis-msk",
99 + &ssusb->u3p_dis_msk);
100 +
101 if (ssusb->dr_mode != USB_DR_MODE_OTG)
102 return 0;
103
104 @@ -304,8 +308,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb)
105 }
106 }
107
108 - dev_info(dev, "dr_mode: %d, is_u3_dr: %d\n",
109 - ssusb->dr_mode, otg_sx->is_u3_drd);
110 + dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk:%x\n",
111 + ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk);
112
113 return 0;
114 }
115 --
116 2.11.0
117