linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH 01/11] rcar-vin: Refactor controls creation for video device
Date: Tue, 6 Jul 2021 18:17:57 +0200	[thread overview]
Message-ID: <YOSCNRbLfPqPSG03@oden.dyn.berto.se> (raw)
In-Reply-To: <20210706160842.ruwejskmpbp6nyff@uno.localdomain>

Hello :-)

On 2021-07-06 18:08:42 +0200, Jacopo Mondi wrote:
> Hi again,
> 
> On Tue, Apr 13, 2021 at 08:02:43PM +0200, Niklas Söderlund wrote:
> > The controls for the video device are created in different code paths
> > depending on if the driver is using the media graph centric model (Gen3)
> > or the device centric model (Gen2 and earlier). This have lead to code
> > duplication that can be consolidated.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-core.c | 82 +++++++++++----------
> >  1 file changed, 45 insertions(+), 37 deletions(-)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
> > index cb3025992817d625..c798dc9409e4cdcd 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-core.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-core.c
> > @@ -405,6 +405,45 @@ static const struct v4l2_ctrl_ops rvin_ctrl_ops = {
> >  	.s_ctrl = rvin_s_ctrl,
> >  };
> >
> > +static void rvin_free_controls(struct rvin_dev *vin)
> > +{
> > +	v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > +	vin->vdev.ctrl_handler = NULL;
> > +}
> > +
> > +static int rvin_create_controls(struct rvin_dev *vin, struct v4l2_subdev *subdev)
> > +{
> > +	int ret;
> > +
> > +	ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
> 
> Not a big deal, but 16 because we have to reserve space for the
> eventual subdevice controls ?

Yes, again for Gen2 where the controls of the subdevice are exposed on 
the video device. IIRC the number 16 comes from the soc-camera ancestor 
for this driver.

> 
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	/* The VIN directly deals with alpha component. */
> > +	v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops,
> > +			  V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255);
> > +
> > +	if (vin->ctrl_handler.error) {
> > +		ret = vin->ctrl_handler.error;
> > +		rvin_free_controls(vin);
> > +		return ret;
> > +	}
> > +
> > +	/* For the non-MC mode add controls from the subdevice. */
> > +	if (subdev) {
> > +		ret = v4l2_ctrl_add_handler(&vin->ctrl_handler,
> > +					    subdev->ctrl_handler, NULL, true);
> > +		if (ret < 0) {
> > +			rvin_free_controls(vin);
> > +			return ret;
> > +		}
> > +	}
> > +
> > +	vin->vdev.ctrl_handler = &vin->ctrl_handler;
> > +
> > +	return 0;
> > +}
> > +
> >  /* -----------------------------------------------------------------------------
> >   * Async notifier
> >   */
> > @@ -490,28 +529,10 @@ static int rvin_parallel_subdevice_attach(struct rvin_dev *vin,
> >  		return ret;
> >
> >  	/* Add the controls */
> > -	ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
> > +	ret = rvin_create_controls(vin, subdev);
> >  	if (ret < 0)
> >  		return ret;
> >
> > -	v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops,
> > -			  V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255);
> > -
> > -	if (vin->ctrl_handler.error) {
> > -		ret = vin->ctrl_handler.error;
> > -		v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > -		return ret;
> > -	}
> > -
> > -	ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, subdev->ctrl_handler,
> > -				    NULL, true);
> > -	if (ret < 0) {
> > -		v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > -		return ret;
> > -	}
> > -
> > -	vin->vdev.ctrl_handler = &vin->ctrl_handler;
> > -
> >  	vin->parallel.subdev = subdev;
> >
> >  	return 0;
> > @@ -522,10 +543,8 @@ static void rvin_parallel_subdevice_detach(struct rvin_dev *vin)
> >  	rvin_v4l2_unregister(vin);
> >  	vin->parallel.subdev = NULL;
> >
> > -	if (!vin->info->use_mc) {
> > -		v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > -		vin->vdev.ctrl_handler = NULL;
> > -	}
> > +	if (!vin->info->use_mc)
> > +		rvin_free_controls(vin);
> >  }
> >
> >  static int rvin_parallel_notify_complete(struct v4l2_async_notifier *notifier)
> > @@ -935,21 +954,10 @@ static int rvin_mc_init(struct rvin_dev *vin)
> >  	if (ret)
> >  		rvin_group_put(vin);
> >
> > -	ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 1);
> > +	ret = rvin_create_controls(vin, NULL);
> >  	if (ret < 0)
> >  		return ret;
> >
> > -	v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops,
> > -			  V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255);
> > -
> > -	if (vin->ctrl_handler.error) {
> > -		ret = vin->ctrl_handler.error;
> > -		v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > -		return ret;
> > -	}
> > -
> > -	vin->vdev.ctrl_handler = &vin->ctrl_handler;
> > -
> >  	return ret;
> >  }
> >
> > @@ -1446,7 +1454,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
> >  	return 0;
> >
> >  error_group_unregister:
> > -	v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > +	rvin_free_controls(vin);
> >
> >  	if (vin->info->use_mc) {
> >  		mutex_lock(&vin->group->lock);
> > @@ -1481,7 +1489,7 @@ static int rcar_vin_remove(struct platform_device *pdev)
> >  		rvin_group_put(vin);
> >  	}
> >
> > -	v4l2_ctrl_handler_free(&vin->ctrl_handler);
> > +	rvin_free_controls(vin);
> >
> >  	rvin_dma_unregister(vin);
> >
> > --
> > 2.31.1
> >

