blob: e5a5b73a08cbb2529ed344eea76894fe9fa1202c [file] [log] [blame]
Russell King96f60e32012-08-15 13:59:49 +01001/*
2 * Copyright (C) 2012 Russell King
3 * Rewritten from the dovefb driver, and Armada510 manuals.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <drm/drmP.h>
Russell King98fb74f2015-06-15 10:17:57 +010010#include <drm/drm_plane_helper.h>
Russell King96f60e32012-08-15 13:59:49 +010011#include "armada_crtc.h"
12#include "armada_drm.h"
13#include "armada_fb.h"
14#include "armada_gem.h"
15#include "armada_hw.h"
16#include <drm/armada_drm.h>
17#include "armada_ioctlP.h"
18
Russell King28a2aeb2015-07-15 18:11:23 +010019struct armada_ovl_plane_properties {
Russell King96f60e32012-08-15 13:59:49 +010020 uint32_t colorkey_yr;
21 uint32_t colorkey_ug;
22 uint32_t colorkey_vb;
23#define K2R(val) (((val) >> 0) & 0xff)
24#define K2G(val) (((val) >> 8) & 0xff)
25#define K2B(val) (((val) >> 16) & 0xff)
26 int16_t brightness;
27 uint16_t contrast;
28 uint16_t saturation;
29 uint32_t colorkey_mode;
30};
31
Russell King28a2aeb2015-07-15 18:11:23 +010032struct armada_ovl_plane {
Russell King561f60b2015-07-15 18:11:24 +010033 struct armada_plane base;
Russell King96f60e32012-08-15 13:59:49 +010034 struct drm_framebuffer *old_fb;
35 uint32_t src_hw;
36 uint32_t dst_hw;
37 uint32_t dst_yx;
38 uint32_t ctrl0;
39 struct {
40 struct armada_vbl_event update;
41 struct armada_regs regs[13];
42 wait_queue_head_t wait;
43 } vbl;
Russell King28a2aeb2015-07-15 18:11:23 +010044 struct armada_ovl_plane_properties prop;
Russell King96f60e32012-08-15 13:59:49 +010045};
Russell King561f60b2015-07-15 18:11:24 +010046#define drm_to_armada_ovl_plane(p) \
47 container_of(p, struct armada_ovl_plane, base.base)
Russell King96f60e32012-08-15 13:59:49 +010048
49
50static void
Russell King28a2aeb2015-07-15 18:11:23 +010051armada_ovl_update_attr(struct armada_ovl_plane_properties *prop,
Russell King96f60e32012-08-15 13:59:49 +010052 struct armada_crtc *dcrtc)
53{
54 writel_relaxed(prop->colorkey_yr, dcrtc->base + LCD_SPU_COLORKEY_Y);
55 writel_relaxed(prop->colorkey_ug, dcrtc->base + LCD_SPU_COLORKEY_U);
56 writel_relaxed(prop->colorkey_vb, dcrtc->base + LCD_SPU_COLORKEY_V);
57
58 writel_relaxed(prop->brightness << 16 | prop->contrast,
59 dcrtc->base + LCD_SPU_CONTRAST);
60 /* Docs say 15:0, but it seems to actually be 31:16 on Armada 510 */
61 writel_relaxed(prop->saturation << 16,
62 dcrtc->base + LCD_SPU_SATURATION);
63 writel_relaxed(0x00002000, dcrtc->base + LCD_SPU_CBSH_HUE);
64
65 spin_lock_irq(&dcrtc->irq_lock);
66 armada_updatel(prop->colorkey_mode | CFG_ALPHAM_GRA,
67 CFG_CKMODE_MASK | CFG_ALPHAM_MASK | CFG_ALPHA_MASK,
68 dcrtc->base + LCD_SPU_DMA_CTRL1);
69
70 armada_updatel(ADV_GRACOLORKEY, 0, dcrtc->base + LCD_SPU_ADV_REG);
71 spin_unlock_irq(&dcrtc->irq_lock);
72}
73
Russell Kingfecfdb22015-07-15 18:11:24 +010074static void armada_ovl_retire_fb(struct armada_ovl_plane *dplane,
75 struct drm_framebuffer *fb)
76{
77 struct drm_framebuffer *old_fb;
78
Russell King66377ef2015-07-15 18:11:24 +010079 old_fb = xchg(&dplane->old_fb, fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010080
81 if (old_fb)
Russell King561f60b2015-07-15 18:11:24 +010082 armada_drm_queue_unref_work(dplane->base.base.dev, old_fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010083}
84
Russell King96f60e32012-08-15 13:59:49 +010085/* === Plane support === */
Russell King28a2aeb2015-07-15 18:11:23 +010086static void armada_ovl_plane_vbl(struct armada_crtc *dcrtc, void *data)
Russell King96f60e32012-08-15 13:59:49 +010087{
Russell King28a2aeb2015-07-15 18:11:23 +010088 struct armada_ovl_plane *dplane = data;
Russell King96f60e32012-08-15 13:59:49 +010089
90 armada_drm_crtc_update_regs(dcrtc, dplane->vbl.regs);
Russell Kingfecfdb22015-07-15 18:11:24 +010091 armada_ovl_retire_fb(dplane, NULL);
Russell King070f3f62015-06-15 10:13:29 +010092
93 wake_up(&dplane->vbl.wait);
Russell King96f60e32012-08-15 13:59:49 +010094}
95
Russell King96f60e32012-08-15 13:59:49 +010096static int
Russell King28a2aeb2015-07-15 18:11:23 +010097armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
Russell King96f60e32012-08-15 13:59:49 +010098 struct drm_framebuffer *fb,
99 int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
100 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
101{
Russell King28a2aeb2015-07-15 18:11:23 +0100102 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100103 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King98fb74f2015-06-15 10:17:57 +0100104 struct drm_rect src = {
105 .x1 = src_x,
106 .y1 = src_y,
107 .x2 = src_x + src_w,
108 .y2 = src_y + src_h,
109 };
110 struct drm_rect dest = {
111 .x1 = crtc_x,
112 .y1 = crtc_y,
113 .x2 = crtc_x + crtc_w,
114 .y2 = crtc_y + crtc_h,
115 };
116 const struct drm_rect clip = {
117 .x2 = crtc->mode.hdisplay,
118 .y2 = crtc->mode.vdisplay,
119 };
Russell King96f60e32012-08-15 13:59:49 +0100120 uint32_t val, ctrl0;
121 unsigned idx = 0;
Russell King98fb74f2015-06-15 10:17:57 +0100122 bool visible;
Russell King96f60e32012-08-15 13:59:49 +0100123 int ret;
124
Russell King98fb74f2015-06-15 10:17:57 +0100125 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip,
126 0, INT_MAX, true, false, &visible);
127 if (ret)
128 return ret;
129
Russell King96f60e32012-08-15 13:59:49 +0100130 ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) |
131 CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) |
132 CFG_CBSH_ENA | CFG_DMA_HSMOOTH | CFG_DMA_ENA;
133
134 /* Does the position/size result in nothing to display? */
Russell King98fb74f2015-06-15 10:17:57 +0100135 if (!visible)
Russell King96f60e32012-08-15 13:59:49 +0100136 ctrl0 &= ~CFG_DMA_ENA;
Russell King96f60e32012-08-15 13:59:49 +0100137
138 if (!dcrtc->plane) {
139 dcrtc->plane = plane;
140 armada_ovl_update_attr(&dplane->prop, dcrtc);
141 }
142
143 /* FIXME: overlay on an interlaced display */
144 /* Just updating the position/size? */
145 if (plane->fb == fb && dplane->ctrl0 == ctrl0) {
Russell King98fb74f2015-06-15 10:17:57 +0100146 val = (drm_rect_height(&src) & 0xffff0000) |
147 drm_rect_width(&src) >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100148 dplane->src_hw = val;
149 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100150
151 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King96f60e32012-08-15 13:59:49 +0100152 dplane->dst_hw = val;
153 writel_relaxed(val, dcrtc->base + LCD_SPU_DZM_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100154
155 val = dest.y1 << 16 | dest.x1;
Russell King96f60e32012-08-15 13:59:49 +0100156 dplane->dst_yx = val;
157 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_OVSA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100158
Russell King96f60e32012-08-15 13:59:49 +0100159 return 0;
160 } else if (~dplane->ctrl0 & ctrl0 & CFG_DMA_ENA) {
161 /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */
162 armada_updatel(0, CFG_PDWN16x66 | CFG_PDWN32x66,
163 dcrtc->base + LCD_SPU_SRAM_PARA1);
164 }
165
Russell King070f3f62015-06-15 10:13:29 +0100166 wait_event_timeout(dplane->vbl.wait,
167 list_empty(&dplane->vbl.update.node),
168 HZ/25);
Russell King96f60e32012-08-15 13:59:49 +0100169
170 if (plane->fb != fb) {
171 struct armada_gem_object *obj = drm_fb_obj(fb);
Russell King73068ce2015-06-15 10:18:02 +0100172 uint32_t addr[3], pixel_format;
173 int i, num_planes, hsub;
Russell King96f60e32012-08-15 13:59:49 +0100174
175 /*
176 * Take a reference on the new framebuffer - we want to
177 * hold on to it while the hardware is displaying it.
178 */
179 drm_framebuffer_reference(fb);
180
Russell Kingfecfdb22015-07-15 18:11:24 +0100181 if (plane->fb)
182 armada_ovl_retire_fb(dplane, plane->fb);
Russell King96f60e32012-08-15 13:59:49 +0100183
Russell King98fb74f2015-06-15 10:17:57 +0100184 src_y = src.y1 >> 16;
185 src_x = src.x1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100186
Russell King73068ce2015-06-15 10:18:02 +0100187 pixel_format = fb->pixel_format;
188 hsub = drm_format_horz_chroma_subsampling(pixel_format);
189 num_planes = drm_format_num_planes(pixel_format);
190
191 /*
192 * Annoyingly, shifting a YUYV-format image by one pixel
193 * causes the U/V planes to toggle. Toggle the UV swap.
194 * (Unfortunately, this causes momentary colour flickering.)
195 */
196 if (src_x & (hsub - 1) && num_planes == 1)
197 ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV);
198
199 for (i = 0; i < num_planes; i++)
200 addr[i] = obj->dev_addr + fb->offsets[i] +
201 src_y * fb->pitches[i] +
202 src_x * drm_format_plane_cpp(pixel_format, i);
203 for (; i < ARRAY_SIZE(addr); i++)
204 addr[i] = 0;
205
206 armada_reg_queue_set(dplane->vbl.regs, idx, addr[0],
Russell King96f60e32012-08-15 13:59:49 +0100207 LCD_SPU_DMA_START_ADDR_Y0);
Russell King73068ce2015-06-15 10:18:02 +0100208 armada_reg_queue_set(dplane->vbl.regs, idx, addr[1],
Russell King96f60e32012-08-15 13:59:49 +0100209 LCD_SPU_DMA_START_ADDR_U0);
Russell King73068ce2015-06-15 10:18:02 +0100210 armada_reg_queue_set(dplane->vbl.regs, idx, addr[2],
Russell King96f60e32012-08-15 13:59:49 +0100211 LCD_SPU_DMA_START_ADDR_V0);
Russell King73068ce2015-06-15 10:18:02 +0100212 armada_reg_queue_set(dplane->vbl.regs, idx, addr[0],
Russell King96f60e32012-08-15 13:59:49 +0100213 LCD_SPU_DMA_START_ADDR_Y1);
Russell King73068ce2015-06-15 10:18:02 +0100214 armada_reg_queue_set(dplane->vbl.regs, idx, addr[1],
Russell King96f60e32012-08-15 13:59:49 +0100215 LCD_SPU_DMA_START_ADDR_U1);
Russell King73068ce2015-06-15 10:18:02 +0100216 armada_reg_queue_set(dplane->vbl.regs, idx, addr[2],
Russell King96f60e32012-08-15 13:59:49 +0100217 LCD_SPU_DMA_START_ADDR_V1);
218
219 val = fb->pitches[0] << 16 | fb->pitches[0];
220 armada_reg_queue_set(dplane->vbl.regs, idx, val,
221 LCD_SPU_DMA_PITCH_YC);
222 val = fb->pitches[1] << 16 | fb->pitches[2];
223 armada_reg_queue_set(dplane->vbl.regs, idx, val,
224 LCD_SPU_DMA_PITCH_UV);
225 }
226
Russell King98fb74f2015-06-15 10:17:57 +0100227 val = (drm_rect_height(&src) & 0xffff0000) | drm_rect_width(&src) >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100228 if (dplane->src_hw != val) {
229 dplane->src_hw = val;
230 armada_reg_queue_set(dplane->vbl.regs, idx, val,
231 LCD_SPU_DMA_HPXL_VLN);
232 }
Russell King98fb74f2015-06-15 10:17:57 +0100233
234 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King96f60e32012-08-15 13:59:49 +0100235 if (dplane->dst_hw != val) {
236 dplane->dst_hw = val;
237 armada_reg_queue_set(dplane->vbl.regs, idx, val,
238 LCD_SPU_DZM_HPXL_VLN);
239 }
Russell King98fb74f2015-06-15 10:17:57 +0100240
241 val = dest.y1 << 16 | dest.x1;
Russell King96f60e32012-08-15 13:59:49 +0100242 if (dplane->dst_yx != val) {
243 dplane->dst_yx = val;
244 armada_reg_queue_set(dplane->vbl.regs, idx, val,
245 LCD_SPU_DMA_OVSA_HPXL_VLN);
246 }
Russell King98fb74f2015-06-15 10:17:57 +0100247
Russell King96f60e32012-08-15 13:59:49 +0100248 if (dplane->ctrl0 != ctrl0) {
249 dplane->ctrl0 = ctrl0;
250 armada_reg_queue_mod(dplane->vbl.regs, idx, ctrl0,
251 CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE |
252 CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE |
253 CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU |
254 CFG_YUV2RGB) | CFG_DMA_ENA,
255 LCD_SPU_DMA_CTRL0);
256 }
257 if (idx) {
258 armada_reg_queue_end(dplane->vbl.regs, idx);
259 armada_drm_vbl_event_add(dcrtc, &dplane->vbl.update);
260 }
261 return 0;
262}
263
Russell King28a2aeb2015-07-15 18:11:23 +0100264static int armada_ovl_plane_disable(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100265{
Russell King28a2aeb2015-07-15 18:11:23 +0100266 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100267 struct drm_framebuffer *fb;
268 struct armada_crtc *dcrtc;
269
Russell King561f60b2015-07-15 18:11:24 +0100270 if (!dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100271 return 0;
272
Russell King561f60b2015-07-15 18:11:24 +0100273 dcrtc = drm_to_armada_crtc(dplane->base.base.crtc);
Russell King96f60e32012-08-15 13:59:49 +0100274 dcrtc->plane = NULL;
275
276 spin_lock_irq(&dcrtc->irq_lock);
277 armada_drm_vbl_event_remove(dcrtc, &dplane->vbl.update);
278 armada_updatel(0, CFG_DMA_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
279 dplane->ctrl0 = 0;
280 spin_unlock_irq(&dcrtc->irq_lock);
281
282 /* Power down the Y/U/V FIFOs */
283 armada_updatel(CFG_PDWN16x66 | CFG_PDWN32x66, 0,
284 dcrtc->base + LCD_SPU_SRAM_PARA1);
285
286 if (plane->fb)
287 drm_framebuffer_unreference(plane->fb);
288
Russell King66377ef2015-07-15 18:11:24 +0100289 fb = xchg(&dplane->old_fb, NULL);
Russell King96f60e32012-08-15 13:59:49 +0100290 if (fb)
291 drm_framebuffer_unreference(fb);
292
293 return 0;
294}
295
Russell King28a2aeb2015-07-15 18:11:23 +0100296static void armada_ovl_plane_destroy(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100297{
Russell King28a2aeb2015-07-15 18:11:23 +0100298 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King41dbb2d2015-06-15 10:13:30 +0100299
300 drm_plane_cleanup(plane);
301
302 kfree(dplane);
Russell King96f60e32012-08-15 13:59:49 +0100303}
304
Russell King28a2aeb2015-07-15 18:11:23 +0100305static int armada_ovl_plane_set_property(struct drm_plane *plane,
Russell King96f60e32012-08-15 13:59:49 +0100306 struct drm_property *property, uint64_t val)
307{
308 struct armada_private *priv = plane->dev->dev_private;
Russell King28a2aeb2015-07-15 18:11:23 +0100309 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100310 bool update_attr = false;
311
312 if (property == priv->colorkey_prop) {
313#define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8)
314 dplane->prop.colorkey_yr = CCC(K2R(val));
315 dplane->prop.colorkey_ug = CCC(K2G(val));
316 dplane->prop.colorkey_vb = CCC(K2B(val));
317#undef CCC
318 update_attr = true;
319 } else if (property == priv->colorkey_min_prop) {
320 dplane->prop.colorkey_yr &= ~0x00ff0000;
321 dplane->prop.colorkey_yr |= K2R(val) << 16;
322 dplane->prop.colorkey_ug &= ~0x00ff0000;
323 dplane->prop.colorkey_ug |= K2G(val) << 16;
324 dplane->prop.colorkey_vb &= ~0x00ff0000;
325 dplane->prop.colorkey_vb |= K2B(val) << 16;
326 update_attr = true;
327 } else if (property == priv->colorkey_max_prop) {
328 dplane->prop.colorkey_yr &= ~0xff000000;
329 dplane->prop.colorkey_yr |= K2R(val) << 24;
330 dplane->prop.colorkey_ug &= ~0xff000000;
331 dplane->prop.colorkey_ug |= K2G(val) << 24;
332 dplane->prop.colorkey_vb &= ~0xff000000;
333 dplane->prop.colorkey_vb |= K2B(val) << 24;
334 update_attr = true;
335 } else if (property == priv->colorkey_val_prop) {
336 dplane->prop.colorkey_yr &= ~0x0000ff00;
337 dplane->prop.colorkey_yr |= K2R(val) << 8;
338 dplane->prop.colorkey_ug &= ~0x0000ff00;
339 dplane->prop.colorkey_ug |= K2G(val) << 8;
340 dplane->prop.colorkey_vb &= ~0x0000ff00;
341 dplane->prop.colorkey_vb |= K2B(val) << 8;
342 update_attr = true;
343 } else if (property == priv->colorkey_alpha_prop) {
344 dplane->prop.colorkey_yr &= ~0x000000ff;
345 dplane->prop.colorkey_yr |= K2R(val);
346 dplane->prop.colorkey_ug &= ~0x000000ff;
347 dplane->prop.colorkey_ug |= K2G(val);
348 dplane->prop.colorkey_vb &= ~0x000000ff;
349 dplane->prop.colorkey_vb |= K2B(val);
350 update_attr = true;
351 } else if (property == priv->colorkey_mode_prop) {
352 dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK;
353 dplane->prop.colorkey_mode |= CFG_CKMODE(val);
354 update_attr = true;
355 } else if (property == priv->brightness_prop) {
356 dplane->prop.brightness = val - 256;
357 update_attr = true;
358 } else if (property == priv->contrast_prop) {
359 dplane->prop.contrast = val;
360 update_attr = true;
361 } else if (property == priv->saturation_prop) {
362 dplane->prop.saturation = val;
363 update_attr = true;
364 }
365
Russell King561f60b2015-07-15 18:11:24 +0100366 if (update_attr && dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100367 armada_ovl_update_attr(&dplane->prop,
Russell King561f60b2015-07-15 18:11:24 +0100368 drm_to_armada_crtc(dplane->base.base.crtc));
Russell King96f60e32012-08-15 13:59:49 +0100369
370 return 0;
371}
372
Russell King28a2aeb2015-07-15 18:11:23 +0100373static const struct drm_plane_funcs armada_ovl_plane_funcs = {
374 .update_plane = armada_ovl_plane_update,
375 .disable_plane = armada_ovl_plane_disable,
376 .destroy = armada_ovl_plane_destroy,
377 .set_property = armada_ovl_plane_set_property,
Russell King96f60e32012-08-15 13:59:49 +0100378};
379
Russell King28a2aeb2015-07-15 18:11:23 +0100380static const uint32_t armada_ovl_formats[] = {
Russell King96f60e32012-08-15 13:59:49 +0100381 DRM_FORMAT_UYVY,
382 DRM_FORMAT_YUYV,
383 DRM_FORMAT_YUV420,
384 DRM_FORMAT_YVU420,
385 DRM_FORMAT_YUV422,
386 DRM_FORMAT_YVU422,
387 DRM_FORMAT_VYUY,
388 DRM_FORMAT_YVYU,
389 DRM_FORMAT_ARGB8888,
390 DRM_FORMAT_ABGR8888,
391 DRM_FORMAT_XRGB8888,
392 DRM_FORMAT_XBGR8888,
393 DRM_FORMAT_RGB888,
394 DRM_FORMAT_BGR888,
395 DRM_FORMAT_ARGB1555,
396 DRM_FORMAT_ABGR1555,
397 DRM_FORMAT_RGB565,
398 DRM_FORMAT_BGR565,
399};
400
401static struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = {
402 { CKMODE_DISABLE, "disabled" },
403 { CKMODE_Y, "Y component" },
404 { CKMODE_U, "U component" },
405 { CKMODE_V, "V component" },
406 { CKMODE_RGB, "RGB" },
407 { CKMODE_R, "R component" },
408 { CKMODE_G, "G component" },
409 { CKMODE_B, "B component" },
410};
411
412static int armada_overlay_create_properties(struct drm_device *dev)
413{
414 struct armada_private *priv = dev->dev_private;
415
416 if (priv->colorkey_prop)
417 return 0;
418
419 priv->colorkey_prop = drm_property_create_range(dev, 0,
420 "colorkey", 0, 0xffffff);
421 priv->colorkey_min_prop = drm_property_create_range(dev, 0,
422 "colorkey_min", 0, 0xffffff);
423 priv->colorkey_max_prop = drm_property_create_range(dev, 0,
424 "colorkey_max", 0, 0xffffff);
425 priv->colorkey_val_prop = drm_property_create_range(dev, 0,
426 "colorkey_val", 0, 0xffffff);
427 priv->colorkey_alpha_prop = drm_property_create_range(dev, 0,
428 "colorkey_alpha", 0, 0xffffff);
429 priv->colorkey_mode_prop = drm_property_create_enum(dev, 0,
430 "colorkey_mode",
431 armada_drm_colorkey_enum_list,
432 ARRAY_SIZE(armada_drm_colorkey_enum_list));
433 priv->brightness_prop = drm_property_create_range(dev, 0,
434 "brightness", 0, 256 + 255);
435 priv->contrast_prop = drm_property_create_range(dev, 0,
436 "contrast", 0, 0x7fff);
437 priv->saturation_prop = drm_property_create_range(dev, 0,
438 "saturation", 0, 0x7fff);
439
440 if (!priv->colorkey_prop)
441 return -ENOMEM;
442
443 return 0;
444}
445
446int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
447{
448 struct armada_private *priv = dev->dev_private;
449 struct drm_mode_object *mobj;
Russell King28a2aeb2015-07-15 18:11:23 +0100450 struct armada_ovl_plane *dplane;
Russell King96f60e32012-08-15 13:59:49 +0100451 int ret;
452
453 ret = armada_overlay_create_properties(dev);
454 if (ret)
455 return ret;
456
457 dplane = kzalloc(sizeof(*dplane), GFP_KERNEL);
458 if (!dplane)
459 return -ENOMEM;
460
Russell King96f60e32012-08-15 13:59:49 +0100461 init_waitqueue_head(&dplane->vbl.wait);
Russell King28a2aeb2015-07-15 18:11:23 +0100462 armada_drm_vbl_event_init(&dplane->vbl.update, armada_ovl_plane_vbl,
Russell King96f60e32012-08-15 13:59:49 +0100463 dplane);
464
Russell King561f60b2015-07-15 18:11:24 +0100465 ret = drm_universal_plane_init(dev, &dplane->base.base, crtcs,
Russell Kingd563c242015-07-15 18:11:24 +0100466 &armada_ovl_plane_funcs,
467 armada_ovl_formats,
468 ARRAY_SIZE(armada_ovl_formats),
469 DRM_PLANE_TYPE_OVERLAY);
Russell King28a2aeb2015-07-15 18:11:23 +0100470 if (ret) {
471 kfree(dplane);
472 return ret;
473 }
Russell King96f60e32012-08-15 13:59:49 +0100474
475 dplane->prop.colorkey_yr = 0xfefefe00;
476 dplane->prop.colorkey_ug = 0x01010100;
477 dplane->prop.colorkey_vb = 0x01010100;
478 dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB);
479 dplane->prop.brightness = 0;
480 dplane->prop.contrast = 0x4000;
481 dplane->prop.saturation = 0x4000;
482
Russell King561f60b2015-07-15 18:11:24 +0100483 mobj = &dplane->base.base.base;
Russell King96f60e32012-08-15 13:59:49 +0100484 drm_object_attach_property(mobj, priv->colorkey_prop,
485 0x0101fe);
486 drm_object_attach_property(mobj, priv->colorkey_min_prop,
487 0x0101fe);
488 drm_object_attach_property(mobj, priv->colorkey_max_prop,
489 0x0101fe);
490 drm_object_attach_property(mobj, priv->colorkey_val_prop,
491 0x0101fe);
492 drm_object_attach_property(mobj, priv->colorkey_alpha_prop,
493 0x000000);
494 drm_object_attach_property(mobj, priv->colorkey_mode_prop,
495 CKMODE_RGB);
496 drm_object_attach_property(mobj, priv->brightness_prop, 256);
497 drm_object_attach_property(mobj, priv->contrast_prop,
498 dplane->prop.contrast);
499 drm_object_attach_property(mobj, priv->saturation_prop,
500 dplane->prop.saturation);
501
502 return 0;
503}