[v3] media: uvcvideo: Fix bandwidth error for Alcor camera

Message ID 20221118022302.112121-1-aichao@kylinos.cn
State New
Headers
Series [v3] media: uvcvideo: Fix bandwidth error for Alcor camera |

Commit Message

Ai Chao Nov. 18, 2022, 2:23 a.m. UTC
  For Alcor Corp. Slave camera(1b17:6684/2017:0011), it support to
output compressed video data, and it return a wrong
dwMaxPayloadTransferSize fields. This is a fireware issue,
but the manufacturer cannot provide a const return fields
by the fireware. For some device, device requested 2752512
 B/frame bandwidth. For some device, device requested 3072
 B/frame bandwidth. so we check the dwMaxPayloadTransferSize
 fields,if it large than 0x1000, reset dwMaxPayloadTransferSize
to 1024, and the camera preview normally.

Signed-off-by: Ai Chao <aichao@kylinos.cn>

---
change for v3
- Add VID/PID 2017:0011

change for v2
- Used usb_match_one_id to check VID and PID
---
---
 drivers/media/usb/uvc/uvc_video.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
  

Comments

Ricardo Ribalda Nov. 18, 2022, 8:15 a.m. UTC | #1
Hi Ai

Thanks for your patch!

On Fri, 18 Nov 2022 at 03:23, Ai Chao <aichao@kylinos.cn> wrote:
>
> For Alcor Corp. Slave camera(1b17:6684/2017:0011), it support to
> output compressed video data, and it return a wrong
> dwMaxPayloadTransferSize fields. This is a fireware issue,
s/fireware/firmware/
> but the manufacturer cannot provide a const return fields
> by the fireware. For some device, device requested 2752512
>  B/frame bandwidth. For some device, device requested 3072
>  B/frame bandwidth. so we check the dwMaxPayloadTransferSize
>  fields,if it large than 0x1000, reset dwMaxPayloadTransferSize
> to 1024, and the camera preview normally.

3072 is smaller than 0x1000.

It is ok to have values between 1024 and 0x1000 (4096) ?

Thanks

>
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
>
> ---
> change for v3
> - Add VID/PID 2017:0011
>
> change for v2
> - Used usb_match_one_id to check VID and PID
> ---
> ---
>  drivers/media/usb/uvc/uvc_video.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index d2eb9066e4dc..1260800ef8bd 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -135,6 +135,10 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
>         static const struct usb_device_id elgato_cam_link_4k = {
>                 USB_DEVICE(0x0fd9, 0x0066)
>         };
> +       static const struct usb_device_id alcor_corp_slave_cam = {
> +               USB_DEVICE(0x1b17, 0x6684),
> +               USB_DEVICE(0x2017, 0x0011),
> +       };
>         struct uvc_format *format = NULL;
>         struct uvc_frame *frame = NULL;
>         unsigned int i;
> @@ -234,6 +238,13 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
>
>                 ctrl->dwMaxPayloadTransferSize = bandwidth;
>         }
> +
> +       /* Alcor Corp. Slave camera return wrong dwMaxPayloadTransferSize */
> +       if ((format->flags & UVC_FMT_FLAG_COMPRESSED) &&
> +           (ctrl->dwMaxPayloadTransferSize > 0x1000) &&
> +            usb_match_one_id(stream->dev->intf, &alcor_corp_slave_cam)) {
> +               ctrl->dwMaxPayloadTransferSize = 1024;
> +       }
>  }
>
>  static size_t uvc_video_ctrl_size(struct uvc_streaming *stream)
> --
> 2.25.1
>
  
