linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode
@ 2019-06-14 22:47 Douglas Anderson
  2019-06-14 22:47 ` [PATCH 2/2] drm/rockchip: Base adjustments of the mode based on prev adjustments Douglas Anderson
  2019-06-16 13:41 ` [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Heiko Stübner
  0 siblings, 2 replies; 3+ messages in thread
From: Douglas Anderson @ 2019-06-14 22:47 UTC (permalink / raw)
  To: Sandy Huang, heiko, seanpaul
  Cc: linux-rockchip, urjaman, Douglas Anderson, Yakir Yang,
	linux-kernel, dri-devel, David Airlie, linux-arm-kernel,
	Daniel Vetter

When fixing up the clock in vop_crtc_mode_fixup() we're not doing it
quite correctly.  Specifically if we've got the true clock 266666667 Hz,
we'll perform this calculation:
   266666667 / 1000 => 266666

Later when we try to set the clock we'll do clk_set_rate(266666 *
1000).  The common clock framework won't actually pick the proper clock
in this case since it always wants clocks <= the specified one.

Let's solve this by using DIV_ROUND_UP.

Fixes: b59b8de31497 ("drm/rockchip: return a true clock rate to adjusted_mode")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Yakir Yang <ykk@rock-chips.com>
---
Back in 2016 Mark Yao said he applied this to his drm fixes [1], but it's
2019 and it's still missing so I'm posting again.

[1] https://patchwork.freedesktop.org/patch/103872/

 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index e4580d8f21e1..d124f34ab9fc 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1006,7 +1006,8 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc,
 	struct vop *vop = to_vop(crtc);
 
 	adjusted_mode->clock =
-		clk_round_rate(vop->dclk, mode->clock * 1000) / 1000;
+		DIV_ROUND_UP(clk_round_rate(vop->dclk, mode->clock * 1000),
+			     1000);
 
 	return true;
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/rockchip: Base adjustments of the mode based on prev adjustments
  2019-06-14 22:47 [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Douglas Anderson
@ 2019-06-14 22:47 ` Douglas Anderson
  2019-06-16 13:41 ` [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Douglas Anderson @ 2019-06-14 22:47 UTC (permalink / raw)
  To: Sandy Huang, heiko, seanpaul
  Cc: linux-rockchip, urjaman, Douglas Anderson, linux-kernel,
	dri-devel, David Airlie, linux-arm-kernel, Daniel Vetter

In vop_crtc_mode_fixup() we fixup the mode to show what we actually
will be able to achieve.  However we should base our adjustments on
any previous adjustments that were made.

As an example, the dw_hdmi driver may wish to make some small
adjustments to clock rates in its atomic_check() function.  If it
does, it will update the adjusted_mode.  We shouldn't throw away those
adjustments.

NOTE: the version of the dw_hdmi driver upstream doesn't _actually_
make such adjustments, but downstream in Chrome OS it does.  It is
plausible that one day we'll figure out how to cleanly make that
happen in an upstream-friendly way, so we should prepare by using the
right mode.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index d124f34ab9fc..09a790c2f3a1 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1006,8 +1006,8 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc,
 	struct vop *vop = to_vop(crtc);
 
 	adjusted_mode->clock =
-		DIV_ROUND_UP(clk_round_rate(vop->dclk, mode->clock * 1000),
-			     1000);
+		DIV_ROUND_UP(clk_round_rate(vop->dclk,
+					    adjusted_mode->clock * 1000), 1000);
 
 	return true;
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode
  2019-06-14 22:47 [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Douglas Anderson
  2019-06-14 22:47 ` [PATCH 2/2] drm/rockchip: Base adjustments of the mode based on prev adjustments Douglas Anderson
@ 2019-06-16 13:41 ` Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2019-06-16 13:41 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: Sandy Huang, seanpaul, linux-rockchip, urjaman, Yakir Yang,
	linux-kernel, dri-devel, David Airlie, linux-arm-kernel,
	Daniel Vetter

Am Samstag, 15. Juni 2019, 00:47:29 CEST schrieb Douglas Anderson:
> When fixing up the clock in vop_crtc_mode_fixup() we're not doing it
> quite correctly.  Specifically if we've got the true clock 266666667 Hz,
> we'll perform this calculation:
>    266666667 / 1000 => 266666
> 
> Later when we try to set the clock we'll do clk_set_rate(266666 *
> 1000).  The common clock framework won't actually pick the proper clock
> in this case since it always wants clocks <= the specified one.
> 
> Let's solve this by using DIV_ROUND_UP.
> 
> Fixes: b59b8de31497 ("drm/rockchip: return a true clock rate to adjusted_mode")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Sean Paul <seanpaul@chromium.org>
> Reviewed-by: Yakir Yang <ykk@rock-chips.com>

I gave both patches a testrun on rk3288, rk3328 and rk3399 and
applied them to drm-misc-next thereafter


Thanks
Heiko




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-16 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14 22:47 [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Douglas Anderson
2019-06-14 22:47 ` [PATCH 2/2] drm/rockchip: Base adjustments of the mode based on prev adjustments Douglas Anderson
2019-06-16 13:41 ` [PATCH 1/2] drm/rockchip: Properly adjust to a true clock in adjusted_mode Heiko Stübner

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).