From patchwork Wed Mar 21 08:42:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todor Tomov X-Patchwork-Id: 132194 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1870222ljb; Wed, 21 Mar 2018 01:43:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELvlStcP6Q75LSsRuDrff0vcLuELImixuGJoXhBKmiZQRwIJtBTEdvhAQ/13hpyvLjQeOhHm X-Received: by 10.99.158.9 with SMTP id s9mr14425195pgd.64.1521621780968; Wed, 21 Mar 2018 01:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521621780; cv=none; d=google.com; s=arc-20160816; b=z+UKibz6IezbS4CJqpDm3zf6cft+8kHpuDAZ3rdOPuer6jpwK9K20dpHaaMQWdSwxd l5w0XhWYx5nYiQAy9Jpu4oJPsZyITeGPniZ4G5K4SH6TUB9MV/BRQUA9+s5kjeGIOrTX yHKX08ej9hawce4SG93LR3cp1EBn7Ckwz3IEYK6PGY/LaZm1MGtGqAh+VtA3EklMebc+ bm73Rw3o9+v54DdTVu+mR5W/L6tUD/IS3RbTBzb1BZsJB6BPMt1VcPAs8sJrmMSt486L cTomc9rOKRa9A8sFbv/3KBAGAZFJSfjbZKgeoyDr5kfDNcUVtXXZirUwWxoNkBIrJkab qjtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jqKwrd7iJQcEsrNWn+jX9jtwT93Xgz//8ZkOu0qjZIs=; b=A+DJpjYi61hppA1lZQCumQ6UPjmBpYn77ROoU7jE3p4wvkKF7wcyPxLCcLRxseiNw7 tCexJgP9qMtRNB+f1zIJQbSeNPQysrV5rJTYYEZG6Xrr4+4Gud1QmTg5YiY4nYjmnDmv 8aijospuNJtSf4prqME6Z5+g9hGH/b6jA+BaDiYoRt9ehjQqn5fdzJqwfVlZcsXxRG/Q klnh/Yj2e73iS1nu62j/quZmRHzpVYbxFGho3KWBMyWLR8E4bCkPE6jXHVC8A2WfYQEk oDBtEkSrDXCw206ewmiZ1yRQvsFgId6TC2zCvagzQU3q4ssceKdUypl4moOd4zUMVYc3 +VCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si2420207pgv.255.2018.03.21.01.43.00; Wed, 21 Mar 2018 01:43:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751526AbeCUIm6 (ORCPT + 5 others); Wed, 21 Mar 2018 04:42:58 -0400 Received: from ns.mm-sol.com ([37.157.136.199]:44522 "EHLO extserv.mm-sol.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751423AbeCUIm5 (ORCPT ); Wed, 21 Mar 2018 04:42:57 -0400 Received: from localhost.localdomain (unknown [218.255.99.6]) by extserv.mm-sol.com (Postfix) with ESMTPSA id C727CCCD5; Wed, 21 Mar 2018 10:42:53 +0200 (EET) From: Todor Tomov To: sakari.ailus@linux.intel.com, linux-media@vger.kernel.org Cc: mchehab@kernel.org, Todor Tomov Subject: [PATCH] media: ov5645: Use v4l2_find_nearest_size Date: Wed, 21 Mar 2018 16:42:36 +0800 Message-Id: <1521621756-20360-1-git-send-email-todor.tomov@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use v4l2_find_nearest_size instead of a driver specific function to find nearest matching size. Signed-off-by: Todor Tomov --- This depends on [1] from Sakari. Thank you, Sakari, this is nice. [1] https://git.linuxtv.org/sailus/media_tree.git/commit/?h=v4l2-common-size&id=83fdb8a0ab43fc86c329f63f1052e6113871a965 drivers/media/i2c/ov5645.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index d28845f..79db74c 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -959,23 +959,6 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct v4l2_subdev_pad_config *cfg, } } -static const struct ov5645_mode_info * -ov5645_find_nearest_mode(unsigned int width, unsigned int height) -{ - int i; - - for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) { - if (ov5645_mode_info_data[i].width <= width && - ov5645_mode_info_data[i].height <= height) - break; - } - - if (i < 0) - i = 0; - - return &ov5645_mode_info_data[i]; -} - static int ov5645_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) @@ -989,8 +972,11 @@ static int ov5645_set_format(struct v4l2_subdev *sd, __crop = __ov5645_get_pad_crop(ov5645, cfg, format->pad, format->which); - new_mode = ov5645_find_nearest_mode(format->format.width, - format->format.height); + new_mode = v4l2_find_nearest_size(ov5645_mode_info_data, + ARRAY_SIZE(ov5645_mode_info_data), + width, height, + format->format.width, format->format.height); + __crop->width = new_mode->width; __crop->height = new_mode->height;