blob: 9a5bab765085293d351a31b7e1e89681cddf4aaa [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];
Russell King96f60e32012-08-15 13:59:49 +010042 } vbl;
Russell King28a2aeb2015-07-15 18:11:23 +010043 struct armada_ovl_plane_properties prop;
Russell King96f60e32012-08-15 13:59:49 +010044};
Russell King561f60b2015-07-15 18:11:24 +010045#define drm_to_armada_ovl_plane(p) \
46 container_of(p, struct armada_ovl_plane, base.base)
Russell King96f60e32012-08-15 13:59:49 +010047
48
49static void
Russell King28a2aeb2015-07-15 18:11:23 +010050armada_ovl_update_attr(struct armada_ovl_plane_properties *prop,
Russell King96f60e32012-08-15 13:59:49 +010051 struct armada_crtc *dcrtc)
52{
53 writel_relaxed(prop->colorkey_yr, dcrtc->base + LCD_SPU_COLORKEY_Y);
54 writel_relaxed(prop->colorkey_ug, dcrtc->base + LCD_SPU_COLORKEY_U);
55 writel_relaxed(prop->colorkey_vb, dcrtc->base + LCD_SPU_COLORKEY_V);
56
57 writel_relaxed(prop->brightness << 16 | prop->contrast,
58 dcrtc->base + LCD_SPU_CONTRAST);
59 /* Docs say 15:0, but it seems to actually be 31:16 on Armada 510 */
60 writel_relaxed(prop->saturation << 16,
61 dcrtc->base + LCD_SPU_SATURATION);
62 writel_relaxed(0x00002000, dcrtc->base + LCD_SPU_CBSH_HUE);
63
64 spin_lock_irq(&dcrtc->irq_lock);
65 armada_updatel(prop->colorkey_mode | CFG_ALPHAM_GRA,
66 CFG_CKMODE_MASK | CFG_ALPHAM_MASK | CFG_ALPHA_MASK,
67 dcrtc->base + LCD_SPU_DMA_CTRL1);
68
69 armada_updatel(ADV_GRACOLORKEY, 0, dcrtc->base + LCD_SPU_ADV_REG);
70 spin_unlock_irq(&dcrtc->irq_lock);
71}
72
Russell Kingfecfdb22015-07-15 18:11:24 +010073static void armada_ovl_retire_fb(struct armada_ovl_plane *dplane,
74 struct drm_framebuffer *fb)
75{
76 struct drm_framebuffer *old_fb;
77
Russell King66377ef2015-07-15 18:11:24 +010078 old_fb = xchg(&dplane->old_fb, fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010079
80 if (old_fb)
Russell King561f60b2015-07-15 18:11:24 +010081 armada_drm_queue_unref_work(dplane->base.base.dev, old_fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010082}
83
Russell King96f60e32012-08-15 13:59:49 +010084/* === Plane support === */
Russell King28a2aeb2015-07-15 18:11:23 +010085static void armada_ovl_plane_vbl(struct armada_crtc *dcrtc, void *data)
Russell King96f60e32012-08-15 13:59:49 +010086{
Russell King28a2aeb2015-07-15 18:11:23 +010087 struct armada_ovl_plane *dplane = data;
Russell King96f60e32012-08-15 13:59:49 +010088
89 armada_drm_crtc_update_regs(dcrtc, dplane->vbl.regs);
Russell Kingfecfdb22015-07-15 18:11:24 +010090 armada_ovl_retire_fb(dplane, NULL);
Russell King070f3f62015-06-15 10:13:29 +010091
Russell King5740d272015-07-15 18:11:25 +010092 wake_up(&dplane->base.frame_wait);
Russell King96f60e32012-08-15 13:59:49 +010093}
94
Russell King96f60e32012-08-15 13:59:49 +010095static int
Russell King28a2aeb2015-07-15 18:11:23 +010096armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
Russell King96f60e32012-08-15 13:59:49 +010097 struct drm_framebuffer *fb,
98 int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
99 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
100{
Russell King28a2aeb2015-07-15 18:11:23 +0100101 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100102 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King98fb74f2015-06-15 10:17:57 +0100103 struct drm_rect src = {
104 .x1 = src_x,
105 .y1 = src_y,
106 .x2 = src_x + src_w,
107 .y2 = src_y + src_h,
108 };
109 struct drm_rect dest = {
110 .x1 = crtc_x,
111 .y1 = crtc_y,
112 .x2 = crtc_x + crtc_w,
113 .y2 = crtc_y + crtc_h,
114 };
115 const struct drm_rect clip = {
116 .x2 = crtc->mode.hdisplay,
117 .y2 = crtc->mode.vdisplay,
118 };
Russell King96f60e32012-08-15 13:59:49 +0100119 uint32_t val, ctrl0;
120 unsigned idx = 0;
Russell King98fb74f2015-06-15 10:17:57 +0100121 bool visible;
Russell King96f60e32012-08-15 13:59:49 +0100122 int ret;
123
Russell King98fb74f2015-06-15 10:17:57 +0100124 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip,
125 0, INT_MAX, true, false, &visible);
126 if (ret)
127 return ret;
128
Russell King96f60e32012-08-15 13:59:49 +0100129 ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) |
130 CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) |
131 CFG_CBSH_ENA | CFG_DMA_HSMOOTH | CFG_DMA_ENA;
132
133 /* Does the position/size result in nothing to display? */
Russell King98fb74f2015-06-15 10:17:57 +0100134 if (!visible)
Russell King96f60e32012-08-15 13:59:49 +0100135 ctrl0 &= ~CFG_DMA_ENA;
Russell King96f60e32012-08-15 13:59:49 +0100136
137 if (!dcrtc->plane) {
138 dcrtc->plane = plane;
139 armada_ovl_update_attr(&dplane->prop, dcrtc);
140 }
141
142 /* FIXME: overlay on an interlaced display */
143 /* Just updating the position/size? */
144 if (plane->fb == fb && dplane->ctrl0 == ctrl0) {
Russell King98fb74f2015-06-15 10:17:57 +0100145 val = (drm_rect_height(&src) & 0xffff0000) |
146 drm_rect_width(&src) >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100147 dplane->src_hw = val;
148 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100149
150 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King96f60e32012-08-15 13:59:49 +0100151 dplane->dst_hw = val;
152 writel_relaxed(val, dcrtc->base + LCD_SPU_DZM_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100153
154 val = dest.y1 << 16 | dest.x1;
Russell King96f60e32012-08-15 13:59:49 +0100155 dplane->dst_yx = val;
156 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_OVSA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100157
Russell King96f60e32012-08-15 13:59:49 +0100158 return 0;
159 } else if (~dplane->ctrl0 & ctrl0 & CFG_DMA_ENA) {
160 /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */
161 armada_updatel(0, CFG_PDWN16x66 | CFG_PDWN32x66,
162 dcrtc->base + LCD_SPU_SRAM_PARA1);
163 }
164
Russell King5740d272015-07-15 18:11:25 +0100165 wait_event_timeout(dplane->base.frame_wait,
Russell King070f3f62015-06-15 10:13:29 +0100166 list_empty(&dplane->vbl.update.node),
167 HZ/25);
Russell King96f60e32012-08-15 13:59:49 +0100168
169 if (plane->fb != fb) {
170 struct armada_gem_object *obj = drm_fb_obj(fb);
Russell King73068ce2015-06-15 10:18:02 +0100171 uint32_t addr[3], pixel_format;
172 int i, num_planes, hsub;
Russell King96f60e32012-08-15 13:59:49 +0100173
174 /*
175 * Take a reference on the new framebuffer - we want to
176 * hold on to it while the hardware is displaying it.
177 */
178 drm_framebuffer_reference(fb);
179
Russell Kingfecfdb22015-07-15 18:11:24 +0100180 if (plane->fb)
181 armada_ovl_retire_fb(dplane, plane->fb);
Russell King96f60e32012-08-15 13:59:49 +0100182
Russell King98fb74f2015-06-15 10:17:57 +0100183 src_y = src.y1 >> 16;
184 src_x = src.x1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100185
Russell King73068ce2015-06-15 10:18:02 +0100186 pixel_format = fb->pixel_format;
187 hsub = drm_format_horz_chroma_subsampling(pixel_format);
188 num_planes = drm_format_num_planes(pixel_format);
189
190 /*
191 * Annoyingly, shifting a YUYV-format image by one pixel
192 * causes the U/V planes to toggle. Toggle the UV swap.
193 * (Unfortunately, this causes momentary colour flickering.)
194 */
195 if (src_x & (hsub - 1) && num_planes == 1)
196 ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV);
197
198 for (i = 0; i < num_planes; i++)
199 addr[i] = obj->dev_addr + fb->offsets[i] +
200 src_y * fb->pitches[i] +
201 src_x * drm_format_plane_cpp(pixel_format, i);
202 for (; i < ARRAY_SIZE(addr); i++)
203 addr[i] = 0;
204
205 armada_reg_queue_set(dplane->vbl.regs, idx, addr[0],
Russell King96f60e32012-08-15 13:59:49 +0100206 LCD_SPU_DMA_START_ADDR_Y0);
Russell King73068ce2015-06-15 10:18:02 +0100207 armada_reg_queue_set(dplane->vbl.regs, idx, addr[1],
Russell King96f60e32012-08-15 13:59:49 +0100208 LCD_SPU_DMA_START_ADDR_U0);
Russell King73068ce2015-06-15 10:18:02 +0100209 armada_reg_queue_set(dplane->vbl.regs, idx, addr[2],
Russell King96f60e32012-08-15 13:59:49 +0100210 LCD_SPU_DMA_START_ADDR_V0);
Russell King73068ce2015-06-15 10:18:02 +0100211 armada_reg_queue_set(dplane->vbl.regs, idx, addr[0],
Russell King96f60e32012-08-15 13:59:49 +0100212 LCD_SPU_DMA_START_ADDR_Y1);
Russell King73068ce2015-06-15 10:18:02 +0100213 armada_reg_queue_set(dplane->vbl.regs, idx, addr[1],
Russell King96f60e32012-08-15 13:59:49 +0100214 LCD_SPU_DMA_START_ADDR_U1);
Russell King73068ce2015-06-15 10:18:02 +0100215 armada_reg_queue_set(dplane->vbl.regs, idx, addr[2],
Russell King96f60e32012-08-15 13:59:49 +0100216 LCD_SPU_DMA_START_ADDR_V1);
217
218 val = fb->pitches[0] << 16 | fb->pitches[0];
219 armada_reg_queue_set(dplane->vbl.regs, idx, val,
220 LCD_SPU_DMA_PITCH_YC);
221 val = fb->pitches[1] << 16 | fb->pitches[2];
222 armada_reg_queue_set(dplane->vbl.regs, idx, val,
223 LCD_SPU_DMA_PITCH_UV);
224 }
225
Russell King98fb74f2015-06-15 10:17:57 +0100226 val = (drm_rect_height(&src) & 0xffff0000) | drm_rect_width(&src) >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100227 if (dplane->src_hw != val) {
228 dplane->src_hw = val;
229 armada_reg_queue_set(dplane->vbl.regs, idx, val,
230 LCD_SPU_DMA_HPXL_VLN);
231 }
Russell King98fb74f2015-06-15 10:17:57 +0100232
233 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King96f60e32012-08-15 13:59:49 +0100234 if (dplane->dst_hw != val) {
235 dplane->dst_hw = val;
236 armada_reg_queue_set(dplane->vbl.regs, idx, val,
237 LCD_SPU_DZM_HPXL_VLN);
238 }
Russell King98fb74f2015-06-15 10:17:57 +0100239
240 val = dest.y1 << 16 | dest.x1;
Russell King96f60e32012-08-15 13:59:49 +0100241 if (dplane->dst_yx != val) {
242 dplane->dst_yx = val;
243 armada_reg_queue_set(dplane->vbl.regs, idx, val,
244 LCD_SPU_DMA_OVSA_HPXL_VLN);
245 }
Russell King98fb74f2015-06-15 10:17:57 +0100246
Russell King96f60e32012-08-15 13:59:49 +0100247 if (dplane->ctrl0 != ctrl0) {
248 dplane->ctrl0 = ctrl0;
249 armada_reg_queue_mod(dplane->vbl.regs, idx, ctrl0,
250 CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE |
251 CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE |
252 CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU |
253 CFG_YUV2RGB) | CFG_DMA_ENA,
254 LCD_SPU_DMA_CTRL0);
255 }
256 if (idx) {
257 armada_reg_queue_end(dplane->vbl.regs, idx);
258 armada_drm_vbl_event_add(dcrtc, &dplane->vbl.update);
259 }
260 return 0;
261}
262
Russell King28a2aeb2015-07-15 18:11:23 +0100263static int armada_ovl_plane_disable(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100264{
Russell King28a2aeb2015-07-15 18:11:23 +0100265 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100266 struct drm_framebuffer *fb;
267 struct armada_crtc *dcrtc;
268
Russell King561f60b2015-07-15 18:11:24 +0100269 if (!dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100270 return 0;
271
Russell King561f60b2015-07-15 18:11:24 +0100272 dcrtc = drm_to_armada_crtc(dplane->base.base.crtc);
Russell King96f60e32012-08-15 13:59:49 +0100273 dcrtc->plane = NULL;
274
Russell King96f60e32012-08-15 13:59:49 +0100275 armada_drm_vbl_event_remove(dcrtc, &dplane->vbl.update);
Russell King96f60e32012-08-15 13:59:49 +0100276
Russell King5c8752c2015-07-15 18:11:25 +0100277 dplane->ctrl0 = 0;
278
Russell King58326802015-07-15 18:11:25 +0100279 armada_drm_crtc_plane_disable(dcrtc, plane);
Russell King96f60e32012-08-15 13:59:49 +0100280
Russell King66377ef2015-07-15 18:11:24 +0100281 fb = xchg(&dplane->old_fb, NULL);
Russell King96f60e32012-08-15 13:59:49 +0100282 if (fb)
283 drm_framebuffer_unreference(fb);
284
285 return 0;
286}
287
Russell King28a2aeb2015-07-15 18:11:23 +0100288static void armada_ovl_plane_destroy(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100289{
Russell King28a2aeb2015-07-15 18:11:23 +0100290 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King41dbb2d2015-06-15 10:13:30 +0100291
292 drm_plane_cleanup(plane);
293
294 kfree(dplane);
Russell King96f60e32012-08-15 13:59:49 +0100295}
296
Russell King28a2aeb2015-07-15 18:11:23 +0100297static int armada_ovl_plane_set_property(struct drm_plane *plane,
Russell King96f60e32012-08-15 13:59:49 +0100298 struct drm_property *property, uint64_t val)
299{
300 struct armada_private *priv = plane->dev->dev_private;
Russell King28a2aeb2015-07-15 18:11:23 +0100301 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100302 bool update_attr = false;
303
304 if (property == priv->colorkey_prop) {
305#define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8)
306 dplane->prop.colorkey_yr = CCC(K2R(val));
307 dplane->prop.colorkey_ug = CCC(K2G(val));
308 dplane->prop.colorkey_vb = CCC(K2B(val));
309#undef CCC
310 update_attr = true;
311 } else if (property == priv->colorkey_min_prop) {
312 dplane->prop.colorkey_yr &= ~0x00ff0000;
313 dplane->prop.colorkey_yr |= K2R(val) << 16;
314 dplane->prop.colorkey_ug &= ~0x00ff0000;
315 dplane->prop.colorkey_ug |= K2G(val) << 16;
316 dplane->prop.colorkey_vb &= ~0x00ff0000;
317 dplane->prop.colorkey_vb |= K2B(val) << 16;
318 update_attr = true;
319 } else if (property == priv->colorkey_max_prop) {
320 dplane->prop.colorkey_yr &= ~0xff000000;
321 dplane->prop.colorkey_yr |= K2R(val) << 24;
322 dplane->prop.colorkey_ug &= ~0xff000000;
323 dplane->prop.colorkey_ug |= K2G(val) << 24;
324 dplane->prop.colorkey_vb &= ~0xff000000;
325 dplane->prop.colorkey_vb |= K2B(val) << 24;
326 update_attr = true;
327 } else if (property == priv->colorkey_val_prop) {
328 dplane->prop.colorkey_yr &= ~0x0000ff00;
329 dplane->prop.colorkey_yr |= K2R(val) << 8;
330 dplane->prop.colorkey_ug &= ~0x0000ff00;
331 dplane->prop.colorkey_ug |= K2G(val) << 8;
332 dplane->prop.colorkey_vb &= ~0x0000ff00;
333 dplane->prop.colorkey_vb |= K2B(val) << 8;
334 update_attr = true;
335 } else if (property == priv->colorkey_alpha_prop) {
336 dplane->prop.colorkey_yr &= ~0x000000ff;
337 dplane->prop.colorkey_yr |= K2R(val);
338 dplane->prop.colorkey_ug &= ~0x000000ff;
339 dplane->prop.colorkey_ug |= K2G(val);
340 dplane->prop.colorkey_vb &= ~0x000000ff;
341 dplane->prop.colorkey_vb |= K2B(val);
342 update_attr = true;
343 } else if (property == priv->colorkey_mode_prop) {
344 dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK;
345 dplane->prop.colorkey_mode |= CFG_CKMODE(val);
346 update_attr = true;
347 } else if (property == priv->brightness_prop) {
348 dplane->prop.brightness = val - 256;
349 update_attr = true;
350 } else if (property == priv->contrast_prop) {
351 dplane->prop.contrast = val;
352 update_attr = true;
353 } else if (property == priv->saturation_prop) {
354 dplane->prop.saturation = val;
355 update_attr = true;
356 }
357
Russell King561f60b2015-07-15 18:11:24 +0100358 if (update_attr && dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100359 armada_ovl_update_attr(&dplane->prop,
Russell King561f60b2015-07-15 18:11:24 +0100360 drm_to_armada_crtc(dplane->base.base.crtc));
Russell King96f60e32012-08-15 13:59:49 +0100361
362 return 0;
363}
364
Russell King28a2aeb2015-07-15 18:11:23 +0100365static const struct drm_plane_funcs armada_ovl_plane_funcs = {
366 .update_plane = armada_ovl_plane_update,
367 .disable_plane = armada_ovl_plane_disable,
368 .destroy = armada_ovl_plane_destroy,
369 .set_property = armada_ovl_plane_set_property,
Russell King96f60e32012-08-15 13:59:49 +0100370};
371
Russell King28a2aeb2015-07-15 18:11:23 +0100372static const uint32_t armada_ovl_formats[] = {
Russell King96f60e32012-08-15 13:59:49 +0100373 DRM_FORMAT_UYVY,
374 DRM_FORMAT_YUYV,
375 DRM_FORMAT_YUV420,
376 DRM_FORMAT_YVU420,
377 DRM_FORMAT_YUV422,
378 DRM_FORMAT_YVU422,
379 DRM_FORMAT_VYUY,
380 DRM_FORMAT_YVYU,
381 DRM_FORMAT_ARGB8888,
382 DRM_FORMAT_ABGR8888,
383 DRM_FORMAT_XRGB8888,
384 DRM_FORMAT_XBGR8888,
385 DRM_FORMAT_RGB888,
386 DRM_FORMAT_BGR888,
387 DRM_FORMAT_ARGB1555,
388 DRM_FORMAT_ABGR1555,
389 DRM_FORMAT_RGB565,
390 DRM_FORMAT_BGR565,
391};
392
393static struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = {
394 { CKMODE_DISABLE, "disabled" },
395 { CKMODE_Y, "Y component" },
396 { CKMODE_U, "U component" },
397 { CKMODE_V, "V component" },
398 { CKMODE_RGB, "RGB" },
399 { CKMODE_R, "R component" },
400 { CKMODE_G, "G component" },
401 { CKMODE_B, "B component" },
402};
403
404static int armada_overlay_create_properties(struct drm_device *dev)
405{
406 struct armada_private *priv = dev->dev_private;
407
408 if (priv->colorkey_prop)
409 return 0;
410
411 priv->colorkey_prop = drm_property_create_range(dev, 0,
412 "colorkey", 0, 0xffffff);
413 priv->colorkey_min_prop = drm_property_create_range(dev, 0,
414 "colorkey_min", 0, 0xffffff);
415 priv->colorkey_max_prop = drm_property_create_range(dev, 0,
416 "colorkey_max", 0, 0xffffff);
417 priv->colorkey_val_prop = drm_property_create_range(dev, 0,
418 "colorkey_val", 0, 0xffffff);
419 priv->colorkey_alpha_prop = drm_property_create_range(dev, 0,
420 "colorkey_alpha", 0, 0xffffff);
421 priv->colorkey_mode_prop = drm_property_create_enum(dev, 0,
422 "colorkey_mode",
423 armada_drm_colorkey_enum_list,
424 ARRAY_SIZE(armada_drm_colorkey_enum_list));
425 priv->brightness_prop = drm_property_create_range(dev, 0,
426 "brightness", 0, 256 + 255);
427 priv->contrast_prop = drm_property_create_range(dev, 0,
428 "contrast", 0, 0x7fff);
429 priv->saturation_prop = drm_property_create_range(dev, 0,
430 "saturation", 0, 0x7fff);
431
432 if (!priv->colorkey_prop)
433 return -ENOMEM;
434
435 return 0;
436}
437
438int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
439{
440 struct armada_private *priv = dev->dev_private;
441 struct drm_mode_object *mobj;
Russell King28a2aeb2015-07-15 18:11:23 +0100442 struct armada_ovl_plane *dplane;
Russell King96f60e32012-08-15 13:59:49 +0100443 int ret;
444
445 ret = armada_overlay_create_properties(dev);
446 if (ret)
447 return ret;
448
449 dplane = kzalloc(sizeof(*dplane), GFP_KERNEL);
450 if (!dplane)
451 return -ENOMEM;
452
Russell King5740d272015-07-15 18:11:25 +0100453 ret = armada_drm_plane_init(&dplane->base);
454 if (ret) {
455 kfree(dplane);
456 return ret;
457 }
458
Russell King28a2aeb2015-07-15 18:11:23 +0100459 armada_drm_vbl_event_init(&dplane->vbl.update, armada_ovl_plane_vbl,
Russell King96f60e32012-08-15 13:59:49 +0100460 dplane);
461
Russell King561f60b2015-07-15 18:11:24 +0100462 ret = drm_universal_plane_init(dev, &dplane->base.base, crtcs,
Russell Kingd563c242015-07-15 18:11:24 +0100463 &armada_ovl_plane_funcs,
464 armada_ovl_formats,
465 ARRAY_SIZE(armada_ovl_formats),
466 DRM_PLANE_TYPE_OVERLAY);
Russell King28a2aeb2015-07-15 18:11:23 +0100467 if (ret) {
468 kfree(dplane);
469 return ret;
470 }
Russell King96f60e32012-08-15 13:59:49 +0100471
472 dplane->prop.colorkey_yr = 0xfefefe00;
473 dplane->prop.colorkey_ug = 0x01010100;
474 dplane->prop.colorkey_vb = 0x01010100;
475 dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB);
476 dplane->prop.brightness = 0;
477 dplane->prop.contrast = 0x4000;
478 dplane->prop.saturation = 0x4000;
479
Russell King561f60b2015-07-15 18:11:24 +0100480 mobj = &dplane->base.base.base;
Russell King96f60e32012-08-15 13:59:49 +0100481 drm_object_attach_property(mobj, priv->colorkey_prop,
482 0x0101fe);
483 drm_object_attach_property(mobj, priv->colorkey_min_prop,
484 0x0101fe);
485 drm_object_attach_property(mobj, priv->colorkey_max_prop,
486 0x0101fe);
487 drm_object_attach_property(mobj, priv->colorkey_val_prop,
488 0x0101fe);
489 drm_object_attach_property(mobj, priv->colorkey_alpha_prop,
490 0x000000);
491 drm_object_attach_property(mobj, priv->colorkey_mode_prop,
492 CKMODE_RGB);
493 drm_object_attach_property(mobj, priv->brightness_prop, 256);
494 drm_object_attach_property(mobj, priv->contrast_prop,
495 dplane->prop.contrast);
496 drm_object_attach_property(mobj, priv->saturation_prop,
497 dplane->prop.saturation);
498
499 return 0;
500}