diff mbox series

Genesys Logic UVC microscopes used to work with Linux

Message ID b3747aa3-9984-0456-943a-b16e687c0ec0@selasky.org (mailing list archive)
State New, archived
Headers show
Series Genesys Logic UVC microscopes used to work with Linux | expand

Commit Message

Hans Petter Selasky June 6, 2021, 1:32 p.m. UTC
Hi,

Some USB video class compliant devices, like Genesys Logic camera chips, 
used in cheap microscopes, doesn't provide any image if there are UVC 
SET current value commands for the processing unit, before the camera 
stream is activated. Fix this by not issuing any UVC SET current value 
commands, if the value was not changed. This should also work fine with 
existing UVC compliant webcams and optimized the number of needed 
processing unit control endpoint requests.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>

Comments

Ricardo Ribalda Delgado June 7, 2021, 8:17 p.m. UTC | #1
Maybe you want to handle this with a quirk? I suspect that some
devices might work differently with this patches?

On Sun, Jun 6, 2021 at 3:36 PM Hans Petter Selasky <hps@selasky.org> wrote:
>
> Hi,
>
> Some USB video class compliant devices, like Genesys Logic camera chips,
> used in cheap microscopes, doesn't provide any image if there are UVC
> SET current value commands for the processing unit, before the camera
> stream is activated. Fix this by not issuing any UVC SET current value
> commands, if the value was not changed. This should also work fine with
> existing UVC compliant webcams and optimized the number of needed
> processing unit control endpoint requests.
>
> Signed-off-by: Hans Petter Selasky <hps@selasky.org>
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c
> b/drivers/media/usb/uvc/uvc_ctrl.c
> index b3dde98499f4..0d7137eca331 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -1697,7 +1697,13 @@ int uvc_ctrl_set(struct uvc_fh *handle,
>          if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
>                  ctrl->handle = handle;
>
> -       ctrl->dirty = 1;
> +       /* Avoid setting the current value. */
> +       if (!ctrl->dirty &&
> +           memcmp(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
> +                  uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
> +                  ctrl->info.size) != 0)
> +               ctrl->dirty = 1;
> +
>          ctrl->modified = 1;
>          return 0;
>   }
Laurent Pinchart June 7, 2021, 10:29 p.m. UTC | #2
On Mon, Jun 07, 2021 at 10:17:35PM +0200, Ricardo Ribalda Delgado wrote:
> Maybe you want to handle this with a quirk? I suspect that some
> devices might work differently with this patches?

Furthermore, for the affected devices, shouldn't the driver cache the
value of the control and apply it only after starting streaming ?
Otherwise a V4L2_S_CTRL() with a new value before streaming will break
the device.

> On Sun, Jun 6, 2021 at 3:36 PM Hans Petter Selasky <hps@selasky.org> wrote:
> >
> > Hi,
> >
> > Some USB video class compliant devices, like Genesys Logic camera chips,
> > used in cheap microscopes, doesn't provide any image if there are UVC
> > SET current value commands for the processing unit, before the camera
> > stream is activated. Fix this by not issuing any UVC SET current value
> > commands, if the value was not changed. This should also work fine with
> > existing UVC compliant webcams and optimized the number of needed
> > processing unit control endpoint requests.
> >
> > Signed-off-by: Hans Petter Selasky <hps@selasky.org>
> >
> > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c
> > b/drivers/media/usb/uvc/uvc_ctrl.c
> > index b3dde98499f4..0d7137eca331 100644
> > --- a/drivers/media/usb/uvc/uvc_ctrl.c
> > +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> > @@ -1697,7 +1697,13 @@ int uvc_ctrl_set(struct uvc_fh *handle,
> >          if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
> >                  ctrl->handle = handle;
> >
> > -       ctrl->dirty = 1;
> > +       /* Avoid setting the current value. */
> > +       if (!ctrl->dirty &&
> > +           memcmp(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
> > +                  uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
> > +                  ctrl->info.size) != 0)
> > +               ctrl->dirty = 1;
> > +
> >          ctrl->modified = 1;
> >          return 0;
> >   }
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c 
b/drivers/media/usb/uvc/uvc_ctrl.c
index b3dde98499f4..0d7137eca331 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1697,7 +1697,13 @@  int uvc_ctrl_set(struct uvc_fh *handle,
         if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
                 ctrl->handle = handle;

-       ctrl->dirty = 1;
+       /* Avoid setting the current value. */
+       if (!ctrl->dirty &&
+           memcmp(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
+                  uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                  ctrl->info.size) != 0)
+               ctrl->dirty = 1;
+
         ctrl->modified = 1;
         return 0;
  }