Skip to contentSkip to conversation

em28xx: introduce #define for maximum supported scaling values (register 0x30-0x33)

PATCH New Frank Schäfer 1 participant 4 messages Feb 10, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 em28xx: introduce #define for maximum supported scaling values (register 0x30-0x33)

The maximum supported scaling value for registers 0x30+0x31 (horizontal scaling) and 0x32+0x33 (vertical scaling) is 0x3fff, which corresponds to 20% of the input frame size.

---
 drivers/media/usb/em28xx/em28xx-reg.h   |    2 ++
 drivers/media/usb/em28xx/em28xx-video.c |    8 ++++----

2 Dateien geändert, 6 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/usb/em28xx/em28xx-reg.h +2 -0
index 885089e..0a3cb04 100644
@@ -152,6 +152,8 @@
 #define EM28XX_R31_HSCALEHIGH	0x31
 #define EM28XX_R32_VSCALELOW	0x32
 #define EM28XX_R33_VSCALEHIGH	0x33
+#define   EM28XX_HVSCALE_MAX	0x3fff /* => 20% */
+
 #define EM28XX_R34_VBI_START_H	0x34
 #define EM28XX_R35_VBI_START_V	0x35
 #define EM28XX_R36_VBI_WIDTH	0x36
drivers/media/usb/em28xx/em28xx-video.c +4 -4
index 6d26123..9451e1e 100644
@@ -807,12 +807,12 @@ static void get_scale(struct em28xx *dev,
 	unsigned int          maxh = norm_maxh(dev);
 
 	*hscale = (((unsigned long)maxw) << 12) / width - 4096L;
-	if (*hscale >= 0x4000)
-		*hscale = 0x3fff;
+	if (*hscale > EM28XX_HVSCALE_MAX)
+		*hscale = EM28XX_HVSCALE_MAX;
 
 	*vscale = (((unsigned long)maxh) << 12) / height - 4096L;
-	if (*vscale >= 0x4000)
-		*vscale = 0x3fff;
+	if (*vscale > EM28XX_HVSCALE_MAX)
+		*vscale = EM28XX_HVSCALE_MAX;
 }
 
 /* ------------------------------------------------------------------
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/4 em28xx: rename function get_scale() to size_to_scale()

---
 drivers/media/usb/em28xx/em28xx-video.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/usb/em28xx/em28xx-video.c +4 -4
index 9451e1e..197823c 100644
@@ -799,7 +799,7 @@ const struct v4l2_ctrl_ops em28xx_ctrl_ops = {
 	.s_ctrl = em28xx_s_ctrl,
 };
 
-static void get_scale(struct em28xx *dev,
+static void size_to_scale(struct em28xx *dev,
 			unsigned int width, unsigned int height,
 			unsigned int *hscale, unsigned int *vscale)
 {
@@ -889,7 +889,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 				      1, 0);
 	}
 
-	get_scale(dev, width, height, &hscale, &vscale);
+	size_to_scale(dev, width, height, &hscale, &vscale);
 
 	width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
 	height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
@@ -923,7 +923,7 @@ static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
 	dev->height = height;
 
 	/* set new image size */
-	get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
+	size_to_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
 
 	em28xx_resolution_set(dev);
 
@@ -986,7 +986,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
 	/* set new image size */
 	dev->width = f.fmt.pix.width;
 	dev->height = f.fmt.pix.height;
-	get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
+	size_to_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
 
 	em28xx_resolution_set(dev);
 	v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 3/4 em28xx: add function scale_to_size()

In reply to Frank Schäfer
---
 drivers/media/usb/em28xx/em28xx-video.c |   15 ++++++++++++---

1 Datei geändert, 12 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

drivers/media/usb/em28xx/em28xx-video.c +12 -3
index 197823c..f745617 100644
@@ -815,6 +815,17 @@ static void size_to_scale(struct em28xx *dev,
 		*vscale = EM28XX_HVSCALE_MAX;
 }
 
+static void scale_to_size(struct em28xx *dev,
+			  unsigned int hscale, unsigned int vscale,
+			  unsigned int *width, unsigned int *height)
+{
+	unsigned int          maxw = norm_maxw(dev);
+	unsigned int          maxh = norm_maxh(dev);
+
+	*width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
+	*height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
+}
+
 /* ------------------------------------------------------------------
 	IOCTL vidioc handling
    ------------------------------------------------------------------*/
@@ -890,9 +901,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 	}
 
 	size_to_scale(dev, width, height, &hscale, &vscale);
-
-	width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
-	height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
+	scale_to_size(dev, hscale, hscale, &width, &height);
 
 	f->fmt.pix.width = width;
 	f->fmt.pix.height = height;
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 4/4 em28xx: VIDIOC_ENUM_FRAMESIZES: consider the scaler limits when calculating the minimum frame size

In reply to Frank Schäfer

Output resolutions <=20% of the input resolution exceed the capabilities of the scaler.

---
 drivers/media/usb/em28xx/em28xx-video.c |    8 ++++++--

1 Datei geändert, 6 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

drivers/media/usb/em28xx/em28xx-video.c +6 -2
index f745617..86fd907 100644
@@ -1405,8 +1405,12 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
 
 	/* Report a continuous range */
 	fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
-	fsize->stepwise.min_width = 48;
-	fsize->stepwise.min_height = 32;
+	scale_to_size(dev, EM28XX_HVSCALE_MAX, EM28XX_HVSCALE_MAX,
+		      &fsize->stepwise.min_width, &fsize->stepwise.min_height);
+	if (fsize->stepwise.min_width < 48)
+		fsize->stepwise.min_width = 48;
+	if (fsize->stepwise.min_height < 38)
+		fsize->stepwise.min_height = 38;
 	fsize->stepwise.max_width = maxw;
 	fsize->stepwise.max_height = maxh;
 	fsize->stepwise.step_width = 1;
Signature · 1 line
1.7.10.4