-- 
Regards,
Niklas Söderlund

  reply	other threads:[~2021-07-06 16:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 18:02 [PATCH 00/11] rcar-vin: Add r8a779a0 support Niklas Söderlund
2021-04-13 18:02 ` [PATCH 01/11] rcar-vin: Refactor controls creation for video device Niklas Söderlund
2021-07-06 16:04   ` Jacopo Mondi
2021-07-06 16:16     ` Niklas Söderlund
2021-07-06 16:58       ` Jacopo Mondi
2021-07-08 13:40         ` Sakari Ailus
2021-07-08 14:05           ` Niklas Söderlund
2021-07-08 14:42             ` Sakari Ailus
2021-07-06 16:08   ` Jacopo Mondi
2021-07-06 16:17     ` Niklas Söderlund [this message]
2021-04-13 18:02 ` [PATCH 02/11] rcar-vin: Fix error paths for rvin_mc_init() Niklas Söderlund
2021-07-06 16:09   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 03/11] rcar-vin: Improve async notifier cleanup paths Niklas Söderlund
2021-07-06 16:41   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 04/11] rcar-vin: Improve reuse of parallel notifier Niklas Söderlund
2021-07-06 16:51   ` Jacopo Mondi
2021-07-07  8:51     ` Niklas Söderlund
2021-04-13 18:02 ` [PATCH 05/11] rcar-vin: Rename array storing subdevice information Niklas Söderlund
2021-07-06 16:53   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 06/11] rcar-vin: Move group async notifier Niklas Söderlund
2021-07-06 16:58   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 07/11] rcar-vin: Extend group notifier DT parser to work with any port Niklas Söderlund
2021-07-07 10:24   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 08/11] rcar-vin: Create a callback to setup media links Niklas Söderlund
2021-07-07 10:33   ` Jacopo Mondi
2021-07-08 15:46     ` Niklas Söderlund
2021-04-13 18:02 ` [PATCH 09/11] rcar-vin: Specify media device ops at group creation time Niklas Söderlund
2021-07-07 10:40   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 10/11] rcar-vin: Move and rename CSI-2 link notifications Niklas Söderlund
2021-07-07 10:46   ` Jacopo Mondi
2021-04-13 18:02 ` [PATCH 11/11] rcar-vin: Add r8a779a0 support Niklas Söderlund
2021-07-07 11:09   ` Jacopo Mondi

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=YOSCNRbLfPqPSG03@oden.dyn.berto.se \
    --to=niklas.soderlund+renesas@ragnatech.se \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.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 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).