linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lubomir Rintel <lkundrak@v3.sk>
To: jacopo mondi <jacopo@jmondi.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-media@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	James Cameron <quozl@laptop.org>, Pavel Machek <pavel@ucw.cz>,
	Libin Yang <lbyang@marvell.com>,
	Albert Wang <twang13@marvell.com>
Subject: Re: [PATCH v3 14/14] [media] marvell-ccic: provide a clock for the sensor
Date: Thu, 25 Apr 2019 15:33:19 +0200	[thread overview]
Message-ID: <3b7fb8442a5e0106f11e328f5bb4f0f46483ccf4.camel@v3.sk> (raw)
In-Reply-To: <20181122200747.GA6788@w540>

On Fri, 2018-11-23 at 08:44 +0100, jacopo mondi wrote:
> HI Lubomir,
> 
> On Tue, Nov 20, 2018 at 11:03:19AM +0100, Lubomir Rintel wrote:
> > The sensor needs the MCLK clock running when it's being probed. On
> > platforms where the sensor is instantiated from a DT (MMP2) it is going
> > to happen asynchronously.
> > 
> > Therefore, the current modus operandi, where the bridge driver fiddles
> > with the sensor power and clock itself is not going to fly. As the comments
> > wisely note, this doesn't even belong there.
> > 
> > Luckily, the ov7670 driver is already able to control its power and
> > reset lines, we can just drop the MMP platform glue altogether.
> > 
> > It also requests the clock via the standard clock subsystem. Good -- let's
> > set up a clock instance so that the sensor can ask us to enable the clock.
> > Note that this is pretty dumb at the moment: the clock is hardwired to a
> > particular frequency and parent. It was always the case.
> > 
> > Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> > 
> > ---
> > Changes since v1:
> > - [kbuild/ia64] depend on COMMON_CLK.
> > - [smatch] fix bad return in mcam_v4l_open() leading to lock not getting
> >   released on error.
> > 
> >  drivers/media/platform/marvell-ccic/Kconfig   |   2 +
> >  .../media/platform/marvell-ccic/cafe-driver.c |   9 +-
> >  .../media/platform/marvell-ccic/mcam-core.c   | 156 +++++++++++++++---
> >  .../media/platform/marvell-ccic/mcam-core.h   |   3 +
> >  .../media/platform/marvell-ccic/mmp-driver.c  | 152 ++---------------
> >  .../linux/platform_data/media/mmp-camera.h    |   2 -
> >  6 files changed, 161 insertions(+), 163 deletions(-)
...
> >  int mccic_register(struct mcam_camera *cam)
> >  {
> > +	struct clk_init_data mclk_init = { };
> >  	int ret;
> > 
> >  	/*
> > @@ -1838,7 +1925,10 @@ int mccic_register(struct mcam_camera *cam)
> >  	mcam_set_config_needed(cam, 1);
> >  	cam->pix_format = mcam_def_pix_format;
> >  	cam->mbus_code = mcam_def_mbus_code;
> > -	mcam_ctlr_init(cam);
> > +
> > +	mcam_clk_enable(cam);
> 
> Am I mis-interpreting the clock bindings, or here you expose a clock
> source, and sensors are supposed to reference it if they need to. It
> is then the sensor driver that by calling clk_prepare_enable() on the
> referenced clock triggers the call of the 'enable' function. It seems
> to me that here you have exposed a clock provider, but the provider
> itself enables its clocks...

What mcam_clk_enable() enables is the clocks for the CCIC IP core; so
that we're able to access the registers.

(Note to self: we're enabling all the clocks here, we just need the
"axi" clock, clk_enable(cam->clk[0]), as done elsewhere, should be
sufficient.)

On the other hand, the "mclk" clock provider that is only registered
below provides the clock for the sensor itself that's provided by the
CCIC block.

>  Am I confused?

Chances are that I am. But maybe you're confusing mcam_clk_enable(cam)
(consumer, enables the CCIC's input clocks) with mclk_enable()
(provider, makes CCIC generate the clock for the sensor).

> 
> Thanks
>    j
> 
> > +	mcam_ctlr_init(cam); // XXX?

This looks like something I shouldn't have left in place though...

> > +	mcam_clk_disable(cam);
> > 
> >  	/*
> >  	 * Register sensor notifier.
> > @@ -1857,6 +1947,26 @@ int mccic_register(struct mcam_camera *cam)
> >  		goto out;
> >  	}
> > 
> > +	/*
> > +	 * Register sensor master clock.
> > +	 */
> > +	mclk_init.parent_names = NULL;
> > +	mclk_init.num_parents = 0;
> > +	mclk_init.ops = &mclk_ops;
> > +	mclk_init.name = "mclk";
> > +
> > +	of_property_read_string(cam->dev->of_node, "clock-output-names",
> > +							&mclk_init.name);
> > +
> > +	cam->mclk_hw.init = &mclk_init;
> > +
> > +	cam->mclk = devm_clk_register(cam->dev, &cam->mclk_hw);
> > +	if (IS_ERR(cam->mclk)) {
> > +		ret = PTR_ERR(cam->mclk);
> > +		dev_err(cam->dev, "can't register clock\n");
> > +		goto out;
> > +	}
> > +
> >  	/*
> >  	 * If so requested, try to get our DMA buffers now.
> >  	 */
> > @@ -1884,7 +1994,7 @@ void mccic_shutdown(struct mcam_camera *cam)
> >  	 */
> >  	if (!list_empty(&cam->vdev.fh_list)) {
> >  		cam_warn(cam, "Removing a device with users!\n");
> > -		mcam_ctlr_power_down(cam);
> > +		sensor_call(cam, core, s_power, 0);
> >  	}
> >  	if (cam->buffer_mode == B_vmalloc)
> >  		mcam_free_dma_bufs(cam);
> > @@ -1906,7 +2016,8 @@ void mccic_suspend(struct mcam_camera *cam)
> >  		enum mcam_state cstate = cam->state;
> > 
> >  		mcam_ctlr_stop_dma(cam);
> > -		mcam_ctlr_power_down(cam);
> > +		sensor_call(cam, core, s_power, 0);
> > +		mcam_clk_disable(cam);
> >  		cam->state = cstate;
> >  	}
> >  	mutex_unlock(&cam->s_mutex);
> > 
...

