2 * Copyright 2018 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
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"
32 #include <nvif/push507c.h>
34 #include <nvhw/class/cl907d.h>
37 head907d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
39 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
40 const int i = head->base.index;
43 if ((ret = PUSH_WAIT(push, 3)))
46 PUSH_NVSQ(push, NV907D, 0x0404 + (i * 0x300), asyh->or.depth << 6 |
47 asyh->or.nvsync << 4 |
48 asyh->or.nhsync << 3 |
50 0x0408 + (i * 0x300), 0x31ec6000 |
51 head->base.index << 25 |
52 asyh->mode.interlace);
57 head907d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
59 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
60 const int i = head->base.index;
63 if ((ret = PUSH_WAIT(push, 2)))
66 PUSH_NVSQ(push, NV907D, 0x0498 + (i * 0x300), asyh->procamp.sat.sin << 20 |
67 asyh->procamp.sat.cos << 8);
72 head907d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
74 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
75 const int i = head->base.index;
78 if ((ret = PUSH_WAIT(push, 2)))
81 PUSH_NVSQ(push, NV907D, 0x0490 + (i * 0x300), asyh->dither.mode << 3 |
82 asyh->dither.bits << 1 |
88 head907d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
90 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
91 const int i = head->base.index;
96 switch (asyh->ovly.cpp) {
97 case 8: bounds |= 0x00000500; break;
98 case 4: bounds |= 0x00000300; break;
99 case 2: bounds |= 0x00000100; break;
104 bounds |= 0x00000001;
106 bounds |= 0x00000100;
109 if ((ret = PUSH_WAIT(push, 2)))
112 PUSH_NVSQ(push, NV907D, 0x04d4 + (i * 0x300), bounds);
117 head907d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
119 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
120 const int i = head->base.index;
124 if (asyh->base.cpp) {
125 switch (asyh->base.cpp) {
126 case 8: bounds |= 0x00000500; break;
127 case 4: bounds |= 0x00000300; break;
128 case 2: bounds |= 0x00000100; break;
129 case 1: bounds |= 0x00000000; break;
134 bounds |= 0x00000001;
137 if ((ret = PUSH_WAIT(push, 2)))
140 PUSH_NVSQ(push, NV907D, 0x04d0 + (i * 0x300), bounds);
145 head907d_curs_clr(struct nv50_head *head)
147 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
148 const int i = head->base.index;
151 if ((ret = PUSH_WAIT(push, 4)))
154 PUSH_NVSQ(push, NV907D, 0x0480 + (i * 0x300), 0x05000000);
155 PUSH_NVSQ(push, NV907D, 0x048c + (i * 0x300), 0x00000000);
160 head907d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
162 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
163 const int i = head->base.index;
166 if ((ret = PUSH_WAIT(push, 5)))
169 PUSH_NVSQ(push, NV907D, 0x0480 + (i * 0x300), 0x80000000 |
170 asyh->curs.layout << 26 |
171 asyh->curs.format << 24,
172 0x0484 + (i * 0x300), asyh->curs.offset >> 8);
173 PUSH_NVSQ(push, NV907D, 0x048c + (i * 0x300), asyh->curs.handle);
178 head907d_core_clr(struct nv50_head *head)
180 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
181 const int i = head->base.index;
184 if ((ret = PUSH_WAIT(push, 2)))
187 PUSH_NVSQ(push, NV907D, 0x0474 + (i * 0x300), 0x00000000);
192 head907d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
194 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
195 const int i = head->base.index;
198 if ((ret = PUSH_WAIT(push, 9)))
201 PUSH_NVSQ(push, NV907D, 0x0460 + (i * 0x300), asyh->core.offset >> 8);
202 PUSH_NVSQ(push, NV907D, 0x0468 + (i * 0x300), asyh->core.h << 16 | asyh->core.w,
203 0x046c + (i * 0x300), asyh->core.layout << 24 |
204 (asyh->core.pitch >> 8) << 8 |
205 asyh->core.blocks << 8 |
207 0x0470 + (i * 0x300), asyh->core.format << 8,
208 0x0474 + (i * 0x300), asyh->core.handle);
209 PUSH_NVSQ(push, NV907D, 0x04b0 + (i * 0x300), asyh->core.y << 16 | asyh->core.x);
214 head907d_olut_clr(struct nv50_head *head)
216 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
217 const int i = head->base.index;
220 if ((ret = PUSH_WAIT(push, 4)))
223 PUSH_NVSQ(push, NV907D, 0x0448 + (i * 0x300), 0x00000000);
224 PUSH_NVSQ(push, NV907D, 0x045c + (i * 0x300), 0x00000000);
229 head907d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
231 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
232 const int i = head->base.index;
235 if ((ret = PUSH_WAIT(push, 5)))
238 PUSH_NVSQ(push, NV907D, 0x0448 + (i * 0x300), 0x80000000 | asyh->olut.mode << 24,
239 0x044c + (i * 0x300), asyh->olut.offset >> 8);
240 PUSH_NVSQ(push, NV907D, 0x045c + (i * 0x300), asyh->olut.handle);
245 head907d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
247 for (; size--; in++, mem += 8) {
248 writew(drm_color_lut_extract(in-> red, 14) + 0x6000, mem + 0);
249 writew(drm_color_lut_extract(in->green, 14) + 0x6000, mem + 2);
250 writew(drm_color_lut_extract(in-> blue, 14) + 0x6000, mem + 4);
253 /* INTERPOLATE modes require a "next" entry to interpolate with,
254 * so we replicate the last entry to deal with this for now.
256 writew(readw(mem - 8), mem + 0);
257 writew(readw(mem - 6), mem + 2);
258 writew(readw(mem - 4), mem + 4);
262 head907d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
264 if (size != 256 && size != 1024)
267 asyh->olut.mode = size == 1024 ? 4 : 7;
268 asyh->olut.load = head907d_olut_load;
273 head907d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
275 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
276 struct nv50_head_mode *m = &asyh->mode;
277 const int i = head->base.index;
280 if ((ret = PUSH_WAIT(push, 14)))
283 PUSH_NVSQ(push, NV907D, 0x0410 + (i * 0x300), 0x00000000,
284 0x0414 + (i * 0x300), m->v.active << 16 | m->h.active,
285 0x0418 + (i * 0x300), m->v.synce << 16 | m->h.synce,
286 0x041c + (i * 0x300), m->v.blanke << 16 | m->h.blanke,
287 0x0420 + (i * 0x300), m->v.blanks << 16 | m->h.blanks,
288 0x0424 + (i * 0x300), m->v.blank2e << 16 | m->v.blank2s);
289 PUSH_NVSQ(push, NV907D, 0x042c + (i * 0x300), 0x00000000,
290 0x0430 + (i * 0x300), 0xffffff00);
291 PUSH_NVSQ(push, NV907D, 0x0450 + (i * 0x300), m->clock * 1000,
292 0x0454 + (i * 0x300), 0x00200000,
293 0x0458 + (i * 0x300), m->clock * 1000);
298 head907d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
300 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
301 const int i = head->base.index;
304 if ((ret = PUSH_WAIT(push, 8)))
307 PUSH_MTHD(push, NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER(i),
308 NVDEF(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, VERTICAL_TAPS, TAPS_1) |
309 NVDEF(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, HORIZONTAL_TAPS, TAPS_1) |
310 NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, HRESPONSE_BIAS, 0) |
311 NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, VRESPONSE_BIAS, 0));
313 PUSH_MTHD(push, NV907D, HEAD_SET_VIEWPORT_SIZE_IN(i),
314 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_IN, WIDTH, asyh->view.iW) |
315 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_IN, HEIGHT, asyh->view.iH));
317 PUSH_MTHD(push, NV907D, HEAD_SET_VIEWPORT_SIZE_OUT(i),
318 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT, WIDTH, asyh->view.oW) |
319 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT, HEIGHT, asyh->view.oH),
321 HEAD_SET_VIEWPORT_SIZE_OUT_MIN(i),
322 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MIN, WIDTH, asyh->view.oW) |
323 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MIN, HEIGHT, asyh->view.oH),
325 HEAD_SET_VIEWPORT_SIZE_OUT_MAX(i),
326 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MAX, WIDTH, asyh->view.oW) |
327 NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MAX, HEIGHT, asyh->view.oH));
331 const struct nv50_head_func
333 .view = head907d_view,
334 .mode = head907d_mode,
335 .olut = head907d_olut,
337 .olut_set = head907d_olut_set,
338 .olut_clr = head907d_olut_clr,
339 .core_calc = head507d_core_calc,
340 .core_set = head907d_core_set,
341 .core_clr = head907d_core_clr,
342 .curs_layout = head507d_curs_layout,
343 .curs_format = head507d_curs_format,
344 .curs_set = head907d_curs_set,
345 .curs_clr = head907d_curs_clr,
346 .base = head907d_base,
347 .ovly = head907d_ovly,
348 .dither = head907d_dither,
349 .procamp = head907d_procamp,