diff mbox

[2/5] media: ov7670: make try_fmt() consistent with 'min_height' and 'min_width'.

Message ID 1348652877-25816-3-git-send-email-javier.martin@vista-silicon.com (mailing list archive)
State New, archived
Headers show

Commit Message

Javier Martin Sept. 26, 2012, 9:47 a.m. UTC
'min_height' and 'min_width' are variables that allow to specify the minimum
resolution that the sensor will achieve. This patch make v4l2 fmt callbacks
consider this parameters in order to return valid data to user space.

Signed-off-by: Javier Martin <javier.martin@vista-silicon.com>
---
 drivers/media/i2c/ov7670.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Jonathan Corbet Sept. 26, 2012, 4:42 p.m. UTC | #1
On Wed, 26 Sep 2012 11:47:54 +0200
Javier Martin <javier.martin@vista-silicon.com> wrote:

> 'min_height' and 'min_width' are variables that allow to specify the minimum
> resolution that the sensor will achieve. This patch make v4l2 fmt callbacks
> consider this parameters in order to return valid data to user space.
> 
I'd have preferred to do this differently, perhaps backing toward larger
sizes if the minimum turns out to be violated.  But so be it...

Acked-by: Jonathan Corbet <corbet@lwn.net>

jon
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Javier Martin Sept. 27, 2012, 7 a.m. UTC | #2
On 26 September 2012 18:42, Jonathan Corbet <corbet@lwn.net> wrote:
> On Wed, 26 Sep 2012 11:47:54 +0200
> Javier Martin <javier.martin@vista-silicon.com> wrote:
>
>> 'min_height' and 'min_width' are variables that allow to specify the minimum
>> resolution that the sensor will achieve. This patch make v4l2 fmt callbacks
>> consider this parameters in order to return valid data to user space.
>>
> I'd have preferred to do this differently, perhaps backing toward larger
> sizes if the minimum turns out to be violated.  But so be it...
>
> Acked-by: Jonathan Corbet <corbet@lwn.net>
>
> jon

Thank you. I will have to modify this patch slightly when I fix the
previous one though.
diff mbox

Patch

diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 0478a7b..627fe5f 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -812,10 +812,11 @@  static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
 		struct ov7670_format_struct **ret_fmt,
 		struct ov7670_win_size **ret_wsize)
 {
-	int index;
+	int index, i;
 	struct ov7670_win_size *wsize;
 	struct ov7670_info *info = to_state(sd);
 	int n_win_sizes = ARRAY_SIZE(ov7670_win_sizes[info->model]);
+	int win_sizes_limit = n_win_sizes;
 
 	for (index = 0; index < N_OV7670_FMTS; index++)
 		if (ov7670_formats[index].mbus_code == fmt->code)
@@ -831,15 +832,30 @@  static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
 	 * Fields: the OV devices claim to be progressive.
 	 */
 	fmt->field = V4L2_FIELD_NONE;
+
+	/*
+	 * Don't consider values that don't match min_height and min_width
+	 * constraints.
+	 */
+	if (info->min_width || info->min_height)
+		for (i = 0; i < n_win_sizes; i++) {
+			wsize = ov7670_win_sizes[info->model] + i;
+
+			if (wsize->width < info->min_width ||
+				wsize->height < info->min_height) {
+				win_sizes_limit = i;
+				break;
+			}
+		}
 	/*
 	 * Round requested image size down to the nearest
 	 * we support, but not below the smallest.
 	 */
 	for (wsize = ov7670_win_sizes[info->model];
-	     wsize < ov7670_win_sizes[info->model] + n_win_sizes; wsize++)
+	     wsize < ov7670_win_sizes[info->model] + win_sizes_limit; wsize++)
 		if (fmt->width >= wsize->width && fmt->height >= wsize->height)
 			break;
-	if (wsize >= ov7670_win_sizes[info->model] + n_win_sizes)
+	if (wsize >= ov7670_win_sizes[info->model] + win_sizes_limit)
 		wsize--;   /* Take the smallest one */
 	if (ret_wsize != NULL)
 		*ret_wsize = wsize;