devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: andrew-ct chen <andrew-ct.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
Cc: Tiffany Lin <tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	Hans Verkuil
	<hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>,
	daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mauro Carvalho Chehab
	<mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>,
	Matthias Brugger
	<matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Pawel Osciak <posciak-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Eddie Huang <eddie.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	Yingjoe Chen
	<yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	PoChun.Lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH v7 2/8] [media] VPU: mediatek: support Mediatek VPU
Date: Mon, 25 Apr 2016 17:22:03 +0800	[thread overview]
Message-ID: <1461576123.15167.3.camel@mtksdaap41> (raw)
In-Reply-To: <571DCA04.8000703-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>

On Mon, 2016-04-25 at 09:40 +0200, Hans Verkuil wrote:
> On 04/22/2016 06:25 AM, Tiffany Lin wrote:
> > From: Andrew-CT Chen <andrew-ct.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> > 
> > The VPU driver for hw video codec embedded in Mediatek's MT8173 SOCs.
> > It is able to handle video decoding/encoding of in a range of formats.
> > The driver provides with VPU firmware download, memory management and
> > the communication interface between CPU and VPU.
> > For VPU initialization, it will create virtual memory for CPU access and
> > IOMMU address for vcodec hw device access. When a decode/encode instance
> > opens a device node, vpu driver will download vpu firmware to the device.
> > A decode/encode instant will decode/encode a frame using VPU
> > interface to interrupt vpu to handle decoding/encoding jobs.
> > 
> > Signed-off-by: Andrew-CT Chen <andrew-ct.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> > Signed-off-by: Tiffany Lin <tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> > 
> > ---
> >  drivers/media/platform/Kconfig           |   13 +
> >  drivers/media/platform/Makefile          |    2 +
> >  drivers/media/platform/mtk-vpu/Makefile  |    3 +
> >  drivers/media/platform/mtk-vpu/mtk_vpu.c |  950 ++++++++++++++++++++++++++++++
> >  drivers/media/platform/mtk-vpu/mtk_vpu.h |  162 +++++
> >  5 files changed, 1130 insertions(+)
> >  create mode 100644 drivers/media/platform/mtk-vpu/Makefile
> >  create mode 100755 drivers/media/platform/mtk-vpu/mtk_vpu.c
> >  create mode 100644 drivers/media/platform/mtk-vpu/mtk_vpu.h
> > 
> 
> 
> > +int vpu_load_firmware(struct platform_device *pdev)
> > +{
> > +	struct mtk_vpu *vpu = platform_get_drvdata(pdev);
> > +	struct device *dev = &pdev->dev;
> > +	struct vpu_run *run = &vpu->run;
> > +	const struct firmware *vpu_fw;
> > +	int ret;
> > +
> > +	if (!pdev) {
> > +		dev_err(dev, "VPU platform device is invalid\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	ret = vpu_clock_enable(vpu);
> > +	if (ret) {
> > +		dev_err(dev, "enable clock failed %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	mutex_lock(&vpu->vpu_mutex);
> > +
> > +	if (vpu_running(vpu)) {
> > +		mutex_unlock(&vpu->vpu_mutex);
> > +		vpu_clock_disable(vpu);
> > +		dev_warn(dev, "vpu is running already\n");
> 
> This warning should be dropped. Currently vpu_load_firmware is called
> every time the video device is opened and no one else has the video device
> open. So calling this multiple times is perfectly normal and the log shouldn't
> be spammed with warnings.
> 
> I would recommend adding a fw_loaded bool to struct mtk_vpu and just
> check that at the beginning of this function and just return 0 if it is true.
> 
> Then you don't need to enable the vpu clock either.
> 
> I hope I understand the hw correctly, though.
> 
> Assuming you can do this, then this code from the v4l driver needs an
> additional comment:

We will change this in next version.

> 
> >>> +	if (v4l2_fh_is_singular(&ctx->fh)) {
> 
> Add a comment here that says that vpu_load_firmware checks if it was
> loaded already and does nothing in that case.

We will change this in next version. Thanks

> 
> >>> +		ret = vpu_load_firmware(dev->vpu_plat_dev);
> >>> +		if (ret < 0) {
> >>> +			/*
> >>> +			  * Return 0 if downloading firmware successfully,
> >>> +			  * otherwise it is failed
> >>> +			  */
> >>> +			mtk_v4l2_err("vpu_load_firmware failed!");
> >>> +			goto err_load_fw;
> >>> +		}
> 
> That makes it clear to the reader (i.e. me :-) ) that you can safely call
> vpu_load_firmware multiple times.
> 
> Regards,
> 
> 	Hans
> 
> > +		return 0;
> > +	}
> > +
> > +	run->signaled = false;
> > +	dev_dbg(vpu->dev, "firmware request\n");
> > +	/* Downloading program firmware to device*/
> > +	ret = load_requested_vpu(vpu, vpu_fw, P_FW);
> > +	if (ret < 0) {
> > +		dev_err(dev, "Failed to request %s, %d\n", VPU_P_FW, ret);
> > +		goto OUT_LOAD_FW;
> > +	}
> > +
> > +	/* Downloading data firmware to device */
> > +	ret = load_requested_vpu(vpu, vpu_fw, D_FW);
> > +	if (ret < 0) {
> > +		dev_err(dev, "Failed to request %s, %d\n", VPU_D_FW, ret);
> > +		goto OUT_LOAD_FW;
> > +	}
> > +
> > +	/* boot up vpu */
> > +	vpu_cfg_writel(vpu, 0x1, VPU_RESET);
> > +
> > +	ret = wait_event_interruptible_timeout(run->wq,
> > +					       run->signaled,
> > +					       msecs_to_jiffies(INIT_TIMEOUT_MS)
> > +					       );
> > +	if (ret == 0) {
> > +		ret = -ETIME;
> > +		dev_err(dev, "wait vpu initialization timout!\n");
> > +		goto OUT_LOAD_FW;
> > +	} else if (-ERESTARTSYS == ret) {
> > +		dev_err(dev, "wait vpu interrupted by a signal!\n");
> > +		goto OUT_LOAD_FW;
> > +	}
> > +
> > +	ret = 0;
> > +	dev_info(dev, "vpu is ready. Fw version %s\n", run->fw_ver);
> > +
> > +OUT_LOAD_FW:
> > +	mutex_unlock(&vpu->vpu_mutex);
> > +	vpu_clock_disable(vpu);
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(vpu_load_firmware);
> 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2016-04-25  9:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22  4:25 [PATCH v7 0/8] Add MT8173 Video Encoder Driver and VPU Driver Tiffany Lin
     [not found] ` <1461299131-57851-1-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  4:25   ` [PATCH v7 1/8] dt-bindings: Add a binding for Mediatek Video Processor Tiffany Lin
2016-04-22  4:25     ` [PATCH v7 2/8] [media] VPU: mediatek: support Mediatek VPU Tiffany Lin
     [not found]       ` <1461299131-57851-3-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  4:25         ` [PATCH v7 3/8] arm64: dts: mediatek: Add node for Mediatek Video Processor Unit Tiffany Lin
     [not found]           ` <1461299131-57851-4-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  4:25             ` [PATCH v7 4/8] dt-bindings: Add a binding for Mediatek Video Encoder Tiffany Lin
2016-04-22  4:25               ` [PATCH v7 5/8] [media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder Driver Tiffany Lin
2016-04-22  4:25                 ` [PATCH v7 6/8] [media] vcodec: mediatek: Add Mediatek VP8 " Tiffany Lin
2016-04-22  4:25                   ` [PATCH v7 7/8] [media] vcodec: mediatek: Add Mediatek H264 " Tiffany Lin
2016-04-22  4:25                     ` [PATCH v7 8/8] arm64: dts: mediatek: Add Video Encoder for MT8173 Tiffany Lin
     [not found]                     ` <1461299131-57851-8-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  8:05                       ` [PATCH v7 7/8] [media] vcodec: mediatek: Add Mediatek H264 Video Encoder Driver kbuild test robot
     [not found]                   ` <1461299131-57851-7-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  6:52                     ` [PATCH v7 6/8] [media] vcodec: mediatek: Add Mediatek VP8 " kbuild test robot
2016-04-22  7:50                     ` kbuild test robot
     [not found]                 ` <1461299131-57851-6-git-send-email-tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-04-22  7:37                   ` [PATCH v7 5/8] [media] vcodec: mediatek: Add Mediatek V4L2 " kbuild test robot
2016-04-22 13:47                 ` Hans Verkuil
     [not found]                   ` <571A2B70.7040402-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2016-04-25  5:16                     ` tiffany lin
2016-04-25  5:42                       ` Wu-Cheng Li (李務誠)
2016-04-25  7:02                         ` tiffany lin
2016-04-22  9:38               ` [PATCH v7 4/8] dt-bindings: Add a binding for Mediatek Video Encoder kbuild test robot
2016-04-25  7:40         ` [PATCH v7 2/8] [media] VPU: mediatek: support Mediatek VPU Hans Verkuil
     [not found]           ` <571DCA04.8000703-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2016-04-25  9:22             ` andrew-ct chen [this message]

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=1461576123.15167.3.camel@mtksdaap41 \
    --to=andrew-ct.chen-nus5lvnupcjwk0htik3j/w@public.gmane.org \
    --cc=PoChun.Lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=eddie.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=hans.verkuil-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org \
    --cc=hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org \
    --cc=posciak-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=tiffany.lin-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@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).