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"
33 head907d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
35 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
37 if ((push = evo_wait(core, 3))) {
38 evo_mthd(push, 0x0404 + (head->base.index * 0x300), 2);
39 evo_data(push, asyh->or.depth << 6 |
40 asyh->or.nvsync << 4 |
41 asyh->or.nhsync << 3 |
43 evo_data(push, 0x31ec6000 | head->base.index << 25 |
44 asyh->mode.interlace);
50 head907d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
52 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
54 if ((push = evo_wait(core, 2))) {
55 evo_mthd(push, 0x0498 + (head->base.index * 0x300), 1);
56 evo_data(push, asyh->procamp.sat.sin << 20 |
57 asyh->procamp.sat.cos << 8);
63 head907d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
65 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
67 if ((push = evo_wait(core, 2))) {
68 evo_mthd(push, 0x0490 + (head->base.index * 0x0300), 1);
69 evo_data(push, asyh->dither.mode << 3 |
70 asyh->dither.bits << 1 |
77 head907d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
79 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
84 switch (asyh->ovly.cpp) {
85 case 8: bounds |= 0x00000500; break;
86 case 4: bounds |= 0x00000300; break;
87 case 2: bounds |= 0x00000100; break;
97 if ((push = evo_wait(core, 2))) {
98 evo_mthd(push, 0x04d4 + head->base.index * 0x300, 1);
99 evo_data(push, bounds);
100 evo_kick(push, core);
105 head907d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
107 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
111 if (asyh->base.cpp) {
112 switch (asyh->base.cpp) {
113 case 8: bounds |= 0x00000500; break;
114 case 4: bounds |= 0x00000300; break;
115 case 2: bounds |= 0x00000100; break;
116 case 1: bounds |= 0x00000000; break;
121 bounds |= 0x00000001;
124 if ((push = evo_wait(core, 2))) {
125 evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1);
126 evo_data(push, bounds);
127 evo_kick(push, core);
132 head907d_curs_clr(struct nv50_head *head)
134 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
136 if ((push = evo_wait(core, 4))) {
137 evo_mthd(push, 0x0480 + head->base.index * 0x300, 1);
138 evo_data(push, 0x05000000);
139 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
140 evo_data(push, 0x00000000);
141 evo_kick(push, core);
146 head907d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
148 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
150 if ((push = evo_wait(core, 5))) {
151 evo_mthd(push, 0x0480 + head->base.index * 0x300, 2);
152 evo_data(push, 0x80000000 | asyh->curs.layout << 26 |
153 asyh->curs.format << 24);
154 evo_data(push, asyh->curs.offset >> 8);
155 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
156 evo_data(push, asyh->curs.handle);
157 evo_kick(push, core);
162 head907d_core_clr(struct nv50_head *head)
164 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
166 if ((push = evo_wait(core, 2))) {
167 evo_mthd(push, 0x0474 + head->base.index * 0x300, 1);
168 evo_data(push, 0x00000000);
169 evo_kick(push, core);
174 head907d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
176 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
178 if ((push = evo_wait(core, 9))) {
179 evo_mthd(push, 0x0460 + head->base.index * 0x300, 1);
180 evo_data(push, asyh->core.offset >> 8);
181 evo_mthd(push, 0x0468 + head->base.index * 0x300, 4);
182 evo_data(push, asyh->core.h << 16 | asyh->core.w);
183 evo_data(push, asyh->core.layout << 24 |
184 (asyh->core.pitch >> 8) << 8 |
185 asyh->core.blocks << 8 |
187 evo_data(push, asyh->core.format << 8);
188 evo_data(push, asyh->core.handle);
189 evo_mthd(push, 0x04b0 + head->base.index * 0x300, 1);
190 evo_data(push, asyh->core.y << 16 | asyh->core.x);
191 evo_kick(push, core);
196 head907d_olut_clr(struct nv50_head *head)
198 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
200 if ((push = evo_wait(core, 4))) {
201 evo_mthd(push, 0x0448 + (head->base.index * 0x300), 1);
202 evo_data(push, 0x00000000);
203 evo_mthd(push, 0x045c + (head->base.index * 0x300), 1);
204 evo_data(push, 0x00000000);
205 evo_kick(push, core);
210 head907d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
212 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
214 if ((push = evo_wait(core, 5))) {
215 evo_mthd(push, 0x0448 + (head->base.index * 0x300), 2);
216 evo_data(push, 0x80000000 | asyh->olut.mode << 24);
217 evo_data(push, asyh->olut.offset >> 8);
218 evo_mthd(push, 0x045c + (head->base.index * 0x300), 1);
219 evo_data(push, asyh->olut.handle);
220 evo_kick(push, core);
225 head907d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
227 for (; size--; in++, mem += 8) {
228 writew(drm_color_lut_extract(in-> red, 14) + 0x6000, mem + 0);
229 writew(drm_color_lut_extract(in->green, 14) + 0x6000, mem + 2);
230 writew(drm_color_lut_extract(in-> blue, 14) + 0x6000, mem + 4);
233 /* INTERPOLATE modes require a "next" entry to interpolate with,
234 * so we replicate the last entry to deal with this for now.
236 writew(readw(mem - 8), mem + 0);
237 writew(readw(mem - 6), mem + 2);
238 writew(readw(mem - 4), mem + 4);
242 head907d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
244 if (size != 256 && size != 1024)
247 asyh->olut.mode = size == 1024 ? 4 : 7;
248 asyh->olut.load = head907d_olut_load;
253 head907d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
255 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
256 struct nv50_head_mode *m = &asyh->mode;
258 if ((push = evo_wait(core, 14))) {
259 evo_mthd(push, 0x0410 + (head->base.index * 0x300), 6);
260 evo_data(push, 0x00000000);
261 evo_data(push, m->v.active << 16 | m->h.active );
262 evo_data(push, m->v.synce << 16 | m->h.synce );
263 evo_data(push, m->v.blanke << 16 | m->h.blanke );
264 evo_data(push, m->v.blanks << 16 | m->h.blanks );
265 evo_data(push, m->v.blank2e << 16 | m->v.blank2s);
266 evo_mthd(push, 0x042c + (head->base.index * 0x300), 2);
267 evo_data(push, 0x00000000); /* ??? */
268 evo_data(push, 0xffffff00);
269 evo_mthd(push, 0x0450 + (head->base.index * 0x300), 3);
270 evo_data(push, m->clock * 1000);
271 evo_data(push, 0x00200000); /* ??? */
272 evo_data(push, m->clock * 1000);
273 evo_kick(push, core);
278 head907d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
280 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
282 if ((push = evo_wait(core, 8))) {
283 evo_mthd(push, 0x0494 + (head->base.index * 0x300), 1);
284 evo_data(push, 0x00000000);
285 evo_mthd(push, 0x04b8 + (head->base.index * 0x300), 1);
286 evo_data(push, asyh->view.iH << 16 | asyh->view.iW);
287 evo_mthd(push, 0x04c0 + (head->base.index * 0x300), 3);
288 evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
289 evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
290 evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
291 evo_kick(push, core);
295 const struct nv50_head_func
297 .view = head907d_view,
298 .mode = head907d_mode,
299 .olut = head907d_olut,
301 .olut_set = head907d_olut_set,
302 .olut_clr = head907d_olut_clr,
303 .core_calc = head507d_core_calc,
304 .core_set = head907d_core_set,
305 .core_clr = head907d_core_clr,
306 .curs_layout = head507d_curs_layout,
307 .curs_format = head507d_curs_format,
308 .curs_set = head907d_curs_set,
309 .curs_clr = head907d_curs_clr,
310 .base = head907d_base,
311 .ovly = head907d_ovly,
312 .dither = head907d_dither,
313 .procamp = head907d_procamp,