Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp636137pxv; Thu, 15 Jul 2021 12:06:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBCk9q4X9dGVRXVfvhbL1dwXUvLnvEVGRmPnm8qbZ1oeQvztJEXxImWnbQJhAEnwLR15bZ X-Received: by 2002:a92:db4b:: with SMTP id w11mr3776881ilq.297.1626375991261; Thu, 15 Jul 2021 12:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375991; cv=none; d=google.com; s=arc-20160816; b=iknvm+AIWugFxo6Y1dOOkGZybDIysZ+wkAmsfC1yN+I4l8Zqg4sl7IoHeiJ+z6bBkg 2AchDc/EnVMckoYZe6XxJyd+vk5Gv3MO9EspoQIFHdEjsSTd3eJ0cns2dmNzR2f6N+CB XAGYUyRO5EHX5/gak+S0WsIxaJq8kAApYE9EkeSECihQXKzV6OXLDAcB8RAa4dBgUnNb iyOkRgDbLh1DUOPe899SClI/5WwFPI5A9xhvDbSzQ5zF+JDosScBN3lWqVXVFptvjtqz 1ZM6s4ujpxOdEDTei0GVcPR5mMYQDbwxH657q3CvpqbbbdqwRk6KpHxwPTKnFAWr1P7G /WCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iV1IkQ88eU7V0tEWF/P3bqBNtbMEPXJ6wcsqbQbrOtY=; b=LQ3SCl4pGN+W84g5g+8DfYatanf1bRah7tQOA7ymQDNWxwc/N6+Hjte1HKZAVI3ZNp HpWWTG5+YIxr7c0pyezOf8Ewrqv6mwm/v8JWWmpeMYWPJlEj5dx7QYdGRgpqpREiW4/F rRenFrqTYuFq80C9kxmEO0q1kPj8xmpAHe007EwGbyCVLrIibc765M7nic0n43g0HuoN 7zogsca4/A5cczAq8jW6JRsbRJcnIk3QxVeyhiEeDj39SatbAdHWRr0Rn+2qZd/ozAd4 KbNPOuguDJTufdZV3FfQUXxSAYTOXxndPUagb3qF/+GtFkO1xZpA8Ec99ymcGtPis1jX S3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AwXwU9Lv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si8081145jad.45.2021.07.15.12.06.17; Thu, 15 Jul 2021 12:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AwXwU9Lv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242324AbhGOTGa (ORCPT + 99 others); Thu, 15 Jul 2021 15:06:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237890AbhGOS4X (ORCPT ); Thu, 15 Jul 2021 14:56:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BBAE613CF; Thu, 15 Jul 2021 18:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375209; bh=GmKKiOyw77r0CD+Z7TsMw8WnLS9v1jPTTdYpMxr1rCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AwXwU9LvNrEzWWV7loInhwgrRQiR2SpPFl7hiUvwHr1LCeL5m+nMc3iBGDTVMbWkd ghnlebuzjLFynwKHdk0iihLwb3mwoEnE8hAVzKk3B9CQRHAuUaI5zSog/pzo+4hZ4a pPyyC+TG+zaudvPsaC3hsQg6a1OFFHTvuhyaaef4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Drung , Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 5.10 207/215] media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K Date: Thu, 15 Jul 2021 20:39:39 +0200 Message-Id: <20210715182635.739003762@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Drung commit 4c6e0976295add7f0ed94d276c04a3d6f1ea8f83 upstream. The Elgato Cam Link 4K HDMI video capture card reports to support three different pixel formats, where the first format depends on the connected HDMI device. ``` $ v4l2-ctl -d /dev/video0 --list-formats-ext ioctl: VIDIOC_ENUM_FMT Type: Video Capture [0]: 'NV12' (Y/CbCr 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) [1]: 'NV12' (Y/CbCr 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) [2]: 'YU12' (Planar YUV 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) ``` Changing the pixel format to anything besides the first pixel format does not work: ``` $ v4l2-ctl -d /dev/video0 --try-fmt-video pixelformat=YU12 Format Video Capture: Width/Height : 3840/2160 Pixel Format : 'NV12' (Y/CbCr 4:2:0) Field : None Bytes per Line : 3840 Size Image : 12441600 Colorspace : sRGB Transfer Function : Rec. 709 YCbCr/HSV Encoding: Rec. 709 Quantization : Default (maps to Limited Range) Flags : ``` User space applications like VLC might show an error message on the terminal in that case: ``` libv4l2: error set_fmt gave us a different result than try_fmt! ``` Depending on the error handling of the user space applications, they might display a distorted video, because they use the wrong pixel format for decoding the stream. The Elgato Cam Link 4K responds to the USB video probe VS_PROBE_CONTROL/VS_COMMIT_CONTROL with a malformed data structure: The second byte contains bFormatIndex (instead of being the second byte of bmHint). The first byte is always zero. The third byte is always 1. The firmware bug was reported to Elgato on 2020-12-01 and it was forwarded by the support team to the developers as feature request. There is no firmware update available since then. The latest firmware for Elgato Cam Link 4K as of 2021-03-23 has MCU 20.02.19 and FPGA 67. Therefore correct the malformed data structure for this device. The change was successfully tested with VLC, OBS, and Chromium using different pixel formats (YUYV, NV12, YU12), resolutions (3840x2160, 1920x1080), and frame rates (29.970 and 59.940 fps). Cc: stable@vger.kernel.org Signed-off-by: Benjamin Drung Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -124,10 +124,37 @@ int uvc_query_ctrl(struct uvc_device *de static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, struct uvc_streaming_control *ctrl) { + static const struct usb_device_id elgato_cam_link_4k = { + USB_DEVICE(0x0fd9, 0x0066) + }; struct uvc_format *format = NULL; struct uvc_frame *frame = NULL; unsigned int i; + /* + * The response of the Elgato Cam Link 4K is incorrect: The second byte + * contains bFormatIndex (instead of being the second byte of bmHint). + * The first byte is always zero. The third byte is always 1. + * + * The UVC 1.5 class specification defines the first five bits in the + * bmHint bitfield. The remaining bits are reserved and should be zero. + * Therefore a valid bmHint will be less than 32. + * + * Latest Elgato Cam Link 4K firmware as of 2021-03-23 needs this fix. + * MCU: 20.02.19, FPGA: 67 + */ + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) && + ctrl->bmHint > 255) { + u8 corrected_format_index = ctrl->bmHint >> 8; + + /* uvc_dbg(stream->dev, VIDEO, + "Correct USB video probe response from {bmHint: 0x%04x, bFormatIndex: %u} to {bmHint: 0x%04x, bFormatIndex: %u}\n", + ctrl->bmHint, ctrl->bFormatIndex, + 1, corrected_format_index); */ + ctrl->bmHint = 1; + ctrl->bFormatIndex = corrected_format_index; + } + for (i = 0; i < stream->nformats; ++i) { if (stream->format[i].index == ctrl->bFormatIndex) { format = &stream->format[i];