blob: e834142123762c9aefde4f026847f9f9098c565a [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
Sylvain Munautb722de72022-10-05 12:39:21 +020024_usb_dev_ctrl_req_write(struct usb_ctrl_req *req, struct usb_xfer *xfer)
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010025{
Sylvain Munautb722de72022-10-05 12:39:21 +020026 switch (req->bRequest) {
27 default:
28 return USB_FND_ERROR;
29 }
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010030
Sylvain Munautb722de72022-10-05 12:39:21 +020031 return USB_FND_SUCCESS;
32}
33
34static enum usb_fnd_resp
35_usb_dev_ctrl_req_read(struct usb_ctrl_req *req, struct usb_xfer *xfer)
36{
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010037 switch (req->bRequest) {
38 case ICE1USB_DEV_GET_CAPABILITIES:
39 xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO);
40 xfer->len = 1;
41 break;
Sylvain Munaut2c33f6d2022-01-12 14:12:31 +010042 case ICE1USB_DEV_GET_FW_BUILD:
43 xfer->data = (void*) fw_build_str;
44 xfer->len = strlen(fw_build_str);
45 break;
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010046 default:
47 return USB_FND_ERROR;
48 }
49
50 return USB_FND_SUCCESS;
51}
52
Sylvain Munautb722de72022-10-05 12:39:21 +020053static enum usb_fnd_resp
54_usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
55{
56 /* Check it's a device-wide vendor request */
57 if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV))
58 return USB_FND_CONTINUE;
59
60 /* Read / Write dispatch */
61 if (USB_REQ_IS_READ(req))
62 return _usb_dev_ctrl_req_read(req, xfer);
63 else
64 return _usb_dev_ctrl_req_write(req, xfer);
65}
66
Sylvain Munautcaf8cf92022-01-12 13:35:12 +010067
68static struct usb_fn_drv _dev_drv = {
69 .ctrl_req = _usb_dev_ctrl_req,
70};
71
72void
73usb_dev_init(void)
74{
75 usb_register_function_driver(&_dev_drv);
76}