From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lelnx194.ext.ti.com ([198.47.27.80]:57187 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751492AbdJLOQ3 (ORCPT ); Thu, 12 Oct 2017 10:16:29 -0400 From: Jyri Sarha To: CC: , , , , Jyri Sarha , Subject: [PATCH] drm/tilcdc: Precalculate total frametime in tilcdc_crtc_set_mode() Date: Thu, 12 Oct 2017 17:16:15 +0300 Message-ID: <1507817775-31550-1-git-send-email-jsarha@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: stable-owner@vger.kernel.org List-ID: =EF=BB=BFWe need the frame refresh time to check if we are too close to vertical sync when updating the two framebuffer DMA registers and risk a collision. This new method is more accurate that the previous that based on mode's vrefresh value, which itself may also be inaccurate or not even initialized. Reported-by: Kevin Hao Fixes: 11abbc9f39e0 ("drm/tilcdc: Set framebuffer DMA address to HW only if= CRTC is enabled") Cc: # v4.11+ Signed-off-by: Jyri Sarha --- This patch is inteded to replace this: https://lists.freedesktop.org/archives/dri-devel/2017-October/154556.html drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/= tilcdc_crtc.c index 704db24..b2f2170 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -48,6 +48,7 @@ struct tilcdc_crtc { unsigned int lcd_fck_rate; =20 ktime_t last_vblank; + unsigned int frametime_us; =20 struct drm_framebuffer *curr_fb; struct drm_framebuffer *next_fb; @@ -292,6 +293,16 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) LCDC_V2_CORE_CLK_EN); } =20 +u32 tilcdc_mode_frametime(const struct drm_display_mode *mode) +{ + u32 totalframes =3D mode->htotal * mode->vtotal; + + if (totalframes < U32_MAX / 1000u) + return (1000u * totalframes) / mode->clock; + else + return 10u * ((100u * totalframes) / mode->clock); +} + static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) { struct tilcdc_crtc *tilcdc_crtc =3D to_tilcdc_crtc(crtc); @@ -459,6 +470,9 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) drm_framebuffer_get(fb); =20 crtc->hwmode =3D crtc->state->adjusted_mode; + + tilcdc_crtc->frametime_us =3D + tilcdc_mode_frametime(&crtc->hwmode); } =20 static void tilcdc_crtc_enable(struct drm_crtc *crtc) @@ -642,7 +656,7 @@ int tilcdc_crtc_update_fb(struct drm_crtc *crtc, spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); =20 next_vblank =3D ktime_add_us(tilcdc_crtc->last_vblank, - 1000000 / crtc->hwmode.vrefresh); + tilcdc_crtc->frametime_us); tdiff =3D ktime_to_us(ktime_sub(next_vblank, ktime_get())); =20 if (tdiff < TILCDC_VBLANK_SAFETY_THRESHOLD_US) --=20 1.9.1 Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Bu= siness ID: 0615521-4. Kotipaikka/Domicile: Helsinki