From: Jerry-ch Chen <Jerry-ch.Chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: Tomasz Figa <tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: "devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"Sean Cheng (鄭昇弘)"
<Sean.Cheng-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
"laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org"
<laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>,
"Rynn Wu (吳育恩)" <Rynn.Wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
srv_heupstream
<srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
"Po-Yang Huang (黃柏陽)"
<po-yang.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
"mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org"
<mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"suleiman-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org"
<suleiman-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
"shik-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org"
<shik-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
"Jungo Lin (林明俊)"
<jungo.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
"Sj Huang (黃信璋)"
<sj.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
"yuzhao-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org"
<yuzhao-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
"linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
<linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
zwisler-F7+t8E8rja8pug/h7KTFAQ@public.gmane.org
Subject: Re: [RFC PATCH V2 4/4] platform: mtk-isp: Add Mediatek FD driver
Date: Tue, 3 Sep 2019 19:46:09 +0800 [thread overview]
Message-ID: <1567511169.18318.65.camel@mtksdccf07> (raw)
In-Reply-To: <CAAFQd5DWM=R7sFHYGhhR_rXrzgRnc4xtH_t8Pig-4tcP9KTSYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hi Tomasz,
On Tue, 2019-09-03 at 15:04 +0800, Tomasz Figa wrote:
> On Tue, Sep 3, 2019 at 3:44 PM Jerry-ch Chen <Jerry-ch.Chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org> wrote:
> >
> > On Tue, 2019-09-03 at 13:19 +0800, Tomasz Figa wrote:
> > > On Mon, Sep 2, 2019 at 8:47 PM Jerry-ch Chen <Jerry-ch.Chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org> wrote:
> > > >
> > > > Hi Tomasz,
> > > >
> > > > On Fri, 2019-08-30 at 16:33 +0800, Tomasz Figa wrote:
> > > > > On Wed, Aug 28, 2019 at 11:00 AM Jerry-ch Chen
> > > > > <Jerry-ch.Chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org> wrote:
> > > > > >
> > > > > > Hi Tomasz,
> > > > > >
> > > > > > On Mon, 2019-08-26 at 14:36 +0800, Tomasz Figa wrote:
> > > > > > > Hi Jerry,
> > > > > > >
> > > > > > > On Sun, Aug 25, 2019 at 6:18 PM Jerry-ch Chen
> > > > > > > <Jerry-ch.Chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org> wrote:
> > > > > > > >
> > > > > > > > Hi Tomasz,
> > > > > > > >
> > > > > > > > On Fri, 2019-08-02 at 16:28 +0800, Tomasz Figa wrote:
> > > > > > > > > Hi Jerry,
> > > > > > > > >
> > > > > > > > > On Tue, Jul 09, 2019 at 04:41:12PM +0800, Jerry-ch Chen wrote:
> > > [snip]
> > > > > > static int mtk_fd_vb2_queue_setup(struct vb2_queue *vq,
> > > > > > unsigned int *num_buffers,
> > > > > > unsigned int *num_planes,
> > > > > > unsigned int sizes[],
> > > > > > struct device *alloc_devs[])
> > > > > > {
> > > > > > struct mtk_fd_ctx *ctx = vb2_get_drv_priv(vq);
> > > > > > struct device *dev = ctx->dev;
> > > > > > unsigned int size[2];
> > > > > >
> > > > > > switch (vq->type) {
> > > > > > case V4L2_BUF_TYPE_META_CAPTURE:
> > > > > > size[0] = ctx->dst_fmt.buffersize;
> > > > > > break;
> > > > > > case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
> > > > > > size[0] = ctx->src_fmt.plane_fmt[0].sizeimage;
> > > > > > if (*num_planes == 2)
> > > > > > size[1] = ctx->src_fmt.plane_fmt[1].sizeimage;
> > > > > > break;
> > > > > > }
> > > > > >
> > > > > > if (*num_planes == 1) {
> > > > > > if (sizes[0] < size[0])
> > > > > > return -EINVAL;
> > > > > > } else if (*num_planes == 2) {
> > > > > > if ((sizes[0] < size[0]) && (sizes[1] < size[1]))
> > > > > > return -EINVAL;
> > > > >
> > > > > Can we just use a loop here and combine the 2 cases above?
> > > > >
> > > > > Also, we need to fail with -EINVAL if *num_planes is > 2.
> > > > >
> > > > > > } else {
> > > > > > *num_planes = 1;
> > > > > > sizes[0] = size[0];
> > > > >
> > > > > This should be the case if *num_planes == 0 and the number of planes
> > > > > and sizes should match the currently active format.
> > > > >
> > > > I appreciate your comments,
> > > >
> > > > Ok, I will update as following:
> > > > static int mtk_fd_vb2_queue_setup(struct vb2_queue *vq,
> > > > unsigned int *num_buffers,
> > > > unsigned int *num_planes,
> > > > unsigned int sizes[],
> > > > struct device *alloc_devs[])
> > > > {
> > > > struct mtk_fd_ctx *ctx = vb2_get_drv_priv(vq);
> > > > unsigned int size[2];
> > > > unsigned int plane;
> > > >
> > > > switch (vq->type) {
> > > > case V4L2_BUF_TYPE_META_CAPTURE:
> > > > size[0] = ctx->dst_fmt.buffersize;
> > > > break;
> > > > case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
> > > > size[0] = ctx->src_fmt.plane_fmt[0].sizeimage;
> > > > if (*num_planes == 2)
> > > > size[1] = ctx->src_fmt.plane_fmt[1].sizeimage;
> > > > break;
> > > > }
> > > >
> > > > if (*num_planes > 2)
> > > > return -EINVAL;
> > > > if (*num_planes == 0) {
> > > > if (vq->type == V4L2_BUF_TYPE_META_CAPTURE) {
> > > > sizes[0] = ctx->dst_fmt.buffersize;
> > > > *num_planes = 1;
> > > > return 0;
> > > > }
> > > >
> > > > *num_planes = ctx->src_fmt.num_planes;
> > > > for (plane = 0; plane < *num_planes; plane++)
> > > > sizes[plane] = ctx->src_fmt.plane_fmt[plane].sizeimage;
> > > > return 0;
> > > > }
> > > >
> > > > for (plane = 0; plane < *num_planes; plane++) {
> > > > if(sizes[plane] < size[plane])
> > > > return -EINVAL;
> > > > }
> > > > return 0;
> > > > }
> > > >
> > >
> > > Looks good, thanks!
> > >
> > > > > > }
> > > > > >
> > > > > > return 0;
> > > > > > }
> > > > > >
> > > > > > > [snip]
> > > > > > >
> > > > > > > > > > +static void mtk_fd_vb2_stop_streaming(struct vb2_queue *vq)
> > > > > > > > > > +{
> > > > > > > > > > + struct mtk_fd_ctx *ctx = vb2_get_drv_priv(vq);
> > > > > > > > > > + struct vb2_buffer *vb;
> > > > > > > > >
> > > > > > > > > How do we guarantee here that the hardware isn't still accessing the buffers
> > > > > > > > > removed below?
> > > > > > > > >
> > > > > > > > Maybe we can check the driver state flag and aborting the unfinished
> > > > > > > > jobs?
> > > > > > > > (fd_hw->state == FD_ENQ)
> > > > > > > >
> > > > > > >
> > > > > > > Yes, we need to either cancel or wait for the currently processing
> > > > > > > job. It depends on hardware capabilities, but cancelling is generally
> > > > > > > preferred for the lower latency.
> > > > > > >
> > > > > > Ok, it the state is ENQ, then we can disable the FD hw by controlling
> > > > > > the registers.
> > > > > >
> > > > > > for example:
> > > > > > writel(0x0, fd->fd_base + FD_HW_ENABLE);
> > > > > > writel(0x0, fd->fd_base + FD_INT_EN);
> > > > > >
> > > > >
> > > > > What's exactly the effect of writing 0 to FD_HW_ENABLE?
> > > > >
> > > > Sorry, my last reply didn't solve the question,
> > > > we should implement a mtk_fd_job_abort() for v4l2_m2m_ops().
> > > >
> > > > which is able to readl_poll_timeout_atomic()
> > > > and check the HW busy bits in the register FD_INT_EN;
> > > >
> > > > if they are not cleared until timeout, we could handle the last
> > > > processing job.
> > > > Otherwise, the FD irq handler should have handled the last processing
> > > > job and we could continue the stop_streaming().
> > > >
> > > > For job_abort():
> > > > static void mtk_fd_job_abort(void *priv)
> > > > {
> > > > struct mtk_fd_ctx *ctx = priv;
> > > > struct mtk_fd_dev *fd = ctx->fd_dev;
> > > > u32 val;
> > > > u32 ret;
> > > >
> > > > ret = readl_poll_timeout_atomic(fd->fd_base + MTK_FD_REG_OFFSET_INT_EN,
> > > > val,
> > > > (val & MTK_FD_HW_BUSY_MASK) ==
> > > > MTK_FD_HW_STATE_IS_BUSY,
> > > > USEC_PER_MSEC, MTK_FD_STOP_HW_TIMEOUT);
> > >
> > > Hmm, would it be possible to avoid the busy wait by having a
> > > completion that could be signalled from the interrupt handler?
> > >
> > > Best regards,
> > > Tomasz
> >
> > I suppose that would be wakeup a wait queue in the interrupt handler,
> > the the wait_event_interrupt_timeout() will be used in here and system
> > suspend e.g. mtk_fd_suspend().
>
> Yes, that should work.
>
> > Or do you suggest to wait_event_interrupt_timeout() every frame in the
> > mtk_fd_ipi_handler()?
>
> Nope, we shouldn't need that.
>
> > I think maybe the readl_poll_timeout_atomic would be good enough.
> >
>
> Not really. Busy waiting should be avoided as much as possible. What's
> the point of entering suspend if you end up burning the power by
> spinning the CPU for some milliseconds?
>
Ok, I see, busy waiting is not a good idea, I will use the wait queue
instead. the job abort will refine as following:
static void mtk_fd_job_abort(void *priv)
{
struct mtk_fd_ctx *ctx = priv;
struct mtk_fd_dev *fd = ctx->fd_dev;
u32 ret;
ret = wait_event_interruptible_timeout
(fd->wq, (fd->fd_irq_result & MTK_FD_HW_IRQ_MASK),
usecs_to_jiffies(50000));
if (ret)
mtk_fd_hw_job_finish(fd, VB2_BUF_STATE_ERROR);
dev_dbg(fd->dev, "%s, ret:%d\n", __func__, ret);
fd->fd_irq_result = 0;
}
static struct v4l2_m2m_ops fd_m2m_ops = {
.device_run = mtk_fd_device_run,
.job_abort = mtk_fd_job_abort,
};
and we could use it in suspend.
static int mtk_fd_suspend(struct device *dev)
{
struct mtk_fd_dev *fd = dev_get_drvdata(dev);
if (pm_runtime_suspended(dev))
return 0;
if (fd->fd_stream_count)
mtk_fd_job_abort(fd->ctx);
/* suspend FD HW */
writel(0x0, fd->fd_base + MTK_FD_REG_OFFSET_INT_EN);
writel(0x0, fd->fd_base + MTK_FD_REG_OFFSET_HW_ENABLE);
clk_disable_unprepare(fd->fd_clk);
dev_dbg(dev, "%s:disable clock\n", __func__);
return 0;
}
static irqreturn_t mtk_fd_irq(int irq, void *data)
{
struct mtk_fd_dev *fd = (struct mtk_fd_dev *)data;
fd->fd_irq_result = readl(fd->fd_base + MTK_FD_REG_OFFSET_INT_VAL);
wake_up_interruptible(&fd->wq);
fd->output->number = readl(fd->fd_base + MTK_FD_REG_OFFSET_RESULT);
dev_dbg(fd->dev, "mtk_fd_face_num:%d\n", fd->output->number);
pm_runtime_put((fd->dev));
mtk_fd_hw_job_finish(fd, VB2_BUF_STATE_DONE);
return IRQ_HANDLED;
}
> >
> > One more thing, for the mtk_fd_video_device_register()
> > Sorry that I would need to use intermediate variable here since the 80
> > columns check.
> >
> > function = MEDIA_ENT_F_PROC_VIDEO_STATISTICS;
> > ret = v4l2_m2m_register_media_controller(m2m_dev, vfd, function);
>
> Why not just make it like this:
>
> ret = v4l2_m2m_register_media_controller(m2m_dev,
> MEDIA_ENT_F_PROC_VIDEO_STATISTICS);
>
> The above line is aligned using tabs so that its end is as close to
> the 80 character boundary as possible.
>
I tried but the checkpatch script still gave me a check saying align to
the scope, I will refine as following:
ret = v4l2_m2m_register_media_controller
(m2m_dev, vfd, MEDIA_ENT_F_PROC_VIDEO_STATISTICS);
Thanks and best regards,
Jerry
> Best regards,
> Tomasz
next prev parent reply other threads:[~2019-09-03 11:46 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-09 8:41 [RFC PATCH V2 0/4] media: platform: Add support for Face Detection (FD) on mt8183 SoC Jerry-ch Chen
2019-07-09 8:41 ` [RFC PATCH V2 1/4] dt-bindings: mt8183: Added FD dt-bindings Jerry-ch Chen
2019-07-12 7:16 ` CK Hu
2019-07-09 8:41 ` [RFC PATCH V2 2/4] dts: arm64: mt8183: Add FD nodes Jerry-ch Chen
2019-07-09 8:41 ` [RFC PATCH V2 3/4] media: platform: Add Mediatek FD driver KConfig Jerry-ch Chen
2019-09-05 12:30 ` Laurent Pinchart
2019-09-05 14:14 ` Jerry-ch Chen
2019-07-09 8:41 ` [RFC PATCH V2 4/4] platform: mtk-isp: Add Mediatek FD driver Jerry-ch Chen
2019-07-09 10:56 ` Enrico Weigelt, metux IT consult
2019-07-29 6:01 ` Jerry-ch Chen
2019-07-29 9:57 ` Tomasz Figa
2019-07-29 11:58 ` Jerry-ch Chen
2019-08-09 8:07 ` Tomasz Figa
2019-09-05 12:35 ` Laurent Pinchart
2019-08-02 8:28 ` Tomasz Figa
2019-08-25 9:18 ` Jerry-ch Chen
2019-08-26 6:36 ` Tomasz Figa
2019-08-28 2:00 ` Jerry-ch Chen
2019-08-30 8:33 ` Tomasz Figa
2019-09-02 11:47 ` Jerry-ch Chen
2019-09-03 5:19 ` Tomasz Figa
2019-09-03 6:44 ` Jerry-ch Chen
2019-09-03 7:04 ` Tomasz Figa
[not found] ` <CAAFQd5DWM=R7sFHYGhhR_rXrzgRnc4xtH_t8Pig-4tcP9KTSYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-03 11:46 ` Jerry-ch Chen [this message]
2019-09-03 12:05 ` Tomasz Figa
2019-09-04 3:38 ` Jerry-ch Chen
2019-09-04 4:15 ` Tomasz Figa
[not found] ` <CAAFQd5CRC2cyV30B4Qv59HdrJ7Cpe_yK5aY-BecQQ3J3i0PtCQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-04 6:09 ` Jerry-ch Chen
2019-09-04 6:34 ` Tomasz Figa
2019-09-04 8:09 ` Jerry-ch Chen
2019-09-04 8:25 ` Tomasz Figa
[not found] ` <CAAFQd5Dzxy10g-MKHMnNbVO6kp9_L_jm1m+gtN+p=YF2LyBiag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-04 9:01 ` Jerry-ch Chen
2019-09-04 9:03 ` Tomasz Figa
[not found] ` <CAAFQd5DWfEEiGthPi=qoxD-mpAWa68GOCi55mqpmagS-tsGYkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-04 9:26 ` Jerry-ch Chen
2019-09-04 13:12 ` Tomasz Figa
[not found] ` <CAAFQd5Ckz9qH7AnLNM4HRTM2gJQP1HXRS09+o6Prf++D1PQhng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-04 13:19 ` Jerry-ch Chen
2019-09-05 7:02 ` Jerry-ch Chen
2019-09-05 7:13 ` Tomasz Figa
2019-09-05 8:16 ` Jerry-ch Chen
2019-09-05 8:52 ` Tomasz Figa
2019-09-05 13:36 ` Jerry-ch Chen
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=1567511169.18318.65.camel@mtksdccf07 \
--to=jerry-ch.chen-nus5lvnupcjwk0htik3j/w@public.gmane.org \
--cc=Rynn.Wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=Sean.Cheng-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=jungo.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
--cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=po-yang.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=shik-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=sj.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=suleiman-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=yuzhao-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=zwisler-F7+t8E8rja8pug/h7KTFAQ@public.gmane.org \
/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).