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, crtc, fb,
49 &crtc->mode, mixer->id,
50 crtc_x, crtc_y, crtc_w, crtc_h,
51 src_x >> 16, src_y >> 16,
52 src_w >> 16, src_h >> 16);
54 DRM_ERROR("Layer prepare failed\n");
58 res = sti_layer_commit(layer);
60 DRM_ERROR("Layer commit failed\n");
64 res = sti_mixer_set_layer_status(mixer, layer, true);
66 DRM_ERROR("Can not enable layer at mixer\n");
73 static int sti_drm_disable_plane(struct drm_plane *plane)
75 struct sti_layer *layer;
76 struct sti_mixer *mixer;
80 DRM_DEBUG_DRIVER("drm plane:%d not enabled\n", plane->base.id);
83 layer = to_sti_layer(plane);
84 mixer = to_sti_mixer(plane->crtc);
86 DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n",
87 plane->crtc->base.id, sti_mixer_to_str(mixer),
88 plane->base.id, sti_layer_to_str(layer));
90 /* Disable layer at mixer level */
91 mix_res = sti_mixer_set_layer_status(mixer, layer, false);
93 DRM_ERROR("Can not disable layer at mixer\n");
95 /* Wait a while to be sure that a Vsync event is received */
96 msleep(WAIT_NEXT_VSYNC_MS);
98 /* Then disable layer itself */
99 lay_res = sti_layer_disable(layer);
101 DRM_ERROR("Layer disable failed\n");
103 if (lay_res || mix_res)
109 static void sti_drm_plane_destroy(struct drm_plane *plane)
111 DRM_DEBUG_DRIVER("\n");
113 sti_drm_disable_plane(plane);
114 drm_plane_cleanup(plane);
117 static int sti_drm_plane_set_property(struct drm_plane *plane,
118 struct drm_property *property,
121 struct drm_device *dev = plane->dev;
122 struct sti_drm_private *private = dev->dev_private;
123 struct sti_layer *layer = to_sti_layer(plane);
125 DRM_DEBUG_DRIVER("\n");
127 if (property == private->plane_zorder_property) {
135 static struct drm_plane_funcs sti_drm_plane_funcs = {
136 .update_plane = sti_drm_update_plane,
137 .disable_plane = sti_drm_disable_plane,
138 .destroy = sti_drm_plane_destroy,
139 .set_property = sti_drm_plane_set_property,
142 static void sti_drm_plane_attach_zorder_property(struct drm_plane *plane,
143 uint64_t default_val)
145 struct drm_device *dev = plane->dev;
146 struct sti_drm_private *private = dev->dev_private;
147 struct drm_property *prop;
148 struct sti_layer *layer = to_sti_layer(plane);
150 prop = private->plane_zorder_property;
152 prop = drm_property_create_range(dev, 0, "zpos", 0,
153 GAM_MIXER_NB_DEPTH_LEVEL - 1);
157 private->plane_zorder_property = prop;
160 drm_object_attach_property(&plane->base, prop, default_val);
161 layer->zorder = default_val;
164 struct drm_plane *sti_drm_plane_init(struct drm_device *dev,
165 struct sti_layer *layer,
166 unsigned int possible_crtcs,
167 enum drm_plane_type type)
170 uint64_t default_zorder = 0;
172 err = drm_universal_plane_init(dev, &layer->plane, possible_crtcs,
173 &sti_drm_plane_funcs,
174 sti_layer_get_formats(layer),
175 sti_layer_get_nb_formats(layer), type);
177 DRM_ERROR("Failed to initialize plane\n");
181 for (i = 0; i < ARRAY_SIZE(sti_layer_default_zorder); i++)
182 if (sti_layer_default_zorder[i] == layer->desc)
187 if (type == DRM_PLANE_TYPE_OVERLAY)
188 sti_drm_plane_attach_zorder_property(&layer->plane,
191 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%llu\n",
192 layer->plane.base.id,
193 sti_layer_to_str(layer), default_zorder);
195 return &layer->plane;
197 EXPORT_SYMBOL(sti_drm_plane_init);