devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Julien Stephan <jstephan@baylibre.com>
Cc: AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Louis Kuo <louis.kuo@mediatek.com>,
	Phi-bang Nguyen <pnguyen@baylibre.com>,
	Florian Sylvestre <fsylvestre@baylibre.com>,
	Andy Hsieh <andy.hsieh@mediatek.com>,
	Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	linux-media@vger.kernel.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Paul Elder <paul.elder@ideasonboard.com>,
	Rob Herring <robh+dt@kernel.org>
Subject: Re: [PATCH v4 3/5] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface
Date: Sat, 15 Jun 2024 03:47:05 +0300	[thread overview]
Message-ID: <20240615004705.GI9171@pendragon.ideasonboard.com> (raw)
In-Reply-To: <CAEHHSvZPATFV=w451KaaT+e__EK9u3Vc5ORPRQ-Gfa4rJ_o8hA@mail.gmail.com>

On Fri, Jun 14, 2024 at 04:54:47PM +0200, Julien Stephan wrote:
> Le ven. 14 juin 2024 à 16:43, Laurent Pinchart a écrit :
> > On Fri, Jun 14, 2024 at 04:14:52PM +0200, Julien Stephan wrote:
> > > Le ven. 14 juin 2024 à 14:34, Laurent Pinchart a écrit :
> > > > On Fri, Jun 14, 2024 at 12:38:15PM +0200, Julien Stephan wrote:
> > > > > Le mer. 12 juin 2024 à 10:06, AngeloGioacchino Del Regno a écrit :
> > > > > >
> > > > > > Il 10/06/24 16:39, Julien Stephan ha scritto:
> > > > > [...]
> > > > > > >>
> > > > > > >>> +     writel(0x10001, input->base + SENINF_TG1_SEN_CK);
> > > > > > >>
> > > > > > >> Unroll this one... this is the TG1 sensor clock divider.
> > > > > > >>
> > > > > > >> CLKFL GENMASK(5, 0)
> > > > > > >> CLKRS GENMASK(13, 8)
> > > > > > >> CLKCNT GENMASK(21,16)
> > > > > > >>
> > > > > > >> Like this, I don't get what you're trying to set, because you're using a fixed
> > > > > > >> sensor clock rate, meaning that only a handful of camera sensors will be usable.
> > > > > > >>
> > > > > > >> Is this 8Mhz? 16? 24? what? :-)
> > > > > > >>
> > > > > > >> Two hints:
> > > > > > >>    - sensor_clk = clk_get_rate(isp_clk) / (tg1_sen_ck_clkcnt + 1);
> > > > > > >>    - int mtk_seninf_set_sensor_clk(u8 rate_mhz);
> > > > > > >>
> > > > > > >> Please :-)
> > > > > > >
> > > > > > > Hi Angelo,
> > > > > > >
> > > > > > > I think I get your point about not hardcoding the sensor rate, but I
> > > > > > > am not sure how to use
> > > > > > > a mtk_seninf_set_sensor_clk(u8 rate_mhz); function.
> > > > > > >
> > > > > > > Where would it be called? How is it exposed to the user?
> > > > > > >
> > > > > >
> > > > > > As for where: setup, streaming start, resolution change (which may be covered
> > > > > > by streaming start anyway, as a change should be calling stop->start anyway).
> > > > > >
> > > > > > And for the how is it exposed to the user - well, depends what you mean for user,
> > > > > > but it's all standard V4L2 API :-)
> > > > > >
> > > > > > Last but not least, I can give you another hint....
> > > > > >
> > > > > > struct media_entity *entity = (something_here);
> > > > > > struct media_pad *mpad;
> > > > > > struct v4l2_subdev *cam_subdev;
> > > > > > struct v4l2_ctrl *ctl;
> > > > > > s64 link_frequency, pixel_clock;
> > > > > >
> > > > > > if (entity->pads[0].flags & MEDIA_PAD_FL_SINK)
> > > > > >     return -E_NOT_A_CAMERA_SENSOR_WE_IGNORE_THIS_ONE;
> > > > > >
> > > > > > pad = media_pad_remote_pad_first(&entity->pads[0]);
> > > > > > if (!pad)
> > > > > >    return -ENOENT;
> > > > > >
> > > > > > if (!is_media_entity_v4l2_subdev(pad->entity))
> > > > > >    return -ENOENT;
> > > > > >
> > > > > > if (pad->entity->function != MEDIA_ENT_F_CAM_SENSOR)
> > > > > >    return -ENOENT;
> > > > > >
> > > > >
> > > > > Hi Angelo,
> > > > >
> > > > > Thank you for the detailed explanation :)
> > > > > However, I can't make it work because in my case, seninf is connected
> > > > > to an external ISP
> > > > > so pad->entity->function == MEDIA_ENT_F_PROC_VIDEO_ISP.
> > > > >
> > > > > How can I get the pad corresponding to the sensor?
> > > >
> > > > You don't have to. You can drop that check, and get the link frequency
> > > > of the source subdev with v4l2_get_link_freq(), whatever it is.
> > > >
> > > > > > cam_subdev = media_entity_to_v4l2_subdev(pad->entity);
> > > > > > ctl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
> > > > >
> > > > > Is this mandatory to implement V4L2_CID_PIXEL_RATE ?
> > > > > Should I return an error if not found?
> > > >
> > > > Does SENINF need to know both the pixel rate and link frequency ?
> > > > V4L2_CID_PIXEL_RATE is very ill-defined, at the moment it only makes
> > > > sense as a value relative to the sensor pixel array, and doesn't really
> > > > apply further down in the pipeline. What information do you need to
> > > > program the SENINF ?
> > >
> > > Hi Laurent,
> > >
> > > I need to know the clock divider for the sensor
> >
> > Could you provide some details on how the SENINF uses that divisor ?
> > What does it control, and what are the constraints ?
> 
> According to the datasheet,  SENINF_TG1_SEN_CK[21:16] :CLKCNT : Sensor
> master clock will be ISP_clock/(CLKCNT+1) where CLKCNT >= 1

