Only hackup shaders once
[nouveau] / src / nv50_connector.c
1 /*
2  * Copyright 2008 Maarten Maathuis
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #include "nouveau_modeset.h"
24 #include "nouveau_crtc.h"
25 #include "nouveau_output.h"
26 #include "nouveau_connector.h"
27
28 static xf86MonPtr
29 NV50ConnectorGetEDID(nouveauConnectorPtr connector)
30 {
31         ScrnInfoPtr pScrn = connector->scrn;
32
33         return xf86DoEDID_DDC2(pScrn->scrnIndex, connector->pDDCBus);
34 }
35
36 static xf86MonPtr
37 NV50ConnectorDDCDetect(nouveauConnectorPtr connector)
38 {
39         ScrnInfoPtr pScrn = connector->scrn;
40         xf86MonPtr ddc_mon;
41
42         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NV50ConnectorDDCDetect is called.\n");
43
44         if (!connector->pDDCBus)
45                 return FALSE;
46
47         ddc_mon = NV50ConnectorGetEDID(connector);
48
49         return ddc_mon;
50 }
51
52 static DisplayModePtr
53 NV50ConnectorGetDDCModes(nouveauConnectorPtr connector)
54 {
55         ScrnInfoPtr pScrn = connector->scrn;
56         xf86MonPtr ddc_mon;
57
58         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NV50ConnectorGetDDCModes is called.\n");
59
60         ddc_mon = NV50ConnectorGetEDID(connector);
61
62         if (!ddc_mon)
63                 return NULL;
64
65         return xf86DDCGetModes(pScrn->scrnIndex, ddc_mon);
66 }
67
68 void
69 NV50ConnectorInit(ScrnInfoPtr pScrn)
70 {
71         int i;
72         NVPtr pNv = NVPTR(pScrn);
73
74         /* Maybe a bit overdone, because often only 3 or 4 connectors are present. */
75         for (i = 0; i < MAX_NUM_DCB_ENTRIES; i++) {
76                 nouveauConnectorPtr connector = xnfcalloc(sizeof(nouveauConnectorRec), 1);
77                 connector->scrn = pScrn;
78                 connector->index = i;
79
80                 char connector_name[20];
81                 sprintf(connector_name, "Connector-%d", i);
82                 connector->name = xstrdup(connector_name);
83
84                 /* Function pointers. */
85                 connector->DDCDetect = NV50ConnectorDDCDetect;
86                 connector->GetDDCModes = NV50ConnectorGetDDCModes;
87                 connector->HotplugDetect = NULL;
88
89                 pNv->connector[i] = connector;
90         }
91 }
92
93 void
94 NV50ConnectorDestroy(ScrnInfoPtr pScrn)
95 {
96         int i;
97         NVPtr pNv = NVPTR(pScrn);
98
99         /* Maybe a bit overdone, because often only 3 or 4 connectors are present. */
100         for (i = 0; i < MAX_NUM_DCB_ENTRIES; i++) {
101                 nouveauConnectorPtr connector = pNv->connector[i];
102
103                 xfree(connector->name);
104                 xfree(connector);
105                 pNv->connector[i] = NULL;
106         }
107 }
108