randr12: common tmds access functions
[nouveau] / src / nv50_crtc.c
1 /*
2  * Copyright (c) 2007 NVIDIA, Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 #include "nv_include.h"
25
26 /* Don't call the directly, only load state should do this on the long run*/
27 void NV50CheckWriteVClk(ScrnInfoPtr pScrn)
28 {
29         NVPtr pNv = NVPTR(pScrn);
30         while (NVRead(pNv, 0x00610300) & 0x80000000) {
31                 /* What does is the meaning of this? */
32                 const int super = ffs((NVRead(pNv, 0x00610024) >> 4) & 0x7);
33
34                 if (super > 0) {
35                         if (super == 2) {
36                                 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
37                                 const CARD32 clockvar = NVRead(pNv, 0x00610030);
38                                 int i;
39
40                                 for(i = 0; i < xf86_config->num_crtc; i++) {
41                                         xf86CrtcPtr crtc = xf86_config->crtc[i];
42                                         NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
43
44                                         if (clockvar & (1 << (9 + nv_crtc->head))) {
45                                                 NV50CrtcSetPClk(crtc);
46                                         }
47                                 }
48                         }
49
50                         NVWrite(pNv, 0x00610024, 1 << (3 + super));
51                         NVWrite(pNv, 0x00610030, 0x80000000);
52                 }
53         }
54 }
55
56 void NV50DisplayCommand(ScrnInfoPtr pScrn, CARD32 addr, CARD32 value)
57 {
58         NVPtr pNv = NVPTR(pScrn);
59         NVWrite(pNv, 0x00610304, value);
60         NVWrite(pNv, 0x00610300, addr | 0x80010001);
61         NV50CheckWriteVClk(pScrn);
62 }
63
64 void NV50CrtcCommand(xf86CrtcPtr crtc, CARD32 addr, CARD32 value)
65 {
66         ScrnInfoPtr pScrn = crtc->scrn;
67         NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
68
69         /* This head dependent offset may not be true everywere */
70         NV50DisplayCommand(pScrn, addr + 0x400 * nv_crtc->head, value);
71 }
72
73 void nv50_crtc_dpms_set(xf86CrtcPtr crtc, int mode)
74 {
75 }
76
77 static Bool nv50_crtc_lock(xf86CrtcPtr crtc)
78 {
79         return FALSE;
80 }
81
82 static const xf86CrtcFuncsRec nv50_crtc_funcs = {
83         .dpms = nv50_crtc_dpms_set,
84         .save = NULL,
85         .restore = NULL,
86         .lock = nv50_crtc_lock,
87         .unlock = NULL,
88         .mode_fixup = NV50CrtcModeFixup,
89         .prepare = NV50CrtcPrepare,
90         .mode_set = NV50CrtcModeSet,
91         // .gamma_set = NV50DispGammaSet,
92         .commit = NV50CrtcCommit,
93         .shadow_create = NULL,
94         .shadow_destroy = NULL,
95         .set_cursor_position = NV50SetCursorPosition,
96         .show_cursor = NV50CrtcShowCursor,
97         .hide_cursor = NV50CrtcHideCursor,
98         .load_cursor_argb = NV50LoadCursorARGB,
99         .destroy = NULL,
100 };
101
102 void NV50DispCreateCrtcs(ScrnInfoPtr pScrn)
103 {
104         NVPtr pNv = NVPTR(pScrn);
105         Head head;
106         xf86CrtcPtr crtc;
107         NVCrtcPrivatePtr nv50_crtc;
108
109         /* Create a "crtc" object for each head */
110         for(head = HEAD0; head <= HEAD1; head++) {
111                 crtc = xf86CrtcCreate(pScrn, &nv50_crtc_funcs);
112                 if(!crtc) return;
113
114                 nv50_crtc = xnfcalloc(sizeof(*nv50_crtc), 1);
115                 nv50_crtc->head = head;
116                 nv50_crtc->ditherEnabled = pNv->FPDither;
117                 crtc->driver_private = nv50_crtc;
118         }
119 }
120