Sylvain Munaut | caf8cf9 | 2022-01-12 13:35:12 +0100 | [diff] [blame^] | 1 | /* |
| 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> |
| 9 | |
| 10 | #include <no2usb/usb.h> |
| 11 | #include <no2usb/usb_proto.h> |
| 12 | |
| 13 | #include "console.h" |
| 14 | #include "misc.h" |
| 15 | |
| 16 | #include "ice1usb_proto.h" |
| 17 | |
| 18 | |
| 19 | static enum usb_fnd_resp |
| 20 | _usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) |
| 21 | { |
| 22 | /* Check it's a device-wide vendor request */ |
| 23 | if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV)) |
| 24 | return USB_FND_CONTINUE; |
| 25 | |
| 26 | /* Dispatch / Handle */ |
| 27 | switch (req->bRequest) { |
| 28 | case ICE1USB_DEV_GET_CAPABILITIES: |
| 29 | xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO); |
| 30 | xfer->len = 1; |
| 31 | break; |
| 32 | default: |
| 33 | return USB_FND_ERROR; |
| 34 | } |
| 35 | |
| 36 | return USB_FND_SUCCESS; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static struct usb_fn_drv _dev_drv = { |
| 41 | .ctrl_req = _usb_dev_ctrl_req, |
| 42 | }; |
| 43 | |
| 44 | void |
| 45 | usb_dev_init(void) |
| 46 | { |
| 47 | usb_register_function_driver(&_dev_drv); |
| 48 | } |