blob: 2d90e7898ec841dc882051160b5b386313c557b8 [file] [log] [blame]
Ilia Mirkin515de6b2013-09-07 20:33:43 -04001/*
2 * Copyright 2013 Ilia Mirkin
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 * Implementation based on the pre-KMS implementation in xf86-video-nouveau,
23 * written by Arthur Huillet.
24 */
25
26#include <drm/drmP.h>
27#include <drm/drm_crtc.h>
28#include <drm/drm_fourcc.h>
29
Ben Skeggs4dc28132016-05-20 09:22:55 +100030#include "nouveau_drv.h"
Ilia Mirkin515de6b2013-09-07 20:33:43 -040031
32#include "nouveau_bo.h"
33#include "nouveau_connector.h"
34#include "nouveau_display.h"
35#include "nvreg.h"
Baoyou Xiee8390eb2016-10-24 11:09:02 +080036#include "disp.h"
Ilia Mirkin515de6b2013-09-07 20:33:43 -040037
38struct nouveau_plane {
39 struct drm_plane base;
40 bool flip;
41 struct nouveau_bo *cur;
42
43 struct {
44 struct drm_property *colorkey;
45 struct drm_property *contrast;
46 struct drm_property *brightness;
47 struct drm_property *hue;
48 struct drm_property *saturation;
49 struct drm_property *iturbt_709;
50 } props;
51
52 int colorkey;
53 int contrast;
54 int brightness;
55 int hue;
56 int saturation;
57 int iturbt_709;
Ilia Mirkinab9b18a2013-11-15 11:26:45 -050058
59 void (*set_params)(struct nouveau_plane *);
Ilia Mirkin515de6b2013-09-07 20:33:43 -040060};
61
62static uint32_t formats[] = {
Ilia Mirkin7ffb0782013-11-15 11:26:44 -050063 DRM_FORMAT_YUYV,
Ilia Mirkin515de6b2013-09-07 20:33:43 -040064 DRM_FORMAT_UYVY,
Ilia Mirkinefffa982013-11-15 11:26:43 -050065 DRM_FORMAT_NV12,
Ilia Mirkin515de6b2013-09-07 20:33:43 -040066};
67
68/* Sine can be approximated with
69 * http://en.wikipedia.org/wiki/Bhaskara_I's_sine_approximation_formula
70 * sin(x degrees) ~= 4 x (180 - x) / (40500 - x (180 - x) )
71 * Note that this only works for the range [0, 180].
72 * Also note that sin(x) == -sin(x - 180)
73 */
74static inline int
75sin_mul(int degrees, int factor)
76{
77 if (degrees > 180) {
78 degrees -= 180;
79 factor *= -1;
80 }
81 return factor * 4 * degrees * (180 - degrees) /
82 (40500 - degrees * (180 - degrees));
83}
84
85/* cos(x) = sin(x + 90) */
86static inline int
87cos_mul(int degrees, int factor)
88{
89 return sin_mul((degrees + 90) % 360, factor);
90}
91
92static int
93nv10_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
94 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
95 unsigned int crtc_w, unsigned int crtc_h,
96 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010097 uint32_t src_w, uint32_t src_h,
98 struct drm_modeset_acquire_ctx *ctx)
Ilia Mirkin515de6b2013-09-07 20:33:43 -040099{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000100 struct nouveau_drm *drm = nouveau_drm(plane->dev);
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000101 struct nvif_object *dev = &drm->client.device.object;
Fabian Frederick5ee932d2014-09-14 18:40:18 +0200102 struct nouveau_plane *nv_plane =
103 container_of(plane, struct nouveau_plane, base);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400104 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
105 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
106 struct nouveau_bo *cur = nv_plane->cur;
107 bool flip = nv_plane->flip;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400108 int soff = NV_PCRTC0_SIZE * nv_crtc->index;
109 int soff2 = NV_PCRTC0_SIZE * !nv_crtc->index;
Ilia Mirkin92e5b0a2013-11-15 11:26:41 -0500110 int format, ret;
111
112 /* Source parameters given in 16.16 fixed point, ignore fractional. */
113 src_x >>= 16;
114 src_y >>= 16;
115 src_w >>= 16;
116 src_h >>= 16;
117
118 format = ALIGN(src_w * 4, 0x100);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400119
120 if (format > 0xffff)
Ilia Mirkin050828e2013-11-15 11:26:42 -0500121 return -ERANGE;
122
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000123 if (drm->client.device.info.chipset >= 0x30) {
Ilia Mirkin050828e2013-11-15 11:26:42 -0500124 if (crtc_w < (src_w >> 1) || crtc_h < (src_h >> 1))
125 return -ERANGE;
126 } else {
127 if (crtc_w < (src_w >> 3) || crtc_h < (src_h >> 3))
128 return -ERANGE;
129 }
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400130
Ben Skeggsad76b3f2014-11-10 11:24:27 +1000131 ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM, false);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400132 if (ret)
133 return ret;
134
135 nv_plane->cur = nv_fb->nvbo;
136
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000137 nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff, NV_CRTC_FSEL_OVERLAY, NV_CRTC_FSEL_OVERLAY);
138 nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff2, NV_CRTC_FSEL_OVERLAY, 0);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400139
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000140 nvif_wr32(dev, NV_PVIDEO_BASE(flip), 0);
141 nvif_wr32(dev, NV_PVIDEO_OFFSET_BUFF(flip), nv_fb->nvbo->bo.offset);
142 nvif_wr32(dev, NV_PVIDEO_SIZE_IN(flip), src_h << 16 | src_w);
143 nvif_wr32(dev, NV_PVIDEO_POINT_IN(flip), src_y << 16 | src_x);
144 nvif_wr32(dev, NV_PVIDEO_DS_DX(flip), (src_w << 20) / crtc_w);
145 nvif_wr32(dev, NV_PVIDEO_DT_DY(flip), (src_h << 20) / crtc_h);
146 nvif_wr32(dev, NV_PVIDEO_POINT_OUT(flip), crtc_y << 16 | crtc_x);
147 nvif_wr32(dev, NV_PVIDEO_SIZE_OUT(flip), crtc_h << 16 | crtc_w);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400148
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200149 if (fb->format->format != DRM_FORMAT_UYVY)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400150 format |= NV_PVIDEO_FORMAT_COLOR_LE_CR8YB8CB8YA8;
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200151 if (fb->format->format == DRM_FORMAT_NV12)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400152 format |= NV_PVIDEO_FORMAT_PLANAR;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400153 if (nv_plane->iturbt_709)
154 format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709;
155 if (nv_plane->colorkey & (1 << 24))
156 format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY;
157
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200158 if (fb->format->format == DRM_FORMAT_NV12) {
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000159 nvif_wr32(dev, NV_PVIDEO_UVPLANE_BASE(flip), 0);
160 nvif_wr32(dev, NV_PVIDEO_UVPLANE_OFFSET_BUFF(flip),
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400161 nv_fb->nvbo->bo.offset + fb->offsets[1]);
162 }
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000163 nvif_wr32(dev, NV_PVIDEO_FORMAT(flip), format);
164 nvif_wr32(dev, NV_PVIDEO_STOP, 0);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400165 /* TODO: wait for vblank? */
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000166 nvif_wr32(dev, NV_PVIDEO_BUFFER, flip ? 0x10 : 0x1);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400167 nv_plane->flip = !flip;
168
169 if (cur)
170 nouveau_bo_unpin(cur);
171
172 return 0;
173}
174
175static int
176nv10_disable_plane(struct drm_plane *plane)
177{
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000178 struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object;
Fabian Frederick5ee932d2014-09-14 18:40:18 +0200179 struct nouveau_plane *nv_plane =
180 container_of(plane, struct nouveau_plane, base);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400181
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000182 nvif_wr32(dev, NV_PVIDEO_STOP, 1);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400183 if (nv_plane->cur) {
184 nouveau_bo_unpin(nv_plane->cur);
185 nv_plane->cur = NULL;
186 }
187
188 return 0;
189}
190
191static void
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500192nv_destroy_plane(struct drm_plane *plane)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400193{
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500194 plane->funcs->disable_plane(plane);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400195 drm_plane_cleanup(plane);
196 kfree(plane);
197}
198
199static void
200nv10_set_params(struct nouveau_plane *plane)
201{
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000202 struct nvif_object *dev = &nouveau_drm(plane->base.dev)->client.device.object;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400203 u32 luma = (plane->brightness - 512) << 16 | plane->contrast;
204 u32 chroma = ((sin_mul(plane->hue, plane->saturation) & 0xffff) << 16) |
205 (cos_mul(plane->hue, plane->saturation) & 0xffff);
206 u32 format = 0;
207
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000208 nvif_wr32(dev, NV_PVIDEO_LUMINANCE(0), luma);
209 nvif_wr32(dev, NV_PVIDEO_LUMINANCE(1), luma);
210 nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(0), chroma);
211 nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(1), chroma);
212 nvif_wr32(dev, NV_PVIDEO_COLOR_KEY, plane->colorkey & 0xffffff);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400213
214 if (plane->cur) {
215 if (plane->iturbt_709)
216 format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709;
217 if (plane->colorkey & (1 << 24))
218 format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY;
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000219 nvif_mask(dev, NV_PVIDEO_FORMAT(plane->flip),
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400220 NV_PVIDEO_FORMAT_MATRIX_ITURBT709 |
221 NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY,
222 format);
223 }
224}
225
226static int
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500227nv_set_property(struct drm_plane *plane,
228 struct drm_property *property,
229 uint64_t value)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400230{
Fabian Frederick5ee932d2014-09-14 18:40:18 +0200231 struct nouveau_plane *nv_plane =
232 container_of(plane, struct nouveau_plane, base);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400233
234 if (property == nv_plane->props.colorkey)
235 nv_plane->colorkey = value;
236 else if (property == nv_plane->props.contrast)
237 nv_plane->contrast = value;
238 else if (property == nv_plane->props.brightness)
239 nv_plane->brightness = value;
240 else if (property == nv_plane->props.hue)
241 nv_plane->hue = value;
242 else if (property == nv_plane->props.saturation)
243 nv_plane->saturation = value;
244 else if (property == nv_plane->props.iturbt_709)
245 nv_plane->iturbt_709 = value;
246 else
247 return -EINVAL;
248
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500249 if (nv_plane->set_params)
250 nv_plane->set_params(nv_plane);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400251 return 0;
252}
253
254static const struct drm_plane_funcs nv10_plane_funcs = {
255 .update_plane = nv10_update_plane,
256 .disable_plane = nv10_disable_plane,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500257 .set_property = nv_set_property,
258 .destroy = nv_destroy_plane,
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400259};
260
261static void
262nv10_overlay_init(struct drm_device *device)
263{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000264 struct nouveau_drm *drm = nouveau_drm(device);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400265 struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL);
Thierry Reding45e37432015-08-12 16:54:28 +0200266 unsigned int num_formats = ARRAY_SIZE(formats);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400267 int ret;
268
269 if (!plane)
270 return;
271
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000272 switch (drm->client.device.info.chipset) {
Ilia Mirkinefffa982013-11-15 11:26:43 -0500273 case 0x10:
274 case 0x11:
275 case 0x15:
276 case 0x1a:
277 case 0x20:
Ilia Mirkin7ffb0782013-11-15 11:26:44 -0500278 num_formats = 2;
Ilia Mirkinefffa982013-11-15 11:26:43 -0500279 break;
280 }
281
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400282 ret = drm_plane_init(device, &plane->base, 3 /* both crtc's */,
283 &nv10_plane_funcs,
Ilia Mirkinefffa982013-11-15 11:26:43 -0500284 formats, num_formats, false);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400285 if (ret)
286 goto err;
287
288 /* Set up the plane properties */
289 plane->props.colorkey = drm_property_create_range(
290 device, 0, "colorkey", 0, 0x01ffffff);
291 plane->props.contrast = drm_property_create_range(
292 device, 0, "contrast", 0, 8192 - 1);
293 plane->props.brightness = drm_property_create_range(
294 device, 0, "brightness", 0, 1024);
295 plane->props.hue = drm_property_create_range(
296 device, 0, "hue", 0, 359);
297 plane->props.saturation = drm_property_create_range(
298 device, 0, "saturation", 0, 8192 - 1);
299 plane->props.iturbt_709 = drm_property_create_range(
300 device, 0, "iturbt_709", 0, 1);
301 if (!plane->props.colorkey ||
302 !plane->props.contrast ||
303 !plane->props.brightness ||
304 !plane->props.hue ||
305 !plane->props.saturation ||
306 !plane->props.iturbt_709)
307 goto cleanup;
308
309 plane->colorkey = 0;
310 drm_object_attach_property(&plane->base.base,
311 plane->props.colorkey, plane->colorkey);
312
313 plane->contrast = 0x1000;
314 drm_object_attach_property(&plane->base.base,
315 plane->props.contrast, plane->contrast);
316
317 plane->brightness = 512;
318 drm_object_attach_property(&plane->base.base,
319 plane->props.brightness, plane->brightness);
320
321 plane->hue = 0;
322 drm_object_attach_property(&plane->base.base,
323 plane->props.hue, plane->hue);
324
325 plane->saturation = 0x1000;
326 drm_object_attach_property(&plane->base.base,
327 plane->props.saturation, plane->saturation);
328
329 plane->iturbt_709 = 0;
330 drm_object_attach_property(&plane->base.base,
331 plane->props.iturbt_709, plane->iturbt_709);
332
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500333 plane->set_params = nv10_set_params;
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400334 nv10_set_params(plane);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500335 nv10_disable_plane(&plane->base);
336 return;
337cleanup:
338 drm_plane_cleanup(&plane->base);
339err:
340 kfree(plane);
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000341 NV_ERROR(drm, "Failed to create plane\n");
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500342}
343
344static int
345nv04_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
346 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
347 unsigned int crtc_w, unsigned int crtc_h,
348 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100349 uint32_t src_w, uint32_t src_h,
350 struct drm_modeset_acquire_ctx *ctx)
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500351{
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000352 struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object;
Fabian Frederick5ee932d2014-09-14 18:40:18 +0200353 struct nouveau_plane *nv_plane =
354 container_of(plane, struct nouveau_plane, base);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500355 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
356 struct nouveau_bo *cur = nv_plane->cur;
357 uint32_t overlay = 1;
358 int brightness = (nv_plane->brightness - 512) * 62 / 512;
359 int pitch, ret, i;
360
361 /* Source parameters given in 16.16 fixed point, ignore fractional. */
362 src_x >>= 16;
363 src_y >>= 16;
364 src_w >>= 16;
365 src_h >>= 16;
366
367 pitch = ALIGN(src_w * 4, 0x100);
368
369 if (pitch > 0xffff)
370 return -ERANGE;
371
372 /* TODO: Compute an offset? Not sure how to do this for YUYV. */
373 if (src_x != 0 || src_y != 0)
374 return -ERANGE;
375
376 if (crtc_w < src_w || crtc_h < src_h)
377 return -ERANGE;
378
Ben Skeggsad76b3f2014-11-10 11:24:27 +1000379 ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM, false);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500380 if (ret)
381 return ret;
382
383 nv_plane->cur = nv_fb->nvbo;
384
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000385 nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0);
386 nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0);
387 nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500388
389 for (i = 0; i < 2; i++) {
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000390 nvif_wr32(dev, NV_PVIDEO_BUFF0_START_ADDRESS + 4 * i,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500391 nv_fb->nvbo->bo.offset);
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000392 nvif_wr32(dev, NV_PVIDEO_BUFF0_PITCH_LENGTH + 4 * i, pitch);
393 nvif_wr32(dev, NV_PVIDEO_BUFF0_OFFSET + 4 * i, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500394 }
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000395 nvif_wr32(dev, NV_PVIDEO_WINDOW_START, crtc_y << 16 | crtc_x);
396 nvif_wr32(dev, NV_PVIDEO_WINDOW_SIZE, crtc_h << 16 | crtc_w);
397 nvif_wr32(dev, NV_PVIDEO_STEP_SIZE,
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500398 (uint32_t)(((src_h - 1) << 11) / (crtc_h - 1)) << 16 | (uint32_t)(((src_w - 1) << 11) / (crtc_w - 1)));
399
400 /* It should be possible to convert hue/contrast to this */
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000401 nvif_wr32(dev, NV_PVIDEO_RED_CSC_OFFSET, 0x69 - brightness);
402 nvif_wr32(dev, NV_PVIDEO_GREEN_CSC_OFFSET, 0x3e + brightness);
403 nvif_wr32(dev, NV_PVIDEO_BLUE_CSC_OFFSET, 0x89 - brightness);
404 nvif_wr32(dev, NV_PVIDEO_CSC_ADJUST, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500405
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000406 nvif_wr32(dev, NV_PVIDEO_CONTROL_Y, 0x001); /* (BLUR_ON, LINE_HALF) */
407 nvif_wr32(dev, NV_PVIDEO_CONTROL_X, 0x111); /* (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500408
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000409 nvif_wr32(dev, NV_PVIDEO_FIFO_BURST_LENGTH, 0x03);
410 nvif_wr32(dev, NV_PVIDEO_FIFO_THRES_SIZE, 0x38);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500411
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000412 nvif_wr32(dev, NV_PVIDEO_KEY, nv_plane->colorkey);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500413
414 if (nv_plane->colorkey & (1 << 24))
415 overlay |= 0x10;
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200416 if (fb->format->format == DRM_FORMAT_YUYV)
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500417 overlay |= 0x100;
418
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000419 nvif_wr32(dev, NV_PVIDEO_OVERLAY, overlay);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500420
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000421 nvif_wr32(dev, NV_PVIDEO_SU_STATE, nvif_rd32(dev, NV_PVIDEO_SU_STATE) ^ (1 << 16));
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500422
423 if (cur)
424 nouveau_bo_unpin(cur);
425
426 return 0;
427}
428
429static int
430nv04_disable_plane(struct drm_plane *plane)
431{
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000432 struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object;
Fabian Frederick5ee932d2014-09-14 18:40:18 +0200433 struct nouveau_plane *nv_plane =
434 container_of(plane, struct nouveau_plane, base);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500435
Ben Skeggsdb2bec12014-08-10 04:10:22 +1000436 nvif_mask(dev, NV_PVIDEO_OVERLAY, 1, 0);
437 nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0);
438 nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0);
439 nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500440 if (nv_plane->cur) {
441 nouveau_bo_unpin(nv_plane->cur);
442 nv_plane->cur = NULL;
443 }
444
445 return 0;
446}
447
448static const struct drm_plane_funcs nv04_plane_funcs = {
449 .update_plane = nv04_update_plane,
450 .disable_plane = nv04_disable_plane,
451 .set_property = nv_set_property,
452 .destroy = nv_destroy_plane,
453};
454
455static void
456nv04_overlay_init(struct drm_device *device)
457{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000458 struct nouveau_drm *drm = nouveau_drm(device);
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500459 struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL);
460 int ret;
461
462 if (!plane)
463 return;
464
465 ret = drm_plane_init(device, &plane->base, 1 /* single crtc */,
466 &nv04_plane_funcs,
467 formats, 2, false);
468 if (ret)
469 goto err;
470
471 /* Set up the plane properties */
472 plane->props.colorkey = drm_property_create_range(
473 device, 0, "colorkey", 0, 0x01ffffff);
474 plane->props.brightness = drm_property_create_range(
475 device, 0, "brightness", 0, 1024);
476 if (!plane->props.colorkey ||
477 !plane->props.brightness)
478 goto cleanup;
479
480 plane->colorkey = 0;
481 drm_object_attach_property(&plane->base.base,
482 plane->props.colorkey, plane->colorkey);
483
484 plane->brightness = 512;
485 drm_object_attach_property(&plane->base.base,
486 plane->props.brightness, plane->brightness);
487
488 nv04_disable_plane(&plane->base);
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400489 return;
490cleanup:
491 drm_plane_cleanup(&plane->base);
492err:
493 kfree(plane);
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000494 NV_ERROR(drm, "Failed to create plane\n");
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400495}
496
497void
498nouveau_overlay_init(struct drm_device *device)
499{
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000500 struct nvif_device *dev = &nouveau_drm(device)->client.device;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000501 if (dev->info.chipset < 0x10)
Ilia Mirkinab9b18a2013-11-15 11:26:45 -0500502 nv04_overlay_init(device);
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000503 else if (dev->info.chipset <= 0x40)
Ilia Mirkin515de6b2013-09-07 20:33:43 -0400504 nv10_overlay_init(device);
505}