Lines Matching +full:chg +full:- +full:status
1 // SPDX-License-Identifier: GPL-2.0+
3 * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
5 * hub.c - virtual hub handling
25 #include <linux/dma-mapping.h>
37 * - We may need to indicate TT support
38 * - We may need a device qualifier descriptor
40 * - Make vid/did overridable
41 * - make it look like usb1 if usb1 mode forced
144 * These strings converted to UTF-16 must be smaller than
176 * Mark it as self-powered, I doubt the BMC is powered off in ast_vhub_hub_dev_status()
185 if (ep->vhub->wakeup_en) in ast_vhub_hub_dev_status()
202 if (ep->vhub->ep1_stalled) in ast_vhub_hub_ep_status()
220 ep->vhub->wakeup_en = is_set; in ast_vhub_hub_dev_feature()
227 val = readl(ep->vhub->regs + AST_VHUB_CTRL); in ast_vhub_hub_dev_feature()
230 writel(val, ep->vhub->regs + AST_VHUB_CTRL); in ast_vhub_hub_dev_feature()
259 ep->vhub->ep1_stalled = is_set; in ast_vhub_hub_ep_feature()
260 reg = readl(ep->vhub->regs + AST_VHUB_EP1_CTRL); in ast_vhub_hub_ep_feature()
267 writel(reg, ep->vhub->regs + AST_VHUB_EP1_CTRL); in ast_vhub_hub_ep_feature()
276 struct ast_vhub *vhub = ep->vhub; in ast_vhub_rep_desc()
282 * we can do some in-place patching if needed. We know in ast_vhub_rep_desc()
292 memcpy(ep->buf, &vhub->vhub_dev_desc, dsize); in ast_vhub_rep_desc()
293 BUILD_BUG_ON(dsize > sizeof(vhub->vhub_dev_desc)); in ast_vhub_rep_desc()
299 memcpy(ep->buf, &vhub->vhub_conf_desc, dsize); in ast_vhub_rep_desc()
300 ((u8 *)ep->buf)[1] = desc_type; in ast_vhub_rep_desc()
301 BUILD_BUG_ON(dsize > sizeof(vhub->vhub_conf_desc)); in ast_vhub_rep_desc()
306 memcpy(ep->buf, &vhub->vhub_hub_desc, dsize); in ast_vhub_rep_desc()
307 BUILD_BUG_ON(dsize > sizeof(vhub->vhub_hub_desc)); in ast_vhub_rep_desc()
311 dsize = sizeof(vhub->vhub_qual_desc); in ast_vhub_rep_desc()
312 memcpy(ep->buf, &vhub->vhub_qual_desc, dsize); in ast_vhub_rep_desc()
329 return (struct usb_gadget_strings *)container->stash; in ast_vhub_str_of_container()
342 max_langs = (size - hdr_len) / sizeof(sdesc->wData[0]); in ast_vhub_collect_languages()
343 list_for_each_entry(container, &vhub->vhub_str_desc, list) { in ast_vhub_collect_languages()
348 sdesc->wData[nlangs++] = cpu_to_le16(lang_str->language); in ast_vhub_collect_languages()
351 rc = hdr_len + nlangs * sizeof(sdesc->wData[0]); in ast_vhub_collect_languages()
352 sdesc->bLength = rc; in ast_vhub_collect_languages()
353 sdesc->bDescriptorType = USB_DT_STRING; in ast_vhub_collect_languages()
364 list_for_each_entry(container, &vhub->vhub_str_desc, list) { in ast_vhub_lookup_string()
366 if (lang_str->language == lang_id) in ast_vhub_lookup_string()
379 struct ast_vhub *vhub = ep->vhub; in ast_vhub_rep_string()
396 memcpy(ep->buf, buf, rc); in ast_vhub_rep_string()
403 struct ast_vhub *vhub = ep->vhub; in ast_vhub_std_hub_request()
406 wValue = le16_to_cpu(crq->wValue); in ast_vhub_std_hub_request()
407 wIndex = le16_to_cpu(crq->wIndex); in ast_vhub_std_hub_request()
408 wLength = le16_to_cpu(crq->wLength); in ast_vhub_std_hub_request()
411 if (vhub->speed == USB_SPEED_UNKNOWN) { in ast_vhub_std_hub_request()
412 u32 ustat = readl(vhub->regs + AST_VHUB_USBSTS); in ast_vhub_std_hub_request()
414 vhub->speed = USB_SPEED_HIGH; in ast_vhub_std_hub_request()
416 vhub->speed = USB_SPEED_FULL; in ast_vhub_std_hub_request()
417 UDCDBG(vhub, "USB status=%08x speed=%s\n", ustat, in ast_vhub_std_hub_request()
418 vhub->speed == USB_SPEED_HIGH ? "high" : "full"); in ast_vhub_std_hub_request()
421 switch ((crq->bRequestType << 8) | crq->bRequest) { in ast_vhub_std_hub_request()
425 writel(wValue, vhub->regs + AST_VHUB_CONF); in ast_vhub_std_hub_request()
484 u32 reg = readl(vhub->regs + AST_VHUB_EP1_STS_CHG); in ast_vhub_update_hub_ep1()
486 if (vhub->ports[port].change) in ast_vhub_update_hub_ep1()
490 writel(reg, vhub->regs + AST_VHUB_EP1_STS_CHG); in ast_vhub_update_hub_ep1()
499 struct ast_vhub_port *p = &vhub->ports[port]; in ast_vhub_change_port_stat()
502 /* Update port status */ in ast_vhub_change_port_stat()
503 prev = p->status; in ast_vhub_change_port_stat()
504 p->status = (prev & ~clr_flags) | set_flags; in ast_vhub_change_port_stat()
505 DDBG(&p->dev, "port %d status %04x -> %04x (C=%d)\n", in ast_vhub_change_port_stat()
506 port + 1, prev, p->status, set_c); in ast_vhub_change_port_stat()
510 u16 chg = p->status ^ prev; in ast_vhub_change_port_stat() local
513 chg &= USB_PORT_STAT_C_CONNECTION | in ast_vhub_change_port_stat()
524 if (p->status & USB_PORT_STAT_ENABLE) in ast_vhub_change_port_stat()
525 chg &= ~USB_PORT_STAT_C_ENABLE; in ast_vhub_change_port_stat()
527 p->change = chg; in ast_vhub_change_port_stat()
534 u32 reg = readl(vhub->regs + AST_VHUB_CTRL); in ast_vhub_send_host_wakeup()
537 writel(reg, vhub->regs + AST_VHUB_CTRL); in ast_vhub_send_host_wakeup()
556 if (vhub->wakeup_en) in ast_vhub_device_connect()
573 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_wake_work()
574 for (i = 0; i < vhub->max_ports; i++) { in ast_vhub_wake_work()
575 struct ast_vhub_port *p = &vhub->ports[i]; in ast_vhub_wake_work()
577 if (!(p->status & USB_PORT_STAT_SUSPEND)) in ast_vhub_wake_work()
582 ast_vhub_dev_resume(&p->dev); in ast_vhub_wake_work()
585 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_wake_work()
595 schedule_work(&vhub->wake_work); in ast_vhub_hub_wake_all()
600 struct ast_vhub_port *p = &vhub->ports[port]; in ast_vhub_port_reset()
610 if (!p->dev.driver) in ast_vhub_port_reset()
617 ast_vhub_dev_reset(&p->dev); in ast_vhub_port_reset()
620 speed = p->dev.driver->max_speed; in ast_vhub_port_reset()
621 if (speed == USB_SPEED_UNKNOWN || speed > vhub->speed) in ast_vhub_port_reset()
622 speed = vhub->speed; in ast_vhub_port_reset()
654 struct ast_vhub *vhub = ep->vhub; in ast_vhub_set_port_feature()
657 if (port == 0 || port > vhub->max_ports) in ast_vhub_set_port_feature()
659 port--; in ast_vhub_set_port_feature()
660 p = &vhub->ports[port]; in ast_vhub_set_port_feature()
664 if (!(p->status & USB_PORT_STAT_ENABLE)) in ast_vhub_set_port_feature()
669 ast_vhub_dev_suspend(&p->dev); in ast_vhub_set_port_feature()
677 * On Power-on, we mark the connected flag changed, in ast_vhub_set_port_feature()
681 if (p->status & USB_PORT_STAT_CONNECTION) { in ast_vhub_set_port_feature()
682 p->change |= USB_PORT_STAT_C_CONNECTION; in ast_vhub_set_port_feature()
697 struct ast_vhub *vhub = ep->vhub; in ast_vhub_clr_port_feature()
700 if (port == 0 || port > vhub->max_ports) in ast_vhub_clr_port_feature()
702 port--; in ast_vhub_clr_port_feature()
703 p = &vhub->ports[port]; in ast_vhub_clr_port_feature()
711 ast_vhub_dev_suspend(&p->dev); in ast_vhub_clr_port_feature()
714 if (!(p->status & USB_PORT_STAT_SUSPEND)) in ast_vhub_clr_port_feature()
719 ast_vhub_dev_resume(&p->dev); in ast_vhub_clr_port_feature()
732 /* Clear state-change feature */ in ast_vhub_clr_port_feature()
733 p->change &= ~(1u << (feat - 16)); in ast_vhub_clr_port_feature()
743 struct ast_vhub *vhub = ep->vhub; in ast_vhub_get_port_stat()
744 u16 stat, chg; in ast_vhub_get_port_stat() local
746 if (port == 0 || port > vhub->max_ports) in ast_vhub_get_port_stat()
748 port--; in ast_vhub_get_port_stat()
750 stat = vhub->ports[port].status; in ast_vhub_get_port_stat()
751 chg = vhub->ports[port].change; in ast_vhub_get_port_stat()
756 EPDBG(ep, " port status=%04x change=%04x\n", stat, chg); in ast_vhub_get_port_stat()
761 chg & 0xff, in ast_vhub_get_port_stat()
762 chg >> 8); in ast_vhub_get_port_stat()
770 wValue = le16_to_cpu(crq->wValue); in ast_vhub_class_hub_request()
771 wIndex = le16_to_cpu(crq->wIndex); in ast_vhub_class_hub_request()
772 wLength = le16_to_cpu(crq->wLength); in ast_vhub_class_hub_request()
774 switch ((crq->bRequestType << 8) | crq->bRequest) { in ast_vhub_class_hub_request()
818 if (vhub->suspended) in ast_vhub_hub_suspend()
821 vhub->suspended = true; in ast_vhub_hub_suspend()
825 * their connection status. in ast_vhub_hub_suspend()
827 for (i = 0; i < vhub->max_ports; i++) { in ast_vhub_hub_suspend()
828 struct ast_vhub_port *p = &vhub->ports[i]; in ast_vhub_hub_suspend()
830 if (!(p->status & USB_PORT_STAT_SUSPEND)) in ast_vhub_hub_suspend()
831 ast_vhub_dev_suspend(&p->dev); in ast_vhub_hub_suspend()
841 if (!vhub->suspended) in ast_vhub_hub_resume()
844 vhub->suspended = false; in ast_vhub_hub_resume()
848 * their connection status. in ast_vhub_hub_resume()
850 for (i = 0; i < vhub->max_ports; i++) { in ast_vhub_hub_resume()
851 struct ast_vhub_port *p = &vhub->ports[i]; in ast_vhub_hub_resume()
853 if (!(p->status & USB_PORT_STAT_SUSPEND)) in ast_vhub_hub_resume()
854 ast_vhub_dev_resume(&p->dev); in ast_vhub_hub_resume()
868 if (vhub->speed == USB_SPEED_UNKNOWN) in ast_vhub_hub_reset()
872 vhub->suspended = false; in ast_vhub_hub_reset()
875 vhub->speed = USB_SPEED_UNKNOWN; in ast_vhub_hub_reset()
878 vhub->wakeup_en = false; in ast_vhub_hub_reset()
881 * Clear all port status, disable gadgets and "suspend" in ast_vhub_hub_reset()
884 for (i = 0; i < vhub->max_ports; i++) { in ast_vhub_hub_reset()
885 struct ast_vhub_port *p = &vhub->ports[i]; in ast_vhub_hub_reset()
888 p->status &= USB_PORT_STAT_CONNECTION; in ast_vhub_hub_reset()
889 p->change = 0; in ast_vhub_hub_reset()
892 ast_vhub_dev_suspend(&p->dev); in ast_vhub_hub_reset()
896 writel(0, vhub->regs + AST_VHUB_CONF); in ast_vhub_hub_reset()
897 writel(0, vhub->regs + AST_VHUB_EP0_CTRL); in ast_vhub_hub_reset()
900 vhub->regs + AST_VHUB_EP1_CTRL); in ast_vhub_hub_reset()
901 writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG); in ast_vhub_hub_reset()
910 if (!of_property_read_u32(vhub_np, "vhub-vendor-id", &data)) { in ast_vhub_of_parse_dev_desc()
912 vhub->vhub_dev_desc.idVendor = cpu_to_le16(id); in ast_vhub_of_parse_dev_desc()
914 if (!of_property_read_u32(vhub_np, "vhub-product-id", &data)) { in ast_vhub_of_parse_dev_desc()
916 vhub->vhub_dev_desc.idProduct = cpu_to_le16(id); in ast_vhub_of_parse_dev_desc()
918 if (!of_property_read_u32(vhub_np, "vhub-device-revision", &data)) { in ast_vhub_of_parse_dev_desc()
920 vhub->vhub_dev_desc.bcdDevice = cpu_to_le16(id); in ast_vhub_of_parse_dev_desc()
926 vhub->vhub_dev_desc.bcdUSB = cpu_to_le16(0x0100); in ast_vhub_fixup_usb1_dev_desc()
927 vhub->vhub_dev_desc.bDeviceProtocol = 0; in ast_vhub_fixup_usb1_dev_desc()
941 container = devm_kzalloc(&vhub->pdev->dev, size, GFP_KERNEL); in ast_vhub_str_container_alloc()
943 return ERR_PTR(-ENOMEM); in ast_vhub_str_container_alloc()
947 lang_str->strings = str_array; in ast_vhub_str_container_alloc()
954 struct usb_string *src_array = src->strings; in ast_vhub_str_deep_copy()
955 struct usb_string *dest_array = dest->strings; in ast_vhub_str_deep_copy()
957 dest->language = src->language; in ast_vhub_str_deep_copy()
963 } while (src_array->s); in ast_vhub_str_deep_copy()
979 list_add_tail(&container->list, &vhub->vhub_str_desc); in ast_vhub_str_alloc_add()
990 {"serial-number", AST_VHUB_STR_SERIAL},
1040 const struct device_node *vhub_np = vhub->pdev->dev.of_node; in ast_vhub_init_desc()
1043 memcpy(&vhub->vhub_dev_desc, &ast_vhub_dev_desc, in ast_vhub_init_desc()
1044 sizeof(vhub->vhub_dev_desc)); in ast_vhub_init_desc()
1046 if (vhub->force_usb1) in ast_vhub_init_desc()
1050 memcpy(&vhub->vhub_conf_desc, &ast_vhub_conf_desc, in ast_vhub_init_desc()
1051 sizeof(vhub->vhub_conf_desc)); in ast_vhub_init_desc()
1054 memcpy(&vhub->vhub_hub_desc, &ast_vhub_hub_desc, in ast_vhub_init_desc()
1055 sizeof(vhub->vhub_hub_desc)); in ast_vhub_init_desc()
1056 vhub->vhub_hub_desc.bNbrPorts = vhub->max_ports; in ast_vhub_init_desc()
1059 INIT_LIST_HEAD(&vhub->vhub_str_desc); in ast_vhub_init_desc()
1060 desc_np = of_get_child_by_name(vhub_np, "vhub-strings"); in ast_vhub_init_desc()
1069 memcpy(&vhub->vhub_qual_desc, &ast_vhub_qual_desc, in ast_vhub_init_desc()
1070 sizeof(vhub->vhub_qual_desc)); in ast_vhub_init_desc()
1077 vhub->speed = USB_SPEED_UNKNOWN; in ast_vhub_init_hub()
1078 INIT_WORK(&vhub->wake_work, ast_vhub_wake_work); in ast_vhub_init_hub()