2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
31 #include "xorg-server.h"
43 #include <sys/types.h>
46 #include <X11/extensions/dpms.h>
48 #include "X11/Xatom.h"
50 #include "xorg_tracker.h"
52 static char *connector_enum_list
[] = {
69 dpms(xf86OutputPtr output
, int mode
)
74 save(xf86OutputPtr output
)
79 restore(xf86OutputPtr output
)
84 mode_valid(xf86OutputPtr output
, DisplayModePtr pMode
)
90 mode_fixup(xf86OutputPtr output
, DisplayModePtr mode
,
91 DisplayModePtr adjusted_mode
)
97 prepare(xf86OutputPtr output
)
99 dpms(output
, DPMSModeOff
);
103 mode_set(xf86OutputPtr output
, DisplayModePtr mode
,
104 DisplayModePtr adjusted_mode
)
109 commit(xf86OutputPtr output
)
111 dpms(output
, DPMSModeOn
);
113 if (output
->scrn
->pScreen
!= NULL
)
114 xf86_reload_cursors(output
->scrn
->pScreen
);
117 static xf86OutputStatus
118 detect(xf86OutputPtr output
)
120 drmModeConnectorPtr drm_connector
= output
->driver_private
;
122 switch (drm_connector
->connection
) {
123 case DRM_MODE_CONNECTED
:
124 return XF86OutputStatusConnected
;
125 case DRM_MODE_DISCONNECTED
:
126 return XF86OutputStatusDisconnected
;
128 return XF86OutputStatusUnknown
;
132 static DisplayModePtr
133 get_modes(xf86OutputPtr output
)
135 drmModeConnectorPtr drm_connector
= output
->driver_private
;
136 drmModeModeInfoPtr drm_mode
= NULL
;
137 DisplayModePtr modes
= NULL
, mode
= NULL
;
140 for (i
= 0; i
< drm_connector
->count_modes
; i
++) {
141 drm_mode
= &drm_connector
->modes
[i
];
143 mode
= xcalloc(1, sizeof(DisplayModeRec
));
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
);
171 destroy(xf86OutputPtr output
)
173 drmModeFreeConnector(output
->driver_private
);
177 create_resources(xf86OutputPtr output
)
179 #ifdef RANDR_12_INTERFACE
180 #endif /* RANDR_12_INTERFACE */
183 #ifdef RANDR_12_INTERFACE
185 set_property(xf86OutputPtr output
, Atom property
, RRPropertyValuePtr value
)
189 #endif /* RANDR_12_INTERFACE */
191 #ifdef RANDR_13_INTERFACE
193 get_property(xf86OutputPtr output
, Atom property
)
197 #endif /* RANDR_13_INTERFACE */
199 #ifdef RANDR_GET_CRTC_INTERFACE
201 get_crtc(xf86OutputPtr output
)
207 static const xf86OutputFuncsRec output_funcs
= {
208 .create_resources
= create_resources
,
212 .mode_valid
= mode_valid
,
213 .mode_fixup
= mode_fixup
,
215 .mode_set
= mode_set
,
218 .get_modes
= get_modes
,
219 #ifdef RANDR_12_INTERFACE
220 .set_property
= set_property
,
222 #ifdef RANDR_13_INTERFACE
223 .get_property
= get_property
,
226 #ifdef RANDR_GET_CRTC_INTERFACE
227 .get_crtc
= get_crtc
,
232 output_init(ScrnInfoPtr pScrn
)
234 modesettingPtr ms
= modesettingPTR(pScrn
);
235 xf86OutputPtr output
;
237 drmModeConnectorPtr drm_connector
= NULL
;
238 drmModeEncoderPtr drm_encoder
= NULL
;
242 res
= drmModeGetResources(ms
->fd
);
244 DRV_ERROR("Failed drmModeGetResources\n");
248 for (c
= 0; c
< res
->count_connectors
; c
++) {
249 drm_connector
= drmModeGetConnector(ms
->fd
, res
->connectors
[c
]);
254 for (p
= 0; p
< drm_connector
->count_props
; p
++) {
255 drmModePropertyPtr prop
;
257 prop
= drmModeGetProperty(ms
->fd
, drm_connector
->props
[p
]);
261 ErrorF("VALUES %d\n", prop
->count_values
);
263 for (v
= 0; v
< prop
->count_values
; v
++)
264 ErrorF("%s %lld\n", prop
->name
, prop
->values
[v
]);
272 name
= connector_enum_list
[drm_connector
->connector_type
];
274 output
= xf86OutputCreate(pScrn
, &output_funcs
, name
);
278 drm_encoder
= drmModeGetEncoder(ms
->fd
, drm_connector
->encoders
[0]);
280 output
->possible_crtcs
= drm_encoder
->possible_crtcs
;
281 output
->possible_clones
= drm_encoder
->possible_clones
;
283 output
->possible_crtcs
= 0;
284 output
->possible_clones
= 0;
286 output
->driver_private
= drm_connector
;
287 output
->subpixel_order
= SubPixelHorizontalRGB
;
288 output
->interlaceAllowed
= FALSE
;
289 output
->doubleScanAllowed
= FALSE
;
293 drmModeFreeResources(res
);
296 /* vim: set sw=4 ts=8 sts=4: */