devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Xavier Roumegue (OSS)" <xavier.roumegue@oss.nxp.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	mchehab@kernel.org, stanimir.varbanov@linaro.org,
	laurent.pinchart@ideasonboard.com,
	tomi.valkeinen@ideasonboard.com, robh+dt@kernel.org,
	nicolas@ndufresne.ca, alexander.stein@ew.tq-group.com,
	ezequiel@vanguardiasur.com.ar
Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v9 7/8] media: dw100: Add i.MX8MP dw100 dewarper driver
Date: Sat, 30 Jul 2022 14:21:57 +0200	[thread overview]
Message-ID: <2df18385-c975-eeab-40b7-7ebfaad8f378@oss.nxp.com> (raw)
In-Reply-To: <5fdb62df-da1a-2c68-aaed-18a394f5f4ba@xs4all.nl>

Hello Hans,

On 7/30/22 12:49, Hans Verkuil wrote:
> Hi Xavier,
> 
> On 30/07/2022 12:24, Xavier Roumegue wrote:
>> Add a V4L2 mem-to-mem driver for the Vivante DW100 Dewarp Processor IP
>> core found on i.MX8MP SoC.
>>
>> The processor core applies a programmable geometrical transformation on
>> input images to correct distorsion introduced by lenses.
>> The transformation function is exposed as a grid map with 16x16 pixel
>> macroblocks indexed using X, Y vertex coordinates.
>>
>> The dewarping map can be set from application through a dedicated v4l2
>> control. If not set or invalid, the driver computes an identity map
>> prior to starting the processing engine.
>>
>> The driver supports scaling, cropping and pixel format conversion.
>>
>> Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
>> Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>> ---
>>   drivers/media/platform/nxp/Kconfig            |    1 +
>>   drivers/media/platform/nxp/Makefile           |    1 +
>>   drivers/media/platform/nxp/dw100/Kconfig      |   17 +
>>   drivers/media/platform/nxp/dw100/Makefile     |    3 +
>>   drivers/media/platform/nxp/dw100/dw100.c      | 1712 +++++++++++++++++
>>   drivers/media/platform/nxp/dw100/dw100_regs.h |  117 ++
>>   6 files changed, 1851 insertions(+)
>>   create mode 100644 drivers/media/platform/nxp/dw100/Kconfig
>>   create mode 100644 drivers/media/platform/nxp/dw100/Makefile
>>   create mode 100644 drivers/media/platform/nxp/dw100/dw100.c
>>   create mode 100644 drivers/media/platform/nxp/dw100/dw100_regs.h
>>
> 
> <snip>
> 
>> +/*
>> + * Initialize the dewarping map with an identity mapping.
>> + *
>> + * A 16 pixels cell size grid is mapped on the destination image.
>> + * The last cells width/height might be lesser than 16 if the destination image
>> + * width/height is not divisible by 16. This dewarping grid map specifies the
>> + * source image pixel location (x, y) on each grid intersection point.
>> + * Bilinear interpolation is used to compute inner cell points locations.
>> + *
>> + * The coordinates are saved in UQ12.4 fixed point format.
>> + */
>> +static void dw100_ctrl_dewarping_map_init(const struct v4l2_ctrl *ctrl,
>> +					  u32 from_idx, u32 elems,
>> +					  union v4l2_ctrl_ptr ptr)
>> +{
>> +	struct dw100_ctx *ctx =
>> +		container_of(ctrl->handler, struct dw100_ctx, hdl);
>> +
>> +	u32 sw, sh, dw, dh, mw, mh, i, j;
>> +	u16 qx, qy, qdx, qdy, qsh, qsw;
>> +	u32 *map = ctrl->p_cur.p_u32;
>> +
>> +	sw = ctx->q_data[DW100_QUEUE_SRC].pix_fmt.width;
>> +	dw = ctx->q_data[DW100_QUEUE_DST].pix_fmt.width;
>> +	sh = ctx->q_data[DW100_QUEUE_SRC].pix_fmt.height;
>> +	dh = ctx->q_data[DW100_QUEUE_DST].pix_fmt.height;
>> +
>> +	mw = dw100_get_n_vertices_from_length(dw);
>> +	mh = dw100_get_n_vertices_from_length(dh);
> 
> Note that ctrl->dims[] contains the array dimensions: use that rather than
> calculating from dw/dh since using dims[] is more robust.
> 
>> +
>> +	qsw = dw100_map_convert_to_uq12_4(sw);
>> +	qsh = dw100_map_convert_to_uq12_4(sh);
>> +	qdx = qsw / (mw - 1);
>> +	qdy = qsh / (mh - 1);
>> +
>> +	ctx->map_width = mw;
>> +	ctx->map_height = mh;
>> +	ctx->map_size = mh * mw * sizeof(u32);
>> +
>> +	for (i = 0, qy = 0; i < mh; i++, qy += qdy) {
> 
> This isn't correct: you actually start from 'from_idx', which is almost always 0,
> except if userspace only sets the first N elements of an array, in that case
> those N elements are copied to the control array and the remainder is initialized.
> 
> I admit that it doesn't make much sense in this particular case, but you still
> need to take it into account.
Right, but it was done on purpose.It's incorrect from the driver 
perspective to initialize partially the dewarping map as this can lead 
to hardware hang up. Strictly speaking, accepting partial update would 
force the driver to verify each individual pixel has been properly set 
prior to start the streaming - which is not reasonable. API/semantic 
wise, if init() is intended to be used as "set_range()", this might 
rather makes more sense to add a dedicated set_range() callback, and 
limit init() use for initializing the entire control range.

Having said that, I can implement as per your suggestions but I will not 
implement sanity checks and error handling in case v4l2-ctrl api and/or 
userspace have not initialized properly the mapping, i.e. partial 
update, assuming that v4l2-ctrl api will always call init() for the 
whole range on its first call.

> 
> I also would rename i and j to y and x, that makes more sense here.
Indeed, but as from_idx/elems involves a 1D handling, the loop index 
will become idx.
> 
>> +		if (qy > qsh)
>> +			qy = qsh;
>> +		for (j = 0, qx = 0; j < mw; j++, qx += qdx) {
>> +			if (qx > qsw)
>> +				qx = qsw;
>> +			*map++ = dw100_map_format_coordinates(qx, qy);
>> +		}
>> +	}
>> +
>> +	ctx->user_map_is_set = false;
>> +}
> 
> Regards,
> 
> 	Hans
> 
Regards.
   Xavier

  reply	other threads:[~2022-07-30 12:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30 10:24 [PATCH v9 0/8] i.MX8MP DW100 dewarper driver Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 1/8] v4l2-ctrls: optimize type_ops for arrays Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 2/8] v4l2-ctrls: Export default v4l2_ctrl_type_ops callbacks Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 3/8] media: Documentation: dw100: Add user documentation for the DW100 driver Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 4/8] media: v4l: uapi: Add user control base for DW100 controls Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 5/8] media: uapi: Add a control for DW100 driver Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 6/8] media: dt-bindings: media: Add i.MX8MP DW100 binding Xavier Roumegue
2022-07-30 10:24 ` [PATCH v9 7/8] media: dw100: Add i.MX8MP dw100 dewarper driver Xavier Roumegue
2022-07-30 10:49   ` Hans Verkuil
2022-07-30 12:21     ` Xavier Roumegue (OSS) [this message]
2022-07-30 10:24 ` [PATCH v9 8/8] media: MAINTAINERS: add entry for i.MX8MP DW100 v4l2 mem2mem driver Xavier Roumegue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2df18385-c975-eeab-40b7-7ebfaad8f378@oss.nxp.com \
    --to=xavier.roumegue@oss.nxp.com \
    --cc=alexander.stein@ew.tq-group.com \
    --cc=devicetree@vger.kernel.org \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=robh+dt@kernel.org \
    --cc=stanimir.varbanov@linaro.org \
    --cc=tomi.valkeinen@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).