docs: update rasterizer for ccw changes
[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 #ifdef HAVE_XEXTPROTO_71
46 #include <X11/extensions/dpmsconst.h>
47 #else
48 #define DPMS_SERVER
49 #include <X11/extensions/dpms.h>
50 #endif
51
52 #include "xorg_tracker.h"
53
54 static char *output_enum_list[] = {
55 "Unknown",
56 "VGA",
57 "DVI",
58 "DVI",
59 "DVI",
60 "Composite",
61 "SVIDEO",
62 "LVDS",
63 "CTV",
64 "DIN",
65 "DP",
66 "HDMI",
67 "HDMI",
68 };
69
70 static void
71 output_create_resources(xf86OutputPtr output)
72 {
73 #ifdef RANDR_12_INTERFACE
74 #endif /* RANDR_12_INTERFACE */
75 }
76
77 static void
78 output_dpms(xf86OutputPtr output, int mode)
79 {
80 }
81
82 static xf86OutputStatus
83 output_detect(xf86OutputPtr output)
84 {
85 drmModeConnectorPtr drm_connector = output->driver_private;
86
87 switch (drm_connector->connection) {
88 case DRM_MODE_CONNECTED:
89 return XF86OutputStatusConnected;
90 case DRM_MODE_DISCONNECTED:
91 return XF86OutputStatusDisconnected;
92 default:
93 return XF86OutputStatusUnknown;
94 }
95 }
96
97 static DisplayModePtr
98 output_get_modes(xf86OutputPtr output)
99 {
100 drmModeConnectorPtr drm_connector = output->driver_private;
101 drmModeModeInfoPtr drm_mode = NULL;
102 DisplayModePtr modes = NULL, mode = NULL;
103 int i;
104
105 for (i = 0; i < drm_connector->count_modes; i++) {
106 drm_mode = &drm_connector->modes[i];
107 if (drm_mode) {
108 mode = xcalloc(1, sizeof(DisplayModeRec));
109 if (!mode)
110 continue;
111 mode->Clock = drm_mode->clock;
112 mode->HDisplay = drm_mode->hdisplay;
113 mode->HSyncStart = drm_mode->hsync_start;
114 mode->HSyncEnd = drm_mode->hsync_end;
115 mode->HTotal = drm_mode->htotal;
116 mode->VDisplay = drm_mode->vdisplay;
117 mode->VSyncStart = drm_mode->vsync_start;
118 mode->VSyncEnd = drm_mode->vsync_end;
119 mode->VTotal = drm_mode->vtotal;
120 mode->Flags = drm_mode->flags;
121 mode->HSkew = drm_mode->hskew;
122 mode->VScan = drm_mode->vscan;
123 mode->VRefresh = xf86ModeVRefresh(mode);
124 mode->Private = (void *)drm_mode;
125 mode->type = 0;
126 if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
127 mode->type |= M_T_PREFERRED;
128 if (drm_mode->type & DRM_MODE_TYPE_DRIVER)
129 mode->type |= M_T_DRIVER;
130 xf86SetModeDefaultName(mode);
131 modes = xf86ModesAdd(modes, mode);
132 xf86PrintModeline(0, mode);
133 }
134 }
135
136 return modes;
137 }
138
139 static int
140 output_mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
141 {
142 return MODE_OK;
143 }
144
145 #ifdef RANDR_12_INTERFACE
146 static Bool
147 output_set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
148 {
149 return TRUE;
150 }
151 #endif /* RANDR_12_INTERFACE */
152
153 #ifdef RANDR_13_INTERFACE
154 static Bool
155 output_get_property(xf86OutputPtr output, Atom property)
156 {
157 return TRUE;
158 }
159 #endif /* RANDR_13_INTERFACE */
160
161 static void
162 output_destroy(xf86OutputPtr output)
163 {
164 drmModeFreeConnector(output->driver_private);
165 }
166
167 static const xf86OutputFuncsRec output_funcs = {
168 .create_resources = output_create_resources,
169 #ifdef RANDR_12_INTERFACE
170 .set_property = output_set_property,
171 #endif
172 #ifdef RANDR_13_INTERFACE
173 .get_property = output_get_property,
174 #endif
175 .dpms = output_dpms,
176 .detect = output_detect,
177
178 .get_modes = output_get_modes,
179 .mode_valid = output_mode_valid,
180 .destroy = output_destroy,
181 };
182
183 void
184 xorg_output_init(ScrnInfoPtr pScrn)
185 {
186 modesettingPtr ms = modesettingPTR(pScrn);
187 xf86OutputPtr output;
188 drmModeResPtr res;
189 drmModeConnectorPtr drm_connector = NULL;
190 drmModeEncoderPtr drm_encoder = NULL;
191 char name[32];
192 int c, v, p;
193
194 res = drmModeGetResources(ms->fd);
195 if (res == 0) {
196 DRV_ERROR("Failed drmModeGetResources\n");
197 return;
198 }
199
200 for (c = 0; c < res->count_connectors; c++) {
201 drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
202 if (!drm_connector)
203 goto out;
204
205 #if 0
206 for (p = 0; p < drm_connector->count_props; p++) {
207 drmModePropertyPtr prop;
208
209 prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
210
211 name = NULL;
212 if (prop) {
213 ErrorF("VALUES %d\n", prop->count_values);
214
215 for (v = 0; v < prop->count_values; v++)
216 ErrorF("%s %lld\n", prop->name, prop->values[v]);
217 }
218 }
219 #else
220 (void)p;
221 (void)v;
222 #endif
223
224 snprintf(name, 32, "%s%d",
225 output_enum_list[drm_connector->connector_type],
226 drm_connector->connector_type_id);
227
228
229 output = xf86OutputCreate(pScrn, &output_funcs, name);
230 if (!output)
231 continue;
232
233 drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
234 if (drm_encoder) {
235 output->possible_crtcs = drm_encoder->possible_crtcs;
236 output->possible_clones = drm_encoder->possible_clones;
237 } else {
238 output->possible_crtcs = 0;
239 output->possible_clones = 0;
240 }
241 output->driver_private = drm_connector;
242 output->subpixel_order = SubPixelHorizontalRGB;
243 output->interlaceAllowed = FALSE;
244 output->doubleScanAllowed = FALSE;
245 }
246
247 out:
248 drmModeFreeResources(res);
249 }
250
251 /* vim: set sw=4 ts=8 sts=4: */