mediatek: backport upstream mediatek patches
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0109-usb-mtu3-add-support-for-usb3.1-IP.patch
1 From 8f444887e23b9f0ea31aaae74fbc18171714d8d2 Mon Sep 17 00:00:00 2001
2 From: Chunfeng Yun <chunfeng.yun@mediatek.com>
3 Date: Fri, 13 Oct 2017 17:10:43 +0800
4 Subject: [PATCH 109/224] usb: mtu3: add support for usb3.1 IP
5
6 Support SuperSpeedPlus for usb3.1 device IP
7
8 Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
9 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
10 ---
11 drivers/usb/mtu3/mtu3.h | 1 +
12 drivers/usb/mtu3/mtu3_core.c | 14 +++++++++++---
13 drivers/usb/mtu3/mtu3_gadget.c | 3 ++-
14 drivers/usb/mtu3/mtu3_gadget_ep0.c | 16 ++++++++--------
15 drivers/usb/mtu3/mtu3_hw_regs.h | 1 +
16 5 files changed, 23 insertions(+), 12 deletions(-)
17
18 diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
19 index b0c2b5dca045..d80e4e813248 100644
20 --- a/drivers/usb/mtu3/mtu3.h
21 +++ b/drivers/usb/mtu3/mtu3.h
22 @@ -94,6 +94,7 @@ enum mtu3_speed {
23 MTU3_SPEED_FULL = 1,
24 MTU3_SPEED_HIGH = 3,
25 MTU3_SPEED_SUPER = 4,
26 + MTU3_SPEED_SUPER_PLUS = 5,
27 };
28
29 /**
30 diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
31 index cd4528f5f337..67f7a309aba7 100644
32 --- a/drivers/usb/mtu3/mtu3_core.c
33 +++ b/drivers/usb/mtu3/mtu3_core.c
34 @@ -237,7 +237,7 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
35
36 void mtu3_dev_on_off(struct mtu3 *mtu, int is_on)
37 {
38 - if (mtu->is_u3_ip && (mtu->max_speed == USB_SPEED_SUPER))
39 + if (mtu->is_u3_ip && mtu->max_speed >= USB_SPEED_SUPER)
40 mtu3_ss_func_set(mtu, is_on);
41 else
42 mtu3_hs_softconn_set(mtu, is_on);
43 @@ -547,6 +547,9 @@ static void mtu3_set_speed(struct mtu3 *mtu)
44 mtu3_clrbits(mbase, U3D_USB3_CONFIG, USB3_EN);
45 /* HS/FS detected by HW */
46 mtu3_setbits(mbase, U3D_POWER_MANAGEMENT, HS_ENABLE);
47 + } else if (mtu->max_speed == USB_SPEED_SUPER) {
48 + mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0),
49 + SSUSB_U3_PORT_SSP_SPEED);
50 }
51
52 dev_info(mtu->dev, "max_speed: %s\n",
53 @@ -624,6 +627,10 @@ static irqreturn_t mtu3_link_isr(struct mtu3 *mtu)
54 udev_speed = USB_SPEED_SUPER;
55 maxpkt = 512;
56 break;
57 + case MTU3_SPEED_SUPER_PLUS:
58 + udev_speed = USB_SPEED_SUPER_PLUS;
59 + maxpkt = 512;
60 + break;
61 default:
62 udev_speed = USB_SPEED_UNKNOWN;
63 break;
64 @@ -825,14 +832,15 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
65 case USB_SPEED_FULL:
66 case USB_SPEED_HIGH:
67 case USB_SPEED_SUPER:
68 + case USB_SPEED_SUPER_PLUS:
69 break;
70 default:
71 dev_err(dev, "invalid max_speed: %s\n",
72 usb_speed_string(mtu->max_speed));
73 /* fall through */
74 case USB_SPEED_UNKNOWN:
75 - /* default as SS */
76 - mtu->max_speed = USB_SPEED_SUPER;
77 + /* default as SSP */
78 + mtu->max_speed = USB_SPEED_SUPER_PLUS;
79 break;
80 }
81
82 diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
83 index 434fca58143c..b495471f689f 100644
84 --- a/drivers/usb/mtu3/mtu3_gadget.c
85 +++ b/drivers/usb/mtu3/mtu3_gadget.c
86 @@ -89,6 +89,7 @@ static int mtu3_ep_enable(struct mtu3_ep *mep)
87
88 switch (mtu->g.speed) {
89 case USB_SPEED_SUPER:
90 + case USB_SPEED_SUPER_PLUS:
91 if (usb_endpoint_xfer_int(desc) ||
92 usb_endpoint_xfer_isoc(desc)) {
93 interval = desc->bInterval;
94 @@ -456,7 +457,7 @@ static int mtu3_gadget_wakeup(struct usb_gadget *gadget)
95 return -EOPNOTSUPP;
96
97 spin_lock_irqsave(&mtu->lock, flags);
98 - if (mtu->g.speed == USB_SPEED_SUPER) {
99 + if (mtu->g.speed >= USB_SPEED_SUPER) {
100 mtu3_setbits(mtu->mac_base, U3D_LINK_POWER_CONTROL, UX_EXIT);
101 } else {
102 mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME);
103 diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c b/drivers/usb/mtu3/mtu3_gadget_ep0.c
104 index 958d74dd2b78..020b25314a68 100644
105 --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
106 +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
107 @@ -212,8 +212,8 @@ ep0_get_status(struct mtu3 *mtu, const struct usb_ctrlrequest *setup)
108 case USB_RECIP_DEVICE:
109 result[0] = mtu->is_self_powered << USB_DEVICE_SELF_POWERED;
110 result[0] |= mtu->may_wakeup << USB_DEVICE_REMOTE_WAKEUP;
111 - /* superspeed only */
112 - if (mtu->g.speed == USB_SPEED_SUPER) {
113 +
114 + if (mtu->g.speed >= USB_SPEED_SUPER) {
115 result[0] |= mtu->u1_enable << USB_DEV_STAT_U1_ENABLED;
116 result[0] |= mtu->u2_enable << USB_DEV_STAT_U2_ENABLED;
117 }
118 @@ -329,8 +329,8 @@ static int ep0_handle_feature_dev(struct mtu3 *mtu,
119 handled = handle_test_mode(mtu, setup);
120 break;
121 case USB_DEVICE_U1_ENABLE:
122 - if (mtu->g.speed != USB_SPEED_SUPER ||
123 - mtu->g.state != USB_STATE_CONFIGURED)
124 + if (mtu->g.speed < USB_SPEED_SUPER ||
125 + mtu->g.state != USB_STATE_CONFIGURED)
126 break;
127
128 lpc = mtu3_readl(mbase, U3D_LINK_POWER_CONTROL);
129 @@ -344,8 +344,8 @@ static int ep0_handle_feature_dev(struct mtu3 *mtu,
130 handled = 1;
131 break;
132 case USB_DEVICE_U2_ENABLE:
133 - if (mtu->g.speed != USB_SPEED_SUPER ||
134 - mtu->g.state != USB_STATE_CONFIGURED)
135 + if (mtu->g.speed < USB_SPEED_SUPER ||
136 + mtu->g.state != USB_STATE_CONFIGURED)
137 break;
138
139 lpc = mtu3_readl(mbase, U3D_LINK_POWER_CONTROL);
140 @@ -384,8 +384,8 @@ static int ep0_handle_feature(struct mtu3 *mtu,
141 break;
142 case USB_RECIP_INTERFACE:
143 /* superspeed only */
144 - if ((value == USB_INTRF_FUNC_SUSPEND)
145 - && (mtu->g.speed == USB_SPEED_SUPER)) {
146 + if (value == USB_INTRF_FUNC_SUSPEND &&
147 + mtu->g.speed >= USB_SPEED_SUPER) {
148 /*
149 * forward the request because function drivers
150 * should handle it
151 diff --git a/drivers/usb/mtu3/mtu3_hw_regs.h b/drivers/usb/mtu3/mtu3_hw_regs.h
152 index a7e35f6ad90a..6953436a1688 100644
153 --- a/drivers/usb/mtu3/mtu3_hw_regs.h
154 +++ b/drivers/usb/mtu3/mtu3_hw_regs.h
155 @@ -467,6 +467,7 @@
156 #define SSUSB_VBUS_CHG_INT_B_EN BIT(6)
157
158 /* U3D_SSUSB_U3_CTRL_0P */
159 +#define SSUSB_U3_PORT_SSP_SPEED BIT(9)
160 #define SSUSB_U3_PORT_HOST_SEL BIT(2)
161 #define SSUSB_U3_PORT_PDN BIT(1)
162 #define SSUSB_U3_PORT_DIS BIT(0)
163 --
164 2.11.0
165