diff --git a/include/zephyr/usb/usb_ch9.h b/include/zephyr/usb/usb_ch9.h index f26e91067f4..2a0eb0cdd17 100644 --- a/include/zephyr/usb/usb_ch9.h +++ b/include/zephyr/usb/usb_ch9.h @@ -14,6 +14,7 @@ #include #include +#include #ifndef ZEPHYR_INCLUDE_USB_CH9_H_ #define ZEPHYR_INCLUDE_USB_CH9_H_ diff --git a/subsys/usb/host/usbh_ch9.c b/subsys/usb/host/usbh_ch9.c index efda4737863..d442f540e2d 100644 --- a/subsys/usb/host/usbh_ch9.c +++ b/subsys/usb/host/usbh_ch9.c @@ -170,3 +170,33 @@ int usbh_req_clear_sfs_rwup(const struct device *dev, bmRequestType, bRequest, wValue, 0, 0, NULL); } + +int usbh_req_set_hcfs_ppwr(const struct device *dev, + const uint8_t addr, const uint8_t port) +{ + const uint8_t bmRequestType = USB_REQTYPE_DIR_TO_DEVICE << 7 | + USB_REQTYPE_TYPE_CLASS << 5 | + USB_REQTYPE_RECIPIENT_OTHER << 0; + const uint8_t bRequest = USB_HCREQ_SET_FEATURE; + const uint16_t wValue = USB_HCFS_PORT_POWER; + const uint16_t wIndex = port; + + return usbh_req_setup(dev, addr, + bmRequestType, bRequest, wValue, wIndex, 0, + NULL); +} + +int usbh_req_set_hcfs_prst(const struct device *dev, + const uint8_t addr, const uint8_t port) +{ + const uint8_t bmRequestType = USB_REQTYPE_DIR_TO_DEVICE << 7 | + USB_REQTYPE_TYPE_CLASS << 5 | + USB_REQTYPE_RECIPIENT_OTHER << 0; + const uint8_t bRequest = USB_HCREQ_SET_FEATURE; + const uint16_t wValue = USB_HCFS_PORT_RESET; + const uint16_t wIndex = port; + + return usbh_req_setup(dev, addr, + bmRequestType, bRequest, wValue, wIndex, 0, + NULL); +} diff --git a/subsys/usb/host/usbh_ch9.h b/subsys/usb/host/usbh_ch9.h index 407b2b90006..c5a932fdec6 100644 --- a/subsys/usb/host/usbh_ch9.h +++ b/subsys/usb/host/usbh_ch9.h @@ -49,4 +49,10 @@ int usbh_req_set_sfs_rwup(const struct device *dev, int usbh_req_clear_sfs_rwup(const struct device *dev, const uint8_t addr); +int usbh_req_set_hcfs_ppwr(const struct device *dev, + const uint8_t addr, const uint8_t port); + +int usbh_req_set_hcfs_prst(const struct device *dev, + const uint8_t addr, const uint8_t port); + #endif /* ZEPHYR_INCLUDE_USBH_CH9_H */ diff --git a/subsys/usb/host/usbh_shell.c b/subsys/usb/host/usbh_shell.c index 746a4af5aa4..238bedb0a43 100644 --- a/subsys/usb/host/usbh_shell.c +++ b/subsys/usb/host/usbh_shell.c @@ -358,6 +358,48 @@ static int cmd_feature_set_rwup(const struct shell *sh, return err; } +static int cmd_feature_set_ppwr(const struct shell *sh, + size_t argc, char **argv) +{ + uint8_t addr; + uint8_t port; + int err; + + addr = strtol(argv[1], NULL, 10); + port = strtol(argv[2], NULL, 10); + + err = usbh_req_set_hcfs_ppwr(uhs_ctx.dev, addr, port); + if (err) { + shell_error(sh, "host: Failed to set ppwr feature"); + } else { + shell_print(sh, "host: Device 0x%02x, port %d, ppwr feature set", + addr, port); + } + + return err; +} + +static int cmd_feature_set_prst(const struct shell *sh, + size_t argc, char **argv) +{ + uint8_t addr; + uint8_t port; + int err; + + addr = strtol(argv[1], NULL, 10); + port = strtol(argv[2], NULL, 10); + + err = usbh_req_set_hcfs_prst(uhs_ctx.dev, addr, port); + if (err) { + shell_error(sh, "host: Failed to set prst feature"); + } else { + shell_print(sh, "host: Device 0x%02x, port %d, prst feature set", + addr, port); + } + + return err; +} + static int cmd_device_config(const struct shell *sh, size_t argc, char **argv) { @@ -537,6 +579,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(desc_cmds, SHELL_STATIC_SUBCMD_SET_CREATE(feature_set_cmds, SHELL_CMD_ARG(rwup, NULL, "
", cmd_feature_set_rwup, 2, 0), + SHELL_CMD_ARG(ppwr, NULL, "
", + cmd_feature_set_ppwr, 3, 0), + SHELL_CMD_ARG(prst, NULL, "
", + cmd_feature_set_prst, 3, 0), SHELL_CMD_ARG(halt, NULL, "
", cmd_feature_set_halt, 3, 0), SHELL_SUBCMD_SET_END