Lines Matching full:vhub

3  * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
31 #include "vhub.h"
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() local
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()
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()
332 static int ast_vhub_collect_languages(struct ast_vhub *vhub, void *buf, in ast_vhub_collect_languages() argument
343 list_for_each_entry(container, &vhub->vhub_str_desc, list) { in ast_vhub_collect_languages()
358 static struct usb_gadget_strings *ast_vhub_lookup_string(struct ast_vhub *vhub, in ast_vhub_lookup_string() argument
364 list_for_each_entry(container, &vhub->vhub_str_desc, list) { in ast_vhub_lookup_string()
379 struct ast_vhub *vhub = ep->vhub; in ast_vhub_rep_string() local
383 rc = ast_vhub_collect_languages(vhub, buf, sizeof(buf)); in ast_vhub_rep_string()
385 lang_str = ast_vhub_lookup_string(vhub, lang_id); in ast_vhub_rep_string()
403 struct ast_vhub *vhub = ep->vhub; in ast_vhub_std_hub_request() local
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()
425 writel(wValue, vhub->regs + AST_VHUB_CONF); in ast_vhub_std_hub_request()
480 static void ast_vhub_update_hub_ep1(struct ast_vhub *vhub, in ast_vhub_update_hub_ep1() argument
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()
493 static void ast_vhub_change_port_stat(struct ast_vhub *vhub, in ast_vhub_change_port_stat() argument
499 struct ast_vhub_port *p = &vhub->ports[port]; in ast_vhub_change_port_stat()
528 ast_vhub_update_hub_ep1(vhub, port); in ast_vhub_change_port_stat()
532 static void ast_vhub_send_host_wakeup(struct ast_vhub *vhub) in ast_vhub_send_host_wakeup() argument
534 u32 reg = readl(vhub->regs + AST_VHUB_CTRL); in ast_vhub_send_host_wakeup()
535 UDCDBG(vhub, "Waking up host !\n"); in ast_vhub_send_host_wakeup()
537 writel(reg, vhub->regs + AST_VHUB_CTRL); in ast_vhub_send_host_wakeup()
540 void ast_vhub_device_connect(struct ast_vhub *vhub, in ast_vhub_device_connect() argument
544 ast_vhub_change_port_stat(vhub, port, 0, in ast_vhub_device_connect()
547 ast_vhub_change_port_stat(vhub, port, in ast_vhub_device_connect()
556 if (vhub->wakeup_en) in ast_vhub_device_connect()
557 ast_vhub_send_host_wakeup(vhub); in ast_vhub_device_connect()
562 struct ast_vhub *vhub = container_of(work, in ast_vhub_wake_work() local
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()
579 ast_vhub_change_port_stat(vhub, i, in ast_vhub_wake_work()
584 ast_vhub_send_host_wakeup(vhub); in ast_vhub_wake_work()
585 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_wake_work()
588 void ast_vhub_hub_wake_all(struct ast_vhub *vhub) in ast_vhub_hub_wake_all() argument
595 schedule_work(&vhub->wake_work); in ast_vhub_hub_wake_all()
598 static void ast_vhub_port_reset(struct ast_vhub *vhub, u8 port) in ast_vhub_port_reset() argument
600 struct ast_vhub_port *p = &vhub->ports[port]; in ast_vhub_port_reset()
604 ast_vhub_change_port_stat(vhub, port, 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()
639 UDCDBG(vhub, "Unsupported speed %d when" in ast_vhub_port_reset()
648 ast_vhub_change_port_stat(vhub, port, clr, set, true); in ast_vhub_port_reset()
654 struct ast_vhub *vhub = ep->vhub; in ast_vhub_set_port_feature() local
657 if (port == 0 || port > vhub->max_ports) in ast_vhub_set_port_feature()
660 p = &vhub->ports[port]; in ast_vhub_set_port_feature()
666 ast_vhub_change_port_stat(vhub, port, in ast_vhub_set_port_feature()
673 ast_vhub_port_reset(vhub, port); in ast_vhub_set_port_feature()
683 ast_vhub_update_hub_ep1(vhub, port); in ast_vhub_set_port_feature()
697 struct ast_vhub *vhub = ep->vhub; in ast_vhub_clr_port_feature() local
700 if (port == 0 || port > vhub->max_ports) in ast_vhub_clr_port_feature()
703 p = &vhub->ports[port]; in ast_vhub_clr_port_feature()
707 ast_vhub_change_port_stat(vhub, port, in ast_vhub_clr_port_feature()
716 ast_vhub_change_port_stat(vhub, port, in ast_vhub_clr_port_feature()
734 ast_vhub_update_hub_ep1(vhub, port); in ast_vhub_clr_port_feature()
743 struct ast_vhub *vhub = ep->vhub; in ast_vhub_get_port_stat() local
746 if (port == 0 || port > vhub->max_ports) 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()
812 void ast_vhub_hub_suspend(struct ast_vhub *vhub) in ast_vhub_hub_suspend() argument
816 UDCDBG(vhub, "USB bus suspend\n"); in ast_vhub_hub_suspend()
818 if (vhub->suspended) in ast_vhub_hub_suspend()
821 vhub->suspended = true; 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()
835 void ast_vhub_hub_resume(struct ast_vhub *vhub) in ast_vhub_hub_resume() argument
839 UDCDBG(vhub, "USB bus resume\n"); in ast_vhub_hub_resume()
841 if (!vhub->suspended) in ast_vhub_hub_resume()
844 vhub->suspended = false; 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()
858 void ast_vhub_hub_reset(struct ast_vhub *vhub) in ast_vhub_hub_reset() argument
862 UDCDBG(vhub, "USB bus reset\n"); in ast_vhub_hub_reset()
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()
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()
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()
904 static void ast_vhub_of_parse_dev_desc(struct ast_vhub *vhub, in ast_vhub_of_parse_dev_desc() argument
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()
924 static void ast_vhub_fixup_usb1_dev_desc(struct ast_vhub *vhub) in ast_vhub_fixup_usb1_dev_desc() argument
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()
931 ast_vhub_str_container_alloc(struct ast_vhub *vhub) in ast_vhub_str_container_alloc() argument
941 container = devm_kzalloc(&vhub->pdev->dev, size, GFP_KERNEL); in ast_vhub_str_container_alloc()
967 static int ast_vhub_str_alloc_add(struct ast_vhub *vhub, in ast_vhub_str_alloc_add() argument
973 container = ast_vhub_str_container_alloc(vhub); in ast_vhub_str_alloc_add()
979 list_add_tail(&container->list, &vhub->vhub_str_desc); in ast_vhub_str_alloc_add()
994 static int ast_vhub_of_parse_str_desc(struct ast_vhub *vhub, in ast_vhub_of_parse_str_desc() argument
1026 ret = ast_vhub_str_alloc_add(vhub, &lang_str); in ast_vhub_of_parse_str_desc()
1036 static int ast_vhub_init_desc(struct ast_vhub *vhub) in ast_vhub_init_desc() argument
1040 const struct device_node *vhub_np = vhub->pdev->dev.of_node; in ast_vhub_init_desc()
1042 /* Initialize vhub Device Descriptor. */ 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()
1045 ast_vhub_of_parse_dev_desc(vhub, vhub_np); in ast_vhub_init_desc()
1046 if (vhub->force_usb1) in ast_vhub_init_desc()
1047 ast_vhub_fixup_usb1_dev_desc(vhub); in ast_vhub_init_desc()
1049 /* Initialize vhub Configuration Descriptor. */ 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()
1053 /* Initialize vhub Hub Descriptor. */ 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()
1058 /* Initialize vhub String Descriptors. */ 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()
1062 ret = ast_vhub_of_parse_str_desc(vhub, desc_np); in ast_vhub_init_desc()
1066 ret = ast_vhub_str_alloc_add(vhub, &ast_vhub_strings); in ast_vhub_init_desc()
1068 /* Initialize vhub Qualifier Descriptor. */ 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()
1075 int ast_vhub_init_hub(struct ast_vhub *vhub) in ast_vhub_init_hub() argument
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()
1080 return ast_vhub_init_desc(vhub); in ast_vhub_init_hub()