Cheers,
Lubo


      reply	other threads:[~2019-04-25 13:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 10:03 [PATCH v3 0/14] media: make Marvell camera work on DT-based OLPC XO-1.75 Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 01/14] media: ov7670: split register setting from set_fmt() logic Lubomir Rintel
2018-11-22 18:37   ` jacopo mondi
2018-11-28 17:10     ` Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 02/14] media: ov7670: split register setting from set_framerate() logic Lubomir Rintel
2019-01-14 23:03   ` Sakari Ailus
2019-01-15  8:30     ` Lubomir Rintel
2019-01-15  8:45       ` Sakari Ailus
2018-11-20 10:03 ` [PATCH v3 03/14] media: ov7670: hook s_power onto v4l2 core Lubomir Rintel
2018-11-22 12:21   ` Sakari Ailus
2018-11-28 11:29     ` Lubomir Rintel
2019-01-10 16:59       ` Sakari Ailus
2019-01-13 16:38         ` Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 04/14] media: ov7670: control clock along with power Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 05/14] media: dt-bindings: marvell,mmp2-ccic: Add Marvell MMP2 camera Lubomir Rintel
2018-11-22 20:08   ` jacopo mondi
2019-04-25 14:28     ` Lubomir Rintel
2018-11-27 10:08   ` Sakari Ailus
2018-11-20 10:03 ` [PATCH v3 06/14] [media] marvell-ccic: fix DMA s/g desc number calculation Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 07/14] [media] marvell-ccic: don't generate EOF on parallel bus Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 08/14] Revert "[media] marvell-ccic: reset ccic phy when stop streaming for stability" Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 09/14] [media] marvell-ccic: drop unused stuff Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 10/14] [media] marvell-ccic/mmp: enable clock before accessing registers Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 11/14] [media] marvell-ccic: rename the clocks Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 12/14] [media] marvell-ccic/mmp: add devicetree support Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 13/14] [media] marvell-ccic: use async notifier to get the sensor Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 14/14] [media] marvell-ccic: provide a clock for " Lubomir Rintel
2018-11-23  7:44   ` jacopo mondi
2019-04-25 13:33     ` Lubomir Rintel [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=3b7fb8442a5e0106f11e328f5bb4f0f46483ccf4.camel@v3.sk \
    --to=lkundrak@v3.sk \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jacopo@jmondi.org \
    --cc=lbyang@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=quozl@laptop.org \
    --cc=robh+dt@kernel.org \
    --cc=twang13@marvell.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).