Module Name: src Committed By: maxv Date: Sat Feb 8 08:18:06 UTC 2020
Modified Files: src/sys/dev/usb: usbdi_util.c usbdi_util.h Log Message: Reorder usbdi_util.{c,h}, for clarity. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/sys/dev/usb/usbdi_util.c cvs rdiff -u -r1.50 -r1.51 src/sys/dev/usb/usbdi_util.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/usbdi_util.c diff -u src/sys/dev/usb/usbdi_util.c:1.76 src/sys/dev/usb/usbdi_util.c:1.77 --- src/sys/dev/usb/usbdi_util.c:1.76 Sat Feb 8 07:53:23 2020 +++ src/sys/dev/usb/usbdi_util.c Sat Feb 8 08:18:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi_util.c,v 1.76 2020/02/08 07:53:23 maxv Exp $ */ +/* $NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $ */ /* * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.76 2020/02/08 07:53:23 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -154,6 +154,8 @@ usbd_get_device_desc(struct usbd_device 0, USB_DEVICE_DESCRIPTOR_SIZE, d); } +/* -------------------------------------------------------------------------- */ + usbd_status usbd_get_device_status(struct usbd_device *dev, usb_status_t *st) { @@ -184,22 +186,6 @@ usbd_get_hub_status(struct usbd_device * } usbd_status -usbd_set_address(struct usbd_device *dev, int addr) -{ - USBHIST_FUNC(); - USBHIST_CALLARGS(usbdebug, "dev %#jx addr %jd", - (uintptr_t)dev, addr, 0, 0); - usb_device_request_t req; - - req.bmRequestType = UT_WRITE_DEVICE; - req.bRequest = UR_SET_ADDRESS; - USETW(req.wValue, addr); - USETW(req.wIndex, 0); - USETW(req.wLength, 0); - return usbd_do_request(dev, &req, 0); -} - -usbd_status usbd_get_port_status(struct usbd_device *dev, int port, usb_port_status_t *ps) { USBHIST_FUNC(); @@ -233,6 +219,8 @@ usbd_get_port_status_ext(struct usbd_dev return usbd_do_request(dev, &req, pse); } +/* -------------------------------------------------------------------------- */ + usbd_status usbd_clear_hub_feature(struct usbd_device *dev, int sel) { @@ -343,6 +331,62 @@ usbd_clear_endpoint_feature(struct usbd_ return usbd_do_request(dev, &req, 0); } +/* -------------------------------------------------------------------------- */ + +usbd_status +usbd_get_config(struct usbd_device *dev, uint8_t *conf) +{ + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0); + usb_device_request_t req; + + req.bmRequestType = UT_READ_DEVICE; + req.bRequest = UR_GET_CONFIG; + USETW(req.wValue, 0); + USETW(req.wIndex, 0); + USETW(req.wLength, 1); + return usbd_do_request(dev, &req, conf); +} + +usbd_status +usbd_set_address(struct usbd_device *dev, int addr) +{ + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "dev %#jx addr %jd", + (uintptr_t)dev, addr, 0, 0); + usb_device_request_t req; + + req.bmRequestType = UT_WRITE_DEVICE; + req.bRequest = UR_SET_ADDRESS; + USETW(req.wValue, addr); + USETW(req.wIndex, 0); + USETW(req.wLength, 0); + return usbd_do_request(dev, &req, 0); +} + +usbd_status +usbd_set_idle(struct usbd_interface *iface, int duration, int id) +{ + usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface); + struct usbd_device *dev; + usb_device_request_t req; + + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "duration %jd id %jd", duration, id, 0, 0); + + if (ifd == NULL) + return USBD_IOERROR; + usbd_interface2device_handle(iface, &dev); + req.bmRequestType = UT_WRITE_CLASS_INTERFACE; + req.bRequest = UR_SET_IDLE; + USETW2(req.wValue, duration, id); + USETW(req.wIndex, ifd->bInterfaceNumber); + USETW(req.wLength, 0); + return usbd_do_request(dev, &req, 0); +} + +/* -------------------------------------------------------------------------- */ + usbd_status usbd_get_protocol(struct usbd_interface *iface, uint8_t *report) { @@ -389,6 +433,8 @@ usbd_set_protocol(struct usbd_interface return usbd_do_request(dev, &req, 0); } +/* -------------------------------------------------------------------------- */ + usbd_status usbd_set_report(struct usbd_interface *iface, int type, int id, void *data, int len) @@ -433,27 +479,6 @@ usbd_get_report(struct usbd_interface *i } usbd_status -usbd_set_idle(struct usbd_interface *iface, int duration, int id) -{ - usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface); - struct usbd_device *dev; - usb_device_request_t req; - - USBHIST_FUNC(); - USBHIST_CALLARGS(usbdebug, "duration %jd id %jd", duration, id, 0, 0); - - if (ifd == NULL) - return USBD_IOERROR; - usbd_interface2device_handle(iface, &dev); - req.bmRequestType = UT_WRITE_CLASS_INTERFACE; - req.bRequest = UR_SET_IDLE; - USETW2(req.wValue, duration, id); - USETW(req.wIndex, ifd->bInterfaceNumber); - USETW(req.wLength, 0); - return usbd_do_request(dev, &req, 0); -} - -usbd_status usbd_get_report_descriptor(struct usbd_device *dev, int ifcno, int size, void *d) { @@ -470,6 +495,8 @@ usbd_get_report_descriptor(struct usbd_d return usbd_do_request(dev, &req, d); } +/* -------------------------------------------------------------------------- */ + usb_hid_descriptor_t * usbd_get_hid_descriptor(struct usbd_interface *ifc) { @@ -529,21 +556,6 @@ usbd_read_report_desc(struct usbd_interf } usbd_status -usbd_get_config(struct usbd_device *dev, uint8_t *conf) -{ - USBHIST_FUNC(); - USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0); - usb_device_request_t req; - - req.bmRequestType = UT_READ_DEVICE; - req.bRequest = UR_GET_CONFIG; - USETW(req.wValue, 0); - USETW(req.wIndex, 0); - USETW(req.wLength, 1); - return usbd_do_request(dev, &req, conf); -} - -usbd_status usbd_bulk_transfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe, uint16_t flags, uint32_t timeout, void *buf, uint32_t *size) { Index: src/sys/dev/usb/usbdi_util.h diff -u src/sys/dev/usb/usbdi_util.h:1.50 src/sys/dev/usb/usbdi_util.h:1.51 --- src/sys/dev/usb/usbdi_util.h:1.50 Sat Feb 8 07:53:23 2020 +++ src/sys/dev/usb/usbdi_util.h Sat Feb 8 08:18:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi_util.h,v 1.50 2020/02/08 07:53:23 maxv Exp $ */ +/* $NetBSD: usbdi_util.h,v 1.51 2020/02/08 08:18:06 maxv Exp $ */ /* * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. @@ -35,56 +35,56 @@ #include <dev/usb/usbhid.h> -usbd_status usbd_get_desc(struct usbd_device *, int, - int, int, void *); +usbd_status usbd_get_desc(struct usbd_device *, int, int, int, void *); usbd_status usbd_get_config_desc(struct usbd_device *, int, - usb_config_descriptor_t *); -usbd_status usbd_get_config_desc_full(struct usbd_device *, int, void *, int); + usb_config_descriptor_t *); +usbd_status usbd_get_config_desc_full(struct usbd_device *, int, void *, + int); usbd_status usbd_get_bos_desc(struct usbd_device *, int, - usb_bos_descriptor_t *); + usb_bos_descriptor_t *); usbd_status usbd_get_bos_desc_full(struct usbd_device *, int, void *, int); usbd_status usbd_get_device_desc(struct usbd_device *, - usb_device_descriptor_t *); -usbd_status usbd_get_desc_fake(struct usbd_device *, int, - int, int, void *); -usbd_status usbd_set_address(struct usbd_device *, int); -usbd_status usbd_get_port_status(struct usbd_device *, - int, usb_port_status_t *); -usbd_status usbd_get_port_status_ext(struct usbd_device *, - int, usb_port_status_ext_t *); -usbd_status usbd_set_hub_feature(struct usbd_device *, int); + usb_device_descriptor_t *); +usbd_status usbd_get_string_desc(struct usbd_device *, int, int, + usb_string_descriptor_t *, int *); + +usbd_status usbd_get_device_status(struct usbd_device *, usb_status_t *); +usbd_status usbd_get_hub_status(struct usbd_device *, usb_hub_status_t *); +usbd_status usbd_get_port_status(struct usbd_device *, int, + usb_port_status_t *); +usbd_status usbd_get_port_status_ext(struct usbd_device *, int, + usb_port_status_ext_t *); + +usbd_status usbd_get_desc_fake(struct usbd_device *, int, int, int, void *); + usbd_status usbd_clear_hub_feature(struct usbd_device *, int); -usbd_status usbd_set_port_feature(struct usbd_device *, int, int); +usbd_status usbd_set_hub_feature(struct usbd_device *, int); usbd_status usbd_clear_port_feature(struct usbd_device *, int, int); +usbd_status usbd_set_port_feature(struct usbd_device *, int, int); usbd_status usbd_set_port_u1_timeout(struct usbd_device *, int, int); usbd_status usbd_set_port_u2_timeout(struct usbd_device *, int, int); usbd_status usbd_clear_endpoint_feature(struct usbd_device *, int, int); -usbd_status usbd_get_device_status(struct usbd_device *, usb_status_t *); -usbd_status usbd_get_hub_status(struct usbd_device *, usb_hub_status_t *); + +usbd_status usbd_get_config(struct usbd_device *, uint8_t *); +usbd_status usbd_set_address(struct usbd_device *, int); +usbd_status usbd_set_idle(struct usbd_interface *, int, int); + usbd_status usbd_get_protocol(struct usbd_interface *, uint8_t *); usbd_status usbd_set_protocol(struct usbd_interface *, int); -usbd_status usbd_get_report_descriptor(struct usbd_device *, int, - int, void *); -usb_hid_descriptor_t *usbd_get_hid_descriptor(struct usbd_interface *); -usbd_status usbd_set_report(struct usbd_interface *, int, int, - void *, int); -usbd_status usbd_get_report(struct usbd_interface *, int, int, - void *, int); -usbd_status usbd_set_idle(struct usbd_interface *, int, int); -usbd_status usbd_read_report_desc(struct usbd_interface *, void **, - int *); -usbd_status usbd_get_config(struct usbd_device *, uint8_t *); -usbd_status usbd_get_string_desc(struct usbd_device *, int, - int, usb_string_descriptor_t *, - int *); +usbd_status usbd_set_report(struct usbd_interface *, int, int, void *, int); +usbd_status usbd_get_report(struct usbd_interface *, int, int, void *, int); +usbd_status usbd_get_report_descriptor(struct usbd_device *, int, int, + void *); + +usb_hid_descriptor_t *usbd_get_hid_descriptor(struct usbd_interface *); +usbd_status usbd_read_report_desc(struct usbd_interface *, void **, int *); usbd_status usbd_set_config_no(struct usbd_device *, int, int); usbd_status usbd_set_config_index(struct usbd_device *, int, int); usbd_status usbd_bulk_transfer(struct usbd_xfer *, struct usbd_pipe *, - uint16_t, uint32_t, void *, uint32_t *); - + uint16_t, uint32_t, void *, uint32_t *); usbd_status usbd_intr_transfer(struct usbd_xfer *, struct usbd_pipe *, uint16_t, uint32_t, void *, uint32_t *);