From patchwork Fri Dec 11 14:14:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 69961 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1knjD8-00FK9e-Ef; Fri, 11 Dec 2020 14:15:55 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405459AbgLKOPQ (ORCPT + 1 other); Fri, 11 Dec 2020 09:15:16 -0500 Received: from relay12.mail.gandi.net ([217.70.178.232]:50949 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405910AbgLKOPE (ORCPT ); Fri, 11 Dec 2020 09:15:04 -0500 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 4914C200007; Fri, 11 Dec 2020 14:14:21 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, sakari.ailus@linux.intel.com Cc: Jacopo Mondi , tfiga@chromium.org, linux-media@vger.kernel.org Subject: [PATCH 1/2] media: i2c: ov13858: Add .get_selection support Date: Fri, 11 Dec 2020 15:14:23 +0100 Message-Id: <20201211141424.277975-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201211141424.277975-1-jacopo@jmondi.org> References: <20201211141424.277975-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Add support for the get_selection subdev pad operation. Support the V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUNDS static targets only to report the active pixel array size. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov13858.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c index 2f3be7a80cef4..5cda917e10569 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -82,6 +82,10 @@ /* Number of frames to skip */ #define OV13858_NUM_OF_SKIP_FRAMES 2 +/* OV13858 pixel array size. */ +#define OV13858_PIXEL_ARRAY_WIDTH 4256 +#define OV13858_PIXEL_ARRAY_HEIGHT 3168 + struct ov13858_reg { u16 address; u8 val; @@ -1152,6 +1156,7 @@ static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); + struct v4l2_rect *try_crop; mutex_lock(&ov13858->mutex); @@ -1161,6 +1166,13 @@ static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; try_fmt->field = V4L2_FIELD_NONE; + /* Initialize try_crop */ + try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0); + try_crop->top = 0; + try_crop->left = 0; + try_crop->width = OV13858_PIXEL_ARRAY_WIDTH; + try_crop->height = OV13858_PIXEL_ARRAY_HEIGHT; + /* No crop or compose */ mutex_unlock(&ov13858->mutex); @@ -1402,6 +1414,24 @@ ov13858_set_pad_format(struct v4l2_subdev *sd, return 0; } +static int ov13858_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + switch (sel->target) { + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = OV13858_PIXEL_ARRAY_WIDTH; + sel->r.height = OV13858_PIXEL_ARRAY_HEIGHT; + + return 0; + } + + return -EINVAL; +} + static int ov13858_get_skip_frames(struct v4l2_subdev *sd, u32 *frames) { *frames = OV13858_NUM_OF_SKIP_FRAMES; @@ -1563,6 +1593,7 @@ static const struct v4l2_subdev_pad_ops ov13858_pad_ops = { .enum_mbus_code = ov13858_enum_mbus_code, .get_fmt = ov13858_get_pad_format, .set_fmt = ov13858_set_pad_format, + .get_selection = ov13858_get_selection, .enum_frame_size = ov13858_enum_frame_size, }; From patchwork Fri Dec 11 14:14:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 69962 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1knjDN-00FK9e-JQ; Fri, 11 Dec 2020 14:16:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405903AbgLKOPn (ORCPT + 1 other); Fri, 11 Dec 2020 09:15:43 -0500 Received: from relay12.mail.gandi.net ([217.70.178.232]:42039 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405911AbgLKOPF (ORCPT ); Fri, 11 Dec 2020 09:15:05 -0500 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B1B59200006; Fri, 11 Dec 2020 14:14:22 +0000 (UTC) From: Jacopo Mondi To: mchehab@kernel.org, sakari.ailus@linux.intel.com Cc: Jacopo Mondi , tfiga@chromium.org, linux-media@vger.kernel.org Subject: [PATCH 2/2] media: i2c: ov5670: Add .get_selection support Date: Fri, 11 Dec 2020 15:14:24 +0100 Message-Id: <20201211141424.277975-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201211141424.277975-1-jacopo@jmondi.org> References: <20201211141424.277975-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Add support for the get_selection subdev pad operation. Support the V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUNDS static targets only to report the active pixel array size. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov5670.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 148fd4e05029a..7f85ae1d93faf 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -67,6 +67,10 @@ /* Initial number of frames to skip to avoid possible garbage */ #define OV5670_NUM_OF_SKIP_FRAMES 2 +/* OV5670 pixel array size. */ +#define OV5670_PIXEL_ARRAY_WIDTH 2592 +#define OV5670_PIXEL_ARRAY_HEIGHT 1944 + struct ov5670_reg { u16 address; u8 val; @@ -1938,6 +1942,7 @@ static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) struct ov5670 *ov5670 = to_ov5670(sd); struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); + struct v4l2_rect *try_crop; mutex_lock(&ov5670->mutex); @@ -1947,7 +1952,13 @@ static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; try_fmt->field = V4L2_FIELD_NONE; - /* No crop or compose */ + /* Initialize try_crop */ + try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0); + try_crop->top = 0; + try_crop->left = 0; + try_crop->width = OV5670_PIXEL_ARRAY_WIDTH; + try_crop->height = OV5670_PIXEL_ARRAY_HEIGHT; + mutex_unlock(&ov5670->mutex); return 0; @@ -2263,6 +2274,24 @@ static int ov5670_set_pad_format(struct v4l2_subdev *sd, return 0; } +static int ov5670_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + switch (sel->target) { + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = OV5670_PIXEL_ARRAY_WIDTH; + sel->r.height = OV5670_PIXEL_ARRAY_HEIGHT; + + return 0; + } + + return -EINVAL; +} + static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames) { *frames = OV5670_NUM_OF_SKIP_FRAMES; @@ -2428,6 +2457,7 @@ static const struct v4l2_subdev_pad_ops ov5670_pad_ops = { .enum_mbus_code = ov5670_enum_mbus_code, .get_fmt = ov5670_get_pad_format, .set_fmt = ov5670_set_pad_format, + .get_selection = ov5670_get_selection, .enum_frame_size = ov5670_enum_frame_size, };