2 * (C) Copyright 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
13 DECLARE_GLOBAL_DATA_PTR;
15 static void usbmon_trace(struct udevice *bus, ulong pipe,
16 struct devrequest *setup, struct udevice *emul)
18 static const char types[] = "ZICB";
21 type = (pipe & USB_PIPE_TYPE_MASK) >> USB_PIPE_TYPE_SHIFT;
22 debug("0 0 S %c%c:%d:%03ld:%ld", types[type],
23 pipe & USB_DIR_IN ? 'i' : 'o',
25 (pipe & USB_PIPE_DEV_MASK) >> USB_PIPE_DEV_SHIFT,
26 (pipe & USB_PIPE_EP_MASK) >> USB_PIPE_EP_SHIFT);
28 debug(" s %02x %02x %04x %04x %04x", setup->requesttype,
29 setup->request, setup->value, setup->index,
32 debug(" %s", emul ? emul->name : "(no emul found)");
37 static int sandbox_submit_control(struct udevice *bus,
38 struct usb_device *udev,
40 void *buffer, int length,
41 struct devrequest *setup)
46 /* Just use child of dev as emulator? */
47 debug("%s: bus=%s\n", __func__, bus->name);
48 ret = usb_emul_find(bus, pipe, &emul);
49 usbmon_trace(bus, pipe, setup, emul);
52 ret = usb_emul_control(emul, udev, pipe, buffer, length, setup);
54 debug("ret=%d\n", ret);
65 static int sandbox_submit_bulk(struct udevice *bus, struct usb_device *udev,
66 unsigned long pipe, void *buffer, int length)
71 /* Just use child of dev as emulator? */
72 debug("%s: bus=%s\n", __func__, bus->name);
73 ret = usb_emul_find(bus, pipe, &emul);
74 usbmon_trace(bus, pipe, NULL, emul);
77 ret = usb_emul_bulk(emul, udev, pipe, buffer, length);
79 debug("ret=%d\n", ret);
90 static int sandbox_alloc_device(struct udevice *dev, struct usb_device *udev)
95 static int sandbox_usb_probe(struct udevice *dev)
100 static const struct dm_usb_ops sandbox_usb_ops = {
101 .control = sandbox_submit_control,
102 .bulk = sandbox_submit_bulk,
103 .alloc_device = sandbox_alloc_device,
106 static const struct udevice_id sandbox_usb_ids[] = {
107 { .compatible = "sandbox,usb" },
111 U_BOOT_DRIVER(usb_sandbox) = {
112 .name = "usb_sandbox",
114 .of_match = sandbox_usb_ids,
115 .probe = sandbox_usb_probe,
116 .ops = &sandbox_usb_ops,