Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp712405pxv; Thu, 15 Jul 2021 14:10:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfUF6QDK/l6A+1Wip+TV4LxiIcSJQUlT5hXcHlIAx0PMnRNj1sPf9U0VVvofWHQrFsXzx0 X-Received: by 2002:aa7:db11:: with SMTP id t17mr9655782eds.297.1626383449868; Thu, 15 Jul 2021 14:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383449; cv=none; d=google.com; s=arc-20160816; b=c7xNGZK0sMZKiKwSRgVNKOm0lleYs2h03oWBhfG7HaEM3WpuICi3ort6bX+zVHU3RP VkYajw6yA1qWjOw5/y+uZSFGgjsWSk5Nv9U+SNaBAMi9LYYAewOhNokmZ93eeZlGEuQ0 ISA0DOX0SMw290UgeCzreApxbJ/y5RXbKlHpulBycAwx4S3vNc0vdKxHcUk57bkOXIqE dKh1xxCuwEEKazH5G1ezFKWESbMFwx1qCn9A57q2c1z/B1ySDQZ20qMpSjpnBzPCOnkp 8NYOQubS5UfmMMOjL7i53q5sd4WaOcF7JBYWAqEE5u3nEwd8Y7xPdCqwhac+GZ6GfDPu buag== 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=NRCGtcQ/E0a8yPK6Jt/TZv/7BEFnbTAtYxQW32xhSBk=; b=AFK5SByf2SAvfYjLtuk4ZS6lKU7T0g0fgC+WROc96kGAZngJhRPBARV7op8Ul+Ek8e OYe+vHl1Z2RA9yF7V+/2pw9R2vmprZzoE3J+OavFxlVxU0sKZO4aXSeBpBuY7B2361JV fWKfrYBsQz3XMAZWDUTu+e2Pfj1H5TpTmYo9C739hDG+bX6VZgqpUpHIA7MzC6wULjup aYKCWaYB0cdQ8qwhzGYJxPSQ0uEPy57/f0V1VWIWMJBpO7R5CBkVI6A2ctjcZlIxZyL1 +1q8VrW+PzpqyzT0wt1dwF9/GzaJTwxJ98UK2p1AIWD4qo9Jbm+tPk+BgTHK5fbu0hzM KxVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jktg4lAS; 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 r11si8135773eja.61.2021.07.15.14.10.26; Thu, 15 Jul 2021 14:10:49 -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=Jktg4lAS; 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 S245353AbhGOTXT (ORCPT + 99 others); Thu, 15 Jul 2021 15:23:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240781AbhGOTGw (ORCPT ); Thu, 15 Jul 2021 15:06:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6055613FC; Thu, 15 Jul 2021 19:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375771; bh=rE2I+zLwsbpaEuctbbzq6PE3wDxXGryaBpIQXgqGLUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jktg4lASSaIHon1GhYx5+1j4HBiv5qqXQPWIbBkSW01aU1ZIQhlULJNmxtXyA/ABk 0BkfQ/yNei45uHLxm+JmWbCTV2BZTutKrbEc2Xh/0t5GDoHZHVhN4FkN5slwP4Im5D qMtSyjAYbqjYldVNSYwpUMIUvglCkcYtOB+V7JkA= 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.12 229/242] media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K Date: Thu, 15 Jul 2021 20:39:51 +0200 Message-Id: <20210715182633.209501250@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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];