Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp36915imm; Tue, 22 May 2018 13:32:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo+UvmRuWG7wqwbtLsWevh/SelJlRntkImnw/83UHLQuq2Fn56bxUr4n4fg+utoVE397hBU X-Received: by 2002:a62:c615:: with SMTP id m21-v6mr25526869pfg.232.1527021177108; Tue, 22 May 2018 13:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527021177; cv=none; d=google.com; s=arc-20160816; b=kXbzr7DspZg+MITovzZ5ns7YPupBkuurApdvmx4kE3gY8nBeFd+CvBh278Z9uvx6Ed RMXLyCCnPTPc2QYclcHpWG3U0H9tOIVAW4ooSSODcUSg5MKDmlh1dwaayt24NHX/X9R8 QwsUDXQyrd9CC9d4jmQ0yMjKbM5JZToRI1RD/rGUFCZEveMt0COnGnk5bFbgI2/ueDzS V+8dO7skdVQHNIDgWLEwFKd5V72NE/QglHsSkuQO0JL1LFrI2+sx1jo1pspdWo8w6Z3Q 8ON4oKhuYibTVvdUsUju9aAAuShNjIwtdyFDFjQajZ/9FggfK4Fy3NimTHNqPKgEmNiz k23w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=bz5419EmqQ9UObZjXA0M6rqcEk/+0TRMMM+PKrKGk4k=; b=UR4F9S1GNOYUvt3qiX5os2eHzTLeEyaP3Ef4/RMpY0YSadEqCI/ipbP/XGTkd4+eKD lnwibMRYkiMX6QVcSeQAJtYxPqsObkeuB2OQfEajxmQJor9v1zJNqTAgFpBOu1AZG1Ze xtJ1nfKn3N4T6XV+4fX+OuEalGKPhNr/IhBPEUH03gpYnt7/iWM1zX32gNzHTF7DWZf8 k1Bj7We6ODOne44ydfcXU5qVDX3ZxLol5hlCq5vGSBnpHnQ+kxw7219KnvAU4Cndh0T7 MLrc3It9OnyyAGHtY12k+BwTn0HgjgfnhKUcdVyzhnfe3wkzkP0/ZhQZK7pdvbuF5a4e Rh2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ChePLqDD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n20-v6si672591plp.298.2018.05.22.13.32.42; Tue, 22 May 2018 13:32:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ChePLqDD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbeEVUcZ (ORCPT + 99 others); Tue, 22 May 2018 16:32:25 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:35282 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751748AbeEVUcY (ORCPT ); Tue, 22 May 2018 16:32:24 -0400 Received: from avalon.localnet (unknown [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84BF61332; Tue, 22 May 2018 22:32:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1527021141; bh=HOa3MPEBZklXoj23HJSuAYS3tjgBeXhYfOmWSu2jxBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ChePLqDDvELGjmXhTAc4460VwDGCfioYCHMSkqbIXSOb5eMIrwEYoXXX8pl/T3mc1 7a4/5a2CPu628xu8TyGtcqPcdhpDz4aUGKhBubtOHNaDfodRM0SMVaZiMqK7YuA2TR GP4X938JkU5zMDPaplf8fTWZAVFIIa6kpqFtdxOM= From: Laurent Pinchart To: ming_qian@realsil.com.cn Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kai-Heng Feng , Hans de Goede , Ana Guerrero Lopez Subject: Re: [PATCH] media: uvcvideo: Support realtek's UVC 1.5 device Date: Tue, 22 May 2018 23:32:19 +0300 Message-ID: <2510852.fx2XduE8hM@avalon> Organization: Ideas on Board Oy In-Reply-To: <1525831988-32017-1-git-send-email-ming_qian@realsil.com.cn> References: <1525831988-32017-1-git-send-email-ming_qian@realsil.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Thank you for the patch. On Wednesday, 9 May 2018 05:13:08 EEST ming_qian@realsil.com.cn wrote: > From: ming_qian > > The length of UVC 1.5 video control is 48, and it id 34 for UVC 1.1. > Change it to 48 for UVC 1.5 device, > and the UVC 1.5 device can be recognized. > > More changes to the driver are needed for full UVC 1.5 compatibility. > However, at least the UVC 1.5 Realtek RTS5847/RTS5852 cameras have > been reported to work well. This patch is however not specific to Realtek devices, so I think we should make the subject line more generic. It's fine mentioning in the commit message itself that the Realtek RTS5847/RTS5852 cameras have been successfully tested. > Signed-off-by: ming_qian > --- > drivers/media/usb/uvc/uvc_video.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_video.c > b/drivers/media/usb/uvc/uvc_video.c index aa0082f..32dfb32 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -171,6 +171,8 @@ static int uvc_get_video_ctrl(struct uvc_streaming > *stream, int ret; > > size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; > + if (stream->dev->uvc_version >= 0x0150) > + size = 48; > if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && > query == UVC_GET_DEF) > return -EIO; > @@ -259,6 +261,8 @@ static int uvc_set_video_ctrl(struct uvc_streaming > *stream, int ret; > > size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; > + if (stream->dev->uvc_version >= 0x0150) > + size = 48; > data = kzalloc(size, GFP_KERNEL); > if (data == NULL) > return -ENOMEM; Instead of duplicating the computation in both functions, I think we should move the code to a helper function. Furthermore there are equality checks further down both functions that compare the size to 34, they should be updated to also support UVC 1.5. I propose the following updated patch. If you're fine with it there's no need to resubmit, I'll queue it for v4.19. I have dropped the Reviewed-by and Tested-by tags as the patch has changed. commit a9c002732695eab2096580a0d1a1687bc2f95928 Author: ming_qian Date: Wed May 9 10:13:08 2018 +0800 media: uvcvideo: Support UVC 1.5 video probe & commit controls The length of UVC 1.5 video control is 48, and it is 34 for UVC 1.1. Change it to 48 for UVC 1.5 device, and the UVC 1.5 device can be recognized. More changes to the driver are needed for full UVC 1.5 compatibility. However, at least the UVC 1.5 Realtek RTS5847/RTS5852 cameras have been reported to work well. Cc: stable@vger.kernel.org Signed-off-by: ming_qian [Factor out code to helper function, update size checks] Signed-off-by: Laurent Pinchart diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index eb9e04a59427..285b0e813b9d 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -207,14 +207,27 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, } } +static size_t uvc_video_ctrl_size(struct uvc_streaming *stream) +{ + /* + * Return the size of the video probe and commit controls, which depends + * on the protocol version. + */ + if (stream->dev->uvc_version < 0x0110) + return 26; + else if (stream->dev->uvc_version < 0x0150) + return 34; + else + return 48; +} + static int uvc_get_video_ctrl(struct uvc_streaming *stream, struct uvc_streaming_control *ctrl, int probe, u8 query) { + u16 size = uvc_video_ctrl_size(stream); u8 *data; - u16 size; int ret; - size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && query == UVC_GET_DEF) return -EIO; @@ -271,7 +284,7 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream, ctrl->dwMaxVideoFrameSize = get_unaligned_le32(&data[18]); ctrl->dwMaxPayloadTransferSize = get_unaligned_le32(&data[22]); - if (size == 34) { + if (size >= 34) { ctrl->dwClockFrequency = get_unaligned_le32(&data[26]); ctrl->bmFramingInfo = data[30]; ctrl->bPreferedVersion = data[31]; @@ -300,11 +313,10 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream, static int uvc_set_video_ctrl(struct uvc_streaming *stream, struct uvc_streaming_control *ctrl, int probe) { + u16 size = uvc_video_ctrl_size(stream); u8 *data; - u16 size; int ret; - size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; data = kzalloc(size, GFP_KERNEL); if (data == NULL) return -ENOMEM; @@ -321,7 +333,7 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream, put_unaligned_le32(ctrl->dwMaxVideoFrameSize, &data[18]); put_unaligned_le32(ctrl->dwMaxPayloadTransferSize, &data[22]); - if (size == 34) { + if (size >= 34) { put_unaligned_le32(ctrl->dwClockFrequency, &data[26]); data[30] = ctrl->bmFramingInfo; data[31] = ctrl->bPreferedVersion; -- Regards, Laurent Pinchart