summaryrefslogtreecommitdiff
path: root/src/glamo-kms-output.c
blob: 1f67eb0668af12cbab820e47483132f9ac9bbdb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
 * KMS Support for the SMedia Glamo3362 X.org Driver
 *
 * Modified: 2009 by Thomas White <taw@bitwiz.org.uk>
 *
 * Based on output.c from xf86-video-modesetting, to which the following
 * notice applies:
 *
 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *
 * Author: Alan Hourihane <alanh@tungstengraphics.com>
 *
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <xf86.h>
#include <xf86i2c.h>
#include <xf86Crtc.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#define DPMS_SERVER
#include <X11/extensions/dpmsconst.h>
#include <X11/Xatom.h>
#include <xf86drmMode.h>

#include "glamo.h"
#include "glamo-kms-output.h"


static char *connector_enum_list[] = {
    "Unknown",
    "VGA",
    "DVI-I",
    "DVI-D",
    "DVI-A",
    "Composite",
    "SVIDEO",
    "LVDS",
    "Component",
    "9-pin DIN",
    "DisplayPort",
    "HDMI Type A",
    "HDMI Type B",
};


static void dpms(xf86OutputPtr output, int mode)
{
}


static void save(xf86OutputPtr output)
{
}


static void restore(xf86OutputPtr output)
{
}


static int mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
{
	return MODE_OK;
}


static Bool mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
                       DisplayModePtr adjusted_mode)
{
	return TRUE;
}


static void prepare(xf86OutputPtr output)
{
	dpms(output, DPMSModeOff);
}


static void mode_set(xf86OutputPtr output, DisplayModePtr mode,
	 DisplayModePtr adjusted_mode)
{
}


static void commit(xf86OutputPtr output)
{
	dpms(output, DPMSModeOn);
}


static xf86OutputStatus detect(xf86OutputPtr output)
{
	drmModeConnectorPtr drm_connector = output->driver_private;

	switch (drm_connector->connection) {
	case DRM_MODE_CONNECTED:
		return XF86OutputStatusConnected;
	case DRM_MODE_DISCONNECTED:
		return XF86OutputStatusDisconnected;
	default:
		return XF86OutputStatusUnknown;
	}
}


static DisplayModePtr get_modes(xf86OutputPtr output)
{
	drmModeConnectorPtr drm_connector = output->driver_private;
	drmModeModeInfoPtr drm_mode = NULL;
	DisplayModePtr modes = NULL, mode = NULL;
	int i;

	for (i = 0; i < drm_connector->count_modes; i++) {
		drm_mode = &drm_connector->modes[i];
		if (drm_mode) {
			mode = xcalloc(1, sizeof(DisplayModeRec));
			if (!mode)
				continue;
			mode->type = 0;
			mode->Clock = drm_mode->clock / 1000.0;
			mode->HDisplay = drm_mode->hdisplay;
			mode->HSyncStart = drm_mode->hsync_start;
			mode->HSyncEnd = drm_mode->hsync_end;
			mode->HTotal = drm_mode->htotal;
			mode->VDisplay = drm_mode->vdisplay;
			mode->VSyncStart = drm_mode->vsync_start;
			mode->VSyncEnd = drm_mode->vsync_end;
			mode->VTotal = drm_mode->vtotal;
			mode->Flags = drm_mode->flags;
			mode->HSkew = drm_mode->hskew;
			mode->VScan = drm_mode->vscan;
			mode->VRefresh = xf86ModeVRefresh(mode);
			mode->Private = (void *)drm_mode;
			xf86SetModeDefaultName(mode);
			modes = xf86ModesAdd(modes, mode);
			xf86PrintModeline(0, mode);
		}
	}

	return modes;
}


static void destroy(xf86OutputPtr output)
{
	drmModeFreeConnector(output->driver_private);
}


static void create_resources(xf86OutputPtr output)
{
#ifdef RANDR_12_INTERFACE
#endif /* RANDR_12_INTERFACE */
}


#ifdef RANDR_12_INTERFACE
static Bool set_property(xf86OutputPtr output, Atom property,
                         RRPropertyValuePtr value)
{
	return TRUE;
}
#endif /* RANDR_12_INTERFACE */


#ifdef RANDR_13_INTERFACE
static Bool get_property(xf86OutputPtr output, Atom property)
{
	return TRUE;
}
#endif /* RANDR_13_INTERFACE */


#ifdef RANDR_GET_CRTC_INTERFACE
static xf86CrtcPtr get_crtc(xf86OutputPtr output)
{
	return NULL;
}
#endif


static const xf86OutputFuncsRec output_funcs = {
	.create_resources = create_resources,
	.dpms = dpms,
	.save = save,
	.restore = restore,
	.mode_valid = mode_valid,
	.mode_fixup = mode_fixup,
	.prepare = prepare,
	.mode_set = mode_set,
	.commit = commit,
	.detect = detect,
	.get_modes = get_modes,
#ifdef RANDR_12_INTERFACE
	.set_property = set_property,
#endif
#ifdef RANDR_13_INTERFACE
	.get_property = get_property,
#endif
	.destroy = destroy,
#ifdef RANDR_GET_CRTC_INTERFACE
	.get_crtc = get_crtc,
#endif
};


void output_init(ScrnInfoPtr pScrn)
{
	GlamoPtr pGlamo = GlamoPTR(pScrn);
	xf86OutputPtr output;
	drmModeResPtr res;
	drmModeConnectorPtr drm_connector = NULL;
	drmModeEncoderPtr drm_encoder = NULL;
	char *name;
	int c, v, p;

	res = drmModeGetResources(pGlamo->drm_fd);
	if (res == 0) {
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
		           "Failed drmModeGetResources\n");
		return;
	}

	for (c = 0; c < res->count_connectors; c++) {
		drm_connector = drmModeGetConnector(pGlamo->drm_fd,
		                                    res->connectors[c]);
		if (!drm_connector)
		goto out;

		for (p = 0; p < drm_connector->count_props; p++) {
			drmModePropertyPtr prop;

			prop = drmModeGetProperty(pGlamo->drm_fd,
				                  drm_connector->props[p]);

			name = NULL;
			if (prop) {
				ErrorF("VALUES %d\n", prop->count_values);
				for (v = 0; v < prop->count_values; v++) {
					ErrorF("%s %lld\n", prop->name,
					                    prop->values[v]);
				}
			}
		}

		name = connector_enum_list[drm_connector->connector_type];

		output = xf86OutputCreate(pScrn, &output_funcs, name);
		if (!output)
			continue;

		drm_encoder = drmModeGetEncoder(pGlamo->drm_fd,
			                        drm_connector->encoders[0]);
		if (drm_encoder) {
			output->possible_crtcs = drm_encoder->possible_crtcs;
			output->possible_clones = drm_encoder->possible_clones;
		} else {
			output->possible_crtcs = 0;
			output->possible_clones = 0;
		}
		output->driver_private = drm_connector;
		output->subpixel_order = SubPixelHorizontalRGB;
		output->interlaceAllowed = FALSE;
		output->doubleScanAllowed = FALSE;
	}

out:
	drmModeFreeResources(res);
}