From patchwork Wed Sep 26 09:47:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martin X-Patchwork-Id: 1508721 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5EDEFDF238 for ; Wed, 26 Sep 2012 09:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754210Ab2IZJsS (ORCPT ); Wed, 26 Sep 2012 05:48:18 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:47851 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753358Ab2IZJsR (ORCPT ); Wed, 26 Sep 2012 05:48:17 -0400 Received: by wibhr7 with SMTP id hr7so481354wib.1 for ; Wed, 26 Sep 2012 02:48:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=KRSzt/0ytHW+N4OqUcT9v3i5RIec5N+qS10myudWH04=; b=ViNPZo8HrC3ItgYlP09mutHwJit+sMouwHFF78KpH0Q4d5cdHrt3tpxHFt/24GnddF rjUoi+tNgxtD1gJg+gI9xiascyCaHhWcJE5ixq9rFa3wz+d2bwYSjFlmpC8spg9WzPUw 0mbXSNekHi7j/epCgEOnci7qZPNNFmxMibs5fPswd2UExMrffe2CryRzb/6lYdt584Er D737FNIxSdSNywyCMvE9epueUlU/C0zxz5pEaaXj6vW7J2U6+4qbe3Wy9jUMUQF7tuT3 9Tjr5p3TiuXca3NWooHiljIpWnIKTTG7v6bFUj57iB8pNQfLdlLh8OelDTGbUgarKKHk ueyA== Received: by 10.180.107.163 with SMTP id hd3mr13544wib.19.1348652896168; Wed, 26 Sep 2012 02:48:16 -0700 (PDT) Received: from piscis.vsilicon.net (122.251.106.212.dynamic.jazztel.es. [212.106.251.122]) by mx.google.com with ESMTPS id bn7sm5826230wib.8.2012.09.26.02.48.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 02:48:15 -0700 (PDT) From: Javier Martin To: linux-media@vger.kernel.org Cc: corbet@lwn.net, mchehab@infradead.org, hverkuil@xs4all.nl, Javier Martin Subject: [PATCH 2/5] media: ov7670: make try_fmt() consistent with 'min_height' and 'min_width'. Date: Wed, 26 Sep 2012 11:47:54 +0200 Message-Id: <1348652877-25816-3-git-send-email-javier.martin@vista-silicon.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348652877-25816-1-git-send-email-javier.martin@vista-silicon.com> References: <1348652877-25816-1-git-send-email-javier.martin@vista-silicon.com> X-Gm-Message-State: ALoCoQm8vDm7fzGrvAvQ24FpfUX2e7lOfX2NtfrmKGx6YxZGyVtNCebQ3wq7xF+LE6Ce8TdAYDyZ Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org '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 Acked-by: Jonathan Corbet --- drivers/media/i2c/ov7670.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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;