drm/nouveau/kms/nv50-: convert core head_core_set() to new push macros
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / dispnv50 / head907d.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 <drm/drm_connector.h>
23 #include <drm/drm_mode_config.h>
24 #include <drm/drm_vblank.h>
25 #include "nouveau_drv.h"
26 #include "nouveau_bios.h"
27 #include "nouveau_connector.h"
28 #include "head.h"
29 #include "core.h"
30 #include "crc.h"
31
32 #include <nvif/push507c.h>
33
34 void
35 head907d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
36 {
37         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
38         u32 *push;
39         if ((push = evo_wait(core, 3))) {
40                 evo_mthd(push, 0x0404 + (head->base.index * 0x300), 2);
41                 evo_data(push, asyh->or.depth  << 6 |
42                                asyh->or.nvsync << 4 |
43                                asyh->or.nhsync << 3 |
44                                asyh->or.crc_raster);
45                 evo_data(push, 0x31ec6000 | head->base.index << 25 |
46                                             asyh->mode.interlace);
47                 evo_kick(push, core);
48         }
49 }
50
51 void
52 head907d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
53 {
54         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
55         u32 *push;
56         if ((push = evo_wait(core, 2))) {
57                 evo_mthd(push, 0x0498 + (head->base.index * 0x300), 1);
58                 evo_data(push, asyh->procamp.sat.sin << 20 |
59                                asyh->procamp.sat.cos << 8);
60                 evo_kick(push, core);
61         }
62 }
63
64 static void
65 head907d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
66 {
67         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
68         u32 *push;
69         if ((push = evo_wait(core, 2))) {
70                 evo_mthd(push, 0x0490 + (head->base.index * 0x0300), 1);
71                 evo_data(push, asyh->dither.mode << 3 |
72                                asyh->dither.bits << 1 |
73                                asyh->dither.enable);
74                 evo_kick(push, core);
75         }
76 }
77
78 void
79 head907d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
80 {
81         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
82         u32 bounds = 0;
83         u32 *push;
84
85         if (asyh->ovly.cpp) {
86                 switch (asyh->ovly.cpp) {
87                 case 8: bounds |= 0x00000500; break;
88                 case 4: bounds |= 0x00000300; break;
89                 case 2: bounds |= 0x00000100; break;
90                 default:
91                         WARN_ON(1);
92                         break;
93                 }
94                 bounds |= 0x00000001;
95         } else {
96                 bounds |= 0x00000100;
97         }
98
99         if ((push = evo_wait(core, 2))) {
100                 evo_mthd(push, 0x04d4 + head->base.index * 0x300, 1);
101                 evo_data(push, bounds);
102                 evo_kick(push, core);
103         }
104 }
105
106 static void
107 head907d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
108 {
109         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
110         u32 bounds = 0;
111         u32 *push;
112
113         if (asyh->base.cpp) {
114                 switch (asyh->base.cpp) {
115                 case 8: bounds |= 0x00000500; break;
116                 case 4: bounds |= 0x00000300; break;
117                 case 2: bounds |= 0x00000100; break;
118                 case 1: bounds |= 0x00000000; break;
119                 default:
120                         WARN_ON(1);
121                         break;
122                 }
123                 bounds |= 0x00000001;
124         }
125
126         if ((push = evo_wait(core, 2))) {
127                 evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1);
128                 evo_data(push, bounds);
129                 evo_kick(push, core);
130         }
131 }
132
133 void
134 head907d_curs_clr(struct nv50_head *head)
135 {
136         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
137         u32 *push;
138         if ((push = evo_wait(core, 4))) {
139                 evo_mthd(push, 0x0480 + head->base.index * 0x300, 1);
140                 evo_data(push, 0x05000000);
141                 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
142                 evo_data(push, 0x00000000);
143                 evo_kick(push, core);
144         }
145 }
146
147 void
148 head907d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
149 {
150         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
151         u32 *push;
152         if ((push = evo_wait(core, 5))) {
153                 evo_mthd(push, 0x0480 + head->base.index * 0x300, 2);
154                 evo_data(push, 0x80000000 | asyh->curs.layout << 26 |
155                                             asyh->curs.format << 24);
156                 evo_data(push, asyh->curs.offset >> 8);
157                 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
158                 evo_data(push, asyh->curs.handle);
159                 evo_kick(push, core);
160         }
161 }
162
163 void
164 head907d_core_clr(struct nv50_head *head)
165 {
166         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
167         u32 *push;
168         if ((push = evo_wait(core, 2))) {
169                 evo_mthd(push, 0x0474 + head->base.index * 0x300, 1);
170                 evo_data(push, 0x00000000);
171                 evo_kick(push, core);
172         }
173 }
174
175 int
176 head907d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
177 {
178         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
179         const int i = head->base.index;
180         int ret;
181
182         if ((ret = PUSH_WAIT(push, 9)))
183                 return ret;
184
185         PUSH_NVSQ(push, NV907D, 0x0460 + (i * 0x300), asyh->core.offset >> 8);
186         PUSH_NVSQ(push, NV907D, 0x0468 + (i * 0x300), asyh->core.h << 16 | asyh->core.w,
187                                 0x046c + (i * 0x300), asyh->core.layout << 24 |
188                                                      (asyh->core.pitch >> 8) << 8 |
189                                                       asyh->core.blocks << 8 |
190                                                       asyh->core.blockh,
191                                 0x0470 + (i * 0x300), asyh->core.format << 8,
192                                 0x0474 + (i * 0x300), asyh->core.handle);
193         PUSH_NVSQ(push, NV907D, 0x04b0 + (i * 0x300), asyh->core.y << 16 | asyh->core.x);
194         return 0;
195 }
196
197 int
198 head907d_olut_clr(struct nv50_head *head)
199 {
200         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
201         const int i = head->base.index;
202         int ret;
203
204         if ((ret = PUSH_WAIT(push, 4)))
205                 return ret;
206
207         PUSH_NVSQ(push, NV907D, 0x0448 + (i * 0x300), 0x00000000);
208         PUSH_NVSQ(push, NV907D, 0x045c + (i * 0x300), 0x00000000);
209         return 0;
210 }
211
212 int
213 head907d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
214 {
215         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
216         const int i = head->base.index;
217         int ret;
218
219         if ((ret = PUSH_WAIT(push, 5)))
220                 return ret;
221
222         PUSH_NVSQ(push, NV907D, 0x0448 + (i * 0x300), 0x80000000 | asyh->olut.mode << 24,
223                                 0x044c + (i * 0x300), asyh->olut.offset >> 8);
224         PUSH_NVSQ(push, NV907D, 0x045c + (i * 0x300), asyh->olut.handle);
225         return 0;
226 }
227
228 void
229 head907d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
230 {
231         for (; size--; in++, mem += 8) {
232                 writew(drm_color_lut_extract(in->  red, 14) + 0x6000, mem + 0);
233                 writew(drm_color_lut_extract(in->green, 14) + 0x6000, mem + 2);
234                 writew(drm_color_lut_extract(in-> blue, 14) + 0x6000, mem + 4);
235         }
236
237         /* INTERPOLATE modes require a "next" entry to interpolate with,
238          * so we replicate the last entry to deal with this for now.
239          */
240         writew(readw(mem - 8), mem + 0);
241         writew(readw(mem - 6), mem + 2);
242         writew(readw(mem - 4), mem + 4);
243 }
244
245 bool
246 head907d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
247 {
248         if (size != 256 && size != 1024)
249                 return false;
250
251         asyh->olut.mode = size == 1024 ? 4 : 7;
252         asyh->olut.load = head907d_olut_load;
253         return true;
254 }
255
256 int
257 head907d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
258 {
259         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
260         struct nv50_head_mode *m = &asyh->mode;
261         const int i = head->base.index;
262         int ret;
263
264         if ((ret = PUSH_WAIT(push, 14)))
265                 return ret;
266
267         PUSH_NVSQ(push, NV907D, 0x0410 + (i * 0x300), 0x00000000,
268                                 0x0414 + (i * 0x300), m->v.active  << 16 | m->h.active,
269                                 0x0418 + (i * 0x300), m->v.synce   << 16 | m->h.synce,
270                                 0x041c + (i * 0x300), m->v.blanke  << 16 | m->h.blanke,
271                                 0x0420 + (i * 0x300), m->v.blanks  << 16 | m->h.blanks,
272                                 0x0424 + (i * 0x300), m->v.blank2e << 16 | m->v.blank2s);
273         PUSH_NVSQ(push, NV907D, 0x042c + (i * 0x300), 0x00000000,
274                                 0x0430 + (i * 0x300), 0xffffff00);
275         PUSH_NVSQ(push, NV907D, 0x0450 + (i * 0x300), m->clock * 1000,
276                                 0x0454 + (i * 0x300), 0x00200000,
277                                 0x0458 + (i * 0x300), m->clock * 1000);
278         return 0;
279 }
280
281 int
282 head907d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
283 {
284         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
285         const int i = head->base.index;
286         int ret;
287
288         if ((ret = PUSH_WAIT(push, 8)))
289                 return ret;
290
291         PUSH_NVSQ(push, NV907D, 0x0494 + (i * 0x300), 0x00000000);
292         PUSH_NVSQ(push, NV907D, 0x04b8 + (i * 0x300), asyh->view.iH << 16 | asyh->view.iW);
293         PUSH_NVSQ(push, NV907D, 0x04c0 + (i * 0x300), asyh->view.oH << 16 | asyh->view.oW,
294                                 0x04c4 + (i * 0x300), asyh->view.oH << 16 | asyh->view.oW,
295                                 0x04c8 + (i * 0x300), asyh->view.oH << 16 | asyh->view.oW);
296         return 0;
297 }
298
299 const struct nv50_head_func
300 head907d = {
301         .view = head907d_view,
302         .mode = head907d_mode,
303         .olut = head907d_olut,
304         .olut_size = 1024,
305         .olut_set = head907d_olut_set,
306         .olut_clr = head907d_olut_clr,
307         .core_calc = head507d_core_calc,
308         .core_set = head907d_core_set,
309         .core_clr = head907d_core_clr,
310         .curs_layout = head507d_curs_layout,
311         .curs_format = head507d_curs_format,
312         .curs_set = head907d_curs_set,
313         .curs_clr = head907d_curs_clr,
314         .base = head907d_base,
315         .ovly = head907d_ovly,
316         .dither = head907d_dither,
317         .procamp = head907d_procamp,
318         .or = head907d_or,
319 };