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>
35 head907d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
37 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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 |
45 evo_data(push, 0x31ec6000 | head->base.index << 25 |
46 asyh->mode.interlace);
52 head907d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
54 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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);
65 head907d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
67 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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 |
79 head907d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
81 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
86 switch (asyh->ovly.cpp) {
87 case 8: bounds |= 0x00000500; break;
88 case 4: bounds |= 0x00000300; break;
89 case 2: bounds |= 0x00000100; break;
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);
107 head907d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
109 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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;
123 bounds |= 0x00000001;
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);
134 head907d_curs_clr(struct nv50_head *head)
136 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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);
148 head907d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
150 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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);
164 head907d_core_clr(struct nv50_head *head)
166 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
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);
176 head907d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
178 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
179 const int i = head->base.index;
182 if ((ret = PUSH_WAIT(push, 9)))
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 |
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);
198 head907d_olut_clr(struct nv50_head *head)
200 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
201 const int i = head->base.index;
204 if ((ret = PUSH_WAIT(push, 4)))
207 PUSH_NVSQ(push, NV907D, 0x0448 + (i * 0x300), 0x00000000);
208 PUSH_NVSQ(push, NV907D, 0x045c + (i * 0x300), 0x00000000);
213 head907d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
215 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
216 const int i = head->base.index;
219 if ((ret = PUSH_WAIT(push, 5)))
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);
229 head907d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
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);
237 /* INTERPOLATE modes require a "next" entry to interpolate with,
238 * so we replicate the last entry to deal with this for now.
240 writew(readw(mem - 8), mem + 0);
241 writew(readw(mem - 6), mem + 2);
242 writew(readw(mem - 4), mem + 4);
246 head907d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
248 if (size != 256 && size != 1024)
251 asyh->olut.mode = size == 1024 ? 4 : 7;
252 asyh->olut.load = head907d_olut_load;
257 head907d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
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;
264 if ((ret = PUSH_WAIT(push, 14)))
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);
282 head907d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
284 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
285 const int i = head->base.index;
288 if ((ret = PUSH_WAIT(push, 8)))
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);
299 const struct nv50_head_func
301 .view = head907d_view,
302 .mode = head907d_mode,
303 .olut = head907d_olut,
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,