From f8437bc879eb4b87546c5818fd69fb2c1cee03d3 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sat, 8 Nov 2025 11:58:30 +0000 Subject: [PATCH] usb: device_next: hid: add a suspend callback Add an optional suspend callback to let a downstream hid driver be notified of HID suspend and resume events. Signed-off-by: Fabio Baltieri --- include/zephyr/usb/class/usbd_hid.h | 6 ++++++ subsys/usb/device_next/class/usbd_hid.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/zephyr/usb/class/usbd_hid.h b/include/zephyr/usb/class/usbd_hid.h index 79b52dd8fd9d3..25efe85b6d083 100644 --- a/include/zephyr/usb/class/usbd_hid.h +++ b/include/zephyr/usb/class/usbd_hid.h @@ -103,6 +103,12 @@ struct hid_device_ops { */ void (*iface_ready)(const struct device *dev, const bool ready); + /** + * This callback is called when the HID interface is suspended by the + * host. This callback is optional. + */ + void (*iface_suspended)(const struct device *dev, const bool suspended); + /** * This callback is called for the HID Get Report request to get a * feature, input, or output report, which is specified by the argument diff --git a/subsys/usb/device_next/class/usbd_hid.c b/subsys/usb/device_next/class/usbd_hid.c index 2ea3a08db763a..9777545e0ac2d 100644 --- a/subsys/usb/device_next/class/usbd_hid.c +++ b/subsys/usb/device_next/class/usbd_hid.c @@ -474,6 +474,12 @@ static void usbd_hid_disable(struct usbd_class_data *const c_data) static void usbd_hid_suspended(struct usbd_class_data *const c_data) { const struct device *dev = usbd_class_get_private(c_data); + struct hid_device_data *ddata = dev->data; + const struct hid_device_ops *const ops = ddata->ops; + + if (ops->iface_suspended) { + ops->iface_suspended(dev, true); + } LOG_DBG("Configuration suspended, device %s", dev->name); } @@ -481,6 +487,12 @@ static void usbd_hid_suspended(struct usbd_class_data *const c_data) static void usbd_hid_resumed(struct usbd_class_data *const c_data) { const struct device *dev = usbd_class_get_private(c_data); + struct hid_device_data *ddata = dev->data; + const struct hid_device_ops *const ops = ddata->ops; + + if (ops->iface_suspended) { + ops->iface_suspended(dev, false); + } LOG_DBG("Configuration resumed, device %s", dev->name); }