From patchwork Thu Sep 27 15:38:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martin X-Patchwork-Id: 1515021 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 1656ADF266 for ; Thu, 27 Sep 2012 15:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755401Ab2I0Piq (ORCPT ); Thu, 27 Sep 2012 11:38:46 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:57703 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755182Ab2I0Pil (ORCPT ); Thu, 27 Sep 2012 11:38:41 -0400 Received: by weyt9 with SMTP id t9so705989wey.19 for ; Thu, 27 Sep 2012 08:38:40 -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=bd5Md++WwgpIazmcj7YmFnK6XolTN0/ODKts9IrgYnU=; b=UXY84EC65TMTf1t5tlUN+FBHE82caWfLvfLwoUWVF8VqRfAt1CqKONa0BROYFbRN8m Ehz5ZxIdXWQHiykxZCeKa3ix5lyILKaFpheVz/vrmbp448f0h6kH5P6oUL8qY+Rs/T5O /hdmmKr15QFTqA4tCrPrt34jGuR5dyeAUNtRpESVqbLi+9v5t9nhUELPpEQlmpaVKwHj jK/9+VVbIkL+7+QfubzFO9fIyh07dXzb4/oIlQkAmqwbmTPdmhlY3fM1RROLMTjkfxtL 02JftrxiJDo/wPxbys8OP0ThnoUPXNoMrTTfTTgdbp+ft0grlmxtOJEohANXpeYmgMtc yXzQ== Received: by 10.180.87.34 with SMTP id u2mr37492978wiz.3.1348760320584; Thu, 27 Sep 2012 08:38:40 -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 eu4sm31740434wib.2.2012.09.27.08.38.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 08:38:40 -0700 (PDT) From: Javier Martin To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl, rusty@rustcorp.com.au, dsd@laptop.org, mchehab@infradead.org, corbet@lwn.net, hdegoede@redhat.com, Javier Martin Subject: [PATCH v2 2/5] media: ov7670: make try_fmt() consistent with 'min_height' and 'min_width'. Date: Thu, 27 Sep 2012 17:38:22 +0200 Message-Id: <1348760305-7481-3-git-send-email-javier.martin@vista-silicon.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348760305-7481-1-git-send-email-javier.martin@vista-silicon.com> References: <1348760305-7481-1-git-send-email-javier.martin@vista-silicon.com> X-Gm-Message-State: ALoCoQlzv1Xi7SzgRSnnuLMzyKuW8p6sA9igOpuRfSup7/SpjyBYFzh+/8gT5866vJX1s5ktfUJT 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. Acked-by: Jonathan Corbet Signed-off-by: Javier Martin --- 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 17eb5d7..3eaa06c 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -786,10 +786,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); unsigned int n_win_sizes = info->devtype->n_win_sizes; + unsigned int win_sizes_limit = n_win_sizes; for (index = 0; index < N_OV7670_FMTS; index++) if (ov7670_formats[index].mbus_code == fmt->code) @@ -805,15 +806,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 = info->devtype->win_sizes + 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 = info->devtype->win_sizes; - wsize < info->devtype->win_sizes + n_win_sizes; wsize++) + wsize < info->devtype->win_sizes + win_sizes_limit; wsize++) if (fmt->width >= wsize->width && fmt->height >= wsize->height) break; - if (wsize >= info->devtype->win_sizes + n_win_sizes) + if (wsize >= info->devtype->win_sizes + win_sizes_limit) wsize--; /* Take the smallest one */ if (ret_wsize != NULL) *ret_wsize = wsize;