blob: 00da2c58701cdc52ef784004711f9908d69dc47d [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 King28a2aeb2015-07-15 18:11:23 +010035 struct armada_ovl_plane_properties prop;
Russell King96f60e32012-08-15 13:59:49 +010036};
Russell King561f60b2015-07-15 18:11:24 +010037#define drm_to_armada_ovl_plane(p) \
38 container_of(p, struct armada_ovl_plane, base.base)
Russell King96f60e32012-08-15 13:59:49 +010039
40
41static void
Russell King28a2aeb2015-07-15 18:11:23 +010042armada_ovl_update_attr(struct armada_ovl_plane_properties *prop,
Russell King96f60e32012-08-15 13:59:49 +010043 struct armada_crtc *dcrtc)
44{
45 writel_relaxed(prop->colorkey_yr, dcrtc->base + LCD_SPU_COLORKEY_Y);
46 writel_relaxed(prop->colorkey_ug, dcrtc->base + LCD_SPU_COLORKEY_U);
47 writel_relaxed(prop->colorkey_vb, dcrtc->base + LCD_SPU_COLORKEY_V);
48
49 writel_relaxed(prop->brightness << 16 | prop->contrast,
50 dcrtc->base + LCD_SPU_CONTRAST);
51 /* Docs say 15:0, but it seems to actually be 31:16 on Armada 510 */
52 writel_relaxed(prop->saturation << 16,
53 dcrtc->base + LCD_SPU_SATURATION);
54 writel_relaxed(0x00002000, dcrtc->base + LCD_SPU_CBSH_HUE);
55
56 spin_lock_irq(&dcrtc->irq_lock);
57 armada_updatel(prop->colorkey_mode | CFG_ALPHAM_GRA,
58 CFG_CKMODE_MASK | CFG_ALPHAM_MASK | CFG_ALPHA_MASK,
59 dcrtc->base + LCD_SPU_DMA_CTRL1);
60
61 armada_updatel(ADV_GRACOLORKEY, 0, dcrtc->base + LCD_SPU_ADV_REG);
62 spin_unlock_irq(&dcrtc->irq_lock);
63}
64
65/* === Plane support === */
Russell King4a8506d2015-08-07 09:33:05 +010066static void armada_ovl_plane_work(struct armada_crtc *dcrtc,
Russell Kingeaab0132017-07-07 15:55:53 +010067 struct armada_plane_work *work)
Russell King96f60e32012-08-15 13:59:49 +010068{
Russell Kinga3f6a182017-07-08 10:16:48 +010069 unsigned long flags;
Russell King96f60e32012-08-15 13:59:49 +010070
Russell Kingeaab0132017-07-07 15:55:53 +010071 trace_armada_ovl_plane_work(&dcrtc->crtc, work->plane);
Russell Kingc8a220c2016-05-17 13:51:08 +010072
Russell Kinga3f6a182017-07-08 10:16:48 +010073 spin_lock_irqsave(&dcrtc->irq_lock, flags);
Russell Kingeaa66272017-07-08 10:22:10 +010074 armada_drm_crtc_update_regs(dcrtc, work->regs);
Russell Kinga3f6a182017-07-08 10:16:48 +010075 spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
Russell King96f60e32012-08-15 13:59:49 +010076}
77
Russell King96f60e32012-08-15 13:59:49 +010078static int
Russell King28a2aeb2015-07-15 18:11:23 +010079armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
Russell King96f60e32012-08-15 13:59:49 +010080 struct drm_framebuffer *fb,
81 int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010082 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h,
83 struct drm_modeset_acquire_ctx *ctx)
Russell King96f60e32012-08-15 13:59:49 +010084{
Russell King28a2aeb2015-07-15 18:11:23 +010085 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King96f60e32012-08-15 13:59:49 +010086 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell Kingd9241552017-07-08 10:22:25 +010087 struct armada_plane_work *work;
Russell King9c898c42017-12-08 12:16:22 +000088 const struct drm_format_info *format;
Russell King7bfab1e2017-07-08 10:22:20 +010089 struct drm_plane_state state = {
90 .plane = plane,
91 .crtc = crtc,
92 .fb = fb,
93 .src_x = src_x,
94 .src_y = src_y,
95 .src_w = src_w,
96 .src_h = src_h,
97 .crtc_x = crtc_x,
98 .crtc_y = crtc_y,
99 .crtc_w = crtc_w,
100 .crtc_h = crtc_h,
101 .rotation = DRM_MODE_ROTATE_0,
Russell King98fb74f2015-06-15 10:17:57 +0100102 };
103 const struct drm_rect clip = {
104 .x2 = crtc->mode.hdisplay,
105 .y2 = crtc->mode.vdisplay,
106 };
Russell King96f60e32012-08-15 13:59:49 +0100107 uint32_t val, ctrl0;
108 unsigned idx = 0;
Russell King7bfab1e2017-07-08 10:22:20 +0100109 bool fb_changed;
Russell King96f60e32012-08-15 13:59:49 +0100110 int ret;
111
Russell Kingc8a220c2016-05-17 13:51:08 +0100112 trace_armada_ovl_plane_update(plane, crtc, fb,
113 crtc_x, crtc_y, crtc_w, crtc_h,
114 src_x, src_y, src_w, src_h);
115
Russell King7bfab1e2017-07-08 10:22:20 +0100116 ret = drm_plane_helper_check_state(&state, &clip, 0, INT_MAX, true,
117 false);
Russell King98fb74f2015-06-15 10:17:57 +0100118 if (ret)
119 return ret;
120
Russell Kingd9241552017-07-08 10:22:25 +0100121 work = &dplane->base.works[dplane->base.next_work];
122
Russell King96f60e32012-08-15 13:59:49 +0100123 ctrl0 = CFG_DMA_FMT(drm_fb_to_armada_fb(fb)->fmt) |
124 CFG_DMA_MOD(drm_fb_to_armada_fb(fb)->mod) |
Russell King73c51ab2017-07-08 10:22:19 +0100125 CFG_CBSH_ENA;
Russell King7bfab1e2017-07-08 10:22:20 +0100126 if (state.visible)
Russell King73c51ab2017-07-08 10:22:19 +0100127 ctrl0 |= CFG_DMA_ENA;
Russell King7bfab1e2017-07-08 10:22:20 +0100128 if (drm_rect_width(&state.src) >> 16 != drm_rect_width(&state.dst))
Russell King73c51ab2017-07-08 10:22:19 +0100129 ctrl0 |= CFG_DMA_HSMOOTH;
Russell King96f60e32012-08-15 13:59:49 +0100130
Russell King9c898c42017-12-08 12:16:22 +0000131 /*
132 * Shifting a YUV packed format image by one pixel causes the U/V
133 * planes to swap. Compensate for it by also toggling the UV swap.
134 */
135 format = fb->format;
Russell King7bfab1e2017-07-08 10:22:20 +0100136 if (format->num_planes == 1 && state.src.x1 >> 16 & (format->hsub - 1))
Russell King9c898c42017-12-08 12:16:22 +0000137 ctrl0 ^= CFG_DMA_MOD(CFG_SWAPUV);
138
Russell Kingd19f6ee2017-07-08 10:22:31 +0100139 if (~dplane->base.state.ctrl0 & ctrl0 & CFG_DMA_ENA) {
Russell King96f60e32012-08-15 13:59:49 +0100140 /* Power up the Y/U/V FIFOs on ENA 0->1 transitions */
Russell King214612f2017-07-08 10:22:15 +0100141 armada_reg_queue_mod(work->regs, idx,
142 0, CFG_PDWN16x66 | CFG_PDWN32x66,
143 LCD_SPU_SRAM_PARA1);
Russell King96f60e32012-08-15 13:59:49 +0100144 }
145
Russell Kingd19f6ee2017-07-08 10:22:31 +0100146 fb_changed = plane->fb != fb ||
147 dplane->base.state.src_x != state.src.x1 >> 16 ||
148 dplane->base.state.src_y != state.src.y1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100149
Russell Kingd19f6ee2017-07-08 10:22:31 +0100150 /* FIXME: overlay on an interlaced display */
Russell King9c898c42017-12-08 12:16:22 +0000151 if (fb_changed) {
152 u32 addrs[3];
Russell King96f60e32012-08-15 13:59:49 +0100153
154 /*
155 * Take a reference on the new framebuffer - we want to
156 * hold on to it while the hardware is displaying it.
157 */
Haneen Mohammeda52ff2a2017-09-20 12:57:16 -0600158 drm_framebuffer_get(fb);
Russell King96f60e32012-08-15 13:59:49 +0100159
Russell Kingeaa66272017-07-08 10:22:10 +0100160 work->old_fb = plane->fb;
Russell King96f60e32012-08-15 13:59:49 +0100161
Russell King7bfab1e2017-07-08 10:22:20 +0100162 dplane->base.state.src_y = src_y = state.src.y1 >> 16;
163 dplane->base.state.src_x = src_x = state.src.x1 >> 16;
Russell King96f60e32012-08-15 13:59:49 +0100164
Russell Kingf0b24872016-08-16 22:09:11 +0100165 armada_drm_plane_calc_addrs(addrs, fb, src_x, src_y);
166
Russell Kingeaa66272017-07-08 10:22:10 +0100167 armada_reg_queue_set(work->regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100168 LCD_SPU_DMA_START_ADDR_Y0);
Russell Kingeaa66272017-07-08 10:22:10 +0100169 armada_reg_queue_set(work->regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100170 LCD_SPU_DMA_START_ADDR_U0);
Russell Kingeaa66272017-07-08 10:22:10 +0100171 armada_reg_queue_set(work->regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100172 LCD_SPU_DMA_START_ADDR_V0);
Russell Kingeaa66272017-07-08 10:22:10 +0100173 armada_reg_queue_set(work->regs, idx, addrs[0],
Russell King96f60e32012-08-15 13:59:49 +0100174 LCD_SPU_DMA_START_ADDR_Y1);
Russell Kingeaa66272017-07-08 10:22:10 +0100175 armada_reg_queue_set(work->regs, idx, addrs[1],
Russell King96f60e32012-08-15 13:59:49 +0100176 LCD_SPU_DMA_START_ADDR_U1);
Russell Kingeaa66272017-07-08 10:22:10 +0100177 armada_reg_queue_set(work->regs, idx, addrs[2],
Russell King96f60e32012-08-15 13:59:49 +0100178 LCD_SPU_DMA_START_ADDR_V1);
179
180 val = fb->pitches[0] << 16 | fb->pitches[0];
Russell Kingeaa66272017-07-08 10:22:10 +0100181 armada_reg_queue_set(work->regs, idx, val,
Russell King96f60e32012-08-15 13:59:49 +0100182 LCD_SPU_DMA_PITCH_YC);
183 val = fb->pitches[1] << 16 | fb->pitches[2];
Russell Kingeaa66272017-07-08 10:22:10 +0100184 armada_reg_queue_set(work->regs, idx, val,
Russell King96f60e32012-08-15 13:59:49 +0100185 LCD_SPU_DMA_PITCH_UV);
Russell Kingb972a802017-07-08 10:16:52 +0100186 } else {
Russell Kingeaa66272017-07-08 10:22:10 +0100187 work->old_fb = NULL;
Russell King96f60e32012-08-15 13:59:49 +0100188 }
189
Russell King7bfab1e2017-07-08 10:22:20 +0100190 val = (drm_rect_height(&state.src) & 0xffff0000) |
191 drm_rect_width(&state.src) >> 16;
Russell King8be523d2016-08-16 22:09:08 +0100192 if (dplane->base.state.src_hw != val) {
193 dplane->base.state.src_hw = val;
Russell Kingeaa66272017-07-08 10:22:10 +0100194 armada_reg_queue_set(work->regs, idx, val,
Russell King96f60e32012-08-15 13:59:49 +0100195 LCD_SPU_DMA_HPXL_VLN);
196 }
Russell King98fb74f2015-06-15 10:17:57 +0100197
Russell King7bfab1e2017-07-08 10:22:20 +0100198 val = drm_rect_height(&state.dst) << 16 | drm_rect_width(&state.dst);
Russell King8be523d2016-08-16 22:09:08 +0100199 if (dplane->base.state.dst_hw != val) {
200 dplane->base.state.dst_hw = val;
Russell Kingeaa66272017-07-08 10:22:10 +0100201 armada_reg_queue_set(work->regs, idx, val,
Russell King96f60e32012-08-15 13:59:49 +0100202 LCD_SPU_DZM_HPXL_VLN);
203 }
Russell King98fb74f2015-06-15 10:17:57 +0100204
Russell King7bfab1e2017-07-08 10:22:20 +0100205 val = state.dst.y1 << 16 | state.dst.x1;
Russell King8be523d2016-08-16 22:09:08 +0100206 if (dplane->base.state.dst_yx != val) {
207 dplane->base.state.dst_yx = val;
Russell Kingeaa66272017-07-08 10:22:10 +0100208 armada_reg_queue_set(work->regs, idx, val,
Russell King96f60e32012-08-15 13:59:49 +0100209 LCD_SPU_DMA_OVSA_HPXL_VLN);
210 }
Russell King98fb74f2015-06-15 10:17:57 +0100211
Russell King8be523d2016-08-16 22:09:08 +0100212 if (dplane->base.state.ctrl0 != ctrl0) {
213 dplane->base.state.ctrl0 = ctrl0;
Russell Kingeaa66272017-07-08 10:22:10 +0100214 armada_reg_queue_mod(work->regs, idx, ctrl0,
Russell King96f60e32012-08-15 13:59:49 +0100215 CFG_CBSH_ENA | CFG_DMAFORMAT | CFG_DMA_FTOGGLE |
216 CFG_DMA_HSMOOTH | CFG_DMA_TSTMODE |
217 CFG_DMA_MOD(CFG_SWAPRB | CFG_SWAPUV | CFG_SWAPYU |
218 CFG_YUV2RGB) | CFG_DMA_ENA,
219 LCD_SPU_DMA_CTRL0);
220 }
Russell Kingd19f6ee2017-07-08 10:22:31 +0100221
222 /* Just updating the position/size? */
223 if (!fb_changed && dplane->base.state.ctrl0 == ctrl0) {
224 armada_reg_queue_end(work->regs, idx);
225 armada_ovl_plane_work(dcrtc, work);
226 return 0;
227 }
228
229 /* Wait for pending work to complete */
230 if (armada_drm_plane_work_wait(&dplane->base, HZ / 25) == 0)
231 armada_drm_plane_work_cancel(dcrtc, &dplane->base);
232
233 if (!dcrtc->plane) {
234 dcrtc->plane = plane;
235 armada_ovl_update_attr(&dplane->prop, dcrtc);
236 }
237
Russell King96f60e32012-08-15 13:59:49 +0100238 if (idx) {
Russell Kingeaa66272017-07-08 10:22:10 +0100239 armada_reg_queue_end(work->regs, idx);
Russell Kingeaab0132017-07-07 15:55:53 +0100240 /* Queue it for update on the next interrupt if we are enabled */
Russell Kingc93dfdc2017-07-08 10:22:23 +0100241 ret = armada_drm_plane_work_queue(dcrtc, work);
242 if (ret)
243 DRM_ERROR("failed to queue plane work: %d\n", ret);
Russell Kingd9241552017-07-08 10:22:25 +0100244
245 dplane->base.next_work = !dplane->base.next_work;
Russell King96f60e32012-08-15 13:59:49 +0100246 }
247 return 0;
248}
249
Russell King28a2aeb2015-07-15 18:11:23 +0100250static void armada_ovl_plane_destroy(struct drm_plane *plane)
Russell King96f60e32012-08-15 13:59:49 +0100251{
Russell King28a2aeb2015-07-15 18:11:23 +0100252 struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
Russell King41dbb2d2015-06-15 10:13:30 +0100253
254 drm_plane_cleanup(plane);
255
256 kfree(dplane);
Russell King96f60e32012-08-15 13:59:49 +0100257}
258
Russell King28a2aeb2015-07-15 18:11:23 +0100259static int armada_ovl_plane_set_property(struct drm_plane *plane,
Russell King96f60e32012-08-15 13:59:49 +0100260 struct drm_property *property, uint64_t val)
261{
262 struct armada_private *priv = plane->dev->dev_private;
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 bool update_attr = false;
265
266 if (property == priv->colorkey_prop) {
267#define CCC(v) ((v) << 24 | (v) << 16 | (v) << 8)
268 dplane->prop.colorkey_yr = CCC(K2R(val));
269 dplane->prop.colorkey_ug = CCC(K2G(val));
270 dplane->prop.colorkey_vb = CCC(K2B(val));
271#undef CCC
272 update_attr = true;
273 } else if (property == priv->colorkey_min_prop) {
274 dplane->prop.colorkey_yr &= ~0x00ff0000;
275 dplane->prop.colorkey_yr |= K2R(val) << 16;
276 dplane->prop.colorkey_ug &= ~0x00ff0000;
277 dplane->prop.colorkey_ug |= K2G(val) << 16;
278 dplane->prop.colorkey_vb &= ~0x00ff0000;
279 dplane->prop.colorkey_vb |= K2B(val) << 16;
280 update_attr = true;
281 } else if (property == priv->colorkey_max_prop) {
282 dplane->prop.colorkey_yr &= ~0xff000000;
283 dplane->prop.colorkey_yr |= K2R(val) << 24;
284 dplane->prop.colorkey_ug &= ~0xff000000;
285 dplane->prop.colorkey_ug |= K2G(val) << 24;
286 dplane->prop.colorkey_vb &= ~0xff000000;
287 dplane->prop.colorkey_vb |= K2B(val) << 24;
288 update_attr = true;
289 } else if (property == priv->colorkey_val_prop) {
290 dplane->prop.colorkey_yr &= ~0x0000ff00;
291 dplane->prop.colorkey_yr |= K2R(val) << 8;
292 dplane->prop.colorkey_ug &= ~0x0000ff00;
293 dplane->prop.colorkey_ug |= K2G(val) << 8;
294 dplane->prop.colorkey_vb &= ~0x0000ff00;
295 dplane->prop.colorkey_vb |= K2B(val) << 8;
296 update_attr = true;
297 } else if (property == priv->colorkey_alpha_prop) {
298 dplane->prop.colorkey_yr &= ~0x000000ff;
299 dplane->prop.colorkey_yr |= K2R(val);
300 dplane->prop.colorkey_ug &= ~0x000000ff;
301 dplane->prop.colorkey_ug |= K2G(val);
302 dplane->prop.colorkey_vb &= ~0x000000ff;
303 dplane->prop.colorkey_vb |= K2B(val);
304 update_attr = true;
305 } else if (property == priv->colorkey_mode_prop) {
306 dplane->prop.colorkey_mode &= ~CFG_CKMODE_MASK;
307 dplane->prop.colorkey_mode |= CFG_CKMODE(val);
308 update_attr = true;
309 } else if (property == priv->brightness_prop) {
310 dplane->prop.brightness = val - 256;
311 update_attr = true;
312 } else if (property == priv->contrast_prop) {
313 dplane->prop.contrast = val;
314 update_attr = true;
315 } else if (property == priv->saturation_prop) {
316 dplane->prop.saturation = val;
317 update_attr = true;
318 }
319
Russell King561f60b2015-07-15 18:11:24 +0100320 if (update_attr && dplane->base.base.crtc)
Russell King96f60e32012-08-15 13:59:49 +0100321 armada_ovl_update_attr(&dplane->prop,
Russell King561f60b2015-07-15 18:11:24 +0100322 drm_to_armada_crtc(dplane->base.base.crtc));
Russell King96f60e32012-08-15 13:59:49 +0100323
324 return 0;
325}
326
Russell King28a2aeb2015-07-15 18:11:23 +0100327static const struct drm_plane_funcs armada_ovl_plane_funcs = {
328 .update_plane = armada_ovl_plane_update,
Russell King890ca8d2017-07-08 10:22:27 +0100329 .disable_plane = armada_drm_plane_disable,
Russell King28a2aeb2015-07-15 18:11:23 +0100330 .destroy = armada_ovl_plane_destroy,
331 .set_property = armada_ovl_plane_set_property,
Russell King96f60e32012-08-15 13:59:49 +0100332};
333
Russell King28a2aeb2015-07-15 18:11:23 +0100334static const uint32_t armada_ovl_formats[] = {
Russell King96f60e32012-08-15 13:59:49 +0100335 DRM_FORMAT_UYVY,
336 DRM_FORMAT_YUYV,
337 DRM_FORMAT_YUV420,
338 DRM_FORMAT_YVU420,
339 DRM_FORMAT_YUV422,
340 DRM_FORMAT_YVU422,
341 DRM_FORMAT_VYUY,
342 DRM_FORMAT_YVYU,
343 DRM_FORMAT_ARGB8888,
344 DRM_FORMAT_ABGR8888,
345 DRM_FORMAT_XRGB8888,
346 DRM_FORMAT_XBGR8888,
347 DRM_FORMAT_RGB888,
348 DRM_FORMAT_BGR888,
349 DRM_FORMAT_ARGB1555,
350 DRM_FORMAT_ABGR1555,
351 DRM_FORMAT_RGB565,
352 DRM_FORMAT_BGR565,
353};
354
Arvind Yadav8a63ca52017-07-01 16:24:42 +0530355static const struct drm_prop_enum_list armada_drm_colorkey_enum_list[] = {
Russell King96f60e32012-08-15 13:59:49 +0100356 { CKMODE_DISABLE, "disabled" },
357 { CKMODE_Y, "Y component" },
358 { CKMODE_U, "U component" },
359 { CKMODE_V, "V component" },
360 { CKMODE_RGB, "RGB" },
361 { CKMODE_R, "R component" },
362 { CKMODE_G, "G component" },
363 { CKMODE_B, "B component" },
364};
365
366static int armada_overlay_create_properties(struct drm_device *dev)
367{
368 struct armada_private *priv = dev->dev_private;
369
370 if (priv->colorkey_prop)
371 return 0;
372
373 priv->colorkey_prop = drm_property_create_range(dev, 0,
374 "colorkey", 0, 0xffffff);
375 priv->colorkey_min_prop = drm_property_create_range(dev, 0,
376 "colorkey_min", 0, 0xffffff);
377 priv->colorkey_max_prop = drm_property_create_range(dev, 0,
378 "colorkey_max", 0, 0xffffff);
379 priv->colorkey_val_prop = drm_property_create_range(dev, 0,
380 "colorkey_val", 0, 0xffffff);
381 priv->colorkey_alpha_prop = drm_property_create_range(dev, 0,
382 "colorkey_alpha", 0, 0xffffff);
383 priv->colorkey_mode_prop = drm_property_create_enum(dev, 0,
384 "colorkey_mode",
385 armada_drm_colorkey_enum_list,
386 ARRAY_SIZE(armada_drm_colorkey_enum_list));
387 priv->brightness_prop = drm_property_create_range(dev, 0,
388 "brightness", 0, 256 + 255);
389 priv->contrast_prop = drm_property_create_range(dev, 0,
390 "contrast", 0, 0x7fff);
391 priv->saturation_prop = drm_property_create_range(dev, 0,
392 "saturation", 0, 0x7fff);
393
394 if (!priv->colorkey_prop)
395 return -ENOMEM;
396
397 return 0;
398}
399
400int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
401{
402 struct armada_private *priv = dev->dev_private;
403 struct drm_mode_object *mobj;
Russell King28a2aeb2015-07-15 18:11:23 +0100404 struct armada_ovl_plane *dplane;
Russell King96f60e32012-08-15 13:59:49 +0100405 int ret;
406
407 ret = armada_overlay_create_properties(dev);
408 if (ret)
409 return ret;
410
411 dplane = kzalloc(sizeof(*dplane), GFP_KERNEL);
412 if (!dplane)
413 return -ENOMEM;
414
Russell King5740d272015-07-15 18:11:25 +0100415 ret = armada_drm_plane_init(&dplane->base);
416 if (ret) {
417 kfree(dplane);
418 return ret;
419 }
420
Russell Kingd9241552017-07-08 10:22:25 +0100421 dplane->base.works[0].fn = armada_ovl_plane_work;
422 dplane->base.works[1].fn = armada_ovl_plane_work;
Russell King96f60e32012-08-15 13:59:49 +0100423
Russell King561f60b2015-07-15 18:11:24 +0100424 ret = drm_universal_plane_init(dev, &dplane->base.base, crtcs,
Russell Kingd563c242015-07-15 18:11:24 +0100425 &armada_ovl_plane_funcs,
426 armada_ovl_formats,
427 ARRAY_SIZE(armada_ovl_formats),
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700428 NULL,
Ville Syrjäläb0b3b792015-12-09 16:19:55 +0200429 DRM_PLANE_TYPE_OVERLAY, NULL);
Russell King28a2aeb2015-07-15 18:11:23 +0100430 if (ret) {
431 kfree(dplane);
432 return ret;
433 }
Russell King96f60e32012-08-15 13:59:49 +0100434
435 dplane->prop.colorkey_yr = 0xfefefe00;
436 dplane->prop.colorkey_ug = 0x01010100;
437 dplane->prop.colorkey_vb = 0x01010100;
438 dplane->prop.colorkey_mode = CFG_CKMODE(CKMODE_RGB);
439 dplane->prop.brightness = 0;
440 dplane->prop.contrast = 0x4000;
441 dplane->prop.saturation = 0x4000;
442
Russell King561f60b2015-07-15 18:11:24 +0100443 mobj = &dplane->base.base.base;
Russell King96f60e32012-08-15 13:59:49 +0100444 drm_object_attach_property(mobj, priv->colorkey_prop,
445 0x0101fe);
446 drm_object_attach_property(mobj, priv->colorkey_min_prop,
447 0x0101fe);
448 drm_object_attach_property(mobj, priv->colorkey_max_prop,
449 0x0101fe);
450 drm_object_attach_property(mobj, priv->colorkey_val_prop,
451 0x0101fe);
452 drm_object_attach_property(mobj, priv->colorkey_alpha_prop,
453 0x000000);
454 drm_object_attach_property(mobj, priv->colorkey_mode_prop,
455 CKMODE_RGB);
456 drm_object_attach_property(mobj, priv->brightness_prop, 256);
457 drm_object_attach_property(mobj, priv->contrast_prop,
458 dplane->prop.contrast);
459 drm_object_attach_property(mobj, priv->saturation_prop,
460 dplane->prop.saturation);
461
462 return 0;
463}