xorg_output.c revision b8843c60565094be311e3b31c0826a3035627a3e
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 "X11/Xatom.h" 53 54#include "xorg_tracker.h" 55 56static char *connector_enum_list[] = { 57 "Unknown", 58 "VGA", 59 "DVI", 60 "DVI", 61 "DVI", 62 "Composite", 63 "SVIDEO", 64 "LVDS", 65 "CTV", 66 "DIN", 67 "DP", 68 "HDMI", 69 "HDMI", 70}; 71 72static void 73dpms(xf86OutputPtr output, int mode) 74{ 75} 76 77static void 78save(xf86OutputPtr output) 79{ 80} 81 82static void 83restore(xf86OutputPtr output) 84{ 85} 86 87static int 88mode_valid(xf86OutputPtr output, DisplayModePtr pMode) 89{ 90 return MODE_OK; 91} 92 93static Bool 94mode_fixup(xf86OutputPtr output, DisplayModePtr mode, 95 DisplayModePtr adjusted_mode) 96{ 97 return TRUE; 98} 99 100static void 101prepare(xf86OutputPtr output) 102{ 103 dpms(output, DPMSModeOff); 104} 105 106static void 107mode_set(xf86OutputPtr output, DisplayModePtr mode, 108 DisplayModePtr adjusted_mode) 109{ 110} 111 112static void 113commit(xf86OutputPtr output) 114{ 115 dpms(output, DPMSModeOn); 116 117 if (output->scrn->pScreen != NULL) 118 xf86_reload_cursors(output->scrn->pScreen); 119} 120 121static xf86OutputStatus 122detect(xf86OutputPtr output) 123{ 124 drmModeConnectorPtr drm_connector = output->driver_private; 125 126 switch (drm_connector->connection) { 127 case DRM_MODE_CONNECTED: 128 return XF86OutputStatusConnected; 129 case DRM_MODE_DISCONNECTED: 130 return XF86OutputStatusDisconnected; 131 default: 132 return XF86OutputStatusUnknown; 133 } 134} 135 136static DisplayModePtr 137get_modes(xf86OutputPtr output) 138{ 139 drmModeConnectorPtr drm_connector = output->driver_private; 140 drmModeModeInfoPtr drm_mode = NULL; 141 DisplayModePtr modes = NULL, mode = NULL; 142 int i; 143 144 for (i = 0; i < drm_connector->count_modes; i++) { 145 drm_mode = &drm_connector->modes[i]; 146 if (drm_mode) { 147 mode = xcalloc(1, sizeof(DisplayModeRec)); 148 if (!mode) 149 continue; 150 mode->type = 0; 151 mode->Clock = drm_mode->clock; 152 mode->HDisplay = drm_mode->hdisplay; 153 mode->HSyncStart = drm_mode->hsync_start; 154 mode->HSyncEnd = drm_mode->hsync_end; 155 mode->HTotal = drm_mode->htotal; 156 mode->VDisplay = drm_mode->vdisplay; 157 mode->VSyncStart = drm_mode->vsync_start; 158 mode->VSyncEnd = drm_mode->vsync_end; 159 mode->VTotal = drm_mode->vtotal; 160 mode->Flags = drm_mode->flags; 161 mode->HSkew = drm_mode->hskew; 162 mode->VScan = drm_mode->vscan; 163 mode->VRefresh = xf86ModeVRefresh(mode); 164 mode->Private = (void *)drm_mode; 165 xf86SetModeDefaultName(mode); 166 modes = xf86ModesAdd(modes, mode); 167 xf86PrintModeline(0, mode); 168 } 169 } 170 171 return modes; 172} 173 174static void 175destroy(xf86OutputPtr output) 176{ 177 drmModeFreeConnector(output->driver_private); 178} 179 180static void 181create_resources(xf86OutputPtr output) 182{ 183#ifdef RANDR_12_INTERFACE 184#endif /* RANDR_12_INTERFACE */ 185} 186 187#ifdef RANDR_12_INTERFACE 188static Bool 189set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) 190{ 191 return TRUE; 192} 193#endif /* RANDR_12_INTERFACE */ 194 195#ifdef RANDR_13_INTERFACE 196static Bool 197get_property(xf86OutputPtr output, Atom property) 198{ 199 return TRUE; 200} 201#endif /* RANDR_13_INTERFACE */ 202 203#ifdef RANDR_GET_CRTC_INTERFACE 204static xf86CrtcPtr 205get_crtc(xf86OutputPtr output) 206{ 207 return NULL; 208} 209#endif 210 211static const xf86OutputFuncsRec output_funcs = { 212 .create_resources = create_resources, 213 .dpms = dpms, 214 .save = save, 215 .restore = restore, 216 .mode_valid = mode_valid, 217 .mode_fixup = mode_fixup, 218 .prepare = prepare, 219 .mode_set = mode_set, 220 .commit = commit, 221 .detect = detect, 222 .get_modes = get_modes, 223#ifdef RANDR_12_INTERFACE 224 .set_property = set_property, 225#endif 226#ifdef RANDR_13_INTERFACE 227 .get_property = get_property, 228#endif 229 .destroy = destroy, 230#ifdef RANDR_GET_CRTC_INTERFACE 231 .get_crtc = get_crtc, 232#endif 233}; 234 235void 236output_init(ScrnInfoPtr pScrn) 237{ 238 modesettingPtr ms = modesettingPTR(pScrn); 239 xf86OutputPtr output; 240 drmModeResPtr res; 241 drmModeConnectorPtr drm_connector = NULL; 242 drmModeEncoderPtr drm_encoder = NULL; 243 char name[32]; 244 int c, v, p; 245 246 res = drmModeGetResources(ms->fd); 247 if (res == 0) { 248 DRV_ERROR("Failed drmModeGetResources\n"); 249 return; 250 } 251 252 for (c = 0; c < res->count_connectors; c++) { 253 drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]); 254 if (!drm_connector) 255 goto out; 256 257#if 0 258 for (p = 0; p < drm_connector->count_props; p++) { 259 drmModePropertyPtr prop; 260 261 prop = drmModeGetProperty(ms->fd, drm_connector->props[p]); 262 263 name = NULL; 264 if (prop) { 265 ErrorF("VALUES %d\n", prop->count_values); 266 267 for (v = 0; v < prop->count_values; v++) 268 ErrorF("%s %lld\n", prop->name, prop->values[v]); 269 } 270 } 271#else 272 (void)p; 273 (void)v; 274#endif 275 276 snprintf(name, 32, "%s%d", 277 connector_enum_list[drm_connector->connector_type], 278 drm_connector->connector_type_id); 279 280 281 output = xf86OutputCreate(pScrn, &output_funcs, name); 282 if (!output) 283 continue; 284 285 drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]); 286 if (drm_encoder) { 287 output->possible_crtcs = drm_encoder->possible_crtcs; 288 output->possible_clones = drm_encoder->possible_clones; 289 } else { 290 output->possible_crtcs = 0; 291 output->possible_clones = 0; 292 } 293 output->driver_private = drm_connector; 294 output->subpixel_order = SubPixelHorizontalRGB; 295 output->interlaceAllowed = FALSE; 296 output->doubleScanAllowed = FALSE; 297 } 298 299 out: 300 drmModeFreeResources(res); 301} 302 303/* vim: set sw=4 ts=8 sts=4: */ 304