2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
4 * Fabien Dessenne <fabien.dessenne@st.com>
5 * for STMicroelectronics.
6 * License terms: GNU General Public License (GPL), version 2
9 #include "sti_compositor.h"
10 #include "sti_drm_drv.h"
11 #include "sti_drm_plane.h"
14 enum sti_layer_desc sti_layer_default_zorder[] = {
23 /* (Background) < GDP0 < VID0 < GDP1 < VID1 < GDP2 < GDP3 < (ForeGround) */
26 sti_drm_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
27 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
28 unsigned int crtc_w, unsigned int crtc_h,
29 uint32_t src_x, uint32_t src_y,
30 uint32_t src_w, uint32_t src_h)
32 struct sti_layer *layer = to_sti_layer(plane);
33 struct sti_mixer *mixer = to_sti_mixer(crtc);
36 DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s) drm fb:%d\n",
37 crtc->base.id, sti_mixer_to_str(mixer),
38 plane->base.id, sti_layer_to_str(layer), fb->base.id);
39 DRM_DEBUG_KMS("(%dx%d)@(%d,%d)\n", crtc_w, crtc_h, crtc_x, crtc_y);
41 res = sti_mixer_set_layer_depth(mixer, layer);
43 DRM_ERROR("Can not set layer depth\n");
47 /* src_x are in 16.16 format. */
48 res = sti_layer_prepare(layer, fb, &crtc->mode, mixer->id,
49 crtc_x, crtc_y, crtc_w, crtc_h,
50 src_x >> 16, src_y >> 16,
51 src_w >> 16, src_h >> 16);
53 DRM_ERROR("Layer prepare failed\n");
57 res = sti_layer_commit(layer);
59 DRM_ERROR("Layer commit failed\n");
63 res = sti_mixer_set_layer_status(mixer, layer, true);
65 DRM_ERROR("Can not enable layer at mixer\n");
72 static int sti_drm_disable_plane(struct drm_plane *plane)
74 struct sti_layer *layer;
75 struct sti_mixer *mixer;
79 DRM_DEBUG_DRIVER("drm plane:%d not enabled\n", plane->base.id);
82 layer = to_sti_layer(plane);
83 mixer = to_sti_mixer(plane->crtc);
85 DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n",
86 plane->crtc->base.id, sti_mixer_to_str(mixer),
87 plane->base.id, sti_layer_to_str(layer));
89 /* Disable layer at mixer level */
90 mix_res = sti_mixer_set_layer_status(mixer, layer, false);
92 DRM_ERROR("Can not disable layer at mixer\n");
94 /* Wait a while to be sure that a Vsync event is received */
95 msleep(WAIT_NEXT_VSYNC_MS);
97 /* Then disable layer itself */
98 lay_res = sti_layer_disable(layer);
100 DRM_ERROR("Layer disable failed\n");
102 if (lay_res || mix_res)
108 static void sti_drm_plane_destroy(struct drm_plane *plane)
110 DRM_DEBUG_DRIVER("\n");
112 sti_drm_disable_plane(plane);
113 drm_plane_cleanup(plane);
116 static int sti_drm_plane_set_property(struct drm_plane *plane,
117 struct drm_property *property,
120 struct drm_device *dev = plane->dev;
121 struct sti_drm_private *private = dev->dev_private;
122 struct sti_layer *layer = to_sti_layer(plane);
124 DRM_DEBUG_DRIVER("\n");
126 if (property == private->plane_zorder_property) {
134 static struct drm_plane_funcs sti_drm_plane_funcs = {
135 .update_plane = sti_drm_update_plane,
136 .disable_plane = sti_drm_disable_plane,
137 .destroy = sti_drm_plane_destroy,
138 .set_property = sti_drm_plane_set_property,
141 static void sti_drm_plane_attach_zorder_property(struct drm_plane *plane,
142 uint64_t default_val)
144 struct drm_device *dev = plane->dev;
145 struct sti_drm_private *private = dev->dev_private;
146 struct drm_property *prop;
147 struct sti_layer *layer = to_sti_layer(plane);
149 prop = private->plane_zorder_property;
151 prop = drm_property_create_range(dev, 0, "zpos", 0,
152 GAM_MIXER_NB_DEPTH_LEVEL - 1);
156 private->plane_zorder_property = prop;
159 drm_object_attach_property(&plane->base, prop, default_val);
160 layer->zorder = default_val;
163 struct drm_plane *sti_drm_plane_init(struct drm_device *dev,
164 struct sti_layer *layer,
165 unsigned int possible_crtcs,
166 enum drm_plane_type type)
169 uint64_t default_zorder = 0;
171 err = drm_universal_plane_init(dev, &layer->plane, possible_crtcs,
172 &sti_drm_plane_funcs,
173 sti_layer_get_formats(layer),
174 sti_layer_get_nb_formats(layer), type);
176 DRM_ERROR("Failed to initialize plane\n");
180 for (i = 0; i < ARRAY_SIZE(sti_layer_default_zorder); i++)
181 if (sti_layer_default_zorder[i] == layer->desc)
186 if (type == DRM_PLANE_TYPE_OVERLAY)
187 sti_drm_plane_attach_zorder_property(&layer->plane,
190 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%llu\n",
191 layer->plane.base.id,
192 sti_layer_to_str(layer), default_zorder);
194 return &layer->plane;