diff mbox

drm/rockchip: Properly adjust to a true clock in adjusted_mode

Message ID 1470684571-37955-1-git-send-email-seanpaul@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Sean Paul Aug. 8, 2016, 7:29 p.m. UTC
From: Douglas Anderson <dianders@chromium.org>

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.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Yakir Yang Aug. 9, 2016, 2:53 a.m. UTC | #1
Sean,


On 08/09/2016 03:29 AM, Sean Paul wrote:
> From: Douglas Anderson <dianders@chromium.org>
>
> 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.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Sean Paul <seanpaul@chromium.org>

After discuss with Zheng Xing (Rockchip clock contributor), we think 
this patch looks good, so:

Reviewed-by: Yakir Yang <ykk@rock-chips.com>

> ---
>   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 31744fe..1bbffaf 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> @@ -891,7 +891,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;
>   }
yao mark Aug. 9, 2016, 3:28 a.m. UTC | #2
On 2016年08月09日 03:29, Sean Paul wrote:
> From: Douglas Anderson <dianders@chromium.org>
>
> 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.
Good, applied to my drm fixes.

Thanks

> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Sean Paul <seanpaul@chromium.org>
> ---
>   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 31744fe..1bbffaf 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> @@ -891,7 +891,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;
>   }
diff mbox

Patch

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 31744fe..1bbffaf 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -891,7 +891,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;
 }