2019-05-27 14:55:21 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-02-19 20:30:26 +08:00
|
|
|
/*
|
|
|
|
* ARC PGU DRM driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-01-09 03:29:36 +08:00
|
|
|
#include <drm/drm_device.h>
|
2016-02-19 20:30:26 +08:00
|
|
|
#include <drm/drm_fb_cma_helper.h>
|
|
|
|
#include <drm/drm_gem_cma_helper.h>
|
|
|
|
#include <drm/drm_plane_helper.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2016-02-19 20:30:26 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/platform_data/simplefb.h>
|
|
|
|
|
|
|
|
#include "arcpgu.h"
|
|
|
|
#include "arcpgu_regs.h"
|
|
|
|
|
|
|
|
#define ENCODE_PGU_XY(x, y) ((((x) - 1) << 16) | ((y) - 1))
|
|
|
|
|
2019-11-19 22:41:45 +08:00
|
|
|
static const u32 arc_pgu_supported_formats[] = {
|
|
|
|
DRM_FORMAT_RGB565,
|
2019-11-19 22:41:46 +08:00
|
|
|
DRM_FORMAT_XRGB8888,
|
2019-11-19 22:41:47 +08:00
|
|
|
DRM_FORMAT_ARGB8888,
|
2016-02-19 20:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void arc_pgu_set_pxl_fmt(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
2016-11-19 03:52:44 +08:00
|
|
|
const struct drm_framebuffer *fb = crtc->primary->state->fb;
|
2016-12-15 05:32:55 +08:00
|
|
|
uint32_t pixel_format = fb->format->format;
|
2019-11-19 22:41:45 +08:00
|
|
|
u32 format = DRM_FORMAT_INVALID;
|
2016-02-19 20:30:26 +08:00
|
|
|
int i;
|
2019-11-19 22:41:44 +08:00
|
|
|
u32 reg_ctrl;
|
2016-02-19 20:30:26 +08:00
|
|
|
|
2019-11-19 22:41:45 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(arc_pgu_supported_formats); i++) {
|
|
|
|
if (arc_pgu_supported_formats[i] == pixel_format)
|
|
|
|
format = arc_pgu_supported_formats[i];
|
2016-02-19 20:30:26 +08:00
|
|
|
}
|
|
|
|
|
2019-11-19 22:41:45 +08:00
|
|
|
if (WARN_ON(format == DRM_FORMAT_INVALID))
|
2016-02-19 20:30:26 +08:00
|
|
|
return;
|
|
|
|
|
2019-11-19 22:41:44 +08:00
|
|
|
reg_ctrl = arc_pgu_read(arcpgu, ARCPGU_REG_CTRL);
|
2019-11-19 22:41:45 +08:00
|
|
|
if (format == DRM_FORMAT_RGB565)
|
2019-11-19 22:41:46 +08:00
|
|
|
reg_ctrl &= ~ARCPGU_MODE_XRGB8888;
|
2019-11-19 22:41:44 +08:00
|
|
|
else
|
2019-11-19 22:41:46 +08:00
|
|
|
reg_ctrl |= ARCPGU_MODE_XRGB8888;
|
2019-11-19 22:41:44 +08:00
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, reg_ctrl);
|
2016-02-19 20:30:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_crtc_funcs arc_pgu_crtc_funcs = {
|
|
|
|
.destroy = drm_crtc_cleanup,
|
|
|
|
.set_config = drm_atomic_helper_set_config,
|
|
|
|
.page_flip = drm_atomic_helper_page_flip,
|
|
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
|
|
|
};
|
|
|
|
|
2017-06-23 17:54:18 +08:00
|
|
|
static enum drm_mode_status arc_pgu_crtc_mode_valid(struct drm_crtc *crtc,
|
|
|
|
const struct drm_display_mode *mode)
|
2017-05-25 22:19:17 +08:00
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
long rate, clk_rate = mode->clock * 1000;
|
2017-07-17 20:08:27 +08:00
|
|
|
long diff = clk_rate / 200; /* +-0.5% allowed by HDMI spec */
|
2017-05-25 22:19:17 +08:00
|
|
|
|
|
|
|
rate = clk_round_rate(arcpgu->clk, clk_rate);
|
2017-07-17 20:08:27 +08:00
|
|
|
if ((max(rate, clk_rate) - min(rate, clk_rate) < diff) && (rate > 0))
|
|
|
|
return MODE_OK;
|
2017-05-25 22:19:17 +08:00
|
|
|
|
2017-07-17 20:08:27 +08:00
|
|
|
return MODE_NOCLOCK;
|
2017-05-25 22:19:17 +08:00
|
|
|
}
|
|
|
|
|
2016-02-19 20:30:26 +08:00
|
|
|
static void arc_pgu_crtc_mode_set_nofb(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
struct drm_display_mode *m = &crtc->state->adjusted_mode;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_FMT,
|
|
|
|
ENCODE_PGU_XY(m->crtc_htotal, m->crtc_vtotal));
|
|
|
|
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_HSYNC,
|
|
|
|
ENCODE_PGU_XY(m->crtc_hsync_start - m->crtc_hdisplay,
|
|
|
|
m->crtc_hsync_end - m->crtc_hdisplay));
|
|
|
|
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_VSYNC,
|
|
|
|
ENCODE_PGU_XY(m->crtc_vsync_start - m->crtc_vdisplay,
|
|
|
|
m->crtc_vsync_end - m->crtc_vdisplay));
|
|
|
|
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_ACTIVE,
|
|
|
|
ENCODE_PGU_XY(m->crtc_hblank_end - m->crtc_hblank_start,
|
|
|
|
m->crtc_vblank_end - m->crtc_vblank_start));
|
|
|
|
|
|
|
|
val = arc_pgu_read(arcpgu, ARCPGU_REG_CTRL);
|
|
|
|
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PVSYNC)
|
|
|
|
val |= ARCPGU_CTRL_VS_POL_MASK << ARCPGU_CTRL_VS_POL_OFST;
|
|
|
|
else
|
|
|
|
val &= ~(ARCPGU_CTRL_VS_POL_MASK << ARCPGU_CTRL_VS_POL_OFST);
|
|
|
|
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PHSYNC)
|
|
|
|
val |= ARCPGU_CTRL_HS_POL_MASK << ARCPGU_CTRL_HS_POL_OFST;
|
|
|
|
else
|
|
|
|
val &= ~(ARCPGU_CTRL_HS_POL_MASK << ARCPGU_CTRL_HS_POL_OFST);
|
|
|
|
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, val);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_STRIDE, 0);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_START_SET, 1);
|
|
|
|
|
|
|
|
arc_pgu_set_pxl_fmt(crtc);
|
|
|
|
|
|
|
|
clk_set_rate(arcpgu->clk, m->crtc_clock * 1000);
|
|
|
|
}
|
|
|
|
|
2017-06-30 17:36:44 +08:00
|
|
|
static void arc_pgu_crtc_atomic_enable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-02-19 20:30:26 +08:00
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
|
|
|
|
clk_prepare_enable(arcpgu->clk);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL,
|
|
|
|
arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) |
|
|
|
|
ARCPGU_CTRL_ENABLE_MASK);
|
|
|
|
}
|
|
|
|
|
2017-06-30 17:36:45 +08:00
|
|
|
static void arc_pgu_crtc_atomic_disable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-02-19 20:30:26 +08:00
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
|
|
|
|
clk_disable_unprepare(arcpgu->clk);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL,
|
|
|
|
arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) &
|
|
|
|
~ARCPGU_CTRL_ENABLE_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_crtc_helper_funcs arc_pgu_crtc_helper_funcs = {
|
2017-05-25 22:19:17 +08:00
|
|
|
.mode_valid = arc_pgu_crtc_mode_valid,
|
2016-02-19 20:30:26 +08:00
|
|
|
.mode_set_nofb = arc_pgu_crtc_mode_set_nofb,
|
2017-06-30 17:36:44 +08:00
|
|
|
.atomic_enable = arc_pgu_crtc_atomic_enable,
|
2017-06-30 17:36:45 +08:00
|
|
|
.atomic_disable = arc_pgu_crtc_atomic_disable,
|
2016-02-19 20:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void arc_pgu_plane_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu;
|
|
|
|
struct drm_gem_cma_object *gem;
|
|
|
|
|
|
|
|
if (!plane->state->crtc || !plane->state->fb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
arcpgu = crtc_to_arcpgu_priv(plane->state->crtc);
|
|
|
|
gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_BUF0_ADDR, gem->paddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_plane_helper_funcs arc_pgu_plane_helper_funcs = {
|
|
|
|
.atomic_update = arc_pgu_plane_atomic_update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void arc_pgu_plane_destroy(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
drm_plane_cleanup(plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_plane_funcs arc_pgu_plane_funcs = {
|
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
|
|
.destroy = arc_pgu_plane_destroy,
|
|
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = drm->dev_private;
|
|
|
|
struct drm_plane *plane = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
|
|
|
|
if (!plane)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
ret = drm_universal_plane_init(drm, plane, 0xff, &arc_pgu_plane_funcs,
|
2019-11-19 22:41:45 +08:00
|
|
|
arc_pgu_supported_formats,
|
|
|
|
ARRAY_SIZE(arc_pgu_supported_formats),
|
2017-07-24 11:46:38 +08:00
|
|
|
NULL,
|
2016-02-19 20:30:26 +08:00
|
|
|
DRM_PLANE_TYPE_PRIMARY, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
|
|
|
drm_plane_helper_add(plane, &arc_pgu_plane_helper_funcs);
|
|
|
|
arcpgu->plane = plane;
|
|
|
|
|
|
|
|
return plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arc_pgu_setup_crtc(struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct arcpgu_drm_private *arcpgu = drm->dev_private;
|
|
|
|
struct drm_plane *primary;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
primary = arc_pgu_plane_init(drm);
|
|
|
|
if (IS_ERR(primary))
|
|
|
|
return PTR_ERR(primary);
|
|
|
|
|
|
|
|
ret = drm_crtc_init_with_planes(drm, &arcpgu->crtc, primary, NULL,
|
|
|
|
&arc_pgu_crtc_funcs, NULL);
|
|
|
|
if (ret) {
|
|
|
|
arc_pgu_plane_destroy(primary);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_crtc_helper_add(&arcpgu->crtc, &arc_pgu_crtc_helper_funcs);
|
|
|
|
return 0;
|
|
|
|
}
|