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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
/*
* Copyright 2007 Tilman Sauerbeck
*
* 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
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* them 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 MERCHANTIBILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS 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.
*
* Authors:
* Tilman Sauerbeck <tilman@code-monkey.de>
*
* Sources:
* xf86-video-intel
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "xf86.h"
#include "xf86PciInfo.h"
#include "mga_reg.h"
#include "mga.h"
#define MGAOUTPUTDATAPTR(p) ((MgaOutputDataPtr) ((p)->driver_private))
typedef struct {
I2CBusPtr ddc_bus;
} MgaOutputDataRec, *MgaOutputDataPtr;
static void output_dac1_dpms(xf86OutputPtr output, int mode);
static void output_dac2_dpms(xf86OutputPtr output, int mode);
static void output_panel_dpms(xf86OutputPtr output, int mode);
static void output_save(xf86OutputPtr output);
static void output_restore(xf86OutputPtr output);
static void output_panel_restore(xf86OutputPtr output);
static int output_mode_valid(xf86OutputPtr output, DisplayModePtr mode);
static Bool output_mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode);
static void output_prepare(xf86OutputPtr output);
static void output_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode);
static void output_dac2_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode);
static void output_panel_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode);
static void output_commit(xf86OutputPtr output);
static xf86OutputStatus output_detect(xf86OutputPtr output);
static DisplayModePtr output_get_modes(xf86OutputPtr output);
static void output_destroy(xf86OutputPtr output);
static const xf86OutputFuncsRec output_dac1_funcs = {
.dpms = output_dac1_dpms,
.save = output_save,
.restore = output_restore,
.mode_valid = output_mode_valid,
.mode_fixup = output_mode_fixup,
.prepare = output_prepare,
.mode_set = output_mode_set,
.commit = output_commit,
.detect = output_detect,
.get_modes = output_get_modes,
.destroy = output_destroy
};
static const xf86OutputFuncsRec output_dac2_funcs = {
.dpms = output_dac2_dpms,
.save = output_save,
.restore = output_restore,
.mode_valid = output_mode_valid,
.mode_fixup = output_mode_fixup,
.prepare = output_prepare,
.mode_set = output_dac2_mode_set,
.commit = output_commit,
.detect = output_detect,
.get_modes = output_get_modes,
.destroy = output_destroy
};
static const xf86OutputFuncsRec output_panel_funcs = {
.dpms = output_panel_dpms,
.save = output_save,
.restore = output_panel_restore,
.mode_valid = output_mode_valid,
.mode_fixup = output_mode_fixup,
.prepare = output_prepare,
.mode_set = output_panel_mode_set,
.commit = output_commit,
.detect = output_detect,
.get_modes = output_get_modes,
.destroy = output_destroy
};
static void
output_dac1_dpms(xf86OutputPtr output, int mode)
{
/* XXX
* . Prefer an implementation that doesn't depend on VGA specifics.
*
* . This will only work for the primary output or maybe only for
* CRTC1?
*/
MGAPtr pMga = MGAPTR(output->scrn);
CARD8 misc_ctl, disp_ctl, mask;
#if 0
CARD8 val, seq1, crtcext1;
OUTREG8(MGAREG_SEQ_INDEX, 0x01); /* Select SEQ1 */
OUTREG8(MGAREG_CRTCEXT_INDEX, 0x01); /* Select CRTCEXT1 */
seq1 = INREG8(MGAREG_SEQ_DATA);
seq1 &= ~MGAREG_SEQ1_SCREEN_OFF;
crtcext1 = INREG8(MGAREG_CRTCEXT_DATA);
crtcext1 &= ~MGAREG_CRTCEXT1_HSYNC_OFF;
crtcext1 &= ~MGAREG_CRTCEXT1_VSYNC_OFF;
switch (mode) {
case DPMSModeOn:
/* nothing to do */
break;
case DPMSModeStandby:
seq1 |= MGAREG_SEQ1_SCREEN_OFF;
crtcext1 = MGAREG_CRTCEXT1_HSYNC_OFF;
break;
case DPMSModeSuspend:
seq1 |= MGAREG_SEQ1_SCREEN_OFF;
crtcext1 |= MGAREG_CRTCEXT1_VSYNC_OFF;
break;
case DPMSModeOff:
seq1 |= MGAREG_SEQ1_SCREEN_OFF;
crtcext1 |= MGAREG_CRTCEXT1_HSYNC_OFF;
crtcext1 |= MGAREG_CRTCEXT1_VSYNC_OFF;
break;
}
MGAWAITVSYNC();
MGAWAITBUSY();
OUTREG8(MGAREG_SEQ_DATA, seq1);
usleep(20000);
OUTREG8(MGAREG_CRTCEXT_DATA, crtcext1);
#endif
/* enable/disable DAC.
*
* FIXME:
* does this affect DAC2 too?
*/
misc_ctl = inMGAdac(MGA1064_MISC_CTL);
mask = MGA1064_MISC_CTL_DAC_EN;
if (mode == DPMSModeOn)
outMGAdac(MGA1064_MISC_CTL, misc_ctl | mask);
else
outMGAdac(MGA1064_MISC_CTL, misc_ctl & ~mask);
disp_ctl = inMGAdac(MGA1064_DISP_CTL);
mask = MGA1064_DISP_CTL_DAC1OUTSEL_EN;
if (mode == DPMSModeOn)
outMGAdac(MGA1064_DISP_CTL, disp_ctl | mask);
else
outMGAdac(MGA1064_DISP_CTL, disp_ctl & ~mask);
}
static void
output_dac2_dpms(xf86OutputPtr output, int mode)
{
MGAPtr pMga = MGAPTR(output->scrn);
CARD8 pwr_ctl, mask;
pwr_ctl = inMGAdac(MGA1064_PWR_CTL);
mask = MGA1064_PWR_CTL_DAC2_EN;
/* dropping _RFIFO_EN disables both outputs, so it's probably
* owned by CRTC1.
* MGA1064_PWR_CTL_RFIFO_EN;
*/
if (mode == DPMSModeOn)
outMGAdac(MGA1064_PWR_CTL, pwr_ctl | mask);
else
outMGAdac(MGA1064_PWR_CTL, pwr_ctl & ~mask);
}
static void
output_panel_dpms(xf86OutputPtr output, int mode)
{
MGAPtr pMga = MGAPTR(output->scrn);
CARD8 pwr_ctl, mask;
pwr_ctl = inMGAdac(MGA1064_PWR_CTL);
mask = MGA1064_PWR_CTL_PANEL_EN;
/* we could drop MGA1064_PWR_CTL_PANEL_EN here,
* but since that affects _both_ panels, it's somewhat useless.
*/
if (mode == DPMSModeOn)
outMGAdac(MGA1064_PWR_CTL, pwr_ctl | mask);
}
static void
output_save(xf86OutputPtr output)
{
}
static void
output_restore(xf86OutputPtr output)
{
}
static void
output_panel_restore(xf86OutputPtr output)
{
MGAPtr pMga = MGAPTR(output->scrn);
/* Reset DUALDVI register */
outMGAdac(MGA1064_DVI_PIPE_CTL, 0x0);
/* Set Panel mode between 20 and 54 MHz */
outMGAdac(MGA1064_PAN_CTL, 0x7);
}
static int
output_mode_valid(xf86OutputPtr output, DisplayModePtr mode)
{
return MODE_OK;
}
static Bool
output_mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode)
{
return TRUE;
}
static void
output_prepare(xf86OutputPtr output)
{
output->funcs->dpms(output, DPMSModeOff);
}
static void
output_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode)
{
}
static void
output_dac2_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode)
{
MGAPtr pMga = MGAPTR(output->scrn);
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(output->scrn);
CARD8 disp_ctl;
disp_ctl = inMGAdac(MGA1064_DISP_CTL);
disp_ctl &= ~MGA1064_DISP_CTL_DAC2OUTSEL_MASK;
/* Is this output mapped to CRTC1? */
if (output->crtc == config->crtc[0])
disp_ctl |= MGA1064_DISP_CTL_DAC2OUTSEL_CRTC1;
else
disp_ctl |= MGA1064_DISP_CTL_DAC2OUTSEL_CRTC2;
outMGAdac(MGA1064_DISP_CTL, disp_ctl);
}
static void
output_commit(xf86OutputPtr output)
{
output->funcs->dpms(output, DPMSModeOn);
}
static CARD8
get_pan_ctl_value(xf86OutputPtr output, DisplayModePtr mode)
{
MGAPtr pMga = MGAPTR(output->scrn);
/* these tables are based on code from matroxfb,
* used with permission by Petr Vandrovec.
*/
static int g450_thresholds[] = {
45000, 65000, 85000, 105000,
135000, 160000, 175000, -1
};
static int g550_thresholds[] = {
45000, 55000, 70000, 85000,
10000, 115000, 125000, -1
};
int *ptr = (pMga->Chipset == PCI_CHIP_MGAG550)
? g550_thresholds : g450_thresholds;
CARD8 ret = 0;
while (*ptr != -1 && *ptr++ < mode->Clock)
ret += 0x08;
return ret;
}
static void
output_panel_mode_set(xf86OutputPtr output, DisplayModePtr mode,
DisplayModePtr adjusted_mode)
{
MGAPtr pMga = MGAPTR(output->scrn);
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(output->scrn);
CARD8 disp_ctl;
outMGAdac(MGA1064_PAN_CTL, get_pan_ctl_value (output, mode));
disp_ctl = inMGAdac(MGA1064_DISP_CTL);
disp_ctl &= ~MGA1064_DISP_CTL_PANOUTSEL_MASK;
/* Is this output mapped to CRTC1? */
if (output->crtc == config->crtc[0])
disp_ctl |= MGA1064_DISP_CTL_PANOUTSEL_CRTC1;
else
disp_ctl |= MGA1064_DISP_CTL_PANOUTSEL_CRTC2RGB;
outMGAdac(MGA1064_DISP_CTL, disp_ctl);
}
static xf86OutputStatus
output_detect(xf86OutputPtr output)
{
MgaOutputDataPtr data = MGAOUTPUTDATAPTR(output);
/* 0xa0 is DDC EEPROM address */
if (xf86I2CProbeAddress(data->ddc_bus, 0xa0))
return XF86OutputStatusConnected;
else
return XF86OutputStatusUnknown;
}
static DisplayModePtr
output_get_modes(xf86OutputPtr output)
{
MgaOutputDataPtr data = MGAOUTPUTDATAPTR(output);
xf86MonPtr mon;
mon = xf86OutputGetEDID(output, data->ddc_bus);
xf86OutputSetEDID(output, mon);
return xf86OutputGetEDIDModes(output);
}
static void
output_destroy(xf86OutputPtr output)
{
if (output->driver_private)
xfree(output->driver_private);
}
xf86OutputPtr
MgaGOutputDac1Init(ScrnInfoPtr scrn)
{
MGAPtr pMga = MGAPTR(scrn);
xf86OutputPtr output;
MgaOutputDataPtr data;
data = xnfcalloc(sizeof(MgaOutputDataRec), 1);
if (!data)
return NULL;
output = xf86OutputCreate(scrn, &output_dac1_funcs, "VGA1");
if (!output) {
xfree(data);
return NULL;
}
output->driver_private = data;
data->ddc_bus = pMga->DDC_Bus1;
return output;
}
xf86OutputPtr
MgaGOutputDac2Init(ScrnInfoPtr scrn)
{
MGAPtr pMga = MGAPTR(scrn);
xf86OutputPtr output;
MgaOutputDataPtr data;
data = xnfcalloc(sizeof(MgaOutputDataRec), 1);
if (!data)
return NULL;
output = xf86OutputCreate(scrn, &output_dac2_funcs, "VGA2");
if (!output) {
xfree(data);
return NULL;
}
output->driver_private = data;
data->ddc_bus = pMga->DDC_Bus2;
return output;
}
xf86OutputPtr
MgaGOutputPanelInit(ScrnInfoPtr scrn)
{
MGAPtr pMga = MGAPTR(scrn);
xf86OutputPtr output;
MgaOutputDataPtr data;
data = xnfcalloc(sizeof(MgaOutputDataRec), 1);
if (!data)
return NULL;
output = xf86OutputCreate(scrn, &output_panel_funcs, "Panel1");
if (!output) {
xfree(data);
return NULL;
}
output->driver_private = data;
data->ddc_bus = pMga->DDC_Bus1;
return output;
}
|