Commit af9c7c11e97ce99a8b8a0de99f91bde1b703377e

Authored by Simon Glass
1 parent 80438a6c71

sandbox: usb: Allow finding a USB emulator for a device

Each USB device has an emulator. Currently this can only be found by
supplying the 'pipe' value, which contains the device number. Add a way
to find it directly from the emulated device.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 25 additions and 2 deletions Side-by-side Diff

drivers/usb/emul/usb-emul-uclass.c
... ... @@ -108,9 +108,8 @@
108 108 return upto ? upto : length ? -EIO : 0;
109 109 }
110 110  
111   -int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp)
  111 +static int usb_emul_find_devnum(int devnum, struct udevice **emulp)
112 112 {
113   - int devnum = usb_pipedevice(pipe);
114 113 struct udevice *dev;
115 114 struct uclass *uc;
116 115 int ret;
... ... @@ -132,6 +131,20 @@
132 131  
133 132 debug("%s: No emulator found, addr %d\n", __func__, devnum);
134 133 return -ENOENT;
  134 +}
  135 +
  136 +int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp)
  137 +{
  138 + int devnum = usb_pipedevice(pipe);
  139 +
  140 + return usb_emul_find_devnum(devnum, emulp);
  141 +}
  142 +
  143 +int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp)
  144 +{
  145 + struct usb_dev_platdata *udev = dev_get_parent_platdata(dev);
  146 +
  147 + return usb_emul_find_devnum(udev->devnum, emulp);
135 148 }
136 149  
137 150 int usb_emul_control(struct udevice *emul, struct usb_device *udev,
... ... @@ -950,6 +950,16 @@
950 950 int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp);
951 951  
952 952 /**
  953 + * usb_emul_find_for_dev() - Find an emulator for a particular device
  954 + *
  955 + * @bus: USB bus (controller)
  956 + * @dev: USB device to check
  957 + * @emulp: Returns pointer to emulator, or NULL if not found
  958 + * @return 0 if found, -ve on error
  959 + */
  960 +int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp);
  961 +
  962 +/**
953 963 * usb_emul_reset() - Reset all emulators ready for use
954 964 *
955 965 * Clear out any address information in the emulators and make then ready for