I'll need more information. My guess so far is that there's a FIFO
somewhere in the SENINF, with the pixel bus clocked by the CSI-2 clock
before the FIFO, and by the "Sensor master clock" after the FIFO. Is
that right ? If so, the simplest approach would be to use the link
frequency to compute the pixel clock before the FIFO, and make sure that
the sensor master clock will be larger than or equal to that.

A better approach from a power consumption point of view would be to
consider horizontal blanking. The FIFO can fill faster than it gets
emptied during the active portion of the line and then drain during
blanking. This allows for a slower clock on the output side. You will
need to pick an output clock frequency that

- on average is larger than the number of active pixels per line divided
  by the line duration ; and

- ensures the FIFO never overflows during the active portion of the line,
  for cases where the line length is larger than the FIFO size.

> > > > > > /* multiplier is usually bits per pixel, divider is usually num of lanes */
> > > > > > link_frequency = v4l2_get_link_freq(cam_subdev->ctrl_handler, multiplier, divider);
> > > > > > pixel_clock = v4l2_ctrl_g_ctrl_int64(ctl);
> > > > >
> > > > > How to know the sensor clock given link_frequency and pixel_clock?
> > > > > Can you point me to drivers doing something similar?
> > > > >
> > > > > >
> > > > > > ....now you know what the sensor wants, set the seninf sensor clock accordingly.
> > > > > >
> > > > > > Cheers
> > > > > > Angelo
> > > > > >
> > > > > [...]

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-06-15  0:47 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 14:14 [PATCH v4 0/5] Add Mediatek ISP3.0 Julien Stephan
2024-01-10 14:14 ` [PATCH v4 1/5] dt-bindings: media: add mediatek ISP3.0 sensor interface Julien Stephan
2024-01-11  8:15   ` Laurent Pinchart
2024-01-12  7:32   ` Krzysztof Kozlowski
2024-06-07  8:52     ` Julien Stephan
2024-06-07 14:41       ` Laurent Pinchart
2024-06-10  7:54         ` Krzysztof Kozlowski
2024-06-10  8:54           ` Laurent Pinchart
2024-06-10 10:18             ` Krzysztof Kozlowski
2024-06-10 16:10               ` Conor Dooley
2024-06-10 16:19                 ` Conor Dooley
2024-06-10  7:39       ` Krzysztof Kozlowski
2024-01-10 14:14 ` [PATCH v4 2/5] dt-bindings: media: add mediatek ISP3.0 camsv Julien Stephan
2024-01-12  7:34   ` Krzysztof Kozlowski
2024-01-12  7:41     ` Laurent Pinchart
2024-01-12  7:49       ` Krzysztof Kozlowski
2024-01-10 14:14 ` [PATCH v4 3/5] media: platform: mediatek: isp_30: add mediatek ISP3.0 sensor interface Julien Stephan
2024-01-11  2:46   ` CK Hu (胡俊光)
2024-01-11 12:04   ` AngeloGioacchino Del Regno
2024-02-12 15:07     ` Julien Stephan
2024-06-10 14:39     ` Julien Stephan
2024-06-12  8:06       ` AngeloGioacchino Del Regno
2024-06-14 10:38         ` Julien Stephan
2024-06-14 12:33           ` Laurent Pinchart
2024-06-14 14:14             ` Julien Stephan
2024-06-14 14:42               ` Laurent Pinchart
2024-06-14 14:54                 ` Julien Stephan
2024-06-15  0:47                   ` Laurent Pinchart [this message]
2024-07-04 13:41                     ` Julien Stephan
2024-02-15  9:21   ` Sakari Ailus
2024-03-20  9:04   ` CK Hu (胡俊光)
2024-01-10 14:14 ` [PATCH v4 4/5] media: platform: mediatek: isp_30: add mediatek ISP3.0 camsv Julien Stephan
2024-01-11 12:07   ` AngeloGioacchino Del Regno
2024-01-12  0:58   ` CK Hu (胡俊光)
2024-01-12  1:48   ` CK Hu (胡俊光)
2024-01-12  3:55   ` CK Hu (胡俊光)
2024-02-15 11:55   ` Sakari Ailus
2024-03-18  3:50   ` CK Hu (胡俊光)
2024-03-18  5:18   ` CK Hu (胡俊光)
2024-03-18  5:42   ` CK Hu (胡俊光)
2024-03-19  8:47   ` CK Hu (胡俊光)
2024-03-20  9:36   ` CK Hu (胡俊光)
2024-01-10 14:14 ` [PATCH v4 5/5] arm64: dts: mediatek: mt8365: Add support for camera Julien Stephan
2024-01-11  8:32   ` Laurent Pinchart
2024-01-11  8:08 ` [PATCH v4 0/5] Add Mediatek ISP3.0 Laurent Pinchart

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=20240615004705.GI9171@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=andy.hsieh@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fsylvestre@baylibre.com \
    --cc=jstephan@baylibre.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=louis.kuo@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=paul.elder@ideasonboard.com \
    --cc=pnguyen@baylibre.com \
    --cc=robh+dt@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).