summaryrefslogtreecommitdiff
path: root/src/glamo-kms-crtc.c
blob: fdf0e9f506978dd660726a8d63f7fb60d81fa565 (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
/*
 * KMS Support for the SMedia Glamo3362 X.org Driver
 *
 * Modified: 2009 by Thomas White <taw@bitwiz.org.uk>
 *
 * Based on crtc.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 <unistd.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <errno.h>

#include <xf86.h>
#include <xf86i2c.h>
#include <xf86Crtc.h>
#include <xf86drm.h>
#include <drm.h>
#include <xf86drmMode.h>
#include <xf86Modes.h>
#define DPMS_SERVER
#include <X11/extensions/dpmsconst.h>

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


struct crtc_private
{
	drmModeCrtcPtr drm_crtc;
};


static void crtc_dpms(xf86CrtcPtr crtc, int mode)
{
	switch (mode) {
	case DPMSModeOn:
	case DPMSModeStandby:
	case DPMSModeSuspend:
		break;
	case DPMSModeOff:
		break;
	}
}


static Bool crtc_lock(xf86CrtcPtr crtc)
{
	return FALSE;
}


static void crtc_unlock(xf86CrtcPtr crtc)
{
}


static void crtc_prepare(xf86CrtcPtr crtc)
{
}


static void crtc_commit(xf86CrtcPtr crtc)
{
}


static Bool crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
                            DisplayModePtr adjusted_mode)
{
	return TRUE;
}


static void crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
                          DisplayModePtr adjusted_mode, int x, int y)
{
	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
	GlamoPtr pGlamo = GlamoPTR(crtc->scrn);
	xf86OutputPtr output = config->output[config->compat_output];
	drmModeConnectorPtr drm_connector = output->driver_private;
	struct crtc_private *crtcp = crtc->driver_private;
	drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
	drmModeModeInfo drm_mode;

	drm_mode.clock = mode->Clock;
	drm_mode.hdisplay = mode->HDisplay;
	drm_mode.hsync_start = mode->HSyncStart;
	drm_mode.hsync_end = mode->HSyncEnd;
	drm_mode.htotal = mode->HTotal;
	drm_mode.vdisplay = mode->VDisplay;
	drm_mode.vsync_start = mode->VSyncStart;
	drm_mode.vsync_end = mode->VSyncEnd;
	drm_mode.vtotal = mode->VTotal;
	drm_mode.flags = mode->Flags;
	drm_mode.hskew = mode->HSkew;
	drm_mode.vscan = mode->VScan;
	drm_mode.vrefresh = mode->VRefresh;
	if ( !mode->name )
		xf86SetModeDefaultName(mode);
	strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);

	drmModeSetCrtc(pGlamo->drm_fd, drm_crtc->crtc_id, pGlamo->fb_id, x, y,
	               &drm_connector->connector_id, 1, &drm_mode);
}


void crtc_load_lut(xf86CrtcPtr crtc)
{
}


static void crtc_gamma_set(xf86CrtcPtr crtc,
                           CARD16 *red, CARD16 *green, CARD16 *blue,
                           int size)
{
}


static void *crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
{
	return NULL;
}


static PixmapPtr crtc_shadow_create(xf86CrtcPtr crtc, void *data,
                                    int width, int height)
{
	return NULL;
}


static void crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap,
                                void *data)
{
}


static void crtc_destroy(xf86CrtcPtr crtc)
{
	struct crtc_private *crtcp = crtc->driver_private;

	drmModeFreeCrtc(crtcp->drm_crtc);
	xfree(crtcp);
}


static const xf86CrtcFuncsRec crtc_funcs = {
	.dpms = crtc_dpms,
	.save = NULL,
	.restore = NULL,
	.lock = crtc_lock,
	.unlock = crtc_unlock,
	.mode_fixup = crtc_mode_fixup,
	.prepare = crtc_prepare,
	.mode_set = crtc_mode_set,
	.commit = crtc_commit,
	.gamma_set = crtc_gamma_set,
	.shadow_create = crtc_shadow_create,
	.shadow_allocate = crtc_shadow_allocate,
	.shadow_destroy = crtc_shadow_destroy,
	.set_cursor_position = NULL,
	.show_cursor = NULL,
	.hide_cursor = NULL,
	.load_cursor_image = NULL,	       /* lets convert to argb only */
	.set_cursor_colors = NULL,	       /* using argb only */
	.load_cursor_argb = NULL,
	.destroy = crtc_destroy,
};


void crtc_init(ScrnInfoPtr pScrn)
{
	xf86CrtcPtr crtc;
	GlamoPtr pGlamo = GlamoPTR(pScrn);
	drmModeResPtr res;
	drmModeCrtcPtr drm_crtc = NULL;
	struct crtc_private *crtcp;
	int c;

	res = drmModeGetResources(pGlamo->drm_fd);
	if (res == 0) {
		ErrorF("Failed drmModeGetResources %d\n", errno);
		return;
	}

	for (c = 0; c < res->count_crtcs; c++) {
		drm_crtc = drmModeGetCrtc(pGlamo->drm_fd, res->crtcs[c]);
		if (!drm_crtc)
		    continue;

		crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
		if (crtc == NULL)
		    goto out;

		crtcp = xcalloc(1, sizeof(struct crtc_private));
		if (!crtcp) {
		    xf86CrtcDestroy(crtc);
		    goto out;
		}

		crtcp->drm_crtc = drm_crtc;

		crtc->driver_private = crtcp;
	}

out:
	drmModeFreeResources(res);
}