From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo+renesas@jmondi.org>
Cc: David Airlie <airlied@linux.ie>,
ulrich.hecht+renesas@gmail.com, kieran.bingham@ideasonboard.com,
"open list:DRM DRIVERS FOR RENESAS"
<dri-devel@lists.freedesktop.org>,
"open list:DRM DRIVERS FOR RENESAS"
<linux-renesas-soc@vger.kernel.org>,
Jacopo Mondi <jacopo@jmondi.org>
Subject: Re: [PATCH v2 2/2] drm: rcar-du: Improve non-DPLL clock selection
Date: Mon, 20 Aug 2018 23:03:21 +0300 [thread overview]
Message-ID: <2548120.ZfZBKIsRRX@avalon> (raw)
In-Reply-To: <1534778777-6002-3-git-send-email-jacopo+renesas@jmondi.org>
Hi Jacopo,
Thank you for the patch.
On Monday, 20 August 2018 18:26:17 EEST Jacopo Mondi wrote:
> From: Jacopo Mondi <jacopo@jmondi.org>
>
> DU channels not equipped with a DPLL use an internal (aka SoC provided) or
I'd say "SoC internal (provided by the CPG)"
> external clock source combined with an internal divider to generate the
and here "a DU internal divider" to avoid confusion with an SoC internal
divider outside of the DU.
> desired output dot clock frequency.
>
> The current clock selection procedure does not fully exploit the ability
> of external clock sources to generate the exact dot clock frequency by
> themselves, but relies instead on tuning the internal DU clock divider
> only, resulting in a less precise clock generation process.
>
> When possible, and desirable, ask the external clock source for the exact
> output dot clock frequency, and test the returned frequency against the
> internally generated one to better approximate the desired output dot clock.
To make this a big more generic, I' say "and select the clock source that
produces the frequency closest to the desired output dot clock".
> This patch specifically targets platforms (like Salvator-X[S] and ULCBs)
> where the DU's input dotclock.in is generated by the versaclock VC5 clock
> source, which is capable of generating the exact rate the DU needs as pixel
> clock output.
>
> This patch fixes higher resolution modes wich requires an high pixel clock
s/wich/which/
> output currently not working on non-HDMI DU channel (as VGA 1920x1080@60Hz).
Maybe "(such as 1920x1080@60Hz on the VGA output)" ?
>
> Fixes: 1b30dbde8 "drm: rcar-du: Add support for external pixel clock"
Please use the output of git show --pretty=fixes to generate the fixes line.
Your SHA1 needs more digits, and the subject should be enclosed with
parentheses.
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
> drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 53 +++++++++++++++++++------------
> 1 file changed, 32 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c index 077e681..98ae697 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> @@ -258,42 +258,53 @@ static void rcar_du_crtc_set_display_timing(struct
> rcar_du_crtc *rcrtc)
>
> escr = ESCR_DCLKSEL_DCLKIN | div;
> } else {
> - unsigned long clk;
> + unsigned long dotclkin_rate;
> + struct clk *dotclkin_clk;
> + unsigned long cpg_dist;
> u32 div;
>
> /*
> * Compute the clock divisor and select the internal or external
> * dot clock based on the requested frequency.
> */
> - clk = clk_get_rate(rcrtc->clock);
> - div = DIV_ROUND_CLOSEST(clk, mode_clock);
> - div = clamp(div, 1U, 64U) - 1;
> -
> + dotclkin_clk = rcrtc->clock;
> + dotclkin_rate = clk_get_rate(rcrtc->clock);
> + div = clamp(DIV_ROUND_CLOSEST(dotclkin_rate, mode_clock),
> + 1UL, 64UL) - 1;
> + cpg_dist = abs(dotclkin_rate / (div + 1) - mode_clock);
> escr = ESCR_DCLKSEL_CLKS | div;
>
> if (rcrtc->extclock) {
> - unsigned long extclk;
> - unsigned long extrate;
> - unsigned long rate;
> - u32 extdiv;
> -
> - extclk = clk_get_rate(rcrtc->extclock);
> - extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock);
> - extdiv = clamp(extdiv, 1U, 64U) - 1;
> + unsigned long ext_rate;
> + unsigned long ext_dist;
>
> - extrate = extclk / (extdiv + 1);
> - rate = clk / (div + 1);
> + /*
> + * If an external clock source is present ask it
> + * for the exact dot clock rate, and test the
> + * returned value against the cpg provided one.
> + */
> + ext_rate = clk_round_rate(rcrtc->extclock,
> + mode_clock);
>
> - if (abs((long)extrate - (long)mode_clock) <
> - abs((long)rate - (long)mode_clock))
> - escr = ESCR_DCLKSEL_DCLKIN | extdiv;
> + div = clamp(DIV_ROUND_CLOSEST(ext_rate, mode_clock),
> + 1UL, 64UL) - 1;
> + ext_dist = abs(ext_rate / (div + 1) - mode_clock);
>
> - dev_dbg(rcrtc->group->dev->dev,
> - "mode clock %lu extrate %lu rate %lu ESCR 0x%08x\n",
> - mode_clock, extrate, rate, escr);
> + if (ext_dist < cpg_dist) {
> + dotclkin_clk = rcrtc->extclock;
> + dotclkin_rate = ext_rate;
> + escr = ESCR_DCLKSEL_DCLKIN | div;
> + }
> }
I think we can do something much simpler here by factoring some code out to a
function. I'll send a proposal in reply to this e-mail.
> + dev_dbg(rcrtc->group->dev->dev, "mode clock %lu %s rate %lu\n",
> + mode_clock, dotclkin_clk == rcrtc->clock ? "cpg" : "ext",
> + dotclkin_rate);
> + clk_set_rate(dotclkin_clk, dotclkin_rate);
> }
>
> + dev_dbg(rcrtc->group->dev->dev, "%s: ESCR 0x%08x\n", __func__, escr);
> +
> rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR,
> escr);
> rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0);
--
Regards,
Laurent Pinchart
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo+renesas@jmondi.org>
Cc: Jacopo Mondi <jacopo@jmondi.org>, David Airlie <airlied@linux.ie>,
kieran.bingham@ideasonboard.com,
"open list:DRM DRIVERS FOR RENESAS"
<dri-devel@lists.freedesktop.org>,
"open list:DRM DRIVERS FOR RENESAS"
<linux-renesas-soc@vger.kernel.org>,
ulrich.hecht+renesas@gmail.com
Subject: Re: [PATCH v2 2/2] drm: rcar-du: Improve non-DPLL clock selection
Date: Mon, 20 Aug 2018 23:03:21 +0300 [thread overview]
Message-ID: <2548120.ZfZBKIsRRX@avalon> (raw)
In-Reply-To: <1534778777-6002-3-git-send-email-jacopo+renesas@jmondi.org>
Hi Jacopo,
Thank you for the patch.
On Monday, 20 August 2018 18:26:17 EEST Jacopo Mondi wrote:
> From: Jacopo Mondi <jacopo@jmondi.org>
>
> DU channels not equipped with a DPLL use an internal (aka SoC provided) or
I'd say "SoC internal (provided by the CPG)"
> external clock source combined with an internal divider to generate the
and here "a DU internal divider" to avoid confusion with an SoC internal
divider outside of the DU.
> desired output dot clock frequency.
>
> The current clock selection procedure does not fully exploit the ability
> of external clock sources to generate the exact dot clock frequency by
> themselves, but relies instead on tuning the internal DU clock divider
> only, resulting in a less precise clock generation process.
>
> When possible, and desirable, ask the external clock source for the exact
> output dot clock frequency, and test the returned frequency against the
> internally generated one to better approximate the desired output dot clock.
To make this a big more generic, I' say "and select the clock source that
produces the frequency closest to the desired output dot clock".
> This patch specifically targets platforms (like Salvator-X[S] and ULCBs)
> where the DU's input dotclock.in is generated by the versaclock VC5 clock
> source, which is capable of generating the exact rate the DU needs as pixel
> clock output.
>
> This patch fixes higher resolution modes wich requires an high pixel clock
s/wich/which/
> output currently not working on non-HDMI DU channel (as VGA 1920x1080@60Hz).
Maybe "(such as 1920x1080@60Hz on the VGA output)" ?
>
> Fixes: 1b30dbde8 "drm: rcar-du: Add support for external pixel clock"
Please use the output of git show --pretty=fixes to generate the fixes line.
Your SHA1 needs more digits, and the subject should be enclosed with
parentheses.
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
> drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 53 +++++++++++++++++++------------
> 1 file changed, 32 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c index 077e681..98ae697 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> @@ -258,42 +258,53 @@ static void rcar_du_crtc_set_display_timing(struct
> rcar_du_crtc *rcrtc)
>
> escr = ESCR_DCLKSEL_DCLKIN | div;
> } else {
> - unsigned long clk;
> + unsigned long dotclkin_rate;
> + struct clk *dotclkin_clk;
> + unsigned long cpg_dist;
> u32 div;
>
> /*
> * Compute the clock divisor and select the internal or external
> * dot clock based on the requested frequency.
> */
> - clk = clk_get_rate(rcrtc->clock);
> - div = DIV_ROUND_CLOSEST(clk, mode_clock);
> - div = clamp(div, 1U, 64U) - 1;
> -
> + dotclkin_clk = rcrtc->clock;
> + dotclkin_rate = clk_get_rate(rcrtc->clock);
> + div = clamp(DIV_ROUND_CLOSEST(dotclkin_rate, mode_clock),
> + 1UL, 64UL) - 1;
> + cpg_dist = abs(dotclkin_rate / (div + 1) - mode_clock);
> escr = ESCR_DCLKSEL_CLKS | div;
>
> if (rcrtc->extclock) {
> - unsigned long extclk;
> - unsigned long extrate;
> - unsigned long rate;
> - u32 extdiv;
> -
> - extclk = clk_get_rate(rcrtc->extclock);
> - extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock);
> - extdiv = clamp(extdiv, 1U, 64U) - 1;
> + unsigned long ext_rate;
> + unsigned long ext_dist;
>
> - extrate = extclk / (extdiv + 1);
> - rate = clk / (div + 1);
> + /*
> + * If an external clock source is present ask it
> + * for the exact dot clock rate, and test the
> + * returned value against the cpg provided one.
> + */
> + ext_rate = clk_round_rate(rcrtc->extclock,
> + mode_clock);
>
> - if (abs((long)extrate - (long)mode_clock) <
> - abs((long)rate - (long)mode_clock))
> - escr = ESCR_DCLKSEL_DCLKIN | extdiv;
> + div = clamp(DIV_ROUND_CLOSEST(ext_rate, mode_clock),
> + 1UL, 64UL) - 1;
> + ext_dist = abs(ext_rate / (div + 1) - mode_clock);
>
> - dev_dbg(rcrtc->group->dev->dev,
> - "mode clock %lu extrate %lu rate %lu ESCR 0x%08x\n",
> - mode_clock, extrate, rate, escr);
> + if (ext_dist < cpg_dist) {
> + dotclkin_clk = rcrtc->extclock;
> + dotclkin_rate = ext_rate;
> + escr = ESCR_DCLKSEL_DCLKIN | div;
> + }
> }
I think we can do something much simpler here by factoring some code out to a
function. I'll send a proposal in reply to this e-mail.
> + dev_dbg(rcrtc->group->dev->dev, "mode clock %lu %s rate %lu\n",
> + mode_clock, dotclkin_clk == rcrtc->clock ? "cpg" : "ext",
> + dotclkin_rate);
> + clk_set_rate(dotclkin_clk, dotclkin_rate);
> }
>
> + dev_dbg(rcrtc->group->dev->dev, "%s: ESCR 0x%08x\n", __func__, escr);
> +
> rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR,
> escr);
> rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0);
--
Regards,
Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-08-20 23:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-20 15:26 [PATCH v2 0/2] drm: rcar-du: Rework clock configuration Jacopo Mondi
2018-08-20 15:26 ` Jacopo Mondi
2018-08-20 15:26 ` [PATCH v2 1/2] drm: rcar-du: Rework clock configuration based on hardware limits Jacopo Mondi
2018-08-20 15:26 ` Jacopo Mondi
2018-08-20 15:26 ` [PATCH v2 2/2] drm: rcar-du: Improve non-DPLL clock selection Jacopo Mondi
2018-08-20 15:26 ` Jacopo Mondi
2018-08-20 20:03 ` Laurent Pinchart [this message]
2018-08-20 20:03 ` Laurent Pinchart
2018-08-20 21:49 ` [PATCH] " Laurent Pinchart
2018-08-20 21:49 ` Laurent Pinchart
2018-08-20 22:12 ` Laurent Pinchart
2018-08-20 22:12 ` Laurent Pinchart
2018-08-21 7:33 ` jacopo mondi
2018-08-21 7:33 ` jacopo mondi
2018-08-21 8:08 ` Laurent Pinchart
2018-08-21 8:08 ` Laurent Pinchart
2018-08-21 15:52 ` Kieran Bingham
2018-08-21 15:52 ` Kieran Bingham
2018-08-21 10:35 ` jacopo mondi
2018-08-21 10:35 ` jacopo mondi
2018-08-21 13:22 ` jacopo mondi
2018-08-21 13:22 ` 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=2548120.ZfZBKIsRRX@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=jacopo+renesas@jmondi.org \
--cc=jacopo@jmondi.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=ulrich.hecht+renesas@gmail.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 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.