Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / state_trackers / xorg / xorg_output.c
1 /*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31 #include "xorg-server.h"
32 #include <xf86.h>
33 #include <xf86i2c.h>
34 #include <xf86Crtc.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <stdint.h>
41 #include <string.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
44
45 #define DPMS_SERVER
46 #include <X11/extensions/dpms.h>
47
48 #include "X11/Xatom.h"
49
50 #include "xorg_tracker.h"
51
52 static char *connector_enum_list[] = {
53 "Unknown",
54 "VGA",
55 "DVI-I",
56 "DVI-D",
57 "DVI-A",
58 "Composite",
59 "SVIDEO",
60 "LVDS",
61 "Component",
62 "9-pin DIN",
63 "DisplayPort",
64 "HDMI Type A",
65 "HDMI Type B",
66 };
67
68 static void
69 dpms(xf86OutputPtr output, int mode)
70 {
71 }
72
73 static void
74 save(xf86OutputPtr output)
75 {
76 }
77
78 static void
79 restore(xf86OutputPtr output)
80 {
81 }
82
83 static int
84 mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
85 {
86 return MODE_OK;
87 }
88
89 static Bool
90 mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
91 DisplayModePtr adjusted_mode)
92 {
93 return TRUE;
94 }
95
96 static void
97 prepare(xf86OutputPtr output)
98 {
99 dpms(output, DPMSModeOff);
100 }
101
102 static void
103 mode_set(xf86OutputPtr output, DisplayModePtr mode,
104 DisplayModePtr adjusted_mode)
105 {
106 }
107
108 static void
109 commit(xf86OutputPtr output)
110 {
111 dpms(output, DPMSModeOn);
112
113 if (output->scrn->pScreen != NULL)
114 xf86_reload_cursors(output->scrn->pScreen);
115 }
116
117 static xf86OutputStatus
118 detect(xf86OutputPtr output)
119 {
120 drmModeConnectorPtr drm_connector = output->driver_private;
121
122 switch (drm_connector->connection) {
123 case DRM_MODE_CONNECTED:
124 return XF86OutputStatusConnected;
125 case DRM_MODE_DISCONNECTED:
126 return XF86OutputStatusDisconnected;
127 default:
128 return XF86OutputStatusUnknown;
129 }
130 }
131
132 static DisplayModePtr
133 get_modes(xf86OutputPtr output)
134 {
135 drmModeConnectorPtr drm_connector = output->driver_private;
136 drmModeModeInfoPtr drm_mode = NULL;
137 DisplayModePtr modes = NULL, mode = NULL;
138 int i;
139
140 for (i = 0; i < drm_connector->count_modes; i++) {
141 drm_mode = &drm_connector->modes[i];
142 if (drm_mode) {
143 mode = xcalloc(1, sizeof(DisplayModeRec));
144 if (!mode)
145 continue;
146 mode->type = 0;
147 mode->Clock = drm_mode->clock;
148 mode->HDisplay = drm_mode->hdisplay;
149 mode->HSyncStart = drm_mode->hsync_start;
150 mode->HSyncEnd = drm_mode->hsync_end;
151 mode->HTotal = drm_mode->htotal;
152 mode->VDisplay = drm_mode->vdisplay;
153 mode->VSyncStart = drm_mode->vsync_start;
154 mode->VSyncEnd = drm_mode->vsync_end;
155 mode->VTotal = drm_mode->vtotal;
156 mode->Flags = drm_mode->flags;
157 mode->HSkew = drm_mode->hskew;
158 mode->VScan = drm_mode->vscan;
159 mode->VRefresh = xf86ModeVRefresh(mode);
160 mode->Private = (void *)drm_mode;
161 xf86SetModeDefaultName(mode);
162 modes = xf86ModesAdd(modes, mode);
163 xf86PrintModeline(0, mode);
164 }
165 }
166
167 return modes;
168 }
169
170 static void
171 destroy(xf86OutputPtr output)
172 {
173 drmModeFreeConnector(output->driver_private);
174 }
175
176 static void
177 create_resources(xf86OutputPtr output)
178 {
179 #ifdef RANDR_12_INTERFACE
180 #endif /* RANDR_12_INTERFACE */
181 }
182
183 #ifdef RANDR_12_INTERFACE
184 static Bool
185 set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
186 {
187 return TRUE;
188 }
189 #endif /* RANDR_12_INTERFACE */
190
191 #ifdef RANDR_13_INTERFACE
192 static Bool
193 get_property(xf86OutputPtr output, Atom property)
194 {
195 return TRUE;
196 }
197 #endif /* RANDR_13_INTERFACE */
198
199 #ifdef RANDR_GET_CRTC_INTERFACE
200 static xf86CrtcPtr
201 get_crtc(xf86OutputPtr output)
202 {
203 return NULL;
204 }
205 #endif
206
207 static const xf86OutputFuncsRec output_funcs = {
208 .create_resources = create_resources,
209 .dpms = dpms,
210 .save = save,
211 .restore = restore,
212 .mode_valid = mode_valid,
213 .mode_fixup = mode_fixup,
214 .prepare = prepare,
215 .mode_set = mode_set,
216 .commit = commit,
217 .detect = detect,
218 .get_modes = get_modes,
219 #ifdef RANDR_12_INTERFACE
220 .set_property = set_property,
221 #endif
222 #ifdef RANDR_13_INTERFACE
223 .get_property = get_property,
224 #endif
225 .destroy = destroy,
226 #ifdef RANDR_GET_CRTC_INTERFACE
227 .get_crtc = get_crtc,
228 #endif
229 };
230
231 void
232 output_init(ScrnInfoPtr pScrn)
233 {
234 modesettingPtr ms = modesettingPTR(pScrn);
235 xf86OutputPtr output;
236 drmModeResPtr res;
237 drmModeConnectorPtr drm_connector = NULL;
238 drmModeEncoderPtr drm_encoder = NULL;
239 char *name;
240 int c, v, p;
241
242 res = drmModeGetResources(ms->fd);
243 if (res == 0) {
244 DRV_ERROR("Failed drmModeGetResources\n");
245 return;
246 }
247
248 for (c = 0; c < res->count_connectors; c++) {
249 drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
250 if (!drm_connector)
251 goto out;
252
253 #if 0
254 for (p = 0; p < drm_connector->count_props; p++) {
255 drmModePropertyPtr prop;
256
257 prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
258
259 name = NULL;
260 if (prop) {
261 ErrorF("VALUES %d\n", prop->count_values);
262
263 for (v = 0; v < prop->count_values; v++)
264 ErrorF("%s %lld\n", prop->name, prop->values[v]);
265 }
266 }
267 #else
268 (void)p;
269 (void)v;
270 #endif
271
272 name = connector_enum_list[drm_connector->connector_type];
273
274 output = xf86OutputCreate(pScrn, &output_funcs, name);
275 if (!output)
276 continue;
277
278 drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
279 if (drm_encoder) {
280 output->possible_crtcs = drm_encoder->possible_crtcs;
281 output->possible_clones = drm_encoder->possible_clones;
282 } else {
283 output->possible_crtcs = 0;
284 output->possible_clones = 0;
285 }
286 output->driver_private = drm_connector;
287 output->subpixel_order = SubPixelHorizontalRGB;
288 output->interlaceAllowed = FALSE;
289 output->doubleScanAllowed = FALSE;
290 }
291
292 out:
293 drmModeFreeResources(res);
294 }
295
296 /* vim: set sw=4 ts=8 sts=4: */