Commit 2b2080d7 authored by Tomi Valkeinen's avatar Tomi Valkeinen Committed by Jyri Sarha

drm/tilcdc: Get rid of complex ping-pong mechanism

Get rid of complex ping-pong mechanism and replace it with simpler
single buffer flipping code.

The LCDC HW appears to be designed mainly static framebuffers in
mind. There are two modes of operation, either static single buffer,
or ping pong double buffering with two static buffers switching back
and forth. Luckily the framebuffer start address is fetched only in
the beginning of the frame and changing the address after that only
takes effect after the next vertical blank. The page flipping code can
simply write the address of the new framebuffer and the page is
flipped automatically after the next vertical blank. Using the ping
pong double buffering makes the flipping code way more complex and it
does not provide any benefit, so it is better to switch to single
buffer operation.

There is still one problem in updating the framebuffer dma address on
the fly. There are two registers defining the framebuffer dma area and
things may break if the dma address is fetched in while the registers
are are being updated.
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
[Added description to the patch]
Signed-off-by: default avatarJyri Sarha <jsarha@ti.com>
parent 317aae73
...@@ -25,15 +25,12 @@ struct tilcdc_crtc { ...@@ -25,15 +25,12 @@ struct tilcdc_crtc {
struct drm_crtc base; struct drm_crtc base;
const struct tilcdc_panel_info *info; const struct tilcdc_panel_info *info;
uint32_t dirty;
dma_addr_t start, end;
struct drm_pending_vblank_event *event; struct drm_pending_vblank_event *event;
int dpms; int dpms;
wait_queue_head_t frame_done_wq; wait_queue_head_t frame_done_wq;
bool frame_done; bool frame_done;
/* fb currently set to scanout 0/1: */ struct drm_framebuffer *curr_fb;
struct drm_framebuffer *scanout[2];
/* for deferred fb unref's: */ /* for deferred fb unref's: */
struct drm_flip_work unref_work; struct drm_flip_work unref_work;
...@@ -54,62 +51,31 @@ static void unref_worker(struct drm_flip_work *work, void *val) ...@@ -54,62 +51,31 @@ static void unref_worker(struct drm_flip_work *work, void *val)
mutex_unlock(&dev->mode_config.mutex); mutex_unlock(&dev->mode_config.mutex);
} }
static void set_scanout(struct drm_crtc *crtc, int n) static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
{
static const uint32_t base_reg[] = {
LCDC_DMA_FB_BASE_ADDR_0_REG,
LCDC_DMA_FB_BASE_ADDR_1_REG,
};
static const uint32_t ceil_reg[] = {
LCDC_DMA_FB_CEILING_ADDR_0_REG,
LCDC_DMA_FB_CEILING_ADDR_1_REG,
};
static const uint32_t stat[] = {
LCDC_END_OF_FRAME0, LCDC_END_OF_FRAME1,
};
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
struct drm_device *dev = crtc->dev;
struct tilcdc_drm_private *priv = dev->dev_private;
tilcdc_write(dev, base_reg[n], tilcdc_crtc->start);
tilcdc_write(dev, ceil_reg[n], tilcdc_crtc->end);
if (tilcdc_crtc->scanout[n]) {
drm_flip_work_queue(&tilcdc_crtc->unref_work, tilcdc_crtc->scanout[n]);
drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq);
}
tilcdc_crtc->scanout[n] = crtc->primary->fb;
drm_framebuffer_reference(tilcdc_crtc->scanout[n]);
tilcdc_crtc->dirty &= ~stat[n];
}
static void update_scanout(struct drm_crtc *crtc)
{ {
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_gem_cma_object *gem; struct drm_gem_cma_object *gem;
unsigned int depth, bpp; unsigned int depth, bpp;
dma_addr_t start, end;
drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
gem = drm_fb_cma_get_gem_obj(fb, 0); gem = drm_fb_cma_get_gem_obj(fb, 0);
tilcdc_crtc->start = gem->paddr + fb->offsets[0] + start = gem->paddr + fb->offsets[0] +
(crtc->y * fb->pitches[0]) + (crtc->x * bpp/8); crtc->y * fb->pitches[0] +
crtc->x * bpp / 8;
tilcdc_crtc->end = tilcdc_crtc->start + end = start + (crtc->mode.vdisplay * fb->pitches[0]);
(crtc->mode.vdisplay * fb->pitches[0]);
if (tilcdc_crtc->dpms == DRM_MODE_DPMS_ON) { tilcdc_write(dev, LCDC_DMA_FB_BASE_ADDR_0_REG, start);
/* already enabled, so just mark the frames that need tilcdc_write(dev, LCDC_DMA_FB_CEILING_ADDR_0_REG, end);
* updating and they will be updated on vblank:
*/ if (tilcdc_crtc->curr_fb)
tilcdc_crtc->dirty |= LCDC_END_OF_FRAME0 | LCDC_END_OF_FRAME1; drm_flip_work_queue(&tilcdc_crtc->unref_work,
drm_vblank_get(dev, 0); tilcdc_crtc->curr_fb);
} else {
/* not enabled yet, so update registers immediately: */ tilcdc_crtc->curr_fb = fb;
set_scanout(crtc, 0);
set_scanout(crtc, 1);
}
} }
static void reset(struct drm_crtc *crtc) static void reset(struct drm_crtc *crtc)
...@@ -131,7 +97,7 @@ static void start(struct drm_crtc *crtc) ...@@ -131,7 +97,7 @@ static void start(struct drm_crtc *crtc)
reset(crtc); reset(crtc);
tilcdc_set(dev, LCDC_DMA_CTRL_REG, LCDC_DUAL_FRAME_BUFFER_ENABLE); tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_DUAL_FRAME_BUFFER_ENABLE);
tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_PALETTE_LOAD_MODE(DATA_ONLY)); tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_PALETTE_LOAD_MODE(DATA_ONLY));
tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
} }
...@@ -179,6 +145,7 @@ static int tilcdc_crtc_page_flip(struct drm_crtc *crtc, ...@@ -179,6 +145,7 @@ static int tilcdc_crtc_page_flip(struct drm_crtc *crtc,
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
int r; int r;
unsigned long flags;
r = tilcdc_verify_fb(crtc, fb); r = tilcdc_verify_fb(crtc, fb);
if (r) if (r)
...@@ -189,12 +156,18 @@ static int tilcdc_crtc_page_flip(struct drm_crtc *crtc, ...@@ -189,12 +156,18 @@ static int tilcdc_crtc_page_flip(struct drm_crtc *crtc,
return -EBUSY; return -EBUSY;
} }
drm_framebuffer_reference(fb);
crtc->primary->fb = fb; crtc->primary->fb = fb;
tilcdc_crtc->event = event;
pm_runtime_get_sync(dev->dev); pm_runtime_get_sync(dev->dev);
update_scanout(crtc);
set_scanout(crtc, fb);
spin_lock_irqsave(&dev->event_lock, flags);
tilcdc_crtc->event = event;
spin_unlock_irqrestore(&dev->event_lock, flags);
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev->dev);
...@@ -237,6 +210,14 @@ void tilcdc_crtc_dpms(struct drm_crtc *crtc, int mode) ...@@ -237,6 +210,14 @@ void tilcdc_crtc_dpms(struct drm_crtc *crtc, int mode)
} }
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev->dev);
if (tilcdc_crtc->curr_fb) {
drm_flip_work_queue(&tilcdc_crtc->unref_work,
tilcdc_crtc->curr_fb);
tilcdc_crtc->curr_fb = NULL;
}
drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq);
} }
} }
...@@ -450,8 +431,10 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc, ...@@ -450,8 +431,10 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
else else
tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER);
drm_framebuffer_reference(crtc->primary->fb);
set_scanout(crtc, crtc->primary->fb);
update_scanout(crtc);
tilcdc_crtc_update_clk(crtc); tilcdc_crtc_update_clk(crtc);
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev->dev);
...@@ -469,9 +452,14 @@ static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, ...@@ -469,9 +452,14 @@ static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
if (r) if (r)
return r; return r;
drm_framebuffer_reference(crtc->primary->fb);
pm_runtime_get_sync(dev->dev); pm_runtime_get_sync(dev->dev);
update_scanout(crtc);
set_scanout(crtc, crtc->primary->fb);
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev->dev);
return 0; return 0;
} }
...@@ -661,30 +649,21 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) ...@@ -661,30 +649,21 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc)
stat = tilcdc_read_irqstatus(dev); stat = tilcdc_read_irqstatus(dev);
tilcdc_clear_irqstatus(dev, stat); tilcdc_clear_irqstatus(dev, stat);
if ((stat & LCDC_END_OF_FRAME0) || (stat & LCDC_END_OF_FRAME1)) { if (stat & LCDC_END_OF_FRAME0) {
struct drm_pending_vblank_event *event;
unsigned long flags; unsigned long flags;
uint32_t dirty = tilcdc_crtc->dirty & stat;
tilcdc_clear_irqstatus(dev, stat);
if (dirty & LCDC_END_OF_FRAME0) drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq);
set_scanout(crtc, 0);
if (dirty & LCDC_END_OF_FRAME1)
set_scanout(crtc, 1);
drm_handle_vblank(dev, 0); drm_handle_vblank(dev, 0);
spin_lock_irqsave(&dev->event_lock, flags); spin_lock_irqsave(&dev->event_lock, flags);
event = tilcdc_crtc->event;
tilcdc_crtc->event = NULL;
if (event)
drm_send_vblank_event(dev, 0, event);
spin_unlock_irqrestore(&dev->event_lock, flags);
if (dirty && !tilcdc_crtc->dirty) if (tilcdc_crtc->event) {
drm_vblank_put(dev, 0); drm_send_vblank_event(dev, 0, tilcdc_crtc->event);
tilcdc_crtc->event = NULL;
}
spin_unlock_irqrestore(&dev->event_lock, flags);
} }
if (priv->rev == 2) { if (priv->rev == 2) {
......
...@@ -381,6 +381,7 @@ static int tilcdc_irq_postinstall(struct drm_device *dev) ...@@ -381,6 +381,7 @@ static int tilcdc_irq_postinstall(struct drm_device *dev)
else else
tilcdc_set(dev, LCDC_INT_ENABLE_SET_REG, tilcdc_set(dev, LCDC_INT_ENABLE_SET_REG,
LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_UNDERFLOW_INT_ENA |
LCDC_V2_END_OF_FRAME0_INT_ENA |
LCDC_FRAME_DONE); LCDC_FRAME_DONE);
return 0; return 0;
...@@ -398,41 +399,19 @@ static void tilcdc_irq_uninstall(struct drm_device *dev) ...@@ -398,41 +399,19 @@ static void tilcdc_irq_uninstall(struct drm_device *dev)
} else { } else {
tilcdc_clear(dev, LCDC_INT_ENABLE_SET_REG, tilcdc_clear(dev, LCDC_INT_ENABLE_SET_REG,
LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_PL_INT_ENA | LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_PL_INT_ENA |
LCDC_V2_END_OF_FRAME0_INT_ENA | LCDC_V2_END_OF_FRAME1_INT_ENA | LCDC_V2_END_OF_FRAME0_INT_ENA |
LCDC_FRAME_DONE); LCDC_FRAME_DONE);
} }
}
static void enable_vblank(struct drm_device *dev, bool enable)
{
struct tilcdc_drm_private *priv = dev->dev_private;
u32 reg, mask;
if (priv->rev == 1) {
reg = LCDC_DMA_CTRL_REG;
mask = LCDC_V1_END_OF_FRAME_INT_ENA;
} else {
reg = LCDC_INT_ENABLE_SET_REG;
mask = LCDC_V2_END_OF_FRAME0_INT_ENA |
LCDC_V2_END_OF_FRAME1_INT_ENA;
}
if (enable)
tilcdc_set(dev, reg, mask);
else
tilcdc_clear(dev, reg, mask);
} }
static int tilcdc_enable_vblank(struct drm_device *dev, unsigned int pipe) static int tilcdc_enable_vblank(struct drm_device *dev, unsigned int pipe)
{ {
enable_vblank(dev, true);
return 0; return 0;
} }
static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe) static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe)
{ {
enable_vblank(dev, false); return;
} }
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP) #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP)
......
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