From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Sun, 8 Nov 2015 23:47:55 -0700 Subject: [U-Boot] [PATCH v2 13/26] sandbox: usb: Allow finding a USB emulator for a device In-Reply-To: <1447051688-24936-1-git-send-email-sjg@chromium.org> References: <1447051688-24936-1-git-send-email-sjg@chromium.org> Message-ID: <1447051688-24936-14-git-send-email-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- Changes in v2: None drivers/usb/emul/usb-emul-uclass.c | 17 +++++++++++++++-- include/usb.h | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index 205f2c5..6b5f3c0 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -108,9 +108,8 @@ static int usb_emul_get_descriptor(struct usb_dev_platdata *plat, int value, return upto ? upto : length ? -EIO : 0; } -int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp) +static int usb_emul_find_devnum(int devnum, struct udevice **emulp) { - int devnum = usb_pipedevice(pipe); struct udevice *dev; struct uclass *uc; int ret; @@ -134,6 +133,20 @@ int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp) return -ENOENT; } +int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp) +{ + int devnum = usb_pipedevice(pipe); + + return usb_emul_find_devnum(devnum, emulp); +} + +int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp) +{ + struct usb_dev_platdata *udev = dev_get_parent_platdata(dev); + + return usb_emul_find_devnum(udev->devnum, emulp); +} + int usb_emul_control(struct udevice *emul, struct usb_device *udev, unsigned long pipe, void *buffer, int length, struct devrequest *setup) diff --git a/include/usb.h b/include/usb.h index a09c7f1..d684531 100644 --- a/include/usb.h +++ b/include/usb.h @@ -950,6 +950,16 @@ int usb_emul_bulk(struct udevice *emul, struct usb_device *udev, int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp); /** + * usb_emul_find_for_dev() - Find an emulator for a particular device + * + * @bus: USB bus (controller) + * @dev: USB device to check + * @emulp: Returns pointer to emulator, or NULL if not found + * @return 0 if found, -ve on error + */ +int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp); + +/** * usb_emul_reset() - Reset all emulators ready for use * * Clear out any address information in the emulators and make then ready for -- 2.6.0.rc2.230.g3dd15c0