forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/usb/gadget/udc/aspeed-vhub/core.c
....@@ -66,14 +66,16 @@
6666 void ast_vhub_nuke(struct ast_vhub_ep *ep, int status)
6767 {
6868 struct ast_vhub_req *req;
69
-
70
- EPDBG(ep, "Nuking\n");
69
+ int count = 0;
7170
7271 /* Beware, lock will be dropped & req-acquired by done() */
7372 while (!list_empty(&ep->queue)) {
7473 req = list_first_entry(&ep->queue, struct ast_vhub_req, queue);
7574 ast_vhub_done(ep, req, status);
75
+ count++;
7676 }
77
+ if (count)
78
+ EPDBG(ep, "Nuked %d request(s)\n", count);
7779 }
7880
7981 struct usb_request *ast_vhub_alloc_request(struct usb_ep *u_ep,
....@@ -98,7 +100,7 @@
98100 {
99101 struct ast_vhub *vhub = data;
100102 irqreturn_t iret = IRQ_NONE;
101
- u32 istat;
103
+ u32 i, istat;
102104
103105 /* Stale interrupt while tearing down */
104106 if (!vhub->ep0_bufs)
....@@ -120,10 +122,10 @@
120122
121123 /* Handle generic EPs first */
122124 if (istat & VHUB_IRQ_EP_POOL_ACK_STALL) {
123
- u32 i, ep_acks = readl(vhub->regs + AST_VHUB_EP_ACK_ISR);
125
+ u32 ep_acks = readl(vhub->regs + AST_VHUB_EP_ACK_ISR);
124126 writel(ep_acks, vhub->regs + AST_VHUB_EP_ACK_ISR);
125127
126
- for (i = 0; ep_acks && i < AST_VHUB_NUM_GEN_EPs; i++) {
128
+ for (i = 0; ep_acks && i < vhub->max_epns; i++) {
127129 u32 mask = VHUB_EP_IRQ(i);
128130 if (ep_acks & mask) {
129131 ast_vhub_epn_ack_irq(&vhub->epns[i]);
....@@ -133,21 +135,11 @@
133135 }
134136
135137 /* Handle device interrupts */
136
- if (istat & (VHUB_IRQ_DEVICE1 |
137
- VHUB_IRQ_DEVICE2 |
138
- VHUB_IRQ_DEVICE3 |
139
- VHUB_IRQ_DEVICE4 |
140
- VHUB_IRQ_DEVICE5)) {
141
- if (istat & VHUB_IRQ_DEVICE1)
142
- ast_vhub_dev_irq(&vhub->ports[0].dev);
143
- if (istat & VHUB_IRQ_DEVICE2)
144
- ast_vhub_dev_irq(&vhub->ports[1].dev);
145
- if (istat & VHUB_IRQ_DEVICE3)
146
- ast_vhub_dev_irq(&vhub->ports[2].dev);
147
- if (istat & VHUB_IRQ_DEVICE4)
148
- ast_vhub_dev_irq(&vhub->ports[3].dev);
149
- if (istat & VHUB_IRQ_DEVICE5)
150
- ast_vhub_dev_irq(&vhub->ports[4].dev);
138
+ if (istat & vhub->port_irq_mask) {
139
+ for (i = 0; i < vhub->max_ports; i++) {
140
+ if (istat & VHUB_DEV_IRQ(i))
141
+ ast_vhub_dev_irq(&vhub->ports[i].dev);
142
+ }
151143 }
152144
153145 /* Handle top-level vHub EP0 interrupts */
....@@ -181,7 +173,7 @@
181173
182174 void ast_vhub_init_hw(struct ast_vhub *vhub)
183175 {
184
- u32 ctrl;
176
+ u32 ctrl, port_mask, epn_mask;
185177
186178 UDCDBG(vhub,"(Re)Starting HW ...\n");
187179
....@@ -221,15 +213,20 @@
221213 }
222214
223215 /* Reset all devices */
224
- writel(VHUB_SW_RESET_ALL, vhub->regs + AST_VHUB_SW_RESET);
216
+ port_mask = GENMASK(vhub->max_ports, 1);
217
+ writel(VHUB_SW_RESET_ROOT_HUB |
218
+ VHUB_SW_RESET_DMA_CONTROLLER |
219
+ VHUB_SW_RESET_EP_POOL |
220
+ port_mask, vhub->regs + AST_VHUB_SW_RESET);
225221 udelay(1);
226222 writel(0, vhub->regs + AST_VHUB_SW_RESET);
227223
228224 /* Disable and cleanup EP ACK/NACK interrupts */
225
+ epn_mask = GENMASK(vhub->max_epns - 1, 0);
229226 writel(0, vhub->regs + AST_VHUB_EP_ACK_IER);
230227 writel(0, vhub->regs + AST_VHUB_EP_NACK_IER);
231
- writel(VHUB_EP_IRQ_ALL, vhub->regs + AST_VHUB_EP_ACK_ISR);
232
- writel(VHUB_EP_IRQ_ALL, vhub->regs + AST_VHUB_EP_NACK_ISR);
228
+ writel(epn_mask, vhub->regs + AST_VHUB_EP_ACK_ISR);
229
+ writel(epn_mask, vhub->regs + AST_VHUB_EP_NACK_ISR);
233230
234231 /* Default settings for EP0, enable HW hub EP1 */
235232 writel(0, vhub->regs + AST_VHUB_EP0_CTRL);
....@@ -272,7 +269,7 @@
272269 return 0;
273270
274271 /* Remove devices */
275
- for (i = 0; i < AST_VHUB_NUM_PORTS; i++)
272
+ for (i = 0; i < vhub->max_ports; i++)
276273 ast_vhub_del_dev(&vhub->ports[i].dev);
277274
278275 spin_lock_irqsave(&vhub->lock, flags);
....@@ -294,7 +291,7 @@
294291 if (vhub->ep0_bufs)
295292 dma_free_coherent(&pdev->dev,
296293 AST_VHUB_EP0_MAX_PACKET *
297
- (AST_VHUB_NUM_PORTS + 1),
294
+ (vhub->max_ports + 1),
298295 vhub->ep0_bufs,
299296 vhub->ep0_bufs_dma);
300297 vhub->ep0_bufs = NULL;
....@@ -308,13 +305,36 @@
308305 struct ast_vhub *vhub;
309306 struct resource *res;
310307 int i, rc = 0;
308
+ const struct device_node *np = pdev->dev.of_node;
311309
312310 vhub = devm_kzalloc(&pdev->dev, sizeof(*vhub), GFP_KERNEL);
313311 if (!vhub)
314312 return -ENOMEM;
315313
314
+ rc = of_property_read_u32(np, "aspeed,vhub-downstream-ports",
315
+ &vhub->max_ports);
316
+ if (rc < 0)
317
+ vhub->max_ports = AST_VHUB_NUM_PORTS;
318
+
319
+ vhub->ports = devm_kcalloc(&pdev->dev, vhub->max_ports,
320
+ sizeof(*vhub->ports), GFP_KERNEL);
321
+ if (!vhub->ports)
322
+ return -ENOMEM;
323
+
324
+ rc = of_property_read_u32(np, "aspeed,vhub-generic-endpoints",
325
+ &vhub->max_epns);
326
+ if (rc < 0)
327
+ vhub->max_epns = AST_VHUB_NUM_GEN_EPs;
328
+
329
+ vhub->epns = devm_kcalloc(&pdev->dev, vhub->max_epns,
330
+ sizeof(*vhub->epns), GFP_KERNEL);
331
+ if (!vhub->epns)
332
+ return -ENOMEM;
333
+
316334 spin_lock_init(&vhub->lock);
317335 vhub->pdev = pdev;
336
+ vhub->port_irq_mask = GENMASK(VHUB_IRQ_DEV1_BIT + vhub->max_ports - 1,
337
+ VHUB_IRQ_DEV1_BIT);
318338
319339 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320340 vhub->regs = devm_ioremap_resource(&pdev->dev, res);
....@@ -349,7 +369,6 @@
349369 /* Find interrupt and install handler */
350370 vhub->irq = platform_get_irq(pdev, 0);
351371 if (vhub->irq < 0) {
352
- dev_err(&pdev->dev, "Failed to get interrupt\n");
353372 rc = vhub->irq;
354373 goto err;
355374 }
....@@ -366,7 +385,7 @@
366385 */
367386 vhub->ep0_bufs = dma_alloc_coherent(&pdev->dev,
368387 AST_VHUB_EP0_MAX_PACKET *
369
- (AST_VHUB_NUM_PORTS + 1),
388
+ (vhub->max_ports + 1),
370389 &vhub->ep0_bufs_dma, GFP_KERNEL);
371390 if (!vhub->ep0_bufs) {
372391 dev_err(&pdev->dev, "Failed to allocate EP0 DMA buffers\n");
....@@ -380,13 +399,15 @@
380399 ast_vhub_init_ep0(vhub, &vhub->ep0, NULL);
381400
382401 /* Init devices */
383
- for (i = 0; i < AST_VHUB_NUM_PORTS && rc == 0; i++)
402
+ for (i = 0; i < vhub->max_ports && rc == 0; i++)
384403 rc = ast_vhub_init_dev(vhub, i);
385404 if (rc)
386405 goto err;
387406
388407 /* Init hub emulation */
389
- ast_vhub_init_hub(vhub);
408
+ rc = ast_vhub_init_hub(vhub);
409
+ if (rc)
410
+ goto err;
390411
391412 /* Initialize HW */
392413 ast_vhub_init_hw(vhub);
....@@ -407,6 +428,9 @@
407428 {
408429 .compatible = "aspeed,ast2500-usb-vhub",
409430 },
431
+ {
432
+ .compatible = "aspeed,ast2600-usb-vhub",
433
+ },
410434 { }
411435 };
412436 MODULE_DEVICE_TABLE(of, ast_vhub_dt_ids);