From patchwork Wed Apr 3 19:58:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Bauer via B4 Relay X-Patchwork-Id: 13616620 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFE34155755; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; cv=none; b=HmTvX+Sb/uCmCttsUzgfXT11X1+oTfQ9J853WBjEzkDqbV58Yd/Ob4F4a/68oOUSPmtkJQ4R95Pim61gCsQ3AGNsWaJYloX363m6Kstejo8M1oejm1mcMSdVL1nuArsztzqFtJfDRQlQx05iTP5f5xj8ylotj88waLnvGFO0Nik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; c=relaxed/simple; bh=40uh/wKUId8Vzuahx/WopdPsq9bSrg4TfoGpA2V/BrE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FFQvjdtfrSMEvNhjzHO5upHzdRF8h2nfXayQdEKbrfj8ZnvfG6e3uinG2cbi95a3a7s97KUhtSwtssjkyVCJTtUIlDnLW69G3ppxFIk/CsXXLRC2q86GqiMJkmfEheRMa5YtNTWrDJjrMisZUsRj4DX8Uo2qpwQq4G7UG5vPbYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mc7Z8ZwZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mc7Z8ZwZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4FEBEC433F1; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712174306; bh=40uh/wKUId8Vzuahx/WopdPsq9bSrg4TfoGpA2V/BrE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mc7Z8ZwZoEo7fY9eOEmoJPFBJBnUxwWtuMstgMLv9obTygRm7wZeGZNalZUbRVcFC kplY32jru+rKFfbpMLZ8xz7MazXEWJCfOtJmSryDRBN9hOytQYF5PqNVoqheRL//w5 pvh8iBXCCH73q75333bjaprz5bd1G4B9TOIGG6UxXsM55e1Z4VQzI0fpJz2avgGHXi jhawDM6I7tnHSiZaG6VOBzZulnWGnMPxh2PkfRxasJj/mXoQD4C/rrZ706aaKBlPxc wf/PjsjDrDSUoTWmvLnso4dgWbJKpKKCYwZqMcYzp9JQxN7fr1jKIKxNQKsNV4y8tD EO1/K9efnSdRw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39EBFCD1288; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) From: John Bauer via B4 Relay Date: Wed, 03 Apr 2024 14:58:07 -0500 Subject: [PATCH 1/3] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240403-uvc-fix-relative-ptz-speed-v1-1-624c9267f745@securitylive.com> References: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> In-Reply-To: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linh.tp.vu@gmail.com, ribalda@chromium.org, soyer@irl.hu, John Bauer X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712174305; l=2495; i=johnebgood@securitylive.com; s=20240325; h=from:subject:message-id; bh=QZxJ8IkQ+0S1QgP+EtdvdygUUbw+bFRKj/oMsKdGp5w=; b=uUDdtIbM/Iiu2FN1XodBx73FkpXtnAmxQXh9J+cIFGTHjyXDcY402bq0qlgqRZZwR4mHQ7qqN bnaBCLaMwDXA8JygZkJyHJPYEC5MYfnxCmXqVeCD3MN4/nc+CM7L6MD X-Developer-Key: i=johnebgood@securitylive.com; a=ed25519; pk=RN31Fmrxbidp1TwtZGNmQwTDjUWMPnewQJfA/ug2P9E= X-Endpoint-Received: by B4 Relay for johnebgood@securitylive.com/20240325 with auth_id=143 X-Original-From: John Bauer Reply-To: johnebgood@securitylive.com From: John Bauer The minimum UVC control value for the relative pan/tilt/zoom speeds cannot be probed as the implementation condenses the pan and tilt direction and speed into two 16 bit values. The minimum cannot be set at probe time because it is probed first and the maximum is not yet known. With this fix if a relative speed control is queried or set the minimum is set and checked based on the additive inverse of the maximum at that time. Signed-off-by: John Bauer --- drivers/media/usb/uvc/uvc_ctrl.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index e59a463c2761..b389ab3ee05d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1322,9 +1322,25 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, break; } - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) - v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) { + switch (v4l2_ctrl->id) { + case V4L2_CID_ZOOM_CONTINUOUS: + case V4L2_CID_PAN_SPEED: + case V4L2_CID_TILT_SPEED: + /* + * For the relative speed implementation the minimum + * value cannot be probed so it becomes the additive + * inverse of maximum. + */ + v4l2_ctrl->minimum = -1 * mapping->get(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + break; + default: + v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + break; + } + } if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, @@ -1914,6 +1930,21 @@ int uvc_ctrl_set(struct uvc_fh *handle, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); max = mapping->get(mapping, UVC_GET_MAX, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + + /* + * For the relative speed implementation the minimum + * value cannot be probed so it becomes the additive + * inverse of maximum. + */ + switch (xctrl->id) { + case V4L2_CID_ZOOM_CONTINUOUS: + case V4L2_CID_PAN_SPEED: + case V4L2_CID_TILT_SPEED: + min = max * -1; + default: + break; + } + step = mapping->get(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); if (step == 0) From patchwork Wed Apr 3 19:58:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Bauer via B4 Relay X-Patchwork-Id: 13616619 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B0AA155753; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; cv=none; b=RzQsDqUY3/8P+I5m+7l9oub2e7vNNPPVqhhV8PDp69dIMfUebQmG4ZoY4arFe5YLAc37HLBQLy6ZaVRbZ03A4LSFdFyrWlpjSo8yH1lfR1CcI2h6csVp3V+zJ6ode1iAKLZohOq5wuFgOSaZePkJQZrRpl3p71lk4Adpjr3v0yQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; c=relaxed/simple; bh=ufR+0iHCmEICheDCukK6osbbIBOdgkBNn3yKED5Aw2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I7+50tZRChc/lcT/vtjzjitgCPtSAohIrDIy5Pa+zbxnvhSquGFOVnHRHBnmSc9462CoBiZvV4CAx1H3msQvKy/hWqDbapb8nxTN/wLH2eBIB+XIsuFPjiTy1wE7ajXiWm7vNzQ5hWtG3gJDFaQkR1/j9Xoj0oqr2keVCpy8q1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ozy/iK1u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ozy/iK1u" Received: by smtp.kernel.org (Postfix) with ESMTPS id 56232C43399; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712174306; bh=ufR+0iHCmEICheDCukK6osbbIBOdgkBNn3yKED5Aw2E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ozy/iK1uxFAo3jgwMa8FTA2qfb4vGjJQUtDVWtFHwZdaU2EmwDUPcDozrvU9HKKqP RHByqs0qO2iAr3J5gljKWxwNaDDSltjQoJX0Me1+1xojzFyUuynJjJteYHmz/aEPQQ 4gzfz/lq/PJ9eTMW4tEhjSzPY9F0ZQHfo9pZjZbbbmVf8BPnYc0WSqO8k4YU0RvJWl ifHuvfa+I8JRn9cKqbRT1gmOwaDr6AzO63O/xuJdSa4rJ2qsTAprg3Y4hA/rm5OL5D P/oyGbvBqQl5XHb1l5ZTQf/O3H8hRv0DfsDOQS4hI3ISkO/Nea62R0oIYCRUFGeMd0 zVHWoxY9XK/ng== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48DDFCD1299; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) From: John Bauer via B4 Relay Date: Wed, 03 Apr 2024 14:58:08 -0500 Subject: [PATCH 2/3] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240403-uvc-fix-relative-ptz-speed-v1-2-624c9267f745@securitylive.com> References: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> In-Reply-To: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linh.tp.vu@gmail.com, ribalda@chromium.org, soyer@irl.hu, John Bauer X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712174305; l=2237; i=johnebgood@securitylive.com; s=20240325; h=from:subject:message-id; bh=XaPSPVobhTGsOxP+SRJcTVrPmARlAP4ikC9wTaKg0Fw=; b=pCd2bn9MLzzfJObg+LGhmAA/y7OKa/cYDJqI58Jva6YEELnlKpa+7FsgXS4EJ9XW0+7eazURY V+EaB3xg7KfBeYqsRyAUMfHDiF83T2CgL/6+t+7KnFhS78zvRIdy3nJ X-Developer-Key: i=johnebgood@securitylive.com; a=ed25519; pk=RN31Fmrxbidp1TwtZGNmQwTDjUWMPnewQJfA/ug2P9E= X-Endpoint-Received: by B4 Relay for johnebgood@securitylive.com/20240325 with auth_id=143 X-Original-From: John Bauer Reply-To: johnebgood@securitylive.com From: John Bauer Made recommended changes from Ricardo. I explored the case where the minimum could be > 0 but less than the maximum. If this were to occur the range of -maximum to maximum would still apply correctly however there would be a range from -min to min that would possibly not apply. It would be possible to capture the probed minimum and check against that when setting the controls. Signed-off-by: John Bauer --- drivers/media/usb/uvc/uvc_ctrl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b389ab3ee05d..04300a782c81 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1322,6 +1322,10 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, break; } + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) + v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) { switch (v4l2_ctrl->id) { case V4L2_CID_ZOOM_CONTINUOUS: @@ -1332,8 +1336,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, * value cannot be probed so it becomes the additive * inverse of maximum. */ - v4l2_ctrl->minimum = -1 * mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + v4l2_ctrl->minimum = -v4l2_ctrl->maximum; break; default: v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, @@ -1342,10 +1345,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, } } - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) - v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); @@ -1940,7 +1939,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, case V4L2_CID_ZOOM_CONTINUOUS: case V4L2_CID_PAN_SPEED: case V4L2_CID_TILT_SPEED: - min = max * -1; + min = -max; default: break; } From patchwork Wed Apr 3 19:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Bauer via B4 Relay X-Patchwork-Id: 13616621 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFDE71553BA; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; cv=none; b=PEIIOJucOmmqrSo8QVjSsuxR6kc+kXOuFLRDW3T5txYPZ0csHmEjUCGSaflVRHRXyXoLOqAkIKovme5xmcDDX10Qx4oEqazClhhDz3p/SaOXle+YC883c8bJdS/njYjNBkPw9EbP0VEOhjY6umowpZl/xM5dj3WNf/MeH7UJSkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712174306; c=relaxed/simple; bh=ZolPI/SXOoFRlsyA2xZ/MLjL4K5rdMbF7iCV+sPToAk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KPmCcUCUc10kG4/JULHFtj+waa+vVgGzCwfzsuOj4Myan9qHasYqzmEfyciV0yPBUZI9T8Zqza36dfyv4VdxjljM2+50rAwHh+mf1q1fMXgD6fGCtzbwT1pD8jqDa0JczPHxlbjT/qkmg+NUg3RsV5pm4jYLVuU4GbEOTNmeIFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DCxaN5Zv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DCxaN5Zv" Received: by smtp.kernel.org (Postfix) with ESMTPS id 61B79C433A6; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712174306; bh=ZolPI/SXOoFRlsyA2xZ/MLjL4K5rdMbF7iCV+sPToAk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DCxaN5ZvrL7/ojIbXsbJ8aeApY/jESwu3jMVvhco88jNo1zYd8RnULzubi7I45Iyr S98AmEEO3ie1jLlYw4mBm4VzSdNrHgLtcIEevu7Y3LJ+Z6A1m32EY/6h0KGggTU8me dHoNt6PiLhQavARzPr8K2X82IiGhu8GoRFUvl8k1mYGe4ibN+PxoTy2gy2sITlvesZ jt3KG3DQs2KkGfqG1sB5Tn+6Dfr1Bf/rTKhJsnLONBQqsneLB8iyEFP1d5MZIyuQKT Gu6uijcRoeC9A75//hhkkYyze48RRxgRgGMpbTja9wPiUxdmyhKVjg2SesmcvF5RwX MxDY2UO7vZ1bA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57305CD129B; Wed, 3 Apr 2024 19:58:26 +0000 (UTC) From: John Bauer via B4 Relay Date: Wed, 03 Apr 2024 14:58:09 -0500 Subject: [PATCH 3/3] media: uvcvideo: Moved control checks to helper function Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240403-uvc-fix-relative-ptz-speed-v1-3-624c9267f745@securitylive.com> References: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> In-Reply-To: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linh.tp.vu@gmail.com, ribalda@chromium.org, soyer@irl.hu, John Bauer X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712174305; l=2692; i=johnebgood@securitylive.com; s=20240325; h=from:subject:message-id; bh=2nl53Ftu6Hpf35R3FNa8JPbVSTHm2rJO1iLfSKB2ysg=; b=BhLEBiU0ZU86ee4ynGsqy1lFJdDPqxN8ydK1MeNxTyyuxPXHnWaLEAdFaP4ffI6z2Y/HjSzDy AyLB7FWoRxJDQTr3AuakRSnCoM6/nkz7NOiXW7IvPBYLDKLc86/p+QM X-Developer-Key: i=johnebgood@securitylive.com; a=ed25519; pk=RN31Fmrxbidp1TwtZGNmQwTDjUWMPnewQJfA/ug2P9E= X-Endpoint-Received: by B4 Relay for johnebgood@securitylive.com/20240325 with auth_id=143 X-Original-From: John Bauer Reply-To: johnebgood@securitylive.com From: John Bauer Made additional recommended changes from Ricardo. Relative controls are now checked with helper function is_relative_ptz_ctrl(). Signed-off-by: John Bauer --- drivers/media/usb/uvc/uvc_ctrl.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 04300a782c81..34a9a29b0754 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -441,7 +441,6 @@ static s32 uvc_ctrl_get_rel_speed(struct uvc_control_mapping *mapping, return (rel == 0) ? 0 : (rel > 0 ? data[first+1] : -data[first+1]); case UVC_GET_MIN: - return -data[first+1]; case UVC_GET_MAX: case UVC_GET_RES: case UVC_GET_DEF: @@ -1233,6 +1232,17 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *ctrl, return ~0; } +static bool is_relative_ptz_ctrl(__u32 ctrl_id) +{ + switch (ctrl_id) { + case V4L2_CID_ZOOM_CONTINUOUS: + case V4L2_CID_PAN_SPEED: + case V4L2_CID_TILT_SPEED: + return true; + } + return false; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1327,22 +1337,16 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) { - switch (v4l2_ctrl->id) { - case V4L2_CID_ZOOM_CONTINUOUS: - case V4L2_CID_PAN_SPEED: - case V4L2_CID_TILT_SPEED: - /* - * For the relative speed implementation the minimum - * value cannot be probed so it becomes the additive - * inverse of maximum. - */ + /* + * For the relative speed implementation the minimum + * value cannot be probed so it becomes the additive + * inverse of maximum. + */ + if (is_relative_ptz_ctrl(v4l2_ctrl->id)) v4l2_ctrl->minimum = -v4l2_ctrl->maximum; - break; - default: + else v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); - break; - } } if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) @@ -1935,14 +1939,8 @@ int uvc_ctrl_set(struct uvc_fh *handle, * value cannot be probed so it becomes the additive * inverse of maximum. */ - switch (xctrl->id) { - case V4L2_CID_ZOOM_CONTINUOUS: - case V4L2_CID_PAN_SPEED: - case V4L2_CID_TILT_SPEED: + if (is_relative_ptz_ctrl(xctrl->id)) min = -max; - default: - break; - } step = mapping->get(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));