summaryrefslogtreecommitdiff
path: root/src/glamo-kms-driver.c
blob: 5bd58e5cd00f9c4db68da14e6f74fd68c75c1dcc (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
/*
 * KMS Support for the SMedia Glamo3362 X.org Driver
 *
 * Copyright 2009 Thomas White <taw@bitwiz.org.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 *
 * The KMS parts of this driver are based on 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>
 *
 */


#include <sys/types.h>
#include <dirent.h>

#include "xf86.h"


static int modesettingEntityIndex = -1;


/* Return TRUE if KMS can be used */
Bool GlamoKernelModesettingAvailable()
{
	DIR *dir;
	struct dirent *ent;

	dir = opendir("/sys/bus/platform/devices/glamo-fb.0/");
	if ( !dir ) return FALSE;

	do {

		ent = readdir(dir);

		if ( strncmp(ent->d_name, "drm:controlD", 12) == 0 ) {
			closedir(dir);
			return TRUE;
		}

	} while ( ent )

	closedir(dir);
	return FALSE;
}


Bool GlamoKMSPreInit(ScrnInfoPtr pScrn, int flags)
{
	xf86CrtcConfigPtr xf86_config;
	GlamoPtr pGlamo;
	MessageType from = X_PROBED;
	rgb defaultWeight = { 0, 0, 0 };
	EntityInfoPtr pEnt;
	EntPtr glamoEnt = NULL;
	char *BusID;
	int i;
	char *s;
	int num_pipe;
	int max_width, max_height;

	if ( pScrn->numEntities != 1 ) return FALSE;

	pEnt = xf86GetEntityInfo(pScrn->entityList[0]);

	/* Can't do this yet */
	if ( flags & PROBE_DETECT ) {
		ConfiguredMonitor = NULL;
		return TRUE;
	}

	/* Allocate driverPrivate */
	if ( !GlamoGetRec(pScrn) ) return FALSE;
	pGlamo = GlamoPTR(pScrn);
	pGlamo->SaveGeneration = -1;
	pGlamo->pEnt = pEnt;

	pScrn->displayWidth = 640;	       /* default it */

	/* Allocate an entity private if necessary */
	if ( xf86IsEntityShared(pScrn->entityList[0]) ) {
		msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
		                             modesettingEntityIndex)->ptr;
		pGlamo->entityPrivate = msEnt;
	} else {
		pGlamo->entityPrivate = NULL;
	}

	if ( xf86RegisterResources(ms->pEnt->index, NULL, ResNone) ) {
		return FALSE;
	}

	if ( xf86IsEntityShared(pScrn->entityList[0]) ) {
		if ( xf86IsPrimInitDone(pScrn->entityList[0]) ) {
			/* do something */
		} else {
		    xf86SetPrimInitDone(pScrn->entityList[0]);
		}
	}

	pGlamo->drm_fd = drmOpen(NULL, "platform:glamo-fb");

	if ( ms->fd < 0 ) return FALSE;

	pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
	pScrn->monitor = pScrn->confScreen->monitor;
	pScrn->progClock = TRUE;
	pScrn->rgbBits = 8;

	if ( !xf86SetDepthBpp (pScrn, 0, 0, 0
	                       PreferConvert24to32
	                       | SupportConvert24to32
	                       | Support32bppFb))
	return FALSE;

	if ( pScrn->depth != 16 ) {
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
		           "Given depth (%d) is not supported by the driver\n",
		           pScrn->depth);
		return FALSE;
	}
	xf86PrintDepthBpp(pScrn);

	if ( !xf86SetWeight(pScrn, defaultWeight, defaultWeight) ) return FALSE;
	if ( !xf86SetDefaultVisual(pScrn, -1) ) return FALSE;

	/* Process the options */
	xf86CollectOptions(pScrn, NULL);
	if ( !(ms->Options = xalloc(sizeof(Options))) ) return FALSE;
	memcpy(ms->Options, Options, sizeof(Options));
	xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);

	/* Allocate an xf86CrtcConfig */
	xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
	xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);

	max_width = 8192;
	max_height = 8192;
	xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);

	if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
		ms->SWCursor = TRUE;
	}

	SaveHWState(pScrn);

	crtc_init(pScrn);
	output_init(pScrn);

	if (!xf86InitialConfiguration(pScrn, TRUE)) {
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
		RestoreHWState(pScrn);
		return FALSE;
	}

	RestoreHWState(pScrn);

	/*
	 * If the driver can do gamma correction, it should call xf86SetGamma() here.
	 */
	{
	Gamma zeros = { 0.0, 0.0, 0.0 };

	if (!xf86SetGamma(pScrn, zeros)) {
	    return FALSE;
	}
	}

	if (pScrn->modes == NULL) {
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
		return FALSE;
	}

	pScrn->currentMode = pScrn->modes;

	/* Set display resolution */
	xf86SetDpi(pScrn, 0, 0);

	/* Load the required sub modules */
	if (!xf86LoadSubModule(pScrn, "fb")) return FALSE;
	xf86LoaderReqSymLists(fbSymbols, NULL);
	xf86LoadSubModule(pScrn, "exa");
	xf86LoadSubModule(pScrn, "dri2");

	return TRUE;
}


Bool GlamoKMSScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
                        char **argv)
{
}


Bool GlamoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
{
}


void GlamoAdjustFrame(int scrnIndex, int x, int y, int flags)
{
}


Bool GlamoEnterVT(int scrnIndex, int flags)
{
}


void GlamoLeaveVT(int scrnIndex, int flags)
{
}


ModeStatus GlamoValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
                     int flags)
{
}