media: uvcvideo: Only create input devs if hw supports it
authorRicardo Ribalda <ribalda@chromium.org>
Tue, 20 Sep 2022 14:09:50 +0000 (16:09 +0200)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Sun, 15 Jan 2023 21:45:09 +0000 (23:45 +0200)
Examine the stream headers to figure out if the device has a button and
can be used as an input.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
drivers/media/usb/uvc/uvc_status.c

index 7518ffce22edb2495db5eb3b86bca45c2f327e92..cb90aff344bcbf4246367a50d81f8795736b46eb 100644 (file)
  * Input device
  */
 #ifdef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV
+
+static bool uvc_input_has_button(struct uvc_device *dev)
+{
+       struct uvc_streaming *stream;
+
+       /*
+        * The device has button events if both bTriggerSupport and
+        * bTriggerUsage are one. Otherwise the camera button does not
+        * exist or is handled automatically by the camera without host
+        * driver or client application intervention.
+        */
+       list_for_each_entry(stream, &dev->streams, list) {
+               if (stream->header.bTriggerSupport == 1 &&
+                   stream->header.bTriggerUsage == 1)
+                       return true;
+       }
+
+       return false;
+}
+
 static int uvc_input_init(struct uvc_device *dev)
 {
        struct input_dev *input;
        int ret;
 
+       if (!uvc_input_has_button(dev))
+               return 0;
+
        input = input_allocate_device();
        if (input == NULL)
                return -ENOMEM;