2 * Copyright 2012 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.
27 #include <core/client.h>
28 #include <core/enum.h>
29 #include <core/gpuobj.h>
30 #include <subdev/bios.h>
31 #include <subdev/bios/disp.h>
32 #include <subdev/bios/init.h>
33 #include <subdev/bios/pll.h>
34 #include <subdev/devinit.h>
35 #include <subdev/timer.h>
37 static const struct nvkm_disp_oclass *
38 nv50_disp_root_(struct nvkm_disp *base)
40 return nv50_disp(base)->func->root;
44 nv50_disp_outp_internal_crt_(struct nvkm_disp *base, int index,
45 struct dcb_output *dcb, struct nvkm_output **poutp)
47 struct nv50_disp *disp = nv50_disp(base);
48 return disp->func->outp.internal.crt(base, index, dcb, poutp);
52 nv50_disp_outp_internal_tmds_(struct nvkm_disp *base, int index,
53 struct dcb_output *dcb,
54 struct nvkm_output **poutp)
56 struct nv50_disp *disp = nv50_disp(base);
57 return disp->func->outp.internal.tmds(base, index, dcb, poutp);
61 nv50_disp_outp_internal_lvds_(struct nvkm_disp *base, int index,
62 struct dcb_output *dcb,
63 struct nvkm_output **poutp)
65 struct nv50_disp *disp = nv50_disp(base);
66 return disp->func->outp.internal.lvds(base, index, dcb, poutp);
70 nv50_disp_outp_internal_dp_(struct nvkm_disp *base, int index,
71 struct dcb_output *dcb, struct nvkm_output **poutp)
73 struct nv50_disp *disp = nv50_disp(base);
74 if (disp->func->outp.internal.dp)
75 return disp->func->outp.internal.dp(base, index, dcb, poutp);
80 nv50_disp_outp_external_tmds_(struct nvkm_disp *base, int index,
81 struct dcb_output *dcb,
82 struct nvkm_output **poutp)
84 struct nv50_disp *disp = nv50_disp(base);
85 if (disp->func->outp.external.tmds)
86 return disp->func->outp.external.tmds(base, index, dcb, poutp);
91 nv50_disp_outp_external_dp_(struct nvkm_disp *base, int index,
92 struct dcb_output *dcb, struct nvkm_output **poutp)
94 struct nv50_disp *disp = nv50_disp(base);
95 if (disp->func->outp.external.dp)
96 return disp->func->outp.external.dp(base, index, dcb, poutp);
101 nv50_disp_vblank_fini_(struct nvkm_disp *base, int head)
103 struct nv50_disp *disp = nv50_disp(base);
104 disp->func->head.vblank_fini(disp, head);
108 nv50_disp_vblank_init_(struct nvkm_disp *base, int head)
110 struct nv50_disp *disp = nv50_disp(base);
111 disp->func->head.vblank_init(disp, head);
115 nv50_disp_intr_(struct nvkm_disp *base)
117 struct nv50_disp *disp = nv50_disp(base);
118 disp->func->intr(disp);
122 nv50_disp_dtor_(struct nvkm_disp *base)
124 struct nv50_disp *disp = nv50_disp(base);
125 nvkm_event_fini(&disp->uevent);
129 static const struct nvkm_disp_func
131 .dtor = nv50_disp_dtor_,
132 .intr = nv50_disp_intr_,
133 .root = nv50_disp_root_,
134 .outp.internal.crt = nv50_disp_outp_internal_crt_,
135 .outp.internal.tmds = nv50_disp_outp_internal_tmds_,
136 .outp.internal.lvds = nv50_disp_outp_internal_lvds_,
137 .outp.internal.dp = nv50_disp_outp_internal_dp_,
138 .outp.external.tmds = nv50_disp_outp_external_tmds_,
139 .outp.external.dp = nv50_disp_outp_external_dp_,
140 .head.vblank_init = nv50_disp_vblank_init_,
141 .head.vblank_fini = nv50_disp_vblank_fini_,
145 nv50_disp_new_(const struct nv50_disp_func *func, struct nvkm_device *device,
146 int index, int heads, struct nvkm_disp **pdisp)
148 struct nv50_disp *disp;
151 if (!(disp = kzalloc(sizeof(*disp), GFP_KERNEL)))
153 INIT_WORK(&disp->supervisor, func->super);
155 *pdisp = &disp->base;
157 ret = nvkm_disp_ctor(&nv50_disp_, device, index, heads, &disp->base);
161 return nvkm_event_init(func->uevent, 1, 1 + (heads * 4), &disp->uevent);
165 nv50_disp_vblank_fini(struct nv50_disp *disp, int head)
167 struct nvkm_device *device = disp->base.engine.subdev.device;
168 nvkm_mask(device, 0x61002c, (4 << head), 0);
172 nv50_disp_vblank_init(struct nv50_disp *disp, int head)
174 struct nvkm_device *device = disp->base.engine.subdev.device;
175 nvkm_mask(device, 0x61002c, (4 << head), (4 << head));
178 static const struct nvkm_enum
179 nv50_disp_intr_error_type[] = {
180 { 3, "ILLEGAL_MTHD" },
181 { 4, "INVALID_VALUE" },
182 { 5, "INVALID_STATE" },
183 { 7, "INVALID_HANDLE" },
187 static const struct nvkm_enum
188 nv50_disp_intr_error_code[] = {
194 nv50_disp_intr_error(struct nv50_disp *disp, int chid)
196 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
197 struct nvkm_device *device = subdev->device;
198 u32 data = nvkm_rd32(device, 0x610084 + (chid * 0x08));
199 u32 addr = nvkm_rd32(device, 0x610080 + (chid * 0x08));
200 u32 code = (addr & 0x00ff0000) >> 16;
201 u32 type = (addr & 0x00007000) >> 12;
202 u32 mthd = (addr & 0x00000ffc);
203 const struct nvkm_enum *ec, *et;
205 et = nvkm_enum_find(nv50_disp_intr_error_type, type);
206 ec = nvkm_enum_find(nv50_disp_intr_error_code, code);
209 "ERROR %d [%s] %02x [%s] chid %d mthd %04x data %08x\n",
210 type, et ? et->name : "", code, ec ? ec->name : "",
213 if (chid < ARRAY_SIZE(disp->chan)) {
216 nv50_disp_chan_mthd(disp->chan[chid], NV_DBG_ERROR);
223 nvkm_wr32(device, 0x610020, 0x00010000 << chid);
224 nvkm_wr32(device, 0x610080 + (chid * 0x08), 0x90000000);
227 static struct nvkm_output *
228 exec_lookup(struct nv50_disp *disp, int head, int or, u32 ctrl,
229 u32 *data, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
230 struct nvbios_outp *info)
232 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
233 struct nvkm_bios *bios = subdev->device->bios;
234 struct nvkm_output *outp;
238 type = DCB_OUTPUT_ANALOG;
242 switch (ctrl & 0x00000f00) {
243 case 0x00000000: type = DCB_OUTPUT_LVDS; mask = 1; break;
244 case 0x00000100: type = DCB_OUTPUT_TMDS; mask = 1; break;
245 case 0x00000200: type = DCB_OUTPUT_TMDS; mask = 2; break;
246 case 0x00000500: type = DCB_OUTPUT_TMDS; mask = 3; break;
247 case 0x00000800: type = DCB_OUTPUT_DP; mask = 1; break;
248 case 0x00000900: type = DCB_OUTPUT_DP; mask = 2; break;
250 nvkm_error(subdev, "unknown SOR mc %08x\n", ctrl);
258 switch (ctrl & 0x00000f00) {
259 case 0x00000000: type |= disp->pior.type[or]; break;
261 nvkm_error(subdev, "unknown PIOR mc %08x\n", ctrl);
266 mask = 0x00c0 & (mask << 6);
267 mask |= 0x0001 << or;
268 mask |= 0x0100 << head;
270 list_for_each_entry(outp, &disp->base.outp, head) {
271 if ((outp->info.hasht & 0xff) == type &&
272 (outp->info.hashm & mask) == mask) {
273 *data = nvbios_outp_match(bios, outp->info.hasht, mask,
274 ver, hdr, cnt, len, info);
284 static struct nvkm_output *
285 exec_script(struct nv50_disp *disp, int head, int id)
287 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
288 struct nvkm_device *device = subdev->device;
289 struct nvkm_bios *bios = device->bios;
290 struct nvkm_output *outp;
291 struct nvbios_outp info;
292 u8 ver, hdr, cnt, len;
298 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->dac.nr; i++)
299 ctrl = nvkm_rd32(device, 0x610b5c + (i * 8));
302 if (!(ctrl & (1 << head))) {
303 if (device->chipset < 0x90 ||
304 device->chipset == 0x92 ||
305 device->chipset == 0xa0) {
310 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->sor.nr; i++)
311 ctrl = nvkm_rd32(device, reg + (i * 8));
316 if (!(ctrl & (1 << head))) {
317 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->pior.nr; i++)
318 ctrl = nvkm_rd32(device, 0x610b84 + (i * 8));
322 if (!(ctrl & (1 << head)))
326 outp = exec_lookup(disp, head, i, ctrl, &data, &ver, &hdr, &cnt, &len, &info);
328 struct nvbios_init init = {
331 .offset = info.script[id],
343 static struct nvkm_output *
344 exec_clkcmp(struct nv50_disp *disp, int head, int id, u32 pclk, u32 *conf)
346 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
347 struct nvkm_device *device = subdev->device;
348 struct nvkm_bios *bios = device->bios;
349 struct nvkm_output *outp;
350 struct nvbios_outp info1;
351 struct nvbios_ocfg info2;
352 u8 ver, hdr, cnt, len;
358 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->dac.nr; i++)
359 ctrl = nvkm_rd32(device, 0x610b58 + (i * 8));
362 if (!(ctrl & (1 << head))) {
363 if (device->chipset < 0x90 ||
364 device->chipset == 0x92 ||
365 device->chipset == 0xa0) {
370 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->sor.nr; i++)
371 ctrl = nvkm_rd32(device, reg + (i * 8));
376 if (!(ctrl & (1 << head))) {
377 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->pior.nr; i++)
378 ctrl = nvkm_rd32(device, 0x610b80 + (i * 8));
382 if (!(ctrl & (1 << head)))
386 outp = exec_lookup(disp, head, i, ctrl, &data, &ver, &hdr, &cnt, &len, &info1);
390 *conf = (ctrl & 0x00000f00) >> 8;
391 if (outp->info.location == 0) {
392 switch (outp->info.type) {
393 case DCB_OUTPUT_TMDS:
397 case DCB_OUTPUT_LVDS:
398 *conf |= disp->sor.lvdsconf;
404 *conf = (ctrl & 0x00000f00) >> 8;
408 data = nvbios_ocfg_match(bios, data, *conf & 0xff, *conf >> 8,
409 &ver, &hdr, &cnt, &len, &info2);
410 if (data && id < 0xff) {
411 data = nvbios_oclk_match(bios, info2.clkcmp[id], pclk);
413 struct nvbios_init init = {
430 nv50_disp_dptmds_war(struct nvkm_device *device)
432 switch (device->chipset) {
444 nv50_disp_dptmds_war_needed(struct nv50_disp *disp, struct dcb_output *outp)
446 struct nvkm_device *device = disp->base.engine.subdev.device;
447 const u32 soff = __ffs(outp->or) * 0x800;
448 if (nv50_disp_dptmds_war(device) && outp->type == DCB_OUTPUT_TMDS) {
449 switch (nvkm_rd32(device, 0x614300 + soff) & 0x00030000) {
462 nv50_disp_dptmds_war_2(struct nv50_disp *disp, struct dcb_output *outp)
464 struct nvkm_device *device = disp->base.engine.subdev.device;
465 const u32 soff = __ffs(outp->or) * 0x800;
467 if (!nv50_disp_dptmds_war_needed(disp, outp))
470 nvkm_mask(device, 0x00e840, 0x80000000, 0x80000000);
471 nvkm_mask(device, 0x614300 + soff, 0x03000000, 0x03000000);
472 nvkm_mask(device, 0x61c10c + soff, 0x00000001, 0x00000001);
474 nvkm_mask(device, 0x61c00c + soff, 0x0f000000, 0x00000000);
475 nvkm_mask(device, 0x61c008 + soff, 0xff000000, 0x14000000);
476 nvkm_usec(device, 400, NVKM_DELAY);
477 nvkm_mask(device, 0x61c008 + soff, 0xff000000, 0x00000000);
478 nvkm_mask(device, 0x61c00c + soff, 0x0f000000, 0x01000000);
480 if (nvkm_rd32(device, 0x61c004 + soff) & 0x00000001) {
481 u32 seqctl = nvkm_rd32(device, 0x61c030 + soff);
482 u32 pu_pc = seqctl & 0x0000000f;
483 nvkm_wr32(device, 0x61c040 + soff + pu_pc * 4, 0x1f008000);
488 nv50_disp_dptmds_war_3(struct nv50_disp *disp, struct dcb_output *outp)
490 struct nvkm_device *device = disp->base.engine.subdev.device;
491 const u32 soff = __ffs(outp->or) * 0x800;
494 if (!nv50_disp_dptmds_war_needed(disp, outp))
497 sorpwr = nvkm_rd32(device, 0x61c004 + soff);
498 if (sorpwr & 0x00000001) {
499 u32 seqctl = nvkm_rd32(device, 0x61c030 + soff);
500 u32 pd_pc = (seqctl & 0x00000f00) >> 8;
501 u32 pu_pc = seqctl & 0x0000000f;
503 nvkm_wr32(device, 0x61c040 + soff + pd_pc * 4, 0x1f008000);
505 nvkm_msec(device, 2000,
506 if (!(nvkm_rd32(device, 0x61c030 + soff) & 0x10000000))
509 nvkm_mask(device, 0x61c004 + soff, 0x80000001, 0x80000000);
510 nvkm_msec(device, 2000,
511 if (!(nvkm_rd32(device, 0x61c030 + soff) & 0x10000000))
515 nvkm_wr32(device, 0x61c040 + soff + pd_pc * 4, 0x00002000);
516 nvkm_wr32(device, 0x61c040 + soff + pu_pc * 4, 0x1f000000);
519 nvkm_mask(device, 0x61c10c + soff, 0x00000001, 0x00000000);
520 nvkm_mask(device, 0x614300 + soff, 0x03000000, 0x00000000);
522 if (sorpwr & 0x00000001) {
523 nvkm_mask(device, 0x61c004 + soff, 0x80000001, 0x80000001);
528 nv50_disp_update_sppll1(struct nv50_disp *disp)
530 struct nvkm_device *device = disp->base.engine.subdev.device;
534 if (!nv50_disp_dptmds_war(device))
537 for (sor = 0; sor < disp->func->sor.nr; sor++) {
538 u32 clksor = nvkm_rd32(device, 0x614300 + (sor * 0x800));
539 switch (clksor & 0x03000000) {
552 nvkm_mask(device, 0x00e840, 0x80000000, 0x00000000);
556 nv50_disp_intr_unk10_0(struct nv50_disp *disp, int head)
558 exec_script(disp, head, 1);
562 nv50_disp_intr_unk20_0(struct nv50_disp *disp, int head)
564 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
565 struct nvkm_output *outp = exec_script(disp, head, 2);
567 /* the binary driver does this outside of the supervisor handling
568 * (after the third supervisor from a detach). we (currently?)
569 * allow both detach/attach to happen in the same set of
570 * supervisor interrupts, so it would make sense to execute this
571 * (full power down?) script after all the detach phases of the
572 * supervisor handling. like with training if needed from the
573 * second supervisor, nvidia doesn't do this, so who knows if it's
574 * entirely safe, but it does appear to work..
576 * without this script being run, on some configurations i've
577 * seen, switching from DP to TMDS on a DP connector may result
578 * in a blank screen (SOR_PWR off/on can restore it)
580 if (outp && outp->info.type == DCB_OUTPUT_DP) {
581 struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
582 struct nvbios_init init = {
584 .bios = subdev->device->bios,
587 .offset = outpdp->info.script[4],
592 atomic_set(&outpdp->lt.done, 0);
597 nv50_disp_intr_unk20_1(struct nv50_disp *disp, int head)
599 struct nvkm_device *device = disp->base.engine.subdev.device;
600 struct nvkm_devinit *devinit = device->devinit;
601 u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
603 nvkm_devinit_pll_set(devinit, PLL_VPLL0 + head, pclk);
607 nv50_disp_intr_unk20_2_dp(struct nv50_disp *disp, int head,
608 struct dcb_output *outp, u32 pclk)
610 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
611 struct nvkm_device *device = subdev->device;
612 const int link = !(outp->sorconf.link & 1);
613 const int or = ffs(outp->or) - 1;
614 const u32 soff = ( or * 0x800);
615 const u32 loff = (link * 0x080) + soff;
616 const u32 ctrl = nvkm_rd32(device, 0x610794 + (or * 8));
617 const u32 symbol = 100000;
618 const s32 vactive = nvkm_rd32(device, 0x610af8 + (head * 0x540)) & 0xffff;
619 const s32 vblanke = nvkm_rd32(device, 0x610ae8 + (head * 0x540)) & 0xffff;
620 const s32 vblanks = nvkm_rd32(device, 0x610af0 + (head * 0x540)) & 0xffff;
621 u32 dpctrl = nvkm_rd32(device, 0x61c10c + loff);
622 u32 clksor = nvkm_rd32(device, 0x614300 + soff);
623 int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
624 int TU, VTUi, VTUf, VTUa;
625 u64 link_data_rate, link_ratio, unk;
626 u32 best_diff = 64 * symbol;
627 u32 link_nr, link_bw, bits;
630 link_bw = (clksor & 0x000c0000) ? 270000 : 162000;
631 link_nr = hweight32(dpctrl & 0x000f0000);
633 /* symbols/hblank - algorithm taken from comments in tegra driver */
634 value = vblanke + vactive - vblanks - 7;
635 value = value * link_bw;
637 value = value - (3 * !!(dpctrl & 0x00004000)) - (12 / link_nr);
638 nvkm_mask(device, 0x61c1e8 + soff, 0x0000ffff, value);
640 /* symbols/vblank - algorithm taken from comments in tegra driver */
641 value = vblanks - vblanke - 25;
642 value = value * link_bw;
644 value = value - ((36 / link_nr) + 3) - 1;
645 nvkm_mask(device, 0x61c1ec + soff, 0x00ffffff, value);
647 /* watermark / activesym */
648 if ((ctrl & 0xf0000) == 0x60000) bits = 30;
649 else if ((ctrl & 0xf0000) == 0x50000) bits = 24;
652 link_data_rate = (pclk * bits / 8) / link_nr;
654 /* calculate ratio of packed data rate to link symbol rate */
655 link_ratio = link_data_rate * symbol;
656 do_div(link_ratio, link_bw);
658 for (TU = 64; TU >= 32; TU--) {
659 /* calculate average number of valid symbols in each TU */
660 u32 tu_valid = link_ratio * TU;
663 /* find a hw representation for the fraction.. */
664 VTUi = tu_valid / symbol;
665 calc = VTUi * symbol;
666 diff = tu_valid - calc;
668 if (diff >= (symbol / 2)) {
669 VTUf = symbol / (symbol - diff);
670 if (symbol - (VTUf * diff))
675 calc += symbol - (symbol / VTUf);
683 VTUf = min((int)(symbol / diff), 15);
684 calc += symbol / VTUf;
687 diff = calc - tu_valid;
689 /* no remainder, but the hw doesn't like the fractional
690 * part to be zero. decrement the integer part and
691 * have the fraction add a whole symbol back
698 if (diff < best_diff) {
710 nvkm_error(subdev, "unable to find suitable dp config\n");
714 /* XXX close to vbios numbers, but not right */
715 unk = (symbol - link_ratio) * bestTU;
721 nvkm_mask(device, 0x61c10c + loff, 0x000001fc, bestTU << 2);
722 nvkm_mask(device, 0x61c128 + loff, 0x010f7f3f, bestVTUa << 24 |
724 bestVTUi << 8 | unk);
728 nv50_disp_intr_unk20_2(struct nv50_disp *disp, int head)
730 struct nvkm_device *device = disp->base.engine.subdev.device;
731 struct nvkm_output *outp;
732 u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
733 u32 hval, hreg = 0x614200 + (head * 0x800);
737 outp = exec_clkcmp(disp, head, 0xff, pclk, &conf);
741 /* we allow both encoder attach and detach operations to occur
742 * within a single supervisor (ie. modeset) sequence. the
743 * encoder detach scripts quite often switch off power to the
744 * lanes, which requires the link to be re-trained.
746 * this is not generally an issue as the sink "must" (heh)
747 * signal an irq when it's lost sync so the driver can
750 * however, on some boards, if one does not configure at least
751 * the gpu side of the link *before* attaching, then various
752 * things can go horribly wrong (PDISP disappearing from mmio,
753 * third supervisor never happens, etc).
755 * the solution is simply to retrain here, if necessary. last
756 * i checked, the binary driver userspace does not appear to
757 * trigger this situation (it forces an UPDATE between steps).
759 if (outp->info.type == DCB_OUTPUT_DP) {
760 u32 soff = (ffs(outp->info.or) - 1) * 0x08;
763 if (outp->info.location == 0) {
764 ctrl = nvkm_rd32(device, 0x610794 + soff);
767 ctrl = nvkm_rd32(device, 0x610b80 + soff);
771 switch ((ctrl & 0x000f0000) >> 16) {
772 case 6: datarate = pclk * 30; break;
773 case 5: datarate = pclk * 24; break;
776 datarate = pclk * 18;
780 if (nvkm_output_dp_train(outp, datarate / soff, true))
781 OUTP_ERR(outp, "link not trained before attach");
784 exec_clkcmp(disp, head, 0, pclk, &conf);
786 if (!outp->info.location && outp->info.type == DCB_OUTPUT_ANALOG) {
787 oreg = 0x614280 + (ffs(outp->info.or) - 1) * 0x800;
792 if (!outp->info.location) {
793 if (outp->info.type == DCB_OUTPUT_DP)
794 nv50_disp_intr_unk20_2_dp(disp, head, &outp->info, pclk);
795 oreg = 0x614300 + (ffs(outp->info.or) - 1) * 0x800;
796 oval = (conf & 0x0100) ? 0x00000101 : 0x00000000;
800 oreg = 0x614380 + (ffs(outp->info.or) - 1) * 0x800;
806 nvkm_mask(device, hreg, 0x0000000f, hval);
807 nvkm_mask(device, oreg, mask, oval);
809 nv50_disp_dptmds_war_2(disp, &outp->info);
812 /* If programming a TMDS output on a SOR that can also be configured for
813 * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
815 * It looks like the VBIOS TMDS scripts make an attempt at this, however,
816 * the VBIOS scripts on at least one board I have only switch it off on
817 * link 0, causing a blank display if the output has previously been
818 * programmed for DisplayPort.
821 nv50_disp_intr_unk40_0_tmds(struct nv50_disp *disp,
822 struct dcb_output *outp)
824 struct nvkm_device *device = disp->base.engine.subdev.device;
825 struct nvkm_bios *bios = device->bios;
826 const int link = !(outp->sorconf.link & 1);
827 const int or = ffs(outp->or) - 1;
828 const u32 loff = (or * 0x800) + (link * 0x80);
829 const u16 mask = (outp->sorconf.link << 6) | outp->or;
830 struct dcb_output match;
833 if (dcb_outp_match(bios, DCB_OUTPUT_DP, mask, &ver, &hdr, &match))
834 nvkm_mask(device, 0x61c10c + loff, 0x00000001, 0x00000000);
838 nv50_disp_intr_unk40_0(struct nv50_disp *disp, int head)
840 struct nvkm_device *device = disp->base.engine.subdev.device;
841 struct nvkm_output *outp;
842 u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
845 outp = exec_clkcmp(disp, head, 1, pclk, &conf);
849 if (outp->info.location == 0 && outp->info.type == DCB_OUTPUT_TMDS)
850 nv50_disp_intr_unk40_0_tmds(disp, &outp->info);
851 nv50_disp_dptmds_war_3(disp, &outp->info);
855 nv50_disp_intr_supervisor(struct work_struct *work)
857 struct nv50_disp *disp =
858 container_of(work, struct nv50_disp, supervisor);
859 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
860 struct nvkm_device *device = subdev->device;
861 u32 super = nvkm_rd32(device, 0x610030);
864 nvkm_debug(subdev, "supervisor %08x %08x\n", disp->super, super);
866 if (disp->super & 0x00000010) {
867 nv50_disp_chan_mthd(disp->chan[0], NV_DBG_DEBUG);
868 for (head = 0; head < disp->base.head.nr; head++) {
869 if (!(super & (0x00000020 << head)))
871 if (!(super & (0x00000080 << head)))
873 nv50_disp_intr_unk10_0(disp, head);
876 if (disp->super & 0x00000020) {
877 for (head = 0; head < disp->base.head.nr; head++) {
878 if (!(super & (0x00000080 << head)))
880 nv50_disp_intr_unk20_0(disp, head);
882 for (head = 0; head < disp->base.head.nr; head++) {
883 if (!(super & (0x00000200 << head)))
885 nv50_disp_intr_unk20_1(disp, head);
887 for (head = 0; head < disp->base.head.nr; head++) {
888 if (!(super & (0x00000080 << head)))
890 nv50_disp_intr_unk20_2(disp, head);
893 if (disp->super & 0x00000040) {
894 for (head = 0; head < disp->base.head.nr; head++) {
895 if (!(super & (0x00000080 << head)))
897 nv50_disp_intr_unk40_0(disp, head);
899 nv50_disp_update_sppll1(disp);
902 nvkm_wr32(device, 0x610030, 0x80000000);
906 nv50_disp_intr(struct nv50_disp *disp)
908 struct nvkm_device *device = disp->base.engine.subdev.device;
909 u32 intr0 = nvkm_rd32(device, 0x610020);
910 u32 intr1 = nvkm_rd32(device, 0x610024);
912 while (intr0 & 0x001f0000) {
913 u32 chid = __ffs(intr0 & 0x001f0000) - 16;
914 nv50_disp_intr_error(disp, chid);
915 intr0 &= ~(0x00010000 << chid);
918 while (intr0 & 0x0000001f) {
919 u32 chid = __ffs(intr0 & 0x0000001f);
920 nv50_disp_chan_uevent_send(disp, chid);
921 intr0 &= ~(0x00000001 << chid);
924 if (intr1 & 0x00000004) {
925 nvkm_disp_vblank(&disp->base, 0);
926 nvkm_wr32(device, 0x610024, 0x00000004);
929 if (intr1 & 0x00000008) {
930 nvkm_disp_vblank(&disp->base, 1);
931 nvkm_wr32(device, 0x610024, 0x00000008);
934 if (intr1 & 0x00000070) {
935 disp->super = (intr1 & 0x00000070);
936 schedule_work(&disp->supervisor);
937 nvkm_wr32(device, 0x610024, disp->super);
941 static const struct nv50_disp_func
943 .intr = nv50_disp_intr,
944 .uevent = &nv50_disp_chan_uevent,
945 .super = nv50_disp_intr_supervisor,
946 .root = &nv50_disp_root_oclass,
947 .head.vblank_init = nv50_disp_vblank_init,
948 .head.vblank_fini = nv50_disp_vblank_fini,
949 .head.scanoutpos = nv50_disp_root_scanoutpos,
950 .outp.internal.crt = nv50_dac_output_new,
951 .outp.internal.tmds = nv50_sor_output_new,
952 .outp.internal.lvds = nv50_sor_output_new,
953 .outp.external.tmds = nv50_pior_output_new,
954 .outp.external.dp = nv50_pior_dp_new,
956 .dac.power = nv50_dac_power,
957 .dac.sense = nv50_dac_sense,
959 .sor.power = nv50_sor_power,
961 .pior.power = nv50_pior_power,
965 nv50_disp_new(struct nvkm_device *device, int index, struct nvkm_disp **pdisp)
967 return nv50_disp_new_(&nv50_disp, device, index, 2, pdisp);