forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/usb/host/xhci-rcar.c
....@@ -6,6 +6,7 @@
66 */
77
88 #include <linux/firmware.h>
9
+#include <linux/iopoll.h>
910 #include <linux/module.h>
1011 #include <linux/platform_device.h>
1112 #include <linux/of.h>
....@@ -107,15 +108,6 @@
107108 of_device_is_compatible(node, "renesas,rcar-gen2-xhci");
108109 }
109110
110
-static int xhci_rcar_is_gen3(struct device *dev)
111
-{
112
- struct device_node *node = dev->of_node;
113
-
114
- return of_device_is_compatible(node, "renesas,xhci-r8a7795") ||
115
- of_device_is_compatible(node, "renesas,xhci-r8a7796") ||
116
- of_device_is_compatible(node, "renesas,rcar-gen3-xhci");
117
-}
118
-
119111 void xhci_rcar_start(struct usb_hcd *hcd)
120112 {
121113 u32 temp;
....@@ -136,8 +128,7 @@
136128 void __iomem *regs = hcd->regs;
137129 struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
138130 const struct firmware *fw;
139
- int retval, index, j, time;
140
- int timeout = 10000;
131
+ int retval, index, j;
141132 u32 data, val, temp;
142133 u32 quirks = 0;
143134 const struct soc_device_attribute *attr;
....@@ -182,32 +173,19 @@
182173 temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
183174 writel(temp, regs + RCAR_USB3_DL_CTRL);
184175
185
- for (time = 0; time < timeout; time++) {
186
- val = readl(regs + RCAR_USB3_DL_CTRL);
187
- if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
188
- break;
189
- udelay(1);
190
- }
191
- if (time == timeout) {
192
- retval = -ETIMEDOUT;
176
+ retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
177
+ val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
178
+ 1, 10000);
179
+ if (retval < 0)
193180 break;
194
- }
195181 }
196182
197183 temp = readl(regs + RCAR_USB3_DL_CTRL);
198184 temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
199185 writel(temp, regs + RCAR_USB3_DL_CTRL);
200186
201
- for (time = 0; time < timeout; time++) {
202
- val = readl(regs + RCAR_USB3_DL_CTRL);
203
- if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
204
- retval = 0;
205
- break;
206
- }
207
- udelay(1);
208
- }
209
- if (time == timeout)
210
- retval = -ETIMEDOUT;
187
+ retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
188
+ val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000);
211189
212190 release_firmware(fw);
213191
....@@ -216,49 +194,24 @@
216194
217195 static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
218196 {
219
- int timeout = 1000;
197
+ int retval;
220198 u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
221199
222
- while (timeout > 0) {
223
- val = readl(hcd->regs + RCAR_USB3_AXH_STA);
224
- if ((val & mask) == mask)
225
- return true;
226
- udelay(1);
227
- timeout--;
228
- }
229
-
230
- return false;
200
+ retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
201
+ val, (val & mask) == mask, 1, 1000);
202
+ return !retval;
231203 }
232204
233205 /* This function needs to initialize a "phy" of usb before */
234206 int xhci_rcar_init_quirk(struct usb_hcd *hcd)
235207 {
236
- struct xhci_hcd *xhci = hcd_to_xhci(hcd);
237
-
238208 /* If hcd->regs is NULL, we don't just call the following function */
239209 if (!hcd->regs)
240210 return 0;
241211
242
- /*
243
- * On R-Car Gen2 and Gen3, the AC64 bit (bit 0) of HCCPARAMS1 is set
244
- * to 1. However, these SoCs don't support 64-bit address memory
245
- * pointers. So, this driver clears the AC64 bit of xhci->hcc_params
246
- * to call dma_set_coherent_mask(dev, DMA_BIT_MASK(32)) in
247
- * xhci_gen_setup().
248
- *
249
- * And, since the firmware/internal CPU control the USBSTS.STS_HALT
250
- * and the process speed is down when the roothub port enters U3,
251
- * long delay for the handshake of STS_HALT is neeed in xhci_suspend().
252
- */
253
- if (xhci_rcar_is_gen2(hcd->self.controller) ||
254
- xhci_rcar_is_gen3(hcd->self.controller)) {
255
- xhci->quirks |= XHCI_NO_64BIT_SUPPORT | XHCI_SLOW_SUSPEND;
256
- }
257
-
258212 if (!xhci_rcar_wait_for_pll_active(hcd))
259213 return -ETIMEDOUT;
260214
261
- xhci->quirks |= XHCI_TRUST_TX_LENGTH;
262215 return xhci_rcar_download_firmware(hcd);
263216 }
264217