blob: b54fd8cbd3a6b59ab4dbced5307eae0022ce2d4a [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"
Russell Kingc8a220c2016-05-17 13:51:08 +010018#include "armada_trace.h"
Russell King96f60e32012-08-15 13:59:49 +010019
Russell King28a2aeb2015-07-15 18:11:23 +010020struct armada_ovl_plane_properties {
Russell King96f60e32012-08-15 13:59:49 +010021 uint32_t colorkey_yr;
22 uint32_t colorkey_ug;
23 uint32_t colorkey_vb;
24#define K2R(val) (((val) >> 0) & 0xff)
25#define K2G(val) (((val) >> 8) & 0xff)
26#define K2B(val) (((val) >> 16) & 0xff)
27 int16_t brightness;
28 uint16_t contrast;
29 uint16_t saturation;
30 uint32_t colorkey_mode;
31};
32
Russell King28a2aeb2015-07-15 18:11:23 +010033struct armada_ovl_plane {
Russell King561f60b2015-07-15 18:11:24 +010034 struct armada_plane base;
Russell King96f60e32012-08-15 13:59:49 +010035 struct drm_framebuffer *old_fb;
Russell King96f60e32012-08-15 13:59:49 +010036 struct {
Russell King4a8506d2015-08-07 09:33:05 +010037 struct armada_plane_work work;
Russell King96f60e32012-08-15 13:59:49 +010038 struct armada_regs regs[13];
Russell King96f60e32012-08-15 13:59:49 +010039 } vbl;
Russell King28a2aeb2015-07-15 18:11:23 +010040 struct armada_ovl_plane_properties prop;
Russell King96f60e32012-08-15 13:59:49 +010041};
Russell King561f60b2015-07-15 18:11:24 +010042#define drm_to_armada_ovl_plane(p) \
43 container_of(p, struct armada_ovl_plane, base.base)
Russell King96f60e32012-08-15 13:59:49 +010044
45
46static void
Russell King28a2aeb2015-07-15 18:11:23 +010047armada_ovl_update_attr(struct armada_ovl_plane_properties *prop,
Russell King96f60e32012-08-15 13:59:49 +010048 struct armada_crtc *dcrtc)
49{
50 writel_relaxed(prop->colorkey_yr, dcrtc->base + LCD_SPU_COLORKEY_Y);
51 writel_relaxed(prop->colorkey_ug, dcrtc->base + LCD_SPU_COLORKEY_U);
52 writel_relaxed(prop->colorkey_vb, dcrtc->base + LCD_SPU_COLORKEY_V);
53
54 writel_relaxed(prop->brightness << 16 | prop->contrast,
55 dcrtc->base + LCD_SPU_CONTRAST);
56 /* Docs say 15:0, but it seems to actually be 31:16 on Armada 510 */
57 writel_relaxed(prop->saturation << 16,
58 dcrtc->base + LCD_SPU_SATURATION);
59 writel_relaxed(0x00002000, dcrtc->base + LCD_SPU_CBSH_HUE);
60
61 spin_lock_irq(&dcrtc->irq_lock);
62 armada_updatel(prop->colorkey_mode | CFG_ALPHAM_GRA,
63 CFG_CKMODE_MASK | CFG_ALPHAM_MASK | CFG_ALPHA_MASK,
64 dcrtc->base + LCD_SPU_DMA_CTRL1);
65
66 armada_updatel(ADV_GRACOLORKEY, 0, dcrtc->base + LCD_SPU_ADV_REG);
67 spin_unlock_irq(&dcrtc->irq_lock);
68}
69
Russell Kingfecfdb22015-07-15 18:11:24 +010070static void armada_ovl_retire_fb(struct armada_ovl_plane *dplane,
71 struct drm_framebuffer *fb)
72{
73 struct drm_framebuffer *old_fb;
74
Russell King66377ef2015-07-15 18:11:24 +010075 old_fb = xchg(&dplane->old_fb, fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010076
77 if (old_fb)
Russell King561f60b2015-07-15 18:11:24 +010078 armada_drm_queue_unref_work(dplane->base.base.dev, old_fb);
Russell Kingfecfdb22015-07-15 18:11:24 +010079}
80
Russell King96f60e32012-08-15 13:59:49 +010081/* === Plane support === */
Russell King4a8506d2015-08-07 09:33:05 +010082static void armada_ovl_plane_work(struct armada_crtc *dcrtc,
83 struct armada_plane *plane, struct armada_plane_work *work)
Russell King96f60e32012-08-15 13:59:49 +010084{
Russell King4a8506d2015-08-07 09:33:05 +010085 struct armada_ovl_plane *dplane = container_of(plane, struct armada_ovl_plane, base);
Russell King96f60e32012-08-15 13:59:49 +010086
Russell Kingc8a220c2016-05-17 13:51:08 +010087 trace_armada_ovl_plane_work(&dcrtc->crtc, &plane->base);
88
Russell King96f60e32012-08-15 13:59:49 +010089 armada_drm_crtc_update_regs(dcrtc, dplane->vbl.regs);
Russell Kingfecfdb22015-07-15 18:11:24 +010090 armada_ovl_retire_fb(dplane, NULL);
Russell King96f60e32012-08-15 13:59:49 +010091}
92
Russell King96f60e32012-08-15 13:59:49 +010093static int
Russell King28a2aeb2015-07-15 18:11:23 +010094armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
Russell King96f60e32012-08-15 13:59:49 +010095 struct drm_framebuffer *fb,
96 int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010097 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h,
98 struct drm_modeset_acquire_ctx *ctx)
Russell King96f60e32012-08-15 13:59:49 +010099{
Russell King28a2aeb2015-07-15 18:11:23 +0100100 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100101 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King98fb74f2015-06-15 10:17:57 +0100102 struct drm_rect src = {
103 .x1 = src_x,
104 .y1 = src_y,
105 .x2 = src_x + src_w,
106 .y2 = src_y + src_h,
107 };
108 struct drm_rect dest = {
109 .x1 = crtc_x,
110 .y1 = crtc_y,
111 .x2 = crtc_x + crtc_w,
112 .y2 = crtc_y + crtc_h,
113 };
114 const struct drm_rect clip = {
115 .x2 = crtc->mode.hdisplay,
116 .y2 = crtc->mode.vdisplay,
117 };
Russell King96f60e32012-08-15 13:59:49 +0100118 uint32_t val, ctrl0;
119 unsigned idx = 0;
Russell King98fb74f2015-06-15 10:17:57 +0100120 bool visible;
Russell King96f60e32012-08-15 13:59:49 +0100121 int ret;
122
Russell Kingc8a220c2016-05-17 13:51:08 +0100123 trace_armada_ovl_plane_update(plane, crtc, fb,
124 crtc_x, crtc_y, crtc_w, crtc_h,
125 src_x, src_y, src_w, src_h);
126
Russell King98fb74f2015-06-15 10:17:57 +0100127 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip,
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +0300128 DRM_ROTATE_0,
Russell King98fb74f2015-06-15 10:17:57 +0100129 0, INT_MAX, true, false, &visible);
130 if (ret)
131 return ret;
132
Russell King96f60e32012-08-15 13:59:49 +0100133 ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) |
134 CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) |
135 CFG_CBSH_ENA | CFG_DMA_HSMOOTH | CFG_DMA_ENA;
136
137 /* Does the position/size result in nothing to display? */
Russell King98fb74f2015-06-15 10:17:57 +0100138 if (!visible)
Russell King96f60e32012-08-15 13:59:49 +0100139 ctrl0 &= ~CFG_DMA_ENA;
Russell King96f60e32012-08-15 13:59:49 +0100140
141 if (!dcrtc->plane) {
142 dcrtc->plane = plane;
143 armada_ovl_update_attr(&dplane->prop, dcrtc);
144 }
145
146 /* FIXME: overlay on an interlaced display */
147 /* Just updating the position/size? */
Russell King8be523d2016-08-16 22:09:08 +0100148 if (plane->fb == fb && dplane->base.state.ctrl0 == ctrl0) {
Russell King98fb74f2015-06-15 10:17:57 +0100149 val = (drm_rect_height(&src) & 0xffff0000) |
150 drm_rect_width(&src) >> 16;
Russell King8be523d2016-08-16 22:09:08 +0100151 dplane->base.state.src_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100152 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100153
154 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King8be523d2016-08-16 22:09:08 +0100155 dplane->base.state.dst_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100156 writel_relaxed(val, dcrtc->base + LCD_SPU_DZM_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100157
158 val = dest.y1 << 16 | dest.x1;
Russell King8be523d2016-08-16 22:09:08 +0100159 dplane->base.state.dst_yx = val;
Russell King96f60e32012-08-15 13:59:49 +0100160 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_OVSA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100161
Russell King96f60e32012-08-15 13:59:49 +0100162 return 0;
Russell King8be523d2016-08-16 22:09:08 +0100163 } else if (~dplane->base.state.ctrl0 & ctrl0 & CFG_DMA_ENA) {
Russell King96f60e32012-08-15 13:59:49 +0100164 /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */
165 armada_updatel(0, CFG_PDWN16x66 | CFG_PDWN32x66,
166 dcrtc->base + LCD_SPU_SRAM_PARA1);
167 }
168
Russell King4a8506d2015-08-07 09:33:05 +0100169 if (armada_drm_plane_work_wait(&dplane->base, HZ / 25) == 0)
170 armada_drm_plane_work_cancel(dcrtc, &dplane->base);
Russell King96f60e32012-08-15 13:59:49 +0100171
172 if (plane->fb != fb) {
Russell Kingf0b24872016-08-16 22:09:11 +0100173 u32 addrs[3], pixel_format;
174 int num_planes, hsub;
Russell King96f60e32012-08-15 13:59:49 +0100175
176 /*
177 * Take a reference on the new framebuffer - we want to
178 * hold on to it while the hardware is displaying it.
179 */
180 drm_framebuffer_reference(fb);
181
Russell Kingfecfdb22015-07-15 18:11:24 +0100182 if (plane->fb)
183 armada_ovl_retire_fb(dplane, plane->fb);
Russell King96f60e32012-08-15 13:59:49 +0100184
Russell King98fb74f2015-06-15 10:17:57 +0100185 src_y = src.y1 >> 16;
186 src_x = src.x1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100187
Russell Kingf0b24872016-08-16 22:09:11 +0100188 armada_drm_plane_calc_addrs(addrs, fb, src_x, src_y);
189
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200190 pixel_format = fb->format->format;
Russell King73068ce2015-06-15 10:18:02 +0100191 hsub = drm_format_horz_chroma_subsampling(pixel_format);
Ville Syrjäläbcb0b462016-12-14 23:30:22 +0200192 num_planes = fb->format->num_planes;
Russell King73068ce2015-06-15 10:18:02 +0100193
194 /*
195 * Annoyingly, shifting a YUYV-format image by one pixel
196 * causes the U/V planes to toggle. Toggle the UV swap.
197 * (Unfortunately, this causes momentary colour flickering.)
198 */
199 if (src_x & (hsub - 1) && num_planes == 1)
200 ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV);
201
Russell Kingf0b24872016-08-16 22:09:11 +0100202 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100203 LCD_SPU_DMA_START_ADDR_Y0);
Russell Kingf0b24872016-08-16 22:09:11 +0100204 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100205 LCD_SPU_DMA_START_ADDR_U0);
Russell Kingf0b24872016-08-16 22:09:11 +0100206 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100207 LCD_SPU_DMA_START_ADDR_V0);
Russell Kingf0b24872016-08-16 22:09:11 +0100208 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100209 LCD_SPU_DMA_START_ADDR_Y1);
Russell Kingf0b24872016-08-16 22:09:11 +0100210 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100211 LCD_SPU_DMA_START_ADDR_U1);
Russell Kingf0b24872016-08-16 22:09:11 +0100212 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100213 LCD_SPU_DMA_START_ADDR_V1);
214
215 val = fb->pitches[0] << 16 | fb->pitches[0];
216 armada_reg_queue_set(dplane->vbl.regs, idx, val,
217 LCD_SPU_DMA_PITCH_YC);
218 val = fb->pitches[1] << 16 | fb->pitches[2];
219 armada_reg_queue_set(dplane->vbl.regs, idx, val,
220 LCD_SPU_DMA_PITCH_UV);
221 }
222
Russell King98fb74f2015-06-15 10:17:57 +0100223 val = (drm_rect_height(&src) & 0xffff0000) | drm_rect_width(&src) >> 16;
Russell King8be523d2016-08-16 22:09:08 +0100224 if (dplane->base.state.src_hw != val) {
225 dplane->base.state.src_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100226 armada_reg_queue_set(dplane->vbl.regs, idx, val,
227 LCD_SPU_DMA_HPXL_VLN);
228 }
Russell King98fb74f2015-06-15 10:17:57 +0100229
230 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King8be523d2016-08-16 22:09:08 +0100231 if (dplane->base.state.dst_hw != val) {
232 dplane->base.state.dst_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100233 armada_reg_queue_set(dplane->vbl.regs, idx, val,
234 LCD_SPU_DZM_HPXL_VLN);
235 }
Russell King98fb74f2015-06-15 10:17:57 +0100236
237 val = dest.y1 << 16 | dest.x1;
Russell King8be523d2016-08-16 22:09:08 +0100238 if (dplane->base.state.dst_yx != val) {
239 dplane->base.state.dst_yx = val;
Russell King96f60e32012-08-15 13:59:49 +0100240 armada_reg_queue_set(dplane->vbl.regs, idx, val,
241 LCD_SPU_DMA_OVSA_HPXL_VLN);
242 }
Russell King98fb74f2015-06-15 10:17:57 +0100243
Russell King8be523d2016-08-16 22:09:08 +0100244 if (dplane->base.state.ctrl0 != ctrl0) {
245 dplane->base.state.ctrl0 = ctrl0;
Russell King96f60e32012-08-15 13:59:49 +0100246 armada_reg_queue_mod(dplane->vbl.regs, idx, ctrl0,
247 CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE |
248 CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE |
249 CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU |
250 CFG_YUV2RGB) | CFG_DMA_ENA,
251 LCD_SPU_DMA_CTRL0);
252 }
253 if (idx) {
254 armada_reg_queue_end(dplane->vbl.regs, idx);
Russell King4a8506d2015-08-07 09:33:05 +0100255 armada_drm_plane_work_queue(dcrtc, &dplane->base,
256 &dplane->vbl.work);
Russell King96f60e32012-08-15 13:59:49 +0100257 }
258 return 0;
259}
260
Russell King28a2aeb2015-07-15 18:11:23 +0100261static int armada_ovl_plane_disable(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100262{
Russell King28a2aeb2015-07-15 18:11:23 +0100263 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100264 struct drm_framebuffer *fb;
265 struct armada_crtc *dcrtc;
266
Russell King561f60b2015-07-15 18:11:24 +0100267 if (!dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100268 return 0;
269
Russell King561f60b2015-07-15 18:11:24 +0100270 dcrtc = drm_to_armada_crtc(dplane->base.base.crtc);
Russell King96f60e32012-08-15 13:59:49 +0100271
Russell King4a8506d2015-08-07 09:33:05 +0100272 armada_drm_plane_work_cancel(dcrtc, &dplane->base);
Russell King58326802015-07-15 18:11:25 +0100273 armada_drm_crtc_plane_disable(dcrtc, plane);
Russell King96f60e32012-08-15 13:59:49 +0100274
Russell King4a8506d2015-08-07 09:33:05 +0100275 dcrtc->plane = NULL;
Russell King8be523d2016-08-16 22:09:08 +0100276 dplane->base.state.ctrl0 = 0;
Russell King4a8506d2015-08-07 09:33:05 +0100277
Russell King66377ef2015-07-15 18:11:24 +0100278 fb = xchg(&dplane->old_fb, NULL);
Russell King96f60e32012-08-15 13:59:49 +0100279 if (fb)
280 drm_framebuffer_unreference(fb);
281
282 return 0;
283}
284
Russell King28a2aeb2015-07-15 18:11:23 +0100285static void armada_ovl_plane_destroy(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100286{
Russell King28a2aeb2015-07-15 18:11:23 +0100287 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King41dbb2d2015-06-15 10:13:30 +0100288
289 drm_plane_cleanup(plane);
290
291 kfree(dplane);
Russell King96f60e32012-08-15 13:59:49 +0100292}
293
Russell King28a2aeb2015-07-15 18:11:23 +0100294static int armada_ovl_plane_set_property(struct drm_plane *plane,
Russell King96f60e32012-08-15 13:59:49 +0100295 struct drm_property *property, uint64_t val)
296{
297 struct armada_private *priv = plane->dev->dev_private;
Russell King28a2aeb2015-07-15 18:11:23 +0100298 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100299 bool update_attr = false;
300
301 if (property == priv->colorkey_prop) {
302#define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8)
303 dplane->prop.colorkey_yr = CCC(K2R(val));
304 dplane->prop.colorkey_ug = CCC(K2G(val));
305 dplane->prop.colorkey_vb = CCC(K2B(val));
306#undef CCC
307 update_attr = true;
308 } else if (property == priv->colorkey_min_prop) {
309 dplane->prop.colorkey_yr &= ~0x00ff0000;
310 dplane->prop.colorkey_yr |= K2R(val) << 16;
311 dplane->prop.colorkey_ug &= ~0x00ff0000;
312 dplane->prop.colorkey_ug |= K2G(val) << 16;
313 dplane->prop.colorkey_vb &= ~0x00ff0000;
314 dplane->prop.colorkey_vb |= K2B(val) << 16;
315 update_attr = true;
316 } else if (property == priv->colorkey_max_prop) {
317 dplane->prop.colorkey_yr &= ~0xff000000;
318 dplane->prop.colorkey_yr |= K2R(val) << 24;
319 dplane->prop.colorkey_ug &= ~0xff000000;
320 dplane->prop.colorkey_ug |= K2G(val) << 24;
321 dplane->prop.colorkey_vb &= ~0xff000000;
322 dplane->prop.colorkey_vb |= K2B(val) << 24;
323 update_attr = true;
324 } else if (property == priv->colorkey_val_prop) {
325 dplane->prop.colorkey_yr &= ~0x0000ff00;
326 dplane->prop.colorkey_yr |= K2R(val) << 8;
327 dplane->prop.colorkey_ug &= ~0x0000ff00;
328 dplane->prop.colorkey_ug |= K2G(val) << 8;
329 dplane->prop.colorkey_vb &= ~0x0000ff00;
330 dplane->prop.colorkey_vb |= K2B(val) << 8;
331 update_attr = true;
332 } else if (property == priv->colorkey_alpha_prop) {
333 dplane->prop.colorkey_yr &= ~0x000000ff;
334 dplane->prop.colorkey_yr |= K2R(val);
335 dplane->prop.colorkey_ug &= ~0x000000ff;
336 dplane->prop.colorkey_ug |= K2G(val);
337 dplane->prop.colorkey_vb &= ~0x000000ff;
338 dplane->prop.colorkey_vb |= K2B(val);
339 update_attr = true;
340 } else if (property == priv->colorkey_mode_prop) {
341 dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK;
342 dplane->prop.colorkey_mode |= CFG_CKMODE(val);
343 update_attr = true;
344 } else if (property == priv->brightness_prop) {
345 dplane->prop.brightness = val - 256;
346 update_attr = true;
347 } else if (property == priv->contrast_prop) {
348 dplane->prop.contrast = val;
349 update_attr = true;
350 } else if (property == priv->saturation_prop) {
351 dplane->prop.saturation = val;
352 update_attr = true;
353 }
354
Russell King561f60b2015-07-15 18:11:24 +0100355 if (update_attr && dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100356 armada_ovl_update_attr(&dplane->prop,
Russell King561f60b2015-07-15 18:11:24 +0100357 drm_to_armada_crtc(dplane->base.base.crtc));
Russell King96f60e32012-08-15 13:59:49 +0100358
359 return 0;
360}
361
Russell King28a2aeb2015-07-15 18:11:23 +0100362static const struct drm_plane_funcs armada_ovl_plane_funcs = {
363 .update_plane = armada_ovl_plane_update,
364 .disable_plane = armada_ovl_plane_disable,
365 .destroy = armada_ovl_plane_destroy,
366 .set_property = armada_ovl_plane_set_property,
Russell King96f60e32012-08-15 13:59:49 +0100367};
368
Russell King28a2aeb2015-07-15 18:11:23 +0100369static const uint32_t armada_ovl_formats[] = {
Russell King96f60e32012-08-15 13:59:49 +0100370 DRM_FORMAT_UYVY,
371 DRM_FORMAT_YUYV,
372 DRM_FORMAT_YUV420,
373 DRM_FORMAT_YVU420,
374 DRM_FORMAT_YUV422,
375 DRM_FORMAT_YVU422,
376 DRM_FORMAT_VYUY,
377 DRM_FORMAT_YVYU,
378 DRM_FORMAT_ARGB8888,
379 DRM_FORMAT_ABGR8888,
380 DRM_FORMAT_XRGB8888,
381 DRM_FORMAT_XBGR8888,
382 DRM_FORMAT_RGB888,
383 DRM_FORMAT_BGR888,
384 DRM_FORMAT_ARGB1555,
385 DRM_FORMAT_ABGR1555,
386 DRM_FORMAT_RGB565,
387 DRM_FORMAT_BGR565,
388};
389
390static struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = {
391 { CKMODE_DISABLE, "disabled" },
392 { CKMODE_Y, "Y component" },
393 { CKMODE_U, "U component" },
394 { CKMODE_V, "V component" },
395 { CKMODE_RGB, "RGB" },
396 { CKMODE_R, "R component" },
397 { CKMODE_G, "G component" },
398 { CKMODE_B, "B component" },
399};
400
401static int armada_overlay_create_properties(struct drm_device *dev)
402{
403 struct armada_private *priv = dev->dev_private;
404
405 if (priv->colorkey_prop)
406 return 0;
407
408 priv->colorkey_prop = drm_property_create_range(dev, 0,
409 "colorkey", 0, 0xffffff);
410 priv->colorkey_min_prop = drm_property_create_range(dev, 0,
411 "colorkey_min", 0, 0xffffff);
412 priv->colorkey_max_prop = drm_property_create_range(dev, 0,
413 "colorkey_max", 0, 0xffffff);
414 priv->colorkey_val_prop = drm_property_create_range(dev, 0,
415 "colorkey_val", 0, 0xffffff);
416 priv->colorkey_alpha_prop = drm_property_create_range(dev, 0,
417 "colorkey_alpha", 0, 0xffffff);
418 priv->colorkey_mode_prop = drm_property_create_enum(dev, 0,
419 "colorkey_mode",
420 armada_drm_colorkey_enum_list,
421 ARRAY_SIZE(armada_drm_colorkey_enum_list));
422 priv->brightness_prop = drm_property_create_range(dev, 0,
423 "brightness", 0, 256 + 255);
424 priv->contrast_prop = drm_property_create_range(dev, 0,
425 "contrast", 0, 0x7fff);
426 priv->saturation_prop = drm_property_create_range(dev, 0,
427 "saturation", 0, 0x7fff);
428
429 if (!priv->colorkey_prop)
430 return -ENOMEM;
431
432 return 0;
433}
434
435int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
436{
437 struct armada_private *priv = dev->dev_private;
438 struct drm_mode_object *mobj;
Russell King28a2aeb2015-07-15 18:11:23 +0100439 struct armada_ovl_plane *dplane;
Russell King96f60e32012-08-15 13:59:49 +0100440 int ret;
441
442 ret = armada_overlay_create_properties(dev);
443 if (ret)
444 return ret;
445
446 dplane = kzalloc(sizeof(*dplane), GFP_KERNEL);
447 if (!dplane)
448 return -ENOMEM;
449
Russell King5740d272015-07-15 18:11:25 +0100450 ret = armada_drm_plane_init(&dplane->base);
451 if (ret) {
452 kfree(dplane);
453 return ret;
454 }
455
Russell King4a8506d2015-08-07 09:33:05 +0100456 dplane->vbl.work.fn = armada_ovl_plane_work;
Russell King96f60e32012-08-15 13:59:49 +0100457
Russell King561f60b2015-07-15 18:11:24 +0100458 ret = drm_universal_plane_init(dev, &dplane->base.base, crtcs,
Russell Kingd563c242015-07-15 18:11:24 +0100459 &armada_ovl_plane_funcs,
460 armada_ovl_formats,
461 ARRAY_SIZE(armada_ovl_formats),
Ville Syrjäläb0b3b792015-12-09 16:19:55 +0200462 DRM_PLANE_TYPE_OVERLAY, NULL);
Russell King28a2aeb2015-07-15 18:11:23 +0100463 if (ret) {
464 kfree(dplane);
465 return ret;
466 }
Russell King96f60e32012-08-15 13:59:49 +0100467
468 dplane->prop.colorkey_yr = 0xfefefe00;
469 dplane->prop.colorkey_ug = 0x01010100;
470 dplane->prop.colorkey_vb = 0x01010100;
471 dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB);
472 dplane->prop.brightness = 0;
473 dplane->prop.contrast = 0x4000;
474 dplane->prop.saturation = 0x4000;
475
Russell King561f60b2015-07-15 18:11:24 +0100476 mobj = &dplane->base.base.base;
Russell King96f60e32012-08-15 13:59:49 +0100477 drm_object_attach_property(mobj, priv->colorkey_prop,
478 0x0101fe);
479 drm_object_attach_property(mobj, priv->colorkey_min_prop,
480 0x0101fe);
481 drm_object_attach_property(mobj, priv->colorkey_max_prop,
482 0x0101fe);
483 drm_object_attach_property(mobj, priv->colorkey_val_prop,
484 0x0101fe);
485 drm_object_attach_property(mobj, priv->colorkey_alpha_prop,
486 0x000000);
487 drm_object_attach_property(mobj, priv->colorkey_mode_prop,
488 CKMODE_RGB);
489 drm_object_attach_property(mobj, priv->brightness_prop, 256);
490 drm_object_attach_property(mobj, priv->contrast_prop,
491 dplane->prop.contrast);
492 drm_object_attach_property(mobj, priv->saturation_prop,
493 dplane->prop.saturation);
494
495 return 0;
496}