All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
To: "Stein, Alexander" <Alexander.Stein@tq-group.com>
Cc: "mani@kernel.org" <mani@kernel.org>,
	"mchehab@kernel.org" <mchehab@kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: Sony IMX290 link frequency
Date: Mon, 20 Sep 2021 12:27:48 +0100	[thread overview]
Message-ID: <CAPY8ntB-7g5FigO9rNV4YGWCeHUWkO4v1kp96mW-icGwT-rk9w@mail.gmail.com> (raw)
In-Reply-To: <01d4c7efb1ef900c499fda6af2c5a19ce923dc15.camel@tq-group.com>

Hi Alexander

On Mon, 20 Sept 2021 at 08:15, Stein, Alexander
<Alexander.Stein@tq-group.com> wrote:
>
> Hello,
>
> the imx290 driver specifies 2 tables of link frequencies, depending on
> number of lanes and the vertical resolution.
> These numbers vary from 148.5 MHz up to 445.5 MHz.
> I'm wondering where these number come from, it's not clear for me. Also
> shouldn't those numbers also depend in bits per pixel and the frames
> per second?
> I suspect that the returned link frequency is not correct which breaks
> things further down using v4l2_get_link_freq().

I looked at imx290 and little brother imx327 a few months back to get
it running with libcamera on the Pi. I have a couple of patches that
ought to be upstreamed when I get a chance [1].

The Sony datasheet provides register configurations for specific modes
(1080p, window cropping, and 720p) and frame rates, rather than a full
description of what the registers do.

It has two clock paths - one driving the pixel array, and one driving
the MIPI core. There is a FIFO between the two, so they can run at
different rates.

My conclusion is that the pixel array always runs at the same pixel
rate, whether 1080p, 720p, or cropped - 148.5MPix/s. Certainly that is
the result needed for vblank and hblank controls to work correctly in
computing frame rate. The datasheet again contains fixed register
settings for 25, 30, 50, 60, 100, and 120fps by changing HMAX
(register 0x301c/d), but they are all just linearly scaled values of
each other, so it maps cleanly onto V4L2_CID_HBLANK. VMAX is fixed for
1080p and 720p modes, so maps to V4L2_CID_VBLANK.

The MIPI PHY then runs at a link frequency sufficient to convey the
desired pixels:
- 3564 Mbit/s across 4 lanes for 1080p100/120 10bpp
- 1782 Mbit/s split across 2 or 4 lanes for 1080p or window cropped
modes up to 60fps, 10 or 12bpp.
- 1188 Mbit/s split across 2 or 4 lanes for 720p up to 60fps, 10 or 12bpp
This is controlled predominantly by INCKSEL1 & 2 (registers 0x305c/d).
I verified the actual link frequencies used on a scope, and they are
as described.
1782Mbit/s is sufficient for 1920x1080@60fps 12bpp. Cropping or 10bpp
just increases the per line blanking period on the CSI2 interface.

AFAICT you could just always run at the 1782 Mbit/s rate with slightly
increased idle time on the CSI2 bus for the 720p mode, but that isn't
the way Sony have specified it.

There is a further register to halve the link frequency again for max
25/30fps modes (0x3405), although doing so has limited benefit (it'd
increase rolling shutter effects as it would increase the temporal
difference between each line).

I hope that makes things a little clearer. Indeed the current driver
is slightly wrong, but only in relation to pixel rate, not link
frequency.

  Dave

[1] https://github.com/raspberrypi/linux/commits/rpi-5.10.y/drivers/media/i2c/imx290.c

> Best regards
> Alexander
> --
> i.A. Alexander Stein
> Entwicklung Standort Chemnitz
> Tel. +49 371 433151-0, Fax +49 371 433151-22
> Zwickauer Straße 173, 09116 Chemnitz
> mailto: Alexander.Stein@tq-group.com
>
> TQ-Systems GmbH
> Mühlstraße 2, Gut Delling, 82229 Seefeld
> Amtsgericht München, HRB 105018
> Sitz der Gesellschaft: Seefeld
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> www.tq-group.com

  reply	other threads:[~2021-09-20 11:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20  7:08 Sony IMX290 link frequency Stein, Alexander
2021-09-20 11:27 ` Dave Stevenson [this message]
2021-09-21  6:49   ` (EXT) " Stein, Alexander
2021-09-21 10:41     ` Dave Stevenson
2021-09-23 13:44       ` (EXT) " Stein, Alexander
2021-09-27 13:56         ` Dave Stevenson

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=CAPY8ntB-7g5FigO9rNV4YGWCeHUWkO4v1kp96mW-icGwT-rk9w@mail.gmail.com \
    --to=dave.stevenson@raspberrypi.com \
    --cc=Alexander.Stein@tq-group.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mani@kernel.org \
    --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.