icE1usb fw: Move handling of device-wide request in usb_dev.c
We have upcoming ones not related to the E1 interface, so really
it make more sense to not have those in usb_e1.c
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I686916bb2b2cb90e94ac9c595deab19f189fcd49
diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.c b/firmware/ice40-riscv/icE1usb/usb_dev.c
new file mode 100644
index 0000000..1187047
--- /dev/null
+++ b/firmware/ice40-riscv/icE1usb/usb_dev.c
@@ -0,0 +1,48 @@
+/*
+ * usb_dev.c
+ *
+ * Copyright (C) 2019-2022 Sylvain Munaut <tnt@246tNt.com>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <stdint.h>
+
+#include <no2usb/usb.h>
+#include <no2usb/usb_proto.h>
+
+#include "console.h"
+#include "misc.h"
+
+#include "ice1usb_proto.h"
+
+
+static enum usb_fnd_resp
+_usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
+{
+ /* Check it's a device-wide vendor request */
+ if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV))
+ return USB_FND_CONTINUE;
+
+ /* Dispatch / Handle */
+ switch (req->bRequest) {
+ case ICE1USB_DEV_GET_CAPABILITIES:
+ xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO);
+ xfer->len = 1;
+ break;
+ default:
+ return USB_FND_ERROR;
+ }
+
+ return USB_FND_SUCCESS;
+}
+
+
+static struct usb_fn_drv _dev_drv = {
+ .ctrl_req = _usb_dev_ctrl_req,
+};
+
+void
+usb_dev_init(void)
+{
+ usb_register_function_driver(&_dev_drv);
+}