* [PATCH v3] media: i2c: imx219: Implement get_selection
@ 2020-04-28 21:09 Jacopo Mondi
2020-04-28 21:35 ` Sakari Ailus
0 siblings, 1 reply; 3+ messages in thread
From: Jacopo Mondi @ 2020-04-28 21:09 UTC (permalink / raw)
To: dave.stevenson, laurent.pinchart, linux-media
Cc: Jacopo Mondi, mchehab, sakari.ailus, hverkuil-cisco
Implement the get_selection pad operation for the IMX219 sensor driver.
The supported targets report the sensor's native size, the crop default
rectangle and the crop rectangle.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
v2->v3:
- Guard with critical section only the V4L2_SEL_TGT_CROP case
v1->v2:
- Add crop rectangle fro 640x480 mode
- Re-order rectangle fields
---
drivers/media/i2c/imx219.c | 99 ++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index cb03bdec1f9c..2916709a4ea3 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -112,6 +112,14 @@
#define IMX219_TESTP_BLUE_DEFAULT 0
#define IMX219_TESTP_GREENB_DEFAULT 0
+/* IMX219 native and active pixel array size. */
+#define IMX219_NATIVE_WIDTH 3296U
+#define IMX219_NATIVE_HEIGHT 2480U
+#define IMX219_PIXEL_ARRAY_LEFT 8U
+#define IMX219_PIXEL_ARRAY_TOP 8U
+#define IMX219_PIXEL_ARRAY_WIDTH 3280U
+#define IMX219_PIXEL_ARRAY_HEIGHT 2464U
+
struct imx219_reg {
u16 address;
u8 val;
@@ -129,6 +137,9 @@ struct imx219_mode {
/* Frame height */
unsigned int height;
+ /* Analog crop rectangle. */
+ struct v4l2_rect crop;
+
/* V-timing */
unsigned int vts_def;
@@ -463,6 +474,12 @@ static const struct imx219_mode supported_modes[] = {
/* 8MPix 15fps mode */
.width = 3280,
.height = 2464,
+ .crop = {
+ .left = 0,
+ .top = 0,
+ .width = 3280,
+ .height = 2464
+ },
.vts_def = IMX219_VTS_15FPS,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_3280x2464_regs),
@@ -473,6 +490,12 @@ static const struct imx219_mode supported_modes[] = {
/* 1080P 30fps cropped */
.width = 1920,
.height = 1080,
+ .crop = {
+ .left = 680,
+ .top = 692,
+ .width = 1920,
+ .height = 1080
+ },
.vts_def = IMX219_VTS_30FPS_1080P,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_1920_1080_regs),
@@ -483,6 +506,12 @@ static const struct imx219_mode supported_modes[] = {
/* 2x2 binned 30fps mode */
.width = 1640,
.height = 1232,
+ .crop = {
+ .left = 0,
+ .top = 0,
+ .width = 3280,
+ .height = 2464
+ },
.vts_def = IMX219_VTS_30FPS_BINNED,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_1640_1232_regs),
@@ -493,6 +522,12 @@ static const struct imx219_mode supported_modes[] = {
/* 640x480 30fps mode */
.width = 640,
.height = 480,
+ .crop = {
+ .left = 1000,
+ .top = 752,
+ .width = 1280,
+ .height = 960
+ },
.vts_def = IMX219_VTS_30FPS_640x480,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_640_480_regs),
@@ -654,6 +689,7 @@ static int imx219_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
struct imx219 *imx219 = to_imx219(sd);
struct v4l2_mbus_framefmt *try_fmt =
v4l2_subdev_get_try_format(sd, fh->pad, 0);
+ struct v4l2_rect *try_crop;
mutex_lock(&imx219->mutex);
@@ -664,6 +700,13 @@ static int imx219_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
MEDIA_BUS_FMT_SRGGB10_1X10);
try_fmt->field = V4L2_FIELD_NONE;
+ /* Initialize try_crop rectangle. */
+ try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0);
+ try_crop->top = IMX219_PIXEL_ARRAY_TOP;
+ try_crop->left = IMX219_PIXEL_ARRAY_LEFT;
+ try_crop->width = IMX219_PIXEL_ARRAY_WIDTH;
+ try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT;
+
mutex_unlock(&imx219->mutex);
return 0;
@@ -928,6 +971,61 @@ static int imx219_set_framefmt(struct imx219 *imx219)
return -EINVAL;
}
+static const struct v4l2_rect *
+__imx219_get_pad_crop(struct imx219 *imx219, struct v4l2_subdev_pad_config *cfg,
+ unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+ switch (which) {
+ case V4L2_SUBDEV_FORMAT_TRY:
+ return v4l2_subdev_get_try_crop(&imx219->sd, cfg, pad);
+ case V4L2_SUBDEV_FORMAT_ACTIVE:
+ return &imx219->mode->crop;
+ default:
+ return NULL;
+ }
+}
+
+static int imx219_get_selection(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_selection *sel)
+{
+ struct imx219 *imx219 = to_imx219(sd);
+ const struct v4l2_rect *__crop;
+ int ret = 0;
+
+ if (sel->pad != 0)
+ return -EINVAL;
+
+ switch (sel->target) {
+ case V4L2_SEL_TGT_NATIVE_SIZE:
+ sel->r.top = 0;
+ sel->r.left = 0;
+ sel->r.width = IMX219_NATIVE_WIDTH;
+ sel->r.height = IMX219_NATIVE_HEIGHT;
+
+ return 0;
+
+ case V4L2_SEL_TGT_CROP_DEFAULT:
+ sel->r.top = IMX219_PIXEL_ARRAY_TOP;
+ sel->r.left = IMX219_PIXEL_ARRAY_LEFT;
+ sel->r.width = IMX219_PIXEL_ARRAY_WIDTH;
+ sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT;
+
+ return 0;
+
+ case V4L2_SEL_TGT_CROP:
+ mutex_lock(&imx219->mutex);
+ __crop = __imx219_get_pad_crop(imx219, cfg, sel->pad,
+ sel->which);
+ sel->r = *__crop;
+ mutex_unlock(&imx219->mutex);
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static int imx219_start_streaming(struct imx219 *imx219)
{
struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
@@ -1152,6 +1250,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = {
.enum_mbus_code = imx219_enum_mbus_code,
.get_fmt = imx219_get_pad_format,
.set_fmt = imx219_set_pad_format,
+ .get_selection = imx219_get_selection,
.enum_frame_size = imx219_enum_frame_size,
};
--
2.26.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] media: i2c: imx219: Implement get_selection
2020-04-28 21:09 [PATCH v3] media: i2c: imx219: Implement get_selection Jacopo Mondi
@ 2020-04-28 21:35 ` Sakari Ailus
2020-04-29 7:06 ` Jacopo Mondi
0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2020-04-28 21:35 UTC (permalink / raw)
To: Jacopo Mondi
Cc: dave.stevenson, laurent.pinchart, linux-media, mchehab, hverkuil-cisco
Hi Jacopo,
On Tue, Apr 28, 2020 at 11:09:03PM +0200, Jacopo Mondi wrote:
> Implement the get_selection pad operation for the IMX219 sensor driver.
> The supported targets report the sensor's native size, the crop default
> rectangle and the crop rectangle.
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
>
> ---
> v2->v3:
> - Guard with critical section only the V4L2_SEL_TGT_CROP case
>
> v1->v2:
> - Add crop rectangle fro 640x480 mode
> - Re-order rectangle fields
> ---
>
> drivers/media/i2c/imx219.c | 99 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 99 insertions(+)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index cb03bdec1f9c..2916709a4ea3 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -112,6 +112,14 @@
> #define IMX219_TESTP_BLUE_DEFAULT 0
> #define IMX219_TESTP_GREENB_DEFAULT 0
>
> +/* IMX219 native and active pixel array size. */
> +#define IMX219_NATIVE_WIDTH 3296U
> +#define IMX219_NATIVE_HEIGHT 2480U
> +#define IMX219_PIXEL_ARRAY_LEFT 8U
> +#define IMX219_PIXEL_ARRAY_TOP 8U
> +#define IMX219_PIXEL_ARRAY_WIDTH 3280U
> +#define IMX219_PIXEL_ARRAY_HEIGHT 2464U
> +
> struct imx219_reg {
> u16 address;
> u8 val;
> @@ -129,6 +137,9 @@ struct imx219_mode {
> /* Frame height */
> unsigned int height;
>
> + /* Analog crop rectangle. */
> + struct v4l2_rect crop;
> +
> /* V-timing */
> unsigned int vts_def;
>
> @@ -463,6 +474,12 @@ static const struct imx219_mode supported_modes[] = {
> /* 8MPix 15fps mode */
> .width = 3280,
> .height = 2464,
> + .crop = {
> + .left = 0,
> + .top = 0,
> + .width = 3280,
> + .height = 2464
> + },
> .vts_def = IMX219_VTS_15FPS,
> .reg_list = {
> .num_of_regs = ARRAY_SIZE(mode_3280x2464_regs),
> @@ -473,6 +490,12 @@ static const struct imx219_mode supported_modes[] = {
> /* 1080P 30fps cropped */
> .width = 1920,
> .height = 1080,
> + .crop = {
> + .left = 680,
> + .top = 692,
> + .width = 1920,
> + .height = 1080
> + },
> .vts_def = IMX219_VTS_30FPS_1080P,
> .reg_list = {
> .num_of_regs = ARRAY_SIZE(mode_1920_1080_regs),
> @@ -483,6 +506,12 @@ static const struct imx219_mode supported_modes[] = {
> /* 2x2 binned 30fps mode */
> .width = 1640,
> .height = 1232,
> + .crop = {
> + .left = 0,
> + .top = 0,
> + .width = 3280,
> + .height = 2464
> + },
> .vts_def = IMX219_VTS_30FPS_BINNED,
> .reg_list = {
> .num_of_regs = ARRAY_SIZE(mode_1640_1232_regs),
> @@ -493,6 +522,12 @@ static const struct imx219_mode supported_modes[] = {
> /* 640x480 30fps mode */
> .width = 640,
> .height = 480,
> + .crop = {
> + .left = 1000,
> + .top = 752,
> + .width = 1280,
> + .height = 960
> + },
> .vts_def = IMX219_VTS_30FPS_640x480,
> .reg_list = {
> .num_of_regs = ARRAY_SIZE(mode_640_480_regs),
> @@ -654,6 +689,7 @@ static int imx219_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> struct imx219 *imx219 = to_imx219(sd);
> struct v4l2_mbus_framefmt *try_fmt =
> v4l2_subdev_get_try_format(sd, fh->pad, 0);
> + struct v4l2_rect *try_crop;
>
> mutex_lock(&imx219->mutex);
>
> @@ -664,6 +700,13 @@ static int imx219_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
> MEDIA_BUS_FMT_SRGGB10_1X10);
> try_fmt->field = V4L2_FIELD_NONE;
>
> + /* Initialize try_crop rectangle. */
> + try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0);
> + try_crop->top = IMX219_PIXEL_ARRAY_TOP;
> + try_crop->left = IMX219_PIXEL_ARRAY_LEFT;
> + try_crop->width = IMX219_PIXEL_ARRAY_WIDTH;
> + try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT;
> +
> mutex_unlock(&imx219->mutex);
>
> return 0;
> @@ -928,6 +971,61 @@ static int imx219_set_framefmt(struct imx219 *imx219)
> return -EINVAL;
> }
>
> +static const struct v4l2_rect *
> +__imx219_get_pad_crop(struct imx219 *imx219, struct v4l2_subdev_pad_config *cfg,
> + unsigned int pad, enum v4l2_subdev_format_whence which)
> +{
> + switch (which) {
> + case V4L2_SUBDEV_FORMAT_TRY:
> + return v4l2_subdev_get_try_crop(&imx219->sd, cfg, pad);
> + case V4L2_SUBDEV_FORMAT_ACTIVE:
> + return &imx219->mode->crop;
> + default:
> + return NULL;
> + }
> +}
> +
> +static int imx219_get_selection(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_selection *sel)
> +{
> + struct imx219 *imx219 = to_imx219(sd);
> + const struct v4l2_rect *__crop;
> + int ret = 0;
ret is unused.
> +
> + if (sel->pad != 0)
> + return -EINVAL;
As you only have a single pad (0), this check is redundant --- the caller
will have done that check already.
> +
> + switch (sel->target) {
> + case V4L2_SEL_TGT_NATIVE_SIZE:
> + sel->r.top = 0;
> + sel->r.left = 0;
> + sel->r.width = IMX219_NATIVE_WIDTH;
> + sel->r.height = IMX219_NATIVE_HEIGHT;
> +
> + return 0;
> +
> + case V4L2_SEL_TGT_CROP_DEFAULT:
> + sel->r.top = IMX219_PIXEL_ARRAY_TOP;
> + sel->r.left = IMX219_PIXEL_ARRAY_LEFT;
> + sel->r.width = IMX219_PIXEL_ARRAY_WIDTH;
> + sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT;
> +
> + return 0;
> +
> + case V4L2_SEL_TGT_CROP:
> + mutex_lock(&imx219->mutex);
> + __crop = __imx219_get_pad_crop(imx219, cfg, sel->pad,
> + sel->which);
> + sel->r = *__crop;
> + mutex_unlock(&imx219->mutex);
> +
> + return 0;
> + }
> +
> + return -EINVAL;
> +}
> +
> static int imx219_start_streaming(struct imx219 *imx219)
> {
> struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
> @@ -1152,6 +1250,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = {
> .enum_mbus_code = imx219_enum_mbus_code,
> .get_fmt = imx219_get_pad_format,
> .set_fmt = imx219_set_pad_format,
> + .get_selection = imx219_get_selection,
> .enum_frame_size = imx219_enum_frame_size,
> };
>
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] media: i2c: imx219: Implement get_selection
2020-04-28 21:35 ` Sakari Ailus
@ 2020-04-29 7:06 ` Jacopo Mondi
0 siblings, 0 replies; 3+ messages in thread
From: Jacopo Mondi @ 2020-04-29 7:06 UTC (permalink / raw)
To: Sakari Ailus
Cc: dave.stevenson, laurent.pinchart, linux-media, mchehab, hverkuil-cisco
Hi Sakari
getting to v4 for such a trivial change is a bit embarassing -.-'
On Wed, Apr 29, 2020 at 12:35:02AM +0300, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Tue, Apr 28, 2020 at 11:09:03PM +0200, Jacopo Mondi wrote:
> > +static int imx219_get_selection(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_pad_config *cfg,
> > + struct v4l2_subdev_selection *sel)
> > +{
> > + struct imx219 *imx219 = to_imx219(sd);
> > + const struct v4l2_rect *__crop;
> > + int ret = 0;
>
> ret is unused.
>
ouch, sorry this was trivial.
> > +
> > + if (sel->pad != 0)
> > + return -EINVAL;
>
> As you only have a single pad (0), this check is redundant --- the caller
> will have done that check already.
>
I see, makes sense to remove it indeed
v4 on its way, maybe this time I can get it right
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-29 7:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 21:09 [PATCH v3] media: i2c: imx219: Implement get_selection Jacopo Mondi
2020-04-28 21:35 ` Sakari Ailus
2020-04-29 7:06 ` Jacopo Mondi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.