blob: 04746ade74e643d869e87c5fbfbf602265ffd2d7 [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,
Russell Kingeaab0132017-07-07 15:55:53 +010083 struct armada_plane_work *work)
Russell King96f60e32012-08-15 13:59:49 +010084{
Russell Kingeaab0132017-07-07 15:55:53 +010085 struct armada_ovl_plane *dplane = container_of(work->plane,
86 struct armada_ovl_plane, base.base);
Russell Kinga3f6a182017-07-08 10:16:48 +010087 unsigned long flags;
Russell King96f60e32012-08-15 13:59:49 +010088
Russell Kingeaab0132017-07-07 15:55:53 +010089 trace_armada_ovl_plane_work(&dcrtc->crtc, work->plane);
Russell Kingc8a220c2016-05-17 13:51:08 +010090
Russell Kinga3f6a182017-07-08 10:16:48 +010091 spin_lock_irqsave(&dcrtc->irq_lock, flags);
Russell King96f60e32012-08-15 13:59:49 +010092 armada_drm_crtc_update_regs(dcrtc, dplane->vbl.regs);
Russell Kinga3f6a182017-07-08 10:16:48 +010093 spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
94
Russell Kingfecfdb22015-07-15 18:11:24 +010095 armada_ovl_retire_fb(dplane, NULL);
Russell King96f60e32012-08-15 13:59:49 +010096}
97
Russell King96f60e32012-08-15 13:59:49 +010098static int
Russell King28a2aeb2015-07-15 18:11:23 +010099armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
Russell King96f60e32012-08-15 13:59:49 +0100100 struct drm_framebuffer *fb,
101 int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100102 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h,
103 struct drm_modeset_acquire_ctx *ctx)
Russell King96f60e32012-08-15 13:59:49 +0100104{
Russell King28a2aeb2015-07-15 18:11:23 +0100105 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100106 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King9c898c42017-12-08 12:16:22 +0000107 const struct drm_format_info *format;
Russell King98fb74f2015-06-15 10:17:57 +0100108 struct drm_rect src = {
109 .x1 = src_x,
110 .y1 = src_y,
111 .x2 = src_x + src_w,
112 .y2 = src_y + src_h,
113 };
114 struct drm_rect dest = {
115 .x1 = crtc_x,
116 .y1 = crtc_y,
117 .x2 = crtc_x + crtc_w,
118 .y2 = crtc_y + crtc_h,
119 };
120 const struct drm_rect clip = {
121 .x2 = crtc->mode.hdisplay,
122 .y2 = crtc->mode.vdisplay,
123 };
Russell King96f60e32012-08-15 13:59:49 +0100124 uint32_t val, ctrl0;
125 unsigned idx = 0;
Russell King9c898c42017-12-08 12:16:22 +0000126 bool visible, fb_changed;
Russell King96f60e32012-08-15 13:59:49 +0100127 int ret;
128
Russell Kingc8a220c2016-05-17 13:51:08 +0100129 trace_armada_ovl_plane_update(plane, crtc, fb,
130 crtc_x, crtc_y, crtc_w, crtc_h,
131 src_x, src_y, src_w, src_h);
132
Russell King98fb74f2015-06-15 10:17:57 +0100133 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip,
Robert Fossc2c446a2017-05-19 16:50:17 -0400134 DRM_MODE_ROTATE_0,
Russell King98fb74f2015-06-15 10:17:57 +0100135 0, INT_MAX, true, false, &visible);
136 if (ret)
137 return ret;
138
Russell King96f60e32012-08-15 13:59:49 +0100139 ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) |
140 CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) |
141 CFG_CBSH_ENA | CFG_DMA_HSMOOTH | CFG_DMA_ENA;
142
143 /* Does the position/size result in nothing to display? */
Russell King98fb74f2015-06-15 10:17:57 +0100144 if (!visible)
Russell King96f60e32012-08-15 13:59:49 +0100145 ctrl0 &= ~CFG_DMA_ENA;
Russell King96f60e32012-08-15 13:59:49 +0100146
Russell King9c898c42017-12-08 12:16:22 +0000147 /*
148 * Shifting a YUV packed format image by one pixel causes the U/V
149 * planes to swap. Compensate for it by also toggling the UV swap.
150 */
151 format = fb->format;
152 if (format->num_planes == 1 && src.x1 >> 16 & (format->hsub - 1))
153 ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV);
154
155 fb_changed = plane->fb != fb ||
156 dplane->base.state.src_x != src.x1 >> 16 ||
157 dplane->base.state.src_y != src.y1 >> 16;
158
Russell King96f60e32012-08-15 13:59:49 +0100159 if (!dcrtc->plane) {
160 dcrtc->plane = plane;
161 armada_ovl_update_attr(&dplane->prop, dcrtc);
162 }
163
164 /* FIXME: overlay on an interlaced display */
165 /* Just updating the position/size? */
Russell King9c898c42017-12-08 12:16:22 +0000166 if (!fb_changed && dplane->base.state.ctrl0 == ctrl0) {
Russell King98fb74f2015-06-15 10:17:57 +0100167 val = (drm_rect_height(&src) & 0xffff0000) |
168 drm_rect_width(&src) >> 16;
Russell King8be523d2016-08-16 22:09:08 +0100169 dplane->base.state.src_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100170 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100171
172 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King8be523d2016-08-16 22:09:08 +0100173 dplane->base.state.dst_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100174 writel_relaxed(val, dcrtc->base + LCD_SPU_DZM_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100175
176 val = dest.y1 << 16 | dest.x1;
Russell King8be523d2016-08-16 22:09:08 +0100177 dplane->base.state.dst_yx = val;
Russell King96f60e32012-08-15 13:59:49 +0100178 writel_relaxed(val, dcrtc->base + LCD_SPU_DMA_OVSA_HPXL_VLN);
Russell King98fb74f2015-06-15 10:17:57 +0100179
Russell King96f60e32012-08-15 13:59:49 +0100180 return 0;
Russell King8be523d2016-08-16 22:09:08 +0100181 } else if (~dplane->base.state.ctrl0 & ctrl0 & CFG_DMA_ENA) {
Russell King96f60e32012-08-15 13:59:49 +0100182 /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */
183 armada_updatel(0, CFG_PDWN16x66 | CFG_PDWN32x66,
184 dcrtc->base + LCD_SPU_SRAM_PARA1);
185 }
186
Russell King4a8506d2015-08-07 09:33:05 +0100187 if (armada_drm_plane_work_wait(&dplane->base, HZ / 25) == 0)
188 armada_drm_plane_work_cancel(dcrtc, &dplane->base);
Russell King96f60e32012-08-15 13:59:49 +0100189
Russell King9c898c42017-12-08 12:16:22 +0000190 if (fb_changed) {
191 u32 addrs[3];
Russell King96f60e32012-08-15 13:59:49 +0100192
193 /*
194 * Take a reference on the new framebuffer - we want to
195 * hold on to it while the hardware is displaying it.
196 */
Haneen Mohammeda52ff2a2017-09-20 12:57:16 -0600197 drm_framebuffer_get(fb);
Russell King96f60e32012-08-15 13:59:49 +0100198
Russell Kingfecfdb22015-07-15 18:11:24 +0100199 if (plane->fb)
200 armada_ovl_retire_fb(dplane, plane->fb);
Russell King96f60e32012-08-15 13:59:49 +0100201
Russell King9c898c42017-12-08 12:16:22 +0000202 dplane->base.state.src_y = src_y = src.y1 >> 16;
203 dplane->base.state.src_x = src_x = src.x1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100204
Russell Kingf0b24872016-08-16 22:09:11 +0100205 armada_drm_plane_calc_addrs(addrs, fb, src_x, src_y);
206
Russell Kingf0b24872016-08-16 22:09:11 +0100207 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100208 LCD_SPU_DMA_START_ADDR_Y0);
Russell Kingf0b24872016-08-16 22:09:11 +0100209 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100210 LCD_SPU_DMA_START_ADDR_U0);
Russell Kingf0b24872016-08-16 22:09:11 +0100211 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100212 LCD_SPU_DMA_START_ADDR_V0);
Russell Kingf0b24872016-08-16 22:09:11 +0100213 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100214 LCD_SPU_DMA_START_ADDR_Y1);
Russell Kingf0b24872016-08-16 22:09:11 +0100215 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100216 LCD_SPU_DMA_START_ADDR_U1);
Russell Kingf0b24872016-08-16 22:09:11 +0100217 armada_reg_queue_set(dplane->vbl.regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100218 LCD_SPU_DMA_START_ADDR_V1);
219
220 val = fb->pitches[0] << 16 | fb->pitches[0];
221 armada_reg_queue_set(dplane->vbl.regs, idx, val,
222 LCD_SPU_DMA_PITCH_YC);
223 val = fb->pitches[1] << 16 | fb->pitches[2];
224 armada_reg_queue_set(dplane->vbl.regs, idx, val,
225 LCD_SPU_DMA_PITCH_UV);
226 }
227
Russell King98fb74f2015-06-15 10:17:57 +0100228 val = (drm_rect_height(&src) & 0xffff0000) | drm_rect_width(&src) >> 16;
Russell King8be523d2016-08-16 22:09:08 +0100229 if (dplane->base.state.src_hw != val) {
230 dplane->base.state.src_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100231 armada_reg_queue_set(dplane->vbl.regs, idx, val,
232 LCD_SPU_DMA_HPXL_VLN);
233 }
Russell King98fb74f2015-06-15 10:17:57 +0100234
235 val = drm_rect_height(&dest) << 16 | drm_rect_width(&dest);
Russell King8be523d2016-08-16 22:09:08 +0100236 if (dplane->base.state.dst_hw != val) {
237 dplane->base.state.dst_hw = val;
Russell King96f60e32012-08-15 13:59:49 +0100238 armada_reg_queue_set(dplane->vbl.regs, idx, val,
239 LCD_SPU_DZM_HPXL_VLN);
240 }
Russell King98fb74f2015-06-15 10:17:57 +0100241
242 val = dest.y1 << 16 | dest.x1;
Russell King8be523d2016-08-16 22:09:08 +0100243 if (dplane->base.state.dst_yx != val) {
244 dplane->base.state.dst_yx = val;
Russell King96f60e32012-08-15 13:59:49 +0100245 armada_reg_queue_set(dplane->vbl.regs, idx, val,
246 LCD_SPU_DMA_OVSA_HPXL_VLN);
247 }
Russell King98fb74f2015-06-15 10:17:57 +0100248
Russell King8be523d2016-08-16 22:09:08 +0100249 if (dplane->base.state.ctrl0 != ctrl0) {
250 dplane->base.state.ctrl0 = ctrl0;
Russell King96f60e32012-08-15 13:59:49 +0100251 armada_reg_queue_mod(dplane->vbl.regs, idx, ctrl0,
252 CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE |
253 CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE |
254 CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU |
255 CFG_YUV2RGB) | CFG_DMA_ENA,
256 LCD_SPU_DMA_CTRL0);
257 }
258 if (idx) {
259 armada_reg_queue_end(dplane->vbl.regs, idx);
Russell Kingeaab0132017-07-07 15:55:53 +0100260 /* Queue it for update on the next interrupt if we are enabled */
261 armada_drm_plane_work_queue(dcrtc, &dplane->vbl.work);
Russell King96f60e32012-08-15 13:59:49 +0100262 }
263 return 0;
264}
265
Daniel Vetter19315292017-03-22 22:50:43 +0100266static int armada_ovl_plane_disable(struct drm_plane *plane,
267 struct drm_modeset_acquire_ctx *ctx)
Russell King96f60e32012-08-15 13:59:49 +0100268{
Russell King28a2aeb2015-07-15 18:11:23 +0100269 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100270 struct drm_framebuffer *fb;
Russell King96f60e32012-08-15 13:59:49 +0100271
Russell Kingf1f1bffc2017-07-08 10:16:42 +0100272 armada_drm_plane_disable(plane, ctx);
Russell King96f60e32012-08-15 13:59:49 +0100273
Russell Kingf1f1bffc2017-07-08 10:16:42 +0100274 if (dplane->base.base.crtc)
275 drm_to_armada_crtc(dplane->base.base.crtc)->plane = NULL;
Russell King96f60e32012-08-15 13:59:49 +0100276
Russell King66377ef2015-07-15 18:11:24 +0100277 fb = xchg(&dplane->old_fb, NULL);
Russell King96f60e32012-08-15 13:59:49 +0100278 if (fb)
Haneen Mohammeda52ff2a2017-09-20 12:57:16 -0600279 drm_framebuffer_put(fb);
Russell King96f60e32012-08-15 13:59:49 +0100280
281 return 0;
282}
283
Russell King28a2aeb2015-07-15 18:11:23 +0100284static void armada_ovl_plane_destroy(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100285{
Russell King28a2aeb2015-07-15 18:11:23 +0100286 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King41dbb2d2015-06-15 10:13:30 +0100287
288 drm_plane_cleanup(plane);
289
290 kfree(dplane);
Russell King96f60e32012-08-15 13:59:49 +0100291}
292
Russell King28a2aeb2015-07-15 18:11:23 +0100293static int armada_ovl_plane_set_property(struct drm_plane *plane,
Russell King96f60e32012-08-15 13:59:49 +0100294 struct drm_property *property, uint64_t val)
295{
296 struct armada_private *priv = plane->dev->dev_private;
Russell King28a2aeb2015-07-15 18:11:23 +0100297 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +0100298 bool update_attr = false;
299
300 if (property == priv->colorkey_prop) {
301#define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8)
302 dplane->prop.colorkey_yr = CCC(K2R(val));
303 dplane->prop.colorkey_ug = CCC(K2G(val));
304 dplane->prop.colorkey_vb = CCC(K2B(val));
305#undef CCC
306 update_attr = true;
307 } else if (property == priv->colorkey_min_prop) {
308 dplane->prop.colorkey_yr &= ~0x00ff0000;
309 dplane->prop.colorkey_yr |= K2R(val) << 16;
310 dplane->prop.colorkey_ug &= ~0x00ff0000;
311 dplane->prop.colorkey_ug |= K2G(val) << 16;
312 dplane->prop.colorkey_vb &= ~0x00ff0000;
313 dplane->prop.colorkey_vb |= K2B(val) << 16;
314 update_attr = true;
315 } else if (property == priv->colorkey_max_prop) {
316 dplane->prop.colorkey_yr &= ~0xff000000;
317 dplane->prop.colorkey_yr |= K2R(val) << 24;
318 dplane->prop.colorkey_ug &= ~0xff000000;
319 dplane->prop.colorkey_ug |= K2G(val) << 24;
320 dplane->prop.colorkey_vb &= ~0xff000000;
321 dplane->prop.colorkey_vb |= K2B(val) << 24;
322 update_attr = true;
323 } else if (property == priv->colorkey_val_prop) {
324 dplane->prop.colorkey_yr &= ~0x0000ff00;
325 dplane->prop.colorkey_yr |= K2R(val) << 8;
326 dplane->prop.colorkey_ug &= ~0x0000ff00;
327 dplane->prop.colorkey_ug |= K2G(val) << 8;
328 dplane->prop.colorkey_vb &= ~0x0000ff00;
329 dplane->prop.colorkey_vb |= K2B(val) << 8;
330 update_attr = true;
331 } else if (property == priv->colorkey_alpha_prop) {
332 dplane->prop.colorkey_yr &= ~0x000000ff;
333 dplane->prop.colorkey_yr |= K2R(val);
334 dplane->prop.colorkey_ug &= ~0x000000ff;
335 dplane->prop.colorkey_ug |= K2G(val);
336 dplane->prop.colorkey_vb &= ~0x000000ff;
337 dplane->prop.colorkey_vb |= K2B(val);
338 update_attr = true;
339 } else if (property == priv->colorkey_mode_prop) {
340 dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK;
341 dplane->prop.colorkey_mode |= CFG_CKMODE(val);
342 update_attr = true;
343 } else if (property == priv->brightness_prop) {
344 dplane->prop.brightness = val - 256;
345 update_attr = true;
346 } else if (property == priv->contrast_prop) {
347 dplane->prop.contrast = val;
348 update_attr = true;
349 } else if (property == priv->saturation_prop) {
350 dplane->prop.saturation = val;
351 update_attr = true;
352 }
353
Russell King561f60b2015-07-15 18:11:24 +0100354 if (update_attr && dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100355 armada_ovl_update_attr(&dplane->prop,
Russell King561f60b2015-07-15 18:11:24 +0100356 drm_to_armada_crtc(dplane->base.base.crtc));
Russell King96f60e32012-08-15 13:59:49 +0100357
358 return 0;
359}
360
Russell King28a2aeb2015-07-15 18:11:23 +0100361static const struct drm_plane_funcs armada_ovl_plane_funcs = {
362 .update_plane = armada_ovl_plane_update,
363 .disable_plane = armada_ovl_plane_disable,
364 .destroy = armada_ovl_plane_destroy,
365 .set_property = armada_ovl_plane_set_property,
Russell King96f60e32012-08-15 13:59:49 +0100366};
367
Russell King28a2aeb2015-07-15 18:11:23 +0100368static const uint32_t armada_ovl_formats[] = {
Russell King96f60e32012-08-15 13:59:49 +0100369 DRM_FORMAT_UYVY,
370 DRM_FORMAT_YUYV,
371 DRM_FORMAT_YUV420,
372 DRM_FORMAT_YVU420,
373 DRM_FORMAT_YUV422,
374 DRM_FORMAT_YVU422,
375 DRM_FORMAT_VYUY,
376 DRM_FORMAT_YVYU,
377 DRM_FORMAT_ARGB8888,
378 DRM_FORMAT_ABGR8888,
379 DRM_FORMAT_XRGB8888,
380 DRM_FORMAT_XBGR8888,
381 DRM_FORMAT_RGB888,
382 DRM_FORMAT_BGR888,
383 DRM_FORMAT_ARGB1555,
384 DRM_FORMAT_ABGR1555,
385 DRM_FORMAT_RGB565,
386 DRM_FORMAT_BGR565,
387};
388
Arvind Yadav8a63ca52017-07-01 16:24:42 +0530389static const struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = {
Russell King96f60e32012-08-15 13:59:49 +0100390 { CKMODE_DISABLE, "disabled" },
391 { CKMODE_Y, "Y component" },
392 { CKMODE_U, "U component" },
393 { CKMODE_V, "V component" },
394 { CKMODE_RGB, "RGB" },
395 { CKMODE_R, "R component" },
396 { CKMODE_G, "G component" },
397 { CKMODE_B, "B component" },
398};
399
400static int armada_overlay_create_properties(struct drm_device *dev)
401{
402 struct armada_private *priv = dev->dev_private;
403
404 if (priv->colorkey_prop)
405 return 0;
406
407 priv->colorkey_prop = drm_property_create_range(dev, 0,
408 "colorkey", 0, 0xffffff);
409 priv->colorkey_min_prop = drm_property_create_range(dev, 0,
410 "colorkey_min", 0, 0xffffff);
411 priv->colorkey_max_prop = drm_property_create_range(dev, 0,
412 "colorkey_max", 0, 0xffffff);
413 priv->colorkey_val_prop = drm_property_create_range(dev, 0,
414 "colorkey_val", 0, 0xffffff);
415 priv->colorkey_alpha_prop = drm_property_create_range(dev, 0,
416 "colorkey_alpha", 0, 0xffffff);
417 priv->colorkey_mode_prop = drm_property_create_enum(dev, 0,
418 "colorkey_mode",
419 armada_drm_colorkey_enum_list,
420 ARRAY_SIZE(armada_drm_colorkey_enum_list));
421 priv->brightness_prop = drm_property_create_range(dev, 0,
422 "brightness", 0, 256 + 255);
423 priv->contrast_prop = drm_property_create_range(dev, 0,
424 "contrast", 0, 0x7fff);
425 priv->saturation_prop = drm_property_create_range(dev, 0,
426 "saturation", 0, 0x7fff);
427
428 if (!priv->colorkey_prop)
429 return -ENOMEM;
430
431 return 0;
432}
433
434int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
435{
436 struct armada_private *priv = dev->dev_private;
437 struct drm_mode_object *mobj;
Russell King28a2aeb2015-07-15 18:11:23 +0100438 struct armada_ovl_plane *dplane;
Russell King96f60e32012-08-15 13:59:49 +0100439 int ret;
440
441 ret = armada_overlay_create_properties(dev);
442 if (ret)
443 return ret;
444
445 dplane = kzalloc(sizeof(*dplane), GFP_KERNEL);
446 if (!dplane)
447 return -ENOMEM;
448
Russell King5740d272015-07-15 18:11:25 +0100449 ret = armada_drm_plane_init(&dplane->base);
450 if (ret) {
451 kfree(dplane);
452 return ret;
453 }
454
Russell Kingeaab0132017-07-07 15:55:53 +0100455 dplane->vbl.work.plane = &dplane->base.base;
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),
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700462 NULL,
Ville Syrjäläb0b3b792015-12-09 16:19:55 +0200463 DRM_PLANE_TYPE_OVERLAY, NULL);
Russell King28a2aeb2015-07-15 18:11:23 +0100464 if (ret) {
465 kfree(dplane);
466 return ret;
467 }
Russell King96f60e32012-08-15 13:59:49 +0100468
469 dplane->prop.colorkey_yr = 0xfefefe00;
470 dplane->prop.colorkey_ug = 0x01010100;
471 dplane->prop.colorkey_vb = 0x01010100;
472 dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB);
473 dplane->prop.brightness = 0;
474 dplane->prop.contrast = 0x4000;
475 dplane->prop.saturation = 0x4000;
476
Russell King561f60b2015-07-15 18:11:24 +0100477 mobj = &dplane->base.base.base;
Russell King96f60e32012-08-15 13:59:49 +0100478 drm_object_attach_property(mobj, priv->colorkey_prop,
479 0x0101fe);
480 drm_object_attach_property(mobj, priv->colorkey_min_prop,
481 0x0101fe);
482 drm_object_attach_property(mobj, priv->colorkey_max_prop,
483 0x0101fe);
484 drm_object_attach_property(mobj, priv->colorkey_val_prop,
485 0x0101fe);
486 drm_object_attach_property(mobj, priv->colorkey_alpha_prop,
487 0x000000);
488 drm_object_attach_property(mobj, priv->colorkey_mode_prop,
489 CKMODE_RGB);
490 drm_object_attach_property(mobj, priv->brightness_prop, 256);
491 drm_object_attach_property(mobj, priv->contrast_prop,
492 dplane->prop.contrast);
493 drm_object_attach_property(mobj, priv->saturation_prop,
494 dplane->prop.saturation);
495
496 return 0;
497}