drm: small property creation cleanup
[deliverable/linux.git] / drivers / gpu / drm / sti / sti_drm_plane.c
1 /*
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
7 */
8
9 #include "sti_compositor.h"
10 #include "sti_drm_drv.h"
11 #include "sti_drm_plane.h"
12 #include "sti_vtg.h"
13
14 enum sti_layer_desc sti_layer_default_zorder[] = {
15 STI_GDP_0,
16 STI_VID_0,
17 STI_GDP_1,
18 STI_VID_1,
19 STI_GDP_2,
20 STI_GDP_3,
21 };
22
23 /* (Background) < GDP0 < VID0 < GDP1 < VID1 < GDP2 < GDP3 < (ForeGround) */
24
25 static int
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)
31 {
32 struct sti_layer *layer = to_sti_layer(plane);
33 struct sti_mixer *mixer = to_sti_mixer(crtc);
34 int res;
35
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);
40
41 res = sti_mixer_set_layer_depth(mixer, layer);
42 if (res) {
43 DRM_ERROR("Can not set layer depth\n");
44 return res;
45 }
46
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);
53 if (res) {
54 DRM_ERROR("Layer prepare failed\n");
55 return res;
56 }
57
58 res = sti_layer_commit(layer);
59 if (res) {
60 DRM_ERROR("Layer commit failed\n");
61 return res;
62 }
63
64 res = sti_mixer_set_layer_status(mixer, layer, true);
65 if (res) {
66 DRM_ERROR("Can not enable layer at mixer\n");
67 return res;
68 }
69
70 return 0;
71 }
72
73 static int sti_drm_disable_plane(struct drm_plane *plane)
74 {
75 struct sti_layer *layer;
76 struct sti_mixer *mixer;
77 int lay_res, mix_res;
78
79 if (!plane->crtc) {
80 DRM_DEBUG_DRIVER("drm plane:%d not enabled\n", plane->base.id);
81 return 0;
82 }
83 layer = to_sti_layer(plane);
84 mixer = to_sti_mixer(plane->crtc);
85
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));
89
90 /* Disable layer at mixer level */
91 mix_res = sti_mixer_set_layer_status(mixer, layer, false);
92 if (mix_res)
93 DRM_ERROR("Can not disable layer at mixer\n");
94
95 /* Wait a while to be sure that a Vsync event is received */
96 msleep(WAIT_NEXT_VSYNC_MS);
97
98 /* Then disable layer itself */
99 lay_res = sti_layer_disable(layer);
100 if (lay_res)
101 DRM_ERROR("Layer disable failed\n");
102
103 if (lay_res || mix_res)
104 return -EINVAL;
105
106 return 0;
107 }
108
109 static void sti_drm_plane_destroy(struct drm_plane *plane)
110 {
111 DRM_DEBUG_DRIVER("\n");
112
113 sti_drm_disable_plane(plane);
114 drm_plane_cleanup(plane);
115 }
116
117 static int sti_drm_plane_set_property(struct drm_plane *plane,
118 struct drm_property *property,
119 uint64_t val)
120 {
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);
124
125 DRM_DEBUG_DRIVER("\n");
126
127 if (property == private->plane_zorder_property) {
128 layer->zorder = val;
129 return 0;
130 }
131
132 return -EINVAL;
133 }
134
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,
140 };
141
142 static void sti_drm_plane_attach_zorder_property(struct drm_plane *plane,
143 uint64_t default_val)
144 {
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);
149
150 prop = private->plane_zorder_property;
151 if (!prop) {
152 prop = drm_property_create_range(dev, 0, "zpos", 0,
153 GAM_MIXER_NB_DEPTH_LEVEL - 1);
154 if (!prop)
155 return;
156
157 private->plane_zorder_property = prop;
158 }
159
160 drm_object_attach_property(&plane->base, prop, default_val);
161 layer->zorder = default_val;
162 }
163
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)
168 {
169 int err, i;
170 uint64_t default_zorder = 0;
171
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);
176 if (err) {
177 DRM_ERROR("Failed to initialize plane\n");
178 return NULL;
179 }
180
181 for (i = 0; i < ARRAY_SIZE(sti_layer_default_zorder); i++)
182 if (sti_layer_default_zorder[i] == layer->desc)
183 break;
184
185 default_zorder = i;
186
187 if (type == DRM_PLANE_TYPE_OVERLAY)
188 sti_drm_plane_attach_zorder_property(&layer->plane,
189 default_zorder);
190
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);
194
195 return &layer->plane;
196 }
197 EXPORT_SYMBOL(sti_drm_plane_init);
This page took 0.037758 seconds and 5 git commands to generate.