Ricardo Ribalda Nov. 18, 2022, 8:20 a.m. UTC | #2
On Fri, 18 Nov 2022 at 09:15, Ricardo Ribalda <ribalda@chromium.org> wrote:
>
> Hi Ai
>
> Thanks for your patch!
>
> On Fri, 18 Nov 2022 at 03:23, Ai Chao <aichao@kylinos.cn> wrote:
> >
> > For Alcor Corp. Slave camera(1b17:6684/2017:0011), it support to
> > output compressed video data, and it return a wrong
> > dwMaxPayloadTransferSize fields. This is a fireware issue,
> s/fireware/firmware/
> > but the manufacturer cannot provide a const return fields
> > by the fireware. For some device, device requested 2752512
> >  B/frame bandwidth. For some device, device requested 3072
> >  B/frame bandwidth. so we check the dwMaxPayloadTransferSize
> >  fields,if it large than 0x1000, reset dwMaxPayloadTransferSize
> > to 1024, and the camera preview normally.
>
> 3072 is smaller than 0x1000.
>
> It is ok to have values between 1024 and 0x1000 (4096) ?
>
> Thanks
>
> >
> > Signed-off-by: Ai Chao <aichao@kylinos.cn>
> >
> > ---
> > change for v3
> > - Add VID/PID 2017:0011
> >
> > change for v2
> > - Used usb_match_one_id to check VID and PID
> > ---
> > ---
> >  drivers/media/usb/uvc/uvc_video.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index d2eb9066e4dc..1260800ef8bd 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -135,6 +135,10 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> >         static const struct usb_device_id elgato_cam_link_4k = {
> >                 USB_DEVICE(0x0fd9, 0x0066)
> >         };
> > +       static const struct usb_device_id alcor_corp_slave_cam = {
> > +               USB_DEVICE(0x1b17, 0x6684),
> > +               USB_DEVICE(0x2017, 0x0011),
> > +       };
> >         struct uvc_format *format = NULL;
> >         struct uvc_frame *frame = NULL;
> >         unsigned int i;
> > @@ -234,6 +238,13 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
> >
> >                 ctrl->dwMaxPayloadTransferSize = bandwidth;
> >         }
> > +
> > +       /* Alcor Corp. Slave camera return wrong dwMaxPayloadTransferSize */
> > +       if ((format->flags & UVC_FMT_FLAG_COMPRESSED) &&
> > +           (ctrl->dwMaxPayloadTransferSize > 0x1000) &&
> > +            usb_match_one_id(stream->dev->intf, &alcor_corp_slave_cam)) {

You cannot use usb_match_one_id when you have multiple ids. Use
usb_match_id (add add the sentinel at the end of the list)

> > +               ctrl->dwMaxPayloadTransferSize = 1024;
> > +       }
> >  }
> >
> >  static size_t uvc_video_ctrl_size(struct uvc_streaming *stream)
> > --
> > 2.25.1
> >
>
>
> --
> Ricardo Ribalda
  

Patch

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index d2eb9066e4dc..1260800ef8bd 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -135,6 +135,10 @@  static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 	static const struct usb_device_id elgato_cam_link_4k = {
 		USB_DEVICE(0x0fd9, 0x0066)
 	};
+	static const struct usb_device_id alcor_corp_slave_cam = {
+		USB_DEVICE(0x1b17, 0x6684),
+		USB_DEVICE(0x2017, 0x0011),
+	};
 	struct uvc_format *format = NULL;
 	struct uvc_frame *frame = NULL;
 	unsigned int i;
@@ -234,6 +238,13 @@  static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 
 		ctrl->dwMaxPayloadTransferSize = bandwidth;
 	}
+
+	/* Alcor Corp. Slave camera return wrong dwMaxPayloadTransferSize */
+	if ((format->flags & UVC_FMT_FLAG_COMPRESSED) &&
+	    (ctrl->dwMaxPayloadTransferSize > 0x1000) &&
+	     usb_match_one_id(stream->dev->intf, &alcor_corp_slave_cam)) {
+		ctrl->dwMaxPayloadTransferSize = 1024;
+	}
 }
 
 static size_t uvc_video_ctrl_size(struct uvc_streaming *stream)