Commit ce99f720 authored by Jyri Sarha's avatar Jyri Sarha

drm/tilcdc: Precalculate total frametime in tilcdc_crtc_set_mode()

We need the total 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 is inaccurate or may not
even be initialized.
Reported-by: default avatarKevin Hao <kexin.hao@windriver.com>
Fixes: 11abbc9f ("drm/tilcdc: Set framebuffer DMA address to HW only if CRTC is enabled")
Cc: <stable@vger.kernel.org> # v4.11+
Signed-off-by: default avatarJyri Sarha <jsarha@ti.com>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
parent ba3fd954
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/of_graph.h> #include <linux/of_graph.h>
#include <linux/math64.h>
#include "tilcdc_drv.h" #include "tilcdc_drv.h"
#include "tilcdc_regs.h" #include "tilcdc_regs.h"
...@@ -48,6 +49,7 @@ struct tilcdc_crtc { ...@@ -48,6 +49,7 @@ struct tilcdc_crtc {
unsigned int lcd_fck_rate; unsigned int lcd_fck_rate;
ktime_t last_vblank; ktime_t last_vblank;
unsigned int hvtotal_us;
struct drm_framebuffer *curr_fb; struct drm_framebuffer *curr_fb;
struct drm_framebuffer *next_fb; struct drm_framebuffer *next_fb;
...@@ -292,6 +294,12 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) ...@@ -292,6 +294,12 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc)
LCDC_V2_CORE_CLK_EN); LCDC_V2_CORE_CLK_EN);
} }
uint tilcdc_mode_hvtotal(const struct drm_display_mode *mode)
{
return (uint) div_u64(1000llu * mode->htotal * mode->vtotal,
mode->clock);
}
static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) static void tilcdc_crtc_set_mode(struct drm_crtc *crtc)
{ {
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
...@@ -459,6 +467,9 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc) ...@@ -459,6 +467,9 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *crtc)
drm_framebuffer_get(fb); drm_framebuffer_get(fb);
crtc->hwmode = crtc->state->adjusted_mode; crtc->hwmode = crtc->state->adjusted_mode;
tilcdc_crtc->hvtotal_us =
tilcdc_mode_hvtotal(&crtc->hwmode);
} }
static void tilcdc_crtc_enable(struct drm_crtc *crtc) static void tilcdc_crtc_enable(struct drm_crtc *crtc)
...@@ -642,7 +653,7 @@ int tilcdc_crtc_update_fb(struct drm_crtc *crtc, ...@@ -642,7 +653,7 @@ int tilcdc_crtc_update_fb(struct drm_crtc *crtc,
spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags);
next_vblank = ktime_add_us(tilcdc_crtc->last_vblank, next_vblank = ktime_add_us(tilcdc_crtc->last_vblank,
1000000 / crtc->hwmode.vrefresh); tilcdc_crtc->hvtotal_us);
tdiff = ktime_to_us(ktime_sub(next_vblank, ktime_get())); tdiff = ktime_to_us(ktime_sub(next_vblank, ktime_get()));
if (tdiff < TILCDC_VBLANK_SAFETY_THRESHOLD_US) if (tdiff < TILCDC_VBLANK_SAFETY_THRESHOLD_US)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment