Lines Matching +full:companion +full:- +full:hub

1 // SPDX-License-Identifier: GPL-2.0+
14 #include <dm/device-internal.h>
16 #include <dm/uclass-internal.h>
36 struct udevice *bus = udev->controller_dev; in submit_int_msg()
39 if (!ops->interrupt) in submit_int_msg()
40 return -ENOSYS; in submit_int_msg()
42 return ops->interrupt(bus, udev, pipe, buffer, length, interval); in submit_int_msg()
48 struct udevice *bus = udev->controller_dev; in submit_control_msg()
50 struct usb_uclass_priv *uc_priv = bus->uclass->priv; in submit_control_msg()
53 if (!ops->control) in submit_control_msg()
54 return -ENOSYS; in submit_control_msg()
56 err = ops->control(bus, udev, pipe, buffer, length, setup); in submit_control_msg()
57 if (setup->request == USB_REQ_SET_FEATURE && in submit_control_msg()
58 setup->requesttype == USB_RT_PORT && in submit_control_msg()
59 setup->value == cpu_to_le16(USB_PORT_FEAT_RESET) && in submit_control_msg()
60 err == -ENXIO) { in submit_control_msg()
61 /* Device handed over to companion after port reset */ in submit_control_msg()
62 uc_priv->companion_device_count++; in submit_control_msg()
71 struct udevice *bus = udev->controller_dev; in submit_bulk_msg()
74 if (!ops->bulk) in submit_bulk_msg()
75 return -ENOSYS; in submit_bulk_msg()
77 return ops->bulk(bus, udev, pipe, buffer, length); in submit_bulk_msg()
84 struct udevice *bus = udev->controller_dev; in create_int_queue()
87 if (!ops->create_int_queue) in create_int_queue()
90 return ops->create_int_queue(bus, udev, pipe, queuesize, elementsize, in create_int_queue()
96 struct udevice *bus = udev->controller_dev; in poll_int_queue()
99 if (!ops->poll_int_queue) in poll_int_queue()
102 return ops->poll_int_queue(bus, udev, queue); in poll_int_queue()
107 struct udevice *bus = udev->controller_dev; in destroy_int_queue()
110 if (!ops->destroy_int_queue) in destroy_int_queue()
111 return -ENOSYS; in destroy_int_queue()
113 return ops->destroy_int_queue(bus, udev, queue); in destroy_int_queue()
118 struct udevice *bus = udev->controller_dev; in usb_alloc_device()
121 /* This is only requird by some controllers - current XHCI */ in usb_alloc_device()
122 if (!ops->alloc_device) in usb_alloc_device()
125 return ops->alloc_device(bus, udev); in usb_alloc_device()
130 struct udevice *bus = udev->controller_dev; in usb_reset_root_port()
133 if (!ops->reset_root_port) in usb_reset_root_port()
134 return -ENOSYS; in usb_reset_root_port()
136 return ops->reset_root_port(bus, udev); in usb_reset_root_port()
141 struct udevice *bus = udev->controller_dev; in usb_update_hub_device()
144 if (!ops->update_hub_device) in usb_update_hub_device()
145 return -ENOSYS; in usb_update_hub_device()
147 return ops->update_hub_device(bus, udev); in usb_update_hub_device()
152 struct udevice *bus = udev->controller_dev; in usb_get_max_xfer_size()
155 if (!ops->get_max_xfer_size) in usb_get_max_xfer_size()
156 return -ENOSYS; in usb_get_max_xfer_size()
158 return ops->get_max_xfer_size(bus, size); in usb_get_max_xfer_size()
169 /* De-activate any devices that have been activated */ in usb_stop()
174 uc_priv = uc->priv; in usb_stop()
181 /* Locate root hub device */ in usb_stop()
185 * All USB devices are children of root hub. in usb_stop()
186 * Unbinding root hub will unbind all of its children. in usb_stop()
197 uc_priv->companion_device_count = 0; in usb_stop()
211 assert(recurse); /* TODO: Support non-recusive */ in usb_scan_bus()
213 printf("scanning bus %d for devices... ", bus->seq); in usb_scan_bus()
218 else if (priv->next_addr == 0) in usb_scan_bus()
221 printf("%d USB Device(s) found\n", priv->next_addr); in usb_scan_bus()
254 uc_priv = uc->priv; in usb_init()
264 * start the USB stack, in order to re-create the emulated USB in usb_init()
276 if (ret == -ENODEV) { /* No such device. */ in usb_init()
299 if (!priv->companion) in usb_init()
308 if (uc_priv->companion_device_count) { in usb_init()
314 if (priv->companion) in usb_init()
335 return usb_started ? 0 : -1; in usb_init()
354 if (udev->devnum == devnum) in find_child_devnum()
396 plat->init_type = USB_INIT_DEVICE; in usb_setup_ehci_gadget()
409 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && in usb_match_device()
410 id->idVendor != le16_to_cpu(desc->idVendor)) in usb_match_device()
413 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && in usb_match_device()
414 id->idProduct != le16_to_cpu(desc->idProduct)) in usb_match_device()
417 /* No need to test id->bcdDevice_lo != 0, since 0 is never in usb_match_device()
419 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && in usb_match_device()
420 (id->bcdDevice_lo > le16_to_cpu(desc->bcdDevice))) in usb_match_device()
423 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && in usb_match_device()
424 (id->bcdDevice_hi < le16_to_cpu(desc->bcdDevice))) in usb_match_device()
427 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && in usb_match_device()
428 (id->bDeviceClass != desc->bDeviceClass)) in usb_match_device()
431 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && in usb_match_device()
432 (id->bDeviceSubClass != desc->bDeviceSubClass)) in usb_match_device()
435 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && in usb_match_device()
436 (id->bDeviceProtocol != desc->bDeviceProtocol)) in usb_match_device()
450 if (desc->bDeviceClass == USB_CLASS_VENDOR_SPEC && in usb_match_one_id_intf()
451 !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && in usb_match_one_id_intf()
452 (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS | in usb_match_one_id_intf()
458 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && in usb_match_one_id_intf()
459 (id->bInterfaceClass != int_desc->bInterfaceClass)) in usb_match_one_id_intf()
462 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && in usb_match_one_id_intf()
463 (id->bInterfaceSubClass != int_desc->bInterfaceSubClass)) in usb_match_one_id_intf()
466 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && in usb_match_one_id_intf()
467 (id->bInterfaceProtocol != int_desc->bInterfaceProtocol)) in usb_match_one_id_intf()
470 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER) && in usb_match_one_id_intf()
471 (id->bInterfaceNumber != int_desc->bInterfaceNumber)) in usb_match_one_id_intf()
489 * usb_find_and_bind_driver() - Find and bind the right USB driver
514 for (id = entry->match; id->match_flags; id++) { in usb_find_and_bind_driver()
518 drv = entry->driver; in usb_find_and_bind_driver()
522 * method to return -ENOENT if it doesn't support this in usb_find_and_bind_driver()
527 ret = device_bind(parent, drv, drv->name, NULL, -1, in usb_find_and_bind_driver()
531 debug("%s: Match found: %s\n", __func__, drv->name); in usb_find_and_bind_driver()
532 dev->driver_data = id->driver_info; in usb_find_and_bind_driver()
534 plat->id = *id; in usb_find_and_bind_driver()
544 return -ENOMEM; in usb_find_and_bind_driver()
553 * usb_find_child() - Find an existing device which matches our needs
574 dev->name, plat->id.bDeviceClass, desc->bDeviceClass); in usb_find_child()
575 if (usb_match_one_id(desc, iface, &plat->id)) { in usb_find_child()
581 return -ENOENT; in usb_find_child()
594 struct usb_interface_descriptor *iface = &udev->config.if_desc[0].desc; in usb_scan_device()
598 udev->controller_dev = usb_get_bus(parent); in usb_scan_device()
599 priv = dev_get_uclass_priv(udev->controller_dev); in usb_scan_device()
606 * udev->dev is set to the parent, since we don't have a real device in usb_scan_device()
629 udev->dev = parent; in usb_scan_device()
630 udev->speed = speed; in usb_scan_device()
631 udev->devnum = priv->next_addr + 1; in usb_scan_device()
632 udev->portnr = port; in usb_scan_device()
633 debug("Calling usb_setup_device(), portnr=%d\n", udev->portnr); in usb_scan_device()
636 ret = usb_setup_device(udev, priv->desc_before_addr, parent_udev); in usb_scan_device()
637 debug("read_descriptor for '%s': ret=%d\n", parent->name, ret); in usb_scan_device()
640 ret = usb_find_child(parent, &udev->descriptor, iface, &dev); in usb_scan_device()
643 if (ret != -ENOENT) in usb_scan_device()
645 ret = usb_find_and_bind_driver(parent, &udev->descriptor, iface, in usb_scan_device()
646 udev->controller_dev->seq, in usb_scan_device()
647 udev->devnum, &dev); in usb_scan_device()
653 debug("%s: Probing '%s', plat=%p\n", __func__, dev->name, plat); in usb_scan_device()
654 plat->devnum = udev->devnum; in usb_scan_device()
655 plat->udev = udev; in usb_scan_device()
656 priv->next_addr++; in usb_scan_device()
659 debug("%s: Device '%s' probe failed\n", __func__, dev->name); in usb_scan_device()
660 priv->next_addr--; in usb_scan_device()
675 struct udevice *hub; in usb_detect_change() local
684 uclass_foreach_dev(hub, uc) { in usb_detect_change()
688 if (!device_active(hub)) in usb_detect_change()
690 for (device_find_first_child(hub, &dev); in usb_detect_change()
699 if (usb_get_port_status(udev, udev->portnr, &status) in usb_detect_change()
722 val = dev_read_u32_default(dev, "usb,device-class", -1); in usb_child_post_bind()
723 if (val != -1) { in usb_child_post_bind()
724 plat->id.match_flags |= USB_DEVICE_ID_MATCH_DEV_CLASS; in usb_child_post_bind()
725 plat->id.bDeviceClass = val; in usb_child_post_bind()
727 val = dev_read_u32_default(dev, "usb,interface-class", -1); in usb_child_post_bind()
728 if (val != -1) { in usb_child_post_bind()
729 plat->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS; in usb_child_post_bind()
730 plat->id.bInterfaceClass = val; in usb_child_post_bind()
741 bus = bus->parent; in usb_get_bus()
745 debug("USB HUB '%s' does not have a controller\n", dev->name); in usb_get_bus()
757 if (plat->udev) { in usb_child_pre_probe()
763 *udev = *(plat->udev); in usb_child_pre_probe()
764 /* And clear plat->udev as it will not be valid for long */ in usb_child_pre_probe()
765 plat->udev = NULL; in usb_child_pre_probe()
766 udev->dev = dev; in usb_child_pre_probe()
773 udev->dev = dev; in usb_child_pre_probe()
774 udev->controller_dev = usb_get_bus(dev); in usb_child_pre_probe()
775 udev->devnum = plat->devnum; in usb_child_pre_probe()