diff mbox series

[v2,1/2] media: uvcvideo: Add a UVC_FIVAL_DENOM define

Message ID 20250106140923.56896-2-hdegoede@redhat.com
State New
Headers show
Series media: uvc: limit max bandwidth for HDMI capture | expand

Commit Message

Hans de Goede Jan. 6, 2025, 2:09 p.m. UTC
Add a define for the UVC frame interval denominator of 10000000
instead of hardcoding 10000000 everywhere.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/usb/uvc/uvc_driver.c |  4 ++--
 drivers/media/usb/uvc/uvc_v4l2.c   | 16 ++++++++--------
 drivers/media/usb/uvc/uvc_video.c  |  4 ++--
 drivers/media/usb/uvc/uvcvideo.h   |  2 ++
 4 files changed, 14 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index c3ccd9be0a47..f754640fddf5 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -320,8 +320,8 @@  static int uvc_parse_frame(struct uvc_device *dev,
 
 	uvc_dbg(dev, DESCR, "- %ux%u (%u.%u fps)\n",
 		frame->wWidth, frame->wHeight,
-		10000000 / frame->dwDefaultFrameInterval,
-		(100000000 / frame->dwDefaultFrameInterval) % 10);
+		UVC_FIVAL_DENOM / frame->dwDefaultFrameInterval,
+		((UVC_FIVAL_DENOM * 10) / frame->dwDefaultFrameInterval) % 10);
 
 	*intervals += n;
 
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 93c6cdb23881..301999e94759 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -282,8 +282,8 @@  static int uvc_v4l2_try_format(struct uvc_streaming *stream,
 	interval = frame->dwDefaultFrameInterval;
 	uvc_dbg(stream->dev, FORMAT,
 		"Using default frame interval %u.%u us (%u.%u fps)\n",
-		interval / 10, interval % 10, 10000000 / interval,
-		(100000000 / interval) % 10);
+		interval / 10, interval % 10, UVC_FIVAL_DENOM / interval,
+		((UVC_FIVAL_DENOM * 10) / interval) % 10);
 
 	/* Set the format index, frame index and frame interval. */
 	memset(probe, 0, sizeof(*probe));
@@ -450,7 +450,7 @@  static int uvc_ioctl_g_parm(struct file *file, void *fh,
 	numerator = stream->ctrl.dwFrameInterval;
 	mutex_unlock(&stream->mutex);
 
-	denominator = 10000000;
+	denominator = UVC_FIVAL_DENOM;
 	v4l2_simplify_fraction(&numerator, &denominator, 8, 333);
 
 	memset(parm, 0, sizeof(*parm));
@@ -551,7 +551,7 @@  static int uvc_ioctl_s_parm(struct file *file, void *fh,
 
 	/* Return the actual frame period. */
 	timeperframe.numerator = probe.dwFrameInterval;
-	timeperframe.denominator = 10000000;
+	timeperframe.denominator = UVC_FIVAL_DENOM;
 	v4l2_simplify_fraction(&timeperframe.numerator,
 		&timeperframe.denominator, 8, 333);
 
@@ -1240,17 +1240,17 @@  static int uvc_ioctl_enum_frameintervals(struct file *file, void *fh,
 		fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
 		fival->discrete.numerator =
 			frame->dwFrameInterval[index];
-		fival->discrete.denominator = 10000000;
+		fival->discrete.denominator = UVC_FIVAL_DENOM;
 		v4l2_simplify_fraction(&fival->discrete.numerator,
 			&fival->discrete.denominator, 8, 333);
 	} else {
 		fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
 		fival->stepwise.min.numerator = frame->dwFrameInterval[0];
-		fival->stepwise.min.denominator = 10000000;
+		fival->stepwise.min.denominator = UVC_FIVAL_DENOM;
 		fival->stepwise.max.numerator = frame->dwFrameInterval[1];
-		fival->stepwise.max.denominator = 10000000;
+		fival->stepwise.max.denominator = UVC_FIVAL_DENOM;
 		fival->stepwise.step.numerator = frame->dwFrameInterval[2];
-		fival->stepwise.step.denominator = 10000000;
+		fival->stepwise.step.denominator = UVC_FIVAL_DENOM;
 		v4l2_simplify_fraction(&fival->stepwise.min.numerator,
 			&fival->stepwise.min.denominator, 8, 333);
 		v4l2_simplify_fraction(&fival->stepwise.max.numerator,
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 7efed64b81a2..41cb1b45fa23 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -231,7 +231,7 @@  static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 		u32 interval;
 		u32 bandwidth;
 
-		interval = (ctrl->dwFrameInterval > 100000)
+		interval = (ctrl->dwFrameInterval > (UVC_FIVAL_DENOM / 100))
 			 ? ctrl->dwFrameInterval
 			 : frame->dwFrameInterval[0];
 
@@ -243,7 +243,7 @@  static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
 		 * header size (assumed to be 12 bytes long).
 		 */
 		bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
-		bandwidth *= 10000000 / interval + 1;
+		bandwidth *= UVC_FIVAL_DENOM / interval + 1;
 		bandwidth /= 1000;
 		if (stream->dev->udev->speed >= USB_SPEED_HIGH)
 			bandwidth /= 8;
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 3d196a696f46..966ff82c2ba8 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -41,6 +41,8 @@ 
 #define UVC_EXT_GPIO_UNIT		0x7ffe
 #define UVC_EXT_GPIO_UNIT_ID		0x100
 
+#define UVC_FIVAL_DENOM			10000000
+
 /* ------------------------------------------------------------------------
  * Driver specific constants.
  */