xref: /linux/drivers/gpu/drm/nouveau/dispnv50/ovly827e.c (revision bcae99c282aad70d5aaf7b34f878c465a675089e)
1 /*
2  * Copyright 2018 Red Hat Inc.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #include "ovly.h"
23 #include "atom.h"
24 
25 #include <nouveau_bo.h>
26 
27 #include <nvif/timer.h>
28 
29 static void
30 ovly827e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
31 {
32 	u32 *push;
33 	if ((push = evo_wait(&wndw->wndw, 12))) {
34 		evo_mthd(push, 0x0084, 1);
35 		evo_data(push, asyw->image.interval << 4);
36 		evo_mthd(push, 0x00c0, 1);
37 		evo_data(push, asyw->image.handle[0]);
38 		evo_mthd(push, 0x0100, 1);
39 		evo_data(push, 0x00000002);
40 		evo_mthd(push, 0x0800, 1);
41 		evo_data(push, asyw->image.offset[0] >> 8);
42 		evo_mthd(push, 0x0808, 3);
43 		evo_data(push, asyw->image.h << 16 | asyw->image.w);
44 		evo_data(push, asyw->image.layout << 20 |
45 			       (asyw->image.pitch[0] >> 8) << 8 |
46 			       asyw->image.blocks[0] << 8 |
47 			       asyw->image.blockh);
48 		evo_data(push, asyw->image.format << 8 |
49 			       asyw->image.colorspace);
50 		evo_kick(push, &wndw->wndw);
51 	}
52 }
53 
54 int
55 ovly827e_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
56 			 struct nvif_device *device)
57 {
58 	s64 time = nvif_msec(device, 2000ULL,
59 		u32 data = nouveau_bo_rd32(bo, offset / 4 + 3);
60 		if ((data & 0xffff0000) == 0xffff0000)
61 			break;
62 		usleep_range(1, 2);
63 	);
64 	return time < 0 ? time : 0;
65 }
66 
67 void
68 ovly827e_ntfy_reset(struct nouveau_bo *bo, u32 offset)
69 {
70 	nouveau_bo_wr32(bo, offset / 4 + 0, 0x00000000);
71 	nouveau_bo_wr32(bo, offset / 4 + 1, 0x00000000);
72 	nouveau_bo_wr32(bo, offset / 4 + 2, 0x00000000);
73 	nouveau_bo_wr32(bo, offset / 4 + 3, 0x80000000);
74 }
75 
76 static const struct nv50_wndw_func
77 ovly827e = {
78 	.acquire = ovly507e_acquire,
79 	.release = ovly507e_release,
80 	.ntfy_set = base507c_ntfy_set,
81 	.ntfy_clr = base507c_ntfy_clr,
82 	.ntfy_reset = ovly827e_ntfy_reset,
83 	.ntfy_wait_begun = ovly827e_ntfy_wait_begun,
84 	.image_set = ovly827e_image_set,
85 	.image_clr = ovly507e_image_clr,
86 	.scale_set = ovly507e_scale_set,
87 	.update = ovly507e_update,
88 };
89 
90 const u32
91 ovly827e_format[] = {
92 	DRM_FORMAT_YUYV,
93 	DRM_FORMAT_UYVY,
94 	DRM_FORMAT_XRGB8888,
95 	DRM_FORMAT_XRGB1555,
96 	DRM_FORMAT_XBGR2101010,
97 	0
98 };
99 
100 int
101 ovly827e_new(struct nouveau_drm *drm, int head, s32 oclass,
102 	     struct nv50_wndw **pwndw)
103 {
104 	return ovly507e_new_(&ovly827e, ovly827e_format, drm, head, oclass,
105 			     0x00000004 << (head * 8), pwndw);
106 }
107