usb: host: add port power and port reset USB hub features

Add port power and port reset USB hub features.

Signed-off-by: Mateusz Wielgos <mateusz.wielgos@emerson.com>
This commit is contained in:
Mateusz Wielgos 2022-10-14 14:20:38 -05:00 committed by Carles Cufí
commit 217987f1b5
4 changed files with 83 additions and 0 deletions

View file

@ -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);
}

View file

@ -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 */

View file

@ -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, "<address>",
cmd_feature_set_rwup, 2, 0),
SHELL_CMD_ARG(ppwr, NULL, "<address> <port>",
cmd_feature_set_ppwr, 3, 0),
SHELL_CMD_ARG(prst, NULL, "<address> <port>",
cmd_feature_set_prst, 3, 0),
SHELL_CMD_ARG(halt, NULL, "<address> <endpoint>",
cmd_feature_set_halt, 3, 0),
SHELL_SUBCMD_SET_END