16598e100795b4a902d197c47d4d6131ea0653f0
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / dispnv50 / head507d.c
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 "head.h"
23 #include "core.h"
24
25 #include <nvif/push507c.h>
26
27 void
28 head507d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
29 {
30         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
31         u32 *push;
32         if ((push = evo_wait(core, 2))) {
33                 evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1);
34                 evo_data(push, asyh->procamp.sat.sin << 20 |
35                                asyh->procamp.sat.cos << 8);
36                 evo_kick(push, core);
37         }
38 }
39
40 void
41 head507d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
42 {
43         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
44         u32 *push;
45         if ((push = evo_wait(core, 2))) {
46                 evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1);
47                 evo_data(push, asyh->dither.mode << 3 |
48                                asyh->dither.bits << 1 |
49                                asyh->dither.enable);
50                 evo_kick(push, core);
51         }
52 }
53
54 int
55 head507d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
56 {
57         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
58         const int i = head->base.index;
59         u32 bounds = 0;
60         int ret;
61
62         if (asyh->ovly.cpp) {
63                 switch (asyh->ovly.cpp) {
64                 case 4: bounds |= 0x00000300; break;
65                 case 2: bounds |= 0x00000100; break;
66                 default:
67                         WARN_ON(1);
68                         break;
69                 }
70                 bounds |= 0x00000001;
71         } else {
72                 bounds |= 0x00000100;
73         }
74
75         if ((ret = PUSH_WAIT(push, 2)))
76                 return ret;
77
78         PUSH_NVSQ(push, NV507D, 0x0904 + (i * 0x400), bounds);
79         return 0;
80 }
81
82 int
83 head507d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
84 {
85         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
86         const int i = head->base.index;
87         u32 bounds = 0;
88         int ret;
89
90         if (asyh->base.cpp) {
91                 switch (asyh->base.cpp) {
92                 case 8: bounds |= 0x00000500; break;
93                 case 4: bounds |= 0x00000300; break;
94                 case 2: bounds |= 0x00000100; break;
95                 case 1: bounds |= 0x00000000; break;
96                 default:
97                         WARN_ON(1);
98                         break;
99                 }
100                 bounds |= 0x00000001;
101         }
102
103         if ((ret = PUSH_WAIT(push, 2)))
104                 return ret;
105
106         PUSH_NVSQ(push, NV507D, 0x0900 + (i * 0x400), bounds);
107         return 0;
108 }
109
110 static int
111 head507d_curs_clr(struct nv50_head *head)
112 {
113         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
114         const int i = head->base.index;
115         int ret;
116
117         if ((ret = PUSH_WAIT(push, 2)))
118                 return ret;
119
120         PUSH_NVSQ(push, NV507D, 0x0880 + (i * 0x400), 0x05000000);
121         return 0;
122 }
123
124 static int
125 head507d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
126 {
127         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
128         const int i = head->base.index;
129         int ret;
130
131         if ((ret = PUSH_WAIT(push, 3)))
132                 return ret;
133
134         PUSH_NVSQ(push, NV507D, 0x0880 + (i * 0x400), 0x80000000 |
135                                                       asyh->curs.layout << 26 |
136                                                       asyh->curs.format << 24,
137                                 0x0884 + (i * 0x400), asyh->curs.offset >> 8);
138         return 0;
139 }
140
141 int
142 head507d_curs_format(struct nv50_head *head, struct nv50_wndw_atom *asyw,
143                      struct nv50_head_atom *asyh)
144 {
145         switch (asyw->image.format) {
146         case 0xcf: asyh->curs.format = 1; break;
147         default:
148                 WARN_ON(1);
149                 return -EINVAL;
150         }
151         return 0;
152 }
153
154 int
155 head507d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
156                      struct nv50_head_atom *asyh)
157 {
158         switch (asyw->image.w) {
159         case 32: asyh->curs.layout = 0; break;
160         case 64: asyh->curs.layout = 1; break;
161         default:
162                 return -EINVAL;
163         }
164         return 0;
165 }
166
167 int
168 head507d_core_clr(struct nv50_head *head)
169 {
170         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
171         const int i = head->base.index;
172         int ret;
173
174         if ((ret = PUSH_WAIT(push, 2)))
175                 return ret;
176
177         PUSH_NVSQ(push, NV507D, 0x0874 + (i * 0x400), 0x00000000);
178         return 0;
179 }
180
181 static int
182 head507d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
183 {
184         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
185         const int i = head->base.index;
186         int ret;
187
188         if ((ret = PUSH_WAIT(push, 9)))
189                 return ret;
190
191         PUSH_NVSQ(push, NV507D, 0x0860 + (i * 0x400), asyh->core.offset >> 8);
192         PUSH_NVSQ(push, NV507D, 0x0868 + (i * 0x400), asyh->core.h << 16 | asyh->core.w,
193                                 0x086c + (i * 0x400), asyh->core.layout << 20 |
194                                                      (asyh->core.pitch >> 8) << 8 |
195                                                       asyh->core.blocks << 8 |
196                                                       asyh->core.blockh,
197                                 0x0870 + (i * 0x400), asyh->core.kind << 16 |
198                                                       asyh->core.format << 8,
199                                 0x0874 + (i * 0x400), asyh->core.handle);
200         PUSH_NVSQ(push, NV507D, 0x08c0 + (i * 0x400), asyh->core.y << 16 | asyh->core.x);
201
202         /* EVO will complain with INVALID_STATE if we have an
203          * active cursor and (re)specify HeadSetContextDmaIso
204          * without also updating HeadSetOffsetCursor.
205          */
206         asyh->set.curs = asyh->curs.visible;
207         asyh->set.olut = asyh->olut.handle != 0;
208         return 0;
209 }
210
211 void
212 head507d_core_calc(struct nv50_head *head, struct nv50_head_atom *asyh)
213 {
214         struct nv50_disp *disp = nv50_disp(head->base.base.dev);
215         if ((asyh->core.visible = (asyh->base.cpp != 0))) {
216                 asyh->core.x = asyh->base.x;
217                 asyh->core.y = asyh->base.y;
218                 asyh->core.w = asyh->base.w;
219                 asyh->core.h = asyh->base.h;
220         } else
221         if ((asyh->core.visible = (asyh->ovly.cpp != 0)) ||
222             (asyh->core.visible = asyh->curs.visible)) {
223                 /*XXX: We need to either find some way of having the
224                  *     primary base layer appear black, while still
225                  *     being able to display the other layers, or we
226                  *     need to allocate a dummy black surface here.
227                  */
228                 asyh->core.x = 0;
229                 asyh->core.y = 0;
230                 asyh->core.w = asyh->state.mode.hdisplay;
231                 asyh->core.h = asyh->state.mode.vdisplay;
232         }
233         asyh->core.handle = disp->core->chan.vram.handle;
234         asyh->core.offset = 0;
235         asyh->core.format = 0xcf;
236         asyh->core.kind = 0;
237         asyh->core.layout = 1;
238         asyh->core.blockh = 0;
239         asyh->core.blocks = 0;
240         asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4;
241 }
242
243 static int
244 head507d_olut_clr(struct nv50_head *head)
245 {
246         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
247         const int i = head->base.index;
248         int ret;
249
250         if ((ret = PUSH_WAIT(push, 2)))
251                 return ret;
252
253         PUSH_NVSQ(push, NV507D, 0x0840 + (i * 0x400), 0x00000000);
254         return 0;
255 }
256
257 static int
258 head507d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
259 {
260         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
261         const int i = head->base.index;
262         int ret;
263
264         if ((ret = PUSH_WAIT(push, 3)))
265                 return ret;
266
267         PUSH_NVSQ(push, NV507D, 0x0840 + (i * 0x400), 0x80000000 | asyh->olut.mode << 30,
268                                 0x0844 + (i * 0x400), asyh->olut.offset >> 8);
269         return 0;
270 }
271
272 static void
273 head507d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
274 {
275         for (; size--; in++, mem += 8) {
276                 writew(drm_color_lut_extract(in->  red, 11) << 3, mem + 0);
277                 writew(drm_color_lut_extract(in->green, 11) << 3, mem + 2);
278                 writew(drm_color_lut_extract(in-> blue, 11) << 3, mem + 4);
279         }
280
281         /* INTERPOLATE modes require a "next" entry to interpolate with,
282          * so we replicate the last entry to deal with this for now.
283          */
284         writew(readw(mem - 8), mem + 0);
285         writew(readw(mem - 6), mem + 2);
286         writew(readw(mem - 4), mem + 4);
287 }
288
289 bool
290 head507d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
291 {
292         if (size != 256)
293                 return false;
294
295         if (asyh->base.cpp == 1)
296                 asyh->olut.mode = 0;
297         else
298                 asyh->olut.mode = 1;
299
300         asyh->olut.load = head507d_olut_load;
301         return true;
302 }
303
304 int
305 head507d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
306 {
307         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
308         struct nv50_head_mode *m = &asyh->mode;
309         const int i = head->base.index;
310         int ret;
311
312         if ((ret = PUSH_WAIT(push, 13)))
313                 return ret;
314
315         PUSH_NVSQ(push, NV507D, 0x0804 + (i * 0x400), 0x00800000 | m->clock,
316                                 0x0808 + (i * 0x400), m->interlace ? 0x00000002 : 0x00000000);
317         PUSH_NVSQ(push, NV507D, 0x0810 + (i * 0x400), 0x00000000,
318                                 0x0814 + (i * 0x400), m->v.active  << 16 | m->h.active,
319                                 0x0818 + (i * 0x400), m->v.synce   << 16 | m->h.synce,
320                                 0x081c + (i * 0x400), m->v.blanke  << 16 | m->h.blanke,
321                                 0x0820 + (i * 0x400), m->v.blanks  << 16 | m->h.blanks,
322                                 0x0824 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s,
323                                 0x0828 + (i * 0x400), asyh->mode.v.blankus);
324         PUSH_NVSQ(push, NV507D, 0x082c + (i * 0x400), 0x00000000);
325         return 0;
326 }
327
328 int
329 head507d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
330 {
331         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
332         const int i = head->base.index;
333         int ret;
334
335         if ((ret = PUSH_WAIT(push, 7)))
336                 return ret;
337
338         PUSH_NVSQ(push, NV507D, 0x08a4 + (i * 0x400), 0x00000000);
339         PUSH_NVSQ(push, NV507D, 0x08c8 + (i * 0x400), asyh->view.iH << 16 | asyh->view.iW);
340         PUSH_NVSQ(push, NV507D, 0x08d8 + (i * 0x400), asyh->view.oH << 16 | asyh->view.oW,
341                                 0x08dc + (i * 0x400), asyh->view.oH << 16 | asyh->view.oW);
342         return 0;
343 }
344
345 const struct nv50_head_func
346 head507d = {
347         .view = head507d_view,
348         .mode = head507d_mode,
349         .olut = head507d_olut,
350         .olut_size = 256,
351         .olut_set = head507d_olut_set,
352         .olut_clr = head507d_olut_clr,
353         .core_calc = head507d_core_calc,
354         .core_set = head507d_core_set,
355         .core_clr = head507d_core_clr,
356         .curs_layout = head507d_curs_layout,
357         .curs_format = head507d_curs_format,
358         .curs_set = head507d_curs_set,
359         .curs_clr = head507d_curs_clr,
360         .base = head507d_base,
361         .ovly = head507d_ovly,
362         .dither = head507d_dither,
363         .procamp = head507d_procamp,
364 };