Commit 2389fc13 authored by Boris Brezillon's avatar Boris Brezillon

drm: atmel-hlcdc: Atomic mode-setting conversion

Convert the HLCDC driver to atomic mode-setting.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: default avatarSylvain Rochet <sylvain.rochet@finsecur.com>
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 45ee2dbc
...@@ -37,14 +37,14 @@ ...@@ -37,14 +37,14 @@
* @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
* @event: pointer to the current page flip event * @event: pointer to the current page flip event
* @id: CRTC id (returned by drm_crtc_index) * @id: CRTC id (returned by drm_crtc_index)
* @dpms: DPMS mode * @enabled: CRTC state
*/ */
struct atmel_hlcdc_crtc { struct atmel_hlcdc_crtc {
struct drm_crtc base; struct drm_crtc base;
struct atmel_hlcdc_dc *dc; struct atmel_hlcdc_dc *dc;
struct drm_pending_vblank_event *event; struct drm_pending_vblank_event *event;
int id; int id;
int dpms; bool enabled;
}; };
static inline struct atmel_hlcdc_crtc * static inline struct atmel_hlcdc_crtc *
...@@ -53,86 +53,17 @@ drm_crtc_to_atmel_hlcdc_crtc(struct drm_crtc *crtc) ...@@ -53,86 +53,17 @@ drm_crtc_to_atmel_hlcdc_crtc(struct drm_crtc *crtc)
return container_of(crtc, struct atmel_hlcdc_crtc, base); return container_of(crtc, struct atmel_hlcdc_crtc, base);
} }
static void atmel_hlcdc_crtc_dpms(struct drm_crtc *c, int mode) static void atmel_hlcdc_crtc_mode_set_nofb(struct drm_crtc *c)
{ {
struct drm_device *dev = c->dev;
struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c); struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
struct regmap *regmap = crtc->dc->hlcdc->regmap; struct regmap *regmap = crtc->dc->hlcdc->regmap;
unsigned int status; struct drm_display_mode *adj = &c->state->adjusted_mode;
if (mode != DRM_MODE_DPMS_ON)
mode = DRM_MODE_DPMS_OFF;
if (crtc->dpms == mode)
return;
pm_runtime_get_sync(dev->dev);
if (mode != DRM_MODE_DPMS_ON) {
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_DISP);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_DISP))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_SYNC);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_SYNC))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_PIXEL_CLK);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_PIXEL_CLK))
cpu_relax();
clk_disable_unprepare(crtc->dc->hlcdc->sys_clk);
pm_runtime_allow(dev->dev);
} else {
pm_runtime_forbid(dev->dev);
clk_prepare_enable(crtc->dc->hlcdc->sys_clk);
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_PIXEL_CLK);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_PIXEL_CLK))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_SYNC);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_SYNC))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_DISP);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_DISP))
cpu_relax();
}
pm_runtime_put_sync(dev->dev);
crtc->dpms = mode;
}
static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c,
struct drm_display_mode *mode,
struct drm_display_mode *adj,
int x, int y,
struct drm_framebuffer *old_fb)
{
struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
struct regmap *regmap = crtc->dc->hlcdc->regmap;
struct drm_plane *plane = c->primary;
struct drm_framebuffer *fb;
unsigned long mode_rate; unsigned long mode_rate;
struct videomode vm; struct videomode vm;
unsigned long prate; unsigned long prate;
unsigned int cfg; unsigned int cfg;
int div; int div;
if (atmel_hlcdc_dc_mode_valid(crtc->dc, adj) != MODE_OK)
return -EINVAL;
vm.vfront_porch = adj->crtc_vsync_start - adj->crtc_vdisplay; vm.vfront_porch = adj->crtc_vsync_start - adj->crtc_vdisplay;
vm.vback_porch = adj->crtc_vtotal - adj->crtc_vsync_end; vm.vback_porch = adj->crtc_vtotal - adj->crtc_vsync_end;
vm.vsync_len = adj->crtc_vsync_end - adj->crtc_vsync_start; vm.vsync_len = adj->crtc_vsync_end - adj->crtc_vsync_start;
...@@ -156,7 +87,7 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c, ...@@ -156,7 +87,7 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c,
cfg = ATMEL_HLCDC_CLKPOL; cfg = ATMEL_HLCDC_CLKPOL;
prate = clk_get_rate(crtc->dc->hlcdc->sys_clk); prate = clk_get_rate(crtc->dc->hlcdc->sys_clk);
mode_rate = mode->crtc_clock * 1000; mode_rate = adj->crtc_clock * 1000;
if ((prate / 2) < mode_rate) { if ((prate / 2) < mode_rate) {
prate *= 2; prate *= 2;
cfg |= ATMEL_HLCDC_CLKSEL; cfg |= ATMEL_HLCDC_CLKSEL;
...@@ -174,10 +105,10 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c, ...@@ -174,10 +105,10 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c,
cfg = 0; cfg = 0;
if (mode->flags & DRM_MODE_FLAG_NVSYNC) if (adj->flags & DRM_MODE_FLAG_NVSYNC)
cfg |= ATMEL_HLCDC_VSPOL; cfg |= ATMEL_HLCDC_VSPOL;
if (mode->flags & DRM_MODE_FLAG_NHSYNC) if (adj->flags & DRM_MODE_FLAG_NHSYNC)
cfg |= ATMEL_HLCDC_HSPOL; cfg |= ATMEL_HLCDC_HSPOL;
regmap_update_bits(regmap, ATMEL_HLCDC_CFG(5), regmap_update_bits(regmap, ATMEL_HLCDC_CFG(5),
...@@ -187,77 +118,132 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c, ...@@ -187,77 +118,132 @@ static int atmel_hlcdc_crtc_mode_set(struct drm_crtc *c,
ATMEL_HLCDC_VSPSU | ATMEL_HLCDC_VSPHO | ATMEL_HLCDC_VSPSU | ATMEL_HLCDC_VSPHO |
ATMEL_HLCDC_GUARDTIME_MASK, ATMEL_HLCDC_GUARDTIME_MASK,
cfg); cfg);
fb = plane->fb;
plane->fb = old_fb;
return atmel_hlcdc_plane_update_with_mode(plane, c, fb, 0, 0,
adj->hdisplay, adj->vdisplay,
x << 16, y << 16,
adj->hdisplay << 16,
adj->vdisplay << 16,
adj);
} }
int atmel_hlcdc_crtc_mode_set_base(struct drm_crtc *c, int x, int y, static bool atmel_hlcdc_crtc_mode_fixup(struct drm_crtc *crtc,
struct drm_framebuffer *old_fb) const struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{ {
struct drm_plane *plane = c->primary; return true;
struct drm_framebuffer *fb = plane->fb;
struct drm_display_mode *mode = &c->hwmode;
plane->fb = old_fb;
return plane->funcs->update_plane(plane, c, fb,
0, 0,
mode->hdisplay,
mode->vdisplay,
x << 16, y << 16,
mode->hdisplay << 16,
mode->vdisplay << 16);
} }
static void atmel_hlcdc_crtc_prepare(struct drm_crtc *crtc) static void atmel_hlcdc_crtc_disable(struct drm_crtc *c)
{ {
atmel_hlcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); struct drm_device *dev = c->dev;
struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
struct regmap *regmap = crtc->dc->hlcdc->regmap;
unsigned int status;
if (!crtc->enabled)
return;
drm_crtc_vblank_off(c);
pm_runtime_get_sync(dev->dev);
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_DISP);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_DISP))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_SYNC);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_SYNC))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_DIS, ATMEL_HLCDC_PIXEL_CLK);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
(status & ATMEL_HLCDC_PIXEL_CLK))
cpu_relax();
clk_disable_unprepare(crtc->dc->hlcdc->sys_clk);
pm_runtime_allow(dev->dev);
pm_runtime_put_sync(dev->dev);
crtc->enabled = false;
} }
static void atmel_hlcdc_crtc_commit(struct drm_crtc *crtc) static void atmel_hlcdc_crtc_enable(struct drm_crtc *c)
{ {
atmel_hlcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON); struct drm_device *dev = c->dev;
struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
struct regmap *regmap = crtc->dc->hlcdc->regmap;
unsigned int status;
if (crtc->enabled)
return;
pm_runtime_get_sync(dev->dev);
pm_runtime_forbid(dev->dev);
clk_prepare_enable(crtc->dc->hlcdc->sys_clk);
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_PIXEL_CLK);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_PIXEL_CLK))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_SYNC);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_SYNC))
cpu_relax();
regmap_write(regmap, ATMEL_HLCDC_EN, ATMEL_HLCDC_DISP);
while (!regmap_read(regmap, ATMEL_HLCDC_SR, &status) &&
!(status & ATMEL_HLCDC_DISP))
cpu_relax();
pm_runtime_put_sync(dev->dev);
drm_crtc_vblank_on(c);
crtc->enabled = true;
} }
static bool atmel_hlcdc_crtc_mode_fixup(struct drm_crtc *crtc, static int atmel_hlcdc_crtc_atomic_check(struct drm_crtc *c,
const struct drm_display_mode *mode, struct drm_crtc_state *s)
struct drm_display_mode *adjusted_mode)
{ {
return true; struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
if (atmel_hlcdc_dc_mode_valid(crtc->dc, &s->adjusted_mode) != MODE_OK)
return -EINVAL;
return 0;
} }
static void atmel_hlcdc_crtc_disable(struct drm_crtc *crtc) static void atmel_hlcdc_crtc_atomic_begin(struct drm_crtc *c)
{ {
struct drm_plane *plane; struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
atmel_hlcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); if (c->state->event) {
crtc->primary->funcs->disable_plane(crtc->primary); c->state->event->pipe = drm_crtc_index(c);
drm_for_each_legacy_plane(plane, &crtc->dev->mode_config.plane_list) { WARN_ON(drm_crtc_vblank_get(c) != 0);
if (plane->crtc != crtc)
continue;
plane->funcs->disable_plane(crtc->primary); crtc->event = c->state->event;
plane->crtc = NULL; c->state->event = NULL;
} }
} }
static void atmel_hlcdc_crtc_atomic_flush(struct drm_crtc *crtc)
{
/* TODO: write common plane control register if available */
}
static const struct drm_crtc_helper_funcs lcdc_crtc_helper_funcs = { static const struct drm_crtc_helper_funcs lcdc_crtc_helper_funcs = {
.mode_fixup = atmel_hlcdc_crtc_mode_fixup, .mode_fixup = atmel_hlcdc_crtc_mode_fixup,
.dpms = atmel_hlcdc_crtc_dpms, .mode_set = drm_helper_crtc_mode_set,
.mode_set = atmel_hlcdc_crtc_mode_set, .mode_set_nofb = atmel_hlcdc_crtc_mode_set_nofb,
.mode_set_base = atmel_hlcdc_crtc_mode_set_base, .mode_set_base = drm_helper_crtc_mode_set_base,
.prepare = atmel_hlcdc_crtc_prepare,
.commit = atmel_hlcdc_crtc_commit,
.disable = atmel_hlcdc_crtc_disable, .disable = atmel_hlcdc_crtc_disable,
.enable = atmel_hlcdc_crtc_enable,
.atomic_check = atmel_hlcdc_crtc_atomic_check,
.atomic_begin = atmel_hlcdc_crtc_atomic_begin,
.atomic_flush = atmel_hlcdc_crtc_atomic_flush,
}; };
static void atmel_hlcdc_crtc_destroy(struct drm_crtc *c) static void atmel_hlcdc_crtc_destroy(struct drm_crtc *c)
...@@ -306,61 +292,13 @@ void atmel_hlcdc_crtc_irq(struct drm_crtc *c) ...@@ -306,61 +292,13 @@ void atmel_hlcdc_crtc_irq(struct drm_crtc *c)
atmel_hlcdc_crtc_finish_page_flip(drm_crtc_to_atmel_hlcdc_crtc(c)); atmel_hlcdc_crtc_finish_page_flip(drm_crtc_to_atmel_hlcdc_crtc(c));
} }
static int atmel_hlcdc_crtc_page_flip(struct drm_crtc *c,
struct drm_framebuffer *fb,
struct drm_pending_vblank_event *event,
uint32_t page_flip_flags)
{
struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
struct atmel_hlcdc_plane_update_req req;
struct drm_plane *plane = c->primary;
struct drm_device *dev = c->dev;
unsigned long flags;
int ret = 0;
spin_lock_irqsave(&dev->event_lock, flags);
if (crtc->event)
ret = -EBUSY;
spin_unlock_irqrestore(&dev->event_lock, flags);
if (ret)
return ret;
memset(&req, 0, sizeof(req));
req.crtc_x = 0;
req.crtc_y = 0;
req.crtc_h = c->mode.crtc_vdisplay;
req.crtc_w = c->mode.crtc_hdisplay;
req.src_x = c->x << 16;
req.src_y = c->y << 16;
req.src_w = req.crtc_w << 16;
req.src_h = req.crtc_h << 16;
req.fb = fb;
ret = atmel_hlcdc_plane_prepare_update_req(plane, &req, &c->hwmode);
if (ret)
return ret;
if (event) {
drm_vblank_get(c->dev, crtc->id);
spin_lock_irqsave(&dev->event_lock, flags);
crtc->event = event;
spin_unlock_irqrestore(&dev->event_lock, flags);
}
ret = atmel_hlcdc_plane_apply_update_req(plane, &req);
if (ret)
crtc->event = NULL;
else
plane->fb = fb;
return ret;
}
static const struct drm_crtc_funcs atmel_hlcdc_crtc_funcs = { static const struct drm_crtc_funcs atmel_hlcdc_crtc_funcs = {
.page_flip = atmel_hlcdc_crtc_page_flip, .page_flip = drm_atomic_helper_page_flip,
.set_config = drm_crtc_helper_set_config, .set_config = drm_atomic_helper_set_config,
.destroy = atmel_hlcdc_crtc_destroy, .destroy = atmel_hlcdc_crtc_destroy,
.reset = drm_atomic_helper_crtc_reset,
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
}; };
int atmel_hlcdc_crtc_create(struct drm_device *dev) int atmel_hlcdc_crtc_create(struct drm_device *dev)
...@@ -375,7 +313,6 @@ int atmel_hlcdc_crtc_create(struct drm_device *dev) ...@@ -375,7 +313,6 @@ int atmel_hlcdc_crtc_create(struct drm_device *dev)
if (!crtc) if (!crtc)
return -ENOMEM; return -ENOMEM;
crtc->dpms = DRM_MODE_DPMS_OFF;
crtc->dc = dc; crtc->dc = dc;
ret = drm_crtc_init_with_planes(dev, &crtc->base, ret = drm_crtc_init_with_planes(dev, &crtc->base,
......
...@@ -222,6 +222,8 @@ static void atmel_hlcdc_fb_output_poll_changed(struct drm_device *dev) ...@@ -222,6 +222,8 @@ static void atmel_hlcdc_fb_output_poll_changed(struct drm_device *dev)
static const struct drm_mode_config_funcs mode_config_funcs = { static const struct drm_mode_config_funcs mode_config_funcs = {
.fb_create = atmel_hlcdc_fb_create, .fb_create = atmel_hlcdc_fb_create,
.output_poll_changed = atmel_hlcdc_fb_output_poll_changed, .output_poll_changed = atmel_hlcdc_fb_output_poll_changed,
.atomic_check = drm_atomic_helper_check,
.atomic_commit = drm_atomic_helper_commit,
}; };
static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev) static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev)
...@@ -319,6 +321,8 @@ static int atmel_hlcdc_dc_load(struct drm_device *dev) ...@@ -319,6 +321,8 @@ static int atmel_hlcdc_dc_load(struct drm_device *dev)
goto err_periph_clk_disable; goto err_periph_clk_disable;
} }
drm_mode_config_reset(dev);
ret = drm_vblank_init(dev, 1); ret = drm_vblank_init(dev, 1);
if (ret < 0) { if (ret < 0) {
dev_err(dev->dev, "failed to initialize vblank\n"); dev_err(dev->dev, "failed to initialize vblank\n");
......
...@@ -26,11 +26,14 @@ ...@@ -26,11 +26,14 @@
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
#include <linux/pwm.h> #include <linux/pwm.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc.h> #include <drm/drm_crtc.h>
#include <drm/drm_crtc_helper.h> #include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_cma_helper.h> #include <drm/drm_fb_cma_helper.h>
#include <drm/drm_gem_cma_helper.h> #include <drm/drm_gem_cma_helper.h>
#include <drm/drm_panel.h> #include <drm/drm_panel.h>
#include <drm/drm_plane_helper.h>
#include <drm/drmP.h> #include <drm/drmP.h>
#include "atmel_hlcdc_layer.h" #include "atmel_hlcdc_layer.h"
...@@ -69,7 +72,6 @@ struct atmel_hlcdc_dc_desc { ...@@ -69,7 +72,6 @@ struct atmel_hlcdc_dc_desc {
*/ */
struct atmel_hlcdc_plane_properties { struct atmel_hlcdc_plane_properties {
struct drm_property *alpha; struct drm_property *alpha;
struct drm_property *rotation;
}; };
/** /**
...@@ -84,7 +86,6 @@ struct atmel_hlcdc_plane { ...@@ -84,7 +86,6 @@ struct atmel_hlcdc_plane {
struct drm_plane base; struct drm_plane base;
struct atmel_hlcdc_layer layer; struct atmel_hlcdc_layer layer;
struct atmel_hlcdc_plane_properties *properties; struct atmel_hlcdc_plane_properties *properties;
unsigned int rotation;
}; };
static inline struct atmel_hlcdc_plane * static inline struct atmel_hlcdc_plane *
...@@ -99,43 +100,6 @@ atmel_hlcdc_layer_to_plane(struct atmel_hlcdc_layer *l) ...@@ -99,43 +100,6 @@ atmel_hlcdc_layer_to_plane(struct atmel_hlcdc_layer *l)
return container_of(l, struct atmel_hlcdc_plane, layer); return container_of(l, struct atmel_hlcdc_plane, layer);
} }
/**
* Atmel HLCDC Plane update request structure.
*
* @crtc_x: x position of the plane relative to the CRTC
* @crtc_y: y position of the plane relative to the CRTC
* @crtc_w: visible width of the plane
* @crtc_h: visible height of the plane
* @src_x: x buffer position
* @src_y: y buffer position
* @src_w: buffer width
* @src_h: buffer height
* @fb: framebuffer object object
* @bpp: bytes per pixel deduced from pixel_format
* @offsets: offsets to apply to the GEM buffers
* @xstride: value to add to the pixel pointer between each line
* @pstride: value to add to the pixel pointer between each pixel
* @nplanes: number of planes (deduced from pixel_format)
*/
struct atmel_hlcdc_plane_update_req {
int crtc_x;
int crtc_y;
unsigned int crtc_w;
unsigned int crtc_h;
uint32_t src_x;
uint32_t src_y;
uint32_t src_w;
uint32_t src_h;
struct drm_framebuffer *fb;
/* These fields are private and should not be touched */
int bpp[ATMEL_HLCDC_MAX_PLANES];
unsigned int offsets[ATMEL_HLCDC_MAX_PLANES];
int xstride[ATMEL_HLCDC_MAX_PLANES];
int pstride[ATMEL_HLCDC_MAX_PLANES];
int nplanes;
};
/** /**
* Atmel HLCDC Planes. * Atmel HLCDC Planes.
* *
...@@ -184,23 +148,6 @@ int atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc, ...@@ -184,23 +148,6 @@ int atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc,
struct atmel_hlcdc_planes * struct atmel_hlcdc_planes *
atmel_hlcdc_create_planes(struct drm_device *dev); atmel_hlcdc_create_planes(struct drm_device *dev);
int atmel_hlcdc_plane_prepare_update_req(struct drm_plane *p,
struct atmel_hlcdc_plane_update_req *req,
const struct drm_display_mode *mode);
int atmel_hlcdc_plane_apply_update_req(struct drm_plane *p,
struct atmel_hlcdc_plane_update_req *req);
int atmel_hlcdc_plane_update_with_mode(struct drm_plane *p,
struct drm_crtc *crtc,
struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w,
unsigned int crtc_h,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h,
const struct drm_display_mode *mode);
void atmel_hlcdc_crtc_irq(struct drm_crtc *c); void atmel_hlcdc_crtc_irq(struct drm_crtc *c);
void atmel_hlcdc_crtc_cancel_page_flip(struct drm_crtc *crtc, void atmel_hlcdc_crtc_cancel_page_flip(struct drm_crtc *crtc,
......
...@@ -298,7 +298,7 @@ void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer *layer) ...@@ -298,7 +298,7 @@ void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer *layer)
spin_unlock_irqrestore(&layer->lock, flags); spin_unlock_irqrestore(&layer->lock, flags);
} }
int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer) void atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer)
{ {
struct atmel_hlcdc_layer_dma_channel *dma = &layer->dma; struct atmel_hlcdc_layer_dma_channel *dma = &layer->dma;
struct atmel_hlcdc_layer_update *upd = &layer->update; struct atmel_hlcdc_layer_update *upd = &layer->update;
...@@ -340,8 +340,6 @@ int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer) ...@@ -340,8 +340,6 @@ int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer)
dma->status = ATMEL_HLCDC_LAYER_DISABLED; dma->status = ATMEL_HLCDC_LAYER_DISABLED;
spin_unlock_irqrestore(&layer->lock, flags); spin_unlock_irqrestore(&layer->lock, flags);
return 0;
} }
int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer) int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer)
......
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
#define ATMEL_HLCDC_LAYER_DISCEN BIT(11) #define ATMEL_HLCDC_LAYER_DISCEN BIT(11)
#define ATMEL_HLCDC_LAYER_GA_SHIFT 16 #define ATMEL_HLCDC_LAYER_GA_SHIFT 16
#define ATMEL_HLCDC_LAYER_GA_MASK GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT) #define ATMEL_HLCDC_LAYER_GA_MASK GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)
#define ATMEL_HLCDC_LAYER_GA(x) ((x) << ATMEL_HLCDC_LAYER_GA_SHIFT)
#define ATMEL_HLCDC_LAYER_CSC_CFG(p, o) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.csc + o) #define ATMEL_HLCDC_LAYER_CSC_CFG(p, o) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.csc + o)
...@@ -376,7 +377,7 @@ int atmel_hlcdc_layer_init(struct drm_device *dev, ...@@ -376,7 +377,7 @@ int atmel_hlcdc_layer_init(struct drm_device *dev,
void atmel_hlcdc_layer_cleanup(struct drm_device *dev, void atmel_hlcdc_layer_cleanup(struct drm_device *dev,
struct atmel_hlcdc_layer *layer); struct atmel_hlcdc_layer *layer);
int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer); void atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer *layer);
int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer); int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer *layer);
......
...@@ -86,25 +86,22 @@ atmel_hlcdc_rgb_output_to_panel(struct atmel_hlcdc_rgb_output *output) ...@@ -86,25 +86,22 @@ atmel_hlcdc_rgb_output_to_panel(struct atmel_hlcdc_rgb_output *output)
return container_of(output, struct atmel_hlcdc_panel, base); return container_of(output, struct atmel_hlcdc_panel, base);
} }
static void atmel_hlcdc_panel_encoder_dpms(struct drm_encoder *encoder, static void atmel_hlcdc_panel_encoder_enable(struct drm_encoder *encoder)
int mode)
{ {
struct atmel_hlcdc_rgb_output *rgb = struct atmel_hlcdc_rgb_output *rgb =
drm_encoder_to_atmel_hlcdc_rgb_output(encoder); drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
struct atmel_hlcdc_panel *panel = atmel_hlcdc_rgb_output_to_panel(rgb); struct atmel_hlcdc_panel *panel = atmel_hlcdc_rgb_output_to_panel(rgb);
if (mode != DRM_MODE_DPMS_ON) drm_panel_enable(panel->panel);
mode = DRM_MODE_DPMS_OFF; }
if (mode == rgb->dpms)
return;
if (mode != DRM_MODE_DPMS_ON) static void atmel_hlcdc_panel_encoder_disable(struct drm_encoder *encoder)
drm_panel_disable(panel->panel); {
else struct atmel_hlcdc_rgb_output *rgb =
drm_panel_enable(panel->panel); drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
struct atmel_hlcdc_panel *panel = atmel_hlcdc_rgb_output_to_panel(rgb);
rgb->dpms = mode; drm_panel_disable(panel->panel);
} }
static bool static bool
...@@ -115,16 +112,6 @@ atmel_hlcdc_panel_encoder_mode_fixup(struct drm_encoder *encoder, ...@@ -115,16 +112,6 @@ atmel_hlcdc_panel_encoder_mode_fixup(struct drm_encoder *encoder,
return true; return true;
} }
static void atmel_hlcdc_panel_encoder_prepare(struct drm_encoder *encoder)
{
atmel_hlcdc_panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
}
static void atmel_hlcdc_panel_encoder_commit(struct drm_encoder *encoder)
{
atmel_hlcdc_panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
}
static void static void
atmel_hlcdc_rgb_encoder_mode_set(struct drm_encoder *encoder, atmel_hlcdc_rgb_encoder_mode_set(struct drm_encoder *encoder,
struct drm_display_mode *mode, struct drm_display_mode *mode,
...@@ -156,11 +143,10 @@ atmel_hlcdc_rgb_encoder_mode_set(struct drm_encoder *encoder, ...@@ -156,11 +143,10 @@ atmel_hlcdc_rgb_encoder_mode_set(struct drm_encoder *encoder,
} }
static struct drm_encoder_helper_funcs atmel_hlcdc_panel_encoder_helper_funcs = { static struct drm_encoder_helper_funcs atmel_hlcdc_panel_encoder_helper_funcs = {
.dpms = atmel_hlcdc_panel_encoder_dpms,
.mode_fixup = atmel_hlcdc_panel_encoder_mode_fixup, .mode_fixup = atmel_hlcdc_panel_encoder_mode_fixup,
.prepare = atmel_hlcdc_panel_encoder_prepare,
.commit = atmel_hlcdc_panel_encoder_commit,
.mode_set = atmel_hlcdc_rgb_encoder_mode_set, .mode_set = atmel_hlcdc_rgb_encoder_mode_set,
.disable = atmel_hlcdc_panel_encoder_disable,
.enable = atmel_hlcdc_panel_encoder_enable,
}; };
static void atmel_hlcdc_rgb_encoder_destroy(struct drm_encoder *encoder) static void atmel_hlcdc_rgb_encoder_destroy(struct drm_encoder *encoder)
...@@ -226,10 +212,13 @@ atmel_hlcdc_panel_connector_destroy(struct drm_connector *connector) ...@@ -226,10 +212,13 @@ atmel_hlcdc_panel_connector_destroy(struct drm_connector *connector)
} }
static const struct drm_connector_funcs atmel_hlcdc_panel_connector_funcs = { static const struct drm_connector_funcs atmel_hlcdc_panel_connector_funcs = {
.dpms = drm_helper_connector_dpms, .dpms = drm_atomic_helper_connector_dpms,
.detect = atmel_hlcdc_panel_connector_detect, .detect = atmel_hlcdc_panel_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes, .fill_modes = drm_helper_probe_single_connector_modes,
.destroy = atmel_hlcdc_panel_connector_destroy, .destroy = atmel_hlcdc_panel_connector_destroy,
.reset = drm_atomic_helper_connector_reset,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
}; };
static int atmel_hlcdc_create_panel_output(struct drm_device *dev, static int atmel_hlcdc_create_panel_output(struct drm_device *dev,
......
...@@ -19,6 +19,52 @@ ...@@ -19,6 +19,52 @@
#include "atmel_hlcdc_dc.h" #include "atmel_hlcdc_dc.h"
/**
* Atmel HLCDC Plane state structure.
*
* @base: DRM plane state
* @crtc_x: x position of the plane relative to the CRTC
* @crtc_y: y position of the plane relative to the CRTC
* @crtc_w: visible width of the plane
* @crtc_h: visible height of the plane
* @src_x: x buffer position
* @src_y: y buffer position
* @src_w: buffer width
* @src_h: buffer height
* @alpha: alpha blending of the plane
* @bpp: bytes per pixel deduced from pixel_format
* @offsets: offsets to apply to the GEM buffers
* @xstride: value to add to the pixel pointer between each line
* @pstride: value to add to the pixel pointer between each pixel
* @nplanes: number of planes (deduced from pixel_format)
*/
struct atmel_hlcdc_plane_state {
struct drm_plane_state base;
int crtc_x;
int crtc_y;
unsigned int crtc_w;
unsigned int crtc_h;
uint32_t src_x;
uint32_t src_y;
uint32_t src_w;
uint32_t src_h;
u8 alpha;
/* These fields are private and should not be touched */
int bpp[ATMEL_HLCDC_MAX_PLANES];
unsigned int offsets[ATMEL_HLCDC_MAX_PLANES];
int xstride[ATMEL_HLCDC_MAX_PLANES];
int pstride[ATMEL_HLCDC_MAX_PLANES];
int nplanes;
};
static inline struct atmel_hlcdc_plane_state *
drm_plane_state_to_atmel_hlcdc_plane_state(struct drm_plane_state *s)
{
return container_of(s, struct atmel_hlcdc_plane_state, base);
}
#define SUBPIXEL_MASK 0xffff #define SUBPIXEL_MASK 0xffff
static uint32_t rgb_formats[] = { static uint32_t rgb_formats[] = {
...@@ -128,7 +174,7 @@ static int atmel_hlcdc_format_to_plane_mode(u32 format, u32 *mode) ...@@ -128,7 +174,7 @@ static int atmel_hlcdc_format_to_plane_mode(u32 format, u32 *mode)
return 0; return 0;
} }
static bool atmel_hlcdc_format_embedds_alpha(u32 format) static bool atmel_hlcdc_format_embeds_alpha(u32 format)
{ {
int i; int i;
...@@ -204,7 +250,7 @@ static u32 heo_upscaling_ycoef[] = { ...@@ -204,7 +250,7 @@ static u32 heo_upscaling_ycoef[] = {
static void static void
atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane, atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane,
struct atmel_hlcdc_plane_update_req *req) struct atmel_hlcdc_plane_state *state)
{ {
const struct atmel_hlcdc_layer_cfg_layout *layout = const struct atmel_hlcdc_layer_cfg_layout *layout =
&plane->layer.desc->layout; &plane->layer.desc->layout;
...@@ -213,69 +259,69 @@ atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane, ...@@ -213,69 +259,69 @@ atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane,
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
layout->size, layout->size,
0xffffffff, 0xffffffff,
(req->crtc_w - 1) | (state->crtc_w - 1) |
((req->crtc_h - 1) << 16)); ((state->crtc_h - 1) << 16));
if (layout->memsize) if (layout->memsize)
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
layout->memsize, layout->memsize,
0xffffffff, 0xffffffff,
(req->src_w - 1) | (state->src_w - 1) |
((req->src_h - 1) << 16)); ((state->src_h - 1) << 16));
if (layout->pos) if (layout->pos)
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
layout->pos, layout->pos,
0xffffffff, 0xffffffff,
req->crtc_x | state->crtc_x |
(req->crtc_y << 16)); (state->crtc_y << 16));
/* TODO: rework the rescaling part */ /* TODO: rework the rescaling part */
if (req->crtc_w != req->src_w || req->crtc_h != req->src_h) { if (state->crtc_w != state->src_w || state->crtc_h != state->src_h) {
u32 factor_reg = 0; u32 factor_reg = 0;
if (req->crtc_w != req->src_w) { if (state->crtc_w != state->src_w) {
int i; int i;
u32 factor; u32 factor;
u32 *coeff_tab = heo_upscaling_xcoef; u32 *coeff_tab = heo_upscaling_xcoef;
u32 max_memsize; u32 max_memsize;
if (req->crtc_w < req->src_w) if (state->crtc_w < state->src_w)
coeff_tab = heo_downscaling_xcoef; coeff_tab = heo_downscaling_xcoef;
for (i = 0; i < ARRAY_SIZE(heo_upscaling_xcoef); i++) for (i = 0; i < ARRAY_SIZE(heo_upscaling_xcoef); i++)
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
17 + i, 17 + i,
0xffffffff, 0xffffffff,
coeff_tab[i]); coeff_tab[i]);
factor = ((8 * 256 * req->src_w) - (256 * 4)) / factor = ((8 * 256 * state->src_w) - (256 * 4)) /
req->crtc_w; state->crtc_w;
factor++; factor++;
max_memsize = ((factor * req->crtc_w) + (256 * 4)) / max_memsize = ((factor * state->crtc_w) + (256 * 4)) /
2048; 2048;
if (max_memsize > req->src_w) if (max_memsize > state->src_w)
factor--; factor--;
factor_reg |= factor | 0x80000000; factor_reg |= factor | 0x80000000;
} }
if (req->crtc_h != req->src_h) { if (state->crtc_h != state->src_h) {
int i; int i;
u32 factor; u32 factor;
u32 *coeff_tab = heo_upscaling_ycoef; u32 *coeff_tab = heo_upscaling_ycoef;
u32 max_memsize; u32 max_memsize;
if (req->crtc_w < req->src_w) if (state->crtc_w < state->src_w)
coeff_tab = heo_downscaling_ycoef; coeff_tab = heo_downscaling_ycoef;
for (i = 0; i < ARRAY_SIZE(heo_upscaling_ycoef); i++) for (i = 0; i < ARRAY_SIZE(heo_upscaling_ycoef); i++)
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
33 + i, 33 + i,
0xffffffff, 0xffffffff,
coeff_tab[i]); coeff_tab[i]);
factor = ((8 * 256 * req->src_w) - (256 * 4)) / factor = ((8 * 256 * state->src_w) - (256 * 4)) /
req->crtc_w; state->crtc_w;
factor++; factor++;
max_memsize = ((factor * req->crtc_w) + (256 * 4)) / max_memsize = ((factor * state->crtc_w) + (256 * 4)) /
2048; 2048;
if (max_memsize > req->src_w) if (max_memsize > state->src_w)
factor--; factor--;
factor_reg |= (factor << 16) | 0x80000000; factor_reg |= (factor << 16) | 0x80000000;
} }
...@@ -287,7 +333,7 @@ atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane, ...@@ -287,7 +333,7 @@ atmel_hlcdc_plane_update_pos_and_size(struct atmel_hlcdc_plane *plane,
static void static void
atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane, atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane,
struct atmel_hlcdc_plane_update_req *req) struct atmel_hlcdc_plane_state *state)
{ {
const struct atmel_hlcdc_layer_cfg_layout *layout = const struct atmel_hlcdc_layer_cfg_layout *layout =
&plane->layer.desc->layout; &plane->layer.desc->layout;
...@@ -297,10 +343,11 @@ atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane, ...@@ -297,10 +343,11 @@ atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane,
cfg |= ATMEL_HLCDC_LAYER_OVR | ATMEL_HLCDC_LAYER_ITER2BL | cfg |= ATMEL_HLCDC_LAYER_OVR | ATMEL_HLCDC_LAYER_ITER2BL |
ATMEL_HLCDC_LAYER_ITER; ATMEL_HLCDC_LAYER_ITER;
if (atmel_hlcdc_format_embedds_alpha(req->fb->pixel_format)) if (atmel_hlcdc_format_embeds_alpha(state->base.fb->pixel_format))
cfg |= ATMEL_HLCDC_LAYER_LAEN; cfg |= ATMEL_HLCDC_LAYER_LAEN;
else else
cfg |= ATMEL_HLCDC_LAYER_GAEN; cfg |= ATMEL_HLCDC_LAYER_GAEN |
ATMEL_HLCDC_LAYER_GA(state->alpha);
} }
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
...@@ -312,24 +359,26 @@ atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane, ...@@ -312,24 +359,26 @@ atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane,
ATMEL_HLCDC_LAYER_ITER2BL | ATMEL_HLCDC_LAYER_ITER2BL |
ATMEL_HLCDC_LAYER_ITER | ATMEL_HLCDC_LAYER_ITER |
ATMEL_HLCDC_LAYER_GAEN | ATMEL_HLCDC_LAYER_GAEN |
ATMEL_HLCDC_LAYER_GA_MASK |
ATMEL_HLCDC_LAYER_LAEN | ATMEL_HLCDC_LAYER_LAEN |
ATMEL_HLCDC_LAYER_OVR | ATMEL_HLCDC_LAYER_OVR |
ATMEL_HLCDC_LAYER_DMA, cfg); ATMEL_HLCDC_LAYER_DMA, cfg);
} }
static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane, static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane,
struct atmel_hlcdc_plane_update_req *req) struct atmel_hlcdc_plane_state *state)
{ {
u32 cfg; u32 cfg;
int ret; int ret;
ret = atmel_hlcdc_format_to_plane_mode(req->fb->pixel_format, &cfg); ret = atmel_hlcdc_format_to_plane_mode(state->base.fb->pixel_format,
&cfg);
if (ret) if (ret)
return; return;
if ((req->fb->pixel_format == DRM_FORMAT_YUV422 || if ((state->base.fb->pixel_format == DRM_FORMAT_YUV422 ||
req->fb->pixel_format == DRM_FORMAT_NV61) && state->base.fb->pixel_format == DRM_FORMAT_NV61) &&
(plane->rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270)))) (state->base.rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))))
cfg |= ATMEL_HLCDC_YUV422ROT; cfg |= ATMEL_HLCDC_YUV422ROT;
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
...@@ -341,7 +390,7 @@ static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane, ...@@ -341,7 +390,7 @@ static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane,
* Rotation optimization is not working on RGB888 (rotation is still * Rotation optimization is not working on RGB888 (rotation is still
* working but without any optimization). * working but without any optimization).
*/ */
if (req->fb->pixel_format == DRM_FORMAT_RGB888) if (state->base.fb->pixel_format == DRM_FORMAT_RGB888)
cfg = ATMEL_HLCDC_LAYER_DMA_ROTDIS; cfg = ATMEL_HLCDC_LAYER_DMA_ROTDIS;
else else
cfg = 0; cfg = 0;
...@@ -352,73 +401,44 @@ static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane, ...@@ -352,73 +401,44 @@ static void atmel_hlcdc_plane_update_format(struct atmel_hlcdc_plane *plane,
} }
static void atmel_hlcdc_plane_update_buffers(struct atmel_hlcdc_plane *plane, static void atmel_hlcdc_plane_update_buffers(struct atmel_hlcdc_plane *plane,
struct atmel_hlcdc_plane_update_req *req) struct atmel_hlcdc_plane_state *state)
{ {
struct atmel_hlcdc_layer *layer = &plane->layer; struct atmel_hlcdc_layer *layer = &plane->layer;
const struct atmel_hlcdc_layer_cfg_layout *layout = const struct atmel_hlcdc_layer_cfg_layout *layout =
&layer->desc->layout; &layer->desc->layout;
int i; int i;
atmel_hlcdc_layer_update_set_fb(&plane->layer, req->fb, req->offsets); atmel_hlcdc_layer_update_set_fb(&plane->layer, state->base.fb,
state->offsets);
for (i = 0; i < req->nplanes; i++) { for (i = 0; i < state->nplanes; i++) {
if (layout->xstride[i]) { if (layout->xstride[i]) {
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
layout->xstride[i], layout->xstride[i],
0xffffffff, 0xffffffff,
req->xstride[i]); state->xstride[i]);
} }
if (layout->pstride[i]) { if (layout->pstride[i]) {
atmel_hlcdc_layer_update_cfg(&plane->layer, atmel_hlcdc_layer_update_cfg(&plane->layer,
layout->pstride[i], layout->pstride[i],
0xffffffff, 0xffffffff,
req->pstride[i]); state->pstride[i]);
} }
} }
} }
static int atmel_hlcdc_plane_check_update_req(struct drm_plane *p, static int atmel_hlcdc_plane_atomic_check(struct drm_plane *p,
struct atmel_hlcdc_plane_update_req *req, struct drm_plane_state *s)
const struct drm_display_mode *mode)
{ {
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p); struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
struct atmel_hlcdc_plane_state *state =
drm_plane_state_to_atmel_hlcdc_plane_state(s);
const struct atmel_hlcdc_layer_cfg_layout *layout = const struct atmel_hlcdc_layer_cfg_layout *layout =
&plane->layer.desc->layout; &plane->layer.desc->layout;
struct drm_framebuffer *fb = state->base.fb;
if (!layout->size && const struct drm_display_mode *mode;
(mode->hdisplay != req->crtc_w || struct drm_crtc_state *crtc_state;
mode->vdisplay != req->crtc_h))
return -EINVAL;
if (plane->layer.desc->max_height &&
req->crtc_h > plane->layer.desc->max_height)
return -EINVAL;
if (plane->layer.desc->max_width &&
req->crtc_w > plane->layer.desc->max_width)
return -EINVAL;
if ((req->crtc_h != req->src_h || req->crtc_w != req->src_w) &&
(!layout->memsize ||
atmel_hlcdc_format_embedds_alpha(req->fb->pixel_format)))
return -EINVAL;
if (req->crtc_x < 0 || req->crtc_y < 0)
return -EINVAL;
if (req->crtc_w + req->crtc_x > mode->hdisplay ||
req->crtc_h + req->crtc_y > mode->vdisplay)
return -EINVAL;
return 0;
}
int atmel_hlcdc_plane_prepare_update_req(struct drm_plane *p,
struct atmel_hlcdc_plane_update_req *req,
const struct drm_display_mode *mode)
{
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
unsigned int patched_crtc_w; unsigned int patched_crtc_w;
unsigned int patched_crtc_h; unsigned int patched_crtc_h;
unsigned int patched_src_w; unsigned int patched_src_w;
...@@ -430,196 +450,194 @@ int atmel_hlcdc_plane_prepare_update_req(struct drm_plane *p, ...@@ -430,196 +450,194 @@ int atmel_hlcdc_plane_prepare_update_req(struct drm_plane *p,
int vsub = 1; int vsub = 1;
int i; int i;
if ((req->src_x | req->src_y | req->src_w | req->src_h) & if (!state->base.crtc || !fb)
return 0;
crtc_state = s->state->crtc_states[drm_crtc_index(s->crtc)];
mode = &crtc_state->adjusted_mode;
state->src_x = s->src_x;
state->src_y = s->src_y;
state->src_h = s->src_h;
state->src_w = s->src_w;
state->crtc_x = s->crtc_x;
state->crtc_y = s->crtc_y;
state->crtc_h = s->crtc_h;
state->crtc_w = s->crtc_w;
if ((state->src_x | state->src_y | state->src_w | state->src_h) &
SUBPIXEL_MASK) SUBPIXEL_MASK)
return -EINVAL; return -EINVAL;
req->src_x >>= 16; state->src_x >>= 16;
req->src_y >>= 16; state->src_y >>= 16;
req->src_w >>= 16; state->src_w >>= 16;
req->src_h >>= 16; state->src_h >>= 16;
req->nplanes = drm_format_num_planes(req->fb->pixel_format); state->nplanes = drm_format_num_planes(fb->pixel_format);
if (req->nplanes > ATMEL_HLCDC_MAX_PLANES) if (state->nplanes > ATMEL_HLCDC_MAX_PLANES)
return -EINVAL; return -EINVAL;
/* /*
* Swap width and size in case of 90 or 270 degrees rotation * Swap width and size in case of 90 or 270 degrees rotation
*/ */
if (plane->rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))) { if (state->base.rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))) {
tmp = req->crtc_w; tmp = state->crtc_w;
req->crtc_w = req->crtc_h; state->crtc_w = state->crtc_h;
req->crtc_h = tmp; state->crtc_h = tmp;
tmp = req->src_w; tmp = state->src_w;
req->src_w = req->src_h; state->src_w = state->src_h;
req->src_h = tmp; state->src_h = tmp;
} }
if (req->crtc_x + req->crtc_w > mode->hdisplay) if (state->crtc_x + state->crtc_w > mode->hdisplay)
patched_crtc_w = mode->hdisplay - req->crtc_x; patched_crtc_w = mode->hdisplay - state->crtc_x;
else else
patched_crtc_w = req->crtc_w; patched_crtc_w = state->crtc_w;
if (req->crtc_x < 0) { if (state->crtc_x < 0) {
patched_crtc_w += req->crtc_x; patched_crtc_w += state->crtc_x;
x_offset = -req->crtc_x; x_offset = -state->crtc_x;
req->crtc_x = 0; state->crtc_x = 0;
} }
if (req->crtc_y + req->crtc_h > mode->vdisplay) if (state->crtc_y + state->crtc_h > mode->vdisplay)
patched_crtc_h = mode->vdisplay - req->crtc_y; patched_crtc_h = mode->vdisplay - state->crtc_y;
else else
patched_crtc_h = req->crtc_h; patched_crtc_h = state->crtc_h;
if (req->crtc_y < 0) { if (state->crtc_y < 0) {
patched_crtc_h += req->crtc_y; patched_crtc_h += state->crtc_y;
y_offset = -req->crtc_y; y_offset = -state->crtc_y;
req->crtc_y = 0; state->crtc_y = 0;
} }
patched_src_w = DIV_ROUND_CLOSEST(patched_crtc_w * req->src_w, patched_src_w = DIV_ROUND_CLOSEST(patched_crtc_w * state->src_w,
req->crtc_w); state->crtc_w);
patched_src_h = DIV_ROUND_CLOSEST(patched_crtc_h * req->src_h, patched_src_h = DIV_ROUND_CLOSEST(patched_crtc_h * state->src_h,
req->crtc_h); state->crtc_h);
hsub = drm_format_horz_chroma_subsampling(req->fb->pixel_format); hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
vsub = drm_format_vert_chroma_subsampling(req->fb->pixel_format); vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
for (i = 0; i < req->nplanes; i++) { for (i = 0; i < state->nplanes; i++) {
unsigned int offset = 0; unsigned int offset = 0;
int xdiv = i ? hsub : 1; int xdiv = i ? hsub : 1;
int ydiv = i ? vsub : 1; int ydiv = i ? vsub : 1;
req->bpp[i] = drm_format_plane_cpp(req->fb->pixel_format, i); state->bpp[i] = drm_format_plane_cpp(fb->pixel_format, i);
if (!req->bpp[i]) if (!state->bpp[i])
return -EINVAL; return -EINVAL;
switch (plane->rotation & 0xf) { switch (state->base.rotation & 0xf) {
case BIT(DRM_ROTATE_90): case BIT(DRM_ROTATE_90):
offset = ((y_offset + req->src_y + patched_src_w - 1) / offset = ((y_offset + state->src_y + patched_src_w - 1) /
ydiv) * req->fb->pitches[i]; ydiv) * fb->pitches[i];
offset += ((x_offset + req->src_x) / xdiv) * offset += ((x_offset + state->src_x) / xdiv) *
req->bpp[i]; state->bpp[i];
req->xstride[i] = ((patched_src_w - 1) / ydiv) * state->xstride[i] = ((patched_src_w - 1) / ydiv) *
req->fb->pitches[i]; fb->pitches[i];
req->pstride[i] = -req->fb->pitches[i] - req->bpp[i]; state->pstride[i] = -fb->pitches[i] - state->bpp[i];
break; break;
case BIT(DRM_ROTATE_180): case BIT(DRM_ROTATE_180):
offset = ((y_offset + req->src_y + patched_src_h - 1) / offset = ((y_offset + state->src_y + patched_src_h - 1) /
ydiv) * req->fb->pitches[i]; ydiv) * fb->pitches[i];
offset += ((x_offset + req->src_x + patched_src_w - 1) / offset += ((x_offset + state->src_x + patched_src_w - 1) /
xdiv) * req->bpp[i]; xdiv) * state->bpp[i];
req->xstride[i] = ((((patched_src_w - 1) / xdiv) - 1) * state->xstride[i] = ((((patched_src_w - 1) / xdiv) - 1) *
req->bpp[i]) - req->fb->pitches[i]; state->bpp[i]) - fb->pitches[i];
req->pstride[i] = -2 * req->bpp[i]; state->pstride[i] = -2 * state->bpp[i];
break; break;
case BIT(DRM_ROTATE_270): case BIT(DRM_ROTATE_270):
offset = ((y_offset + req->src_y) / ydiv) * offset = ((y_offset + state->src_y) / ydiv) *
req->fb->pitches[i]; fb->pitches[i];
offset += ((x_offset + req->src_x + patched_src_h - 1) / offset += ((x_offset + state->src_x + patched_src_h - 1) /
xdiv) * req->bpp[i]; xdiv) * state->bpp[i];
req->xstride[i] = -(((patched_src_w - 1) / ydiv) * state->xstride[i] = -(((patched_src_w - 1) / ydiv) *
req->fb->pitches[i]) - fb->pitches[i]) -
(2 * req->bpp[i]); (2 * state->bpp[i]);
req->pstride[i] = req->fb->pitches[i] - req->bpp[i]; state->pstride[i] = fb->pitches[i] - state->bpp[i];
break; break;
case BIT(DRM_ROTATE_0): case BIT(DRM_ROTATE_0):
default: default:
offset = ((y_offset + req->src_y) / ydiv) * offset = ((y_offset + state->src_y) / ydiv) *
req->fb->pitches[i]; fb->pitches[i];
offset += ((x_offset + req->src_x) / xdiv) * offset += ((x_offset + state->src_x) / xdiv) *
req->bpp[i]; state->bpp[i];
req->xstride[i] = req->fb->pitches[i] - state->xstride[i] = fb->pitches[i] -
((patched_src_w / xdiv) * ((patched_src_w / xdiv) *
req->bpp[i]); state->bpp[i]);
req->pstride[i] = 0; state->pstride[i] = 0;
break; break;
} }
req->offsets[i] = offset + req->fb->offsets[i]; state->offsets[i] = offset + fb->offsets[i];
} }
req->src_w = patched_src_w; state->src_w = patched_src_w;
req->src_h = patched_src_h; state->src_h = patched_src_h;
req->crtc_w = patched_crtc_w; state->crtc_w = patched_crtc_w;
req->crtc_h = patched_crtc_h; state->crtc_h = patched_crtc_h;
return atmel_hlcdc_plane_check_update_req(p, req, mode); if (!layout->size &&
} (mode->hdisplay != state->crtc_w ||
mode->vdisplay != state->crtc_h))
return -EINVAL;
int atmel_hlcdc_plane_apply_update_req(struct drm_plane *p, if (plane->layer.desc->max_height &&
struct atmel_hlcdc_plane_update_req *req) state->crtc_h > plane->layer.desc->max_height)
{ return -EINVAL;
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
int ret;
ret = atmel_hlcdc_layer_update_start(&plane->layer); if (plane->layer.desc->max_width &&
if (ret) state->crtc_w > plane->layer.desc->max_width)
return ret; return -EINVAL;
atmel_hlcdc_plane_update_pos_and_size(plane, req); if ((state->crtc_h != state->src_h || state->crtc_w != state->src_w) &&
atmel_hlcdc_plane_update_general_settings(plane, req); (!layout->memsize ||
atmel_hlcdc_plane_update_format(plane, req); atmel_hlcdc_format_embeds_alpha(state->base.fb->pixel_format)))
atmel_hlcdc_plane_update_buffers(plane, req); return -EINVAL;
atmel_hlcdc_layer_update_commit(&plane->layer); if (state->crtc_x < 0 || state->crtc_y < 0)
return -EINVAL;
if (state->crtc_w + state->crtc_x > mode->hdisplay ||
state->crtc_h + state->crtc_y > mode->vdisplay)
return -EINVAL;
return 0; return 0;
} }
int atmel_hlcdc_plane_update_with_mode(struct drm_plane *p, static int atmel_hlcdc_plane_prepare_fb(struct drm_plane *p,
struct drm_crtc *crtc, struct drm_framebuffer *fb)
struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w,
unsigned int crtc_h,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h,
const struct drm_display_mode *mode)
{ {
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p); struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
struct atmel_hlcdc_plane_update_req req;
int ret = 0;
memset(&req, 0, sizeof(req));
req.crtc_x = crtc_x;
req.crtc_y = crtc_y;
req.crtc_w = crtc_w;
req.crtc_h = crtc_h;
req.src_x = src_x;
req.src_y = src_y;
req.src_w = src_w;
req.src_h = src_h;
req.fb = fb;
ret = atmel_hlcdc_plane_prepare_update_req(&plane->base, &req, mode);
if (ret)
return ret;
if (!req.crtc_h || !req.crtc_w) return atmel_hlcdc_layer_update_start(&plane->layer);
return atmel_hlcdc_layer_disable(&plane->layer);
return atmel_hlcdc_plane_apply_update_req(&plane->base, &req);
} }
static int atmel_hlcdc_plane_update(struct drm_plane *p, static void atmel_hlcdc_plane_atomic_update(struct drm_plane *p,
struct drm_crtc *crtc, struct drm_plane_state *old_s)
struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h)
{ {
return atmel_hlcdc_plane_update_with_mode(p, crtc, fb, crtc_x, crtc_y, struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
crtc_w, crtc_h, src_x, src_y, struct atmel_hlcdc_plane_state *state =
src_w, src_h, &crtc->hwmode); drm_plane_state_to_atmel_hlcdc_plane_state(p->state);
if (!p->state->crtc || !p->state->fb)
return;
atmel_hlcdc_plane_update_pos_and_size(plane, state);
atmel_hlcdc_plane_update_general_settings(plane, state);
atmel_hlcdc_plane_update_format(plane, state);
atmel_hlcdc_plane_update_buffers(plane, state);
atmel_hlcdc_layer_update_commit(&plane->layer);
} }
static int atmel_hlcdc_plane_disable(struct drm_plane *p) static void atmel_hlcdc_plane_atomic_disable(struct drm_plane *p,
struct drm_plane_state *old_state)
{ {
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p); struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
return atmel_hlcdc_layer_disable(&plane->layer); atmel_hlcdc_layer_disable(&plane->layer);
} }
static void atmel_hlcdc_plane_destroy(struct drm_plane *p) static void atmel_hlcdc_plane_destroy(struct drm_plane *p)
...@@ -635,38 +653,36 @@ static void atmel_hlcdc_plane_destroy(struct drm_plane *p) ...@@ -635,38 +653,36 @@ static void atmel_hlcdc_plane_destroy(struct drm_plane *p)
devm_kfree(p->dev->dev, plane); devm_kfree(p->dev->dev, plane);
} }
static int atmel_hlcdc_plane_set_alpha(struct atmel_hlcdc_plane *plane, static int atmel_hlcdc_plane_atomic_set_property(struct drm_plane *p,
u8 alpha) struct drm_plane_state *s,
struct drm_property *property,
uint64_t val)
{ {
atmel_hlcdc_layer_update_start(&plane->layer); struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
atmel_hlcdc_layer_update_cfg(&plane->layer, struct atmel_hlcdc_plane_properties *props = plane->properties;
plane->layer.desc->layout.general_config, struct atmel_hlcdc_plane_state *state =
ATMEL_HLCDC_LAYER_GA_MASK, drm_plane_state_to_atmel_hlcdc_plane_state(s);
alpha << ATMEL_HLCDC_LAYER_GA_SHIFT);
atmel_hlcdc_layer_update_commit(&plane->layer);
return 0;
}
static int atmel_hlcdc_plane_set_rotation(struct atmel_hlcdc_plane *plane, if (property == props->alpha)
unsigned int rotation) state->alpha = val;
{ else
plane->rotation = rotation; return -EINVAL;
return 0; return 0;
} }
static int atmel_hlcdc_plane_set_property(struct drm_plane *p, static int atmel_hlcdc_plane_atomic_get_property(struct drm_plane *p,
struct drm_property *property, const struct drm_plane_state *s,
uint64_t value) struct drm_property *property,
uint64_t *val)
{ {
struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p); struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
struct atmel_hlcdc_plane_properties *props = plane->properties; struct atmel_hlcdc_plane_properties *props = plane->properties;
const struct atmel_hlcdc_plane_state *state =
container_of(s, const struct atmel_hlcdc_plane_state, base);
if (property == props->alpha) if (property == props->alpha)
atmel_hlcdc_plane_set_alpha(plane, value); *val = state->alpha;
else if (property == props->rotation)
atmel_hlcdc_plane_set_rotation(plane, value);
else else
return -EINVAL; return -EINVAL;
...@@ -694,8 +710,8 @@ static void atmel_hlcdc_plane_init_properties(struct atmel_hlcdc_plane *plane, ...@@ -694,8 +710,8 @@ static void atmel_hlcdc_plane_init_properties(struct atmel_hlcdc_plane *plane,
if (desc->layout.xstride && desc->layout.pstride) if (desc->layout.xstride && desc->layout.pstride)
drm_object_attach_property(&plane->base.base, drm_object_attach_property(&plane->base.base,
props->rotation, plane->base.dev->mode_config.rotation_property,
BIT(DRM_ROTATE_0)); BIT(DRM_ROTATE_0));
if (desc->layout.csc) { if (desc->layout.csc) {
/* /*
...@@ -717,11 +733,74 @@ static void atmel_hlcdc_plane_init_properties(struct atmel_hlcdc_plane *plane, ...@@ -717,11 +733,74 @@ static void atmel_hlcdc_plane_init_properties(struct atmel_hlcdc_plane *plane,
} }
} }
static struct drm_plane_helper_funcs atmel_hlcdc_layer_plane_helper_funcs = {
.prepare_fb = atmel_hlcdc_plane_prepare_fb,
.atomic_check = atmel_hlcdc_plane_atomic_check,
.atomic_update = atmel_hlcdc_plane_atomic_update,
.atomic_disable = atmel_hlcdc_plane_atomic_disable,
};
static void atmel_hlcdc_plane_reset(struct drm_plane *p)
{
struct atmel_hlcdc_plane_state *state;
if (p->state) {
state = drm_plane_state_to_atmel_hlcdc_plane_state(p->state);
if (state->base.fb)
drm_framebuffer_unreference(state->base.fb);
kfree(state);
p->state = NULL;
}
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (state) {
state->alpha = 255;
p->state = &state->base;
p->state->plane = p;
}
}
static struct drm_plane_state *
atmel_hlcdc_plane_atomic_duplicate_state(struct drm_plane *p)
{
struct atmel_hlcdc_plane_state *state =
drm_plane_state_to_atmel_hlcdc_plane_state(p->state);
struct atmel_hlcdc_plane_state *copy;
copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
if (!copy)
return NULL;
if (copy->base.fb)
drm_framebuffer_reference(copy->base.fb);
return &copy->base;
}
static void atmel_hlcdc_plane_atomic_destroy_state(struct drm_plane *plane,
struct drm_plane_state *s)
{
struct atmel_hlcdc_plane_state *state =
drm_plane_state_to_atmel_hlcdc_plane_state(s);
if (s->fb)
drm_framebuffer_unreference(s->fb);
kfree(state);
}
static struct drm_plane_funcs layer_plane_funcs = { static struct drm_plane_funcs layer_plane_funcs = {
.update_plane = atmel_hlcdc_plane_update, .update_plane = drm_atomic_helper_update_plane,
.disable_plane = atmel_hlcdc_plane_disable, .disable_plane = drm_atomic_helper_disable_plane,
.set_property = atmel_hlcdc_plane_set_property, .set_property = drm_atomic_helper_plane_set_property,
.destroy = atmel_hlcdc_plane_destroy, .destroy = atmel_hlcdc_plane_destroy,
.reset = atmel_hlcdc_plane_reset,
.atomic_duplicate_state = atmel_hlcdc_plane_atomic_duplicate_state,
.atomic_destroy_state = atmel_hlcdc_plane_atomic_destroy_state,
.atomic_set_property = atmel_hlcdc_plane_atomic_set_property,
.atomic_get_property = atmel_hlcdc_plane_atomic_get_property,
}; };
static struct atmel_hlcdc_plane * static struct atmel_hlcdc_plane *
...@@ -755,6 +834,9 @@ atmel_hlcdc_plane_create(struct drm_device *dev, ...@@ -755,6 +834,9 @@ atmel_hlcdc_plane_create(struct drm_device *dev,
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
drm_plane_helper_add(&plane->base,
&atmel_hlcdc_layer_plane_helper_funcs);
/* Set default property values*/ /* Set default property values*/
atmel_hlcdc_plane_init_properties(plane, desc, props); atmel_hlcdc_plane_init_properties(plane, desc, props);
...@@ -774,12 +856,13 @@ atmel_hlcdc_plane_create_properties(struct drm_device *dev) ...@@ -774,12 +856,13 @@ atmel_hlcdc_plane_create_properties(struct drm_device *dev)
if (!props->alpha) if (!props->alpha)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
props->rotation = drm_mode_create_rotation_property(dev, dev->mode_config.rotation_property =
BIT(DRM_ROTATE_0) | drm_mode_create_rotation_property(dev,
BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_0) |
BIT(DRM_ROTATE_180) | BIT(DRM_ROTATE_90) |
BIT(DRM_ROTATE_270)); BIT(DRM_ROTATE_180) |
if (!props->rotation) BIT(DRM_ROTATE_270));
if (!dev->mode_config.rotation_property)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
return props; return props;
......
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