Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp663692pxv; Thu, 15 Jul 2021 12:51:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye5PYO6h1Y1hprKEt/Xi5sHy7CgO/IWMYJBFSWrLeuknMe44lF/Yl4sk1PcBn+2ksd4TGC X-Received: by 2002:a17:906:a450:: with SMTP id cb16mr3099449ejb.296.1626378664787; Thu, 15 Jul 2021 12:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626378664; cv=none; d=google.com; s=arc-20160816; b=O5irejyIOpFMLjRssW67pImHOU6u8ZwbiWtJwilpd2niWWzdTX3BLCi8MMP/xz8+ql JNF1SVC6o6uYvSmRwFWbArMWz5kEU73JGNeBONB6qaAamaRaMFPg0xL9liZ04lEk4rkj g5TN7Et0a4Pr9b/dHQiMXz1P4xUcobp/03wF7X3Ji+FUFH0sHfT/NUkJG7tA6XJ9BiME Yqd/R0m6/aELFPbUaRoWhP1aTXiCQpTJZoop3PsOagTnSkn7ffx316RKFeW6p3OmkECB etC7Gs6XlhTmurW8mZxH0Yh1/ONeFnxJ3EedRgofpC7bvaJfhPWXMtKHnpVKIQ6cnwM6 UiTg== 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=vjXpCoAd8pFjgBZB++sHTuBRQudsux1fTYRXmfsk/X4=; b=BDZ/IHDbLiXrVO4CXkTb1QpVUGhW8H8lXaW1zyh/b5H5KFYxbEmQfogpm3LFYNC46P nTXXrcFKMeMZDqoeKusscQZaEp2Y5tN2fBLKTEUoAWAJc9v7dnzfdI4kS3zSqCIVsxeU tLXKe/UuYpnquo+2SVAaF9oqHG95T7NFD4GAgZgAaf7C/L+yQlItSxngx8zI08z+KOzK DXbk/JlSazGdRZWM4YsN+LpDR6st0K6wxhA4whTgMaJsHanPAHKJTN5MkZlrzfPi+htn Z89ig1jlc+mrmnXohPAQkrwx8Xqrn0hJ9mF+lLWBih+pja6JuJvWrWRNYl2AXvCvD7R5 xfrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yov8d9gH; 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 i11si10292663edb.471.2021.07.15.12.50.40; Thu, 15 Jul 2021 12:51:04 -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=Yov8d9gH; 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 S1345021AbhGOTt5 (ORCPT + 99 others); Thu, 15 Jul 2021 15:49:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:58950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245039AbhGOTTN (ORCPT ); Thu, 15 Jul 2021 15:19:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84B2B61415; Thu, 15 Jul 2021 19:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376431; bh=P5e3LcRXQTOMtejRS7EmpVKCIKYiiGiRS6xTSoz7s/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yov8d9gHXrsPldABKNusq7mahOulUgj8lVIfdQUhCFpnzczt0TczMKnw0fyqKj6pL J/TtZMxos26ccqkwE3YWtW67wH+Atue6GaGi9Zz2Y4M2UyW1yKU1BSo3hWu4p2aZR0 DRHvOA9G6Ue5YN4jE6D5BsfxzQXiAFbHH3D3W3iI= 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.13 253/266] media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K Date: Thu, 15 Jul 2021 20:40:08 +0200 Message-Id: <20210715182652.352616199@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 @@ -127,10 +127,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];