From: jacopo mondi <jacopo@jmondi.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
magnus.damm@gmail.com, geert@glider.be, mchehab@kernel.org,
hverkuil@xs4all.nl, linux-renesas-soc@vger.kernel.org,
linux-media@vger.kernel.org, linux-sh@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 03/10] v4l: platform: Add Renesas CEU driver
Date: Tue, 19 Dec 2017 12:57:42 +0100 [thread overview]
Message-ID: <20171219115742.GB27115@w540> (raw)
In-Reply-To: <2710170.YbEgzp5Yxe@avalon>
Hi Laurent,
a few more details on subdevice management
On Mon, Dec 11, 2017 at 06:15:23PM +0200, Laurent Pinchart wrote:
> Hi Jacopo,
>
> Thank you for the patch.
>
> [snip]
>
> > +static int ceu_sensor_bound(struct v4l2_async_notifier *notifier,
> > + struct v4l2_subdev *v4l2_sd,
> > + struct v4l2_async_subdev *asd)
> > +{
> > + struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
> > + struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
> > + struct ceu_subdev *ceu_sd = to_ceu_subdev(asd);
> > +
> > + if (video_is_registered(&ceudev->vdev)) {
> > + v4l2_err(&ceudev->v4l2_dev,
> > + "Video device registered before this sub-device.\n");
> > + return -EBUSY;
>
> Can this happen ?
>
> > + }
> > +
> > + /* Assign subdevices in the order they appear */
> > + ceu_sd->v4l2_sd = v4l2_sd;
> > + ceudev->num_sd++;
> > +
> > + return 0;
> > +}
> > +
> > +static int ceu_sensor_complete(struct v4l2_async_notifier *notifier)
> > +{
> > + struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
> > + struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
> > + struct video_device *vdev = &ceudev->vdev;
> > + struct vb2_queue *q = &ceudev->vb2_vq;
> > + struct v4l2_subdev *v4l2_sd;
> > + int ret;
> > +
> > + /* Initialize vb2 queue */
> > + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
> > + q->io_modes = VB2_MMAP | VB2_USERPTR;
>
> No dmabuf ?
>
> > + q->drv_priv = ceudev;
> > + q->ops = &ceu_videobuf_ops;
> > + q->mem_ops = &vb2_dma_contig_memops;
> > + q->buf_struct_size = sizeof(struct ceu_buffer);
> > + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
> > + q->lock = &ceudev->mlock;
> > + q->dev = ceudev->v4l2_dev.dev;
>
> [snip]
>
> > +static int ceu_probe(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct ceu_device *ceudev;
> > + struct resource *res;
> > + void __iomem *base;
> > + unsigned int irq;
> > + int num_sd;
> > + int ret;
> > +
> > + ceudev = kzalloc(sizeof(*ceudev), GFP_KERNEL);
>
> The memory is freed in ceu_vdev_release() as expected, but that will only work
> if the video device is registered. If the subdevs are never bound, the ceudev
> memory will be leaked if you unbind the CEU device from its driver. In my
> opinion this calls for registering the video device at probe time (although
> Hans disagrees).
>
> > + if (!ceudev)
> > + return -ENOMEM;
> > +
> > + platform_set_drvdata(pdev, ceudev);
> > + dev_set_drvdata(dev, ceudev);
>
> You don't need the second line, platform_set_drvdata() is a wrapper around
> dev_set_drvdata().
>
> > + ceudev->dev = dev;
> > +
> > + INIT_LIST_HEAD(&ceudev->capture);
> > + spin_lock_init(&ceudev->lock);
> > + mutex_init(&ceudev->mlock);
> > +
> > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (IS_ERR(res))
> > + return PTR_ERR(res);
>
> No need for error handling here, devm_ioremap_resource() will check the res
> pointer.
>
> > + base = devm_ioremap_resource(dev, res);
>
> You can assign ceudev->base directly and remove the base local variable.
>
> > + if (IS_ERR(base))
> > + return PTR_ERR(base);
> > + ceudev->base = base;
> > +
> > + ret = platform_get_irq(pdev, 0);
> > + if (ret < 0) {
> > + dev_err(dev, "failed to get irq: %d\n", ret);
> > + return ret;
> > + }
> > + irq = ret;
> > +
> > + ret = devm_request_irq(dev, irq, ceu_irq,
> > + 0, dev_name(dev), ceudev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
> > + return ret;
> > + }
> > +
> > + pm_suspend_ignore_children(dev, true);
> > + pm_runtime_enable(dev);
> > +
> > + ret = v4l2_device_register(dev, &ceudev->v4l2_dev);
> > + if (ret)
> > + goto error_pm_disable;
> > +
> > + if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
> > + num_sd = ceu_parse_dt(ceudev);
> > + } else if (dev->platform_data) {
> > + num_sd = ceu_parse_platform_data(ceudev, dev->platform_data);
> > + } else {
> > + dev_err(dev, "CEU platform data not set and no OF support\n");
> > + ret = -EINVAL;
> > + goto error_v4l2_unregister;
> > + }
> > +
> > + if (num_sd < 0) {
> > + ret = num_sd;
> > + goto error_v4l2_unregister;
> > + } else if (num_sd == 0)
> > + return 0;
>
> You need braces around the second statement too.
Ok, actually parse_dt() and parse_platform_data() behaves differently.
The former returns error if no subdevices are connected to CEU, the
latter returns 0. That's wrong.
I wonder what's the correct behavior here. Other mainline drivers I
looked into (pxa_camera and atmel-isc) behaves differently from each
other, so I guess this is up to each platform to decide.
Also, the CEU can accept one single input (and I made it clear
in DT bindings documentation saying it accepts a single endpoint,
while I'm parsing all the available ones in driver, I will fix this)
but as it happens on Migo-R, there could be HW hacks to share the input
lines between multiple subdevices. Should I accept it from dts as well?
So:
1) Should we fail to probe if no subdevices are connected?
2) Should we accept more than 1 subdevice from dts as it happens right
now for platform data?
Thanks
j
>
> [snip]
>
> > +static const struct dev_pm_ops ceu_pm_ops = {
> > + SET_RUNTIME_PM_OPS(ceu_runtime_suspend,
> > + ceu_runtime_resume,
> > + NULL)
>
> You'll probably need system PM ops eventually, but for now this isn't a
> regression so I won't complain too much.
>
> > +};
>
> [snip]
>
> --
> Regards,
>
> Laurent Pinchart
>
WARNING: multiple messages have this Message-ID (diff)
From: jacopo mondi <jacopo@jmondi.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
magnus.damm@gmail.com, geert@glider.be, mchehab@kernel.org,
hverkuil@xs4all.nl, linux-renesas-soc@vger.kernel.org,
linux-media@vger.kernel.org, linux-sh@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 03/10] v4l: platform: Add Renesas CEU driver
Date: Tue, 19 Dec 2017 11:57:42 +0000 [thread overview]
Message-ID: <20171219115742.GB27115@w540> (raw)
In-Reply-To: <2710170.YbEgzp5Yxe@avalon>
Hi Laurent,
a few more details on subdevice management
On Mon, Dec 11, 2017 at 06:15:23PM +0200, Laurent Pinchart wrote:
> Hi Jacopo,
>
> Thank you for the patch.
>
> [snip]
>
> > +static int ceu_sensor_bound(struct v4l2_async_notifier *notifier,
> > + struct v4l2_subdev *v4l2_sd,
> > + struct v4l2_async_subdev *asd)
> > +{
> > + struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
> > + struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
> > + struct ceu_subdev *ceu_sd = to_ceu_subdev(asd);
> > +
> > + if (video_is_registered(&ceudev->vdev)) {
> > + v4l2_err(&ceudev->v4l2_dev,
> > + "Video device registered before this sub-device.\n");
> > + return -EBUSY;
>
> Can this happen ?
>
> > + }
> > +
> > + /* Assign subdevices in the order they appear */
> > + ceu_sd->v4l2_sd = v4l2_sd;
> > + ceudev->num_sd++;
> > +
> > + return 0;
> > +}
> > +
> > +static int ceu_sensor_complete(struct v4l2_async_notifier *notifier)
> > +{
> > + struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
> > + struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
> > + struct video_device *vdev = &ceudev->vdev;
> > + struct vb2_queue *q = &ceudev->vb2_vq;
> > + struct v4l2_subdev *v4l2_sd;
> > + int ret;
> > +
> > + /* Initialize vb2 queue */
> > + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
> > + q->io_modes = VB2_MMAP | VB2_USERPTR;
>
> No dmabuf ?
>
> > + q->drv_priv = ceudev;
> > + q->ops = &ceu_videobuf_ops;
> > + q->mem_ops = &vb2_dma_contig_memops;
> > + q->buf_struct_size = sizeof(struct ceu_buffer);
> > + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
> > + q->lock = &ceudev->mlock;
> > + q->dev = ceudev->v4l2_dev.dev;
>
> [snip]
>
> > +static int ceu_probe(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct ceu_device *ceudev;
> > + struct resource *res;
> > + void __iomem *base;
> > + unsigned int irq;
> > + int num_sd;
> > + int ret;
> > +
> > + ceudev = kzalloc(sizeof(*ceudev), GFP_KERNEL);
>
> The memory is freed in ceu_vdev_release() as expected, but that will only work
> if the video device is registered. If the subdevs are never bound, the ceudev
> memory will be leaked if you unbind the CEU device from its driver. In my
> opinion this calls for registering the video device at probe time (although
> Hans disagrees).
>
> > + if (!ceudev)
> > + return -ENOMEM;
> > +
> > + platform_set_drvdata(pdev, ceudev);
> > + dev_set_drvdata(dev, ceudev);
>
> You don't need the second line, platform_set_drvdata() is a wrapper around
> dev_set_drvdata().
>
> > + ceudev->dev = dev;
> > +
> > + INIT_LIST_HEAD(&ceudev->capture);
> > + spin_lock_init(&ceudev->lock);
> > + mutex_init(&ceudev->mlock);
> > +
> > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (IS_ERR(res))
> > + return PTR_ERR(res);
>
> No need for error handling here, devm_ioremap_resource() will check the res
> pointer.
>
> > + base = devm_ioremap_resource(dev, res);
>
> You can assign ceudev->base directly and remove the base local variable.
>
> > + if (IS_ERR(base))
> > + return PTR_ERR(base);
> > + ceudev->base = base;
> > +
> > + ret = platform_get_irq(pdev, 0);
> > + if (ret < 0) {
> > + dev_err(dev, "failed to get irq: %d\n", ret);
> > + return ret;
> > + }
> > + irq = ret;
> > +
> > + ret = devm_request_irq(dev, irq, ceu_irq,
> > + 0, dev_name(dev), ceudev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
> > + return ret;
> > + }
> > +
> > + pm_suspend_ignore_children(dev, true);
> > + pm_runtime_enable(dev);
> > +
> > + ret = v4l2_device_register(dev, &ceudev->v4l2_dev);
> > + if (ret)
> > + goto error_pm_disable;
> > +
> > + if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
> > + num_sd = ceu_parse_dt(ceudev);
> > + } else if (dev->platform_data) {
> > + num_sd = ceu_parse_platform_data(ceudev, dev->platform_data);
> > + } else {
> > + dev_err(dev, "CEU platform data not set and no OF support\n");
> > + ret = -EINVAL;
> > + goto error_v4l2_unregister;
> > + }
> > +
> > + if (num_sd < 0) {
> > + ret = num_sd;
> > + goto error_v4l2_unregister;
> > + } else if (num_sd = 0)
> > + return 0;
>
> You need braces around the second statement too.
Ok, actually parse_dt() and parse_platform_data() behaves differently.
The former returns error if no subdevices are connected to CEU, the
latter returns 0. That's wrong.
I wonder what's the correct behavior here. Other mainline drivers I
looked into (pxa_camera and atmel-isc) behaves differently from each
other, so I guess this is up to each platform to decide.
Also, the CEU can accept one single input (and I made it clear
in DT bindings documentation saying it accepts a single endpoint,
while I'm parsing all the available ones in driver, I will fix this)
but as it happens on Migo-R, there could be HW hacks to share the input
lines between multiple subdevices. Should I accept it from dts as well?
So:
1) Should we fail to probe if no subdevices are connected?
2) Should we accept more than 1 subdevice from dts as it happens right
now for platform data?
Thanks
j
>
> [snip]
>
> > +static const struct dev_pm_ops ceu_pm_ops = {
> > + SET_RUNTIME_PM_OPS(ceu_runtime_suspend,
> > + ceu_runtime_resume,
> > + NULL)
>
> You'll probably need system PM ops eventually, but for now this isn't a
> regression so I won't complain too much.
>
> > +};
>
> [snip]
>
> --
> Regards,
>
> Laurent Pinchart
>
next prev parent reply other threads:[~2017-12-19 11:57 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 10:55 [PATCH v1 00/10] Renesas Capture Engine Unit (CEU) V4L2 driver Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-15 10:55 ` [PATCH v1 01/10] dt-bindings: media: Add Renesas CEU bindings Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-15 11:32 ` Kieran Bingham
2017-11-15 12:33 ` Sakari Ailus
2017-11-15 12:33 ` Sakari Ailus
2017-12-11 14:24 ` Laurent Pinchart
2017-12-11 14:24 ` Laurent Pinchart
2017-11-15 13:07 ` Geert Uytterhoeven
2017-11-15 13:07 ` Geert Uytterhoeven
2017-11-15 13:07 ` Geert Uytterhoeven
2017-11-15 18:15 ` jacopo mondi
2017-11-15 18:15 ` jacopo mondi
2017-11-15 18:39 ` Geert Uytterhoeven
2017-11-15 18:39 ` Geert Uytterhoeven
2017-11-15 10:55 ` [PATCH v1 02/10] include: media: Add Renesas CEU driver interface Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-15 12:36 ` Sakari Ailus
2017-11-15 12:36 ` Sakari Ailus
2017-12-11 14:26 ` Laurent Pinchart
2017-12-11 14:26 ` Laurent Pinchart
2017-12-11 14:32 ` Laurent Pinchart
2017-12-11 14:32 ` Laurent Pinchart
2017-11-15 10:55 ` [PATCH v1 03/10] v4l: platform: Add Renesas CEU driver Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-15 12:45 ` Sakari Ailus
2017-11-15 12:45 ` Sakari Ailus
2017-11-15 14:25 ` jacopo mondi
2017-11-15 14:25 ` jacopo mondi
2017-11-17 0:36 ` Sakari Ailus
2017-11-17 0:36 ` Sakari Ailus
2017-11-17 9:33 ` jacopo mondi
2017-11-17 9:33 ` jacopo mondi
2017-11-25 15:56 ` Sakari Ailus
2017-11-25 15:56 ` Sakari Ailus
2017-11-25 18:17 ` jacopo mondi
2017-11-25 18:17 ` jacopo mondi
2017-12-11 15:04 ` Laurent Pinchart
2017-12-11 15:04 ` Laurent Pinchart
2017-12-11 16:15 ` Laurent Pinchart
2017-12-11 16:15 ` Laurent Pinchart
2017-12-18 12:25 ` jacopo mondi
2017-12-18 12:25 ` jacopo mondi
2017-12-18 15:28 ` Laurent Pinchart
2017-12-18 15:28 ` Laurent Pinchart
2017-12-21 16:27 ` jacopo mondi
2017-12-21 16:27 ` jacopo mondi
2017-12-22 12:03 ` Laurent Pinchart
2017-12-22 12:03 ` Laurent Pinchart
2017-12-22 14:40 ` jacopo mondi
2017-12-22 14:40 ` jacopo mondi
2017-12-23 11:39 ` Laurent Pinchart
2017-12-23 11:39 ` Laurent Pinchart
2017-12-19 11:57 ` jacopo mondi [this message]
2017-12-19 11:57 ` jacopo mondi
2017-12-19 13:07 ` Laurent Pinchart
2017-12-19 13:07 ` Laurent Pinchart
2017-12-19 13:28 ` Sakari Ailus
2017-12-19 13:28 ` Sakari Ailus
2017-12-19 13:52 ` Laurent Pinchart
2017-12-19 13:52 ` Laurent Pinchart
2017-12-13 12:03 ` Hans Verkuil
2017-12-13 12:03 ` Hans Verkuil
2017-12-18 14:12 ` jacopo mondi
2017-12-18 14:12 ` jacopo mondi
2017-11-15 10:55 ` [PATCH v1 04/10] ARM: dts: r7s72100: Add Capture Engine Unit (CEU) Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-17 14:22 ` Simon Horman
2017-11-17 14:22 ` Simon Horman
2017-11-23 9:41 ` Geert Uytterhoeven
2017-11-23 9:41 ` Geert Uytterhoeven
2017-11-15 10:55 ` [PATCH v1 05/10] arch: sh: migor: Use new renesas-ceu camera driver Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-12-11 14:36 ` Laurent Pinchart
2017-12-11 14:36 ` Laurent Pinchart
2017-12-12 10:00 ` Laurent Pinchart
2017-12-12 10:00 ` Laurent Pinchart
2017-12-21 20:31 ` jacopo mondi
2017-12-21 20:31 ` jacopo mondi
2017-12-22 8:04 ` Geert Uytterhoeven
2017-12-22 8:04 ` Geert Uytterhoeven
2017-12-22 11:56 ` Laurent Pinchart
2017-12-22 11:56 ` Laurent Pinchart
2017-11-15 10:55 ` [PATCH v1 06/10] sh: sh7722: Rename CEU clock Jacopo Mondi
2017-11-15 10:55 ` Jacopo Mondi
2017-11-15 13:13 ` Geert Uytterhoeven
2017-11-15 13:13 ` Geert Uytterhoeven
2017-11-17 9:15 ` jacopo mondi
2017-11-17 9:15 ` jacopo mondi
2017-11-15 10:56 ` [PATCH v1 07/10] v4l: i2c: Copy ov772x soc_camera sensor driver Jacopo Mondi
2017-11-15 10:56 ` Jacopo Mondi
2017-12-11 14:49 ` Laurent Pinchart
2017-12-11 14:49 ` Laurent Pinchart
2017-12-13 12:10 ` Hans Verkuil
2017-12-13 12:10 ` Hans Verkuil
2017-12-13 13:02 ` Philippe Ombredanne
2017-12-13 13:02 ` Philippe Ombredanne
2017-11-15 10:56 ` [PATCH v1 08/10] media: i2c: ov772x: Remove soc_camera dependencies Jacopo Mondi
2017-11-15 10:56 ` Jacopo Mondi
2017-11-17 0:43 ` Sakari Ailus
2017-11-17 0:43 ` Sakari Ailus
2017-11-17 9:14 ` jacopo mondi
2017-11-17 9:14 ` jacopo mondi
2017-11-25 16:04 ` Sakari Ailus
2017-11-25 16:04 ` Sakari Ailus
2017-12-11 14:47 ` Laurent Pinchart
2017-12-11 14:47 ` Laurent Pinchart
2017-11-15 10:56 ` [PATCH v1 09/10] v4l: i2c: Copy tw9910 soc_camera sensor driver Jacopo Mondi
2017-11-15 10:56 ` Jacopo Mondi
2017-12-11 14:50 ` Laurent Pinchart
2017-12-11 14:50 ` Laurent Pinchart
2017-11-15 10:56 ` [PATCH v1 10/10] media: i2c: tw9910: Remove soc_camera dependencies Jacopo Mondi
2017-11-15 10:56 ` Jacopo Mondi
2017-12-11 14:55 ` Laurent Pinchart
2017-12-11 14:55 ` Laurent Pinchart
2017-12-13 12:13 ` Hans Verkuil
2017-12-13 12:13 ` Hans Verkuil
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=20171219115742.GB27115@w540 \
--to=jacopo@jmondi.org \
--cc=geert@glider.be \
--cc=hverkuil@xs4all.nl \
--cc=jacopo+renesas@jmondi.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mchehab@kernel.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 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.