[PATCH v3 1/2] drm: mali-dp: add malidp_crtc_state struct

From: Mihail Atanassov
Date: Tue Feb 07 2017 - 11:49:57 EST


Add a custom CRTC state struct to enable storing driver-private per-CRTC
state. This patch only adds the base drm_crtc_state struct.

Signed-off-by: Mihail Atanassov <mihail.atanassov@xxxxxxx>
Reviewed-by: Brian Starkey <brian.starkey@xxxxxxx>
Acked-by: Liviu Dudau <liviu.dudau@xxxxxxx>
---
Link to v2: https://lkml.org/lkml/2017/2/1/378
Link to v1: https://lkml.org/lkml/2017/2/1/203

Changes since v2:
- rebased and fixed conflicts
- s/MALIDP_DISP_FUNC_GAM/MALIDP_DISP_FUNC_GAMMA/g
- added MALIDP_GAMMA_LUT_SIZE #define + s/4096/MALIDP_GAMMA_LUT_SIZE/g in
malidp_crtc.c
- improved readability in a few places

Changes since v1:
- Moved unused variable to patch 2/2, where it is used.

drivers/gpu/drm/arm/malidp_crtc.c | 37 +++++++++++++++++++++++++++++++++++--
drivers/gpu/drm/arm/malidp_drv.h | 6 ++++++
2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c
index 08e6a71..ebf57e6 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -160,6 +160,39 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc,
return 0;
}

+static struct drm_crtc_state *malidp_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+ struct malidp_crtc_state *state;
+
+ if (WARN_ON(!crtc->state))
+ return NULL;
+
+ state = kmalloc(sizeof(*state), GFP_KERNEL);
+ if (!state)
+ return NULL;
+
+ __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
+
+ return &state->base;
+}
+
+static void malidp_crtc_reset(struct drm_crtc *crtc)
+{
+ struct malidp_crtc_state *cs = (crtc->state) ?
+ to_malidp_crtc_state(crtc->state) : NULL;
+
+ if (crtc->state)
+ __drm_atomic_helper_crtc_destroy_state(crtc->state);
+
+ kfree(cs);
+ cs = kzalloc(sizeof(*cs), GFP_KERNEL);
+ if (!cs)
+ return;
+
+ crtc->state = &cs->base;
+ crtc->state->crtc = crtc;
+}
+
static const struct drm_crtc_helper_funcs malidp_crtc_helper_funcs = {
.mode_fixup = malidp_crtc_mode_fixup,
.enable = malidp_crtc_enable,
@@ -171,8 +204,8 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc,
.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,
+ .reset = malidp_crtc_reset,
+ .atomic_duplicate_state = malidp_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
};

diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h
index dbc617c..558f4bf 100644
--- a/drivers/gpu/drm/arm/malidp_drv.h
+++ b/drivers/gpu/drm/arm/malidp_drv.h
@@ -47,6 +47,12 @@ struct malidp_plane_state {
#define to_malidp_plane(x) container_of(x, struct malidp_plane, base)
#define to_malidp_plane_state(x) container_of(x, struct malidp_plane_state, base)

+struct malidp_crtc_state {
+ struct drm_crtc_state base;
+};
+
+#define to_malidp_crtc_state(x) container_of(x, struct malidp_crtc_state, base)
+
int malidp_de_planes_init(struct drm_device *drm);
void malidp_de_planes_destroy(struct drm_device *drm);
int malidp_crtc_init(struct drm_device *drm);
--
1.9.1