blob: e19d9a0d8e870a6080be56a0e70c7f5f760e7fe0 [file] [log] [blame]
Sylvain Munautcaf8cf92022-01-12 13:35:12 +01001/*
2 * usb_dev.c
3 *
4 * Copyright (C) 2019-2022 Sylvain Munaut <tnt@246tNt.com>
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#include <stdint.h>
Sylvain Munaut2c33f6d2022-01-12 14:12:31 +01009#include <string.h>
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010010
11#include <no2usb/usb.h>
12#include <no2usb/usb_proto.h>
13
14#include "console.h"
15#include "misc.h"
16
17#include "ice1usb_proto.h"
18
19
Sylvain Munaut2c33f6d2022-01-12 14:12:31 +010020const char *fw_build_str = BUILD_INFO;
21
22
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010023static enum usb_fnd_resp
24_usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
25{
26 /* Check it's a device-wide vendor request */
27 if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV))
28 return USB_FND_CONTINUE;
29
30 /* Dispatch / Handle */
31 switch (req->bRequest) {
32 case ICE1USB_DEV_GET_CAPABILITIES:
33 xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO);
34 xfer->len = 1;
35 break;
Sylvain Munaut2c33f6d2022-01-12 14:12:31 +010036 case ICE1USB_DEV_GET_FW_BUILD:
37 xfer->data = (void*) fw_build_str;
38 xfer->len = strlen(fw_build_str);
39 break;
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010040 default:
41 return USB_FND_ERROR;
42 }
43
44 return USB_FND_SUCCESS;
45}
46
47
48static struct usb_fn_drv _dev_drv = {
49 .ctrl_req = _usb_dev_ctrl_req,
50};
51
52void
53usb_dev_init(void)
54{
55 usb_register_function_driver(&_dev_drv);
56}