Lines Matching +full:max +full:- +full:speed
1 // SPDX-License-Identifier: GPL-2.0+
3 * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
5 * dev.c - Individual device/gadget management (ie, a port = a gadget)
31 #include <linux/dma-mapping.h>
39 u32 istat = readl(d->regs + AST_VHUB_DEV_ISR); in ast_vhub_dev_irq()
41 writel(istat, d->regs + AST_VHUB_DEV_ISR); in ast_vhub_dev_irq()
44 ast_vhub_ep0_handle_ack(&d->ep0, true); in ast_vhub_dev_irq()
46 ast_vhub_ep0_handle_ack(&d->ep0, false); in ast_vhub_dev_irq()
48 ast_vhub_ep0_handle_setup(&d->ep0); in ast_vhub_dev_irq()
55 if (d->enabled) in ast_vhub_dev_enable()
66 if (d->gadget.speed == USB_SPEED_HIGH) in ast_vhub_dev_enable()
68 writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_enable()
71 hmsk = VHUB_IRQ_DEVICE1 << d->index; in ast_vhub_dev_enable()
72 reg = readl(d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_enable()
74 writel(reg, d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_enable()
77 writel(d->ep0.buf_dma, d->regs + AST_VHUB_DEV_EP0_DATA); in ast_vhub_dev_enable()
80 for (i = 0; i < d->max_epns; i++) { in ast_vhub_dev_enable()
81 struct ast_vhub_ep *ep = d->epns[i]; in ast_vhub_dev_enable()
83 if (ep && (ep->epn.stalled || ep->epn.wedged)) { in ast_vhub_dev_enable()
84 ep->epn.stalled = false; in ast_vhub_dev_enable()
85 ep->epn.wedged = false; in ast_vhub_dev_enable()
91 d->wakeup_en = false; in ast_vhub_dev_enable()
92 d->enabled = true; in ast_vhub_dev_enable()
99 if (!d->enabled) in ast_vhub_dev_disable()
103 hmsk = VHUB_IRQ_DEVICE1 << d->index; in ast_vhub_dev_disable()
104 reg = readl(d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_disable()
106 writel(reg, d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_disable()
109 writel(0, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_disable()
110 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_dev_disable()
111 d->enabled = false; in ast_vhub_dev_disable()
124 d->wakeup_en = is_set; in ast_vhub_dev_feature()
140 if (ep_num >= d->max_epns || !d->epns[ep_num - 1]) in ast_vhub_ep_feature()
145 ep = d->epns[ep_num - 1]; in ast_vhub_ep_feature()
149 if (!ep->epn.enabled || !ep->ep.desc || ep->epn.is_iso || in ast_vhub_ep_feature()
150 ep->epn.is_in != !!(wIndex & USB_DIR_IN)) in ast_vhub_ep_feature()
155 ep->epn.stalled = is_set; in ast_vhub_ep_feature()
168 st0 = d->gadget.is_selfpowered << USB_DEVICE_SELF_POWERED; in ast_vhub_dev_status()
169 if (d->wakeup_en) in ast_vhub_dev_status()
172 return ast_vhub_simple_reply(&d->ep0, st0, 0); in ast_vhub_dev_status()
184 if (ep_num >= d->max_epns) in ast_vhub_ep_status()
187 ep = d->epns[ep_num - 1]; in ast_vhub_ep_status()
190 if (!ep->epn.enabled || !ep->ep.desc || ep->epn.is_iso || in ast_vhub_ep_status()
191 ep->epn.is_in != !!(wIndex & USB_DIR_IN)) in ast_vhub_ep_status()
193 if (ep->epn.stalled) in ast_vhub_ep_status()
197 return ast_vhub_simple_reply(&d->ep0, st0, 0); in ast_vhub_ep_status()
206 reg = readl(d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_set_address()
209 writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_set_address()
215 struct ast_vhub_dev *d = ep->dev; in ast_vhub_std_dev_request()
219 if (!d->driver || !d->enabled) { in ast_vhub_std_dev_request()
222 d->driver, d->enabled); in ast_vhub_std_dev_request()
232 /* First packet, grab speed */ in ast_vhub_std_dev_request()
233 if (d->gadget.speed == USB_SPEED_UNKNOWN) { in ast_vhub_std_dev_request()
234 d->gadget.speed = ep->vhub->speed; in ast_vhub_std_dev_request()
235 if (d->gadget.speed > d->driver->max_speed) in ast_vhub_std_dev_request()
236 d->gadget.speed = d->driver->max_speed; in ast_vhub_std_dev_request()
237 DDBG(d, "fist packet, captured speed %d\n", in ast_vhub_std_dev_request()
238 d->gadget.speed); in ast_vhub_std_dev_request()
241 wValue = le16_to_cpu(crq->wValue); in ast_vhub_std_dev_request()
242 wIndex = le16_to_cpu(crq->wIndex); in ast_vhub_std_dev_request()
244 switch ((crq->bRequestType << 8) | crq->bRequest) { in ast_vhub_std_dev_request()
275 int rc = -EINVAL; in ast_vhub_udc_wakeup()
277 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_wakeup()
278 if (!d->wakeup_en) in ast_vhub_udc_wakeup()
284 ast_vhub_hub_wake_all(d->vhub); in ast_vhub_udc_wakeup()
287 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_wakeup()
295 return (readl(d->vhub->regs + AST_VHUB_USBSTS) >> 16) & 0x7ff; in ast_vhub_udc_get_frame()
302 for (i = 0; i < d->max_epns; i++) { in ast_vhub_dev_nuke()
303 if (!d->epns[i]) in ast_vhub_dev_nuke()
305 ast_vhub_nuke(d->epns[i], -ESHUTDOWN); in ast_vhub_dev_nuke()
314 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_pullup()
319 ast_vhub_device_connect(d->vhub, d->index, on); in ast_vhub_udc_pullup()
325 if (d->enabled) { in ast_vhub_udc_pullup()
330 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_pullup()
341 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_start()
346 d->driver = driver; in ast_vhub_udc_start()
347 d->gadget.is_selfpowered = 1; in ast_vhub_udc_start()
349 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_start()
361 unsigned int max, addr, i; in ast_vhub_udc_match_ep() local
371 list_for_each_entry(u_ep, &gadget->ep_list, ep_list) { in ast_vhub_udc_match_ep()
373 DDBG(d, " -> using existing EP%d\n", in ast_vhub_udc_match_ep()
374 to_ast_ep(u_ep)->d_idx); in ast_vhub_udc_match_ep()
389 /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ in ast_vhub_udc_match_ep()
391 max = 1024; in ast_vhub_udc_match_ep()
393 max = 1023; in ast_vhub_udc_match_ep()
397 max = 512; in ast_vhub_udc_match_ep()
399 max = 64; in ast_vhub_udc_match_ep()
403 max = 1024; in ast_vhub_udc_match_ep()
405 max = 64; in ast_vhub_udc_match_ep()
408 if (usb_endpoint_maxp(desc) > max) in ast_vhub_udc_match_ep()
419 for (i = 0; i < d->max_epns; i++) in ast_vhub_udc_match_ep()
420 if (d->epns[i] == NULL) in ast_vhub_udc_match_ep()
422 if (i >= d->max_epns) in ast_vhub_udc_match_ep()
434 ep->epn.g_idx, addr); in ast_vhub_udc_match_ep()
436 return &ep->ep; in ast_vhub_udc_match_ep()
444 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_stop()
448 d->driver = NULL; in ast_vhub_udc_stop()
449 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_udc_stop()
453 if (d->enabled) in ast_vhub_udc_stop()
456 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_stop()
472 if (d->driver && d->driver->suspend) { in ast_vhub_dev_suspend()
473 spin_unlock(&d->vhub->lock); in ast_vhub_dev_suspend()
474 d->driver->suspend(&d->gadget); in ast_vhub_dev_suspend()
475 spin_lock(&d->vhub->lock); in ast_vhub_dev_suspend()
481 if (d->driver && d->driver->resume) { in ast_vhub_dev_resume()
482 spin_unlock(&d->vhub->lock); in ast_vhub_dev_resume()
483 d->driver->resume(&d->gadget); in ast_vhub_dev_resume()
484 spin_lock(&d->vhub->lock); in ast_vhub_dev_resume()
491 if (!d->driver) { in ast_vhub_dev_reset()
497 if (!d->enabled) { in ast_vhub_dev_reset()
502 spin_unlock(&d->vhub->lock); in ast_vhub_dev_reset()
503 usb_gadget_udc_reset(&d->gadget, d->driver); in ast_vhub_dev_reset()
504 spin_lock(&d->vhub->lock); in ast_vhub_dev_reset()
507 * Disable and maybe re-enable HW, this will clear the address in ast_vhub_dev_reset()
508 * and speed setting. in ast_vhub_dev_reset()
519 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_del_dev()
520 if (!d->registered) { in ast_vhub_del_dev()
521 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_del_dev()
524 d->registered = false; in ast_vhub_del_dev()
525 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_del_dev()
527 usb_del_gadget_udc(&d->gadget); in ast_vhub_del_dev()
528 device_unregister(d->port_dev); in ast_vhub_del_dev()
529 kfree(d->epns); in ast_vhub_del_dev()
539 struct ast_vhub_dev *d = &vhub->ports[idx].dev; in ast_vhub_init_dev()
540 struct device *parent = &vhub->pdev->dev; in ast_vhub_init_dev()
543 d->vhub = vhub; in ast_vhub_init_dev()
544 d->index = idx; in ast_vhub_init_dev()
545 d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx+1); in ast_vhub_init_dev()
546 d->regs = vhub->regs + 0x100 + 0x10 * idx; in ast_vhub_init_dev()
548 ast_vhub_init_ep0(vhub, &d->ep0, d); in ast_vhub_init_dev()
554 d->max_epns = min_t(u32, vhub->max_epns, 30); in ast_vhub_init_dev()
555 d->epns = kcalloc(d->max_epns, sizeof(*d->epns), GFP_KERNEL); in ast_vhub_init_dev()
556 if (!d->epns) in ast_vhub_init_dev()
557 return -ENOMEM; in ast_vhub_init_dev()
564 d->port_dev = kzalloc(sizeof(struct device), GFP_KERNEL); in ast_vhub_init_dev()
565 if (!d->port_dev) { in ast_vhub_init_dev()
566 rc = -ENOMEM; in ast_vhub_init_dev()
569 device_initialize(d->port_dev); in ast_vhub_init_dev()
570 d->port_dev->release = ast_vhub_dev_release; in ast_vhub_init_dev()
571 d->port_dev->parent = parent; in ast_vhub_init_dev()
572 dev_set_name(d->port_dev, "%s:p%d", dev_name(parent), idx + 1); in ast_vhub_init_dev()
573 rc = device_add(d->port_dev); in ast_vhub_init_dev()
578 INIT_LIST_HEAD(&d->gadget.ep_list); in ast_vhub_init_dev()
579 d->gadget.ops = &ast_vhub_udc_ops; in ast_vhub_init_dev()
580 d->gadget.ep0 = &d->ep0.ep; in ast_vhub_init_dev()
581 d->gadget.name = KBUILD_MODNAME; in ast_vhub_init_dev()
582 if (vhub->force_usb1) in ast_vhub_init_dev()
583 d->gadget.max_speed = USB_SPEED_FULL; in ast_vhub_init_dev()
585 d->gadget.max_speed = USB_SPEED_HIGH; in ast_vhub_init_dev()
586 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_init_dev()
587 d->gadget.dev.of_node = vhub->pdev->dev.of_node; in ast_vhub_init_dev()
589 rc = usb_add_gadget_udc(d->port_dev, &d->gadget); in ast_vhub_init_dev()
592 d->registered = true; in ast_vhub_init_dev()
596 device_del(d->port_dev); in ast_vhub_init_dev()
598 put_device(d->port_dev); in ast_vhub_init_dev()
600 kfree(d->epns); in ast_vhub_init_dev()